22 #include <glib/gi18n-lib.h>
23 #include <libgxps/gxps.h>
65 g_object_unref (xps->
file);
70 g_object_unref (xps->
xps);
75 g_object_unref (xps->
doc);
79 G_OBJECT_CLASS (xps_document_parent_class)->dispose (
object);
90 xps->
file = g_file_new_for_uri (uri);
91 xps->
xps = gxps_file_new (xps->
file, error);
97 xps->
doc = gxps_file_get_document (xps->
xps, 0, error);
99 g_object_unref (xps->
xps);
117 dest = g_file_new_for_uri (uri);
118 retval = g_file_copy (xps->
file, dest,
119 G_FILE_COPY_TARGET_DEFAULT_PERMS |
120 G_FILE_COPY_OVERWRITE,
121 NULL, NULL, NULL, error);
122 g_object_unref (dest);
132 return gxps_document_get_n_pages (xps->
doc);
143 xps_page = gxps_document_get_page (xps->
doc, index, NULL);
159 gxps_page_get_size (GXPS_PAGE (page->
backend_page), width, height);
174 info->n_pages = gxps_document_get_n_pages (xps->
doc);
175 if (info->n_pages > 0) {
178 gxps_page = gxps_document_get_page (xps->
doc, 0, NULL);
179 gxps_page_get_size (gxps_page, &(info->paper_width), &(info->paper_height));
180 g_object_unref (gxps_page);
182 info->paper_width = info->paper_width / 96.0f * 25.4f;
183 info->paper_height = info->paper_height / 96.0f * 25.4f;
193 info->
name =
"libgxps";
194 info->
version = GXPS_VERSION_STRING;
199 static cairo_surface_t *
204 gdouble page_width, page_height;
206 double scale_x, scale_y;
207 cairo_surface_t *surface;
209 GError *error = NULL;
211 xps_page = GXPS_PAGE (rc->page->backend_page);
213 gxps_page_get_size (xps_page, &page_width, &page_height);
217 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
219 cr = cairo_create (surface);
221 cairo_set_source_rgb (cr, 1., 1., 1.);
224 switch (rc->rotation) {
226 cairo_translate (cr, width, 0);
229 cairo_translate (cr, width, height);
232 cairo_translate (cr, 0, height);
235 cairo_translate (cr, 0, 0);
240 cairo_scale (cr, scale_x, scale_y);
242 cairo_rotate (cr, rc->rotation * G_PI / 180.0);
243 gxps_page_render (xps_page, cr, &error);
247 g_warning (
"Error rendering page %d: %s\n",
248 rc->page->index, error->message);
249 g_error_free (error);
258 GObjectClass *object_class = G_OBJECT_CLASS (klass);
278 GXPSDocumentStructure *structure;
281 structure = gxps_document_get_structure (xps_document->
doc);
285 retval = gxps_document_structure_has_outline (structure);
286 g_object_unref (structure);
293 GXPSLinkTarget *target)
297 if (gxps_link_target_is_internal (target)) {
302 anchor = gxps_link_target_get_anchor (target);
305 doc = gxps_file_get_document_for_link_target (xps_document->
xps, target);
312 g_object_unref (dest);
313 }
else if (doc == -1 && anchor &&
314 gxps_document_get_page_for_anchor (xps_document->
doc, anchor) >= 0) {
320 g_object_unref (dest);
325 filename = g_file_get_path (xps_document->
file);
330 g_clear_object (&dest);
336 uri = gxps_link_target_get_uri (target);
347 GXPSOutlineIter *iter)
350 GtkTreeIter tree_iter;
351 GXPSOutlineIter child_iter;
354 GXPSLinkTarget *target;
357 target = gxps_outline_iter_get_target (iter);
358 title = g_markup_escape_text (gxps_outline_iter_get_description (iter), -1);
361 g_object_unref (action);
362 gxps_link_target_free (target);
364 gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
365 gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
370 g_object_unref (link);
373 if (gxps_outline_iter_children (&child_iter, iter))
374 build_tree (xps_document, model, &tree_iter, &child_iter);
375 }
while (gxps_outline_iter_next (iter));
378 static GtkTreeModel *
382 GXPSDocumentStructure *structure;
383 GXPSOutlineIter iter;
384 GtkTreeModel *model = NULL;
386 structure = gxps_document_get_structure (xps_document->
doc);
390 if (gxps_document_structure_outline_iter_init (&iter, structure)) {
396 build_tree (xps_document, model, NULL, &iter);
399 g_object_unref (structure);
410 GList *retval = NULL;
415 mapping_list = gxps_page_get_links (xps_page, NULL);
417 for (list = mapping_list; list; list = list->next) {
419 GXPSLinkTarget *target;
422 cairo_rectangle_t area;
424 xps_link = (GXPSLink *)list->
data;
426 gxps_link_get_area (xps_link, &area);
427 target = gxps_link_get_target (xps_link);
431 ev_link_mapping->
area.
x1 = area.x;
432 ev_link_mapping->
area.
x2 = area.x + area.width;
433 ev_link_mapping->
area.
y1 = area.y;
434 ev_link_mapping->
area.
y2 = area.y + area.height;
436 retval = g_list_prepend (retval, ev_link_mapping);
437 gxps_link_free (xps_link);
438 g_object_unref (action);
441 g_list_free (mapping_list);
448 const gchar *link_name)
453 cairo_rectangle_t area;
456 page = gxps_document_get_page_for_anchor (xps_document->
doc, link_name);
460 xps_page = gxps_document_get_page (xps_document->
doc, page, NULL);
464 if (gxps_page_get_anchor_destination (xps_page, link_name, &area, NULL))
467 g_object_unref (xps_page);
474 const gchar *link_name)
478 return gxps_document_get_page_for_anchor (xps_document->
doc, link_name);
497 GError *error = NULL;
499 gxps_page_render (GXPS_PAGE (page->
backend_page), cr, &error);
501 g_warning (
"Error rendering page %d for printing: %s\n",
502 page->
index, error->message);
503 g_error_free (error);