mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-08 17:50:10 +00:00
Merge branch 'iss-5072' into 'main'
gtk/print/gtkprintoperation{,-unix,-portal}.c: add CAIRO_HAS checks Closes #5072 See merge request GNOME/gtk!7717
This commit is contained in:
commit
a50df37d52
@ -4862,7 +4862,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
if (surface != NULL)
|
||||
{
|
||||
array = g_byte_array_new ();
|
||||
#if CAIRO_HAS_PNG_FUNCTIONS
|
||||
cairo_surface_write_to_png_stream (surface, cairo_write_array, array);
|
||||
#endif
|
||||
|
||||
_indent (p);
|
||||
g_string_append (p->str, "pixels: url(\"data:image/png;base64,\\\n");
|
||||
|
@ -24,8 +24,13 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <cairo.h>
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
#include <cairo-pdf.h>
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
#include <cairo-ps.h>
|
||||
#endif
|
||||
|
||||
#include <gio/gunixfdlist.h>
|
||||
|
||||
@ -147,6 +152,7 @@ portal_start_page (GtkPrintOperation *op,
|
||||
{
|
||||
if (type == CAIRO_SURFACE_TYPE_PS)
|
||||
{
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
cairo_ps_surface_set_size (op_portal->surface, w, h);
|
||||
cairo_ps_surface_dsc_begin_page_setup (op_portal->surface);
|
||||
switch (gtk_page_setup_get_orientation (page_setup))
|
||||
@ -164,15 +170,18 @@ portal_start_page (GtkPrintOperation *op,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (type == CAIRO_SURFACE_TYPE_PDF)
|
||||
{
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
if (!op->priv->manual_orientation)
|
||||
{
|
||||
w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
|
||||
h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
|
||||
}
|
||||
cairo_pdf_surface_set_size (op_portal->surface, w, h);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +36,13 @@
|
||||
#include "gtkprintoperation-private.h"
|
||||
#include "gtkprintoperation-portal.h"
|
||||
|
||||
#include <cairo.h>
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
#include <cairo-pdf.h>
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
#include <cairo-ps.h>
|
||||
#endif
|
||||
#include "gtkprintunixdialog.h"
|
||||
#include "gtkpagesetupunixdialog.h"
|
||||
#include "gtkprintbackendprivate.h"
|
||||
@ -90,6 +95,7 @@ unix_start_page (GtkPrintOperation *op,
|
||||
{
|
||||
if (type == CAIRO_SURFACE_TYPE_PS)
|
||||
{
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
cairo_ps_surface_set_size (op_unix->surface, w, h);
|
||||
cairo_ps_surface_dsc_begin_page_setup (op_unix->surface);
|
||||
switch (gtk_page_setup_get_orientation (page_setup))
|
||||
@ -106,15 +112,18 @@ unix_start_page (GtkPrintOperation *op,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (type == CAIRO_SURFACE_TYPE_PDF)
|
||||
{
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
if (!op->priv->manual_orientation)
|
||||
{
|
||||
w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
|
||||
h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
|
||||
}
|
||||
cairo_pdf_surface_set_size (op_unix->surface, w, h);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -746,6 +755,7 @@ gtk_print_operation_unix_run_dialog_async (GtkPrintOperation *op,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
static cairo_status_t
|
||||
write_preview (void *closure,
|
||||
const unsigned char *data,
|
||||
@ -817,6 +827,7 @@ gtk_print_operation_unix_create_preview_surface (GtkPrintOperation *op,
|
||||
|
||||
return surface;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gtk_print_operation_unix_preview_start_page (GtkPrintOperation *op,
|
||||
@ -838,11 +849,13 @@ gtk_print_operation_unix_resize_preview_surface (GtkPrintOperation *op,
|
||||
GtkPageSetup *page_setup,
|
||||
cairo_surface_t *surface)
|
||||
{
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
double w, h;
|
||||
|
||||
w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
|
||||
h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
|
||||
cairo_pdf_surface_set_size (surface, w, h);
|
||||
#endif
|
||||
}
|
||||
|
||||
static GtkPrintOperationResult
|
||||
@ -1292,7 +1305,11 @@ _gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation
|
||||
double *dpi_y,
|
||||
char **target)
|
||||
{
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
return gtk_print_operation_unix_create_preview_surface (op, page_setup, dpi_x, dpi_y, target);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -23,7 +23,10 @@
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cairo.h>
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
#include <cairo-pdf.h>
|
||||
#endif
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include "gtkmarshalers.h"
|
||||
@ -1953,6 +1956,7 @@ create_page_setup (GtkPrintOperation *op)
|
||||
return page_setup;
|
||||
}
|
||||
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
static void
|
||||
pdf_start_page (GtkPrintOperation *op,
|
||||
GtkPrintContext *print_context,
|
||||
@ -2063,7 +2067,7 @@ run_pdf (GtkPrintOperation *op,
|
||||
|
||||
return GTK_PRINT_OPERATION_RESULT_APPLY;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void
|
||||
clamp_page_ranges (PrintPagesData *data)
|
||||
@ -3096,7 +3100,11 @@ gtk_print_operation_run (GtkPrintOperation *op,
|
||||
*/
|
||||
priv->is_sync = TRUE;
|
||||
g_return_val_if_fail (priv->export_filename != NULL, GTK_PRINT_OPERATION_RESULT_ERROR);
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
result = run_pdf (op, parent, &do_print);
|
||||
#else
|
||||
result = GTK_PRINT_OPERATION_RESULT_ERROR;
|
||||
#endif
|
||||
}
|
||||
else if (action == GTK_PRINT_OPERATION_ACTION_PREVIEW)
|
||||
{
|
||||
|
@ -27,10 +27,17 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <cairo.h>
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
#include <cairo-pdf.h>
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
#include <cairo-ps.h>
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
#include <cairo-svg.h>
|
||||
#endif
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
|
||||
@ -60,17 +67,29 @@ struct _GtkPrintBackendFile
|
||||
|
||||
typedef enum
|
||||
{
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
FORMAT_PDF,
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
FORMAT_PS,
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
FORMAT_SVG,
|
||||
#endif
|
||||
N_FORMATS
|
||||
} OutputFormat;
|
||||
|
||||
static const char * formats[N_FORMATS] =
|
||||
{
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
"pdf",
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
"ps",
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
"svg"
|
||||
#endif
|
||||
};
|
||||
|
||||
static GObjectClass *backend_parent_class;
|
||||
@ -220,15 +239,21 @@ output_file_from_settings (GtkPrintSettings *settings,
|
||||
{
|
||||
default:
|
||||
case N_FORMATS:
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
case FORMAT_PDF:
|
||||
extension = "pdf";
|
||||
break;
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
case FORMAT_PS:
|
||||
extension = "ps";
|
||||
break;
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
case FORMAT_SVG:
|
||||
extension = "svg";
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,8 +350,10 @@ file_printer_create_cairo_surface (GtkPrinter *printer,
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
OutputFormat format;
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
const cairo_svg_version_t *versions;
|
||||
int num_versions = 0;
|
||||
#endif
|
||||
|
||||
format = format_from_settings (settings);
|
||||
|
||||
@ -334,18 +361,24 @@ file_printer_create_cairo_surface (GtkPrinter *printer,
|
||||
{
|
||||
default:
|
||||
case N_FORMATS:
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
case FORMAT_PDF:
|
||||
surface = cairo_pdf_surface_create_for_stream (_cairo_write, cache_io, width, height);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
case FORMAT_PS:
|
||||
surface = cairo_ps_surface_create_for_stream (_cairo_write, cache_io, width, height);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
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;
|
||||
#endif
|
||||
}
|
||||
|
||||
cairo_surface_set_fallback_resolution (surface,
|
||||
@ -550,15 +583,21 @@ set_printer_format_from_option_set (GtkPrinter *printer,
|
||||
|
||||
switch (i)
|
||||
{
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
case FORMAT_PDF:
|
||||
gtk_printer_set_accepts_pdf (printer, TRUE);
|
||||
gtk_printer_set_accepts_ps (printer, FALSE);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
case FORMAT_PS:
|
||||
gtk_printer_set_accepts_pdf (printer, FALSE);
|
||||
gtk_printer_set_accepts_ps (printer, TRUE);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
case FORMAT_SVG:
|
||||
#endif
|
||||
default:
|
||||
gtk_printer_set_accepts_pdf (printer, FALSE);
|
||||
gtk_printer_set_accepts_ps (printer, FALSE);
|
||||
@ -660,6 +699,7 @@ file_printer_get_options (GtkPrinter *printer,
|
||||
|
||||
if (capabilities & (GTK_PRINT_CAPABILITY_GENERATE_PDF | GTK_PRINT_CAPABILITY_GENERATE_PS))
|
||||
{
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
if (capabilities & GTK_PRINT_CAPABILITY_GENERATE_PDF)
|
||||
{
|
||||
if (format == FORMAT_PDF || format == N_FORMATS)
|
||||
@ -671,6 +711,8 @@ file_printer_get_options (GtkPrinter *printer,
|
||||
display_format_names[n_formats] = _(format_names[FORMAT_PDF]);
|
||||
n_formats++;
|
||||
}
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
if (capabilities & GTK_PRINT_CAPABILITY_GENERATE_PS)
|
||||
{
|
||||
if (format == FORMAT_PS || format == N_FORMATS)
|
||||
@ -679,6 +721,7 @@ file_printer_get_options (GtkPrinter *printer,
|
||||
display_format_names[n_formats] = _(format_names[FORMAT_PS]);
|
||||
n_formats++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -686,15 +729,21 @@ file_printer_get_options (GtkPrinter *printer,
|
||||
{
|
||||
default:
|
||||
case N_FORMATS:
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
case FORMAT_PDF:
|
||||
current_format = FORMAT_PDF;
|
||||
break;
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
case FORMAT_PS:
|
||||
current_format = FORMAT_PS;
|
||||
break;
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
case FORMAT_SVG:
|
||||
current_format = FORMAT_SVG;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
for (n_formats = 0; n_formats < N_FORMATS; ++n_formats)
|
||||
@ -802,13 +851,19 @@ file_printer_prepare_for_print (GtkPrinter *printer,
|
||||
format = format_from_settings (settings);
|
||||
switch (format)
|
||||
{
|
||||
#ifdef CAIRO_HAS_PDF_SURFACE
|
||||
case FORMAT_PDF:
|
||||
#endif
|
||||
case N_FORMATS:
|
||||
gtk_print_job_set_rotate (print_job, FALSE);
|
||||
break;
|
||||
default:
|
||||
#ifdef CAIRO_HAS_PS_SURFACE
|
||||
case FORMAT_PS:
|
||||
#endif
|
||||
#ifdef CAIRO_HAS_SVG_SURFACE
|
||||
case FORMAT_SVG:
|
||||
#endif
|
||||
gtk_print_job_set_rotate (print_job, TRUE);
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user