X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=pdf%2Fev-poppler.cc;h=aa33b7f1ba39726b3522fcbd72da5ccbc8522254;hb=12edcbdf1fbf4d45e9f111cd44df261623ab23e0;hp=e5444f60ce65bea6783059718ed49280e94c7d29;hpb=d8897e96db8b9c75a30d48c33b41fddf105b8df1;p=evince.git diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index e5444f60..aa33b7f1 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -33,6 +33,7 @@ #include "ev-document-fonts.h" #include "ev-document-security.h" #include "ev-document-thumbnails.h" +#include "ev-selection.h" typedef struct { PdfDocument *document; @@ -73,12 +74,16 @@ static void pdf_document_document_links_iface_init (EvDocumentLinksIface static void pdf_document_document_fonts_iface_init (EvDocumentFontsIface *iface); static void pdf_document_find_iface_init (EvDocumentFindIface *iface); static void pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface); +static void pdf_selection_iface_init (EvSelectionIface *iface); static void pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails, gint page, gint size, gint *width, gint *height); +static int pdf_document_get_n_pages (EvDocument *document); + static EvLink * ev_link_from_action (PopplerAction *action); +static void pdf_document_search_free (PdfDocumentSearch *search); G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT, @@ -97,13 +102,39 @@ G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT, pdf_document_find_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_PS_EXPORTER, pdf_document_ps_exporter_iface_init); + G_IMPLEMENT_INTERFACE (EV_TYPE_SELECTION, + pdf_selection_iface_init); }); +static void +pdf_document_search_free (PdfDocumentSearch *search) +{ + PdfDocument *pdf_document = search->document; + int n_pages; + int i; + + if (search->idle != 0) + g_source_remove (search->idle); + + n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document)); + for (i = 0; i < n_pages; i++) { + g_list_foreach (search->pages[i], (GFunc) g_free, NULL); + g_list_free (search->pages[i]); + } + + g_free (search->text); +} + static void pdf_document_dispose (GObject *object) { PdfDocument *pdf_document = PDF_DOCUMENT(object); + if (pdf_document->search) { + pdf_document_search_free (pdf_document->search); + pdf_document->search = NULL; + } + if (pdf_document->document) { g_object_unref (pdf_document->document); } @@ -303,8 +334,7 @@ pdf_document_get_links (EvDocument *document, static GdkPixbuf * pdf_document_render_pixbuf (EvDocument *document, - int page, - double scale) + EvRenderContext *rc) { PdfDocument *pdf_document; PopplerPage *poppler_page; @@ -314,12 +344,12 @@ pdf_document_render_pixbuf (EvDocument *document, pdf_document = PDF_DOCUMENT (document); poppler_page = poppler_document_get_page (pdf_document->document, - page); + rc->page); set_page_orientation (pdf_document, poppler_page); poppler_page_get_size (poppler_page, &width_points, &height_points); - width = (int) ((width_points * scale) + 0.5); - height = (int) ((height_points * scale) + 0.5); + width = (int) ((width_points * rc->scale) + 0.5); + height = (int) ((height_points * rc->scale) + 0.5); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, @@ -328,9 +358,8 @@ pdf_document_render_pixbuf (EvDocument *document, poppler_page_render_to_pixbuf (poppler_page, 0, 0, width, height, - scale, - pixbuf, - 0, 0); + rc->scale, + pixbuf); g_object_unref (poppler_page); @@ -538,18 +567,20 @@ pdf_document_get_orientation (EvDocument *document) } switch (pdf_document->orientation) { - case POPPLER_ORIENTATION_PORTRAIT: - result = EV_ORIENTATION_PORTRAIT; - break; - case POPPLER_ORIENTATION_LANDSCAPE: - result = EV_ORIENTATION_LANDSCAPE; - break; - case POPPLER_ORIENTATION_UPSIDEDOWN: - result = EV_ORIENTATION_UPSIDEDOWN; - break; - case POPPLER_ORIENTATION_SEASCAPE: - result = EV_ORIENTATION_SEASCAPE; - break; + case POPPLER_ORIENTATION_PORTRAIT: + result = EV_ORIENTATION_PORTRAIT; + break; + case POPPLER_ORIENTATION_LANDSCAPE: + result = EV_ORIENTATION_LANDSCAPE; + break; + case POPPLER_ORIENTATION_UPSIDEDOWN: + result = EV_ORIENTATION_UPSIDEDOWN; + break; + case POPPLER_ORIENTATION_SEASCAPE: + result = EV_ORIENTATION_SEASCAPE; + break; + default: + g_assert_not_reached (); } return result; @@ -562,18 +593,20 @@ pdf_document_set_orientation (EvDocument *document, EvOrientation orientation) PopplerOrientation poppler_orientation; switch (orientation) { - case EV_ORIENTATION_PORTRAIT: - poppler_orientation = POPPLER_ORIENTATION_PORTRAIT; - break; - case EV_ORIENTATION_LANDSCAPE: - poppler_orientation = POPPLER_ORIENTATION_LANDSCAPE; - break; - case EV_ORIENTATION_UPSIDEDOWN: - poppler_orientation = POPPLER_ORIENTATION_UPSIDEDOWN; - break; - case EV_ORIENTATION_SEASCAPE: - poppler_orientation = POPPLER_ORIENTATION_SEASCAPE; - break; + case EV_ORIENTATION_PORTRAIT: + poppler_orientation = POPPLER_ORIENTATION_PORTRAIT; + break; + case EV_ORIENTATION_LANDSCAPE: + poppler_orientation = POPPLER_ORIENTATION_LANDSCAPE; + break; + case EV_ORIENTATION_UPSIDEDOWN: + poppler_orientation = POPPLER_ORIENTATION_UPSIDEDOWN; + break; + case EV_ORIENTATION_SEASCAPE: + poppler_orientation = POPPLER_ORIENTATION_SEASCAPE; + break; + default: + g_assert_not_reached (); } pdf_document->orientation = poppler_orientation; @@ -657,7 +690,6 @@ pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts, if (iter) { do { GtkTreeIter list_iter; - PopplerIndexIter *child; const char *name; name = poppler_fonts_iter_get_name (iter); @@ -789,9 +821,8 @@ make_thumbnail_for_size (PdfDocument *pdf_document, gboolean border) { PopplerPage *poppler_page; - GdkPixbuf *pixbuf; + GdkPixbuf *pixbuf, *sub_pixbuf; int width, height; - int x_offset, y_offset; double scale; gdouble unscaled_width, unscaled_height; @@ -805,20 +836,24 @@ make_thumbnail_for_size (PdfDocument *pdf_document, if (border) { pixbuf = ev_document_misc_get_thumbnail_frame (width, height, NULL); - x_offset = 1; - y_offset = 1; + + sub_pixbuf = gdk_pixbuf_new_subpixbuf (pixbuf, + 1, 1, + width - 1, height - 1); } else { pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height); gdk_pixbuf_fill (pixbuf, 0xffffffff); - x_offset = 0; - y_offset = 0; + sub_pixbuf = gdk_pixbuf_new_subpixbuf (pixbuf, + 0, 0, + width, height); } poppler_page_render_to_pixbuf (poppler_page, 0, 0, width, height, - scale, pixbuf, - x_offset, y_offset); + scale, sub_pixbuf); + + g_object_unref (G_OBJECT (sub_pixbuf)); g_object_unref (poppler_page); return pixbuf; @@ -978,25 +1013,6 @@ pdf_document_search_new (PdfDocument *pdf_document, return search; } -static void -pdf_document_search_free (PdfDocumentSearch *search) -{ - PdfDocument *pdf_document = search->document; - int n_pages; - int i; - - if (search->idle != 0) - g_source_remove (search->idle); - - n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document)); - for (i = 0; i < n_pages; i++) { - g_list_foreach (search->pages[i], (GFunc) g_free, NULL); - g_list_free (search->pages[i]); - } - - g_free (search->text); -} - static void pdf_document_find_begin (EvDocumentFind *document, int page, @@ -1165,6 +1181,94 @@ pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface) iface->end = pdf_document_ps_exporter_end; } + +void +pdf_selection_render_selection (EvSelection *selection, + EvRenderContext *rc, + GdkPixbuf **pixbuf, + EvRectangle *points, + EvRectangle *old_points) +{ + PdfDocument *pdf_document; + PopplerPage *poppler_page; + double width_points, height_points; + gint width, height; + + pdf_document = PDF_DOCUMENT (selection); + poppler_page = poppler_document_get_page (pdf_document->document, + rc->page); + set_page_orientation (pdf_document, poppler_page); + + poppler_page_get_size (poppler_page, &width_points, &height_points); + width = (int) ((width_points * rc->scale) + 0.5); + height = (int) ((height_points * rc->scale) + 0.5); + + if (*pixbuf == NULL) { + * pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, + TRUE, 8, + width, height); + } + + poppler_page_render_selection (poppler_page, + rc->scale, *pixbuf, + (PopplerRectangle *)points, + (PopplerRectangle *)old_points); + g_object_unref (poppler_page); + +} + + +GdkRegion * +pdf_selection_get_selection_region (EvSelection *selection, + EvRenderContext *rc, + EvRectangle *points) +{ + PdfDocument *pdf_document; + PopplerPage *poppler_page; + GdkRegion *retval; + + pdf_document = PDF_DOCUMENT (selection); + poppler_page = poppler_document_get_page (pdf_document->document, + rc->page); + set_page_orientation (pdf_document, poppler_page); + + retval = poppler_page_get_selection_region (poppler_page, rc->scale, (PopplerRectangle *) points); + g_object_unref (poppler_page); + + return retval; +} + +GdkRegion * +pdf_selection_get_selection_map (EvSelection *selection, + EvRenderContext *rc) +{ + PdfDocument *pdf_document; + PopplerPage *poppler_page; + PopplerRectangle points; + GdkRegion *retval; + + pdf_document = PDF_DOCUMENT (selection); + poppler_page = poppler_document_get_page (pdf_document->document, + rc->page); + set_page_orientation (pdf_document, poppler_page); + + points.x1 = 0.0; + points.y1 = 0.0; + poppler_page_get_size (poppler_page, &(points.x2), &(points.y2)); + retval = poppler_page_get_selection_region (poppler_page, 1.0, &points); + g_object_unref (poppler_page); + + return retval; +} + +static void +pdf_selection_iface_init (EvSelectionIface *iface) +{ + iface->render_selection = pdf_selection_render_selection; + iface->get_selection_region = pdf_selection_get_selection_region; + iface->get_selection_map = pdf_selection_get_selection_map; +} + PdfDocument * pdf_document_new (void) {