Commit 27a4b3e5 authored by William Jon McCann's avatar William Jon McCann

Move setting limits on zoom into the view

This allows the policy to be shared by all users of the view
from the library and makes it adapt correctly to changes in the
pixbuf cache.

https://bugzilla.gnome.org/show_bug.cgi?id=690510
parent ce199f7e
......@@ -66,7 +66,9 @@ enum {
PROP_CONTINUOUS,
PROP_DUAL_PAGE,
PROP_DUAL_PAGE_ODD_LEFT,
PROP_FULLSCREEN
PROP_FULLSCREEN,
PROP_MIN_SCALE,
PROP_MAX_SCALE
};
enum
......@@ -79,6 +81,9 @@ static guint signals[N_SIGNALS] = { 0 };
G_DEFINE_TYPE (EvDocumentModel, ev_document_model, G_TYPE_OBJECT)
#define DEFAULT_MIN_SCALE 0.25
#define DEFAULT_MAX_SCALE 5.0
static void
ev_document_model_finalize (GObject *object)
{
......@@ -116,6 +121,12 @@ ev_document_model_set_property (GObject *object,
case PROP_SCALE:
ev_document_model_set_scale (model, g_value_get_double (value));
break;
case PROP_MIN_SCALE:
ev_document_model_set_min_scale (model, g_value_get_double (value));
break;
case PROP_MAX_SCALE:
ev_document_model_set_max_scale (model, g_value_get_double (value));
break;
case PROP_SIZING_MODE:
ev_document_model_set_sizing_mode (model, g_value_get_enum (value));
break;
......@@ -160,6 +171,12 @@ ev_document_model_get_property (GObject *object,
case PROP_SCALE:
g_value_set_double (value, model->scale);
break;
case PROP_MIN_SCALE:
g_value_set_double (value, model->min_scale);
break;
case PROP_MAX_SCALE:
g_value_set_double (value, model->max_scale);
break;
case PROP_SIZING_MODE:
g_value_set_enum (value, model->sizing_mode);
break;
......@@ -230,6 +247,22 @@ ev_document_model_class_init (EvDocumentModelClass *klass)
0., G_MAXDOUBLE, 1.,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (g_object_class,
PROP_SCALE,
g_param_spec_double ("min-scale",
"Minimum Scale",
"Minium scale factor",
0., G_MAXDOUBLE, DEFAULT_MIN_SCALE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (g_object_class,
PROP_SCALE,
g_param_spec_double ("max-scale",
"Maximum Scale",
"Maximum scale factor",
0., G_MAXDOUBLE, DEFAULT_MAX_SCALE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (g_object_class,
PROP_SIZING_MODE,
g_param_spec_enum ("sizing-mode",
......@@ -292,8 +325,8 @@ ev_document_model_init (EvDocumentModel *model)
model->sizing_mode = EV_SIZING_FIT_WIDTH;
model->continuous = TRUE;
model->inverted_colors = FALSE;
model->min_scale = 0.;
model->max_scale = G_MAXDOUBLE;
model->min_scale = DEFAULT_MIN_SCALE;
model->max_scale = DEFAULT_MAX_SCALE;
}
EvDocumentModel *
......@@ -427,6 +460,8 @@ ev_document_model_set_max_scale (EvDocumentModel *model,
if (model->scale > max_scale)
ev_document_model_set_scale (model, max_scale);
g_object_notify (G_OBJECT (model), "max-scale");
}
gdouble
......@@ -450,6 +485,8 @@ ev_document_model_set_min_scale (EvDocumentModel *model,
if (model->scale < min_scale)
ev_document_model_set_scale (model, min_scale);
g_object_notify (G_OBJECT (model), "min-scale");
}
gdouble
......
......@@ -94,6 +94,7 @@ typedef struct {
EvRectangle doc_rect;
} EvViewChild;
#define MIN_SCALE 0.2
#define ZOOM_IN_FACTOR 1.2
#define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR)
......@@ -4696,6 +4697,50 @@ ev_view_forall (GtkContainer *container,
}
}
static void
view_update_scale_limits (EvView *view)
{
gdouble min_width, min_height;
gdouble width, height;
gdouble max_scale;
gdouble dpi;
gint rotation;
GdkScreen *screen;
if (!view->model)
return;
rotation = ev_document_model_get_rotation (view->model);
screen = gtk_widget_get_screen (GTK_WIDGET (view));
dpi = ev_document_misc_get_screen_dpi (screen) / 72.0;
ev_document_get_min_page_size (view->document, &min_width, &min_height);
width = (rotation == 0 || rotation == 180) ? min_width : min_height;
height = (rotation == 0 || rotation == 180) ? min_height : min_width;
max_scale = sqrt (view->pixbuf_cache_size / (width * dpi * 4 * height * dpi));
ev_document_model_set_min_scale (view->model, MIN_SCALE * dpi);
ev_document_model_set_max_scale (view->model, max_scale * dpi);
}
static void
ev_view_screen_changed (GtkWidget *widget,
GdkScreen *old_screen)
{
EvView *view = EV_VIEW (widget);
GdkScreen *screen;
screen = gtk_widget_get_screen (widget);
if (screen == old_screen)
return;
view_update_scale_limits (view);
if (GTK_WIDGET_CLASS (ev_view_parent_class)->screen_changed) {
GTK_WIDGET_CLASS (ev_view_parent_class)->screen_changed (widget, old_screen);
}
}
static void
ev_view_class_init (EvViewClass *class)
{
......@@ -4729,6 +4774,7 @@ ev_view_class_init (EvViewClass *class)
widget_class->drag_motion = ev_view_drag_motion;
widget_class->popup_menu = ev_view_popup_menu;
widget_class->query_tooltip = ev_view_query_tooltip;
widget_class->screen_changed = ev_view_screen_changed;
container_class->remove = ev_view_remove;
container_class->forall = ev_view_forall;
......@@ -5056,6 +5102,8 @@ ev_view_set_page_cache_size (EvView *view,
view->pixbuf_cache_size = cache_size;
if (view->pixbuf_cache)
ev_pixbuf_cache_set_max_size (view->pixbuf_cache, cache_size);
view_update_scale_limits (view);
}
void
......@@ -5183,6 +5231,8 @@ ev_view_document_changed_cb (EvDocumentModel *model,
view->pending_scroll = SCROLL_TO_KEEP_POSITION;
gtk_widget_queue_resize (GTK_WIDGET (view));
}
view_update_scale_limits (view);
}
}
......@@ -5203,6 +5253,7 @@ ev_view_rotation_changed_cb (EvDocumentModel *model,
}
ev_view_remove_all (view);
view_update_scale_limits (view);
if (rotation != 0)
clear_selection (view);
......
......@@ -271,9 +271,6 @@ struct _EvWindowPrivate {
#define EV_TOOLBARS_FILENAME "evince-toolbar.xml"
#define MIN_SCALE 0.05409
#define PAGE_CACHE_SIZE 52428800 /* 50MB */
#define MAX_RECENT_ITEM_LEN (40)
#define TOOLBAR_RESOURCE_PATH "/org/gnome/evince/shell/ui/toolbar.xml"
......@@ -362,7 +359,6 @@ static void ev_window_load_file_remote (EvWindow *ev_wi
static void ev_window_media_player_key_pressed (EvWindow *window,
const gchar *key,
gpointer user_data);
static void ev_window_update_max_min_scale (EvWindow *window);
#ifdef ENABLE_DBUS
static void ev_window_emit_closed (EvWindow *window);
static void ev_window_emit_doc_loaded (EvWindow *window);
......@@ -1566,8 +1562,6 @@ ev_window_set_document (EvWindow *ev_window, EvDocument *document)
g_object_unref (ev_window->priv->document);
ev_window->priv->document = g_object_ref (document);
ev_window_update_max_min_scale (ev_window);
ev_window_set_message_area (ev_window, NULL);
if (ev_document_get_n_pages (document) <= 0) {
......@@ -4331,34 +4325,6 @@ ev_window_setup_gtk_settings (EvWindow *window)
g_free (menubar_accel_accel);
}
static void
ev_window_update_max_min_scale (EvWindow *window)
{
gdouble dpi;
GtkAction *action;
gdouble min_width, min_height;
gdouble width, height;
gdouble max_scale;
gint rotation = ev_document_model_get_rotation (window->priv->model);
if (!window->priv->document)
return;
dpi = get_screen_dpi (window) / 72.0;
ev_document_get_min_page_size (window->priv->document, &min_width, &min_height);
width = (rotation == 0 || rotation == 180) ? min_width : min_height;
height = (rotation == 0 || rotation == 180) ? min_height : min_width;
max_scale = sqrt (PAGE_CACHE_SIZE / (width * dpi * 4 * height * dpi));
action = gtk_action_group_get_action (window->priv->action_group,
ZOOM_CONTROL_ACTION);
ephy_zoom_action_set_max_zoom_level (EPHY_ZOOM_ACTION (action), max_scale);
ev_document_model_set_min_scale (window->priv->model, MIN_SCALE * dpi);
ev_document_model_set_max_scale (window->priv->model, max_scale * dpi);
}
static void
ev_window_screen_changed (GtkWidget *widget,
GdkScreen *old_screen)
......@@ -4371,7 +4337,6 @@ ev_window_screen_changed (GtkWidget *widget,
return;
ev_window_setup_gtk_settings (window);
ev_window_update_max_min_scale (window);
if (GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed) {
GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed (widget, old_screen);
......@@ -4873,6 +4838,18 @@ ev_window_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow *
}
}
static void
ev_window_max_zoom_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvWindow *window)
{
GtkAction *action;
gdouble max_scale;
max_scale = ev_document_model_get_max_scale (model);
action = gtk_action_group_get_action (window->priv->action_group,
ZOOM_CONTROL_ACTION);
ephy_zoom_action_set_max_zoom_level (EPHY_ZOOM_ACTION (action), max_scale);
}
static void
ev_window_update_continuous_action (EvWindow *window)
{
......@@ -4910,7 +4887,6 @@ ev_window_rotation_changed_cb (EvDocumentModel *model,
ev_metadata_set_int (window->priv->metadata, "rotation",
rotation);
ev_window_update_max_min_scale (window);
ev_window_refresh_window_thumbnail (window);
}
......@@ -7478,7 +7454,6 @@ ev_window_init (EvWindow *ev_window)
gtk_widget_show (ev_window->priv->view_box);
ev_window->priv->view = ev_view_new ();
ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view), PAGE_CACHE_SIZE);
ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model);
ev_window->priv->password_view = ev_password_view_new (GTK_WINDOW (ev_window));
......@@ -7547,6 +7522,10 @@ ev_window_init (EvWindow *ev_window)
"notify::scale",
G_CALLBACK (ev_window_zoom_changed_cb),
ev_window);
g_signal_connect (ev_window->priv->model,
"notify::max-scale",
G_CALLBACK (ev_window_max_zoom_changed_cb),
ev_window);
g_signal_connect (ev_window->priv->model,
"notify::sizing-mode",
G_CALLBACK (ev_window_sizing_mode_changed_cb),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment