From f8d14d07de8db5ba5aa1377650a69532ff744552 Mon Sep 17 00:00:00 2001
From: Ben Pfaff <blp@gnu.org>
Date: Tue, 28 Jul 2009 06:41:06 -0700
Subject: [PATCH] charts: Use numeric colors instead of color names.

Cairo doesn't support color names, so this will ease the transition.
---
 src/output/chart-provider.h     | 10 +++++++++-
 src/output/chart.c              |  7 +++++--
 src/output/charts/box-whisker.c |  5 ++++-
 src/output/charts/piechart.c    |  8 ++++----
 src/output/charts/plot-chart.c  | 20 ++++++++++----------
 src/output/charts/plot-chart.h  | 11 +++++------
 src/output/charts/plot-hist.c   |  5 ++++-
 7 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/src/output/chart-provider.h b/src/output/chart-provider.h
index 4b36c55a14..2ff4aafafd 100644
--- a/src/output/chart-provider.h
+++ b/src/output/chart-provider.h
@@ -18,8 +18,16 @@
 #define OUTPUT_CHART_PROVIDER_H 1
 
 #include <stdbool.h>
+#include <stdint.h>
 #include <output/chart.h>
 
+struct chart_colour
+  {
+    uint8_t red;
+    uint8_t green;
+    uint8_t blue;
+  };
+
 struct chart_class
   {
     void (*draw) (const struct chart *, plPlotter *);
@@ -57,7 +65,7 @@ struct chart_geometry
     /* Default font size for the plot (if zero, then use plotter default) */
     int font_size;
 
-    char fill_colour[10];
+    struct chart_colour fill_colour;
 
     /* Stuff Particular to Cartesians (and Boxplots ) */
     double ordinate_scale;
diff --git a/src/output/chart.c b/src/output/chart.c
index 2a2bc12451..8d99f41fd0 100644
--- a/src/output/chart.c
+++ b/src/output/chart.c
@@ -58,7 +58,7 @@ chart_geometry_init (plPlotter *lp, struct chart_geometry *geom)
 
   /* Set line thickness. */
   pl_flinewidth_r (lp, 0.25);
-  pl_pencolorname_r (lp, "black");
+  pl_pencolor_r (lp, 0, 0, 0);
 
   /* Erase graphics display. */
   pl_erase_r (lp);
@@ -77,7 +77,10 @@ chart_geometry_init (plPlotter *lp, struct chart_geometry *geom)
   geom->legend_left = 810;
   geom->legend_right = 1000;
   geom->font_size = 0;
-  strcpy (geom->fill_colour, "red");
+
+  geom->fill_colour.red = 255;
+  geom->fill_colour.green = 0;
+  geom->fill_colour.blue = 0;
 
   /* Get default font size */
   if (!geom->font_size)
diff --git a/src/output/charts/box-whisker.c b/src/output/charts/box-whisker.c
index 301d762b8b..24b2914593 100644
--- a/src/output/charts/box-whisker.c
+++ b/src/output/charts/box-whisker.c
@@ -142,7 +142,10 @@ boxplot_draw_box (plPlotter *lp, const struct chart_geometry *geom,
 
   /* Draw the box */
   pl_savestate_r (lp);
-  pl_fillcolorname_r (lp, geom->fill_colour);
+  pl_fillcolor_r (lp,
+                  geom->fill_colour.red * 257,
+                  geom->fill_colour.green * 257,
+                  geom->fill_colour.blue * 257);
   pl_filltype_r (lp,1);
   pl_fbox_r (lp,
 	    box_left,
diff --git a/src/output/charts/piechart.c b/src/output/charts/piechart.c
index 4b7b1400e9..94881b417a 100644
--- a/src/output/charts/piechart.c
+++ b/src/output/charts/piechart.c
@@ -48,7 +48,7 @@ draw_segment(plPlotter *,
 	     double centre_x, double centre_y,
 	     double radius,
 	     double start_angle, double segment_angle,
-	     const char *colour) ;
+	     const struct chart_colour *) ;
 
 
 
@@ -121,7 +121,7 @@ piechart_draw (const struct chart *chart, plPlotter *lp)
       draw_segment (lp,
                     centre_x, centre_y, radius,
                     angle, segment_angle,
-                    data_colour[i % N_CHART_COLOURS]);
+                    &data_colour[i % N_CHART_COLOURS]);
 
       /* Now add the labels */
       if ( label_x < centre_x )
@@ -197,7 +197,7 @@ draw_segment(plPlotter *lp,
 	     double x0, double y0,
 	     double radius,
 	     double start_angle, double segment_angle,
-	     const char *colour)
+	     const struct chart_colour *colour)
 {
   const double start_x  = x0 - radius * sin(start_angle);
   const double start_y  = y0 + radius * cos(start_angle);
@@ -205,7 +205,7 @@ draw_segment(plPlotter *lp,
   pl_savestate_r(lp);
 
   pl_savestate_r(lp);
-  pl_colorname_r(lp, colour);
+  pl_color_r(lp, colour->red * 257, colour->green * 257, colour->blue * 257);
 
   pl_pentype_r(lp,1);
   pl_filltype_r(lp,1);
diff --git a/src/output/charts/plot-chart.c b/src/output/charts/plot-chart.c
index 86e1c80f44..9d298cd26a 100644
--- a/src/output/charts/plot-chart.c
+++ b/src/output/charts/plot-chart.c
@@ -35,17 +35,17 @@
 
 #include "xalloc.h"
 
-const char *const data_colour[N_CHART_COLOURS] =
+const struct chart_colour data_colour[N_CHART_COLOURS] =
   {
-    "brown",
-    "red",
-    "orange",
-    "yellow",
-    "green",
-    "blue",
-    "violet",
-    "grey",
-    "pink"
+    { 165, 42, 42 },            /* brown */
+    { 255, 0, 0 },              /* red */
+    { 255, 165, 0 },            /* orange */
+    { 255, 255, 0 },            /* yellow */
+    { 0, 255, 0 },              /* green */
+    { 0, 0, 255 },              /* blue */
+    { 238, 130, 238 },          /* violet */
+    { 190, 190, 190 },          /* grey */
+    { 255, 192, 203 },          /* pink */
   };
 
 
diff --git a/src/output/charts/plot-chart.h b/src/output/charts/plot-chart.h
index 59d385bb56..e425987b9a 100644
--- a/src/output/charts/plot-chart.h
+++ b/src/output/charts/plot-chart.h
@@ -14,6 +14,9 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
+#ifndef PLOT_CHART_H
+#define PLOT_CHART_H
+
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
@@ -25,19 +28,15 @@
 
 #include <math/chart-geometry.h>
 #include <output/chart.h>
+#include <output/chart-provider.h>
 
 #include <libpspp/compiler.h>
 #include <libpspp/str.h>
 #include <output/manager.h>
 #include <output/output.h>
 
-#include "xalloc.h"
-
-#ifndef PLOT_CHART_H
-#define PLOT_CHART_H
-
 #define N_CHART_COLOURS 9
-extern const char *const data_colour[];
+extern const struct chart_colour data_colour[];
 
 enum tick_orientation
   {
diff --git a/src/output/charts/plot-hist.c b/src/output/charts/plot-hist.c
index d647dd71fe..0e52889f0c 100644
--- a/src/output/charts/plot-hist.c
+++ b/src/output/charts/plot-hist.c
@@ -96,7 +96,10 @@ hist_draw_bar (plPlotter *lp, const struct chart_geometry *geom,
 
   pl_savestate_r (lp);
   pl_move_r (lp,geom->data_left, geom->data_bottom);
-  pl_fillcolorname_r (lp, geom->fill_colour);
+  pl_fillcolor_r (lp,
+                  geom->fill_colour.red * 257,
+                  geom->fill_colour.green * 257,
+                  geom->fill_colour.blue * 257);
   pl_filltype_r (lp,1);
 
 
-- 
2.30.2