- xr = xzalloc (sizeof *xr);
- d = &xr->driver;
- output_driver_init (d, &cairo_driver_class, name, device_type);
- xr->headers = true;
- xr->font_height = XR_POINT * 10;
- xr->fonts[XR_FONT_FIXED].string
- = parse_string (opt (d, o, "fixed-font", "monospace"));
- xr->fonts[XR_FONT_PROPORTIONAL].string
- = parse_string (opt (d, o, "prop-font", "serif"));
- xr->fonts[XR_FONT_EMPHASIS].string
- = parse_string (opt (d, o, "emph-font", "serif italic"));
- xr->line_gutter = XR_POINT;
+ 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;
+ }
+ }
+
+ 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 *
+parse_font (struct output_driver *d, struct string_map *options,
+ const char *key, const char *default_value,
+ int default_size)
+{
+ PangoFontDescription *desc;
+ char *string;
+
+ /* Parse KEY as a font description. */
+ string = parse_string (opt (d, options, key, default_value));
+ desc = pango_font_description_from_string (string);
+ if (desc == NULL)
+ {
+ msg (MW, _("`%s': bad font specification"), string);
+
+ /* Fall back to DEFAULT_VALUE, which had better be a valid font
+ description. */
+ desc = pango_font_description_from_string (default_value);
+ assert (desc != NULL);
+ }
+ free (string);
+
+ /* If the font description didn't include an explicit font size, then set it
+ to DEFAULT_SIZE, which is in inch/72000 units. */
+ if (!(pango_font_description_get_set_fields (desc) & PANGO_FONT_MASK_SIZE))
+ pango_font_description_set_size (desc,
+ (default_size / 1000.0) * PANGO_SCALE);
+
+ return desc;
+}
+
+
+static void
+apply_options (struct xr_driver *xr, struct string_map *o)
+{
+ struct output_driver *d = &xr->driver;
+
+ /* In inch/72000 units used by parse_paper_size() and parse_dimension(). */
+ int left_margin, right_margin;
+ int top_margin, bottom_margin;
+ int paper_width, paper_length;
+ int font_size;
+ int min_break[TABLE_N_AXES];
+
+ /* Scale factor from inch/72000 to inch/(72 * XR_POINT). */
+ const double scale = XR_POINT / 1000.;
+
+ int i;
+
+ for (i = 0; i < XR_N_FONTS; i++)
+ {
+ struct xr_font *font = &xr->fonts[i];
+
+ if (font->desc != NULL)
+ pango_font_description_free (font->desc);
+ }
+
+ font_size = parse_int (opt (d, o, "font-size", "10000"), 1000, 1000000);
+ xr->fonts[XR_FONT_FIXED].desc = parse_font (d, o, "fixed-font", "monospace",
+ font_size);
+ xr->fonts[XR_FONT_PROPORTIONAL].desc = parse_font (d, o, "prop-font",
+ "serif", font_size);
+ xr->fonts[XR_FONT_EMPHASIS].desc = parse_font (d, o, "emph-font",
+ "serif italic", font_size);
+ xr->fonts[XR_FONT_MARKER].desc = parse_font (d, o, "marker-font", "serif",
+ font_size * PANGO_SCALE_X_SMALL);
+
+ xr->line_gutter = XR_POINT / 2;