SVG support for Amiga version using libsvgtiny and libcairo

Cairo plotter for arcs

Cairo support is experimental and can be enabled with option NETSURF_AMIGA_USE_CAIRO
For some reason linking against shared objects breaks forms.

svn path=/trunk/netsurf/; revision=5939
This commit is contained in:
Chris Young 2008-12-28 00:41:35 +00:00
parent 2967b76f4a
commit fcf46a91b6
3 changed files with 166 additions and 3 deletions

View File

@ -434,15 +434,22 @@ ifeq ($(TARGET),amiga)
NETSURF_FEATURE_BMP_CFLAGS := -DWITH_BMP
NETSURF_FEATURE_GIF_CFLAGS := -DWITH_GIF
NETSURF_FEATURE_PNG_CFLAGS := -DWITH_PNG
NETSURF_FEATURE_NSSVG_CFLAGS := -DWITH_NS_SVG
$(eval $(call feature_enabled,ROSPRITE,-DWITH_NSSPRITE,-lrosprite,RISC OS Sprite decoder))
$(eval $(call feature_enabled,HUBBUB,-DWITH_HUBBUB,-lhubbub -lparserutils,Hubbub HTML parser))
$(eval $(call feature_enabled,HUBBUB,-DWITH_HUBBUB,-lhubbub,Hubbub HTML parser))
$(eval $(call feature_enabled,BMP,-DWITH_BMP,-lnsbmp,NetSurf BMP decoder))
$(eval $(call feature_enabled,GIF,-DWITH_GIF,-lnsgif,NetSurf GIF decoder))
$(eval $(call feature_enabled,PNG,-DWITH_PNG,-lpng,PNG support))
$(eval $(call feature_enabled,NSSVG,-DWITH_NS_SVG,-lsvgtiny,SVG rendering))
CFLAGS += -mcrt=newlib -D__USE_INLINE__ -std=c99 -I . -Dnsamiga
LDFLAGS += -lxml2 -lcurl -lm -lsocket -lpthread -lregex -lauto -lraauto -lssl -lcrypto -lamisslauto -mcrt=newlib
LDFLAGS += -lxml2 -lcurl -lm -lsocket -lpthread -lregex -lauto -lraauto -lssl -lcrypto -lamisslauto -lparserutils -mcrt=newlib
ifeq ($(NETSURF_AMIGA_USE_CAIRO),YES)
CFLAGS += -DNS_AMIGA_CAIRO
LDFLAGS += -use-dynld -lcairo -lpixman-1 -lfreetype -lfontconfig -lpng12 -lexpat
endif
endif
# ----------------------------------------------------------------------------

View File

@ -167,6 +167,17 @@ ifeq ($(TARGET),amiga)
# Valid options: YES, NO, AUTO (highly recommended)
NETSURF_USE_HUBBUB := YES
# Enable NetSurf's use of libsvgtiny for displaying SVGs
# (NB: Requires NETSURF_AMIGA_USE_CAIRO)
# Valid options: YES, NO
NETSURF_USE_NSSVG := NO
# Enable NetSurf's use of libcairo for some plotter functions
# This will also link NetSurf with shared objects, and
# requires AmigaOS 4.1 or higher to run the resulting executable
# Valid options: YES, NO
NETSURF_AMIGA_USE_CAIRO := NO
# Optimisation levels
CFLAGS += -O2 -Wuninitialized

View File

@ -30,6 +30,17 @@
#include "amiga/options.h"
#include <graphics/blitattr.h>
#include <graphics/composite.h>
#include "utils/log.h"
#include <math.h>
#ifndef M_PI /* For some reason we don't always get this from math.h */
#define M_PI 3.14159265358979323846
#endif
#ifdef NS_AMIGA_CAIRO
#include <cairo/cairo.h>
#include <cairo/cairo-amigaos.h>
#endif
#define PATT_DOT 0xAAAA
#define PATT_DASH 0xCCCC
@ -55,6 +66,41 @@ const struct plotter_table amiplot = {
false // option_knockout
};
#ifdef NS_AMIGA_CAIRO
void ami_cairo_set_colour(cairo_t *cr,colour c)
{
int r, g, b;
r = c & 0xff;
g = (c & 0xff00) >> 8;
b = (c & 0xff0000) >> 16;
cairo_set_source_rgba(cr, r / 255.0,
g / 255.0, b / 255.0, 1.0);
}
void ami_cairo_set_solid(cairo_t *cr)
{
double dashes = 0;
cairo_set_dash(cr, &dashes, 0, 0);
}
void ami_cairo_set_dotted(cairo_t *cr)
{
double cdashes = 1;
cairo_set_dash(cr, &cdashes, 1, 0);
}
void ami_cairo_set_dashed(cairo_t *cr)
{
double cdashes = 3;
cairo_set_dash(cr, &cdashes, 1, 0);
}
#endif
bool ami_clg(colour c)
{
SetRPAttrs(currp,RPTAG_BPenColor,p96EncodeColor(RGBFB_A8B8G8R8,c),
@ -234,6 +280,22 @@ bool ami_disc(int x, int y, int radius, colour c, bool filled)
bool ami_arc(int x, int y, int radius, int angle1, int angle2,
colour c)
{
#ifdef NS_AMIGA_CAIRO
cairo_surface_t *surface = cairo_amigaos_surface_create(currp->BitMap);
cairo_t *cr = cairo_create(surface);
ami_cairo_set_colour(cr,c);
ami_cairo_set_solid(cr);
cairo_set_line_width(cr, 1);
cairo_arc(cr, x, y, radius,
(angle1 + 90) * (M_PI / 180),
(angle2 + 90) * (M_PI / 180));
cairo_stroke(cr);
cairo_destroy (cr);
cairo_surface_destroy(surface);
#else
/* http://www.crbond.com/primitives.htm
CommonFuncsPPC.lha */
//DebugPrintF("arc\n");
@ -242,6 +304,7 @@ CommonFuncsPPC.lha */
TAG_DONE);
// DrawArc(currp,x,y,(float)angle1,(float)angle2,radius);
#endif
return true;
}
@ -437,6 +500,88 @@ bool ami_flush(void)
bool ami_path(float *p, unsigned int n, colour fill, float width,
colour c, float *transform)
{
/* Not implemented yet - unable to locate website which requires this plotter! */
/* For SVG only, because it needs Bezier curves we are going to cheat
and insist on Cairo */
#ifdef NS_AMIGA_CAIRO
cairo_surface_t *surface = cairo_amigaos_surface_create(currp->BitMap);
cairo_t *cr = cairo_create(surface);
unsigned int i;
cairo_matrix_t old_ctm, n_ctm;
if (n == 0)
return true;
if (p[0] != PLOTTER_PATH_MOVE) {
LOG(("Path does not start with move"));
return false;
}
/* Save CTM */
cairo_get_matrix(cr, &old_ctm);
/* Set up line style and width */
cairo_set_line_width(cr, 1);
ami_cairo_set_solid(cr);
/* Load new CTM */
n_ctm.xx = transform[0];
n_ctm.yx = transform[1];
n_ctm.xy = transform[2];
n_ctm.yy = transform[3];
n_ctm.x0 = transform[4];
n_ctm.y0 = transform[5];
cairo_set_matrix(cr, &n_ctm);
/* Construct path */
for (i = 0; i < n; ) {
if (p[i] == PLOTTER_PATH_MOVE) {
cairo_move_to(cr, p[i+1], p[i+2]);
i += 3;
} else if (p[i] == PLOTTER_PATH_CLOSE) {
cairo_close_path(cr);
i++;
} else if (p[i] == PLOTTER_PATH_LINE) {
cairo_line_to(cr, p[i+1], p[i+2]);
i += 3;
} else if (p[i] == PLOTTER_PATH_BEZIER) {
cairo_curve_to(cr, p[i+1], p[i+2],
p[i+3], p[i+4],
p[i+5], p[i+6]);
i += 7;
} else {
LOG(("bad path command %f", p[i]));
/* Reset matrix for safety */
cairo_set_matrix(cr, &old_ctm);
return false;
}
}
/* Restore original CTM */
cairo_set_matrix(cr, &old_ctm);
/* Now draw path */
if (fill != TRANSPARENT) {
ami_cairo_set_colour(cr,fill);
if (c != TRANSPARENT) {
/* Fill & Stroke */
cairo_fill_preserve(cr);
ami_cairo_set_colour(cr,c);
cairo_stroke(cr);
} else {
/* Fill only */
cairo_fill(cr);
}
} else if (c != TRANSPARENT) {
/* Stroke only */
ami_cairo_set_colour(cr,c);
cairo_stroke(cr);
}
cairo_destroy (cr);
cairo_surface_destroy(surface);
#endif
return true;
}