From: Marco Pesenti Gritti Date: Sat, 24 Sep 2005 10:57:13 +0000 (+0000) Subject: Implement FIT_HEIGHT mode (only for links). Implement FITH links X-Git-Tag: EVINCE_0_5_0~135 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=5cc835ba642f057395b3b79d48495a3ab55de6db;p=evince.git Implement FIT_HEIGHT mode (only for links). Implement FITH links 2005-09-24 Marco Pesenti Gritti * backend/ev-link.c: (ev_link_type_get_type), (ev_link_new_page_fith), (ev_link_new_page_fitv): * backend/ev-link.h: * pdf/ev-poppler.cc: * shell/ev-view.c: (goto_fitv_link), (goto_fith_link), (ev_view_goto_link), (ev_view_size_request_continuous_dual_page), (ev_view_size_request_continuous), (ev_view_size_request_dual_page), (ev_view_size_request_single_page), (ev_view_size_allocate), (zoom_for_size_fit_height), (ev_view_zoom_for_size_continuous_and_dual_page), (ev_view_zoom_for_size_continuous), (ev_view_zoom_for_size_dual_page), (ev_view_zoom_for_size_single_page), (ev_view_set_zoom_for_size), (ev_sizing_mode_get_type): * shell/ev-view.h: * shell/ev-window.c: (ev_window_sizing_mode_changed_cb): Implement FIT_HEIGHT mode (only for links). Implement FITH links --- diff --git a/ChangeLog b/ChangeLog index d91b7acb..6666e0b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2005-09-24 Marco Pesenti Gritti + + * backend/ev-link.c: (ev_link_type_get_type), + (ev_link_new_page_fith), (ev_link_new_page_fitv): + * backend/ev-link.h: + * pdf/ev-poppler.cc: + * shell/ev-view.c: (goto_fitv_link), (goto_fith_link), + (ev_view_goto_link), (ev_view_size_request_continuous_dual_page), + (ev_view_size_request_continuous), + (ev_view_size_request_dual_page), + (ev_view_size_request_single_page), (ev_view_size_allocate), + (zoom_for_size_fit_height), + (ev_view_zoom_for_size_continuous_and_dual_page), + (ev_view_zoom_for_size_continuous), + (ev_view_zoom_for_size_dual_page), + (ev_view_zoom_for_size_single_page), (ev_view_set_zoom_for_size), + (ev_sizing_mode_get_type): + * shell/ev-view.h: + * shell/ev-window.c: (ev_window_sizing_mode_changed_cb): + + Implement FIT_HEIGHT mode (only for links). + Implement FITH links + 2005-09-24 Marco Pesenti Gritti * shell/ev-window-title.c: (get_filename_from_uri), diff --git a/backend/ev-link.c b/backend/ev-link.c index 071d6af5..82fce8dd 100644 --- a/backend/ev-link.c +++ b/backend/ev-link.c @@ -72,6 +72,7 @@ ev_link_type_get_type (void) { EV_LINK_TYPE_PAGE_XYZ, "EV_LINK_TYPE_PAGE_XYZ", "page-xyz" }, { EV_LINK_TYPE_PAGE_FIT, "EV_LINK_TYPE_PAGE_FIT", "page-fit" }, { EV_LINK_TYPE_PAGE_FITH, "EV_LINK_TYPE_PAGE_FITH", "page-fith" }, + { EV_LINK_TYPE_PAGE_FITV, "EV_LINK_TYPE_PAGE_FITV", "page-fitv" }, { EV_LINK_TYPE_EXTERNAL_URI, "EV_LINK_TYPE_EXTERNAL_URI", "external" }, { 0, NULL, NULL } }; @@ -382,6 +383,19 @@ ev_link_new_page_fith (const char *title, NULL)); } +EvLink * +ev_link_new_page_fitv (const char *title, + int page, + double left) +{ + return EV_LINK (g_object_new (EV_TYPE_LINK, + "title", title, + "page", page, + "type", EV_LINK_TYPE_PAGE_FITV, + "left", left, + NULL)); +} + EvLink * ev_link_new_external (const char *title, const char *uri) { diff --git a/backend/ev-link.h b/backend/ev-link.h index 508e89de..86b3cc2b 100644 --- a/backend/ev-link.h +++ b/backend/ev-link.h @@ -46,6 +46,7 @@ typedef enum EV_LINK_TYPE_PAGE_XYZ, EV_LINK_TYPE_PAGE_FIT, EV_LINK_TYPE_PAGE_FITH, + EV_LINK_TYPE_PAGE_FITV, EV_LINK_TYPE_EXTERNAL_URI, /* We'll probably fill this in more as we support the other types of * links */ @@ -65,6 +66,9 @@ EvLink *ev_link_new_page_xyz (const char *title, EvLink *ev_link_new_page_fith (const char *title, int page, double top); +EvLink *ev_link_new_page_fitv (const char *title, + int page, + double left); EvLink *ev_link_new_page_fit (const char *title, int page); EvLink *ev_link_new_external (const char *title, diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index 9b1fc47d..5e95943e 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -729,7 +729,9 @@ ev_link_from_dest (PopplerAction *action) action->goto_dest.dest->top); break; case POPPLER_DEST_FITV: - unimplemented_dest = "POPPLER_DEST_FITV"; + link = ev_link_new_page_fitv (action->any.title, + action->goto_dest.dest->page_num - 1, + action->goto_dest.dest->left); break; case POPPLER_DEST_FITR: unimplemented_dest = "POPPLER_DEST_FITR"; diff --git a/shell/ev-view.c b/shell/ev-view.c index 612ffc5c..c7125d9e 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -1095,6 +1095,24 @@ get_link_at_location (EvView *view, return NULL; } +static void +goto_fitv_link (EvView *view, EvLink *link) +{ + GdkPoint view_point; + EvPoint doc_point; + int page; + + page = ev_link_get_page (link); + + ev_view_set_sizing_mode (view, EV_SIZING_FIT_HEIGHT); + + doc_point.x = ev_link_get_left (link); + doc_point.y = 0; + doc_point_to_view_point (view, page, &doc_point, &view_point); + + gtk_adjustment_set_value (view->hadjustment, view_point.x); +} + static void goto_fith_link (EvView *view, EvLink *link) { @@ -1105,7 +1123,7 @@ goto_fith_link (EvView *view, EvLink *link) page = ev_link_get_page (link); ev_page_cache_get_size (view->page_cache, page, 0, 1.0, NULL, &height); - ev_view_set_sizing_mode (view, EV_SIZING_BEST_FIT); + ev_view_set_sizing_mode (view, EV_SIZING_FIT_WIDTH); doc_point.x = 0; doc_point.y = height - ev_link_get_top (link); @@ -1163,6 +1181,9 @@ ev_view_goto_link (EvView *view, EvLink *link) case EV_LINK_TYPE_PAGE_FITH: goto_fith_link (view, link); break; + case EV_LINK_TYPE_PAGE_FITV: + goto_fitv_link (view, link); + break; case EV_LINK_TYPE_PAGE_XYZ: goto_xyz_link (view, link); break; @@ -1260,6 +1281,8 @@ ev_view_size_request_continuous_dual_page (EvView *view, if (view->sizing_mode == EV_SIZING_FIT_WIDTH) { requisition->width = 1; + } else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) { + requisition->height = 1; } else if (view->sizing_mode == EV_SIZING_BEST_FIT) { requisition->width = 1; /* FIXME: This could actually be set on one page docs or docs @@ -1287,6 +1310,8 @@ ev_view_size_request_continuous (EvView *view, if (view->sizing_mode == EV_SIZING_FIT_WIDTH) { requisition->width = 1; + } else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) { + requisition->height = 1; } else if (view->sizing_mode == EV_SIZING_BEST_FIT) { requisition->width = 1; /* FIXME: This could actually be set on one page docs or docs @@ -1329,6 +1354,8 @@ ev_view_size_request_dual_page (EvView *view, if (view->sizing_mode == EV_SIZING_FIT_WIDTH) { requisition->width = 1; + } else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) { + requisition->height = 1; } else if (view->sizing_mode == EV_SIZING_BEST_FIT) { requisition->width = 1; requisition->height = 1; @@ -1355,6 +1382,8 @@ ev_view_size_request_single_page (EvView *view, if (view->sizing_mode == EV_SIZING_FIT_WIDTH) { requisition->width = 1; requisition->height = height + border.top + border.bottom + (2 * view->spacing); + } else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) { + requisition->height = 1; } else if (view->sizing_mode == EV_SIZING_BEST_FIT) { requisition->width = 1; requisition->height = 1; @@ -1396,7 +1425,8 @@ ev_view_size_allocate (GtkWidget *widget, EvView *view = EV_VIEW (widget); if (view->sizing_mode == EV_SIZING_FIT_WIDTH || - view->sizing_mode == EV_SIZING_BEST_FIT) { + view->sizing_mode == EV_SIZING_FIT_HEIGHT || + view->sizing_mode == EV_SIZING_BEST_FIT) { g_signal_emit (view, signals[SIGNAL_ZOOM_INVALID], 0); @@ -2704,6 +2734,23 @@ zoom_for_size_fit_width (int doc_width, return scale; } +static double +zoom_for_size_fit_height (int doc_width, + int doc_height, + int target_width, + int target_height, + int vsb_height) +{ + double scale; + + scale = (double)target_height / doc_height; + + if (doc_width * scale > target_width) + scale = (double) (target_height - vsb_height) / doc_height; + + return scale; +} + static double zoom_for_size_best_fit (int doc_width, int doc_height, @@ -2775,6 +2822,8 @@ ev_view_zoom_for_size_continuous_and_dual_page (EvView *view, * now. We need to fix this. */ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) scale = zoom_for_size_fit_width (doc_width, doc_height, width - vsb_width, height, 0); + else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) + scale = zoom_for_size_fit_height (doc_width, doc_height, width - vsb_width, height, hsb_height); else if (view->sizing_mode == EV_SIZING_BEST_FIT) scale = zoom_for_size_best_fit (doc_width, doc_height, width - vsb_width, height, 0, hsb_height); else @@ -2812,6 +2861,8 @@ ev_view_zoom_for_size_continuous (EvView *view, * now. We need to fix this. */ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) scale = zoom_for_size_fit_width (doc_width, doc_height, width - vsb_width, height, 0); + else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) + scale = zoom_for_size_fit_height (doc_width, doc_height, width - vsb_width, height, hsb_height); else if (view->sizing_mode == EV_SIZING_BEST_FIT) scale = zoom_for_size_best_fit (doc_width, doc_height, width - vsb_width, height, 0, hsb_height); else @@ -2861,6 +2912,8 @@ ev_view_zoom_for_size_dual_page (EvView *view, if (view->sizing_mode == EV_SIZING_FIT_WIDTH) scale = zoom_for_size_fit_width (doc_width, doc_height, width, height, vsb_width); + else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) + scale = zoom_for_size_fit_height (doc_width, doc_height, width, height, hsb_height); else if (view->sizing_mode == EV_SIZING_BEST_FIT) scale = zoom_for_size_best_fit (doc_width, doc_height, width, height, vsb_width, hsb_height); else @@ -2894,6 +2947,8 @@ ev_view_zoom_for_size_single_page (EvView *view, if (view->sizing_mode == EV_SIZING_FIT_WIDTH) scale = zoom_for_size_fit_width (doc_width, doc_height, width, height, vsb_width); + else if (view->sizing_mode == EV_SIZING_FIT_HEIGHT) + scale = zoom_for_size_fit_height (doc_width, doc_height, width, height, hsb_height); else if (view->sizing_mode == EV_SIZING_BEST_FIT) scale = zoom_for_size_best_fit (doc_width, doc_height, width, height, vsb_width, hsb_height); else @@ -2910,6 +2965,7 @@ ev_view_set_zoom_for_size (EvView *view, int hsb_height) { g_return_if_fail (view->sizing_mode == EV_SIZING_FIT_WIDTH || + view->sizing_mode == EV_SIZING_FIT_HEIGHT || view->sizing_mode == EV_SIZING_BEST_FIT); g_return_if_fail (width >= 0); g_return_if_fail (height >= 0); @@ -3675,6 +3731,7 @@ ev_sizing_mode_get_type (void) if (etype == 0) { static const GEnumValue values[] = { { EV_SIZING_FIT_WIDTH, "EV_SIZING_FIT_WIDTH", "fit-width" }, + { EV_SIZING_FIT_HEIGHT, "EV_SIZING_FIT_HEIGHT", "fit-height" }, { EV_SIZING_BEST_FIT, "EV_SIZING_BEST_FIT", "best-fit" }, { EV_SIZING_FREE, "EV_SIZING_FREE", "free" }, { 0, NULL, NULL } diff --git a/shell/ev-view.h b/shell/ev-view.h index 77914929..586c6ad0 100644 --- a/shell/ev-view.h +++ b/shell/ev-view.h @@ -41,6 +41,7 @@ typedef struct _EvViewClass EvViewClass; typedef enum { EV_SIZING_BEST_FIT, EV_SIZING_FIT_WIDTH, + EV_SIZING_FIT_HEIGHT, EV_SIZING_FREE, } EvSizingMode; diff --git a/shell/ev-window.c b/shell/ev-window.c index 9acf5056..17baf744 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -311,7 +311,9 @@ update_action_sensitivity (EvWindow *ev_window) set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages); set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages); - if (has_pages && ev_view_get_sizing_mode (view) == EV_SIZING_FREE) { + if (has_pages && + ev_view_get_sizing_mode (view) != EV_SIZING_FIT_WIDTH && + ev_view_get_sizing_mode (view) != EV_SIZING_BEST_FIT) { GtkAction *action; float zoom; float real_zoom; @@ -2343,6 +2345,15 @@ ev_window_sizing_mode_changed_cb (EvView *view, GParamSpec *pspec, G_CALLBACK (update_view_size), ev_window); break; + case EV_SIZING_FIT_HEIGHT: + g_object_set (G_OBJECT (scrolled_window), + "hscrollbar-policy", GTK_POLICY_AUTOMATIC, + "vscrollbar-policy", GTK_POLICY_NEVER, + NULL); + g_signal_connect (ev_window->priv->view, "zoom_invalid", + G_CALLBACK (update_view_size), + ev_window); + break; case EV_SIZING_FREE: g_object_set (G_OBJECT (scrolled_window), "hscrollbar-policy", GTK_POLICY_AUTOMATIC,