+static PangoFontDescription *
+parse_font (const char *font, int default_size, bool bold, bool italic)
+{
+ if (!c_strcasecmp (font, "Monospaced"))
+ font = "Monospace";
+
+ PangoFontDescription *desc = pango_font_description_from_string (font);
+ if (desc == NULL)
+ return NULL;
+
+ /* 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);
+
+ pango_font_description_set_weight (desc, (bold
+ ? PANGO_WEIGHT_BOLD
+ : PANGO_WEIGHT_NORMAL));
+ pango_font_description_set_style (desc, (italic
+ ? PANGO_STYLE_ITALIC
+ : PANGO_STYLE_NORMAL));
+
+ return desc;
+}
+
+static PangoFontDescription *
+parse_font_option (struct output_driver *d, struct string_map *options,
+ const char *key, const char *default_value,
+ int default_size, bool bold, bool italic)
+{
+ char *string = parse_string (opt (d, options, key, default_value));
+ PangoFontDescription *desc = parse_font (string, default_size, bold, italic);
+ if (!desc)
+ {
+ msg (MW, _("`%s': bad font specification"), string);
+
+ /* Fall back to DEFAULT_VALUE, which had better be a valid font
+ description. */
+ desc = parse_font (default_value, default_size, bold, italic);
+ assert (desc != NULL);
+ }
+ free (string);
+
+ 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++)
+ if (xr->fonts[i] != NULL)
+ pango_font_description_free (xr->fonts[i]);
+
+ font_size = parse_int (opt (d, o, "font-size", "10000"), 1000, 1000000);
+ xr->fonts[XR_FONT_FIXED] = parse_font_option
+ (d, o, "fixed-font", "monospace", font_size, false, false);
+ xr->fonts[XR_FONT_PROPORTIONAL] = parse_font_option (
+ d, o, "prop-font", "sans serif", font_size, false, false);
+
+ 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"));
+
+ /* Get dimensions. */
+ parse_paper_size (opt (d, o, "paper-size", ""), &paper_width, &paper_length);
+ left_margin = parse_dimension (opt (d, o, "left-margin", ".5in"));
+ right_margin = parse_dimension (opt (d, o, "right-margin", ".5in"));
+ top_margin = parse_dimension (opt (d, o, "top-margin", ".5in"));
+ bottom_margin = parse_dimension (opt (d, o, "bottom-margin", ".5in"));
+
+ min_break[H] = parse_dimension (opt (d, o, "min-hbreak", NULL)) * scale;
+ min_break[V] = parse_dimension (opt (d, o, "min-vbreak", NULL)) * scale;
+
+ int object_spacing = (parse_dimension (opt (d, o, "object-spacing", NULL))
+ * scale);
+
+ /* Convert to inch/(XR_POINT * 72). */
+ xr->left_margin = left_margin * scale;
+ xr->right_margin = right_margin * scale;
+ xr->top_margin = top_margin * scale;
+ xr->bottom_margin = bottom_margin * scale;
+ xr->width = (paper_width - left_margin - right_margin) * scale;
+ xr->length = (paper_length - top_margin - bottom_margin) * scale;
+ xr->min_break[H] = min_break[H] >= 0 ? min_break[H] : xr->width / 2;
+ xr->min_break[V] = min_break[V] >= 0 ? min_break[V] : xr->length / 2;
+ xr->object_spacing = object_spacing >= 0 ? object_spacing : XR_POINT * 12;
+
+ /* There are no headings so headings_height can stay 0. */
+}
+