Ejemplo n.º 1
0
void
foreach_gxps_page (const gchar *xps_filename, GXPSPageFunc page_func, gpointer data)
{
	GError *error = NULL;
	GFile *gfile = g_file_new_for_commandline_arg (xps_filename);

	GXPSFile *file = gxps_file_new (gfile, &error);
	if (file == NULL)
		rerror ("Unable to open %s: %s", xps_filename, error->message);

	GXPSDocument *doc = gxps_file_get_document (file, 0, &error);
	if (doc == NULL)
		rerror ("Unable to open %s: %s", xps_filename, error->message);

	gint page_count = gxps_document_get_n_pages (doc);
	xps_range_set_min (range, 1);
	xps_range_set_max (range, page_count);
	if (xps_range_is_empty (range)) xps_range_append (range, 1, page_count, 1);

	gint pi;
	XpsRangeIter iter;
	xps_range_iter_init (&iter, range);
	while (xps_range_iter_next (&iter, &pi)) {
		GXPSPage *page = gxps_document_get_page (doc, pi-1, &error);
		gdouble width, height;
		gxps_page_get_size (page, &width, &height);
		page_func (page, width, height, data);
		g_object_unref (page);
	}
}
Ejemplo n.º 2
0
static void
page_changed_callback (GtkSpinButton *button,
		       GXPSView      *view)
{
	GXPSPage *xps_page;
	gint      page;
	gdouble   width, height;
	cairo_t  *cr;
	GError   *error = NULL;

	page = gtk_spin_button_get_value_as_int (button);

	xps_page = gxps_document_get_page (view->doc, page, &error);
	if (error) {
		g_printerr ("Error getting page %d: %s\n", page, error->message);
		g_error_free (error);

		return;
	}
	gxps_page_get_size (xps_page, &width, &height);

	cairo_surface_destroy (view->surface);
	view->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
						    width, height);

	cr = cairo_create (view->surface);
	gxps_page_render (xps_page, cr, &error);
	if (error) {
		g_printerr ("Error rendering page: %d: %s\n", page, error->message);
		g_error_free (error);
	}
	cairo_destroy (cr);

	gtk_widget_set_size_request (view->darea, width, height);
	gtk_widget_queue_draw (view->darea);

	g_object_unref (xps_page);
}