X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=pdf%2Fev-poppler.cc;h=0f9a3562c2dde199d2ff3a763ba2ade5916be8ff;hb=274f17472f798aa469fe6089291efa5379de157c;hp=a4033881b314680334ea9c03be6ce426c88eedd4;hpb=dbe438c1e95c6d2901c282a0c0e204c94114fb75;p=evince.git diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index a4033881..0f9a3562 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -56,6 +56,12 @@ struct _PdfDocument PopplerPSFile *ps_file; gchar *password; + PopplerOrientation orientation; + + PopplerFontInfo *font_info; + PopplerFontsIter *fonts_iter; + int fonts_scanned_pages; + PdfDocumentSearch *search; }; @@ -100,6 +106,14 @@ pdf_document_dispose (GObject *object) if (pdf_document->document) { g_object_unref (pdf_document->document); } + + if (pdf_document->font_info) { + poppler_font_info_free (pdf_document->font_info); + } + + if (pdf_document->fonts_iter) { + poppler_fonts_iter_free (pdf_document->fonts_iter); + } } static void @@ -114,6 +128,7 @@ static void pdf_document_init (PdfDocument *pdf_document) { pdf_document->password = NULL; + pdf_document->orientation = POPPLER_ORIENTATION_PORTRAIT; } static void @@ -161,6 +176,24 @@ pdf_document_save (EvDocument *document, return retval; } +static PopplerOrientation +get_document_orientation (PdfDocument *pdf_document) +{ +#ifdef POPPLER_ORIENTATION + PopplerPage *page; + + /* Should prolly be smarter here and check more than first page */ + page = poppler_document_get_page (pdf_document->document, 0); + if (page) { + return poppler_page_get_orientation (page); + } else { + return POPPLER_ORIENTATION_PORTRAIT; + } +#else + return POPPLER_ORIENTATION_PORTRAIT; +#endif +} + static gboolean pdf_document_load (EvDocument *document, const char *uri, @@ -177,6 +210,8 @@ pdf_document_load (EvDocument *document, return FALSE; } + pdf_document->orientation = get_document_orientation (pdf_document); + return TRUE; } @@ -192,11 +227,11 @@ pdf_document_get_page_size (EvDocument *document, double *width, double *height) { + PdfDocument *pdf_document = PDF_DOCUMENT (document); PopplerPage *poppler_page; - poppler_page = poppler_document_get_page (PDF_DOCUMENT (document)->document, - page); - + poppler_page = poppler_document_get_page (pdf_document->document, page); + poppler_page_set_orientation (poppler_page, pdf_document->orientation); poppler_page_get_size (poppler_page, width, height); } @@ -270,6 +305,7 @@ pdf_document_render_pixbuf (EvDocument *document, pdf_document = PDF_DOCUMENT (document); poppler_page = poppler_document_get_page (pdf_document->document, page); + poppler_page_set_orientation (poppler_page, pdf_document->orientation); poppler_page_get_size (poppler_page, &width_points, &height_points); width = (int) ((width_points * scale) + 0.5); @@ -473,6 +509,54 @@ pdf_document_get_text (EvDocument *document, int page, EvRectangle *rect) return poppler_page_get_text (poppler_page, &r); } +static EvOrientation +pdf_document_get_orientation (EvDocument *document) +{ + EvOrientation result; + PdfDocument *pdf_document = PDF_DOCUMENT (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; + } + + return result; +} + +static void +pdf_document_set_orientation (EvDocument *document, EvOrientation orientation) +{ + PdfDocument *pdf_document = PDF_DOCUMENT (document); + 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; + } + + pdf_document->orientation = poppler_orientation; +} + static void pdf_document_document_iface_init (EvDocumentIface *iface) { @@ -486,6 +570,8 @@ pdf_document_document_iface_init (EvDocumentIface *iface) iface->get_text = pdf_document_get_text; iface->can_get_text = pdf_document_can_get_text; iface->get_info = pdf_document_get_info; + iface->set_orientation = pdf_document_set_orientation; + iface->get_orientation = pdf_document_get_orientation; }; static void @@ -495,53 +581,77 @@ pdf_document_security_iface_init (EvDocumentSecurityIface *iface) iface->set_password = pdf_document_set_password; } -static void -build_fonts_list (PdfDocument *pdf_document, - GtkTreeModel *model, - GtkTreeIter *parent, - PopplerFontsIter *iter) +static gdouble +pdf_document_fonts_get_progress (EvDocumentFonts *document_fonts) { -#ifdef POPPLER_FONT_INFO - do { - GtkTreeIter list_iter; - PopplerIndexIter *child; - char *name; - - name = poppler_fonts_iter_get_name (iter); - gtk_list_store_append (GTK_LIST_STORE (model), &list_iter); - gtk_list_store_set (GTK_LIST_STORE (model), &list_iter, - EV_DOCUMENT_FONTS_COLUMN_NAME, name, - -1); - g_free (name); - } while (poppler_fonts_iter_next (iter)); -#endif + PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts); + int n_pages; + + n_pages = pdf_document_get_n_pages (EV_DOCUMENT (pdf_document)); + + return (double)pdf_document->fonts_scanned_pages / (double)n_pages; } -static GtkTreeModel * -pdf_document_fonts_get_fonts_model (EvDocumentFonts *document_fonts) +static gboolean +pdf_document_fonts_scan (EvDocumentFonts *document_fonts, + int n_pages) { PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts); - GtkTreeModel *model = NULL; - PopplerFontsIter *iter; + gboolean result; - g_return_val_if_fail (PDF_IS_DOCUMENT (document_fonts), NULL); + g_return_val_if_fail (PDF_IS_DOCUMENT (document_fonts), FALSE); - iter = poppler_fonts_iter_new (pdf_document->document); - /* Create the model iff we have items*/ - if (iter != NULL) { - model = (GtkTreeModel *) gtk_list_store_new (EV_DOCUMENT_FONTS_COLUMN_NUM_COLUMNS, - G_TYPE_STRING); - build_fonts_list (pdf_document, model, NULL, iter); - poppler_fonts_iter_free (iter); + if (pdf_document->font_info == NULL) { + pdf_document->font_info = poppler_font_info_new (pdf_document->document); } - return model; + if (pdf_document->fonts_iter) { + poppler_fonts_iter_free (pdf_document->fonts_iter); + } + + pdf_document->fonts_scanned_pages += n_pages; + + result = poppler_font_info_scan (pdf_document->font_info, n_pages, + &pdf_document->fonts_iter); + if (!result) { + pdf_document->fonts_scanned_pages = 0; + poppler_font_info_free (pdf_document->font_info); + pdf_document->font_info = NULL; + } + + return result; +} + +static void +pdf_document_fonts_fill_model (EvDocumentFonts *document_fonts, + GtkTreeModel *model) +{ + PdfDocument *pdf_document = PDF_DOCUMENT (document_fonts); + PopplerFontsIter *iter = pdf_document->fonts_iter; + + g_return_if_fail (PDF_IS_DOCUMENT (document_fonts)); + + if (iter) { + do { + GtkTreeIter list_iter; + PopplerIndexIter *child; + const char *name; + + name = poppler_fonts_iter_get_name (iter); + gtk_list_store_append (GTK_LIST_STORE (model), &list_iter); + gtk_list_store_set (GTK_LIST_STORE (model), &list_iter, + EV_DOCUMENT_FONTS_COLUMN_NAME, name, + -1); + } while (poppler_fonts_iter_next (iter)); + } } static void pdf_document_document_fonts_iface_init (EvDocumentFontsIface *iface) { - iface->get_fonts_model = pdf_document_fonts_get_fonts_model; + iface->fill_model = pdf_document_fonts_fill_model; + iface->scan = pdf_document_fonts_scan; + iface->get_progress = pdf_document_fonts_get_progress; } static gboolean @@ -591,8 +701,10 @@ build_tree (PdfDocument *pdf_document, PopplerIndexIter *child; PopplerAction *action; EvLink *link; + gboolean expand; action = poppler_index_iter_get_action (iter); + expand = poppler_index_iter_is_open (iter); if (action) { gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent); link = ev_link_from_action (action); @@ -601,6 +713,7 @@ build_tree (PdfDocument *pdf_document, gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter, EV_DOCUMENT_LINKS_COLUMN_MARKUP, ev_link_get_title (link), EV_DOCUMENT_LINKS_COLUMN_LINK, link, + EV_DOCUMENT_LINKS_COLUMN_EXPAND, expand, -1); child = poppler_index_iter_get_child (iter); if (child) @@ -621,16 +734,16 @@ pdf_document_links_get_links_model (EvDocumentLinks *document_links) g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL); iter = poppler_index_iter_new (pdf_document->document); - /* Create the model iff we have items*/ + /* Create the model if we have items*/ if (iter != NULL) { model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS, G_TYPE_STRING, - G_TYPE_POINTER); + G_TYPE_POINTER, + G_TYPE_BOOLEAN); build_tree (pdf_document, model, NULL, iter); poppler_index_iter_free (iter); } - return model; }