+/* Output driver basics. */
+
+static struct xr_driver *
+xr_driver_cast (struct output_driver *driver)
+{
+ assert (driver->class == &cairo_driver_class);
+ return UP_CAST (driver, struct xr_driver, driver);
+}
+
+static struct driver_option *
+opt (struct output_driver *d, struct string_map *options, const char *key,
+ const char *default_value)
+{
+ return driver_option_get (d, options, key, default_value);
+}
+
+static PangoFontDescription *
+parse_font (struct output_driver *d, struct string_map *options,
+ const char *key, const char *default_value,
+ int default_points)
+{
+ 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)
+ {
+ error (0, 0, _("`%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_POINTS. */
+ if (!(pango_font_description_get_set_fields (desc) & PANGO_FONT_MASK_SIZE))
+ pango_font_description_set_size (desc,
+ default_points / 1000.0 * PANGO_SCALE);
+
+ return desc;
+}
+
+static struct xr_driver *
+xr_allocate (const char *name, int device_type, struct string_map *o)
+{
+ int paper_width, paper_length;
+ struct output_driver *d;
+ struct xr_driver *xr;
+ int font_points;
+
+ xr = xzalloc (sizeof *xr);
+ d = &xr->driver;
+ output_driver_init (d, &cairo_driver_class, name, device_type);
+
+ font_points = parse_int (opt (d, o, "font-size", "10000"),
+ 1000, 1000000);
+ xr->fonts[XR_FONT_FIXED].desc = parse_font (d, o, "fixed-font", "monospace",
+ font_points);
+ xr->fonts[XR_FONT_PROPORTIONAL].desc = parse_font (d, o, "prop-font",
+ "serif", font_points);
+ xr->fonts[XR_FONT_EMPHASIS].desc = parse_font (d, o, "emph-font",
+ "serif italic", font_points);
+
+ xr->line_gutter = XR_POINT;
+ xr->line_space = XR_POINT;
+ xr->line_width = XR_POINT / 2;
+ xr->page_number = 0;
+
+ parse_paper_size (opt (d, o, "paper-size", ""), &paper_width, &paper_length);
+ xr->left_margin = parse_dimension (opt (d, o, "left-margin", ".5in"));
+ xr->right_margin = parse_dimension (opt (d, o, "right-margin", ".5in"));
+ xr->top_margin = parse_dimension (opt (d, o, "top-margin", ".5in"));
+ xr->bottom_margin = parse_dimension (opt (d, o, "bottom-margin", ".5in"));
+
+ xr->width = paper_width - xr->left_margin - xr->right_margin;
+ xr->length = paper_length - xr->top_margin - xr->bottom_margin;
+
+ return xr;
+}