From f9ecd56f62f833f21b3475f0d1b59bc8e053a03e Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 8 Jul 2009 22:04:40 +0000 Subject: ploter refactor of rectangle handling svn path=/trunk/netsurf/; revision=8399 --- gtk/gtk_plotters.c | 70 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 34 deletions(-) (limited to 'gtk/gtk_plotters.c') diff --git a/gtk/gtk_plotters.c b/gtk/gtk_plotters.c index 6c7306b11..2a843c5b8 100644 --- a/gtk/gtk_plotters.c +++ b/gtk/gtk_plotters.c @@ -49,14 +49,12 @@ GdkDrawable *current_drawable; GdkGC *current_gc; cairo_t *current_cr; -static bool nsgtk_plot_rectangle(int x0, int y0, int width, int height, - int line_width, colour c, bool dotted, bool dashed); static bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width, colour c, bool dotted, bool dashed); 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_fill(int x0, int y0, int x1, int y1, plot_style_t *style); +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, @@ -80,7 +78,6 @@ const struct plotter_table nsgtk_plotters = { .rectangle = nsgtk_plot_rectangle, .line = nsgtk_plot_line, .polygon = nsgtk_plot_polygon, - .fill = nsgtk_plot_fill, .clip = nsgtk_plot_clip, .text = nsgtk_plot_text, .disc = nsgtk_plot_disc, @@ -91,28 +88,47 @@ const struct plotter_table nsgtk_plotters = { }; -bool nsgtk_plot_rectangle(int x0, int y0, int width, int height, - int line_width, colour c, bool dotted, bool dashed) +bool nsgtk_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) { - nsgtk_set_colour(c); - if (dotted) - nsgtk_set_dotted(); - else if (dashed) - nsgtk_set_dashed(); - else + if (style->fill_type != PLOT_OP_TYPE_NONE) { + nsgtk_set_colour(style->fill_colour); nsgtk_set_solid(); - if (line_width == 0) - line_width = 1; - - cairo_set_line_width(current_cr, line_width); - cairo_rectangle(current_cr, x0 + 0.5, y0 + 0.5, width, height); - cairo_stroke(current_cr); - + 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; } - bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width, colour c, bool dotted, bool dashed) { @@ -155,20 +171,6 @@ bool nsgtk_plot_polygon(const int *p, unsigned int n, colour fill) } -bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, plot_style_t *style) -{ - 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); - - return true; -} - - bool nsgtk_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1) { -- cgit v1.2.3