These patches fix the recently reported problem with charts being emitted black on black.
I'm not totally happy with the way this patch exposes functions which were previously known only to the driver, but its the easiest solution in the short term. A review before I push them would be appreciated. J' -- PGP Public key ID: 1024D/2DE827B3 fingerprint = 8797 A26D 0854 2EAB 0285 A290 8A67 719C 2DE8 27B3 See http://sks-keyservers.net or any PGP keyserver for public key.
From d036c4b79922f2339e7db9d0aef7ecad5e93bd91 Mon Sep 17 00:00:00 2001 From: John Darrington <j...@darrington.wattle.id.au> Date: Sat, 19 Oct 2013 13:44:54 +0200 Subject: [PATCH 1/2] New structure xr_color --- src/output/cairo.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/output/cairo.c b/src/output/cairo.c index 516ac76..cb90125 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -110,6 +110,13 @@ struct xr_render_fsm void (*destroy) (struct xr_render_fsm *); }; +struct xr_color +{ + double red; + double green; + double blue; +}; + /* Cairo output driver. */ struct xr_driver { @@ -130,8 +137,8 @@ struct xr_driver int line_space; /* Space between lines. */ int line_width; /* Width of lines. */ - double bg_red, bg_green, bg_blue; /* Background color */ - double fg_red, fg_green, fg_blue; /* Foreground color */ + struct xr_color bg; /* Background color */ + struct xr_color fg; /* Foreground color */ /* Internal state. */ struct render_params *params; @@ -186,8 +193,8 @@ opt (struct output_driver *d, struct string_map *options, const char *key, */ static void parse_color (struct output_driver *d, struct string_map *options, - const char *key, const char *default_value, - double *dred, double *dgreen, double *dblue) + const char *key, const char *default_value, + struct xr_color *color) { int red, green, blue; char *string = parse_string (opt (d, options, key, default_value)); @@ -205,9 +212,9 @@ parse_color (struct output_driver *d, struct string_map *options, free (string); /* Convert 16 bit ints to float */ - *dred = red / (double) 0xFFFF; - *dgreen = green / (double) 0xFFFF; - *dblue = blue / (double) 0xFFFF; + color->red = red / (double) 0xFFFF; + color->green = green / (double) 0xFFFF; + color->blue = blue / (double) 0xFFFF; } static PangoFontDescription * @@ -271,8 +278,8 @@ apply_options (struct xr_driver *xr, struct string_map *o) xr->line_width = XR_POINT / 2; xr->page_number = 0; - parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &xr->bg_red, &xr->bg_green, &xr->bg_blue); - parse_color (d, o, "foreground-color", "#000000000000", &xr->fg_red, &xr->fg_green, &xr->fg_blue); + parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &xr->bg); + parse_color (d, o, "foreground-color", "#000000000000", &xr->fg); parse_paper_size (opt (d, o, "paper-size", ""), &paper_width, &paper_length); xr->left_margin = parse_dimension (opt (d, o, "left-margin", ".5in")); @@ -347,7 +354,7 @@ xr_set_cairo (struct xr_driver *xr, cairo_t *cairo) } } - cairo_set_source_rgb (xr->cairo, xr->fg_red, xr->fg_green, xr->fg_blue); + cairo_set_source_rgb (xr->cairo, xr->fg.red, xr->fg.green, xr->fg.blue); return true; } @@ -551,7 +558,7 @@ xr_driver_next_page (struct xr_driver *xr, cairo_t *cairo) if (cairo != NULL) { cairo_save (cairo); - cairo_set_source_rgb (cairo, xr->bg_red, xr->bg_green, xr->bg_blue); + cairo_set_source_rgb (cairo, xr->bg.red, xr->bg.green, xr->bg.blue); cairo_rectangle (cairo, 0, 0, xr->width, xr->length); cairo_fill (cairo); cairo_restore (cairo); -- 1.7.10.4
From b51ab36f5a828654ed03e96c90a1241852f6d70c Mon Sep 17 00:00:00 2001 From: John Darrington <j...@darrington.wattle.id.au> Date: Sat, 19 Oct 2013 14:20:38 +0200 Subject: [PATCH 2/2] Respect forground and background options when writing PNG charts. The default colours for charts in PNG format was black on black, which wasn't very useful. This change makes the defaults black on white. Perhaps for png charts intended for embedding in HTML it should be black on transparent, but this hasn't been implemented in this change. Fixes bugs #40107 and #40208 --- src/output/ascii.c | 12 +++++++++++- src/output/cairo.c | 19 +++++++++---------- src/output/cairo.h | 20 +++++++++++++++++++- src/output/html.c | 11 ++++++++++- 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/output/ascii.c b/src/output/ascii.c index 27b39e3..7de2d05 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -150,6 +150,11 @@ struct ascii_driver enum emphasis_style emphasis; /* How to emphasize text. */ char *chart_file_name; /* Name of files used for charts. */ + /* Colours for charts */ + struct xr_color fg; + struct xr_color bg; + + int width; /* Page width. */ int length; /* Page length minus margins and header. */ bool auto_width; /* Use viewwidth as page width? */ @@ -257,6 +262,9 @@ ascii_create (const char *file_name, enum settings_output_devices device_type, a->auto_length = paper_length < 0; a->length = paper_length - vertical_margins (a); + parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &a->bg); + parse_color (d, o, "foreground-color", "#000000000000", &a->fg); + box = parse_enum (opt (d, o, "box", "ascii"), "ascii", BOX_ASCII, "unicode", BOX_UNICODE, @@ -520,7 +528,9 @@ ascii_submit (struct output_driver *driver, char *file_name; file_name = xr_draw_png_chart (chart_item, a->chart_file_name, - a->chart_cnt++); + a->chart_cnt++, + &a->fg, + &a->bg); if (file_name != NULL) { struct text_item *text_item; diff --git a/src/output/cairo.c b/src/output/cairo.c index cb90125..6db8631 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -110,13 +110,6 @@ struct xr_render_fsm void (*destroy) (struct xr_render_fsm *); }; -struct xr_color -{ - double red; - double green; - double blue; -}; - /* Cairo output driver. */ struct xr_driver { @@ -191,7 +184,7 @@ opt (struct output_driver *d, struct string_map *options, const char *key, Future implementations might allow things like "yellow" and "sky-blue-ultra-brown" */ -static void +void parse_color (struct output_driver *d, struct string_map *options, const char *key, const char *default_value, struct xr_color *color) @@ -1096,7 +1089,10 @@ xr_draw_chart (const struct chart_item *chart_item, cairo_t *cr, char * xr_draw_png_chart (const struct chart_item *item, - const char *file_name_template, int number) + const char *file_name_template, int number, + const struct xr_color *fg, + const struct xr_color *bg + ) { const int width = 640; const int length = 480; @@ -1117,7 +1113,10 @@ xr_draw_png_chart (const struct chart_item *item, surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, length); cr = cairo_create (surface); - cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + cairo_set_source_rgb (cr, bg->red, bg->green, bg->blue); + cairo_paint (cr); + + cairo_set_source_rgb (cr, fg->red, fg->green, fg->blue); xr_draw_chart (item, cr, 0.0, 0.0, width, length); diff --git a/src/output/cairo.h b/src/output/cairo.h index 974acb4..7ed828f 100644 --- a/src/output/cairo.h +++ b/src/output/cairo.h @@ -82,9 +82,27 @@ void xr_driver_output_item (struct xr_driver *, const struct output_item *); bool xr_driver_need_new_page (const struct xr_driver *); bool xr_driver_is_page_blank (const struct xr_driver *); +struct xr_color +{ + double red; + double green; + double blue; +}; + +struct output_driver; +struct string_map; + +void parse_color (struct output_driver *d, struct string_map *options, + const char *key, const char *default_value, + struct xr_color *color); + + /* Render charts with Cairo. */ char *xr_draw_png_chart (const struct chart_item *, - const char *file_name_template, int number); + const char *file_name_template, int number, + const struct xr_color *fg, + const struct xr_color *bg); + #endif /* HAVE_CAIRO */ diff --git a/src/output/html.c b/src/output/html.c index cf9b2da..822c6b5 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -48,6 +48,9 @@ struct html_driver { struct output_driver driver; + struct xr_color fg; + struct xr_color bg; + char *file_name; char *chart_file_name; @@ -102,6 +105,9 @@ html_create (const char *file_name, enum settings_output_devices device_type, html->file = NULL; html->chart_cnt = 1; + parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &html->bg); + parse_color (d, o, "foreground-color", "#000000000000", &html->fg); + html->file = fn_open (html->file_name, "w"); if (html->file == NULL) { @@ -238,7 +244,10 @@ html_submit (struct output_driver *driver, char *file_name; file_name = xr_draw_png_chart (chart_item, html->chart_file_name, - html->chart_cnt++); + html->chart_cnt++, + &html->fg, + &html->bg + ); if (file_name != NULL) { const char *title = chart_item_get_title (chart_item); -- 1.7.10.4
signature.asc
Description: Digital signature
_______________________________________________ pspp-dev mailing list pspp-dev@gnu.org https://lists.gnu.org/mailman/listinfo/pspp-dev