]> www.fi.muni.cz Git - evince.git/blobdiff - backend/pdf/ev-poppler.cc
Add support for double and triple click selections.
[evince.git] / backend / pdf / ev-poppler.cc
index cc6137b11be2d0bef8271aa4fec08084f47de800..09edfb4165ea8067817d2fdce9ef4d87df0d3e9f 100644 (file)
@@ -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;
 
@@ -565,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)
 {
@@ -716,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)
 {
@@ -752,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;
 };
 
@@ -1559,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);
 }
@@ -1592,6 +1563,7 @@ pdf_document_file_exporter_begin (EvFileExporter        *exporter,
        ctx->pages_per_sheet = fc->pages_per_sheet;
 
        landscape = (fc->orientation == EV_FILE_EXPORTER_LANDSCAPE);
+       change_orient = landscape;
        
        switch (fc->pages_per_sheet) {
                default:
@@ -1600,7 +1572,6 @@ pdf_document_file_exporter_begin (EvFileExporter        *exporter,
                        ctx->pages_y = 1;
                        break;
                case 2:
-                       change_orient = TRUE;
                        landscape = !landscape;
                        ctx->pages_x = 1;
                        ctx->pages_y = 2;
@@ -1610,7 +1581,6 @@ pdf_document_file_exporter_begin (EvFileExporter        *exporter,
                        ctx->pages_y = 2;
                        break;
                case 6:
-                       change_orient = TRUE;
                        landscape = !landscape;
                        ctx->pages_x = 2;
                        ctx->pages_y = 3;
@@ -1625,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;
@@ -1632,17 +1604,20 @@ pdf_document_file_exporter_begin (EvFileExporter        *exporter,
                width = fc->paper_width;
                height = fc->paper_height;
        }
-       
+
        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->page_width = width / ctx->pages_x;
-       ctx->page_height = height / ctx->pages_y;
 
        ctx->pages_printed = 0;
 
@@ -1669,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
 }
@@ -1698,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);
@@ -1768,6 +1759,7 @@ pdf_selection_render_selection (EvSelection      *selection,
                                cairo_surface_t **surface,
                                EvRectangle      *points,
                                EvRectangle      *old_points,
+                               EvSelectionStyle  style,
                                GdkColor         *text,
                                GdkColor         *base)
 {
@@ -1783,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;
 
@@ -1803,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);
@@ -1818,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)
@@ -1828,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;
@@ -1843,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;
 }
@@ -1863,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;
@@ -1873,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;
 }