next round of plotter refactor

svn path=/trunk/netsurf/; revision=8512
This commit is contained in:
Vincent Sanders 2009-07-14 10:03:58 +00:00
parent ed2206316c
commit 86232d72a6
15 changed files with 843 additions and 704 deletions

View File

@ -321,7 +321,7 @@ bool ami_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
return true;
}
bool ami_polygon(const int *p, unsigned int n, colour fill)
bool ami_polygon(const int *p, unsigned int n, const plot_style_t *style)
{
int k;
#ifndef NS_AMIGA_CAIRO
@ -329,10 +329,13 @@ bool ami_polygon(const int *p, unsigned int n, colour fill)
//DebugPrintF("poly\n");
SetRPAttrs(&glob->rp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,fill),
RPTAG_OPenColor,p96EncodeColor(RGBFB_A8B8G8R8,fill),
SetRPAttrs(&glob->rp,
RPTAG_APenColor,
p96EncodeColor(RGBFB_A8B8G8R8, style->fill_colour),
RPTAG_OPenColor,
p96EncodeColor(RGBFB_A8B8G8R8, style->fill_colour),
// RPTAG_OPenColor,0xffffffff,
TAG_DONE);
TAG_DONE);
AreaMove(&glob->rp,p[0],p[1]);
@ -344,7 +347,7 @@ bool ami_polygon(const int *p, unsigned int n, colour fill)
AreaEnd(&glob->rp);
BNDRYOFF(&glob->rp);
#else
ami_cairo_set_colour(glob->cr,fill);
ami_cairo_set_colour(glob->cr, style->fill_colour);
ami_cairo_set_solid(glob->cr);
cairo_set_line_width(glob->cr, 0);
@ -404,45 +407,58 @@ bool ami_text(int x, int y, const struct css_style *style,
return true;
}
bool ami_disc(int x, int y, int radius, colour c, bool filled)
bool ami_disc(int x, int y, int radius, const plot_style_t *style)
{
#ifndef NS_AMIGA_CAIRO_ALL
SetRPAttrs(&glob->rp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c),
TAG_DONE);
if(filled)
{
if (style->fill_type != PLOT_OP_TYPE_NONE) {
SetRPAttrs(&glob->rp,
RPTAG_APenColor,
p96EncodeColor(RGBFB_A8B8G8R8, style->fill_colour),
TAG_DONE);
AreaCircle(&glob->rp,x,y,radius);
AreaEnd(&glob->rp);
}
else
{
DrawEllipse(&glob->rp,x,y,radius,radius); // NB: does not support fill, need to use AreaCircle for that
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
SetRPAttrs(&glob->rp,
RPTAG_APenColor,
p96EncodeColor(RGBFB_A8B8G8R8, style->stroke_colour),
TAG_DONE);
DrawEllipse(&glob->rp,x,y,radius,radius);
}
#else
ami_cairo_set_colour(glob->cr,c);
ami_cairo_set_solid(glob->cr);
if (style->fill_type != PLOT_OP_TYPE_NONE) {
ami_cairo_set_colour(glob->cr, style->fill_colour);
ami_cairo_set_solid(glob->cr);
if (filled)
cairo_set_line_width(glob->cr, 0);
else
cairo_set_line_width(glob->cr, 1);
cairo_arc(glob->cr, x, y, radius, 0, M_PI * 2);
cairo_arc(glob->cr, x, y, radius, 0, M_PI * 2);
if (filled)
cairo_fill(glob->cr);
cairo_stroke(glob->cr);
cairo_stroke(glob->cr);
}
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
ami_cairo_set_colour(glob->cr, style->stroke_colour);
ami_cairo_set_solid(glob->cr);
cairo_set_line_width(glob->cr, 1);
cairo_arc(glob->cr, x, y, radius, 0, M_PI * 2);
cairo_stroke(glob->cr);
}
#endif
return true;
}
bool ami_arc(int x, int y, int radius, int angle1, int angle2,
colour c)
bool ami_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style)
{
#ifdef NS_AMIGA_CAIRO
ami_cairo_set_colour(glob->cr,c);
ami_cairo_set_colour(glob->cr, style->fill_colour);
ami_cairo_set_solid(glob->cr);
cairo_set_line_width(glob->cr, 1);
@ -455,8 +471,10 @@ bool ami_arc(int x, int y, int radius, int angle1, int angle2,
CommonFuncsPPC.lha */
//DebugPrintF("arc\n");
SetRPAttrs(&glob->rp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c),
TAG_DONE);
SetRPAttrs(&glob->rp,
RPTAG_APenColor,
p96EncodeColor(RGBFB_A8B8G8R8, style->fill_colour),
TAG_DONE);
// DrawArc(&glob->rp,x,y,(float)angle1,(float)angle2,radius);
#endif

View File

@ -44,13 +44,13 @@ extern const struct plotter_table amiplot;
bool ami_clg(colour c);
bool ami_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style);
bool ami_line(int x0, int y0, int x1, int y1, const plot_style_t *style);
bool ami_polygon(const int *p, unsigned int n, colour fill);
bool ami_polygon(const int *p, unsigned int n, const plot_style_t *style);
bool ami_clip(int x0, int y0, int x1, int y1);
bool ami_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c);
bool ami_disc(int x, int y, int radius, colour c, bool filled);
bool ami_disc(int x, int y, int radius, const plot_style_t *style);
bool ami_arc(int x, int y, int radius, int angle1, int angle2,
colour c);
const plot_style_t *style);
bool ami_bitmap_tile(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags);

View File

@ -63,16 +63,16 @@ cairo_t *current_cr;
static bool nsbeos_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool nsbeos_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool nsbeos_plot_polygon(const int *p, unsigned int n, colour fill);
static bool nsbeos_plot_polygon(const int *p, unsigned int n, const plot_style_t *style);
static bool nsbeos_plot_path(const float *p, unsigned int n, colour fill, float width,
colour c, const float transform[6]);
static bool nsbeos_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1);
static bool nsbeos_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c);
static bool nsbeos_plot_disc(int x, int y, int radius, colour c, bool filled);
static bool nsbeos_plot_disc(int x, int y, int radius, const plot_style_t *style);
static bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2,
colour c);
const plot_style_t *style);
static bool nsbeos_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags);
@ -91,18 +91,18 @@ static const rgb_color kBlackColor = { 0, 0, 0, 255 };
struct plotter_table plot;
const struct plotter_table nsbeos_plotters = {
nsbeos_plot_rectangle,
nsbeos_plot_line,
nsbeos_plot_polygon,
nsbeos_plot_clip,
nsbeos_plot_text,
nsbeos_plot_disc,
nsbeos_plot_arc,
nsbeos_plot_bitmap,
NULL,
NULL,
NULL,
nsbeos_plot_disc,
nsbeos_plot_line,
nsbeos_plot_rectangle,
nsbeos_plot_polygon,
nsbeos_plot_path,
nsbeos_plot_bitmap,
nsbeos_plot_text,
NULL, // Group Start
NULL, // Group End
NULL, // Flush
false // option_knockout
};
@ -286,7 +286,7 @@ bool nsbeos_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
}
bool nsbeos_plot_polygon(const int *p, unsigned int n, colour fill)
bool nsbeos_plot_polygon(const int *p, unsigned int n, const plot_style_t *style)
{
unsigned int i;
BView *view;
@ -297,7 +297,7 @@ bool nsbeos_plot_polygon(const int *p, unsigned int n, colour fill)
return false;
}
nsbeos_set_colour(fill);
nsbeos_set_colour(style->fill_colour);
BPoint points[n];
@ -305,7 +305,7 @@ bool nsbeos_plot_polygon(const int *p, unsigned int n, colour fill)
points[i] = BPoint(p[2 * i], p[2 * i + 1]);
}
if (fill == TRANSPARENT)
if (style->fill_colour == TRANSPARENT)
view->StrokePolygon(points, (int32)n);
else
view->FillPolygon(points, (int32)n);
@ -401,7 +401,7 @@ bool nsbeos_plot_text(int x, int y, const struct css_style *style,
}
bool nsbeos_plot_disc(int x, int y, int radius, colour c, bool filled)
bool nsbeos_plot_disc(int x, int y, int radius, const plot_style_t *style)
{
BView *view;
@ -411,10 +411,10 @@ bool nsbeos_plot_disc(int x, int y, int radius, colour c, bool filled)
return false;
}
nsbeos_set_colour(c);
nsbeos_set_colour(style->fill_colour);
BPoint center(x, y);
if (filled)
if (style->fill_type != PLOT_OP_TYPE_NONE)
view->FillEllipse(center, radius, radius);
else
view->StrokeEllipse(center, radius, radius);
@ -449,7 +449,7 @@ bool nsbeos_plot_disc(int x, int y, int radius, colour c, bool filled)
return true;
}
bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c)
bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style)
{
BView *view;
@ -459,7 +459,7 @@ bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c)
return false;
}
nsbeos_set_colour(c);
nsbeos_set_colour(style->fill_colour);
BPoint center(x, y);
float angle = angle1; // in degree
@ -469,7 +469,7 @@ bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c)
//nsbeos_current_gc_unlock();
#if 0 /* GTK */
nsbeos_set_colour(c);
nsbeos_set_colour(style->fill_colour);
nsbeos_set_solid();
#ifdef CAIRO_VERSION
if (option_render_cairo) {

View File

@ -86,15 +86,14 @@ static bool knockout_plot_bitmap_recursive(struct knockout_box *box,
struct knockout_entry *entry);
static bool knockout_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle);
static bool knockout_plot_polygon(const int *p, unsigned int n, colour fill);
static bool knockout_plot_polygon(const int *p, unsigned int n, const plot_style_t *pstyle);
static bool knockout_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *plot_style);
static bool knockout_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1);
static bool knockout_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c);
static bool knockout_plot_disc(int x, int y, int radius, colour colour, bool filled);
static bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2,
colour c);
static bool knockout_plot_disc(int x, int y, int radius, const plot_style_t *pstyle);
static bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *pstyle);
static bool knockout_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags);
@ -171,7 +170,7 @@ struct knockout_entry {
struct {
int *p;
unsigned int n;
colour fill;
plot_style_t plot_style;
} polygon;
struct {
int x0;
@ -199,8 +198,7 @@ struct knockout_entry {
int x;
int y;
int radius;
colour colour;
bool filled;
plot_style_t plot_style;
} disc;
struct {
int x;
@ -208,7 +206,7 @@ struct knockout_entry {
int radius;
int angle1;
int angle2;
colour c;
plot_style_t plot_style;
} arc;
struct {
int x;
@ -326,7 +324,7 @@ bool knockout_plot_flush(void)
success &= plot.polygon(
knockout_entries[i].data.polygon.p,
knockout_entries[i].data.polygon.n,
knockout_entries[i].data.polygon.fill);
&knockout_entries[i].data.polygon.plot_style);
break;
case KNOCKOUT_PLOT_FILL:
box = knockout_entries[i].box->child;
@ -363,8 +361,7 @@ bool knockout_plot_flush(void)
knockout_entries[i].data.disc.x,
knockout_entries[i].data.disc.y,
knockout_entries[i].data.disc.radius,
knockout_entries[i].data.disc.colour,
knockout_entries[i].data.disc.filled);
&knockout_entries[i].data.disc.plot_style);
break;
case KNOCKOUT_PLOT_ARC:
success &= plot.arc(
@ -373,7 +370,7 @@ bool knockout_plot_flush(void)
knockout_entries[i].data.arc.radius,
knockout_entries[i].data.arc.angle1,
knockout_entries[i].data.arc.angle2,
knockout_entries[i].data.arc.c);
&knockout_entries[i].data.arc.plot_style);
break;
case KNOCKOUT_PLOT_BITMAP:
box = knockout_entries[i].box->child;
@ -676,7 +673,7 @@ bool knockout_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *psty
}
bool knockout_plot_polygon(const int *p, unsigned int n, colour fill)
bool knockout_plot_polygon(const int *p, unsigned int n, const plot_style_t *pstyle)
{
bool success = true;
int *dest;
@ -684,7 +681,7 @@ bool knockout_plot_polygon(const int *p, unsigned int n, colour fill)
/* ensure we have sufficient room even when flushed */
if (n * 2 >= KNOCKOUT_POLYGONS) {
knockout_plot_flush();
success = real_plot.polygon(p, n, fill);
success = real_plot.polygon(p, n, pstyle);
return success;
}
@ -698,7 +695,7 @@ bool knockout_plot_polygon(const int *p, unsigned int n, colour fill)
knockout_polygon_cur += n * 2;
knockout_entries[knockout_entry_cur].data.polygon.p = dest;
knockout_entries[knockout_entry_cur].data.polygon.n = n;
knockout_entries[knockout_entry_cur].data.polygon.fill = fill;
knockout_entries[knockout_entry_cur].data.polygon.plot_style = *pstyle;
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_POLYGON;
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
knockout_plot_flush();
@ -757,27 +754,26 @@ bool knockout_plot_text(int x, int y, const struct css_style *style,
}
bool knockout_plot_disc(int x, int y, int radius, colour colour, bool filled)
bool knockout_plot_disc(int x, int y, int radius, const plot_style_t *pstyle)
{
knockout_entries[knockout_entry_cur].data.disc.x = x;
knockout_entries[knockout_entry_cur].data.disc.y = y;
knockout_entries[knockout_entry_cur].data.disc.radius = radius;
knockout_entries[knockout_entry_cur].data.disc.colour = colour;
knockout_entries[knockout_entry_cur].data.disc.filled = filled;
knockout_entries[knockout_entry_cur].data.disc.plot_style = *pstyle;
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_DISC;
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
knockout_plot_flush();
return true;
}
bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c)
bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *pstyle)
{
knockout_entries[knockout_entry_cur].data.arc.x = x;
knockout_entries[knockout_entry_cur].data.arc.y = y;
knockout_entries[knockout_entry_cur].data.arc.radius = radius;
knockout_entries[knockout_entry_cur].data.arc.angle1 = angle1;
knockout_entries[knockout_entry_cur].data.arc.angle2 = angle2;
knockout_entries[knockout_entry_cur].data.arc.c = c;
knockout_entries[knockout_entry_cur].data.arc.plot_style = *pstyle;
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_ARC;
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
knockout_plot_flush();

View File

@ -73,13 +73,27 @@ plot_style_t *plot_style_caret = &plot_style_caret_static;
/* html redraw widget styles */
/** plot style for widget base. */
/** plot style for filled widget base colour. */
static plot_style_t plot_style_fill_wbasec_static = {
.fill_type = PLOT_OP_TYPE_SOLID,
.fill_colour = WIDGET_BASEC,
};
plot_style_t *plot_style_fill_wbasec = &plot_style_fill_wbasec_static;
/** plot style for dark filled widget base colour . */
static plot_style_t plot_style_fill_darkwbasec_static = {
.fill_type = PLOT_OP_TYPE_SOLID,
.fill_colour = double_darken_colour(WIDGET_BASEC),
};
plot_style_t *plot_style_fill_darkwbasec = &plot_style_fill_darkwbasec_static;
/** plot style for light filled widget base colour. */
static plot_style_t plot_style_fill_lightwbasec_static = {
.fill_type = PLOT_OP_TYPE_SOLID,
.fill_colour = double_lighten_colour(WIDGET_BASEC),
};
plot_style_t *plot_style_fill_lightwbasec = &plot_style_fill_lightwbasec_static;
/** plot style for widget background. */
static plot_style_t plot_style_fill_wblobc_static = {

View File

@ -91,6 +91,8 @@ extern plot_style_t *plot_style_stroke_yellow;
extern plot_style_t *plot_style_caret;
extern plot_style_t *plot_style_stroke_history;
extern plot_style_t *plot_style_fill_wbasec;
extern plot_style_t *plot_style_fill_darkwbasec;
extern plot_style_t *plot_style_fill_lightwbasec;
extern plot_style_t *plot_style_fill_wblobc;
extern plot_style_t *plot_style_stroke_wblobc;
extern plot_style_t *plot_style_stroke_darkwbasec;

View File

@ -95,22 +95,35 @@ typedef unsigned long bitmap_flags_t;
* 3 | | | | | |
*/
struct plotter_table {
bool (*rectangle)(int x0, int y0, int x1, int y1, const plot_style_t *pstyle);
bool (*line)(int x0, int y0, int x1, int y1, const plot_style_t *pstyle);
bool (*polygon)(const int *p, unsigned int n, colour fill);
/* clipping operations */
bool (*clip)(int x0, int y0, int x1, int y1);
bool (*text)(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c);
bool (*disc)(int x, int y, int radius, colour c, bool filled);
bool (*arc)(int x, int y, int radius, int angle1, int angle2, colour c);
/* shape primatives */
bool (*arc)(int x, int y, int radius, int angle1, int angle2, const plot_style_t *pstyle);
bool (*disc)(int x, int y, int radius, const plot_style_t *pstyle);
bool (*line)(int x0, int y0, int x1, int y1, const plot_style_t *pstyle);
bool (*rectangle)(int x0, int y0, int x1, int y1, const plot_style_t *pstyle);
bool (*polygon)(const int *p, unsigned int n, const plot_style_t *pstyle);
/* complex path (for SVG) */
bool (*path)(const float *p, unsigned int n, colour fill, float width,
colour c, const float transform[6]);
/* Image */
bool (*bitmap)(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags);
/* text */
bool (*text)(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c);
/* optional callbacks */
bool (*group_start)(const char *name); /**< optional, may be NULL */
bool (*group_end)(void); /**< optional, may be NULL */
bool (*flush)(void); /**< optional, may be NULL */
bool (*path)(const float *p, unsigned int n, colour fill, float width,
colour c, const float transform[6]);
/* flags */
bool option_knockout; /**< set if knockout rendering is required */
};

View File

@ -47,14 +47,14 @@
static bool pdf_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool pdf_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle);
static bool pdf_plot_polygon(const int *p, unsigned int n, colour fill);
static bool pdf_plot_polygon(const int *p, unsigned int n, const plot_style_t *style);
static bool pdf_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1);
static bool pdf_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c);
static bool pdf_plot_disc(int x, int y, int radius, colour c, bool filled);
static bool pdf_plot_disc(int x, int y, int radius, const plot_style_t *style);
static bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2,
colour c);
const plot_style_t *style);
static bool pdf_plot_bitmap_tile(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags);
@ -231,7 +231,7 @@ bool pdf_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle)
return true;
}
bool pdf_plot_polygon(const int *p, unsigned int n, colour fill)
bool pdf_plot_polygon(const int *p, unsigned int n, const plot_style_t *style)
{
unsigned int i;
#ifdef PDF_DEBUG
@ -242,7 +242,7 @@ bool pdf_plot_polygon(const int *p, unsigned int n, colour fill)
if (n == 0)
return true;
apply_clip_and_mode(false, fill, TRANSPARENT, 0., DashPattern_eNone);
apply_clip_and_mode(false, style->fill_colour, TRANSPARENT, 0., DashPattern_eNone);
HPDF_Page_MoveTo(pdf_page, p[0], page_height - p[1]);
for (i = 1 ; i<n ; i++) {
@ -318,35 +318,45 @@ bool pdf_plot_text(int x, int y, const struct css_style *style,
return true;
}
bool pdf_plot_disc(int x, int y, int radius, colour c, bool filled)
bool pdf_plot_disc(int x, int y, int radius, const plot_style_t *style)
{
#ifdef PDF_DEBUG
LOG(("."));
#endif
if (style->fill_type != PLOT_OP_TYPE_NONE) {
apply_clip_and_mode(false,
style->fill_colour,
TRANSPARENT,
1., DashPattern_eNone);
/* FIXME: line width 1 is ok ? */
apply_clip_and_mode(false,
filled ? c : TRANSPARENT, filled ? TRANSPARENT : c,
1., DashPattern_eNone);
HPDF_Page_Circle(pdf_page, x, page_height - y, radius);
HPDF_Page_Circle(pdf_page, x, page_height - y, radius);
if (filled)
HPDF_Page_Fill(pdf_page);
else
}
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
/* FIXME: line width 1 is ok ? */
apply_clip_and_mode(false,
TRANSPARENT,
style->stroke_colour,
1., DashPattern_eNone);
HPDF_Page_Circle(pdf_page, x, page_height - y, radius);
HPDF_Page_Stroke(pdf_page);
}
return true;
}
bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c)
bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style)
{
#ifdef PDF_DEBUG
LOG(("%d %d %d %d %d %X", x, y, radius, angle1, angle2, c));
#endif
/* FIXME: line width 1 is ok ? */
apply_clip_and_mode(false, TRANSPARENT, c, 1., DashPattern_eNone);
apply_clip_and_mode(false, TRANSPARENT, style->fill_colour, 1., DashPattern_eNone);
/* Normalize angles */
angle1 %= 360;

View File

@ -44,6 +44,37 @@ static nsfb_t *nsfb;
#ifdef FB_USE_FREETYPE
static bool
framebuffer_plot_disc(int x, int y, int radius, const plot_style_t *style)
{
nsfb_bbox_t ellipse;
ellipse.x0 = x - radius;
ellipse.y0 = y - radius;
ellipse.x1 = x + radius;
ellipse.y1 = y + radius;
if (style->fill_type != PLOT_OP_TYPE_NONE) {
nsfb_plot_ellipse_fill(nsfb, &ellipse, style->fill_colour);
}
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
nsfb_plot_ellipse(nsfb, &ellipse, style->stroke_colour);
}
return true;
}
static bool
framebuffer_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style)
{
return nsfb_plot_arc(nsfb, x, y, radius, angle1, angle2, style->fill_colour);
}
static bool framebuffer_plot_polygon(const int *p, unsigned int n, const plot_style_t *style)
{
return nsfb_plot_polygon(nsfb, p, n, style->fill_colour);
}
static bool framebuffer_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c)
{
@ -251,11 +282,6 @@ framebuffer_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
return true;
}
static bool framebuffer_plot_flush(void)
{
LOG(("flush unimplemnted"));
return true;
}
static bool
framebuffer_plot_path(const float *p,
@ -270,16 +296,15 @@ framebuffer_plot_path(const float *p,
}
struct plotter_table plot = {
.rectangle = framebuffer_plot_rectangle,
.line = framebuffer_plot_line,
.polygon = nsfb_lplot_polygon,
.clip = nsfb_lplot_clip,
.text = framebuffer_plot_text,
.disc = nsfb_lplot_disc,
.arc = nsfb_lplot_arc,
.bitmap = framebuffer_plot_bitmap,
.flush = framebuffer_plot_flush,
.arc = framebuffer_plot_arc,
.disc = framebuffer_plot_disc,
.line = framebuffer_plot_line,
.rectangle = framebuffer_plot_rectangle,
.polygon = framebuffer_plot_polygon,
.path = framebuffer_plot_path,
.bitmap = framebuffer_plot_bitmap,
.text = framebuffer_plot_text,
.option_knockout = true,
};

View File

@ -49,86 +49,163 @@ GdkDrawable *current_drawable;
GdkGC *current_gc;
cairo_t *current_cr;
static bool nsgtk_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool nsgtk_plot_polygon(const int *p, unsigned int n, colour fill);
static bool nsgtk_plot_path(const float *p, unsigned int n, colour fill, float width,
colour c, const float transform[6]);
static bool nsgtk_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool nsgtk_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1);
static bool nsgtk_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c);
static bool nsgtk_plot_disc(int x, int y, int radius, colour c, bool filled);
static bool nsgtk_plot_arc(int x, int y, int radius, int angle1, int angle2,
colour c);
static bool nsgtk_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags);
static void nsgtk_set_solid(void); /**< Set for drawing solid lines */
static void nsgtk_set_dotted(void); /**< Set for drawing dotted lines */
static void nsgtk_set_dashed(void); /**< Set for drawing dashed lines */
static GdkRectangle cliprect;
static float nsgtk_plot_scale = 1.0;
struct plotter_table plot;
const struct plotter_table nsgtk_plotters = {
.rectangle = nsgtk_plot_rectangle,
.line = nsgtk_plot_line,
.polygon = nsgtk_plot_polygon,
.clip = nsgtk_plot_clip,
.text = nsgtk_plot_text,
.disc = nsgtk_plot_disc,
.arc = nsgtk_plot_arc,
.bitmap = nsgtk_plot_bitmap,
.path = nsgtk_plot_path,
.option_knockout = true
};
bool nsgtk_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style)
/** set plotting scale factor. */
void nsgtk_plot_set_scale(float s)
{
if (style->fill_type != PLOT_OP_TYPE_NONE) {
nsgtk_set_colour(style->fill_colour);
nsgtk_set_solid();
nsgtk_plot_scale = s;
}
cairo_set_line_width(current_cr, 0);
cairo_rectangle(current_cr, x0, y0, x1 - x0, y1 - y0);
cairo_fill(current_cr);
cairo_stroke(current_cr);
}
/** get plotting scale factor. */
float nsgtk_plot_get_scale(void)
{
return nsgtk_plot_scale;
}
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
nsgtk_set_colour(style->stroke_colour);
/** Set cairo context colour to nsgtk colour. */
void nsgtk_set_colour(colour c)
{
int r, g, b;
GdkColor colour;
switch (style->stroke_type) {
case PLOT_OP_TYPE_SOLID: /**< Solid colour */
default:
nsgtk_set_solid();
break;
r = c & 0xff;
g = (c & 0xff00) >> 8;
b = (c & 0xff0000) >> 16;
case PLOT_OP_TYPE_DOT: /**< Doted plot */
nsgtk_set_dotted();
break;
colour.red = r | (r << 8);
colour.green = g | (g << 8);
colour.blue = b | (b << 8);
colour.pixel = (r << 16) | (g << 8) | b;
case PLOT_OP_TYPE_DASH: /**< dashed plot */
nsgtk_set_dashed();
break;
}
gdk_color_alloc(gdk_colormap_get_system(),
&colour);
gdk_gc_set_foreground(current_gc, &colour);
if (style->stroke_width == 0)
cairo_set_line_width(current_cr, 1);
else
cairo_set_line_width(current_cr, style->stroke_width);
cairo_set_source_rgba(current_cr, r / 255.0,
g / 255.0, b / 255.0, 1.0);
}
/** Plot a caret.
*
* @note It is assumed that the plotters have been set up.
*/
void nsgtk_plot_caret(int x, int y, int h)
{
GdkColor colour;
colour.red = 0;
colour.green = 0;
colour.blue = 0;
colour.pixel = 0;
gdk_color_alloc(gdk_colormap_get_system(),
&colour);
gdk_gc_set_foreground(current_gc, &colour);
gdk_draw_line(current_drawable, current_gc,
x, y,
x, y + h - 1);
}
/** Set cairo context to solid plot operation. */
static inline void nsgtk_set_solid(void)
{
double dashes = 0;
cairo_set_dash(current_cr, &dashes, 0, 0);
}
/** Set cairo context to dotted plot operation. */
static inline void nsgtk_set_dotted(void)
{
double cdashes[] = { 1.0, 2.0 };
cairo_set_dash(current_cr, cdashes, 2, 0);
}
/** Set cairo context to dashed plot operation. */
static inline void nsgtk_set_dashed(void)
{
double cdashes[] = { 8.0, 2.0 };
cairo_set_dash(current_cr, cdashes, 2, 0);
}
/** Set clipping area for subsequent plot operations. */
static bool nsgtk_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1)
{
cairo_reset_clip(current_cr);
cairo_rectangle(current_cr, clip_x0, clip_y0,
clip_x1 - clip_x0, clip_y1 - clip_y0);
cairo_clip(current_cr);
cliprect.x = clip_x0;
cliprect.y = clip_y0;
cliprect.width = clip_x1 - clip_x0;
cliprect.height = clip_y1 - clip_y0;
gdk_gc_set_clip_rectangle(current_gc, &cliprect);
cairo_rectangle(current_cr, x0 + 0.5, y0 + 0.5, x1 - x0, y1 - y0);
cairo_stroke(current_cr);
}
return true;
}
bool nsgtk_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
static bool nsgtk_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style)
{
nsgtk_set_colour(style->fill_colour);
nsgtk_set_solid();
cairo_set_line_width(current_cr, 1);
cairo_arc(current_cr, x, y, radius,
(angle1 + 90) * (M_PI / 180),
(angle2 + 90) * (M_PI / 180));
cairo_stroke(current_cr);
return true;
}
static bool nsgtk_plot_disc(int x, int y, int radius, const plot_style_t *style)
{
if (style->fill_type != PLOT_OP_TYPE_NONE) {
nsgtk_set_colour(style->fill_colour);
nsgtk_set_solid();
cairo_set_line_width(current_cr, 0);
cairo_arc(current_cr, x, y, radius, 0, M_PI * 2);
cairo_fill(current_cr);
cairo_stroke(current_cr);
}
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
nsgtk_set_colour(style->stroke_colour);
switch (style->stroke_type) {
case PLOT_OP_TYPE_SOLID: /**< Solid colour */
default:
nsgtk_set_solid();
break;
case PLOT_OP_TYPE_DOT: /**< Doted plot */
nsgtk_set_dotted();
break;
case PLOT_OP_TYPE_DASH: /**< dashed plot */
nsgtk_set_dashed();
break;
}
if (style->stroke_width == 0)
cairo_set_line_width(current_cr, 1);
else
cairo_set_line_width(current_cr, style->stroke_width);
cairo_arc(current_cr, x, y, radius, 0, M_PI * 2);
cairo_stroke(current_cr);
}
return true;
}
static bool nsgtk_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
{
nsgtk_set_colour(style->stroke_colour);
@ -148,7 +225,11 @@ bool nsgtk_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
break;
}
if (style->stroke_width == 0)
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
nsgtk_set_colour(style->stroke_colour);
}
if (style->stroke_width == 0)
cairo_set_line_width(current_cr, 1);
else
cairo_set_line_width(current_cr, style->stroke_width);
@ -161,11 +242,52 @@ bool nsgtk_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
}
bool nsgtk_plot_polygon(const int *p, unsigned int n, colour fill)
static bool nsgtk_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style)
{
if (style->fill_type != PLOT_OP_TYPE_NONE) {
nsgtk_set_colour(style->fill_colour);
nsgtk_set_solid();
cairo_set_line_width(current_cr, 0);
cairo_rectangle(current_cr, x0, y0, x1 - x0, y1 - y0);
cairo_fill(current_cr);
cairo_stroke(current_cr);
}
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
nsgtk_set_colour(style->stroke_colour);
switch (style->stroke_type) {
case PLOT_OP_TYPE_SOLID: /**< Solid colour */
default:
nsgtk_set_solid();
break;
case PLOT_OP_TYPE_DOT: /**< Doted plot */
nsgtk_set_dotted();
break;
case PLOT_OP_TYPE_DASH: /**< dashed plot */
nsgtk_set_dashed();
break;
}
if (style->stroke_width == 0)
cairo_set_line_width(current_cr, 1);
else
cairo_set_line_width(current_cr, style->stroke_width);
cairo_rectangle(current_cr, x0 + 0.5, y0 + 0.5, x1 - x0, y1 - y0);
cairo_stroke(current_cr);
}
return true;
}
static bool nsgtk_plot_polygon(const int *p, unsigned int n, const plot_style_t *style)
{
unsigned int i;
nsgtk_set_colour(fill);
nsgtk_set_colour(style->fill_colour);
nsgtk_set_solid();
cairo_set_line_width(current_cr, 0);
@ -180,67 +302,18 @@ bool nsgtk_plot_polygon(const int *p, unsigned int n, colour fill)
}
bool nsgtk_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1)
{
cairo_reset_clip(current_cr);
cairo_rectangle(current_cr, clip_x0, clip_y0,
clip_x1 - clip_x0, clip_y1 - clip_y0);
cairo_clip(current_cr);
cliprect.x = clip_x0;
cliprect.y = clip_y0;
cliprect.width = clip_x1 - clip_x0;
cliprect.height = clip_y1 - clip_y0;
gdk_gc_set_clip_rectangle(current_gc, &cliprect);
return true;
}
bool nsgtk_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c)
static bool nsgtk_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c)
{
return nsfont_paint(style, text, length, x, y, c);
}
bool nsgtk_plot_disc(int x, int y, int radius, colour c, bool filled)
{
nsgtk_set_colour(c);
nsgtk_set_solid();
if (filled)
cairo_set_line_width(current_cr, 0);
else
cairo_set_line_width(current_cr, 1);
cairo_arc(current_cr, x, y, radius, 0, M_PI * 2);
if (filled)
cairo_fill(current_cr);
cairo_stroke(current_cr);
return true;
}
bool nsgtk_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c)
{
nsgtk_set_colour(c);
nsgtk_set_solid();
cairo_set_line_width(current_cr, 1);
cairo_arc(current_cr, x, y, radius,
(angle1 + 90) * (M_PI / 180),
(angle2 + 90) * (M_PI / 180));
cairo_stroke(current_cr);
return true;
}
static bool nsgtk_plot_pixbuf(int x, int y, int width, int height,
GdkPixbuf *pixbuf, colour bg)
GdkPixbuf *pixbuf, colour bg)
{
/* XXX: This currently ignores the background colour supplied.
* Does this matter?
@ -250,7 +323,7 @@ static bool nsgtk_plot_pixbuf(int x, int y, int width, int height,
return true;
if (gdk_pixbuf_get_width(pixbuf) == width &&
gdk_pixbuf_get_height(pixbuf) == height) {
gdk_pixbuf_get_height(pixbuf) == height) {
gdk_draw_pixbuf(current_drawable, current_gc,
pixbuf,
0, 0,
@ -261,9 +334,9 @@ static bool nsgtk_plot_pixbuf(int x, int y, int width, int height,
} else {
GdkPixbuf *scaled;
scaled = gdk_pixbuf_scale_simple(pixbuf,
width, height,
option_render_resample ? GDK_INTERP_BILINEAR
: GDK_INTERP_NEAREST);
width, height,
option_render_resample ? GDK_INTERP_BILINEAR
: GDK_INTERP_NEAREST);
if (!scaled)
return false;
@ -280,21 +353,21 @@ static bool nsgtk_plot_pixbuf(int x, int y, int width, int height,
return true;
}
bool nsgtk_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags)
static bool nsgtk_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags)
{
int doneheight = 0, donewidth = 0;
GdkPixbuf *primary;
GdkPixbuf *pretiled = NULL;
bool repeat_x = (flags & BITMAPF_REPEAT_X);
bool repeat_y = (flags & BITMAPF_REPEAT_Y);
bool repeat_x = (flags & BITMAPF_REPEAT_X);
bool repeat_y = (flags & BITMAPF_REPEAT_Y);
if (!(repeat_x || repeat_y)) {
/* Not repeating at all, so just pass it on */
primary = gtk_bitmap_get_primary(bitmap);
return nsgtk_plot_pixbuf(x, y, width, height, primary, bg);
/* Not repeating at all, so just pass it on */
primary = gtk_bitmap_get_primary(bitmap);
return nsgtk_plot_pixbuf(x, y, width, height, primary, bg);
}
if (repeat_x && !repeat_y)
@ -303,9 +376,9 @@ bool nsgtk_plot_bitmap(int x, int y, int width, int height,
pretiled = gtk_bitmap_get_pretile_xy(bitmap);
if (!repeat_x && repeat_y)
pretiled = gtk_bitmap_get_pretile_y(bitmap);
assert(pretiled != NULL);
primary = gtk_bitmap_get_primary(bitmap);
/* use the primary and pretiled widths to scale the w/h provided */
width *= gdk_pixbuf_get_width(pretiled);
@ -325,7 +398,7 @@ bool nsgtk_plot_bitmap(int x, int y, int width, int height,
donewidth = x;
while (donewidth < (cliprect.x + cliprect.width)) {
nsgtk_plot_pixbuf(donewidth, doneheight,
width, height, pretiled, bg);
width, height, pretiled, bg);
donewidth += width;
if (!repeat_x) break;
}
@ -336,8 +409,8 @@ bool nsgtk_plot_bitmap(int x, int y, int width, int height,
return true;
}
bool nsgtk_plot_path(const float *p, unsigned int n, colour fill, float width,
colour c, const float transform[6])
static bool nsgtk_plot_path(const float *p, unsigned int n, colour fill, float width,
colour c, const float transform[6])
{
unsigned int i;
cairo_matrix_t old_ctm, n_ctm;
@ -381,8 +454,8 @@ bool nsgtk_plot_path(const float *p, unsigned int n, colour fill, float width,
i += 3;
} else if (p[i] == PLOTTER_PATH_BEZIER) {
cairo_curve_to(current_cr, p[i+1], p[i+2],
p[i+3], p[i+4],
p[i+5], p[i+6]);
p[i+3], p[i+4],
p[i+5], p[i+6]);
i += 7;
} else {
LOG(("bad path command %f", p[i]));
@ -417,74 +490,19 @@ bool nsgtk_plot_path(const float *p, unsigned int n, colour fill, float width,
return true;
}
void nsgtk_set_colour(colour c)
{
int r, g, b;
GdkColor colour;
/** GTK plotter table */
const struct plotter_table nsgtk_plotters = {
.clip = nsgtk_plot_clip,
.arc = nsgtk_plot_arc,
.disc = nsgtk_plot_disc,
.line = nsgtk_plot_line,
.rectangle = nsgtk_plot_rectangle,
.polygon = nsgtk_plot_polygon,
.path = nsgtk_plot_path,
.bitmap = nsgtk_plot_bitmap,
.text = nsgtk_plot_text,
.option_knockout = true
};
r = c & 0xff;
g = (c & 0xff00) >> 8;
b = (c & 0xff0000) >> 16;
colour.red = r | (r << 8);
colour.green = g | (g << 8);
colour.blue = b | (b << 8);
colour.pixel = (r << 16) | (g << 8) | b;
gdk_color_alloc(gdk_colormap_get_system(),
&colour);
gdk_gc_set_foreground(current_gc, &colour);
cairo_set_source_rgba(current_cr, r / 255.0,
g / 255.0, b / 255.0, 1.0);
}
void nsgtk_set_solid()
{
double dashes = 0;
cairo_set_dash(current_cr, &dashes, 0, 0);
}
void nsgtk_set_dotted()
{
double cdashes[] = { 1.0, 2.0 };
cairo_set_dash(current_cr, cdashes, 2, 0);
}
void nsgtk_set_dashed()
{
double cdashes[] = { 8.0, 2.0 };
cairo_set_dash(current_cr, cdashes, 2, 0);
}
void nsgtk_plot_set_scale(float s)
{
nsgtk_plot_scale = s;
}
float nsgtk_plot_get_scale(void)
{
return nsgtk_plot_scale;
}
/** Plot a caret. It is assumed that the plotters have been set up. */
void nsgtk_plot_caret(int x, int y, int h)
{
GdkColor colour;
colour.red = 0;
colour.green = 0;
colour.blue = 0;
colour.pixel = 0;
gdk_color_alloc(gdk_colormap_get_system(),
&colour);
gdk_gc_set_foreground(current_gc, &colour);
gdk_draw_line(current_drawable, current_gc,
x, y,
x, y + h - 1);
}

View File

@ -45,66 +45,241 @@
#include "utils/log.h"
#include "utils/utils.h"
static bool nsgtk_print_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style);
bool nsgtk_print_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool nsgtk_print_plot_polygon(const int *p, unsigned int n, colour fill);
static bool nsgtk_print_plot_path(const float *p, unsigned int n, colour fill,
float width, colour c, const float transform[6]);
static bool nsgtk_print_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1);
static bool nsgtk_print_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c);
static bool nsgtk_print_plot_disc(int x, int y, int radius, colour c,
bool filled);
static bool nsgtk_print_plot_arc(int x, int y, int radius, int angle1,
int angle2, colour c);
static bool nsgtk_print_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags);
static void nsgtk_print_set_solid(void); /**< Set for drawing solid lines */
static void nsgtk_print_set_dotted(void); /**< Set for drawing dotted lines */
static void nsgtk_print_set_dashed(void); /**< Set for drawing dashed lines */
static void nsgtk_print_set_colour(colour c);
static bool gtk_print_font_paint(const struct css_style *style,
const char *string, size_t length,
int x, int y, colour c);
static bool gtk_print_begin(struct print_settings* settings);
static bool gtk_print_next_page(void);
static void gtk_print_end(void);
/* Globals */
cairo_t *gtk_print_current_cr;
static struct print_settings* settings;
struct content *content_to_print;
static GdkRectangle cliprect;
static const struct plotter_table nsgtk_print_plotters = {
.rectangle = nsgtk_print_plot_rectangle,
.line = nsgtk_print_plot_line,
.polygon = nsgtk_print_plot_polygon,
.clip = nsgtk_print_plot_clip,
.text = nsgtk_print_plot_text,
.disc = nsgtk_print_plot_disc,
.arc = nsgtk_print_plot_arc,
.bitmap = nsgtk_print_plot_bitmap,
.path = nsgtk_print_plot_path,
.option_knockout = false,
};
static inline void nsgtk_print_set_colour(colour c)
{
int r, g, b;
GdkColor colour;
static const struct printer gtk_printer = {
&nsgtk_print_plotters,
gtk_print_begin,
gtk_print_next_page,
gtk_print_end
};
r = c & 0xff;
g = (c & 0xff00) >> 8;
b = (c & 0xff0000) >> 16;
bool nsgtk_print_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style)
colour.red = r | (r << 8);
colour.green = g | (g << 8);
colour.blue = b | (b << 8);
colour.pixel = (r << 16) | (g << 8) | b;
gdk_color_alloc(gdk_colormap_get_system(), &colour);
cairo_set_source_rgba(gtk_print_current_cr, r / 255.0,
g / 255.0, b / 255.0, 1.0);
}
static bool nsgtk_print_plot_pixbuf(int x, int y, int width, int height,
GdkPixbuf *pixbuf, colour bg)
{
/* XXX: This currently ignores the background colour supplied.
* Does this matter?
*/
if (width == 0 || height == 0)
return true;
if (gdk_pixbuf_get_width(pixbuf) == width &&
gdk_pixbuf_get_height(pixbuf) == height) {
gdk_cairo_set_source_pixbuf(gtk_print_current_cr, pixbuf, x, y);
cairo_paint(gtk_print_current_cr);
} else {
GdkPixbuf *scaled;
scaled = gdk_pixbuf_scale_simple(pixbuf,
width, height,
/* plotting for the printer doesn't have
* to be fast so we can use always the
* interp_style that gives better quality
*/
GDK_INTERP_BILINEAR);
if (!scaled)
return false;
gdk_cairo_set_source_pixbuf(gtk_print_current_cr, scaled, x, y);
cairo_paint(gtk_print_current_cr);
g_object_unref(scaled);
}
return true;
}
static bool gtk_print_font_paint(const struct css_style *style,
const char *string, size_t length,
int x, int y, colour c)
{
PangoFontDescription *desc;
PangoLayout *layout;
gint size;
PangoLayoutLine *line;
if (length == 0)
return true;
desc = nsfont_style_to_description(style);
size = (gint) ((double) pango_font_description_get_size(desc) *
settings->scale);
if (pango_font_description_get_size_is_absolute(desc))
pango_font_description_set_absolute_size(desc, size);
else
pango_font_description_set_size(desc, size);
layout = pango_cairo_create_layout(gtk_print_current_cr);
pango_layout_set_font_description(layout, desc);
pango_layout_set_text(layout, string, length);
line = pango_layout_get_line(layout, 0);
cairo_move_to(gtk_print_current_cr, x, y);
nsgtk_print_set_colour(c);
pango_cairo_show_layout_line(gtk_print_current_cr, line);
g_object_unref(layout);
pango_font_description_free(desc);
return true;
}
/** Set cairo context to solid plot operation. */
static inline void nsgtk_print_set_solid(void)
{
double dashes = 0;
cairo_set_dash(gtk_print_current_cr, &dashes, 0, 0);
}
/** Set cairo context to dotted plot operation. */
static inline void nsgtk_print_set_dotted(void)
{
double cdashes[] = { 1.0, 2.0 };
cairo_set_dash(gtk_print_current_cr, cdashes, 1, 0);
}
/** Set cairo context to dashed plot operation. */
static inline void nsgtk_print_set_dashed(void)
{
double cdashes[] = { 8.0, 2.0 };
cairo_set_dash(gtk_print_current_cr, cdashes, 1, 0);
}
/** Set clipping area for subsequent plot operations. */
static bool nsgtk_print_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1)
{
LOG(("Clipping. x0: %i ;\t y0: %i ;\t x1: %i ;\t y1: %i",
clip_x0,clip_y0,clip_x1,clip_y1));
/* Normalize cllipping area - to prevent overflows.
* See comment in pdf_plot_fill. */
clip_x0 = min(max(clip_x0, 0), settings->page_width);
clip_y0 = min(max(clip_y0, 0), settings->page_height);
clip_x1 = min(max(clip_x1, 0), settings->page_width);
clip_y1 = min(max(clip_y1, 0), settings->page_height);
cairo_reset_clip(gtk_print_current_cr);
cairo_rectangle(gtk_print_current_cr, clip_x0, clip_y0,
clip_x1 - clip_x0, clip_y1 - clip_y0);
cairo_clip(gtk_print_current_cr);
cliprect.x = clip_x0;
cliprect.y = clip_y0;
cliprect.width = clip_x1 - clip_x0;
cliprect.height = clip_y1 - clip_y0;
return true;
}
static bool nsgtk_print_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style)
{
nsgtk_print_set_colour(style->fill_colour);
nsgtk_print_set_solid();
cairo_set_line_width(gtk_print_current_cr, 1);
cairo_arc(gtk_print_current_cr, x, y, radius,
(angle1 + 90) * (M_PI / 180),
(angle2 + 90) * (M_PI / 180));
cairo_stroke(gtk_print_current_cr);
return true;
}
static bool nsgtk_print_plot_disc(int x, int y, int radius, const plot_style_t *style)
{
if (style->fill_type != PLOT_OP_TYPE_NONE) {
nsgtk_print_set_colour(style->fill_colour);
nsgtk_print_set_solid();
cairo_set_line_width(gtk_print_current_cr, 0);
cairo_arc(gtk_print_current_cr, x, y, radius, 0, M_PI * 2);
cairo_fill(gtk_print_current_cr);
cairo_stroke(gtk_print_current_cr);
}
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
nsgtk_print_set_colour(style->stroke_colour);
switch (style->stroke_type) {
case PLOT_OP_TYPE_SOLID: /**< Solid colour */
default:
nsgtk_print_set_solid();
break;
case PLOT_OP_TYPE_DOT: /**< Doted plot */
nsgtk_print_set_dotted();
break;
case PLOT_OP_TYPE_DASH: /**< dashed plot */
nsgtk_print_set_dashed();
break;
}
if (style->stroke_width == 0)
cairo_set_line_width(gtk_print_current_cr, 1);
else
cairo_set_line_width(gtk_print_current_cr, style->stroke_width);
cairo_arc(gtk_print_current_cr, x, y, radius, 0, M_PI * 2);
cairo_stroke(gtk_print_current_cr);
}
return true;
}
static bool nsgtk_print_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
{
nsgtk_print_set_colour(style->stroke_colour);
switch (style->stroke_type) {
case PLOT_OP_TYPE_SOLID: /**< Solid colour */
default:
nsgtk_print_set_solid();
break;
case PLOT_OP_TYPE_DOT: /**< Doted plot */
nsgtk_print_set_dotted();
break;
case PLOT_OP_TYPE_DASH: /**< dashed plot */
nsgtk_print_set_dashed();
break;
}
if (style->stroke_width == 0)
cairo_set_line_width(gtk_print_current_cr, 1);
else
cairo_set_line_width(gtk_print_current_cr, style->stroke_width);
cairo_move_to(gtk_print_current_cr, x0 + 0.5, y0 + 0.5);
cairo_line_to(gtk_print_current_cr, x1 + 0.5, y1 + 0.5);
cairo_stroke(gtk_print_current_cr);
return true;
}
static bool nsgtk_print_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style)
{
LOG(("x0: %i ;\t y0: %i ;\t x1: %i ;\t y1: %i", x0,y0,x1,y1));
@ -156,48 +331,13 @@ bool nsgtk_print_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style
return true;
}
bool nsgtk_print_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
{
nsgtk_print_set_colour(style->stroke_colour);
switch (style->stroke_type) {
case PLOT_OP_TYPE_SOLID: /**< Solid colour */
default:
nsgtk_print_set_solid();
break;
case PLOT_OP_TYPE_DOT: /**< Doted plot */
nsgtk_print_set_dotted();
break;
case PLOT_OP_TYPE_DASH: /**< dashed plot */
nsgtk_print_set_dashed();
break;
}
if (style->stroke_width == 0)
cairo_set_line_width(gtk_print_current_cr, 1);
else
cairo_set_line_width(gtk_print_current_cr, style->stroke_width);
cairo_move_to(gtk_print_current_cr, x0 + 0.5, y0 + 0.5);
cairo_line_to(gtk_print_current_cr, x1 + 0.5, y1 + 0.5);
cairo_stroke(gtk_print_current_cr);
return true;
}
bool nsgtk_print_plot_polygon(const int *p, unsigned int n, colour fill)
static bool nsgtk_print_plot_polygon(const int *p, unsigned int n, const plot_style_t *style)
{
unsigned int i;
LOG(("Plotting polygon."));
nsgtk_print_set_colour(fill);
nsgtk_print_set_colour(style->fill_colour);
nsgtk_print_set_solid();
cairo_set_line_width(gtk_print_current_cr, 0);
@ -217,114 +357,17 @@ bool nsgtk_print_plot_polygon(const int *p, unsigned int n, colour fill)
}
bool nsgtk_print_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1)
static bool nsgtk_print_plot_path(const float *p, unsigned int n, colour fill,
float width, colour c, const float transform[6])
{
LOG(("Clipping. x0: %i ;\t y0: %i ;\t x1: %i ;\t y1: %i",
clip_x0,clip_y0,clip_x1,clip_y1));
/* Normalize cllipping area - to prevent overflows.
* See comment in pdf_plot_fill. */
clip_x0 = min(max(clip_x0, 0), settings->page_width);
clip_y0 = min(max(clip_y0, 0), settings->page_height);
clip_x1 = min(max(clip_x1, 0), settings->page_width);
clip_y1 = min(max(clip_y1, 0), settings->page_height);
cairo_reset_clip(gtk_print_current_cr);
cairo_rectangle(gtk_print_current_cr, clip_x0, clip_y0,
clip_x1 - clip_x0, clip_y1 - clip_y0);
cairo_clip(gtk_print_current_cr);
cliprect.x = clip_x0;
cliprect.y = clip_y0;
cliprect.width = clip_x1 - clip_x0;
cliprect.height = clip_y1 - clip_y0;
return true;
}
bool nsgtk_print_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c)
{
return gtk_print_font_paint(style, text, length, x, y, c);
}
bool nsgtk_print_plot_disc(int x, int y, int radius, colour c, bool filled)
{
nsgtk_print_set_colour(c);
nsgtk_print_set_solid();
if (filled)
cairo_set_line_width(gtk_print_current_cr, 0);
else
cairo_set_line_width(gtk_print_current_cr, 1);
cairo_arc(gtk_print_current_cr, x, y, radius, 0, M_PI * 2);
if (filled)
cairo_fill(gtk_print_current_cr);
cairo_stroke(gtk_print_current_cr);
/* Only the internal SVG renderer uses this plot call currently,
* and the GTK version uses librsvg. Thus, we ignore this complexity,
* and just return true obliviously. */
return true;
}
bool nsgtk_print_plot_arc(int x, int y, int radius, int angle1, int angle2,
colour c)
{
nsgtk_print_set_colour(c);
nsgtk_print_set_solid();
cairo_set_line_width(gtk_print_current_cr, 1);
cairo_arc(gtk_print_current_cr, x, y, radius,
(angle1 + 90) * (M_PI / 180),
(angle2 + 90) * (M_PI / 180));
cairo_stroke(gtk_print_current_cr);
return true;
}
static bool nsgtk_print_plot_pixbuf(int x, int y, int width, int height,
GdkPixbuf *pixbuf, colour bg)
{
/* XXX: This currently ignores the background colour supplied.
* Does this matter?
*/
if (width == 0 || height == 0)
return true;
if (gdk_pixbuf_get_width(pixbuf) == width &&
gdk_pixbuf_get_height(pixbuf) == height) {
gdk_cairo_set_source_pixbuf(gtk_print_current_cr, pixbuf, x, y);
cairo_paint(gtk_print_current_cr);
} else {
GdkPixbuf *scaled;
scaled = gdk_pixbuf_scale_simple(pixbuf,
width, height,
/* plotting for the printer doesn't have
* to be fast so we can use always the
* interp_style that gives better quality
*/
GDK_INTERP_BILINEAR);
if (!scaled)
return false;
gdk_cairo_set_source_pixbuf(gtk_print_current_cr, scaled, x, y);
cairo_paint(gtk_print_current_cr);
g_object_unref(scaled);
}
return true;
}
bool nsgtk_print_plot_bitmap(int x, int y, int width, int height,
static bool nsgtk_print_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags)
{
@ -386,107 +429,48 @@ bool nsgtk_print_plot_bitmap(int x, int y, int width, int height,
return true;
}
bool nsgtk_print_plot_path(const float *p, unsigned int n, colour fill,
float width, colour c, const float transform[6])
static bool nsgtk_print_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c)
{
/* Only the internal SVG renderer uses this plot call currently,
* and the GTK version uses librsvg. Thus, we ignore this complexity,
* and just return true obliviously. */
return true;
return gtk_print_font_paint(style, text, length, x, y, c);
}
void nsgtk_print_set_colour(colour c)
{
int r, g, b;
GdkColor colour;
/** GTK print plotter table */
static const struct plotter_table nsgtk_print_plotters = {
.clip = nsgtk_print_plot_clip,
.arc = nsgtk_print_plot_arc,
.disc = nsgtk_print_plot_disc,
.line = nsgtk_print_plot_line,
.rectangle = nsgtk_print_plot_rectangle,
.polygon = nsgtk_print_plot_polygon,
.path = nsgtk_print_plot_path,
.bitmap = nsgtk_print_plot_bitmap,
.text = nsgtk_print_plot_text,
.option_knockout = false,
};
r = c & 0xff;
g = (c & 0xff00) >> 8;
b = (c & 0xff0000) >> 16;
colour.red = r | (r << 8);
colour.green = g | (g << 8);
colour.blue = b | (b << 8);
colour.pixel = (r << 16) | (g << 8) | b;
gdk_color_alloc(gdk_colormap_get_system(), &colour);
cairo_set_source_rgba(gtk_print_current_cr, r / 255.0,
g / 255.0, b / 255.0, 1.0);
}
void nsgtk_print_set_solid(void)
{
double dashes = 0;
cairo_set_dash(gtk_print_current_cr, &dashes, 0, 0);
}
void nsgtk_print_set_dotted(void)
{
double cdashes = 1;
cairo_set_dash(gtk_print_current_cr, &cdashes, 1, 0);
}
void nsgtk_print_set_dashed(void)
{
double cdashes = 3;
cairo_set_dash(gtk_print_current_cr, &cdashes, 1, 0);
}
bool gtk_print_font_paint(const struct css_style *style,
const char *string, size_t length,
int x, int y, colour c)
{
PangoFontDescription *desc;
PangoLayout *layout;
gint size;
PangoLayoutLine *line;
if (length == 0)
return true;
desc = nsfont_style_to_description(style);
size = (gint) ((double) pango_font_description_get_size(desc) *
settings->scale);
if (pango_font_description_get_size_is_absolute(desc))
pango_font_description_set_absolute_size(desc, size);
else
pango_font_description_set_size(desc, size);
layout = pango_cairo_create_layout(gtk_print_current_cr);
pango_layout_set_font_description(layout, desc);
pango_layout_set_text(layout, string, length);
line = pango_layout_get_line(layout, 0);
cairo_move_to(gtk_print_current_cr, x, y);
nsgtk_print_set_colour(c);
pango_cairo_show_layout_line(gtk_print_current_cr, line);
g_object_unref(layout);
pango_font_description_free(desc);
return true;
}
static bool gtk_print_begin(struct print_settings* settings)
{
return true;
}
static bool gtk_print_next_page(void)
{
return true;
}
static void gtk_print_end(void)
{
}
static const struct printer gtk_printer = {
&nsgtk_print_plotters,
gtk_print_begin,
gtk_print_next_page,
gtk_print_end
};
/**
* Handle the begin_print signal from the GtkPrintOperation
*
@ -555,3 +539,4 @@ void gtk_print_signal_end_print(GtkPrintOperation *operation,
print_cleanup(content_to_print, &gtk_printer, user_data);
}

View File

@ -1074,6 +1074,24 @@ bool html_redraw_inline_borders(struct box *box, int x0, int y0, int x1, int y1,
return true;
}
static plot_style_t plot_style_bdr = {
.stroke_type = PLOT_OP_TYPE_DASH,
};
static plot_style_t plot_style_fillbdr = {
.fill_type = PLOT_OP_TYPE_SOLID,
};
static plot_style_t plot_style_fillbdr_dark = {
.fill_type = PLOT_OP_TYPE_SOLID,
};
static plot_style_t plot_style_fillbdr_light = {
.fill_type = PLOT_OP_TYPE_SOLID,
};
static plot_style_t plot_style_fillbdr_ddark = {
.fill_type = PLOT_OP_TYPE_SOLID,
};
static plot_style_t plot_style_fillbdr_dlight = {
.fill_type = PLOT_OP_TYPE_SOLID,
};
/**
* Draw one border.
@ -1091,17 +1109,21 @@ bool html_redraw_border_plot(int i, int *p, colour c,
{
int z[8];
unsigned int light = i;
colour c_plot;
plot_style_t plot_style_bdr = {
.stroke_type = PLOT_OP_TYPE_DASH,
.stroke_colour = c,
.stroke_width = thickness,
.fill_type = PLOT_OP_TYPE_NONE,
};
plot_style_t *plot_style_bdr_in;
plot_style_t *plot_style_bdr_out;
if (c == TRANSPARENT)
return true;
plot_style_bdr.stroke_type = PLOT_OP_TYPE_DASH;
plot_style_bdr.stroke_colour = c;
plot_style_bdr.stroke_width = thickness;
plot_style_fillbdr.fill_colour = c;
plot_style_fillbdr_dark.fill_colour = darken_colour(c);
plot_style_fillbdr_light.fill_colour = lighten_colour(c);
plot_style_fillbdr_ddark.fill_colour = double_darken_colour(c);
plot_style_fillbdr_dlight.fill_colour = double_lighten_colour(c);
switch (style) {
case CSS_BORDER_STYLE_DOTTED:
plot_style_bdr.stroke_type = PLOT_OP_TYPE_DOT;
@ -1117,7 +1139,7 @@ bool html_redraw_border_plot(int i, int *p, colour c,
case CSS_BORDER_STYLE_SOLID:
default:
if (!plot.polygon(p + i * 4, 4, c))
if (!plot.polygon(p + i * 4, 4, &plot_style_fillbdr))
return false;
break;
@ -1130,7 +1152,7 @@ bool html_redraw_border_plot(int i, int *p, colour c,
z[5] = (p[i * 4 + 7] * 2 + p[i * 4 + 5]) / 3;
z[6] = p[i * 4 + 6];
z[7] = p[i * 4 + 7];
if (!plot.polygon(z, 4, c))
if (!plot.polygon(z, 4, &plot_style_fillbdr))
return false;
z[0] = p[i * 4 + 2];
z[1] = p[i * 4 + 3];
@ -1140,13 +1162,20 @@ bool html_redraw_border_plot(int i, int *p, colour c,
z[5] = (p[i * 4 + 5] * 2 + p[i * 4 + 7]) / 3;
z[6] = p[i * 4 + 4];
z[7] = p[i * 4 + 5];
if (!plot.polygon(z, 4, c))
if (!plot.polygon(z, 4, &plot_style_fillbdr))
return false;
break;
case CSS_BORDER_STYLE_GROOVE:
light = 3 - light;
case CSS_BORDER_STYLE_RIDGE:
if (light <= 1) {
plot_style_bdr_in = &plot_style_fillbdr_dark;
plot_style_bdr_out = &plot_style_fillbdr_light;
} else {
plot_style_bdr_in = &plot_style_fillbdr_light;
plot_style_bdr_out = &plot_style_fillbdr_dark;
}
z[0] = p[i * 4 + 0];
z[1] = p[i * 4 + 1];
z[2] = (p[i * 4 + 0] + p[i * 4 + 2]) / 2;
@ -1155,21 +1184,42 @@ bool html_redraw_border_plot(int i, int *p, colour c,
z[5] = (p[i * 4 + 7] + p[i * 4 + 5]) / 2;
z[6] = p[i * 4 + 6];
z[7] = p[i * 4 + 7];
if (!plot.polygon(z, 4, light <= 1 ?
darken_colour(c) : lighten_colour(c)))
if (!plot.polygon(z, 4, plot_style_bdr_in))
return false;
z[0] = p[i * 4 + 2];
z[1] = p[i * 4 + 3];
z[6] = p[i * 4 + 4];
z[7] = p[i * 4 + 5];
if (!plot.polygon(z, 4, light <= 1 ?
lighten_colour(c) : darken_colour(c)))
if (!plot.polygon(z, 4, plot_style_bdr_out))
return false;
break;
case CSS_BORDER_STYLE_INSET:
light = (light + 2) % 4;
case CSS_BORDER_STYLE_OUTSET:
switch (light) {
case 0:
plot_style_bdr_in = &plot_style_fillbdr_light;
plot_style_bdr_out = &plot_style_fillbdr_dlight;
break;
case 1:
plot_style_bdr_in = &plot_style_fillbdr_ddark;
plot_style_bdr_out = &plot_style_fillbdr_dark;
break;
case 2:
plot_style_bdr_in = &plot_style_fillbdr_dark;
plot_style_bdr_out = &plot_style_fillbdr_ddark;
break;
case 3:
plot_style_bdr_in = &plot_style_fillbdr_dlight;
plot_style_bdr_out = &plot_style_fillbdr_light;
break;
default:
plot_style_bdr_in = &plot_style_fillbdr;
plot_style_bdr_out = &plot_style_fillbdr;
break;
}
z[0] = p[i * 4 + 0];
z[1] = p[i * 4 + 1];
z[2] = (p[i * 4 + 0] + p[i * 4 + 2]) / 2;
@ -1178,42 +1228,13 @@ bool html_redraw_border_plot(int i, int *p, colour c,
z[5] = (p[i * 4 + 7] + p[i * 4 + 5]) / 2;
z[6] = p[i * 4 + 6];
z[7] = p[i * 4 + 7];
c_plot = c;
switch (light) {
case 3:
c_plot = double_lighten_colour(c);
break;
case 0:
c_plot = lighten_colour(c);
break;
case 1:
c_plot = double_darken_colour(c);
break;
case 2:
c_plot = darken_colour(c);
break;
}
if (!plot.polygon(z, 4, c_plot))
if (!plot.polygon(z, 4, plot_style_bdr_in))
return false;
z[0] = p[i * 4 + 2];
z[1] = p[i * 4 + 3];
z[6] = p[i * 4 + 4];
z[7] = p[i * 4 + 5];
switch (light) {
case 0:
c_plot = double_lighten_colour(c);
break;
case 3:
c_plot = lighten_colour(c);
break;
case 2:
c_plot = double_darken_colour(c);
break;
case 1:
c_plot = darken_colour(c);
break;
}
if (!plot.polygon(z, 4, c_plot))
if (!plot.polygon(z, 4, plot_style_bdr_out))
return false;
break;
}
@ -1291,28 +1312,37 @@ bool html_redraw_checkbox(int x, int y, int width, int height,
bool html_redraw_radio(int x, int y, int width, int height,
bool selected)
{
int dark = double_darken_colour(WIDGET_BASEC);
int lite = double_lighten_colour(WIDGET_BASEC);
/* plot background of radio button */
if (!plot.disc(x + width * 0.5, y + height * 0.5,
width * 0.5 - 1, WIDGET_BASEC, true))
if (!plot.disc(x + width * 0.5,
y + height * 0.5,
width * 0.5 - 1,
plot_style_fill_wbasec))
return false;
/* plot dark arc */
if (!plot.arc(x + width * 0.5, y + height * 0.5,
width * 0.5 - 1, 45, 225, dark))
if (!plot.arc(x + width * 0.5,
y + height * 0.5,
width * 0.5 - 1,
45,
225,
plot_style_fill_darkwbasec))
return false;
/* plot light arc */
if (!plot.arc(x + width * 0.5, y + height * 0.5,
width * 0.5 - 1, 225, 45, lite))
if (!plot.arc(x + width * 0.5,
y + height * 0.5,
width * 0.5 - 1,
225,
45,
plot_style_fill_lightwbasec))
return false;
if (selected) {
/* plot selection blob */
if (!plot.disc(x + width * 0.5, y + height * 0.5,
width * 0.3 - 1, WIDGET_BLOBC, true))
if (!plot.disc(x + width * 0.5,
y + height * 0.5,
width * 0.3 - 1,
plot_style_fill_wblobc))
return false;
}
@ -1941,6 +1971,10 @@ bool html_redraw_scrollbars(struct box *box, float scale,
.fill_type = PLOT_OP_TYPE_SOLID,
.fill_colour = css_scrollbar_fg_colour,
};
plot_style_t pstyle_css_scrollbar_arrow_colour = {
.fill_type = PLOT_OP_TYPE_SOLID,
.fill_colour = css_scrollbar_arrow_colour,
};
box_scrollbar_dimensions(box, padding_width, padding_height, w,
&vscroll, &hscroll,
@ -1978,7 +2012,7 @@ bool html_redraw_scrollbars(struct box *box, float scale,
v[3] = y + padding_height - w * 3 / 4;
v[4] = x + w * 3 / 4;
v[5] = y + padding_height - w / 4;
if (!plot.polygon(v, 3, css_scrollbar_arrow_colour))
if (!plot.polygon(v, 3, &pstyle_css_scrollbar_arrow_colour))
return false;
/* scroll well background */
if (!plot.rectangle(x + w - 1,
@ -2021,7 +2055,7 @@ bool html_redraw_scrollbars(struct box *box, float scale,
v[3] = y + padding_height - w * 3 / 4;
v[4] = x + w + well_width + w / 4 + (vscroll ? 1 : 0);
v[5] = y + padding_height - w / 4;
if (!plot.polygon(v, 3, css_scrollbar_arrow_colour))
if (!plot.polygon(v, 3, &pstyle_css_scrollbar_arrow_colour))
return false;
}
@ -2056,7 +2090,7 @@ bool html_redraw_scrollbars(struct box *box, float scale,
v[3] = y + w * 3 / 4;
v[4] = x + padding_width - w / 4;
v[5] = y + w * 3 / 4;
if (!plot.polygon(v, 3, css_scrollbar_arrow_colour))
if (!plot.polygon(v, 3, &pstyle_css_scrollbar_arrow_colour))
return false;
/* scroll well background */
if (!plot.rectangle(x + padding_width - w + 1,
@ -2098,7 +2132,7 @@ bool html_redraw_scrollbars(struct box *box, float scale,
v[3] = y + w + well_height + w / 4;
v[4] = x + padding_width - w / 4;
v[5] = y + w + well_height + w / 4;
if (!plot.polygon(v, 3, css_scrollbar_arrow_colour))
if (!plot.polygon(v, 3, &pstyle_css_scrollbar_arrow_colour))
return false;
}

View File

@ -38,16 +38,16 @@ static bool ro_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t
static bool ro_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool ro_plot_draw_path(const draw_path * const path, int width,
colour c, bool dotted, bool dashed);
static bool ro_plot_polygon(const int *p, unsigned int n, colour fill);
static bool ro_plot_polygon(const int *p, unsigned int n, const plot_style_t *style);
static bool ro_plot_path(const float *p, unsigned int n, colour fill, float width,
colour c, const float transform[6]);
static bool ro_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1);
static bool ro_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c);
static bool ro_plot_disc(int x, int y, int radius, colour colour, bool filled);
static bool ro_plot_disc(int x, int y, int radius, const plot_style_t *style);
static bool ro_plot_arc(int x, int y, int radius, int angle1, int angle2,
colour c);
const plot_style_t *style);
static bool ro_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags);
@ -216,7 +216,7 @@ bool ro_plot_draw_path(const draw_path * const path, int width,
}
bool ro_plot_polygon(const int *p, unsigned int n, colour fill)
bool ro_plot_polygon(const int *p, unsigned int n, const plot_style_t *style)
{
int path[n * 3 + 2];
unsigned int i;
@ -231,7 +231,7 @@ bool ro_plot_polygon(const int *p, unsigned int n, colour fill)
path[n * 3] = draw_END_PATH;
path[n * 3 + 1] = 0;
error = xcolourtrans_set_gcol(fill << 8, 0, os_ACTION_OVERWRITE, 0, 0);
error = xcolourtrans_set_gcol(style->fill_colour << 8, 0, os_ACTION_OVERWRITE, 0, 0);
if (error) {
LOG(("xcolourtrans_set_gcol: 0x%x: %s",
error->errnum, error->errmess));
@ -414,39 +414,59 @@ bool ro_plot_text(int x, int y, const struct css_style *style,
}
bool ro_plot_disc(int x, int y, int radius, colour colour, bool filled)
bool ro_plot_disc(int x, int y, int radius, const plot_style_t *style)
{
os_error *error;
error = xcolourtrans_set_gcol(colour << 8, 0,
os_ACTION_OVERWRITE, 0, 0);
if (error) {
LOG(("xcolourtrans_set_gcol: 0x%x: %s",
error->errnum, error->errmess));
return false;
}
error = xos_plot(os_MOVE_TO,
ro_plot_origin_x + x * 2,
ro_plot_origin_y - y * 2);
if (error) {
LOG(("xos_plot: 0x%x: %s", error->errnum, error->errmess));
return false;
}
if (filled) {
error = xos_plot(os_PLOT_CIRCLE | os_PLOT_BY, radius * 2, 0);
} else {
error = xos_plot(os_PLOT_CIRCLE_OUTLINE | os_PLOT_BY,
radius * 2, 0);
if (style->fill_type != PLOT_OP_TYPE_NONE) {
error = xcolourtrans_set_gcol(style->fill_colour << 8, 0,
os_ACTION_OVERWRITE, 0, 0);
if (error) {
LOG(("xcolourtrans_set_gcol: 0x%x: %s",
error->errnum, error->errmess));
return false;
}
error = xos_plot(os_MOVE_TO,
ro_plot_origin_x + x * 2,
ro_plot_origin_y - y * 2);
if (error) {
LOG(("xos_plot: 0x%x: %s", error->errnum, error->errmess));
return false;
}
error = xos_plot(os_PLOT_CIRCLE | os_PLOT_BY, radius * 2, 0);
if (error) {
LOG(("xos_plot: 0x%x: %s", error->errnum, error->errmess));
return false;
}
}
if (error) {
LOG(("xos_plot: 0x%x: %s", error->errnum, error->errmess));
return false;
}
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
error = xcolourtrans_set_gcol(style->stroke_colour << 8, 0,
os_ACTION_OVERWRITE, 0, 0);
if (error) {
LOG(("xcolourtrans_set_gcol: 0x%x: %s",
error->errnum, error->errmess));
return false;
}
error = xos_plot(os_MOVE_TO,
ro_plot_origin_x + x * 2,
ro_plot_origin_y - y * 2);
if (error) {
LOG(("xos_plot: 0x%x: %s", error->errnum, error->errmess));
return false;
}
error = xos_plot(os_PLOT_CIRCLE_OUTLINE | os_PLOT_BY,
radius * 2, 0);
if (error) {
LOG(("xos_plot: 0x%x: %s", error->errnum, error->errmess));
return false;
}
}
return true;
}
bool ro_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c)
bool ro_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style)
{
os_error *error;
int sx, sy, ex, ey;
@ -456,7 +476,7 @@ bool ro_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c)
y = ro_plot_origin_y - y * 2;
radius <<= 1;
error = xcolourtrans_set_gcol(c << 8, 0,
error = xcolourtrans_set_gcol(style->fill_colour << 8, 0,
os_ACTION_OVERWRITE, 0, 0);
if (error) {

View File

@ -99,15 +99,13 @@ static bool print_document(struct gui_window *g, const char *filename);
static const char *print_declare_fonts(struct content *content);
static bool print_fonts_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool print_fonts_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool print_fonts_plot_polygon(const int *p, unsigned int n, colour fill);
static bool print_fonts_plot_polygon(const int *p, unsigned int n, const plot_style_t *style);
static bool print_fonts_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1);
static bool print_fonts_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c);
static bool print_fonts_plot_disc(int x, int y, int radius, colour c,
bool filled);
static bool print_fonts_plot_arc(int x, int y, int radius, int angle1, int angle2,
colour c);
static bool print_fonts_plot_disc(int x, int y, int radius, const plot_style_t *style);
static bool print_fonts_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style);
static bool print_fonts_plot_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags);
@ -814,7 +812,7 @@ bool print_fonts_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *s
return true;
}
bool print_fonts_plot_polygon(const int *p, unsigned int n, colour fill)
bool print_fonts_plot_polygon(const int *p, unsigned int n, const plot_style_t *style)
{
return true;
}
@ -826,14 +824,13 @@ bool print_fonts_plot_clip(int clip_x0, int clip_y0,
return true;
}
bool print_fonts_plot_disc(int x, int y, int radius, colour colour,
bool filled)
bool print_fonts_plot_disc(int x, int y, int radius, const plot_style_t *style)
{
return true;
}
bool print_fonts_plot_arc(int x, int y, int radius, int angle1, int angle2,
colour c)
const plot_style_t *style)
{
return true;
}

View File

@ -39,17 +39,16 @@
static bool ro_save_draw_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool ro_save_draw_line(int x0, int y0, int x1, int y1, const plot_style_t *style);
static bool ro_save_draw_polygon(const int *p, unsigned int n, colour fill);
static bool ro_save_draw_polygon(const int *p, unsigned int n, const plot_style_t *style);
static bool ro_save_draw_path(const float *p, unsigned int n, colour fill,
float width, colour c, const float transform[6]);
static bool ro_save_draw_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1);
static bool ro_save_draw_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c);
static bool ro_save_draw_disc(int x, int y, int radius, colour colour,
bool filled);
static bool ro_save_draw_disc(int x, int y, int radius, const plot_style_t *style);
static bool ro_save_draw_arc(int x, int y, int radius, int angle1, int angle2,
colour c);
const plot_style_t *style);
static bool ro_save_draw_bitmap(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg, bitmap_flags_t flags);
static bool ro_save_draw_group_start(const char *name);
@ -216,7 +215,7 @@ bool ro_save_draw_line(int x0, int y0, int x1, int y1, const plot_style_t *style
}
bool ro_save_draw_polygon(const int *p, unsigned int n, colour fill)
bool ro_save_draw_polygon(const int *p, unsigned int n, const plot_style_t *style)
{
pencil_code code;
int path[n * 3 + 1];
@ -230,10 +229,18 @@ bool ro_save_draw_polygon(const int *p, unsigned int n, colour fill)
path[0] = draw_MOVE_TO;
path[n * 3] = draw_END_PATH;
code = pencil_path(ro_save_draw_diagram, path, n * 3 + 1,
fill << 8, pencil_TRANSPARENT, 0, pencil_JOIN_MITRED,
pencil_CAP_BUTT, pencil_CAP_BUTT, 0, 0, false,
pencil_SOLID);
code = pencil_path(ro_save_draw_diagram,
path, n * 3 + 1,
style->fill_colour << 8,
pencil_TRANSPARENT,
0,
pencil_JOIN_MITRED,
pencil_CAP_BUTT,
pencil_CAP_BUTT,
0,
0,
false,
pencil_SOLID);
if (code != pencil_OK)
return ro_save_draw_error(code);
@ -360,13 +367,13 @@ bool ro_save_draw_text(int x, int y, const struct css_style *style,
}
bool ro_save_draw_disc(int x, int y, int radius, colour colour, bool filled)
bool ro_save_draw_disc(int x, int y, int radius, const plot_style_t *style)
{
return true;
}
bool ro_save_draw_arc(int x, int y, int radius, int angle1, int angle2,
colour c)
const plot_style_t *style)
{
return true;
}