Commit fad69ba0 authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Add gtkprintoperationpreview.[ch] Set default preview command. Hardcoded

2006-06-02  Alexander Larsson  <alexl@redhat.com>

	* gtk/Makefile.am:
	Add gtkprintoperationpreview.[ch]
	Set default preview command. Hardcoded for now.

	* gtk/gtkmarshalers.list:
	Add BOOLEAN:OBJECT,OBJECT,OBJECT

	* gtk/gtkprintbackend.c:
	Add preview command property.

	* gtk/gtkprintcontext.[ch]:
	Make less dependent on PrintOperation for output settings
	Externally set cairo_t and dpi. Resettable.
	Create fontmap without metrics hinting (so that print preview
	text layout doesn't depend on zoom level).

	* gtk/gtkprintoperation-private.h:
	* gtk/gtkprintoperation-unix.c:
	* gtk/gtkprintoperation.[ch]:
	Initial work on print preview API and default implementation
	using an external preview app.

	* gtk/gtkprintoperation-win32.c:
	Some needed updates. Not done, needs more work.

	* gtk/gtkprintoperationpreview.[ch]:
	New interface used in print preview api.

	* gtk/gtkprintunixdialog.c:
	Add print preview dialog.

	* tests/print-editor.c:
	Test using an custom print preview widget.
parent caf6c419
2006-06-02 Alexander Larsson <alexl@redhat.com>
* gtk/Makefile.am:
Add gtkprintoperationpreview.[ch]
Set default preview command. Hardcoded for now.
* gtk/gtkmarshalers.list:
Add BOOLEAN:OBJECT,OBJECT,OBJECT
* gtk/gtkprintbackend.c:
Add preview command property.
* gtk/gtkprintcontext.[ch]:
Make less dependent on PrintOperation for output settings
Externally set cairo_t and dpi. Resettable.
Create fontmap without metrics hinting (so that print preview
text layout doesn't depend on zoom level).
* gtk/gtkprintoperation-private.h:
* gtk/gtkprintoperation-unix.c:
* gtk/gtkprintoperation.[ch]:
Initial work on print preview API and default implementation
using an external preview app.
* gtk/gtkprintoperation-win32.c:
Some needed updates. Not done, needs more work.
* gtk/gtkprintoperationpreview.[ch]:
New interface used in print preview api.
* gtk/gtkprintunixdialog.c:
Add print preview dialog.
* tests/print-editor.c:
Test using an custom print preview widget.
2006-06-02 Emmanuele Bassi <ebassi@gnome.org>
* gtk/gtkrecentmanager.c
......
2006-06-02 Alexander Larsson <alexl@redhat.com>
* gtk/Makefile.am:
Add gtkprintoperationpreview.[ch]
Set default preview command. Hardcoded for now.
* gtk/gtkmarshalers.list:
Add BOOLEAN:OBJECT,OBJECT,OBJECT
* gtk/gtkprintbackend.c:
Add preview command property.
* gtk/gtkprintcontext.[ch]:
Make less dependent on PrintOperation for output settings
Externally set cairo_t and dpi. Resettable.
Create fontmap without metrics hinting (so that print preview
text layout doesn't depend on zoom level).
* gtk/gtkprintoperation-private.h:
* gtk/gtkprintoperation-unix.c:
* gtk/gtkprintoperation.[ch]:
Initial work on print preview API and default implementation
using an external preview app.
* gtk/gtkprintoperation-win32.c:
Some needed updates. Not done, needs more work.
* gtk/gtkprintoperationpreview.[ch]:
New interface used in print preview api.
* gtk/gtkprintunixdialog.c:
Add print preview dialog.
* tests/print-editor.c:
Test using an custom print preview widget.
2006-06-02 Emmanuele Bassi <ebassi@gnome.org>
* gtk/gtkrecentmanager.c
......
......@@ -4,6 +4,7 @@ SUBDIRS=theme-bits
if OS_UNIX
SUBDIRS += xdgmime
GTK_PRINT_PREVIEW_COMMAND="evince %f"
endif
DIST_SUBDIRS=theme-bits xdgmime
......@@ -25,6 +26,7 @@ INCLUDES = \
-DGTK_HOST=\"$(host)\" \
-DGTK_COMPILATION \
-DGTK_PRINT_BACKENDS=\"$(GTK_PRINT_BACKENDS)\" \
-DGTK_PRINT_PREVIEW_COMMAND=\"$(GTK_PRINT_PREVIEW_COMMAND)\" \
-I$(top_builddir)/gtk \
-I$(top_srcdir) -I../gdk \
-I$(top_srcdir)/gdk \
......@@ -231,6 +233,7 @@ gtk_public_h_sources = \
gtkpreview.h \
gtkprintcontext.h \
gtkprintoperation.h \
gtkprintoperationpreview.h \
gtkprintsettings.h \
gtkprivate.h \
gtkprogress.h \
......@@ -487,6 +490,7 @@ gtk_c_sources = \
gtkpreview.c \
gtkprintcontext.c \
gtkprintoperation.c \
gtkprintoperationpreview.c \
gtkprintsettings.c \
gtkprintutils.c \
gtkprogress.c \
......
......@@ -32,6 +32,7 @@ BOOLEAN:OBJECT,INT,INT,UINT
BOOLEAN:OBJECT,STRING,STRING,BOXED
BOOLEAN:OBJECT,BOXED
BOOLEAN:OBJECT,BOXED,BOXED
BOOLEAN:OBJECT,OBJECT,OBJECT
BOOLEAN:OBJECT,STRING,STRING
BOOLEAN:INT
BOOLEAN:INT,INT
......
......@@ -191,7 +191,7 @@ _gtk_print_backend_module_create (GtkPrintBackendModule *pb_module)
return NULL;
}
GtkPrintBackend *
static GtkPrintBackend *
_gtk_print_backend_create (const char *backend_name)
{
GSList *l;
......@@ -200,7 +200,6 @@ _gtk_print_backend_create (const char *backend_name)
GtkPrintBackendModule *pb_module;
GtkPrintBackend *pb;
/* TODO: make module loading code work */
for (l = loaded_backends; l != NULL; l = l->next)
{
pb_module = l->data;
......@@ -255,6 +254,11 @@ gtk_print_backend_initialize (void)
GTK_PRINT_BACKENDS,
GTK_PARAM_READWRITE));
gtk_settings_install_property (g_param_spec_string ("gtk-print-preview-command",
P_("Default command to run when displaying a print preview"),
P_("Command to run when displaying a print preview"),
GTK_PRINT_PREVIEW_COMMAND,
GTK_PARAM_READWRITE));
initialized = TRUE;
}
}
......
......@@ -40,6 +40,9 @@ struct _GtkPrintContext
GtkPageSetup *page_setup;
PangoFontMap *fontmap;
gdouble surface_dpi_x;
gdouble surface_dpi_y;
gdouble pixels_per_unit_x;
gdouble pixels_per_unit_y;
};
......@@ -60,9 +63,9 @@ gtk_print_context_finalize (GObject *object)
if (context->page_setup)
g_object_unref (context->page_setup);
if (context->cr)
cairo_destroy (context->cr);
G_OBJECT_CLASS (gtk_print_context_parent_class)->finalize (object);
}
......@@ -83,15 +86,31 @@ gtk_print_context_class_init (GtkPrintContextClass *class)
GtkPrintContext *
_gtk_print_context_new (GtkPrintOperation *op)
{
GtkPrintOperationPrivate *priv = op->priv;
GtkPrintContext *context;
context = g_object_new (GTK_TYPE_PRINT_CONTEXT, NULL);
context->op = op;
context->cr = cairo_create (priv->surface);
context->cr = NULL;
context->fontmap = pango_cairo_font_map_new ();
switch (priv->unit)
return context;
}
void
gtk_print_context_set_cairo_context (GtkPrintContext *context,
cairo_t *cr,
double dpi_x,
double dpi_y)
{
if (context->cr)
cairo_destroy (context->cr);
context->cr = cairo_reference (cr);
context->surface_dpi_x = dpi_x;
context->surface_dpi_y = dpi_y;
switch (context->op->priv->unit)
{
default:
case GTK_UNIT_PIXEL:
......@@ -100,34 +119,31 @@ _gtk_print_context_new (GtkPrintOperation *op)
context->pixels_per_unit_y = 1.0;
break;
case GTK_UNIT_POINTS:
context->pixels_per_unit_x = priv->dpi_x / POINTS_PER_INCH;
context->pixels_per_unit_y = priv->dpi_y / POINTS_PER_INCH;
context->pixels_per_unit_x = dpi_x / POINTS_PER_INCH;
context->pixels_per_unit_y = dpi_y / POINTS_PER_INCH;
break;
case GTK_UNIT_INCH:
context->pixels_per_unit_x = priv->dpi_x;
context->pixels_per_unit_y = priv->dpi_y;
context->pixels_per_unit_x = dpi_x;
context->pixels_per_unit_y = dpi_y;
break;
case GTK_UNIT_MM:
context->pixels_per_unit_x = priv->dpi_x / MM_PER_INCH;
context->pixels_per_unit_y = priv->dpi_y / MM_PER_INCH;
context->pixels_per_unit_x = dpi_x / MM_PER_INCH;
context->pixels_per_unit_y = dpi_y / MM_PER_INCH;
break;
}
cairo_scale (context->cr,
context->pixels_per_unit_x,
context->pixels_per_unit_y);
context->fontmap = pango_cairo_font_map_new ();
/* We use the unit-scaled resolution, as we still want fonts given in points to work */
pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (context->fontmap),
priv->dpi_y / context->pixels_per_unit_y);
return context;
dpi_y / context->pixels_per_unit_y);
}
void
_gtk_print_context_rotate_according_to_orientation (GtkPrintContext *context)
{
GtkPrintOperationPrivate *priv = context->op->priv;
cairo_t *cr = context->cr;
cairo_matrix_t matrix;
GtkPaperSize *paper_size;
......@@ -136,9 +152,9 @@ _gtk_print_context_rotate_according_to_orientation (GtkPrintContext *context)
paper_size = gtk_page_setup_get_paper_size (context->page_setup);
width = gtk_paper_size_get_width (paper_size, GTK_UNIT_INCH);
width = width * priv->dpi_x / context->pixels_per_unit_x;
width = width * context->surface_dpi_x / context->pixels_per_unit_x;
height = gtk_paper_size_get_height (paper_size, GTK_UNIT_INCH);
height = height * priv->dpi_y / context->pixels_per_unit_y;
height = height * context->surface_dpi_y / context->pixels_per_unit_y;
switch (gtk_page_setup_get_orientation (context->page_setup))
{
......@@ -188,8 +204,8 @@ _gtk_print_context_translate_into_margin (GtkPrintContext *context)
top = gtk_page_setup_get_top_margin (context->page_setup, GTK_UNIT_INCH);
cairo_translate (context->cr,
left * priv->dpi_x / context->pixels_per_unit_x,
top * priv->dpi_y / context->pixels_per_unit_y);
left * context->surface_dpi_x / context->pixels_per_unit_x,
top * context->surface_dpi_y / context->pixels_per_unit_y);
}
void
......@@ -272,7 +288,7 @@ gtk_print_context_get_width (GtkPrintContext *context)
width = gtk_page_setup_get_page_width (context->page_setup, GTK_UNIT_INCH);
/* Really dpi_x? What about landscape? what does dpi_x mean in that case? */
return width * priv->dpi_x / context->pixels_per_unit_x;
return width * context->surface_dpi_x / context->pixels_per_unit_x;
}
/**
......@@ -300,8 +316,8 @@ gtk_print_context_get_height (GtkPrintContext *context)
else
height = gtk_page_setup_get_page_height (context->page_setup, GTK_UNIT_INCH);
/* Really dpi_x? What about landscape? what does dpi_x mean in that case? */
return height * priv->dpi_y / context->pixels_per_unit_y;
/* Really dpi_y? What about landscape? what does dpi_y mean in that case? */
return height * context->surface_dpi_y / context->pixels_per_unit_y;
}
/**
......@@ -320,7 +336,7 @@ gtk_print_context_get_dpi_x (GtkPrintContext *context)
{
g_return_val_if_fail (GTK_IS_PRINT_CONTEXT (context), 0);
return context->op->priv->dpi_x;
return context->surface_dpi_x;
}
/**
......@@ -339,7 +355,7 @@ gtk_print_context_get_dpi_y (GtkPrintContext *context)
{
g_return_val_if_fail (GTK_IS_PRINT_CONTEXT (context), 0);
return context->op->priv->dpi_y;
return context->surface_dpi_y;
}
/**
......@@ -376,11 +392,17 @@ PangoContext *
gtk_print_context_create_pango_context (GtkPrintContext *context)
{
PangoContext *pango_context;
cairo_font_options_t *options;
g_return_val_if_fail (GTK_IS_PRINT_CONTEXT (context), NULL);
pango_context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (context->fontmap));
options = cairo_font_options_create ();
cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF);
pango_cairo_context_set_font_options (pango_context, options);
cairo_font_options_destroy (options);
return pango_context;
}
......
......@@ -51,6 +51,11 @@ PangoFontMap *gtk_print_context_get_pango_fontmap (GtkPrintContext *context);
PangoContext *gtk_print_context_create_pango_context (GtkPrintContext *context);
PangoLayout *gtk_print_context_create_pango_layout (GtkPrintContext *context);
/* Needed for preview implementations */
void gtk_print_context_set_cairo_context (GtkPrintContext *context,
cairo_t *cr,
double dpi_x,
double dpi_y);
G_END_DECLS
......
......@@ -46,9 +46,11 @@ struct _GtkPrintOperationPrivate
guint print_pages_idle_id;
guint show_progress_timeout_id;
GtkPrintContext *print_context;
/* Data for the print job: */
cairo_surface_t *surface;
gdouble dpi_x, dpi_y;
/* cairo_surface_t *surface; */
/* gdouble dpi_x, dpi_y; */
GtkPrintPages print_pages;
GtkPageRange *page_ranges;
......@@ -78,17 +80,29 @@ struct _GtkPrintOperationPrivate
gboolean cancelled);
};
typedef void (* GtkPrintOperationPrintFunc) (GtkPrintOperation *op,
GtkWindow *parent,
gboolean is_preview);
GtkPrintOperationResult _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *operation,
GtkWindow *parent,
gboolean *do_print,
GError **error);
typedef void (* GtkPrintOperationPrintFunc) (GtkPrintOperation *op,
GtkWindow *parent);
void _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
GtkWindow *parent,
GtkPrintOperationPrintFunc print_cb);
void _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
GtkWindow *parent,
const char *filename);
cairo_surface_t * _gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation *op,
GtkPageSetup *page_setup,
gdouble *dpi_x,
gdouble *dpi_y,
const gchar *target);
void _gtk_print_operation_platform_backend_resize_preview_surface (GtkPrintOperation *op,
GtkPageSetup *page_setup,
cairo_surface_t *surface);
void _gtk_print_operation_set_status (GtkPrintOperation *op,
GtkPrintStatus status,
......
This diff is collapsed.
......@@ -492,6 +492,7 @@ win32_end_run (GtkPrintOperation *op,
GlobalFree(op_win32->devmode);
GlobalFree(op_win32->devnames);
cairo_surface_finish (op->priv->surface);
cairo_surface_destroy (op->priv->surface);
op->priv->surface = NULL;
......
This diff is collapsed.
......@@ -29,6 +29,7 @@
#include "gtkpagesetup.h"
#include "gtkprintsettings.h"
#include "gtkprintcontext.h"
#include "gtkprintoperationpreview.h"
G_BEGIN_DECLS
......@@ -85,6 +86,12 @@ struct _GtkPrintOperationClass
void (*custom_widget_apply) (GtkPrintOperation *operation,
GtkWidget *widget);
gboolean (*preview) (GtkPrintOperation *operation,
GtkPrintOperationPreview *preview,
GtkPrintContext *context,
GtkWindow *parent);
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
......@@ -98,7 +105,8 @@ struct _GtkPrintOperationClass
typedef enum {
GTK_PRINT_OPERATION_RESULT_ERROR,
GTK_PRINT_OPERATION_RESULT_APPLY,
GTK_PRINT_OPERATION_RESULT_CANCEL
GTK_PRINT_OPERATION_RESULT_CANCEL,
GTK_PRINT_OPERATION_RESULT_PREVIEW
} GtkPrintOperationResult;
#define GTK_PRINT_ERROR gtk_print_error_quark ()
......
/* GTK - The GIMP Toolkit
* gtkprintoperationpreview.c: Abstract print preview interface
* Copyright (C) 2006, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "gtkprintoperationpreview.h"
#include "gtkmarshalers.h"
#include "gtkintl.h"
static void gtk_print_operation_preview_base_init (gpointer g_iface);
GType
gtk_print_operation_preview_get_type (void)
{
static GType print_operation_preview_type = 0;
if (!print_operation_preview_type)
{
static const GTypeInfo print_operation_preview_info =
{
sizeof (GtkPrintOperationPreviewIface), /* class_size */
gtk_print_operation_preview_base_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
print_operation_preview_type =
g_type_register_static (G_TYPE_INTERFACE, I_("GtkPrintOperationPreview"),
&print_operation_preview_info, 0);
g_type_interface_add_prerequisite (print_operation_preview_type, G_TYPE_OBJECT);
}
return print_operation_preview_type;
}
static void
gtk_print_operation_preview_base_init (gpointer g_iface)
{
static gboolean initialized = FALSE;
if (!initialized)
{
g_signal_new (I_("ready"),
GTK_TYPE_PRINT_OPERATION_PREVIEW,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationPreviewIface, ready),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
g_signal_new (I_("got-page-size"),
GTK_TYPE_PRINT_OPERATION_PREVIEW,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkPrintOperationPreviewIface, ready),
NULL, NULL,
_gtk_marshal_VOID__OBJECT_OBJECT,
G_TYPE_NONE, 2,
GTK_TYPE_PRINT_CONTEXT,
GTK_TYPE_PAGE_SETUP);
initialized = TRUE;
}
}
void
gtk_print_operation_preview_render_page (GtkPrintOperationPreview *preview,
gint page_nr)
{
g_return_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (preview));
GTK_PRINT_OPERATION_PREVIEW_GET_IFACE (preview)->render_page (preview,
page_nr);
}
void
gtk_print_operation_preview_end_preview (GtkPrintOperationPreview *preview)
{
g_return_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (preview));
GTK_PRINT_OPERATION_PREVIEW_GET_IFACE (preview)->end_preview (preview);
}
gboolean
gtk_print_operation_preview_is_selected (GtkPrintOperationPreview *preview,
gint page_nr)
{
g_return_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (preview));
return GTK_PRINT_OPERATION_PREVIEW_GET_IFACE (preview)->is_selected (preview, page_nr);
}
/* GTK - The GIMP Toolkit
* gtkprintoperationpreview.h: Abstract print preview interface
* Copyright (C) 2006, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GTK_PRINT_OPERATION_PREVIEW_H__
#define __GTK_PRINT_OPERATION_PREVIEW_H__
#include <glib-object.h>
#include <cairo.h>
#include "gtkprintcontext.h"
G_BEGIN_DECLS
#define GTK_TYPE_PRINT_OPERATION_PREVIEW (gtk_print_operation_preview_get_type ())
#define GTK_PRINT_OPERATION_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PRINT_OPERATION_PREVIEW, GtkPrintOperationPreview))
#define GTK_IS_PRINT_OPERATION_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PRINT_OPERATION_PREVIEW))
#define GTK_PRINT_OPERATION_PREVIEW_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_PRINT_OPERATION_PREVIEW, GtkPrintOperationPreviewIface))
typedef struct _GtkPrintOperationPreview GtkPrintOperationPreview; /*dummy typedef */
typedef struct _GtkPrintOperationPreviewIface GtkPrintOperationPreviewIface;
struct _GtkPrintOperationPreviewIface
{
GTypeInterface g_iface;
/* signals */
void (*ready) (GtkPrintOperationPreview *preview,
GtkPrintContext *context);
void (*got_page_size) (GtkPrintOperationPreview *preview,
GtkPrintContext *context,
GtkPageSetup *page_setup);
/* methods */
void (*render_page) (GtkPrintOperationPreview *preview,
gint page_nr);
gboolean (*is_selected) (GtkPrintOperationPreview *preview,
gint page_nr);
void (*end_preview) (GtkPrintOperationPreview *preview);
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
void (*_gtk_reserved5) (void);
void (*_gtk_reserved6) (void);
void (*_gtk_reserved7) (void);
};
GType gtk_print_operation_preview_get_type (void) G_GNUC_CONST;
void gtk_print_operation_preview_render_page (GtkPrintOperationPreview *preview,
gint page_nr);
void gtk_print_operation_preview_end_preview (GtkPrintOperationPreview *preview);
gboolean gtk_print_operation_preview_is_selected (GtkPrintOperationPreview *preview,
gint page_nr);
#endif /* __GTK_PRINT_OPERATION_PREVIEW_H__ */
......@@ -276,6 +276,7 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
NULL);
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
GTK_STOCK_PRINT_PREVIEW, GTK_RESPONSE_APPLY,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_PRINT, GTK_RESPONSE_OK,
NULL);
......
#include <math.h>
#include <pango/pangocairo.h>
#include <gtk/gtk.h>
#include <gtk/gtkprintoperation.h>
......@@ -303,7 +304,6 @@ begin_print (GtkPrintOperation *operation,
gtk_print_operation_set_n_pages (operation, g_list_length (page_breaks) + 1);
print_data->page_breaks = page_breaks;
}
static void
......@@ -317,6 +317,7 @@ draw_page (GtkPrintOperation *operation,
int start, end, i;
PangoLayoutIter *iter;
double start_pos;
if (page_nr == 0)
start = 0;
else
......@@ -430,17 +431,195 @@ custom_widget_apply (GtkPrintOperation *operation,
data->font = g_strdup (selected_font);
}
typedef struct
{
GtkPrintOperation *op;
GtkPrintOperationPreview *preview;
GtkWidget *spin;
GtkWidget *area;
gint page;
PrintData *data;
gdouble dpi_x, dpi_y;
} PreviewOp;
static gboolean
preview_expose (GtkWidget *widget,
GdkEventExpose *event,
gpointer data)
{
PreviewOp *pop = data;
gdk_window_clear (pop->area->window);
gtk_print_operation_preview_render_page (pop->preview,
pop->page - 1);
return TRUE;
}
static void
preview_ready (GtkPrintOperationPreview *preview,
GtkPrintContext *context,
gpointer data)
{
PreviewOp *pop = data;
gint n_pages;
g_object_get (pop->op, "n-pages", &n_pages, NULL);
gtk_spin_button_set_range (GTK_SPIN_BUTTON (pop->spin),
1.0, n_pages);
g_signal_connect (pop->area, "expose_event",
G_CALLBACK (preview_expose),
pop);
gtk_widget_queue_draw (pop->area);
}
static void
preview_got_page_size (GtkPrintOperationPreview *preview,
GtkPrintContext *context,
GtkPageSetup *page_setup,
gpointer data)
{
PreviewOp *pop = data;
GtkPaperSize *paper_size;
double w, h;
cairo_t *cr;
gdouble dpi_x, dpi_y;
paper_size = gtk_page_setup_get_paper_size (page_setup);
w = gtk_paper_size_get_width (paper_size, GTK_UNIT_INCH);
h = gtk_paper_size_get_height (paper_size, GTK_UNIT_INCH);
cr = gdk_cairo_create (pop->area->window);
dpi_x = pop->area->allocation.width/w;
dpi_y = pop->area->allocation.height/h;
if (fabs (dpi_x - pop->dpi_x) > 0.001 ||
fabs (dpi_y - pop->dpi_y) > 0.001)
{
gtk_print_context_set_cairo_context (context, cr, dpi_x, dpi_y);
pop->dpi_x = dpi_x;
pop->dpi_y = dpi_y;
}
pango_cairo_update_layout (cr, pop->data->layout);
cairo_destroy (cr);
}
static void
update_page (GtkSpinButton *widget,
gpointer data)
{
PreviewOp *pop = data;
pop->page = gtk_spin_button_get_value_as_int (widget);
gtk_widget_queue_draw (pop->area);
}
static void
preview_destroy (GtkWindow *window,
PreviewOp *pop)
{
gtk_print_operation_preview_end_preview (pop->preview);
g_object_unref (pop->op);
g_free (pop);
}