From e9ffd7b5401b32979ea83bc56da4592e80f8ce3e Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 16 Jun 2005 16:40:40 +0000 Subject: [PATCH] Add a get_orientation api. Improve set_orientation. 2005-06-16 Marco Pesenti Gritti * backend/ev-document.c: (ev_document_get_orientation): * backend/ev-document.h: * pdf/ev-poppler.cc: * ps/ps-document.c: (ps_document_get_orientation), (ps_document_set_orientation), (ps_document_document_iface_init): Add a get_orientation api. Improve set_orientation. * data/evince-ui.xml: * shell/ev-view.c: (ev_view_set_orientation), (ev_view_rotate_right), (ev_view_rotate_left): * shell/ev-view.h: * shell/ev-window.c: (ev_window_cmd_edit_rotate_left), (ev_window_cmd_edit_rotate_right): Better ui for changing document orientation --- ChangeLog | 19 +++++++++++++++++ backend/ev-document.c | 8 +++++++ backend/ev-document.h | 3 ++- data/evince-ui.xml | 5 ++--- pdf/ev-poppler.cc | 49 ++++++++++++++++++++++++++++++++++++++++--- ps/ps-document.c | 33 ++++++++++++++++++++++++++--- shell/ev-view.c | 38 ++++++++++++++++++++++++++++++++- shell/ev-view.h | 4 ++-- shell/ev-window.c | 32 +++++++++------------------- 9 files changed, 156 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index a53082e9..ab67697c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2005-06-16 Marco Pesenti Gritti + + * backend/ev-document.c: (ev_document_get_orientation): + * backend/ev-document.h: + * pdf/ev-poppler.cc: + * ps/ps-document.c: (ps_document_get_orientation), + (ps_document_set_orientation), (ps_document_document_iface_init): + + Add a get_orientation api. Improve set_orientation. + + * data/evince-ui.xml: + * shell/ev-view.c: (ev_view_set_orientation), + (ev_view_rotate_right), (ev_view_rotate_left): + * shell/ev-view.h: + * shell/ev-window.c: (ev_window_cmd_edit_rotate_left), + (ev_window_cmd_edit_rotate_right): + + Better ui for changing document orientation + 2005-06-16 Nickolay V. Shmyrev * shell/ev-sidebar-links.c: (ev_sidebar_links_get_property), diff --git a/backend/ev-document.c b/backend/ev-document.c index 4513df50..9bccc4ca 100644 --- a/backend/ev-document.c +++ b/backend/ev-document.c @@ -218,6 +218,14 @@ ev_document_render_pixbuf (EvDocument *document, return retval; } +EvOrientation +ev_document_get_orientation (EvDocument *document) +{ + EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); + + return iface->get_orientation (document); +} + void ev_document_set_orientation (EvDocument *document, EvOrientation orientation) diff --git a/backend/ev-document.h b/backend/ev-document.h index 1fd8fe32..044014f3 100644 --- a/backend/ev-document.h +++ b/backend/ev-document.h @@ -57,7 +57,6 @@ typedef enum typedef enum { - EV_ORIENTATION_DOCUMENT, EV_ORIENTATION_PORTRAIT, EV_ORIENTATION_LANDSCAPE, EV_ORIENTATION_UPSIDEDOWN, @@ -98,6 +97,7 @@ struct _EvDocumentIface GdkPixbuf * (* render_pixbuf) (EvDocument *document, int page, double scale); + EvOrientation (* get_orientation) (EvDocument *document); void (* set_orientation) (EvDocument *document, EvOrientation orientation); EvDocumentInfo * (* get_info) (EvDocument *document); @@ -132,6 +132,7 @@ GList *ev_document_get_links (EvDocument *document, GdkPixbuf *ev_document_render_pixbuf (EvDocument *document, int page, double scale); +EvOrientation ev_document_get_orientation (EvDocument *document); void ev_document_set_orientation (EvDocument *document, EvOrientation orientation); diff --git a/data/evince-ui.xml b/data/evince-ui.xml index 1d251ca0..c64df653 100644 --- a/data/evince-ui.xml +++ b/data/evince-ui.xml @@ -20,9 +20,8 @@ - - - + + diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index 1f1e4e50..0f9a3562 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -128,6 +128,7 @@ static void pdf_document_init (PdfDocument *pdf_document) { pdf_document->password = NULL; + pdf_document->orientation = POPPLER_ORIENTATION_PORTRAIT; } static void @@ -175,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, @@ -191,6 +210,8 @@ pdf_document_load (EvDocument *document, return FALSE; } + pdf_document->orientation = get_document_orientation (pdf_document); + return TRUE; } @@ -488,6 +509,30 @@ 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) { @@ -495,9 +540,6 @@ pdf_document_set_orientation (EvDocument *document, EvOrientation orientation) 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; @@ -529,6 +571,7 @@ pdf_document_document_iface_init (EvDocumentIface *iface) 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 diff --git a/ps/ps-document.c b/ps/ps-document.c index 83fa3d9f..642f5c8e 100644 --- a/ps/ps-document.c +++ b/ps/ps-document.c @@ -1241,6 +1241,35 @@ ps_document_get_info (EvDocument *document) return info; } +static EvOrientation +ps_document_get_orientation (EvDocument *document) +{ + EvOrientation orientation; + PSDocument *ps = PS_DOCUMENT (document); + + g_return_val_if_fail (ps != NULL, EV_ORIENTATION_PORTRAIT); + + switch (ps->orientation) { + case GTK_GS_ORIENTATION_PORTRAIT: + orientation = EV_ORIENTATION_PORTRAIT; + break; + case GTK_GS_ORIENTATION_LANDSCAPE: + orientation = EV_ORIENTATION_LANDSCAPE; + break; + case GTK_GS_ORIENTATION_UPSIDEDOWN: + orientation = EV_ORIENTATION_UPSIDEDOWN; + break; + case GTK_GS_ORIENTATION_SEASCAPE: + orientation = EV_ORIENTATION_SEASCAPE; + break; + default: + orientation = EV_ORIENTATION_PORTRAIT; + break; + } + + return orientation; +} + static void ps_document_set_orientation (EvDocument *document, EvOrientation orientation) { @@ -1249,9 +1278,6 @@ ps_document_set_orientation (EvDocument *document, EvOrientation orientation) g_return_if_fail (ps != NULL); switch (orientation) { - case EV_ORIENTATION_DOCUMENT: - ps->orientation = GTK_GS_ORIENTATION_NONE; - break; case EV_ORIENTATION_PORTRAIT: ps->orientation = GTK_GS_ORIENTATION_PORTRAIT; break; @@ -1277,6 +1303,7 @@ ps_document_document_iface_init (EvDocumentIface *iface) iface->get_page_size = ps_document_get_page_size; iface->get_info = ps_document_get_info; iface->set_orientation = ps_document_set_orientation; + iface->get_orientation = ps_document_get_orientation; } static void diff --git a/shell/ev-view.c b/shell/ev-view.c index 6ae9ac61..c366b04c 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -2145,7 +2145,7 @@ ev_view_zoom_out (EvView *view) ev_view_set_zoom (view, ZOOM_OUT_FACTOR, TRUE); } -void +static void ev_view_set_orientation (EvView *view, EvOrientation orientation) { @@ -2157,6 +2157,42 @@ ev_view_set_orientation (EvView *view, gtk_widget_queue_resize (GTK_WIDGET (view)); } +void +ev_view_rotate_right (EvView *view) +{ + EvOrientation orientation, new_orientation; + + orientation = ev_document_get_orientation (view->document); + if (orientation == EV_ORIENTATION_PORTRAIT) { + new_orientation = EV_ORIENTATION_LANDSCAPE; + } else if (orientation == EV_ORIENTATION_LANDSCAPE) { + new_orientation = EV_ORIENTATION_UPSIDEDOWN; + } else if (orientation == EV_ORIENTATION_UPSIDEDOWN) { + new_orientation = EV_ORIENTATION_SEASCAPE; + } else { + new_orientation = EV_ORIENTATION_PORTRAIT; + } + ev_view_set_orientation (view, new_orientation); +} + +void +ev_view_rotate_left (EvView *view) +{ + EvOrientation orientation, new_orientation; + + orientation = ev_document_get_orientation (view->document); + if (orientation == EV_ORIENTATION_PORTRAIT) { + new_orientation = EV_ORIENTATION_SEASCAPE; + } else if (orientation == EV_ORIENTATION_SEASCAPE) { + new_orientation = EV_ORIENTATION_UPSIDEDOWN; + } else if (orientation == EV_ORIENTATION_UPSIDEDOWN) { + new_orientation = EV_ORIENTATION_LANDSCAPE; + } else { + new_orientation = EV_ORIENTATION_PORTRAIT; + } + ev_view_set_orientation (view, new_orientation); +} + 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 2244ae0f..05b25429 100644 --- a/shell/ev-view.h +++ b/shell/ev-view.h @@ -90,8 +90,8 @@ void ev_view_set_zoom_for_size (EvView *view, int height, int vsb_width, int hsb_height); -void ev_view_set_orientation (EvView *view, - EvOrientation orientation); +void ev_view_rotate_left (EvView *view); +void ev_view_rotate_right (EvView *view); /* Find */ gboolean ev_view_can_find_next (EvView *view); diff --git a/shell/ev-window.c b/shell/ev-window.c index e9e1c4e6..2020e9ce 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -1798,24 +1798,15 @@ ev_window_cmd_edit_toolbar_cb (GtkDialog *dialog, gint response, gpointer data) } static void -ev_window_cmd_edit_landscape (GtkAction *action, EvWindow *ev_window) +ev_window_cmd_edit_rotate_left (GtkAction *action, EvWindow *ev_window) { - ev_view_set_orientation (EV_VIEW (ev_window->priv->view), - EV_ORIENTATION_LANDSCAPE); + ev_view_rotate_left (EV_VIEW (ev_window->priv->view)); } static void -ev_window_cmd_edit_portrait (GtkAction *action, EvWindow *ev_window) +ev_window_cmd_edit_rotate_right (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); + ev_view_rotate_right (EV_VIEW (ev_window->priv->view)); } static void @@ -2511,15 +2502,12 @@ 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) }, + { "EditRotateLeft", NULL, N_("Rotate _Left"), NULL, + N_("Rotate the document to the left"), + G_CALLBACK (ev_window_cmd_edit_rotate_left) }, + { "EditRotateRight", NULL, N_("Rotate _Right"), NULL, + N_("Rotate the document to the right"), + G_CALLBACK (ev_window_cmd_edit_rotate_right) }, /* View menu */ { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "plus", -- 2.43.5