Seems like a more natural place for it.
a->min_hbreak = parse_int (opt (d, o, "min-hbreak", "-1"), -1, INT_MAX);
#ifdef HAVE_CAIRO
- parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &a->bg);
- parse_color (d, o, "foreground-color", "#000000000000", &a->fg);
+ a->bg = parse_color (opt (d, o, "background-color", "#FFFFFFFFFFFF"));
+ a->fg = parse_color (opt (d, o, "foreground-color", "#000000000000"));
#endif
const char *default_box = (terminal && (!strcmp (locale_charset (), "UTF-8")
return driver_option_get (d, options, key, default_value);
}
-static int
-lookup_color_name (const char *s)
-{
- struct color
- {
- struct hmap_node hmap_node;
- const char *name;
- int code;
- };
-
- static struct color colors[] =
- {
- { .name = "aliceblue", .code = 0xf0f8ff },
- { .name = "antiquewhite", .code = 0xfaebd7 },
- { .name = "aqua", .code = 0x00ffff },
- { .name = "aquamarine", .code = 0x7fffd4 },
- { .name = "azure", .code = 0xf0ffff },
- { .name = "beige", .code = 0xf5f5dc },
- { .name = "bisque", .code = 0xffe4c4 },
- { .name = "black", .code = 0x000000 },
- { .name = "blanchedalmond", .code = 0xffebcd },
- { .name = "blue", .code = 0x0000ff },
- { .name = "blueviolet", .code = 0x8a2be2 },
- { .name = "brown", .code = 0xa52a2a },
- { .name = "burlywood", .code = 0xdeb887 },
- { .name = "cadetblue", .code = 0x5f9ea0 },
- { .name = "chartreuse", .code = 0x7fff00 },
- { .name = "chocolate", .code = 0xd2691e },
- { .name = "coral", .code = 0xff7f50 },
- { .name = "cornflowerblue", .code = 0x6495ed },
- { .name = "cornsilk", .code = 0xfff8dc },
- { .name = "crimson", .code = 0xdc143c },
- { .name = "cyan", .code = 0x00ffff },
- { .name = "darkblue", .code = 0x00008b },
- { .name = "darkcyan", .code = 0x008b8b },
- { .name = "darkgoldenrod", .code = 0xb8860b },
- { .name = "darkgray", .code = 0xa9a9a9 },
- { .name = "darkgreen", .code = 0x006400 },
- { .name = "darkgrey", .code = 0xa9a9a9 },
- { .name = "darkkhaki", .code = 0xbdb76b },
- { .name = "darkmagenta", .code = 0x8b008b },
- { .name = "darkolivegreen", .code = 0x556b2f },
- { .name = "darkorange", .code = 0xff8c00 },
- { .name = "darkorchid", .code = 0x9932cc },
- { .name = "darkred", .code = 0x8b0000 },
- { .name = "darksalmon", .code = 0xe9967a },
- { .name = "darkseagreen", .code = 0x8fbc8f },
- { .name = "darkslateblue", .code = 0x483d8b },
- { .name = "darkslategray", .code = 0x2f4f4f },
- { .name = "darkslategrey", .code = 0x2f4f4f },
- { .name = "darkturquoise", .code = 0x00ced1 },
- { .name = "darkviolet", .code = 0x9400d3 },
- { .name = "deeppink", .code = 0xff1493 },
- { .name = "deepskyblue", .code = 0x00bfff },
- { .name = "dimgray", .code = 0x696969 },
- { .name = "dimgrey", .code = 0x696969 },
- { .name = "dodgerblue", .code = 0x1e90ff },
- { .name = "firebrick", .code = 0xb22222 },
- { .name = "floralwhite", .code = 0xfffaf0 },
- { .name = "forestgreen", .code = 0x228b22 },
- { .name = "fuchsia", .code = 0xff00ff },
- { .name = "gainsboro", .code = 0xdcdcdc },
- { .name = "ghostwhite", .code = 0xf8f8ff },
- { .name = "gold", .code = 0xffd700 },
- { .name = "goldenrod", .code = 0xdaa520 },
- { .name = "gray", .code = 0x808080 },
- { .name = "green", .code = 0x008000 },
- { .name = "greenyellow", .code = 0xadff2f },
- { .name = "grey", .code = 0x808080 },
- { .name = "honeydew", .code = 0xf0fff0 },
- { .name = "hotpink", .code = 0xff69b4 },
- { .name = "indianred", .code = 0xcd5c5c },
- { .name = "indigo", .code = 0x4b0082 },
- { .name = "ivory", .code = 0xfffff0 },
- { .name = "khaki", .code = 0xf0e68c },
- { .name = "lavender", .code = 0xe6e6fa },
- { .name = "lavenderblush", .code = 0xfff0f5 },
- { .name = "lawngreen", .code = 0x7cfc00 },
- { .name = "lemonchiffon", .code = 0xfffacd },
- { .name = "lightblue", .code = 0xadd8e6 },
- { .name = "lightcoral", .code = 0xf08080 },
- { .name = "lightcyan", .code = 0xe0ffff },
- { .name = "lightgoldenrodyellow", .code = 0xfafad2 },
- { .name = "lightgray", .code = 0xd3d3d3 },
- { .name = "lightgreen", .code = 0x90ee90 },
- { .name = "lightgrey", .code = 0xd3d3d3 },
- { .name = "lightpink", .code = 0xffb6c1 },
- { .name = "lightsalmon", .code = 0xffa07a },
- { .name = "lightseagreen", .code = 0x20b2aa },
- { .name = "lightskyblue", .code = 0x87cefa },
- { .name = "lightslategray", .code = 0x778899 },
- { .name = "lightslategrey", .code = 0x778899 },
- { .name = "lightsteelblue", .code = 0xb0c4de },
- { .name = "lightyellow", .code = 0xffffe0 },
- { .name = "lime", .code = 0x00ff00 },
- { .name = "limegreen", .code = 0x32cd32 },
- { .name = "linen", .code = 0xfaf0e6 },
- { .name = "magenta", .code = 0xff00ff },
- { .name = "maroon", .code = 0x800000 },
- { .name = "mediumaquamarine", .code = 0x66cdaa },
- { .name = "mediumblue", .code = 0x0000cd },
- { .name = "mediumorchid", .code = 0xba55d3 },
- { .name = "mediumpurple", .code = 0x9370db },
- { .name = "mediumseagreen", .code = 0x3cb371 },
- { .name = "mediumslateblue", .code = 0x7b68ee },
- { .name = "mediumspringgreen", .code = 0x00fa9a },
- { .name = "mediumturquoise", .code = 0x48d1cc },
- { .name = "mediumvioletred", .code = 0xc71585 },
- { .name = "midnightblue", .code = 0x191970 },
- { .name = "mintcream", .code = 0xf5fffa },
- { .name = "mistyrose", .code = 0xffe4e1 },
- { .name = "moccasin", .code = 0xffe4b5 },
- { .name = "navajowhite", .code = 0xffdead },
- { .name = "navy", .code = 0x000080 },
- { .name = "oldlace", .code = 0xfdf5e6 },
- { .name = "olive", .code = 0x808000 },
- { .name = "olivedrab", .code = 0x6b8e23 },
- { .name = "orange", .code = 0xffa500 },
- { .name = "orangered", .code = 0xff4500 },
- { .name = "orchid", .code = 0xda70d6 },
- { .name = "palegoldenrod", .code = 0xeee8aa },
- { .name = "palegreen", .code = 0x98fb98 },
- { .name = "paleturquoise", .code = 0xafeeee },
- { .name = "palevioletred", .code = 0xdb7093 },
- { .name = "papayawhip", .code = 0xffefd5 },
- { .name = "peachpuff", .code = 0xffdab9 },
- { .name = "peru", .code = 0xcd853f },
- { .name = "pink", .code = 0xffc0cb },
- { .name = "plum", .code = 0xdda0dd },
- { .name = "powderblue", .code = 0xb0e0e6 },
- { .name = "purple", .code = 0x800080 },
- { .name = "red", .code = 0xff0000 },
- { .name = "rosybrown", .code = 0xbc8f8f },
- { .name = "royalblue", .code = 0x4169e1 },
- { .name = "saddlebrown", .code = 0x8b4513 },
- { .name = "salmon", .code = 0xfa8072 },
- { .name = "sandybrown", .code = 0xf4a460 },
- { .name = "seagreen", .code = 0x2e8b57 },
- { .name = "seashell", .code = 0xfff5ee },
- { .name = "sienna", .code = 0xa0522d },
- { .name = "silver", .code = 0xc0c0c0 },
- { .name = "skyblue", .code = 0x87ceeb },
- { .name = "slateblue", .code = 0x6a5acd },
- { .name = "slategray", .code = 0x708090 },
- { .name = "slategrey", .code = 0x708090 },
- { .name = "snow", .code = 0xfffafa },
- { .name = "springgreen", .code = 0x00ff7f },
- { .name = "steelblue", .code = 0x4682b4 },
- { .name = "tan", .code = 0xd2b48c },
- { .name = "teal", .code = 0x008080 },
- { .name = "thistle", .code = 0xd8bfd8 },
- { .name = "tomato", .code = 0xff6347 },
- { .name = "turquoise", .code = 0x40e0d0 },
- { .name = "violet", .code = 0xee82ee },
- { .name = "wheat", .code = 0xf5deb3 },
- { .name = "white", .code = 0xffffff },
- { .name = "whitesmoke", .code = 0xf5f5f5 },
- { .name = "yellow", .code = 0xffff00 },
- { .name = "yellowgreen", .code = 0x9acd32 },
- };
-
- static struct hmap color_table = HMAP_INITIALIZER (color_table);
-
- if (hmap_is_empty (&color_table))
- for (size_t i = 0; i < sizeof colors / sizeof *colors; i++)
- hmap_insert (&color_table, &colors[i].hmap_node,
- hash_string (colors[i].name, 0));
-
- const struct color *color;
- HMAP_FOR_EACH_WITH_HASH (color, struct color, hmap_node,
- hash_string (s, 0), &color_table)
- if (!strcmp (color->name, s))
- return color->code;
- return -1;
-}
-
-static bool
-parse_color__ (const char *s, struct cell_color *color)
-{
- /* #rrrrggggbbbb */
- uint16_t r16, g16, b16;
- int len;
- if (sscanf (s, "#%4"SCNx16"%4"SCNx16"%4"SCNx16"%n",
- &r16, &g16, &b16, &len) == 3
- && len == 13
- && !s[len])
- {
- color->r = r16 >> 8;
- color->g = g16 >> 8;
- color->b = b16 >> 8;
- return true;
- }
-
- /* #rrggbb */
- uint8_t r, g, b;
- if (sscanf (s, "#%2"SCNx8"%2"SCNx8"%2"SCNx8"%n", &r, &g, &b, &len) == 3
- && len == 7
- && !s[len])
- {
- color->r = r;
- color->g = g;
- color->b = b;
- return true;
- }
-
- /* rrggbb */
- if (sscanf (s, "%2"SCNx8"%2"SCNx8"%2"SCNx8"%n", &r, &g, &b, &len) == 3
- && len == 6
- && !s[len])
- {
- color->r = r;
- color->g = g;
- color->b = b;
- return true;
- }
-
- /* rgb(r,g,b) */
- if (sscanf (s, "rgb (%"SCNi8" , %"SCNi8" , %"SCNi8") %n",
- &r, &g, &b, &len) == 3
- && !s[len])
- {
- color->r = r;
- color->g = g;
- color->b = b;
- return true;
- }
-
- /* rgba(r,g,b,a), ignoring a. */
- if (sscanf (s, "rgba (%"SCNi8" , %"SCNi8" , %"SCNi8", %*f) %n",
- &r, &g, &b, &len) == 3
- && !s[len])
- {
- color->r = r;
- color->g = g;
- color->b = b;
- return true;
- }
-
- int code = lookup_color_name (s);
- if (code >= 0)
- {
- color->r = code >> 16;
- color->g = code >> 8;
- color->b = code;
- return true;
- }
-
- return false;
-}
-
-/* Parse color information specified by KEY into {RED,GREEN,BLUE}.
- Currently, the input string must be of the form "#RRRRGGGGBBBB"
- Future implementations might allow things like "yellow" and
- "sky-blue-ultra-brown"
-*/
-void
-parse_color (struct output_driver *d, struct string_map *options,
- const char *key, const char *default_value,
- struct cell_color *color)
-{
- char *string = parse_string (opt (d, options, key, default_value));
- if (!parse_color__ (string, color) && !parse_color__ (default_value, color))
- *color = (struct cell_color) CELL_COLOR_BLACK;
- free (string);
-}
-
static PangoFontDescription *
parse_font (const char *font, int default_size, bool bold, bool italic)
{
xr->fonts[XR_FONT_EMPHASIS].desc = parse_font_option (
d, o, "emph-font", "sans serif", font_size, false, true);
- parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &xr->bg);
- parse_color (d, o, "foreground-color", "#000000000000", &xr->fg);
+ xr->fg = parse_color (opt (d, o, "foreground-color", "#000000000000"));
+ xr->bg = parse_color (opt (d, o, "background-color", "#FFFFFFFFFFFF"));
xr->transparent = parse_boolean (opt (d, o, "transparent", "false"));
xr->systemcolors = parse_boolean (opt (d, o, "systemcolors", "false"));
bool xr_driver_need_new_page (const struct xr_driver *);
bool xr_driver_is_page_blank (const struct xr_driver *);
-void parse_color (struct output_driver *d, struct string_map *options,
- const char *key, const char *default_value,
- struct cell_color *);
-
-
/* Render charts with Cairo. */
char *xr_draw_png_chart (const struct chart_item *,
const char *file_name_template, int number,
html->file = NULL;
html->chart_cnt = 1;
#ifdef HAVE_CAIRO
- parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &html->bg);
- parse_color (d, o, "foreground-color", "#000000000000", &html->fg);
+ html->bg = parse_color (opt (d, o, "background-color", "#FFFFFFFFFFFF"));
+ html->fg = parse_color (opt (d, o, "foreground-color", "#000000000000"));
#endif
html->file = fn_open (html->handle, "w");
if (html->file == NULL)
#include "output/options.h"
#include <errno.h>
+#include <inttypes.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
+#include "libpspp/hash-functions.h"
+#include "libpspp/hmap.h"
#include "libpspp/str.h"
#include "libpspp/string-map.h"
#include "output/driver-provider.h"
#include "output/measure.h"
+#include "output/table.h"
#include "gl/xalloc.h"
return chart_file_name;
}
+
+static int
+lookup_color_name (const char *s)
+{
+ struct color
+ {
+ struct hmap_node hmap_node;
+ const char *name;
+ int code;
+ };
+
+ static struct color colors[] =
+ {
+ { .name = "aliceblue", .code = 0xf0f8ff },
+ { .name = "antiquewhite", .code = 0xfaebd7 },
+ { .name = "aqua", .code = 0x00ffff },
+ { .name = "aquamarine", .code = 0x7fffd4 },
+ { .name = "azure", .code = 0xf0ffff },
+ { .name = "beige", .code = 0xf5f5dc },
+ { .name = "bisque", .code = 0xffe4c4 },
+ { .name = "black", .code = 0x000000 },
+ { .name = "blanchedalmond", .code = 0xffebcd },
+ { .name = "blue", .code = 0x0000ff },
+ { .name = "blueviolet", .code = 0x8a2be2 },
+ { .name = "brown", .code = 0xa52a2a },
+ { .name = "burlywood", .code = 0xdeb887 },
+ { .name = "cadetblue", .code = 0x5f9ea0 },
+ { .name = "chartreuse", .code = 0x7fff00 },
+ { .name = "chocolate", .code = 0xd2691e },
+ { .name = "coral", .code = 0xff7f50 },
+ { .name = "cornflowerblue", .code = 0x6495ed },
+ { .name = "cornsilk", .code = 0xfff8dc },
+ { .name = "crimson", .code = 0xdc143c },
+ { .name = "cyan", .code = 0x00ffff },
+ { .name = "darkblue", .code = 0x00008b },
+ { .name = "darkcyan", .code = 0x008b8b },
+ { .name = "darkgoldenrod", .code = 0xb8860b },
+ { .name = "darkgray", .code = 0xa9a9a9 },
+ { .name = "darkgreen", .code = 0x006400 },
+ { .name = "darkgrey", .code = 0xa9a9a9 },
+ { .name = "darkkhaki", .code = 0xbdb76b },
+ { .name = "darkmagenta", .code = 0x8b008b },
+ { .name = "darkolivegreen", .code = 0x556b2f },
+ { .name = "darkorange", .code = 0xff8c00 },
+ { .name = "darkorchid", .code = 0x9932cc },
+ { .name = "darkred", .code = 0x8b0000 },
+ { .name = "darksalmon", .code = 0xe9967a },
+ { .name = "darkseagreen", .code = 0x8fbc8f },
+ { .name = "darkslateblue", .code = 0x483d8b },
+ { .name = "darkslategray", .code = 0x2f4f4f },
+ { .name = "darkslategrey", .code = 0x2f4f4f },
+ { .name = "darkturquoise", .code = 0x00ced1 },
+ { .name = "darkviolet", .code = 0x9400d3 },
+ { .name = "deeppink", .code = 0xff1493 },
+ { .name = "deepskyblue", .code = 0x00bfff },
+ { .name = "dimgray", .code = 0x696969 },
+ { .name = "dimgrey", .code = 0x696969 },
+ { .name = "dodgerblue", .code = 0x1e90ff },
+ { .name = "firebrick", .code = 0xb22222 },
+ { .name = "floralwhite", .code = 0xfffaf0 },
+ { .name = "forestgreen", .code = 0x228b22 },
+ { .name = "fuchsia", .code = 0xff00ff },
+ { .name = "gainsboro", .code = 0xdcdcdc },
+ { .name = "ghostwhite", .code = 0xf8f8ff },
+ { .name = "gold", .code = 0xffd700 },
+ { .name = "goldenrod", .code = 0xdaa520 },
+ { .name = "gray", .code = 0x808080 },
+ { .name = "green", .code = 0x008000 },
+ { .name = "greenyellow", .code = 0xadff2f },
+ { .name = "grey", .code = 0x808080 },
+ { .name = "honeydew", .code = 0xf0fff0 },
+ { .name = "hotpink", .code = 0xff69b4 },
+ { .name = "indianred", .code = 0xcd5c5c },
+ { .name = "indigo", .code = 0x4b0082 },
+ { .name = "ivory", .code = 0xfffff0 },
+ { .name = "khaki", .code = 0xf0e68c },
+ { .name = "lavender", .code = 0xe6e6fa },
+ { .name = "lavenderblush", .code = 0xfff0f5 },
+ { .name = "lawngreen", .code = 0x7cfc00 },
+ { .name = "lemonchiffon", .code = 0xfffacd },
+ { .name = "lightblue", .code = 0xadd8e6 },
+ { .name = "lightcoral", .code = 0xf08080 },
+ { .name = "lightcyan", .code = 0xe0ffff },
+ { .name = "lightgoldenrodyellow", .code = 0xfafad2 },
+ { .name = "lightgray", .code = 0xd3d3d3 },
+ { .name = "lightgreen", .code = 0x90ee90 },
+ { .name = "lightgrey", .code = 0xd3d3d3 },
+ { .name = "lightpink", .code = 0xffb6c1 },
+ { .name = "lightsalmon", .code = 0xffa07a },
+ { .name = "lightseagreen", .code = 0x20b2aa },
+ { .name = "lightskyblue", .code = 0x87cefa },
+ { .name = "lightslategray", .code = 0x778899 },
+ { .name = "lightslategrey", .code = 0x778899 },
+ { .name = "lightsteelblue", .code = 0xb0c4de },
+ { .name = "lightyellow", .code = 0xffffe0 },
+ { .name = "lime", .code = 0x00ff00 },
+ { .name = "limegreen", .code = 0x32cd32 },
+ { .name = "linen", .code = 0xfaf0e6 },
+ { .name = "magenta", .code = 0xff00ff },
+ { .name = "maroon", .code = 0x800000 },
+ { .name = "mediumaquamarine", .code = 0x66cdaa },
+ { .name = "mediumblue", .code = 0x0000cd },
+ { .name = "mediumorchid", .code = 0xba55d3 },
+ { .name = "mediumpurple", .code = 0x9370db },
+ { .name = "mediumseagreen", .code = 0x3cb371 },
+ { .name = "mediumslateblue", .code = 0x7b68ee },
+ { .name = "mediumspringgreen", .code = 0x00fa9a },
+ { .name = "mediumturquoise", .code = 0x48d1cc },
+ { .name = "mediumvioletred", .code = 0xc71585 },
+ { .name = "midnightblue", .code = 0x191970 },
+ { .name = "mintcream", .code = 0xf5fffa },
+ { .name = "mistyrose", .code = 0xffe4e1 },
+ { .name = "moccasin", .code = 0xffe4b5 },
+ { .name = "navajowhite", .code = 0xffdead },
+ { .name = "navy", .code = 0x000080 },
+ { .name = "oldlace", .code = 0xfdf5e6 },
+ { .name = "olive", .code = 0x808000 },
+ { .name = "olivedrab", .code = 0x6b8e23 },
+ { .name = "orange", .code = 0xffa500 },
+ { .name = "orangered", .code = 0xff4500 },
+ { .name = "orchid", .code = 0xda70d6 },
+ { .name = "palegoldenrod", .code = 0xeee8aa },
+ { .name = "palegreen", .code = 0x98fb98 },
+ { .name = "paleturquoise", .code = 0xafeeee },
+ { .name = "palevioletred", .code = 0xdb7093 },
+ { .name = "papayawhip", .code = 0xffefd5 },
+ { .name = "peachpuff", .code = 0xffdab9 },
+ { .name = "peru", .code = 0xcd853f },
+ { .name = "pink", .code = 0xffc0cb },
+ { .name = "plum", .code = 0xdda0dd },
+ { .name = "powderblue", .code = 0xb0e0e6 },
+ { .name = "purple", .code = 0x800080 },
+ { .name = "red", .code = 0xff0000 },
+ { .name = "rosybrown", .code = 0xbc8f8f },
+ { .name = "royalblue", .code = 0x4169e1 },
+ { .name = "saddlebrown", .code = 0x8b4513 },
+ { .name = "salmon", .code = 0xfa8072 },
+ { .name = "sandybrown", .code = 0xf4a460 },
+ { .name = "seagreen", .code = 0x2e8b57 },
+ { .name = "seashell", .code = 0xfff5ee },
+ { .name = "sienna", .code = 0xa0522d },
+ { .name = "silver", .code = 0xc0c0c0 },
+ { .name = "skyblue", .code = 0x87ceeb },
+ { .name = "slateblue", .code = 0x6a5acd },
+ { .name = "slategray", .code = 0x708090 },
+ { .name = "slategrey", .code = 0x708090 },
+ { .name = "snow", .code = 0xfffafa },
+ { .name = "springgreen", .code = 0x00ff7f },
+ { .name = "steelblue", .code = 0x4682b4 },
+ { .name = "tan", .code = 0xd2b48c },
+ { .name = "teal", .code = 0x008080 },
+ { .name = "thistle", .code = 0xd8bfd8 },
+ { .name = "tomato", .code = 0xff6347 },
+ { .name = "turquoise", .code = 0x40e0d0 },
+ { .name = "violet", .code = 0xee82ee },
+ { .name = "wheat", .code = 0xf5deb3 },
+ { .name = "white", .code = 0xffffff },
+ { .name = "whitesmoke", .code = 0xf5f5f5 },
+ { .name = "yellow", .code = 0xffff00 },
+ { .name = "yellowgreen", .code = 0x9acd32 },
+ };
+
+ static struct hmap color_table = HMAP_INITIALIZER (color_table);
+
+ if (hmap_is_empty (&color_table))
+ for (size_t i = 0; i < sizeof colors / sizeof *colors; i++)
+ hmap_insert (&color_table, &colors[i].hmap_node,
+ hash_string (colors[i].name, 0));
+
+ const struct color *color;
+ HMAP_FOR_EACH_WITH_HASH (color, struct color, hmap_node,
+ hash_string (s, 0), &color_table)
+ if (!strcmp (color->name, s))
+ return color->code;
+ return -1;
+}
+
+static bool
+parse_color__ (const char *s, struct cell_color *color)
+{
+ /* #rrrrggggbbbb */
+ uint16_t r16, g16, b16;
+ int len;
+ if (sscanf (s, "#%4"SCNx16"%4"SCNx16"%4"SCNx16"%n",
+ &r16, &g16, &b16, &len) == 3
+ && len == 13
+ && !s[len])
+ {
+ color->r = r16 >> 8;
+ color->g = g16 >> 8;
+ color->b = b16 >> 8;
+ return true;
+ }
+
+ /* #rrggbb */
+ uint8_t r, g, b;
+ if (sscanf (s, "#%2"SCNx8"%2"SCNx8"%2"SCNx8"%n", &r, &g, &b, &len) == 3
+ && len == 7
+ && !s[len])
+ {
+ color->r = r;
+ color->g = g;
+ color->b = b;
+ return true;
+ }
+
+ /* rrggbb */
+ if (sscanf (s, "%2"SCNx8"%2"SCNx8"%2"SCNx8"%n", &r, &g, &b, &len) == 3
+ && len == 6
+ && !s[len])
+ {
+ color->r = r;
+ color->g = g;
+ color->b = b;
+ return true;
+ }
+
+ /* rgb(r,g,b) */
+ if (sscanf (s, "rgb (%"SCNi8" , %"SCNi8" , %"SCNi8") %n",
+ &r, &g, &b, &len) == 3
+ && !s[len])
+ {
+ color->r = r;
+ color->g = g;
+ color->b = b;
+ return true;
+ }
+
+ /* rgba(r,g,b,a), ignoring a. */
+ if (sscanf (s, "rgba (%"SCNi8" , %"SCNi8" , %"SCNi8", %*f) %n",
+ &r, &g, &b, &len) == 3
+ && !s[len])
+ {
+ color->r = r;
+ color->g = g;
+ color->b = b;
+ return true;
+ }
+
+ int code = lookup_color_name (s);
+ if (code >= 0)
+ {
+ color->r = code >> 16;
+ color->g = code >> 8;
+ color->b = code;
+ return true;
+ }
+
+ return false;
+}
+
+/* Parses and returns color information from O. */
+struct cell_color
+parse_color (struct driver_option *o)
+{
+ if (o->value)
+ {
+ struct cell_color color;
+ if (parse_color__ (o->value, &color))
+ return color;
+
+ msg (MW, _("%s: `%s' is `%s', which could not be parsed as a color"),
+ o->driver_name, o->name, o->value);
+ }
+
+ struct cell_color color;
+ if (parse_color__ (o->default_value, &color))
+ return color;
+
+ return (struct cell_color) CELL_COLOR_BLACK;
+}
+
int parse_dimension (struct driver_option *);
char *parse_string (struct driver_option *);
char *parse_chart_file_name (struct driver_option *);
+struct cell_color parse_color (struct driver_option *);
#endif /* output/options.h */
fh_get_file_name (fh)));
tex->chart_cnt = 1;
#ifdef HAVE_CAIRO
- parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &tex->bg);
- parse_color (d, o, "foreground-color", "#000000000000", &tex->fg);
+ tex->bg = parse_color (opt (d, o, "background-color", "#FFFFFFFFFFFF"));
+ tex->fg = parse_color (opt (d, o, "foreground-color", "#000000000000"));
#endif
tex->file = fn_open (tex->handle, "w");