Verified Commit ff4c247d authored by Zander's avatar Zander 💥

Move cairo renderer into lib

The cairo plugin is now little more than a stub to register exporters
parent 1b7726cd
...@@ -1126,7 +1126,7 @@ new_aa_renderer (DDisplay *ddisp) ...@@ -1126,7 +1126,7 @@ new_aa_renderer (DDisplay *ddisp)
/* we really should not come here but instead disable the menu command earlier */ /* we really should not come here but instead disable the menu command earlier */
message_warning (_("No antialiased renderer found")); message_warning (_("No antialiased renderer found"));
/* fallback: built-in libart renderer */ /* fallback: built-in libart renderer */
return dia_cairo_interactive_renderer_new (ddisp); return dia_cairo_interactive_renderer_new ();
} }
void void
...@@ -1152,7 +1152,11 @@ ddisplay_set_renderer(DDisplay *ddisp, int aa_renderer) ...@@ -1152,7 +1152,11 @@ ddisplay_set_renderer(DDisplay *ddisp, int aa_renderer)
if (ddisp->aa_renderer){ if (ddisp->aa_renderer){
ddisp->renderer = new_aa_renderer (ddisp); ddisp->renderer = new_aa_renderer (ddisp);
} else { } else {
ddisp->renderer = dia_cairo_interactive_renderer_new(ddisp); ddisp->renderer = dia_cairo_interactive_renderer_new();
g_object_set (ddisp->renderer,
"zoom", &ddisp->zoom_factor,
"rect", &ddisp->visible,
NULL);
} }
if (window) if (window)
...@@ -1164,10 +1168,15 @@ ddisplay_resize_canvas(DDisplay *ddisp, ...@@ -1164,10 +1168,15 @@ ddisplay_resize_canvas(DDisplay *ddisp,
int width, int height) int width, int height)
{ {
if (ddisp->renderer==NULL) { if (ddisp->renderer==NULL) {
if (ddisp->aa_renderer) if (ddisp->aa_renderer) {
ddisp->renderer = new_aa_renderer (ddisp); ddisp->renderer = new_aa_renderer (ddisp);
else } else {
ddisp->renderer = dia_cairo_interactive_renderer_new(ddisp); ddisp->renderer = dia_cairo_interactive_renderer_new();
g_object_set (ddisp->renderer,
"zoom", &ddisp->zoom_factor,
"rect", &ddisp->visible,
NULL);
}
} }
dia_renderer_set_size(ddisp->renderer, gtk_widget_get_window(ddisp->canvas), width, height); dia_renderer_set_size(ddisp->renderer, gtk_widget_get_window(ddisp->canvas), width, height);
......
This diff is collapsed.
...@@ -661,3 +661,8 @@ fill_pixel_rect(DiaRenderer *object, ...@@ -661,3 +661,8 @@ fill_pixel_rect(DiaRenderer *object,
#endif #endif
} }
DiaRenderer *
dia_cairo_interactive_renderer_new ()
{
return g_object_new (DIA_TYPE_CAIRO_INTERACTIVE_RENDERER, NULL);
}
\ No newline at end of file
...@@ -60,27 +60,14 @@ ...@@ -60,27 +60,14 @@
#include "diacairo.h" #include "diacairo.h"
#include "diacairo-print.h" #include "diacairo-print.h"
typedef enum OutputKind
{
OUTPUT_PS = 1,
OUTPUT_PNG,
OUTPUT_PNGA,
OUTPUT_PDF,
OUTPUT_WMF,
OUTPUT_EMF,
OUTPUT_CLIPBOARD,
OUTPUT_SVG,
OUTPUT_CAIRO_SCRIPT
} OutputKind;
#if defined CAIRO_HAS_WIN32_SURFACE && CAIRO_VERSION > 10510 #if defined CAIRO_HAS_WIN32_SURFACE && CAIRO_VERSION > 10510
#define DIA_CAIRO_CAN_EMF 1 #define DIA_CAIRO_CAN_EMF 1
#pragma message ("DiaCairo can EMF;)") #pragma message ("DiaCairo can EMF;)")
#endif #endif
/* dia export funtion */ /* dia export funtion */
static gboolean gboolean
export_data(DiagramData *data, DiaContext *ctx, cairo_export_data(DiagramData *data, DiaContext *ctx,
const gchar *filename, const gchar *diafilename, const gchar *filename, const gchar *diafilename,
void* user_data) void* user_data)
{ {
...@@ -349,191 +336,3 @@ export_print_data (DiagramData *data, DiaContext *ctx, ...@@ -349,191 +336,3 @@ export_print_data (DiagramData *data, DiaContext *ctx,
} }
return TRUE; return TRUE;
} }
#ifdef CAIRO_HAS_PS_SURFACE
static const gchar *ps_extensions[] = { "ps", NULL };
static DiaExportFilter ps_export_filter = {
N_("Cairo PostScript"),
ps_extensions,
export_data,
(void*)OUTPUT_PS,
"cairo-ps" /* unique name */
};
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
static const gchar *pdf_extensions[] = { "pdf", NULL };
static DiaExportFilter pdf_export_filter = {
N_("Cairo Portable Document Format"),
pdf_extensions,
/* not using export_print_data() due to bug 599401 */
export_data,
(void*)OUTPUT_PDF,
"cairo-pdf"
};
#endif
static const gchar *svg_extensions[] = { "svg", NULL };
static DiaExportFilter svg_export_filter = {
N_("Cairo Scalable Vector Graphics"),
svg_extensions,
export_data,
(void*)OUTPUT_SVG,
"cairo-svg",
FILTER_DONT_GUESS /* don't use this if not asked explicit */
};
#ifdef CAIRO_HAS_SCRIPT_SURFACE
static const gchar *cs_extensions[] = { "cs", NULL };
static DiaExportFilter cs_export_filter = {
N_("CairoScript"),
cs_extensions,
export_data,
(void*)OUTPUT_CAIRO_SCRIPT,
"cairo-script",
FILTER_DONT_GUESS /* don't use this if not asked explicit */
};
#endif
static const gchar *png_extensions[] = { "png", NULL };
static DiaExportFilter png_export_filter = {
N_("Cairo PNG"),
png_extensions,
export_data,
(void*)OUTPUT_PNG,
"cairo-png"
};
static DiaExportFilter pnga_export_filter = {
N_("Cairo PNG (with alpha)"),
png_extensions,
export_data,
(void*)OUTPUT_PNGA,
"cairo-alpha-png"
};
#if DIA_CAIRO_CAN_EMF
static const gchar *emf_extensions[] = { "emf", NULL };
static DiaExportFilter emf_export_filter = {
N_("Cairo EMF"),
emf_extensions,
export_data,
(void*)OUTPUT_EMF,
"cairo-emf",
FILTER_DONT_GUESS /* don't use this if not asked explicit */
};
static const gchar *wmf_extensions[] = { "wmf", NULL };
static DiaExportFilter wmf_export_filter = {
N_("Cairo WMF"),
wmf_extensions,
export_data,
(void*)OUTPUT_WMF,
"cairo-wmf",
FILTER_DONT_GUESS /* don't use this if not asked explicit */
};
static ObjectChange *
cairo_clipboard_callback (DiagramData *data,
const gchar *filename,
guint flags, /* further additions */
void *user_data)
{
DiaContext *ctx = dia_context_new(_("Cairo Clipboard Copy"));
g_return_val_if_fail ((OutputKind)user_data == OUTPUT_CLIPBOARD, NULL);
g_return_val_if_fail (data != NULL, NULL);
/* filename is not necessary */
export_data (data, ctx, filename, filename, user_data);
dia_context_release (ctx);
return NULL;
}
static DiaCallbackFilter cb_clipboard = {
"EditCopyDiagram",
N_("Copy _Diagram"),
"/DisplayMenu/Edit/CopyDiagram",
cairo_clipboard_callback,
(void*)OUTPUT_CLIPBOARD
};
#endif
static DiaCallbackFilter cb_gtk_print = {
"FilePrintGTK",
N_("Print (GTK) \342\200\246"),
"/InvisibleMenu/File/FilePrint",
cairo_print_callback,
(void*)OUTPUT_PDF
};
static gboolean
_plugin_can_unload (PluginInfo *info)
{
/* Can't unload as long as we are giving away our types,
* e.g. dia_cairo_interactive_renderer_get_type () */
return FALSE;
}
static void
_plugin_unload (PluginInfo *info)
{
#ifdef CAIRO_HAS_PS_SURFACE
filter_unregister_export(&ps_export_filter);
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
filter_unregister_export(&pdf_export_filter);
#endif
filter_unregister_export(&svg_export_filter);
#ifdef CAIRO_HAS_SCRIPT_SURFACE
filter_unregister_export(&cs_export_filter);
#endif
filter_unregister_export(&png_export_filter);
filter_unregister_export(&pnga_export_filter);
#if DIA_CAIRO_CAN_EMF
filter_unregister_export(&emf_export_filter);
filter_unregister_export(&wmf_export_filter);
filter_unregister_callback (&cb_clipboard);
#endif
filter_unregister_callback (&cb_gtk_print);
}
/* --- dia plug-in interface --- */
DIA_PLUGIN_CHECK_INIT
PluginInitResult
dia_plugin_init(PluginInfo *info)
{
if (!dia_plugin_info_init(info, "Cairo",
_("Cairo-based Rendering"),
_plugin_can_unload,
_plugin_unload))
return DIA_PLUGIN_INIT_ERROR;
/* FIXME: need to think about of proper way of registration, see also app/display.c */
png_export_filter.renderer_type = dia_cairo_interactive_renderer_get_type ();
#ifdef CAIRO_HAS_PS_SURFACE
filter_register_export(&ps_export_filter);
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
filter_register_export(&pdf_export_filter);
#endif
filter_register_export(&svg_export_filter);
#ifdef CAIRO_HAS_SCRIPT_SURFACE
filter_register_export(&cs_export_filter);
#endif
filter_register_export(&png_export_filter);
filter_register_export(&pnga_export_filter);
#if DIA_CAIRO_CAN_EMF
filter_register_export(&emf_export_filter);
filter_register_export(&wmf_export_filter);
filter_register_callback (&cb_clipboard);
#endif
filter_register_callback (&cb_gtk_print);
return DIA_PLUGIN_INIT_OK;
}
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include <cairo.h> #include <cairo.h>
#include "diarenderer.h" #include "diarenderer.h"
#include "display.h"
/* /*
#define DEBUG_CAIRO #define DEBUG_CAIRO
...@@ -91,9 +90,28 @@ struct _DiaCairoRendererClass ...@@ -91,9 +90,28 @@ struct _DiaCairoRendererClass
DiaRendererClass parent_class; DiaRendererClass parent_class;
}; };
typedef enum OutputKind
{
OUTPUT_PS = 1,
OUTPUT_PNG,
OUTPUT_PNGA,
OUTPUT_PDF,
OUTPUT_WMF,
OUTPUT_EMF,
OUTPUT_CLIPBOARD,
OUTPUT_SVG,
OUTPUT_CAIRO_SCRIPT
} OutputKind;
gboolean cairo_export_data (DiagramData *data,
DiaContext *ctx,
const gchar *filename,
const gchar *diafilename,
void *user_data);
/* FIXME: need to think about proper registration */ /* FIXME: need to think about proper registration */
GType dia_cairo_interactive_renderer_get_type (void) G_GNUC_CONST; GType dia_cairo_interactive_renderer_get_type (void) G_GNUC_CONST;
DiaRenderer *dia_cairo_interactive_renderer_new (DDisplay *ddisp); DiaRenderer *dia_cairo_interactive_renderer_new ();
G_END_DECLS G_END_DECLS
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1998 Alexander Larsson
*
* diacairo-print.c -- Cairo/gtk+ based printing for dia
* Copyright (C) 2008, Hans Breuer, <Hans@Breuer.Org>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "diacairo.h"
#include "diacairo-print.h"
#include "message.h"
typedef struct _PrintData
{
DiagramData *data;
DiaRenderer *renderer;
} PrintData;
G_GNUC_UNUSED static void
count_objs(DiaObject *obj, DiaRenderer *renderer, int active_layer, guint *nobjs)
{
(*nobjs)++;
}
/* Dia has it's own thing */
static void
_dia_to_gtk_page_setup (const DiagramData *data, GtkPageSetup *setup)
{
GtkPaperSize *paper_size;
const double points_per_cm = 28.346457;
const PaperInfo *paper = &(data->paper);
int index = find_paper (paper->name);
if (index < 0)
index = get_default_paper ();
paper_size = gtk_paper_size_new_from_ppd (
paper->name, paper->name,
get_paper_pswidth (index) * points_per_cm,
get_paper_psheight (index) * points_per_cm);
gtk_page_setup_set_orientation (setup, data->paper.is_portrait ?
GTK_PAGE_ORIENTATION_PORTRAIT : GTK_PAGE_ORIENTATION_LANDSCAPE);
gtk_page_setup_set_paper_size (setup, paper_size);
gtk_page_setup_set_left_margin (setup, data->paper.lmargin * 10, GTK_UNIT_MM);
gtk_page_setup_set_top_margin (setup, data->paper.tmargin * 10, GTK_UNIT_MM);
gtk_page_setup_set_right_margin (setup, data->paper.rmargin * 10, GTK_UNIT_MM);
gtk_page_setup_set_bottom_margin (setup, data->paper.bmargin * 10, GTK_UNIT_MM);
}
static void
begin_print (GtkPrintOperation *operation,
GtkPrintContext *context,
PrintData *print_data)
{
DiaCairoRenderer *cairo_renderer;
g_return_if_fail (print_data->renderer != NULL);
cairo_renderer = DIA_CAIRO_RENDERER (print_data->renderer);
g_return_if_fail (cairo_renderer->cr == NULL);
/* the renderer wants it's own reference */
#if 0 /* no alpha with printers */
cairo_renderer->with_alpha = TRUE;
#endif
cairo_renderer->cr = cairo_reference (gtk_print_context_get_cairo_context (context));
cairo_renderer->dia = print_data->data;
#if 0 /* needs some text size scaling ... */
cairo_renderer->layout = gtk_print_context_create_pango_layout (context);
#endif
/* scaling - as usual I don't get it, or do I? */
cairo_renderer->scale = (
gtk_page_setup_get_paper_width (gtk_print_context_get_page_setup (context), GTK_UNIT_MM)
- gtk_page_setup_get_left_margin( gtk_print_context_get_page_setup (context), GTK_UNIT_MM)
- gtk_page_setup_get_right_margin( gtk_print_context_get_page_setup (context), GTK_UNIT_MM)
) / print_data->data->paper.width;
cairo_renderer->skip_show_page = TRUE;
}
static void
draw_page (GtkPrintOperation *operation,
GtkPrintContext *context,
int page_nr,
PrintData *print_data)
{
Rectangle bounds;
DiagramData *data = print_data->data;
int x, y;
/* the effective sizes - dia already applied is_portrait */
double dp_width = data->paper.width;
double dp_height = data->paper.height;
DiaCairoRenderer *cairo_renderer;
g_return_if_fail (print_data->renderer != NULL);
cairo_renderer = DIA_CAIRO_RENDERER (print_data->renderer);
if (data->paper.fitto) {
x = page_nr % data->paper.fitwidth;
y = page_nr / data->paper.fitwidth;
bounds.left = dp_width * x + data->extents.left;
bounds.top = dp_height * y + data->extents.top;
bounds.right = bounds.left + dp_width;
bounds.bottom = bounds.top + dp_height;
} else {
double dx, dy;
int nx = ceil((data->extents.right - data->extents.left) / dp_width);
x = page_nr % nx;
y = page_nr / nx;
/* Respect the original pagination as shown by the page guides.
* Caclulate the offset between page origin 0,0 and data.extents.topleft.
* For the usual first page this boils down to lefttop=(0,0) but beware
* the origin being negative.
*/
dx = fmod(data->extents.left, dp_width);
if (dx < 0.0)
dx += dp_width;
dy = fmod(data->extents.top, dp_height);
if (dy < 0.0)
dy += dp_height;
bounds.left = dp_width * x + data->extents.left - dx;
bounds.top = dp_height * y + data->extents.top - dy;
bounds.right = bounds.left + dp_width;
bounds.bottom = bounds.top + dp_height;
}
#if 0 /* calls begin/end of the given renderer */
/* count the number of objects in this region */
data_render(data, print_data->renderer, &bounds,
(ObjectRenderer) count_objs, &nobjs);
if (!nobjs)
return; /* not printing empty pages */
#endif
/* setup a clipping rect */
{
GtkPageSetup *setup = gtk_print_context_get_page_setup (context);
double left = gtk_page_setup_get_left_margin (setup, GTK_UNIT_MM);
double top = gtk_page_setup_get_top_margin (setup, GTK_UNIT_MM);
double width = gtk_page_setup_get_paper_width (setup, GTK_UNIT_MM)
- left - gtk_page_setup_get_right_margin (setup, GTK_UNIT_MM);
double height = gtk_page_setup_get_paper_height (setup, GTK_UNIT_MM)
- top - gtk_page_setup_get_bottom_margin (setup, GTK_UNIT_MM);
cairo_save (cairo_renderer->cr);
/* we are still in the gtk-print coordinate system */
#if 1
/* ... but apparently already transalted to top,left */
top = left = 0;
#endif
cairo_rectangle (cairo_renderer->cr, left, top, width, height);
cairo_clip (cairo_renderer->cr);
}
{
Rectangle extents = data->extents;
data->extents = bounds;
/* render only the region, FIXME: better way than modifying DiagramData ? */
data_render(data, print_data->renderer, &bounds, NULL, NULL);
data->extents = extents;
}
cairo_restore (cairo_renderer->cr);
}
static void
end_print (GtkPrintOperation *operation,
GtkPrintContext *context,
PrintData *print_data)
{
g_object_unref (print_data->data);
g_object_unref (print_data->renderer);
g_free (print_data);
}
GtkPrintOperation *
create_print_operation (DiagramData *data, const char *name)
{
PrintData *print_data;
GtkPrintOperation *operation;
GtkPageSetup * setup;
int num_pages;
/* gets deleted in end_print */
print_data = g_new0 (PrintData, 1);
print_data->data = g_object_ref (data);
print_data->renderer = g_object_new (DIA_TYPE_CAIRO_RENDERER, NULL);
operation = gtk_print_operation_new ();
gtk_print_operation_set_job_name (operation, name);
setup = gtk_print_operation_get_default_page_setup (operation);
if (!setup)
setup = gtk_page_setup_new ();
_dia_to_gtk_page_setup (print_data->data, setup);
gtk_print_operation_set_default_page_setup (operation, setup);
g_object_unref (setup);
/* similar logic draw_page() but we need to set the total pages in advance */
if (data->paper.fitto) {
num_pages = data->paper.fitwidth * data->paper.fitheight;
} else {
int nx = ceil((data->extents.right - data->extents.left) / data->paper.width);
int ny = ceil((data->extents.bottom - data->extents.top) / data->paper.height);
num_pages = nx * ny;
}
gtk_print_operation_set_n_pages (operation, num_pages);
gtk_print_operation_set_unit (operation, GTK_UNIT_MM);
g_signal_connect (operation, "draw_page", G_CALLBACK (draw_page), print_data);
g_signal_connect (operation, "begin_print", G_CALLBACK (begin_print), print_data);
g_signal_connect (operation, "end_print", G_CALLBACK (end_print), print_data);
return operation;
}
ObjectChange *
cairo_print_callback (DiagramData *data,
const gchar *filename,
guint flags, /* further additions */
void *user_data)
{
GtkPrintOperation *op = create_print_operation (data, filename ? filename : "diagram");
GtkPrintOperationResult res;
GError *error = NULL;
res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, &error);
if (GTK_PRINT_OPERATION_RESULT_ERROR == res) {
message_error ("%s", error->message);
g_error_free (error);
}
return NULL;
}
#include <gtk/gtk.h>
#include "diagramdata.h"
GtkPrintOperation *
create_print_operation (DiagramData *data,
const char *name);
ObjectChange *
cairo_print_callback (DiagramData *dia,
const gchar *filename,
guint flags, /* further additions */
void *user_data);
This diff is collapsed.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* diacairo.c -- Cairo based export plugin for dia * diacairo.c -- Cairo based export plugin for dia
* Copyright (C) 2004, Hans Breuer, <Hans@Breuer.Org> * Copyright (C) 2004, Hans Breuer, <Hans@Breuer.Org>
* based on wpg.c * based on wpg.c
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -57,305 +57,15 @@ ...@@ -57,305 +57,15 @@
#include "filter.h" #include "filter.h"
#include "plug-ins.h" #include "plug-ins.h"
#include "diacairo.h" #include "renderer/diacairo.h"
#include "diacairo-print.h" #include "renderer/diacairo-print.h"
typedef enum OutputKind
{
OUTPUT_PS = 1,
OUTPUT_PNG,
OUTPUT_PNGA,
OUTPUT_PDF,
OUTPUT_WMF,
OUTPUT_EMF,
OUTPUT_CLIPBOARD,
OUTPUT_SVG,
OUTPUT_CAIRO_SCRIPT
} OutputKind;
#if defined CAIRO_HAS_WIN32_SURFACE && CAIRO_VERSION > 10510
#define DIA_CAIRO_CAN_EMF 1
#pragma message ("DiaCairo can EMF;)")
#endif
/* dia export funtion */
static gboolean
export_data(DiagramData *data, DiaContext *ctx,
const gchar *filename, const gchar *diafilename,
void* user_data)
{
DiaCairoRenderer *renderer;
FILE *file;
real width, height;
OutputKind kind = (OutputKind)user_data;
/* the passed in filename is in GLib's filename encoding. On Linux everything
* should be fine in passing it to the C-runtime (or cairo). On win32 GLib's
* filename encdong is always utf-8, so another conversion is needed.
*/
gchar *filename_crt = (gchar *)filename;
#if DIA_CAIRO_CAN_EMF
HDC hFileDC = NULL;
#endif
if (kind != OUTPUT_CLIPBOARD) {
file = g_fopen(filename, "wb"); /* "wb" for binary! */
if (file == NULL) {
dia_context_add_message_with_errno(ctx, errno, _("Can't open output file %s."),
dia_context_get_filename(ctx));
return FALSE;
}
fclose (file);
#ifdef G_OS_WIN32
filename_crt = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL);
if (!filename_crt) {
dia_context_add_message(ctx, _("Can't convert output filename '%s' to locale encoding.\n"
"Please choose a different name to save with Cairo.\n"),
dia_context_get_filename(ctx));
return FALSE;
}
#endif
} /* != CLIPBOARD */
renderer = g_object_new (DIA_TYPE_CAIRO_RENDERER, NULL);
renderer->dia = data; /* FIXME: not sure if this a good idea */
renderer->scale = 1.0;
switch (kind) {
#ifdef CAIRO_HAS_PS_SURFACE
case OUTPUT_PS :
width = data->paper.width * (72.0 / 2.54) + 0.5;
height = data->paper.height * (72.0 / 2.54) + 0.5;
renderer->scale = data->paper.scaling * (72.0 / 2.54);
DIAG_NOTE(g_message ("PS Surface %dx%d\n", (int)width, (int)height));
renderer->surface = cairo_ps_surface_create (filename_crt,
width, height); /* in points? */
/* maybe we should increase the resolution here as well */
break;
#endif
#if defined CAIRO_HAS_PNG_SURFACE || defined CAIRO_HAS_PNG_FUNCTIONS
case OUTPUT_PNGA :
renderer->with_alpha = TRUE;
/* fall through */
case OUTPUT_PNG :
/* quite arbitrary, but consistent with ../pixbuf ;-) */
renderer->scale = 20.0 * data->paper.scaling;
width = ceil((data->extents.right - data->extents.left) * renderer->scale) + 1;
height = ceil((data->extents.bottom - data->extents.top) * renderer->scale) + 1;
DIAG_NOTE(g_message ("PNG Surface %dx%d\n", (int)width, (int)height));
/* use case screwed by API shakeup. We need to special case */
renderer->surface = cairo_image_surface_create(
CAIRO_FORMAT_ARGB32,
(int)width, (int)height);
/* an extra refernce to make it survive end_render():cairo_surface_destroy() */
cairo_surface_reference(renderer->surface);
break;
#endif
#ifdef CAIRO_HAS_PDF_SURFACE
case OUTPUT_PDF :
#define DPI 300.0 /* 600.0? */
/* I just don't get how the scaling is supposed to work, dpi versus page size ? */
renderer->scale = data->paper.scaling * (72.0 / 2.54);
/* Dia's paper.width already contains the scale, cairo needs it without
* Similar for margins, Dia's without, but cairo wants them. The full
* extents don't matter here, because we do cairo_pdf_set_size() for every page.