From 66493421e65d8cbda3e17fdbe43824387e3d51a7 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 23 May 2018 13:04:19 +0100 Subject: Plotters: Change stroke width in the plot_style_t to fixed point. --- content/handlers/html/html_redraw_border.c | 2 +- content/handlers/image/svg.c | 11 ++++++----- desktop/local_history.c | 6 +++--- desktop/plot_style.c | 10 +++++----- desktop/save_pdf.c | 16 ++++++++-------- desktop/scrollbar.c | 6 +++--- desktop/textarea.c | 6 +++--- frontends/amiga/dt_sound.c | 2 +- frontends/amiga/plotters.c | 8 ++++---- frontends/amiga/plugin_hack.c | 2 +- frontends/atari/plot/plot.c | 6 +++--- frontends/beos/plotters.cpp | 4 ++-- frontends/framebuffer/framebuffer.c | 6 ++++-- frontends/gtk/plotters.c | 29 +++++++++++++++++------------ frontends/gtk/print.c | 30 ++++++++++++++---------------- frontends/riscos/plotters.c | 14 +++++++------- frontends/riscos/save_draw.c | 4 ++-- frontends/windows/plot.c | 8 ++++++-- include/netsurf/plot_style.h | 15 ++++++++++++++- 19 files changed, 104 insertions(+), 81 deletions(-) diff --git a/content/handlers/html/html_redraw_border.c b/content/handlers/html/html_redraw_border.c index 2a849e853..0b3d858e6 100644 --- a/content/handlers/html/html_redraw_border.c +++ b/content/handlers/html/html_redraw_border.c @@ -111,7 +111,7 @@ html_redraw_border_plot(const int side, plot_style_bdr.stroke_type = PLOT_OP_TYPE_DASH; plot_style_bdr.stroke_colour = c; - plot_style_bdr.stroke_width = thickness; + plot_style_bdr.stroke_width = (thickness << PLOT_STYLE_RADIX); plot_style_fillbdr.fill_colour = c; plot_style_fillbdr_dark.fill_colour = darken_colour(c); plot_style_fillbdr_light.fill_colour = lighten_colour(c); diff --git a/content/handlers/image/svg.c b/content/handlers/image/svg.c index 924c84879..766bb104c 100644 --- a/content/handlers/image/svg.c +++ b/content/handlers/image/svg.c @@ -191,11 +191,12 @@ svg_redraw_internal(struct content *c, pstyle.stroke_colour = BGR(diagram->shape[i].stroke); pstyle.fill_colour = BGR(diagram->shape[i].fill); res = ctx->plot->path(ctx, - &pstyle, - diagram->shape[i].path, - diagram->shape[i].path_length, - diagram->shape[i].stroke_width, - transform); + &pstyle, + diagram->shape[i].path, + diagram->shape[i].path_length, + plot_style_int_to_fixed( + diagram->shape[i].stroke_width), + transform); if (res != NSERROR_OK) { return false; } diff --git a/desktop/local_history.c b/desktop/local_history.c index dc5bac99a..75da4aff1 100644 --- a/desktop/local_history.c +++ b/desktop/local_history.c @@ -55,7 +55,7 @@ struct local_history_session { */ static plot_style_t pstyle_line = { .stroke_type = PLOT_OP_TYPE_SOLID, - .stroke_width = 2, + .stroke_width = plot_style_int_to_fixed(2), }; @@ -72,7 +72,7 @@ static plot_style_t pstyle_bg = { */ static plot_style_t pstyle_rect = { .stroke_type = PLOT_OP_TYPE_SOLID, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; @@ -81,7 +81,7 @@ static plot_style_t pstyle_rect = { */ static plot_style_t pstyle_rect_sel = { .stroke_type = PLOT_OP_TYPE_SOLID, - .stroke_width = 3, + .stroke_width = plot_style_int_to_fixed(3), }; diff --git a/desktop/plot_style.c b/desktop/plot_style.c index c3a41398d..05954144a 100644 --- a/desktop/plot_style.c +++ b/desktop/plot_style.c @@ -47,7 +47,7 @@ plot_style_t *plot_style_fill_red = &plot_style_fill_red_static; static const plot_style_t plot_style_content_edge_static = { .stroke_type = PLOT_OP_TYPE_SOLID, .stroke_colour = 0x00ff0000, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; plot_style_t const * const plot_style_content_edge = &plot_style_content_edge_static; @@ -55,7 +55,7 @@ plot_style_t const * const plot_style_content_edge = static const plot_style_t plot_style_padding_edge_static = { .stroke_type = PLOT_OP_TYPE_SOLID, .stroke_colour = 0x000000ff, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; plot_style_t const * const plot_style_padding_edge = &plot_style_padding_edge_static; @@ -63,7 +63,7 @@ plot_style_t const * const plot_style_padding_edge = static const plot_style_t plot_style_margin_edge_static = { .stroke_type = PLOT_OP_TYPE_SOLID, .stroke_colour = 0x0000ffff, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; plot_style_t const * const plot_style_margin_edge = &plot_style_margin_edge_static; @@ -74,7 +74,7 @@ static const plot_style_t plot_style_broken_object_static = { .fill_colour = 0x008888ff, .stroke_type = PLOT_OP_TYPE_SOLID, .stroke_colour = 0x000000ff, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; plot_style_t const * const plot_style_broken_object = &plot_style_broken_object_static; @@ -134,7 +134,7 @@ plot_style_t *plot_style_fill_wblobc = &plot_style_fill_wblobc_static; static plot_style_t plot_style_stroke_wblobc_static = { .stroke_type = PLOT_OP_TYPE_SOLID, .stroke_colour = WIDGET_BLOBC, - .stroke_width = 2, + .stroke_width = plot_style_int_to_fixed(2), }; plot_style_t *plot_style_stroke_wblobc = &plot_style_stroke_wblobc_static; diff --git a/desktop/save_pdf.c b/desktop/save_pdf.c index 83e3d4f31..889190089 100644 --- a/desktop/save_pdf.c +++ b/desktop/save_pdf.c @@ -213,10 +213,10 @@ bool pdf_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *psty } apply_clip_and_mode(false, - NS_TRANSPARENT, - pstyle->stroke_colour, - pstyle->stroke_width, - dash); + NS_TRANSPARENT, + pstyle->stroke_colour, + plot_style_int_to_fixed(pstyle->stroke_width), + dash); HPDF_Page_Rectangle(pdf_page, x0, page_height - y0, x1 - x0, -(y1 - y0)); HPDF_Page_Stroke(pdf_page); @@ -245,10 +245,10 @@ bool pdf_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle) } apply_clip_and_mode(false, - NS_TRANSPARENT, - pstyle->stroke_colour, - pstyle->stroke_width, - dash); + NS_TRANSPARENT, + pstyle->stroke_colour, + plot_style_int_to_fixed(pstyle->stroke_width), + dash); HPDF_Page_MoveTo(pdf_page, x0, page_height - y0); HPDF_Page_LineTo(pdf_page, x1, page_height - y1); diff --git a/desktop/scrollbar.c b/desktop/scrollbar.c index 5a7420ae1..af5536ba4 100644 --- a/desktop/scrollbar.c +++ b/desktop/scrollbar.c @@ -164,17 +164,17 @@ scrollbar_rectangle(const struct redraw_context *ctx, static plot_style_t c0 = { .stroke_type = PLOT_OP_TYPE_SOLID, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; static plot_style_t c1 = { .stroke_type = PLOT_OP_TYPE_SOLID, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; static plot_style_t c2 = { .stroke_type = PLOT_OP_TYPE_SOLID, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; if (inset) { diff --git a/desktop/textarea.c b/desktop/textarea.c index 5666c975b..5bae27a5c 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -45,9 +45,9 @@ #define TA_ALLOC_STEP 512 static plot_style_t pstyle_stroke_caret = { - .stroke_type = PLOT_OP_TYPE_SOLID, - .stroke_colour = CARET_COLOR, - .stroke_width = 1, + .stroke_type = PLOT_OP_TYPE_SOLID, + .stroke_colour = CARET_COLOR, + .stroke_width = plot_style_int_to_fixed(1), }; struct line_info { diff --git a/frontends/amiga/dt_sound.c b/frontends/amiga/dt_sound.c index ae313bb51..f3b365ddb 100644 --- a/frontends/amiga/dt_sound.c +++ b/frontends/amiga/dt_sound.c @@ -195,7 +195,7 @@ bool amiga_dt_sound_redraw(struct content *c, .fill_type = PLOT_OP_TYPE_SOLID, .fill_colour = 0xffffff, .stroke_colour = 0x000000, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; struct rect rect; diff --git a/frontends/amiga/plotters.c b/frontends/amiga/plotters.c index b8485430f..58dc90503 100644 --- a/frontends/amiga/plotters.c +++ b/frontends/amiga/plotters.c @@ -722,8 +722,8 @@ ami_line(const struct redraw_context *ctx, struct gui_globals *glob = (struct gui_globals *)ctx->priv; - glob->rp->PenWidth = style->stroke_width; - glob->rp->PenHeight = style->stroke_width; + glob->rp->PenWidth = plot_style_fixed_to_int(style->stroke_width); + glob->rp->PenHeight = plot_style_fixed_to_int(style->stroke_width); switch (style->stroke_type) { case PLOT_OP_TYPE_SOLID: /**< Solid colour */ @@ -780,8 +780,8 @@ ami_rectangle(const struct redraw_context *ctx, } if (style->stroke_type != PLOT_OP_TYPE_NONE) { - glob->rp->PenWidth = style->stroke_width; - glob->rp->PenHeight = style->stroke_width; + glob->rp->PenWidth = plot_style_fixed_to_int(style->stroke_width); + glob->rp->PenHeight = plot_style_fixed_to_int(style->stroke_width); switch (style->stroke_type) { case PLOT_OP_TYPE_SOLID: /**< Solid colour */ diff --git a/frontends/amiga/plugin_hack.c b/frontends/amiga/plugin_hack.c index 4fd1f03f7..5d7ec19c1 100644 --- a/frontends/amiga/plugin_hack.c +++ b/frontends/amiga/plugin_hack.c @@ -151,7 +151,7 @@ bool amiga_plugin_hack_redraw(struct content *c, .fill_type = PLOT_OP_TYPE_SOLID, .fill_colour = 0xffffff, .stroke_colour = 0x000000, - .stroke_width = 1, + .stroke_width = plot_style_int_to_fixed(1), }; struct rect rect; nserror res; diff --git a/frontends/atari/plot/plot.c b/frontends/atari/plot/plot.c index 14c670352..5f69f2af5 100644 --- a/frontends/atari/plot/plot.c +++ b/frontends/atari/plot/plot.c @@ -2124,7 +2124,7 @@ plot_line(const struct redraw_context *ctx, { short pxy[4]; uint32_t lt; - int sw = pstyle->stroke_width; + int sw = plot_style_fixed_to_int(pstyle->stroke_width); if (((line->x0 < 0) && (line->x1 < 0)) || ((line->y0 < 0) && (line->y1 < 0))) { @@ -2183,7 +2183,7 @@ plot_rectangle(const struct redraw_context *ctx, { short pxy[4]; GRECT r, rclip, sclip; - int sw = pstyle->stroke_width; + int sw = plot_style_fixed_to_int(pstyle->stroke_width); uint32_t lt; /* current canvas clip: */ @@ -2266,7 +2266,7 @@ plot_rectangle(const struct redraw_context *ctx, if (pstyle->fill_type != PLOT_OP_TYPE_NONE ) { short stroke_width = (short)(pstyle->stroke_type != PLOT_OP_TYPE_NONE) ? - pstyle->stroke_width : 0; + plot_style_fixed_to_int(pstyle->stroke_width) : 0; vsf_rgbcolor(atari_plot_vdi_handle, pstyle->fill_colour); vsf_perimeter(atari_plot_vdi_handle, 0); diff --git a/frontends/beos/plotters.cpp b/frontends/beos/plotters.cpp index c4903e045..a0a70f5b7 100644 --- a/frontends/beos/plotters.cpp +++ b/frontends/beos/plotters.cpp @@ -370,7 +370,7 @@ nsbeos_plot_line(const struct redraw_context *ctx, nsbeos_set_colour(style->stroke_colour); float pensize = view->PenSize(); - view->SetPenSize(style->stroke_width); + view->SetPenSize(plot_style_fixed_to_float(style->stroke_width)); BPoint start(line->x0, line->y0); BPoint end(line->x1, line->y1); @@ -447,7 +447,7 @@ nsbeos_plot_rectangle(const struct redraw_context *ctx, nsbeos_set_colour(style->stroke_colour); float pensize = view->PenSize(); - view->SetPenSize(style->stroke_width); + view->SetPenSize(plot_style_fixed_to_float(style->stroke_width)); BRect rect(nsrect->x0, nsrect->y0, nsrect->x1, nsrect->y1); view->StrokeRect(rect, pat); diff --git a/frontends/framebuffer/framebuffer.c b/frontends/framebuffer/framebuffer.c index 2ccc75062..5a2603535 100644 --- a/frontends/framebuffer/framebuffer.c +++ b/frontends/framebuffer/framebuffer.c @@ -168,7 +168,7 @@ framebuffer_plot_line(const struct redraw_context *ctx, } pen.stroke_colour = style->stroke_colour; - pen.stroke_width = style->stroke_width; + pen.stroke_width = plot_style_fixed_to_int(style->stroke_width); nsfb_plot_line(nsfb, &rect, &pen); } @@ -216,7 +216,9 @@ framebuffer_plot_rectangle(const struct redraw_context *ctx, dashed = true; } - nsfb_plot_rectangle(nsfb, &rect, style->stroke_width, style->stroke_colour, dotted, dashed); + nsfb_plot_rectangle(nsfb, &rect, + plot_style_fixed_to_int(style->stroke_width), + style->stroke_colour, dotted, dashed); } return NSERROR_OK; } diff --git a/frontends/gtk/plotters.c b/frontends/gtk/plotters.c index 88e7760c6..6178104d5 100644 --- a/frontends/gtk/plotters.c +++ b/frontends/gtk/plotters.c @@ -88,6 +88,20 @@ static inline void nsgtk_set_dashed(void) } +/** + * Set cairo context line width. + */ +static inline void nsgtk_set_line_width(plot_style_fixed width) +{ + if (width == 0) { + cairo_set_line_width(current_cr, 1); + } else { + cairo_set_line_width(current_cr, + plot_style_fixed_to_double(width)); + } +} + + /** * \brief Sets a clip rectangle for subsequent plot operations. * @@ -191,10 +205,7 @@ nsgtk_plot_disc(const struct redraw_context *ctx, break; } - if (style->stroke_width == 0) - cairo_set_line_width(current_cr, 1); - else - cairo_set_line_width(current_cr, style->stroke_width); + nsgtk_set_line_width(style->stroke_width); cairo_arc(current_cr, x, y, radius, 0, M_PI * 2); @@ -242,10 +253,7 @@ nsgtk_plot_line(const struct redraw_context *ctx, 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); + nsgtk_set_line_width(style->stroke_width); /* core expects horizontal and vertical lines to be on pixels, not * between pixels @@ -331,10 +339,7 @@ nsgtk_plot_rectangle(const struct redraw_context *ctx, break; } - if (style->stroke_width == 0) - cairo_set_line_width(current_cr, 1); - else - cairo_set_line_width(current_cr, style->stroke_width); + nsgtk_set_line_width(style->stroke_width); cairo_rectangle(current_cr, rect->x0 + 0.5, diff --git a/frontends/gtk/print.c b/frontends/gtk/print.c index 8f71230a6..f447a463e 100644 --- a/frontends/gtk/print.c +++ b/frontends/gtk/print.c @@ -133,6 +133,17 @@ static inline void nsgtk_print_set_dashed(void) cairo_set_dash(gtk_print_current_cr, cdashes, 1, 0); } +/** Set cairo context line width. */ +static inline void nsgtk_set_line_width(plot_style_fixed width) +{ + if (width == 0) { + cairo_set_line_width(gtk_print_current_cr, 1); + } else { + cairo_set_line_width(gtk_print_current_cr, + plot_style_fixed_to_double(width)); + } +} + /** * \brief Sets a clip rectangle for subsequent plot operations. @@ -248,10 +259,7 @@ nsgtk_print_plot_disc(const struct redraw_context *ctx, 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); + nsgtk_set_line_width(style->stroke_width); cairo_arc(gtk_print_current_cr, x, y, radius, 0, M_PI * 2); @@ -294,10 +302,7 @@ nsgtk_print_plot_line(const struct redraw_context *ctx, 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); + nsgtk_set_line_width(style->stroke_width); cairo_move_to(gtk_print_current_cr, line->x0 + 0.5, line->y0 + 0.5); cairo_line_to(gtk_print_current_cr, line->x1 + 0.5, line->y1 + 0.5); @@ -350,13 +355,6 @@ nsgtk_print_plot_rectangle(const struct redraw_context *ctx, } if (style->stroke_type != PLOT_OP_TYPE_NONE) { - int stroke_width; - - /* ensure minimum stroke width */ - stroke_width = style->stroke_width; - if (stroke_width == 0) { - stroke_width = 1; - } nsgtk_print_set_colour(style->stroke_colour); @@ -375,7 +373,7 @@ nsgtk_print_plot_rectangle(const struct redraw_context *ctx, break; } - cairo_set_line_width(gtk_print_current_cr, stroke_width); + nsgtk_set_line_width(style->stroke_width); cairo_rectangle(gtk_print_current_cr, rect->x0, rect->y0, diff --git a/frontends/riscos/plotters.c b/frontends/riscos/plotters.c index 2fbd12aeb..286ddab1b 100644 --- a/frontends/riscos/plotters.c +++ b/frontends/riscos/plotters.c @@ -324,9 +324,9 @@ ro_plot_line(const struct redraw_context *ctx, dashed = true; return ro_plot_draw_path((const draw_path *)path, - style->stroke_width, - style->stroke_colour, - dotted, dashed); + plot_style_fixed_to_int(style->stroke_width), + style->stroke_colour, + dotted, dashed); } return NSERROR_OK; } @@ -412,10 +412,10 @@ ro_plot_rectangle(const struct redraw_context *ctx, dashed = true; ro_plot_draw_path((const draw_path *)path, - style->stroke_width, - style->stroke_colour, - dotted, - dashed); + plot_style_fixed_to_int(style->stroke_width), + style->stroke_colour, + dotted, + dashed); } return NSERROR_OK; diff --git a/frontends/riscos/save_draw.c b/frontends/riscos/save_draw.c index 9ee730434..41764d927 100644 --- a/frontends/riscos/save_draw.c +++ b/frontends/riscos/save_draw.c @@ -168,7 +168,7 @@ ro_save_draw_line(const struct redraw_context *ctx, sizeof path / sizeof path[0], pencil_TRANSPARENT, style->stroke_colour << 8, - style->stroke_width, + plot_style_fixed_to_int(style->stroke_width), pencil_JOIN_MITRED, pencil_CAP_BUTT, pencil_CAP_BUTT, @@ -235,7 +235,7 @@ ro_save_draw_rectangle(const struct redraw_context *ctx, sizeof path / sizeof path[0], pencil_TRANSPARENT, style->stroke_colour << 8, - style->stroke_width, + plot_style_fixed_to_int(style->stroke_width), pencil_JOIN_MITRED, pencil_CAP_BUTT, pencil_CAP_BUTT, diff --git a/frontends/windows/plot.c b/frontends/windows/plot.c index 3668e4bb6..60b175a6b 100644 --- a/frontends/windows/plot.c +++ b/frontends/windows/plot.c @@ -601,7 +601,9 @@ line(const struct redraw_context *ctx, (style->stroke_type == PLOT_OP_TYPE_DASH) ? PS_DASH: 0); LOGBRUSH lb = {BS_SOLID, col, 0}; - HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL); + HPEN pen = ExtCreatePen(penstyle, + plot_style_fixed_to_int(style->stroke_width), + &lb, 0, NULL); if (pen == NULL) { DeleteObject(clipregion); return NSERROR_INVALID; @@ -672,7 +674,9 @@ rectangle(const struct redraw_context *ctx, if (style->fill_type == PLOT_OP_TYPE_NONE) lb1.lbStyle = BS_HOLLOW; - HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL); + HPEN pen = ExtCreatePen(penstyle, + plot_style_fixed_to_int(style->stroke_width), + &lb, 0, NULL); if (pen == NULL) { return NSERROR_INVALID; } diff --git a/include/netsurf/plot_style.h b/include/netsurf/plot_style.h index db5a5ee26..d7a027cee 100644 --- a/include/netsurf/plot_style.h +++ b/include/netsurf/plot_style.h @@ -24,6 +24,7 @@ #ifndef NETSURF_PLOT_STYLE_H #define NETSURF_PLOT_STYLE_H +#include #include #include "netsurf/types.h" @@ -45,6 +46,18 @@ /* type for fixed point numbers */ typedef int32_t plot_style_fixed; +/* Convert an int to fixed point */ +#define plot_style_int_to_fixed(v) ((v) << PLOT_STYLE_RADIX) + +/* Convert fixed point to int */ +#define plot_style_fixed_to_int(v) ((v) >> PLOT_STYLE_RADIX) + +/* Convert fixed point to float */ +#define plot_style_fixed_to_float(v) (((float)v) / PLOT_STYLE_SCALE) + +/* Convert fixed point to double */ +#define plot_style_fixed_to_double(v) (((double)v) / PLOT_STYLE_SCALE) + /** * Type of plot operation */ @@ -61,7 +74,7 @@ typedef enum { */ typedef struct plot_style_s { plot_operation_type_t stroke_type; /**< Stroke plot type */ - int stroke_width; /**< Width of stroke, in pixels */ + plot_style_fixed stroke_width; /**< Width of stroke, in pixels */ colour stroke_colour; /**< Colour of stroke */ plot_operation_type_t fill_type; /**< Fill plot type */ colour fill_colour; /**< Colour of fill */ -- cgit v1.2.3