Plotters: Change stroke width in the plot_style_t to fixed point.

This commit is contained in:
Michael Drake 2018-05-23 13:04:19 +01:00
parent a58d97a41a
commit 66493421e6
19 changed files with 104 additions and 81 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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),
};

View File

@ -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;

View File

@ -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);

View File

@ -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) {

View File

@ -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 {

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

@ -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,

View File

@ -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;
}

View File

@ -24,6 +24,7 @@
#ifndef NETSURF_PLOT_STYLE_H
#define NETSURF_PLOT_STYLE_H
#include <stdint.h>
#include <stdint.h>
#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 */