X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=backend%2Fpdf%2Fev-poppler.cc;h=09edfb4165ea8067817d2fdce9ef4d87df0d3e9f;hb=982600bbceb76a22d5c7b3e0cbe6e20421105ad6;hp=38a96a533a4d75fd4b397513fce56e06a48bdbad;hpb=85fa11d86616d3a9c5a5cfeba78dd7aa72e7997a;p=evince.git diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index 38a96a53..09edfb41 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -67,8 +67,9 @@ typedef struct { typedef struct { EvFileExporterFormat format; - PopplerPSFile *ps_file; + gboolean landscape; + /* Pages per sheet */ gint pages_per_sheet; gint pages_printed; @@ -79,6 +80,8 @@ typedef struct { #ifdef HAVE_CAIRO_PRINT cairo_t *cr; +#else + PopplerPSFile *ps_file; #endif } PdfPrintContext; @@ -126,6 +129,7 @@ static EvLink *ev_link_from_action (PdfDocument *pdf_document, static void pdf_document_search_free (PdfDocumentSearch *search); static void pdf_print_context_free (PdfPrintContext *ctx); +#ifdef HAVE_FORMS G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT, { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, @@ -138,10 +142,8 @@ G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT, pdf_document_document_links_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_IMAGES, pdf_document_document_images_iface_init); -#ifdef HAVE_FORMS G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FORMS, pdf_document_document_forms_iface_init); -#endif /* HAVE_FORMS */ G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FONTS, pdf_document_document_fonts_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND, @@ -153,7 +155,31 @@ G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TRANSITION, pdf_document_page_transition_iface_init); }); - +#else /* !HAVE_FORMS */ +G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT, + { + G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, + pdf_document_document_iface_init); + G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY, + pdf_document_security_iface_init); + G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, + pdf_document_document_thumbnails_iface_init); + G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS, + pdf_document_document_links_iface_init); + G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_IMAGES, + pdf_document_document_images_iface_init); + G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FONTS, + pdf_document_document_fonts_iface_init); + G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND, + pdf_document_find_iface_init); + G_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, + pdf_document_file_exporter_iface_init); + G_IMPLEMENT_INTERFACE (EV_TYPE_SELECTION, + pdf_selection_iface_init); + G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_TRANSITION, + pdf_document_page_transition_iface_init); + }); +#endif /* HAVE_FORMS */ static void set_rc_data (PdfDocument *pdf_document, @@ -477,7 +503,7 @@ pdf_document_render (EvDocument *document, #ifdef HAVE_POPPLER_PAGE_RENDER cairo_t *cr; - surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height); memset (cairo_image_surface_get_data (surface), 0xff, cairo_image_surface_get_height (surface) * @@ -542,12 +568,6 @@ pdf_document_set_password (EvDocumentSecurity *document_security, document->password = g_strdup (password); } -static gboolean -pdf_document_can_get_text (EvDocument *document) -{ - return TRUE; -} - static EvDocumentInfo * pdf_document_get_info (EvDocument *document) { @@ -693,31 +713,6 @@ pdf_document_get_info (EvDocument *document) return info; } -static char * -pdf_document_get_text (EvDocument *document, int page, EvRectangle *rect) -{ - PdfDocument *pdf_document = PDF_DOCUMENT (document); - PopplerPage *poppler_page; - PopplerRectangle r; - double height; - char *text; - - poppler_page = poppler_document_get_page (pdf_document->document, page); - g_return_val_if_fail (poppler_page != NULL, NULL); - - poppler_page_get_size (poppler_page, NULL, &height); - r.x1 = rect->x1; - r.y1 = height - rect->y2; - r.x2 = rect->x2; - r.y2 = height - rect->y1; - - text = poppler_page_get_text (poppler_page, &r); - - g_object_unref (poppler_page); - - return text; -} - static void pdf_document_document_iface_init (EvDocumentIface *iface) { @@ -729,8 +724,6 @@ pdf_document_document_iface_init (EvDocumentIface *iface) iface->has_attachments = pdf_document_has_attachments; iface->get_attachments = pdf_document_get_attachments; iface->render = pdf_document_render; - iface->get_text = pdf_document_get_text; - iface->can_get_text = pdf_document_can_get_text; iface->get_info = pdf_document_get_info; }; @@ -1270,7 +1263,15 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails g_return_val_if_fail (poppler_page != NULL, NULL); pixbuf = poppler_page_get_thumbnail (poppler_page); - if (!pixbuf) { + if (pixbuf) { + /* Rotate provided thumbnail if needed */ + GdkPixbuf *rotated_pixbuf; + + rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, + (GdkPixbufRotation) (360 - rc->rotation)); + g_object_unref (pixbuf); + pixbuf = rotated_pixbuf; + } else { /* There is no provided thumbnail. We need to make one. */ pixbuf = make_thumbnail_for_page (pdf_document, poppler_page, rc); } @@ -1528,15 +1529,16 @@ pdf_print_context_free (PdfPrintContext *ctx) if (!ctx) return; - if (ctx->ps_file) { - poppler_ps_file_free (ctx->ps_file); - ctx->ps_file = NULL; - } #ifdef HAVE_CAIRO_PRINT if (ctx->cr) { cairo_destroy (ctx->cr); ctx->cr = NULL; } +#else + if (ctx->ps_file) { + poppler_ps_file_free (ctx->ps_file); + ctx->ps_file = NULL; + } #endif g_free (ctx); } @@ -1548,7 +1550,7 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, PdfDocument *pdf_document = PDF_DOCUMENT (exporter); PdfPrintContext *ctx; gdouble width, height; - gboolean change_orient = FALSE; + gboolean landscape, change_orient = FALSE; #ifdef HAVE_CAIRO_PRINT cairo_surface_t *surface = NULL; #endif @@ -1560,6 +1562,9 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, ctx->format = fc->format; ctx->pages_per_sheet = fc->pages_per_sheet; + landscape = (fc->orientation == EV_FILE_EXPORTER_LANDSCAPE); + change_orient = landscape; + switch (fc->pages_per_sheet) { default: case 1: @@ -1567,18 +1572,18 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, ctx->pages_y = 1; break; case 2: - change_orient = TRUE; - ctx->pages_x = 2; - ctx->pages_y = 1; + landscape = !landscape; + ctx->pages_x = 1; + ctx->pages_y = 2; break; case 4: ctx->pages_x = 2; ctx->pages_y = 2; break; case 6: - change_orient = TRUE; - ctx->pages_x = 3; - ctx->pages_y = 2; + landscape = !landscape; + ctx->pages_x = 2; + ctx->pages_y = 3; break; case 9: ctx->pages_x = 3; @@ -1590,6 +1595,8 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, break; } + ctx->landscape = landscape; + if (change_orient) { width = fc->paper_height; height = fc->paper_width; @@ -1598,8 +1605,19 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, height = fc->paper_height; } - ctx->page_width = width / ctx->pages_x; - ctx->page_height = height / ctx->pages_y; + if (landscape) { + gint tmp; + + tmp = ctx->pages_x; + ctx->pages_x = ctx->pages_y; + ctx->pages_y = tmp; + + ctx->page_width = height / ctx->pages_x; + ctx->page_height = width / ctx->pages_y; + } else { + ctx->page_width = width / ctx->pages_x; + ctx->page_height = height / ctx->pages_y; + } ctx->pages_printed = 0; @@ -1626,6 +1644,16 @@ pdf_document_file_exporter_begin (EvFileExporter *exporter, #ifdef HAVE_CAIRO_PRINT ctx->cr = cairo_create (surface); + if (landscape) { + cairo_matrix_t matrix; + + cairo_translate (ctx->cr, width, 0); + cairo_matrix_init (&matrix, + 0, 1, + -1, 0, + 0, 0); + cairo_transform (ctx->cr, &matrix); + } cairo_surface_destroy (surface); #endif } @@ -1655,9 +1683,15 @@ pdf_document_file_exporter_do_page (EvFileExporter *exporter, cairo_translate (ctx->cr, x * ctx->page_width, y * ctx->page_height); - cairo_scale (ctx->cr, - ctx->page_width / page_width, - ctx->page_height / page_height); + if (ctx->landscape) { + cairo_scale (ctx->cr, + ctx->page_height / page_height, + ctx->page_height / page_height); + } else { + cairo_scale (ctx->cr, + ctx->page_width / page_width, + ctx->page_height / page_height); + } #ifdef HAVE_POPPLER_PAGE_RENDER poppler_page_render (poppler_page, ctx->cr); @@ -1725,6 +1759,7 @@ pdf_selection_render_selection (EvSelection *selection, cairo_surface_t **surface, EvRectangle *points, EvRectangle *old_points, + EvSelectionStyle style, GdkColor *text, GdkColor *base) { @@ -1740,7 +1775,6 @@ pdf_selection_render_selection (EvSelection *selection, width = (int) ((width_points * rc->scale) + 0.5); height = (int) ((height_points * rc->scale) + 0.5); - #ifdef HAVE_POPPLER_PAGE_RENDER cairo_t *cr; @@ -1760,7 +1794,7 @@ pdf_selection_render_selection (EvSelection *selection, cr, (PopplerRectangle *)points, (PopplerRectangle *)old_points, - POPPLER_SELECTION_NORMAL, /* SelectionStyle */ + (PopplerSelectionStyle)style, text, base); cairo_destroy (cr); @@ -1775,7 +1809,7 @@ pdf_selection_render_selection (EvSelection *selection, rc->scale, rc->rotation, pixbuf, (PopplerRectangle *)points, (PopplerRectangle *)old_points, - POPPLER_SELECTION_NORMAL, /* SelectionStyle */ + (PopplerSelectionStyle)style, text, base); if (*surface) @@ -1785,10 +1819,40 @@ pdf_selection_render_selection (EvSelection *selection, #endif /* HAVE_POPPLER_PAGE_RENDER */ } +static gchar * +pdf_selection_get_selected_text (EvSelection *selection, + EvRenderContext *rc, + EvSelectionStyle style, + EvRectangle *points) +{ + PdfDocument *pdf_document = PDF_DOCUMENT (selection); + PopplerPage *poppler_page; + PopplerRectangle r; + double height; + char *retval; + + poppler_page = poppler_document_get_page (pdf_document->document, rc->page); + g_return_val_if_fail (poppler_page != NULL, NULL); + + poppler_page_get_size (poppler_page, NULL, &height); + r.x1 = points->x1; + r.y1 = height - points->y2; + r.x2 = points->x2; + r.y2 = height - points->y1; + + retval = poppler_page_get_text (poppler_page, + (PopplerSelectionStyle)style, + &r); + + g_object_unref (poppler_page); + + return retval; +} static GdkRegion * pdf_selection_get_selection_region (EvSelection *selection, EvRenderContext *rc, + EvSelectionStyle style, EvRectangle *points) { PdfDocument *pdf_document; @@ -1800,6 +1864,7 @@ pdf_selection_get_selection_region (EvSelection *selection, retval = poppler_page_get_selection_region ((PopplerPage *)rc->data, rc->scale, + (PopplerSelectionStyle)style, (PopplerRectangle *) points); return retval; } @@ -1820,7 +1885,9 @@ pdf_selection_get_selection_map (EvSelection *selection, 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); + retval = poppler_page_get_selection_region (poppler_page, 1.0, + POPPLER_SELECTION_GLYPH, + &points); g_object_unref (poppler_page); return retval; @@ -1830,6 +1897,7 @@ static void pdf_selection_iface_init (EvSelectionIface *iface) { iface->render_selection = pdf_selection_render_selection; + iface->get_selected_text = pdf_selection_get_selected_text; iface->get_selection_region = pdf_selection_get_selection_region; iface->get_selection_map = pdf_selection_get_selection_map; }