From: Mark McLoughlin Date: Wed, 22 Dec 2004 12:31:53 +0000 (+0000) Subject: add zooming. X-Git-Tag: EVINCE_0_1_0~90 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=7f32f6e5c1cd8f8868f6b0a26dde7259e79e5411;p=evince.git add zooming. 2004-12-22 Mark McLoughlin * shell/ev-view.[ch]: (ev_view_zoom), (ev_view_zoom_in), (ev_view_zoom_out), (ev_view_normal_size), (ev_view_best_fit), (ev_view_fit_width): add zooming. * shell/ev-window.c: (ev_window_cmd_view_zoom_in), (ev_window_cmd_view_zoom_out), (ev_window_cmd_view_normal_size), (ev_window_cmd_view_best_fit), (ev_window_cmd_view_page_width): hook it up. * pdf/xpdf/pdf-document.cc: (pdf_document_begin_find), (pdf_document_end_find): make static. --- diff --git a/ChangeLog b/ChangeLog index 3f9b7d8a..0c205247 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2004-12-22 Mark McLoughlin + + * shell/ev-view.[ch]: + (ev_view_zoom), (ev_view_zoom_in), (ev_view_zoom_out), + (ev_view_normal_size), (ev_view_best_fit), (ev_view_fit_width): + add zooming. + + * shell/ev-window.c: (ev_window_cmd_view_zoom_in), + (ev_window_cmd_view_zoom_out), (ev_window_cmd_view_normal_size), + (ev_window_cmd_view_best_fit), (ev_window_cmd_view_page_width): + hook it up. + + * pdf/xpdf/pdf-document.cc: + (pdf_document_begin_find), + (pdf_document_end_find): make static. + 2004-12-22 Martin Kretzschmar * pdf/xpdf/GlobalParams.h (setupBaseFontsFc): add prototype. diff --git a/pdf/xpdf/pdf-document.cc b/pdf/xpdf/pdf-document.cc index fa7c7fcf..9deda49e 100644 --- a/pdf/xpdf/pdf-document.cc +++ b/pdf/xpdf/pdf-document.cc @@ -272,7 +272,7 @@ pdf_document_render (EvDocument *document, draw.width, draw.height); } -void +static void pdf_document_begin_find (EvDocument *document, const char *search_string, gboolean case_sensitive) @@ -340,7 +340,7 @@ pdf_document_begin_find (EvDocument *document, g_array_free (results, TRUE); } -void +static void pdf_document_end_find (EvDocument *document) { PdfDocument *pdf_document = PDF_DOCUMENT (document); diff --git a/shell/ev-view.c b/shell/ev-view.c index a928ed30..78a75d99 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -41,6 +41,8 @@ struct _EvView { GtkAdjustment *vadjustment; GArray *find_results; + + double scale; }; struct _EvViewClass { @@ -457,6 +459,8 @@ static void ev_view_init (EvView *view) { static const GdkColor white = { 0, 0xffff, 0xffff, 0xffff }; + + view->scale = 1.0; gtk_widget_modify_bg (GTK_WIDGET (view), GTK_STATE_NORMAL, &white); @@ -552,3 +556,84 @@ ev_view_get_page (EvView *view) else return 1; } + +#define ZOOM_IN_FACTOR 1.2 +#define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR) + +#define MIN_SCALE 0.05409 +#define MAX_SCALE 18.4884 + +static void +ev_view_zoom (EvView *view, + double factor, + gboolean relative) +{ + double scale; + + if (relative) + scale = view->scale * factor; + else + scale = factor; + + view->scale = CLAMP (scale, MIN_SCALE, MAX_SCALE); + + ev_document_set_scale (view->document, view->scale); + + gtk_widget_queue_draw (GTK_WIDGET (view)); +} + +void +ev_view_zoom_in (EvView *view) +{ + ev_view_zoom (view, ZOOM_IN_FACTOR, TRUE); +} + +void +ev_view_zoom_out (EvView *view) +{ + ev_view_zoom (view, ZOOM_OUT_FACTOR, TRUE); +} + +void +ev_view_normal_size (EvView *view) +{ + ev_view_zoom (view, 1.0, FALSE); +} + +void +ev_view_best_fit (EvView *view) +{ + double scale; + int width, height; + + width = height = 0; + ev_document_get_page_size (view->document, &width, &height); + + scale = 1.0; + if (width != 0 && height != 0) { + double scale_w, scale_h; + + scale_w = (double)GTK_WIDGET (view)->allocation.width / width; + scale_h = (double)GTK_WIDGET (view)->allocation.height / height; + + scale = (scale_w < scale_h) ? scale_w : scale_h; + } + + ev_view_zoom (view, scale, FALSE); +} + +void +ev_view_fit_width (EvView *view) +{ + double scale = 1.0; + int width; + + width = 0; + ev_document_get_page_size (view->document, &width, NULL); + + scale = 1.0; + if (width != 0) + scale = (double)GTK_WIDGET (view)->allocation.width / width; + + ev_view_zoom (view, scale, FALSE); +} diff --git a/shell/ev-view.h b/shell/ev-view.h index 5173461c..f175b16f 100644 --- a/shell/ev-view.h +++ b/shell/ev-view.h @@ -43,6 +43,12 @@ void ev_view_set_page (EvView *view, int page); int ev_view_get_page (EvView *view); +void ev_view_zoom_in (EvView *view); +void ev_view_zoom_out (EvView *view); +void ev_view_normal_size (EvView *view); +void ev_view_best_fit (EvView *view); +void ev_view_fit_width (EvView *view); + G_END_DECLS #endif /* __EV_VIEW_H__ */ diff --git a/shell/ev-window.c b/shell/ev-window.c index 64f01632..a1521fca 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -291,7 +291,7 @@ ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); - /* FIXME */ + ev_view_zoom_in (EV_VIEW (ev_window->priv->view)); } static void @@ -299,7 +299,7 @@ ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); - /* FIXME */ + ev_view_zoom_out (EV_VIEW (ev_window->priv->view)); } static void @@ -307,7 +307,7 @@ ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); - /* FIXME */ + ev_view_normal_size (EV_VIEW (ev_window->priv->view)); } static void @@ -315,7 +315,7 @@ ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); - /* FIXME */ + ev_view_best_fit (EV_VIEW (ev_window->priv->view)); } static void @@ -323,7 +323,7 @@ ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); - /* FIXME */ + ev_view_fit_width (EV_VIEW (ev_window->priv->view)); } static void