From b51ab36f5a828654ed03e96c90a1241852f6d70c Mon Sep 17 00:00:00 2001 From: John Darrington 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