#include <pango/pangocairo.h>
#include <stdlib.h>
-#include "gl/error.h"
#include "gl/intprops.h"
#include "gl/minmax.h"
#include "gl/xalloc.h"
int line_space; /* Space between lines. */
int line_width; /* Width of lines. */
- double bg_red, bg_green, bg_blue; /* Background color */
- double fg_red, fg_green, fg_blue; /* Foreground color */
+ struct xr_color bg; /* Background color */
+ struct xr_color fg; /* Foreground color */
/* Internal state. */
struct render_params *params;
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,
- double *dred, double *dgreen, double *dblue)
+ const char *key, const char *default_value,
+ struct xr_color *color)
{
int red, green, blue;
char *string = parse_string (opt (d, options, key, default_value));
free (string);
/* Convert 16 bit ints to float */
- *dred = red / (double) 0xFFFF;
- *dgreen = green / (double) 0xFFFF;
- *dblue = blue / (double) 0xFFFF;
+ color->red = red / (double) 0xFFFF;
+ color->green = green / (double) 0xFFFF;
+ color->blue = blue / (double) 0xFFFF;
}
static PangoFontDescription *
desc = pango_font_description_from_string (string);
if (desc == NULL)
{
- error (0, 0, _("`%s': bad font specification"), string);
+ msg (MW, _("`%s': bad font specification"), string);
/* Fall back to DEFAULT_VALUE, which had better be a valid font
description. */
xr->line_width = XR_POINT / 2;
xr->page_number = 0;
- parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &xr->bg_red, &xr->bg_green, &xr->bg_blue);
- parse_color (d, o, "foreground-color", "#000000000000", &xr->fg_red, &xr->fg_green, &xr->fg_blue);
+ parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &xr->bg);
+ parse_color (d, o, "foreground-color", "#000000000000", &xr->fg);
parse_paper_size (opt (d, o, "paper-size", ""), &paper_width, &paper_length);
xr->left_margin = parse_dimension (opt (d, o, "left-margin", ".5in"));
}
}
- cairo_set_source_rgb (xr->cairo, xr->fg_red, xr->fg_green, xr->fg_blue);
+ cairo_set_source_rgb (xr->cairo, xr->fg.red, xr->fg.green, xr->fg.blue);
return true;
}
status = cairo_surface_status (surface);
if (status != CAIRO_STATUS_SUCCESS)
{
- error (0, 0, _("error opening output file `%s': %s"),
+ msg (ME, _("error opening output file `%s': %s"),
file_name, cairo_status_to_string (status));
cairo_surface_destroy (surface);
goto error;
if (xr->width / xr->char_width < MIN_WIDTH)
{
- error (0, 0, _("The defined page is not wide enough to hold at least %d "
+ msg (ME, _("The defined page is not wide enough to hold at least %d "
"characters in the default font. In fact, there's only "
"room for %d characters."),
MIN_WIDTH,
if (xr->length / xr->char_height < MIN_LENGTH)
{
- error (0, 0, _("The defined page is not long enough to hold at least %d "
+ msg (ME, _("The defined page is not long enough to hold at least %d "
"lines in the default font. In fact, there's only "
"room for %d lines."),
MIN_LENGTH,
cairo_surface_finish (cairo_get_target (xr->cairo));
status = cairo_status (xr->cairo);
if (status != CAIRO_STATUS_SUCCESS)
- error (0, 0, _("error drawing output for %s driver: %s"),
+ msg (ME, _("error drawing output for %s driver: %s"),
output_driver_get_name (driver),
cairo_status_to_string (status));
cairo_destroy (xr->cairo);
if (cairo != NULL)
{
cairo_save (cairo);
- cairo_set_source_rgb (cairo, xr->bg_red, xr->bg_green, xr->bg_blue);
+ cairo_set_source_rgb (cairo, xr->bg.red, xr->bg.green, xr->bg.blue);
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 char *file_name_template, int number,
+ const struct xr_color *fg,
+ const struct xr_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, 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);
status = cairo_surface_write_to_png (surface, file_name);
if (status != CAIRO_STATUS_SUCCESS)
- error (0, 0, _("error writing output file `%s': %s"),
+ msg (ME, _("error writing output file `%s': %s"),
file_name, cairo_status_to_string (status));
cairo_destroy (cr);