diff options
author | Marek Kasik <mkasik@redhat.com> | 2009-08-03 11:25:19 +0200 |
---|---|---|
committer | Marek Kasik <mkasik@redhat.com> | 2009-08-03 11:25:19 +0200 |
commit | 39b960216c91dba2af2730e0e49893af155b0bfc (patch) | |
tree | 76fe84e6d72db5c216497c99fcdd6c7524c1dc85 /modules | |
parent | f29b9e2dafc458f88837e4484b729ed10b92dbb5 (diff) | |
download | gtk+-39b960216c91dba2af2730e0e49893af155b0bfc.tar.gz |
Add SVG support to GtkPrintBackendFile
This add support for printing to SVG 1.2 files (#357655).
Diffstat (limited to 'modules')
-rw-r--r-- | modules/printbackends/file/gtkprintbackendfile.c | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/modules/printbackends/file/gtkprintbackendfile.c b/modules/printbackends/file/gtkprintbackendfile.c index 7bdaaa7b99..bc58751e01 100644 --- a/modules/printbackends/file/gtkprintbackendfile.c +++ b/modules/printbackends/file/gtkprintbackendfile.c @@ -32,6 +32,7 @@ #include <cairo.h> #include <cairo-pdf.h> #include <cairo-ps.h> +#include <cairo-svg.h> #include <glib/gi18n-lib.h> @@ -64,13 +65,15 @@ typedef enum { FORMAT_PDF, FORMAT_PS, + FORMAT_SVG, N_FORMATS } OutputFormat; static const gchar* formats[N_FORMATS] = { "pdf", - "ps" + "ps", + "svg" }; static GObjectClass *backend_parent_class; @@ -228,7 +231,19 @@ output_file_from_settings (GtkPrintSettings *settings, OutputFormat format; format = format_from_settings (settings); - extension = format == FORMAT_PS ? "ps" : "pdf"; + switch (format) + { + default: + case FORMAT_PDF: + extension = "pdf"; + break; + case FORMAT_PS: + extension = "ps"; + break; + case FORMAT_SVG: + extension = "svg"; + break; + } } /* default filename used for print-to-file */ @@ -298,13 +313,27 @@ file_printer_create_cairo_surface (GtkPrinter *printer, { cairo_surface_t *surface; OutputFormat format; + const cairo_svg_version_t *versions; + int num_versions = 0; format = format_from_settings (settings); - if (format == FORMAT_PS) - surface = cairo_ps_surface_create_for_stream (_cairo_write, cache_io, width, height); - else - surface = cairo_pdf_surface_create_for_stream (_cairo_write, cache_io, width, height); + switch (format) + { + default: + case FORMAT_PDF: + surface = cairo_pdf_surface_create_for_stream (_cairo_write, cache_io, width, height); + break; + case FORMAT_PS: + surface = cairo_ps_surface_create_for_stream (_cairo_write, cache_io, width, height); + break; + case FORMAT_SVG: + surface = cairo_svg_surface_create_for_stream (_cairo_write, cache_io, width, height); + cairo_svg_get_versions (&versions, &num_versions); + if (num_versions > 0) + cairo_svg_surface_restrict_to_version (surface, versions[num_versions - 1]); + break; + } if (gtk_print_settings_get_printer_lpi (settings) == 0.0) gtk_print_settings_set_printer_lpi (settings, 150.0); @@ -543,7 +572,7 @@ file_printer_get_options (GtkPrinter *printer, GtkPrinterOption *option; const gchar *n_up[] = {"1", "2", "4", "6", "9", "16" }; const gchar *pages_per_sheet = NULL; - const gchar *format_names[N_FORMATS] = { N_("PDF"), N_("Postscript") }; + const gchar *format_names[N_FORMATS] = { N_("PDF"), N_("Postscript"), N_("SVG") }; const gchar *supported_formats[N_FORMATS]; gchar *display_format_names[N_FORMATS]; gint n_formats = 0; @@ -591,7 +620,20 @@ file_printer_get_options (GtkPrinter *printer, } else { - current_format = format == FORMAT_PS ? FORMAT_PS : FORMAT_PDF; + switch (format) + { + default: + case FORMAT_PDF: + current_format = FORMAT_PDF; + break; + case FORMAT_PS: + current_format = FORMAT_PS; + break; + case FORMAT_SVG: + current_format = FORMAT_SVG; + break; + } + for (n_formats = 0; n_formats < N_FORMATS; ++n_formats) { supported_formats[n_formats] = formats[n_formats]; |