From 9a1751020684c410d7ad8824dd3cab7c5dd90733 Mon Sep 17 00:00:00 2001 From: John Tytgat Date: Mon, 2 Feb 2009 23:25:36 +0000 Subject: - apply_clip_and_mode(): pass text mode selection as parameter instead of using global variable text_mode_request. - pdf_next_page()/pdf_end: fix possible gstate unbalance by using apply_clip_and_mode(). svn path=/trunk/netsurf/; revision=6360 --- desktop/save_pdf/pdf_plotters.c | 78 ++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 37 deletions(-) (limited to 'desktop/save_pdf') diff --git a/desktop/save_pdf/pdf_plotters.c b/desktop/save_pdf/pdf_plotters.c index 6457a7378..02d19d70f 100644 --- a/desktop/save_pdf/pdf_plotters.c +++ b/desktop/save_pdf/pdf_plotters.c @@ -1,5 +1,6 @@ /* * Copyright 2008 Adam Blokus + * Copyright 2009 John Tytgat * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -72,7 +73,7 @@ static void pdf_set_dashed(void); static void pdf_set_dotted(void); static HPDF_Image pdf_extract_image(struct bitmap *bitmap, struct content *content); -static void apply_clip_and_mode(void); +static void apply_clip_and_mode(bool selectTextMode); static void error_handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, @@ -94,9 +95,9 @@ static HPDF_REAL page_height, page_width; static bool page_clipped; static int last_clip_x0, last_clip_y0, last_clip_x1, last_clip_y1; -static bool in_text_mode, text_mode_request; +static bool in_text_mode; -static struct print_settings* settings; +static const struct print_settings *settings; static const struct plotter_table pdf_plotters = { pdf_plot_clg, @@ -139,7 +140,7 @@ bool pdf_plot_rectangle(int x0, int y0, int width, int height, #ifdef PDF_DEBUG LOG((".")); #endif - apply_clip_and_mode(); + apply_clip_and_mode(false); HPDF_Page_SetLineWidth(pdf_page, line_width); @@ -165,7 +166,7 @@ bool pdf_plot_line(int x0, int y0, int x1, int y1, int width, LOG((".")); #endif - apply_clip_and_mode(); + apply_clip_and_mode(false); HPDF_Page_SetLineWidth(pdf_page, width); @@ -197,7 +198,7 @@ bool pdf_plot_polygon(int *p, unsigned int n, colour fill) if (n == 0) return true; - apply_clip_and_mode(); + apply_clip_and_mode(false); HPDF_Page_SetRGBFill(pdf_page, R(fill), G(fill), B(fill)); HPDF_Page_MoveTo(pdf_page, p[0], page_height - p[1]); @@ -238,7 +239,7 @@ bool pdf_plot_fill(int x0, int y0, int x1, int y1, colour c) x1 = min(max(x1, 0), page_width); y1 = min(max(y1, 0), page_height); - apply_clip_and_mode(); + apply_clip_and_mode(false); HPDF_Page_SetRGBFill(pdf_page, R(c), G(c), B(c)); HPDF_Page_Rectangle(pdf_page, x0, page_height - y1, x1-x0, y1-y0); @@ -271,7 +272,7 @@ bool pdf_plot_text(int x, int y, const struct css_style *style, const char *text, size_t length, colour bg, colour c) { #ifdef PDF_DEBUG - LOG((". %d %d %s", x, y, text)); + LOG((". %d %d %.*s", x, y, (int)length, text)); #endif char *word; HPDF_REAL size; @@ -280,8 +281,7 @@ bool pdf_plot_text(int x, int y, const struct css_style *style, if (length == 0) return true; - text_mode_request = true; - apply_clip_and_mode(); + apply_clip_and_mode(true); if (style->font_size.value.length.unit == CSS_UNIT_PX) size = style->font_size.value.length.value; @@ -323,7 +323,7 @@ bool pdf_plot_disc(int x, int y, int radius, colour c, bool filled) #ifdef PDF_DEBUG LOG((".")); #endif - apply_clip_and_mode(); + apply_clip_and_mode(false); if (filled) HPDF_Page_SetRGBFill(pdf_page, R(c), G(c), B(c)); @@ -352,7 +352,7 @@ bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2, colour c) if (angle1 > angle2) angle1 -= 360; - apply_clip_and_mode(); + apply_clip_and_mode(false); HPDF_Page_SetRGBStroke(pdf_page, R(c), G(c), B(c)); @@ -368,13 +368,13 @@ bool pdf_plot_bitmap(int x, int y, int width, int height, HPDF_Image image; #ifdef PDF_DEBUG - LOG(("%d %d %d %d %X %X %X", x, y, width, height, + LOG(("%d %d %d %d %p 0x%x %p", x, y, width, height, bitmap, bg, content)); #endif if (width == 0 || height == 0) return true; - apply_clip_and_mode(); + apply_clip_and_mode(false); image = pdf_extract_image(bitmap, content); @@ -396,13 +396,13 @@ bool pdf_plot_bitmap_tile(int x, int y, int width, int height, HPDF_Image image; #ifdef PDF_DEBUG - LOG(("%d %d %d %d %X %X %X", x, y, width, height, + LOG(("%d %d %d %d %p 0x%x %p", x, y, width, height, bitmap, bg, content)); #endif if (width == 0 || height == 0) return true; - apply_clip_and_mode(); + apply_clip_and_mode(false); image = pdf_extract_image(bitmap, content); if (!image) @@ -510,17 +510,17 @@ HPDF_Image pdf_extract_image(struct bitmap *bitmap, struct content *content) return image; } -/**change the mode and clip only if it's necessary*/ -static void apply_clip_and_mode() +/** + * Change the mode and clip only if it's necessary + */ +static void apply_clip_and_mode(bool selectTextMode) { - - if (in_text_mode && (!text_mode_request || page_clipped)) { + if (in_text_mode && (!selectTextMode || page_clipped)) { HPDF_Page_EndText(pdf_page); in_text_mode = false; } if (page_clipped) { - HPDF_Page_GRestore(pdf_page); HPDF_Page_GSave(pdf_page); @@ -534,13 +534,11 @@ static void apply_clip_and_mode() page_clipped = false; } - if (text_mode_request) { + if (selectTextMode) { if (!in_text_mode) { HPDF_Page_BeginText(pdf_page); in_text_mode = true; } - - text_mode_request = false; } } @@ -584,7 +582,7 @@ bool pdf_plot_path(float *p, unsigned int n, colour fill, float width, transform[4] = 0; transform[5] = 0; - for (i = 0 ; i