]> www.fi.muni.cz Git - evince.git/blob - cut-n-paste/zoom-control/ephy-zoom.c
Update FSF address everywhere.
[evince.git] / cut-n-paste / zoom-control / ephy-zoom.c
1 /*
2  *  Copyright (C) 2003 Christian Persch
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2, or (at your option)
7  *  any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  *  $Id$
19  */
20
21 #include "config.h"
22
23 #include "ephy-zoom.h"
24
25 #include <math.h>
26
27 guint
28 ephy_zoom_get_zoom_level_index (float level)
29 {
30         guint i;
31         float previous, current, mean;
32
33         /* Handle our options at the beginning of the list. */
34         if (level == EPHY_ZOOM_BEST_FIT) {
35           return 0;
36         } else if (level == EPHY_ZOOM_FIT_WIDTH) {
37           return 1;
38         }
39
40         previous = zoom_levels[3].level;
41
42         for (i = 4; i < n_zoom_levels; i++)
43         {
44                 current = zoom_levels[i].level;
45                 mean = sqrt (previous * current);
46
47                 if (level <= mean) return i - 1;
48
49                 previous = current;
50         }
51
52         return n_zoom_levels - 1;
53 }
54
55
56 float
57 ephy_zoom_get_changed_zoom_level (float level, gint steps)
58 {
59         guint index;
60
61         index = ephy_zoom_get_zoom_level_index (level);
62         return zoom_levels[CLAMP(index + steps, 3, n_zoom_levels - 1)].level;
63 }
64
65 float   ephy_zoom_get_nearest_zoom_level (float level)
66 {
67         return ephy_zoom_get_changed_zoom_level (level, 0);
68 }