From 79986dda7231d1ef1c530909bde8e18a507a2a2a Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 14 Jun 2005 21:04:23 +0000 Subject: [PATCH] Add orientation api. Currently poppler api is not optimal, we need to set 2005-06-14 Marco Pesenti Gritti * backend/ev-document.c: (ev_document_set_orientation): * backend/ev-document.h: * pdf/ev-poppler.cc: Add orientation api. Currently poppler api is not optimal, we need to set orientation every time we _get a page * data/evince-ui.xml: * shell/ev-window.c: (ev_window_cmd_edit_landscape), (ev_window_cmd_edit_portrait), (ev_window_cmd_edit_flip): Add orientation menu items * shell/ev-page-cache.c: (ev_page_cache_clear): * shell/ev-page-cache.h: Add api to clear the cache * shell/ev-view.c: (setup_caches), (clear_caches), (ev_view_set_document), (ev_view_zoom_out), (ev_view_set_orientation): * shell/ev-view.h: Implement orientation changing --- ChangeLog | 27 +++++++++++ backend/ev-document.c | 9 ++++ backend/ev-document.h | 105 ++++++++++++++++++++++++------------------ data/evince-ui.xml | 4 ++ pdf/ev-poppler.cc | 37 +++++++++++++-- shell/ev-page-cache.c | 6 +++ shell/ev-page-cache.h | 3 +- shell/ev-view.c | 45 ++++++++++++++---- shell/ev-view.h | 12 +++-- shell/ev-window.c | 30 ++++++++++++ 10 files changed, 215 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index f2a3b7d8..4b20650f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2005-06-14 Marco Pesenti Gritti + + * backend/ev-document.c: (ev_document_set_orientation): + * backend/ev-document.h: + * pdf/ev-poppler.cc: + + Add orientation api. Currently poppler api is not optimal, + we need to set orientation every time we _get a page + + * data/evince-ui.xml: + * shell/ev-window.c: (ev_window_cmd_edit_landscape), + (ev_window_cmd_edit_portrait), (ev_window_cmd_edit_flip): + + Add orientation menu items + + * shell/ev-page-cache.c: (ev_page_cache_clear): + * shell/ev-page-cache.h: + + Add api to clear the cache + + * shell/ev-view.c: (setup_caches), (clear_caches), + (ev_view_set_document), (ev_view_zoom_out), + (ev_view_set_orientation): + * shell/ev-view.h: + + Implement orientation changing + 2005-06-13 Marco Pesenti Gritti * backend/ev-document-fonts.c: (ev_document_fonts_get_progress), diff --git a/backend/ev-document.c b/backend/ev-document.c index d4130838..4513df50 100644 --- a/backend/ev-document.c +++ b/backend/ev-document.c @@ -218,6 +218,15 @@ ev_document_render_pixbuf (EvDocument *document, return retval; } +void +ev_document_set_orientation (EvDocument *document, + EvOrientation orientation) +{ + EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); + + iface->set_orientation (document, orientation); +} + void ev_document_info_free (EvDocumentInfo *info) { diff --git a/backend/ev-document.h b/backend/ev-document.h index ffc9c2ec..1fd8fe32 100644 --- a/backend/ev-document.h +++ b/backend/ev-document.h @@ -55,6 +55,15 @@ typedef enum EV_DOCUMENT_ERROR_ENCRYPTED } EvDocumentError; +typedef enum +{ + EV_ORIENTATION_DOCUMENT, + EV_ORIENTATION_PORTRAIT, + EV_ORIENTATION_LANDSCAPE, + EV_ORIENTATION_UPSIDEDOWN, + EV_ORIENTATION_SEASCAPE +} EvOrientation; + typedef struct { double x1; double y1; @@ -67,29 +76,31 @@ struct _EvDocumentIface GTypeInterface base_iface; /* Methods */ - gboolean (* load) (EvDocument *document, - const char *uri, - GError **error); - gboolean (* save) (EvDocument *document, - const char *uri, - GError **error); - int (* get_n_pages) (EvDocument *document); - void (* get_page_size) (EvDocument *document, - int page, - double *width, - double *height); - char * (* get_page_label) (EvDocument *document, - int page); - gboolean (* can_get_text) (EvDocument *document); - char * (* get_text) (EvDocument *document, - int page, - EvRectangle *rect); - GList * (* get_links) (EvDocument *document, - int page); - GdkPixbuf * (* render_pixbuf) (EvDocument *document, - int page, - double scale); - EvDocumentInfo *(* get_info) (EvDocument *document); + gboolean (* load) (EvDocument *document, + const char *uri, + GError **error); + gboolean (* save) (EvDocument *document, + const char *uri, + GError **error); + int (* get_n_pages) (EvDocument *document); + void (* get_page_size) (EvDocument *document, + int page, + double *width, + double *height); + char * (* get_page_label) (EvDocument *document, + int page); + gboolean (* can_get_text) (EvDocument *document); + char * (* get_text) (EvDocument *document, + int page, + EvRectangle *rect); + GList * (* get_links) (EvDocument *document, + int page); + GdkPixbuf * (* render_pixbuf) (EvDocument *document, + int page, + double scale); + void (* set_orientation) (EvDocument *document, + EvOrientation orientation); + EvDocumentInfo * (* get_info) (EvDocument *document); }; GType ev_document_get_type (void); @@ -98,29 +109,31 @@ GMutex *ev_document_get_doc_mutex (void); void ev_document_doc_mutex_lock (void); void ev_document_doc_mutex_unlock (void); -EvDocumentInfo *ev_document_get_info (EvDocument *document); -gboolean ev_document_load (EvDocument *document, - const char *uri, - GError **error); -gboolean ev_document_save (EvDocument *document, - const char *uri, - GError **error); -int ev_document_get_n_pages (EvDocument *document); -void ev_document_get_page_size (EvDocument *document, - int page, - double *width, - double *height); -char *ev_document_get_page_label (EvDocument *document, - int page); -gboolean ev_document_can_get_text (EvDocument *document); -char *ev_document_get_text (EvDocument *document, - int page, - EvRectangle *rect); -GList *ev_document_get_links (EvDocument *document, - int page); -GdkPixbuf *ev_document_render_pixbuf (EvDocument *document, - int page, - double scale); +EvDocumentInfo *ev_document_get_info (EvDocument *document); +gboolean ev_document_load (EvDocument *document, + const char *uri, + GError **error); +gboolean ev_document_save (EvDocument *document, + const char *uri, + GError **error); +int ev_document_get_n_pages (EvDocument *document); +void ev_document_get_page_size (EvDocument *document, + int page, + double *width, + double *height); +char *ev_document_get_page_label (EvDocument *document, + int page); +gboolean ev_document_can_get_text (EvDocument *document); +char *ev_document_get_text (EvDocument *document, + int page, + EvRectangle *rect); +GList *ev_document_get_links (EvDocument *document, + int page); +GdkPixbuf *ev_document_render_pixbuf (EvDocument *document, + int page, + double scale); +void ev_document_set_orientation (EvDocument *document, + EvOrientation orientation); G_END_DECLS diff --git a/data/evince-ui.xml b/data/evince-ui.xml index e519b85e..1d251ca0 100644 --- a/data/evince-ui.xml +++ b/data/evince-ui.xml @@ -20,6 +20,10 @@ + + + + diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index 7c60d9cf..9989d827 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -56,6 +56,8 @@ struct _PdfDocument PopplerPSFile *ps_file; gchar *password; + PopplerOrientation orientation; + PopplerFontInfo *font_info; PopplerFontsIter *fonts_iter; int fonts_scanned_pages; @@ -204,11 +206,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); } @@ -282,6 +284,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); @@ -485,6 +488,33 @@ pdf_document_get_text (EvDocument *document, int page, EvRectangle *rect) return poppler_page_get_text (poppler_page, &r); } +static void +pdf_document_set_orientation (EvDocument *document, EvOrientation orientation) +{ + PdfDocument *pdf_document = PDF_DOCUMENT (document); + PopplerOrientation poppler_orientation; + + switch (orientation) { + case EV_ORIENTATION_DOCUMENT: + poppler_orientation = POPPLER_ORIENTATION_DOCUMENT; + 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; + } + + pdf_document->orientation = poppler_orientation; +} + static void pdf_document_document_iface_init (EvDocumentIface *iface) { @@ -498,6 +528,7 @@ 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; }; static void diff --git a/shell/ev-page-cache.c b/shell/ev-page-cache.c index 6c44c9fc..936328ff 100644 --- a/shell/ev-page-cache.c +++ b/shell/ev-page-cache.c @@ -482,4 +482,10 @@ ev_page_cache_get (EvDocument *document) return page_cache; } +void +ev_page_cache_clear (EvDocument *document) +{ + g_return_if_fail (EV_IS_DOCUMENT (document)); + g_object_set_data (G_OBJECT (document), PAGE_CACHE_STRING, NULL); +} diff --git a/shell/ev-page-cache.h b/shell/ev-page-cache.h index b0bf6ccd..2b270b04 100644 --- a/shell/ev-page-cache.h +++ b/shell/ev-page-cache.h @@ -67,7 +67,8 @@ void ev_page_cache_set_link (EvPageCache *page_cache, gboolean ev_page_cache_next_page (EvPageCache *page_cache); gboolean ev_page_cache_prev_page (EvPageCache *page_cache); -EvPageCache* ev_page_cache_get (EvDocument *document); +EvPageCache *ev_page_cache_get (EvDocument *document); +void ev_page_cache_clear (EvDocument *document); G_END_DECLS diff --git a/shell/ev-view.c b/shell/ev-view.c index ff05be21..3e31d293 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -1899,6 +1899,28 @@ ev_view_new (void) return view; } +static void +setup_caches (EvView *view) +{ + view->page_cache = ev_page_cache_get (view->document); + g_signal_connect (view->page_cache, "page-changed", G_CALLBACK (page_changed_cb), view); + view->pixbuf_cache = ev_pixbuf_cache_new (view->document); + g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view); +} + +static void +clear_caches (EvView *view) +{ + if (view->pixbuf_cache) { + g_object_unref (view->pixbuf_cache); + view->pixbuf_cache = NULL; + } + + if (view->document) { + ev_page_cache_clear (view->document); + } +} + void ev_view_set_document (EvView *view, EvDocument *document) @@ -1915,10 +1937,7 @@ ev_view_set_document (EvView *view, } - if (view->pixbuf_cache) { - g_object_unref (view->pixbuf_cache); - view->pixbuf_cache = NULL; - } + clear_caches (view); view->document = document; view->find_page = 0; @@ -1932,10 +1951,8 @@ ev_view_set_document (EvView *view, G_CALLBACK (find_changed_cb), view); } - view->page_cache = ev_page_cache_get (view->document); - g_signal_connect (view->page_cache, "page-changed", G_CALLBACK (page_changed_cb), view); - view->pixbuf_cache = ev_pixbuf_cache_new (view->document); - g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view); + + setup_caches (view); } gtk_widget_queue_resize (GTK_WIDGET (view)); @@ -2125,6 +2142,18 @@ ev_view_zoom_out (EvView *view) ev_view_set_zoom (view, ZOOM_OUT_FACTOR, TRUE); } +void +ev_view_set_orientation (EvView *view, + EvOrientation orientation) +{ + ev_document_set_orientation (view->document, orientation); + + clear_caches (view); + setup_caches (view); + + gtk_widget_queue_resize (GTK_WIDGET (view)); +} + static double zoom_for_size_fit_width (int doc_width, int doc_height, diff --git a/shell/ev-view.h b/shell/ev-view.h index 42437616..2244ae0f 100644 --- a/shell/ev-view.h +++ b/shell/ev-view.h @@ -85,12 +85,14 @@ void ev_view_set_zoom (EvView *view, double factor, gboolean relative); double ev_view_get_zoom (EvView *view); +void ev_view_set_zoom_for_size (EvView *view, + int width, + int height, + int vsb_width, + int hsb_height); +void ev_view_set_orientation (EvView *view, + EvOrientation orientation); -void ev_view_set_zoom_for_size (EvView *view, - int width, - int height, - int vsb_width, - int hsb_height); /* Find */ gboolean ev_view_can_find_next (EvView *view); void ev_view_find_next (EvView *view); diff --git a/shell/ev-window.c b/shell/ev-window.c index 46ae9a20..12fa3d86 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -1781,6 +1781,27 @@ ev_window_cmd_edit_toolbar_cb (GtkDialog *dialog, gint response, gpointer data) gtk_widget_destroy (GTK_WIDGET (dialog)); } +static void +ev_window_cmd_edit_landscape (GtkAction *action, EvWindow *ev_window) +{ + ev_view_set_orientation (EV_VIEW (ev_window->priv->view), + EV_ORIENTATION_LANDSCAPE); +} + +static void +ev_window_cmd_edit_portrait (GtkAction *action, EvWindow *ev_window) +{ + ev_view_set_orientation (EV_VIEW (ev_window->priv->view), + EV_ORIENTATION_PORTRAIT); +} + +static void +ev_window_cmd_edit_flip (GtkAction *action, EvWindow *ev_window) +{ + ev_view_set_orientation (EV_VIEW (ev_window->priv->view), + EV_ORIENTATION_SEASCAPE); +} + static void ev_window_cmd_edit_toolbar (GtkAction *action, EvWindow *ev_window) { @@ -2474,6 +2495,15 @@ static const GtkActionEntry entries[] = { { "EditToolbar", NULL, N_("T_oolbar"), NULL, N_("Customize the toolbar"), G_CALLBACK (ev_window_cmd_edit_toolbar) }, + { "EditLandscape", NULL, N_("_Landscape"), NULL, + N_("Change the document orientation to landscape"), + G_CALLBACK (ev_window_cmd_edit_landscape) }, + { "EditPortrait", NULL, N_("_Portrait"), NULL, + N_("Change the document orientation to portrait"), + G_CALLBACK (ev_window_cmd_edit_portrait) }, + { "EditFlip", NULL, N_("_Flip"), NULL, + N_("Flip the document"), + G_CALLBACK (ev_window_cmd_edit_flip) }, /* View menu */ { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "plus", -- 2.43.5