diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2009-07-08 22:04:40 +0000 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2009-07-08 22:04:40 +0000 |
commit | f9ecd56f62f833f21b3475f0d1b59bc8e053a03e (patch) | |
tree | 9874485045ec0fc52fccab99ad545bdefb672203 /desktop | |
parent | 651228e64d688e1a565ac88e60b736995ba84012 (diff) | |
download | netsurf-f9ecd56f62f833f21b3475f0d1b59bc8e053a03e.tar.gz netsurf-f9ecd56f62f833f21b3475f0d1b59bc8e053a03e.tar.bz2 |
ploter refactor of rectangle handling
svn path=/trunk/netsurf/; revision=8399
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/history_core.c | 13 | ||||
-rw-r--r-- | desktop/knockout.c | 160 | ||||
-rw-r--r-- | desktop/plotters.h | 7 | ||||
-rw-r--r-- | desktop/save_pdf/pdf_plotters.c | 84 | ||||
-rw-r--r-- | desktop/textarea.c | 29 |
5 files changed, 164 insertions, 129 deletions
diff --git a/desktop/history_core.c b/desktop/history_core.c index 6ec2cc137..d02820b20 100644 --- a/desktop/history_core.c +++ b/desktop/history_core.c @@ -628,6 +628,11 @@ bool history_redraw_entry(struct history *history, int tailsize = 5; int xoffset = x - x0; int yoffset = y - y0; + plot_style_t pstyle_history_rect = { + .stroke_type = PLOT_OP_TYPE_SOLID, + .stroke_colour = c, + .stroke_width = entry == history->current ? 2 : 1, + }; if (clip) { if(!plot.clip(x0 + xoffset, y0 + yoffset, x1 + xoffset, y1 + yoffset)) @@ -637,9 +642,11 @@ bool history_redraw_entry(struct history *history, if (!plot.bitmap(entry->x + xoffset, entry->y + yoffset, WIDTH, HEIGHT, entry->bitmap, 0xffffff, 0)) return false; - if (!plot.rectangle(entry->x - 1 + xoffset, entry->y - 1 + yoffset, - WIDTH + 1, HEIGHT + 1, - entry == history->current ? 2 : 1, c, false, false)) + if (!plot.rectangle(entry->x - 1 + xoffset, + entry->y - 1 + yoffset, + entry->x + xoffset + WIDTH, + entry->y + yoffset + HEIGHT, + &pstyle_history_rect)) return false; if (!nsfont.font_position_in_string(&css_base_style, entry->page.title, diff --git a/desktop/knockout.c b/desktop/knockout.c index a31b9e0cf..807833b8b 100644 --- a/desktop/knockout.c +++ b/desktop/knockout.c @@ -91,9 +91,30 @@ static plot_style_t plot_style_fill_black_static = { .fill_colour = 0x0, }; +static plot_style_t plot_style_stroke_red_static = { + .stroke_type = PLOT_OP_TYPE_SOLID, + .stroke_colour = 0x000000ff, + .stroke_width = 1, +}; + +static plot_style_t plot_style_stroke_blue_static = { + .stroke_type = PLOT_OP_TYPE_SOLID, + .stroke_colour = 0x00ff0000, + .stroke_width = 1, +}; + +static plot_style_t plot_style_stroke_yellow_static = { + .stroke_type = PLOT_OP_TYPE_SOLID, + .stroke_colour = 0x0000ffff, + .stroke_width = 1, +}; + plot_style_t *plot_style_fill_white = &plot_style_fill_white_static; plot_style_t *plot_style_fill_red = &plot_style_fill_red_static; plot_style_t *plot_style_fill_black = &plot_style_fill_black_static; +plot_style_t *plot_style_stroke_red = &plot_style_stroke_red_static; +plot_style_t *plot_style_stroke_blue = &plot_style_stroke_blue_static; +plot_style_t *plot_style_stroke_yellow = &plot_style_stroke_yellow_static; struct knockout_box; struct knockout_entry; @@ -105,12 +126,10 @@ static bool knockout_plot_fill_recursive(struct knockout_box *box, plot_style_t static bool knockout_plot_bitmap_recursive(struct knockout_box *box, struct knockout_entry *entry); -static bool knockout_plot_rectangle(int x0, int y0, int width, int height, - int line_width, colour c, bool dotted, bool dashed); static bool knockout_plot_line(int x0, int y0, int x1, int y1, int width, colour c, bool dotted, bool dashed); static bool knockout_plot_polygon(const int *p, unsigned int n, colour fill); -static bool knockout_plot_fill(int x0, int y0, int x1, int y1, plot_style_t *plot_style); +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, @@ -132,7 +151,6 @@ const struct plotter_table knockout_plotters = { .rectangle = knockout_plot_rectangle, .line = knockout_plot_line, .polygon = knockout_plot_polygon, - .fill = knockout_plot_fill, .clip = knockout_plot_clip, .text = knockout_plot_text, .disc = knockout_plot_disc, @@ -181,12 +199,9 @@ struct knockout_entry { struct { int x0; int y0; - int width; - int height; - int line_width; - colour c; - bool dotted; - bool dashed; + int x1; + int y1; + plot_style_t plot_style; } rectangle; struct { int x0; @@ -337,15 +352,12 @@ bool knockout_plot_flush(void) for (i = 0; i < knockout_entry_cur; i++) { switch (knockout_entries[i].type) { case KNOCKOUT_PLOT_RECTANGLE: - success &= plot.rectangle( - knockout_entries[i].data.rectangle.x0, - knockout_entries[i].data.rectangle.y0, - knockout_entries[i].data.rectangle.width, - knockout_entries[i].data.rectangle.height, - knockout_entries[i].data.rectangle.line_width, - knockout_entries[i].data.rectangle.c, - knockout_entries[i].data.rectangle.dotted, - knockout_entries[i].data.rectangle.dashed); + success &= plot.rectangle( + knockout_entries[i].data.rectangle.x0, + knockout_entries[i].data.rectangle.y0, + knockout_entries[i].data.rectangle.x1, + knockout_entries[i].data.rectangle.y1, + &knockout_entries[i].data.rectangle.plot_style); break; case KNOCKOUT_PLOT_LINE: success &= plot.line( @@ -370,7 +382,7 @@ bool knockout_plot_flush(void) success &= knockout_plot_fill_recursive(box, &knockout_entries[i].data.fill.plot_style); else if (!knockout_entries[i].box->deleted) - success &= plot.fill( + success &= plot.rectangle( knockout_entries[i].data.fill.x0, knockout_entries[i].data.fill.y0, knockout_entries[i].data.fill.x1, @@ -605,11 +617,11 @@ bool knockout_plot_fill_recursive(struct knockout_box *box, plot_style_t *plot_s if (parent->child) knockout_plot_fill_recursive(parent->child, plot_style); else - success &= plot.fill(parent->bbox.x0, - parent->bbox.y0, - parent->bbox.x1, - parent->bbox.y1, - plot_style); + success &= plot.rectangle(parent->bbox.x0, + parent->bbox.y0, + parent->bbox.x1, + parent->bbox.y1, + plot_style); } return success; } @@ -643,26 +655,57 @@ bool knockout_plot_bitmap_recursive(struct knockout_box *box, return success; } +bool knockout_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *pstyle) +{ + int kx0, ky0, kx1, ky1; + if (pstyle->fill_type != PLOT_OP_TYPE_NONE) { + /* filled draw */ -bool knockout_plot_rectangle(int x0, int y0, int width, int height, - int line_width, colour c, bool dotted, bool dashed) -{ - knockout_entries[knockout_entry_cur].data.rectangle.x0 = x0; - knockout_entries[knockout_entry_cur].data.rectangle.y0 = y0; - knockout_entries[knockout_entry_cur].data.rectangle.width = width; - knockout_entries[knockout_entry_cur].data.rectangle.height = height; - knockout_entries[knockout_entry_cur].data.rectangle.line_width = line_width; - knockout_entries[knockout_entry_cur].data.rectangle.c = c; - knockout_entries[knockout_entry_cur].data.rectangle.dotted = dotted; - knockout_entries[knockout_entry_cur].data.rectangle.dashed = dashed; - knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_RECTANGLE; - if (++knockout_entry_cur >= KNOCKOUT_ENTRIES) - knockout_plot_flush(); + /* get our bounds */ + kx0 = (x0 > clip_x0_cur) ? x0 : clip_x0_cur; + ky0 = (y0 > clip_y0_cur) ? y0 : clip_y0_cur; + kx1 = (x1 < clip_x1_cur) ? x1 : clip_x1_cur; + ky1 = (y1 < clip_y1_cur) ? y1 : clip_y1_cur; + if ((kx0 > clip_x1_cur) || (kx1 < clip_x0_cur) || + (ky0 > clip_y1_cur) || (ky1 < clip_y0_cur)) + return true; + + /* fills both knock out and get knocked out */ + knockout_calculate(kx0, ky0, kx1, ky1, NULL); + knockout_boxes[knockout_box_cur].bbox.x0 = x0; + knockout_boxes[knockout_box_cur].bbox.y0 = y0; + knockout_boxes[knockout_box_cur].bbox.x1 = x1; + knockout_boxes[knockout_box_cur].bbox.y1 = y1; + knockout_boxes[knockout_box_cur].deleted = false; + knockout_boxes[knockout_box_cur].child = NULL; + knockout_boxes[knockout_box_cur].next = knockout_list; + knockout_list = &knockout_boxes[knockout_box_cur]; + knockout_entries[knockout_entry_cur].box = &knockout_boxes[knockout_box_cur]; + knockout_entries[knockout_entry_cur].data.fill.x0 = x0; + knockout_entries[knockout_entry_cur].data.fill.y0 = y0; + knockout_entries[knockout_entry_cur].data.fill.x1 = x1; + knockout_entries[knockout_entry_cur].data.fill.y1 = y1; + knockout_entries[knockout_entry_cur].data.fill.plot_style = *pstyle; + knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_FILL; + if ((++knockout_entry_cur >= KNOCKOUT_ENTRIES) || + (++knockout_box_cur >= KNOCKOUT_BOXES)) + knockout_plot_flush(); + } else if (pstyle->stroke_type != PLOT_OP_TYPE_NONE) { + /* not a filled area */ + + knockout_entries[knockout_entry_cur].data.rectangle.x0 = x0; + knockout_entries[knockout_entry_cur].data.rectangle.y0 = y0; + knockout_entries[knockout_entry_cur].data.rectangle.x1 = x1; + knockout_entries[knockout_entry_cur].data.rectangle.y1 = y1; + knockout_entries[knockout_entry_cur].data.fill.plot_style = *pstyle; + knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_RECTANGLE; + if (++knockout_entry_cur >= KNOCKOUT_ENTRIES) + knockout_plot_flush(); + } return true; } - bool knockout_plot_line(int x0, int y0, int x1, int y1, int width, colour c, bool dotted, bool dashed) { @@ -719,43 +762,6 @@ bool knockout_plot_path(const float *p, unsigned int n, colour fill, } -bool knockout_plot_fill(int x0, int y0, int x1, int y1, plot_style_t *plot_style) -{ - int kx0, ky0, kx1, ky1; - - /* get our bounds */ - kx0 = (x0 > clip_x0_cur) ? x0 : clip_x0_cur; - ky0 = (y0 > clip_y0_cur) ? y0 : clip_y0_cur; - kx1 = (x1 < clip_x1_cur) ? x1 : clip_x1_cur; - ky1 = (y1 < clip_y1_cur) ? y1 : clip_y1_cur; - if ((kx0 > clip_x1_cur) || (kx1 < clip_x0_cur) || - (ky0 > clip_y1_cur) || (ky1 < clip_y0_cur)) - return true; - - /* fills both knock out and get knocked out */ - knockout_calculate(kx0, ky0, kx1, ky1, NULL); - knockout_boxes[knockout_box_cur].bbox.x0 = x0; - knockout_boxes[knockout_box_cur].bbox.y0 = y0; - knockout_boxes[knockout_box_cur].bbox.x1 = x1; - knockout_boxes[knockout_box_cur].bbox.y1 = y1; - knockout_boxes[knockout_box_cur].deleted = false; - knockout_boxes[knockout_box_cur].child = NULL; - knockout_boxes[knockout_box_cur].next = knockout_list; - knockout_list = &knockout_boxes[knockout_box_cur]; - knockout_entries[knockout_entry_cur].box = &knockout_boxes[knockout_box_cur]; - knockout_entries[knockout_entry_cur].data.fill.x0 = x0; - knockout_entries[knockout_entry_cur].data.fill.y0 = y0; - knockout_entries[knockout_entry_cur].data.fill.x1 = x1; - knockout_entries[knockout_entry_cur].data.fill.y1 = y1; - knockout_entries[knockout_entry_cur].data.fill.plot_style = *plot_style; - knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_FILL; - if ((++knockout_entry_cur >= KNOCKOUT_ENTRIES) || - (++knockout_box_cur >= KNOCKOUT_BOXES)) - knockout_plot_flush(); - return true; -} - - bool knockout_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1) { diff --git a/desktop/plotters.h b/desktop/plotters.h index d634f2135..3f317b1af 100644 --- a/desktop/plotters.h +++ b/desktop/plotters.h @@ -55,6 +55,9 @@ typedef struct { extern plot_style_t *plot_style_fill_white; extern plot_style_t *plot_style_fill_red; extern plot_style_t *plot_style_fill_black; +extern plot_style_t *plot_style_stroke_red; +extern plot_style_t *plot_style_stroke_blue; +extern plot_style_t *plot_style_stroke_yellow; /** Set of target specific plotting functions. * @@ -115,12 +118,10 @@ extern plot_style_t *plot_style_fill_black; * 3 | | | | | | */ struct plotter_table { - bool (*rectangle)(int x0, int y0, int width, int height, - int line_width, colour c, bool dotted, bool dashed); + bool (*rectangle)(int x0, int y0, int x1, int y1, const plot_style_t *style); bool (*line)(int x0, int y0, int x1, int y1, int width, colour c, bool dotted, bool dashed); bool (*polygon)(const int *p, unsigned int n, colour fill); - bool (*fill)(int x0, int y0, int x1, int y1, plot_style_t *style); 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); diff --git a/desktop/save_pdf/pdf_plotters.c b/desktop/save_pdf/pdf_plotters.c index 7f573d9aa..468c19ed1 100644 --- a/desktop/save_pdf/pdf_plotters.c +++ b/desktop/save_pdf/pdf_plotters.c @@ -45,12 +45,10 @@ /* #define PDF_DEBUG */ /* #define PDF_DEBUG_DUMPGRID */ -static bool pdf_plot_rectangle(int x0, int y0, int width, int height, - int line_width, colour c, bool dotted, bool dashed); +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, int width, colour c, bool dotted, bool dashed); static bool pdf_plot_polygon(const int *p, unsigned int n, colour fill); -static bool pdf_plot_fill(int x0, int y0, int x1, int y1, 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, @@ -126,7 +124,6 @@ static const struct plotter_table pdf_plotters = { .rectangle = pdf_plot_rectangle, .line = pdf_plot_line, .polygon = pdf_plot_polygon, - .fill = pdf_plot_fill, .clip = pdf_plot_clip, .text = pdf_plot_text, .disc = pdf_plot_disc, @@ -146,19 +143,59 @@ const struct printer pdf_printer = { static char *owner_pass; static char *user_pass; -bool pdf_plot_rectangle(int x0, int y0, int width, int height, - int line_width, colour c, bool dotted, bool dashed) +bool pdf_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *pstyle) { + DashPattern_e dash; #ifdef PDF_DEBUG - LOG((".")); + LOG(("%d %d %d %d %f %X", x0, y0, x1, y1, page_height - y0, style->fill_colour)); #endif - apply_clip_and_mode(false, TRANSPARENT, c, line_width, - (dotted) ? DashPattern_eDotted : - ((dashed) ? DashPattern_eDash : DashPattern_eNone)); + if (pstyle->fill_type != PLOT_OP_TYPE_NONE) { - HPDF_Page_Rectangle(pdf_page, x0, page_height - y0, width, -height); - HPDF_Page_Stroke(pdf_page); + apply_clip_and_mode(false, pstyle->fill_colour, TRANSPARENT, 0., DashPattern_eNone); + + /* Normalize boundaries of the area - to prevent + overflows. It is needed only in a few functions, + where integers are subtracted. When the whole + browser window is meant min and max int values are + used what must be handled in paged output. + */ + x0 = min(max(x0, 0), page_width); + y0 = min(max(y0, 0), page_height); + x1 = min(max(x1, 0), page_width); + y1 = min(max(y1, 0), page_height); + + HPDF_Page_Rectangle(pdf_page, x0, page_height - y1, x1 - x0, y1 - y0); + HPDF_Page_Fill(pdf_page); + + } + + if (pstyle->stroke_type != PLOT_OP_TYPE_NONE) { + + switch (pstyle->stroke_type) { + case PLOT_OP_TYPE_DOT: + dash = DashPattern_eDotted; + break; + + case PLOT_OP_TYPE_DASH: + dash = DashPattern_eDash; + break; + + default: + dash = DashPattern_eNone; + break; + + } + + apply_clip_and_mode(false, + TRANSPARENT, + pstyle->stroke_colour, + pstyle->stroke_width, + dash); + + HPDF_Page_Rectangle(pdf_page, x0, page_height - y0, x1 - x0, -(y1 - y0)); + HPDF_Page_Stroke(pdf_page); + } return true; } @@ -214,29 +251,6 @@ bool pdf_plot_polygon(const int *p, unsigned int n, colour fill) return true; } -bool pdf_plot_fill(int x0, int y0, int x1, int y1, plot_style_t *style) -{ -#ifdef PDF_DEBUG - LOG(("%d %d %d %d %f %X", x0, y0, x1, y1, page_height - y0, style->fill_colour)); -#endif - - apply_clip_and_mode(false, style->fill_colour, TRANSPARENT, 0., DashPattern_eNone); - - /*Normalize boundaries of the area - to prevent overflows. - It is needed only in a few functions, where integers are subtracted. - When the whole browser window is meant min and max int values are used - what must be handled in paged output. - */ - x0 = min(max(x0, 0), page_width); - y0 = min(max(y0, 0), page_height); - x1 = min(max(x1, 0), page_width); - y1 = min(max(y1, 0), page_height); - - HPDF_Page_Rectangle(pdf_page, x0, page_height - y1, x1 - x0, y1 - y0); - HPDF_Page_Fill(pdf_page); - - return true; -} /**here the clip is only queried */ bool pdf_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1) diff --git a/desktop/textarea.c b/desktop/textarea.c index 20aaeed78..520b53090 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -41,11 +41,17 @@ #define BORDER_COLOR 0x000000 #define SELECTION_COL 0xFFDDDD -static plot_style_t plot_style_fill_selection = { +static plot_style_t pstyle_fill_selection = { .fill_type = PLOT_OP_TYPE_SOLID, .fill_colour = SELECTION_COL, }; +static plot_style_t pstyle_stroke_border = { + .stroke_type = PLOT_OP_TYPE_SOLID, + .stroke_colour = BORDER_COLOR, + .stroke_width = 1, +}; + struct line_info { unsigned int b_start; /**< Byte offset of line start */ unsigned int b_length; /**< Byte length of line */ @@ -782,9 +788,10 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1) y1 = ta->y + ta->vis_height; plot.clip(x0, y0, x1, y1); - plot.fill(x0, y0, x1, y1, &plot_style_fill_bg); - plot.rectangle(ta->x, ta->y, ta->vis_width - 1, ta->vis_height - 1, 1, - BORDER_COLOR, false, false); + plot.rectangle(x0, y0, x1, y1, &plot_style_fill_bg); + plot.rectangle(ta->x, ta->y, + ta->x + ta->vis_width - 1, ta->y + ta->vis_height - 1, + &pstyle_stroke_border); if (x0 < ta->x + MARGIN_LEFT) x0 = ta->x + MARGIN_LEFT; @@ -864,13 +871,13 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1) b_start]), b_end, &x1); x1 += x0; - plot.fill(x0 - ta->scroll_x, ta->y + - line * ta->line_height - + 1 - ta->scroll_y, - x1 - ta->scroll_x, - ta->y + (line + 1) * ta->line_height - - 1 - ta->scroll_y, - &plot_style_fill_selection); + plot.rectangle(x0 - ta->scroll_x, ta->y + + line * ta->line_height + + 1 - ta->scroll_y, + x1 - ta->scroll_x, + ta->y + (line + 1) * ta->line_height - + 1 - ta->scroll_y, + &pstyle_fill_selection); } |