Exemplo 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);
	}
}
Exemplo n.º 2
0
G_MODULE_EXPORT gboolean
tracker_extract_get_metadata (TrackerExtractInfo *info)
{
	TrackerResource *resource;
	GXPSDocument *document;
	GXPSFile *xps_file;
	GFile *file;
	gchar *filename;
	GError *error = NULL;

	file = tracker_extract_info_get_file (info);
	xps_file = gxps_file_new (file, &error);
	filename = g_file_get_path (file);

	if (error != NULL) {
		g_warning ("Unable to open '%s': %s", filename, error->message);
		g_error_free (error);
		g_free (filename);
		return FALSE;
	}

	document = gxps_file_get_document (xps_file, 0, &error);
	g_object_unref (xps_file);

	if (error != NULL) {
		g_warning ("Unable to read '%s': %s", filename, error->message);
		g_error_free (error);
		g_free (filename);
		return FALSE;
	}

	resource = tracker_resource_new (NULL);
	tracker_resource_add_uri (resource, "rdf:type", "nfo:PaginatedTextDocument");
	tracker_resource_set_int64 (resource, "nfo:pageCount", gxps_document_get_n_pages (document));

	g_object_unref (document);
	g_free (filename);

	tracker_extract_info_set_resource (info, resource);
	g_object_unref (resource);

	return TRUE;
}
Exemplo n.º 3
0
gint main (gint argc, gchar **argv)
{
	GFile     *file;
	GXPSFile  *xps;
	GXPSView  *view;
	GtkWidget *win;
	GtkWidget *hbox, *vbox, *sw;
        GtkWidget *button;
	guint      page = 0;
	GError    *error = NULL;

	if (argc < 2) {
		g_printerr ("Use: test-xps file\n");

		return 1;
	}

	gtk_init (&argc, &argv);

	file = g_file_new_for_commandline_arg (argv[1]);
	xps = gxps_file_new (file, &error);
	g_object_unref (file);

	if (error) {
		g_printerr ("Error creating file: %s\n", error->message);
		g_error_free (error);
		g_object_unref (xps);

		return 1;
	}

	view = g_new0 (GXPSView, 1);
	view->doc = gxps_file_get_document (xps, 0, &error);
	if (error) {
		g_printerr ("Error getting document 0: %s\n", error->message);
		g_error_free (error);
		g_object_unref (xps);

		return 1;
	}

	win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_default_size (GTK_WINDOW (win), 600, 600);
	g_signal_connect (win, "delete-event",
			  G_CALLBACK (gtk_main_quit),
			  NULL);

	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	view->spin_button = gtk_spin_button_new_with_range  (0,
							     gxps_document_get_n_pages (view->doc) - 1,
							     1);
	g_signal_connect (view->spin_button,
			  "value-changed",
			  G_CALLBACK (page_changed_callback),
			  view);
	gtk_box_pack_end (GTK_BOX (hbox), view->spin_button, FALSE, TRUE, 0);
	gtk_widget_show (view->spin_button);

        button = gtk_button_new ();
        g_signal_connect (button, "clicked",
                          G_CALLBACK (properties_button_clicked),
                          xps);
        gtk_button_set_image (GTK_BUTTON (button),
                              gtk_image_new_from_icon_name ("document-properties", GTK_ICON_SIZE_SMALL_TOOLBAR));
        gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
        gtk_widget_show (button);

	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
	gtk_widget_show (hbox);

	view->darea = gtk_drawing_area_new ();
	g_signal_connect (view->darea, "draw",
			  G_CALLBACK (drawing_area_draw),
			  view);

	sw = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
					GTK_POLICY_AUTOMATIC,
					GTK_POLICY_AUTOMATIC);
	gtk_container_add (GTK_CONTAINER (sw), view->darea);
	gtk_widget_show (view->darea);

	gtk_box_pack_end (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
	gtk_widget_show (sw);

	gtk_container_add (GTK_CONTAINER (win), vbox);
	gtk_widget_show (vbox);

	gtk_widget_show (win);

	if (argc > 2)
		page = atoi (argv[2]);
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (view->spin_button), page);
	if (page == 0)
		page_changed_callback (GTK_SPIN_BUTTON (view->spin_button), view);

	gtk_main ();

	g_object_unref (view->doc);
	g_object_unref (xps);
	cairo_surface_destroy (view->surface);
	g_free (view);

	return 0;
}