/* PSPP - a program for statistical analysis.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
int y;
};
+static const struct output_driver_class cairo_driver_class;
+
static void xr_show_page (struct xr_driver *);
static void draw_headers (struct xr_driver *);
static struct xr_driver *
xr_driver_cast (struct output_driver *driver)
{
- assert (driver->class == &cairo_class);
+ assert (driver->class == &cairo_driver_class);
return UP_CAST (driver, struct xr_driver, driver);
}
xr = xzalloc (sizeof *xr);
d = &xr->driver;
- output_driver_init (d, &cairo_class, name, device_type);
+ 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
}
static struct output_driver *
-xr_create (const char *name, enum output_device_type device_type,
- struct string_map *o)
+xr_create (const char *file_name, enum settings_output_devices device_type,
+ struct string_map *o, enum xr_output_type file_type)
{
- enum { MIN_LENGTH = 3 };
+ enum { MIN_WIDTH = 3, MIN_LENGTH = 3 };
struct output_driver *d;
struct xr_driver *xr;
cairo_surface_t *surface;
cairo_status_t status;
double width_pt, length_pt;
int paper_width, paper_length;
- char *file_name;
- xr = xr_allocate (name, device_type, o);
+ xr = xr_allocate (file_name, device_type, o);
d = &xr->driver;
xr->headers = parse_boolean (opt (d, o, "headers", "true"));
- xr->file_type = parse_enum (opt (d, o, "output-type", "pdf"),
- "pdf", XR_PDF,
- "ps", XR_PS,
- "svg", XR_SVG,
- (char *) NULL);
- file_name = parse_string (opt (d, o, "output-file",
- (xr->file_type == XR_PDF ? "pspp.pdf"
- : xr->file_type == XR_PS ? "pspp.ps"
- : "pspp.svg")));
+ xr->file_type = file_type;
parse_paper_size (opt (d, o, "paper-size", ""), &paper_width, &paper_length);
xr->left_margin = parse_dimension (opt (d, o, "left-margin", ".5in"));
if (!xr_set_cairo (xr, xr->cairo))
goto error;
+ if (xr->width / (xr->font_height / 2) < MIN_WIDTH)
+ {
+ error (0, 0, _("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,
+ xr->width / (xr->font_height / 2));
+ goto error;
+ }
+
if (xr->length / xr->font_height < MIN_LENGTH)
{
error (0, 0, _("The defined page is not long "
goto error;
}
- free (file_name);
return &xr->driver;
error:
return NULL;
}
+static struct output_driver *
+xr_pdf_create (const char *file_name, enum settings_output_devices device_type,
+ struct string_map *o)
+{
+ return xr_create (file_name, device_type, o, XR_PDF);
+}
+
+static struct output_driver *
+xr_ps_create (const char *file_name, enum settings_output_devices device_type,
+ struct string_map *o)
+{
+ return xr_create (file_name, device_type, o, XR_PS);
+}
+
+static struct output_driver *
+xr_svg_create (const char *file_name, enum settings_output_devices device_type,
+ struct string_map *o)
+{
+ return xr_create (file_name, device_type, o, XR_SVG);
+}
+
static void
xr_destroy (struct output_driver *driver)
{
{
struct table_item *item;
- item = table_item_create (table_from_string (0, text), NULL);
+ item = table_item_create (table_from_string (TAB_LEFT, text),
+ NULL);
xr_submit (&xr->driver, &item->output_item);
table_item_unref (item);
}
if (font->desc != NULL)
pango_font_description_free (font->desc);
pango_font_metrics_unref (font->metrics);
- g_object_unref (font->layout);
+ if (font->layout != NULL)
+ g_object_unref (font->layout);
}
-/* Cairo driver class. */
-const struct output_driver_class cairo_class =
+struct output_driver_factory pdf_driver_factory = { "pdf", xr_pdf_create };
+struct output_driver_factory ps_driver_factory = { "ps", xr_ps_create };
+struct output_driver_factory svg_driver_factory = { "svg", xr_svg_create };
+
+static const struct output_driver_class cairo_driver_class =
{
"cairo",
- xr_create,
xr_destroy,
xr_submit,
xr_flush,
const char *text = text_item_get_text (text_item);
struct table_item *table_item;
- table_item = table_item_create (table_from_string (0, text), NULL);
+ table_item = table_item_create (table_from_string (TAB_LEFT, text),
+ NULL);
r = xr_rendering_create (xr, &table_item->output_item, cr);
table_item_unref (table_item);
}