#include "libpspp/assertion.h"
#include "libpspp/cast.h"
+#include "libpspp/hash-functions.h"
#include "libpspp/message.h"
#include "libpspp/pool.h"
#include "libpspp/start-date.h"
#include <cairo/cairo-ps.h>
#include <cairo/cairo-svg.h>
#include <cairo/cairo.h>
+#include <inttypes.h>
#include <math.h>
#include <pango/pango-font.h>
#include <pango/pango-layout.h>
int min_break[TABLE_N_AXES]; /* Min cell size to break across pages. */
int object_spacing; /* Space between output objects. */
- struct xr_color bg; /* Background color */
- struct xr_color fg; /* Foreground color */
+ struct cell_color bg; /* Background color */
+ struct cell_color fg; /* Foreground color */
int initial_page_number;
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
void
parse_color (struct output_driver *d, struct string_map *options,
const char *key, const char *default_value,
- struct xr_color *color)
+ struct cell_color *color)
{
- int red, green, blue;
char *string = parse_string (opt (d, options, key, default_value));
-
- if (3 != sscanf (string, "#%04x%04x%04x", &red, &green, &blue))
- {
- /* If the parsed option string fails, then try the default value */
- if ( 3 != sscanf (default_value, "#%04x%04x%04x", &red, &green, &blue))
- {
- /* ... and if that fails set everything to zero */
- red = green = blue = 0;
- }
- }
-
+ if (!parse_color__ (string, color) && !parse_color__ (default_value, color))
+ *color = (struct cell_color) CELL_COLOR_BLACK;
free (string);
-
- /* Convert 16 bit ints to float */
- color->red = red / (double) 0xFFFF;
- color->green = green / (double) 0xFFFF;
- color->blue = blue / (double) 0xFFFF;
}
static PangoFontDescription *
xr->params->rtl = render_direction_rtl ();
}
- cairo_set_source_rgb (xr->cairo, xr->fg.red, xr->fg.green, xr->fg.blue);
+ cairo_set_source_rgb (xr->cairo,
+ xr->fg.r / 255.0, xr->fg.g / 255.0, xr->fg.b / 255.0);
}
static struct output_driver *
xr_driver_next_page (struct xr_driver *xr, cairo_t *cairo)
{
cairo_save (cairo);
- cairo_set_source_rgb (cairo, xr->bg.red, xr->bg.green, xr->bg.blue);
+ cairo_set_source_rgb (cairo,
+ xr->bg.r / 255.0, xr->bg.g / 255.0, xr->bg.b / 255.0);
cairo_rectangle (cairo, 0, 0, xr->width, xr->length);
cairo_fill (cairo);
cairo_restore (cairo);
char *
xr_draw_png_chart (const struct chart_item *item,
const char *file_name_template, int number,
- const struct xr_color *fg,
- const struct xr_color *bg
- )
+ const struct cell_color *fg,
+ const struct cell_color *bg)
{
const int width = 640;
const int length = 480;
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, length);
cr = cairo_create (surface);
- cairo_set_source_rgb (cr, bg->red, bg->green, bg->blue);
+ cairo_set_source_rgb (cr, bg->r / 255.0, bg->g / 255.0, bg->b / 255.0);
cairo_paint (cr);
- cairo_set_source_rgb (cr, fg->red, fg->green, fg->blue);
+ cairo_set_source_rgb (cr, fg->r / 255.0, fg->g / 255.0, fg->b / 255.0);
xr_draw_chart (item, cr, 0.0, 0.0, width, length);
string_map_replace (&xr->heading_vars, "PageTitle", text);
break;
- case TEXT_ITEM_BLANK_LINE:
- if (xr->y > 0)
- xr->y += xr->char_height;
- break;
-
case TEXT_ITEM_EJECT_PAGE:
if (xr->y > 0)
return xr_render_eject ();
const struct message_item *message_item)
{
char *s = msg_to_string (message_item_get_msg (message_item));
- struct text_item *item = text_item_create (TEXT_ITEM_PARAGRAPH, s);
+ struct text_item *item = text_item_create (TEXT_ITEM_LOG, s);
free (s);
return xr_render_table (xr, text_item_to_table_item (item));
}