Respect forground and background options when writing PNG charts.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 19 Oct 2013 12:20:38 +0000 (14:20 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 19 Oct 2013 12:20:38 +0000 (14:20 +0200)
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
src/output/cairo.c
src/output/cairo.h
src/output/html.c

index 27b39e34e53e13fe216dda0e6e295340ec53b209..7de2d0523a5942dfabcc20bf4ae743c9ba6dfb59 100644 (file)
@@ -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;
index cb901258d3acaaf8f760d371f7fc6010a31de98c..6db86317d893447012f2e7cfd16bb069948c893e 100644 (file)
@@ -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);
 
index 974acb444e5f6e191896fad3036891dfc159bb94..7ed828f515d61b24d7c5153cde9dc831dd7d44fe 100644 (file)
@@ -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 */
 
index cf9b2da3c11cc8077850fd6c5aeabd085b38beed..822c6b5c9b8f9c6c6844a49760f405f26e4694d7 100644 (file)
@@ -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);