]> git.sur5r.net Git - glabels/blob - src/units-util.c
Imported Upstream version 3.0.0
[glabels] / src / units-util.c
1 /*
2  *  units-util.c
3  *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22
23 #include "units-util.h"
24
25 #include "debug.h"
26
27
28 /*========================================================*/
29 /* Private macros and constants.                          */
30 /*========================================================*/
31
32
33 /*========================================================*/
34 /* Private types.                                         */
35 /*========================================================*/
36
37
38 /*========================================================*/
39 /* Private globals.                                       */
40 /*========================================================*/
41
42
43 /*========================================================*/
44 /* Private function prototypes.                           */
45 /*========================================================*/
46
47
48 /****************************************************************************/
49 /* Get step size for desired units.                                         */
50 /****************************************************************************/
51 gdouble
52 gl_units_util_get_step_size (lglUnits units)
53 {
54
55         switch (units) {
56         case LGL_UNITS_POINT:
57                 return 0.1;     /* points */
58         case LGL_UNITS_INCH:
59                 return 0.001;   /* inches */
60         case LGL_UNITS_MM:
61                 return 0.1;     /* mm */
62         default:
63                 g_message ("Illegal units");    /* Should not happen */
64                 return 1.0;
65         }
66 }
67
68
69 /****************************************************************************/
70 /* Get precision for desired units.                                         */
71 /****************************************************************************/
72 gint
73 gl_units_util_get_precision (lglUnits units)
74 {
75
76         switch (units) {
77         case LGL_UNITS_POINT:
78                 return 1;       /* points */
79         case LGL_UNITS_INCH:
80                 return 3;       /* inches */
81         case LGL_UNITS_MM:
82                 return 1;       /* mm */
83         default:
84                 g_message ("Illegal units");    /* Should not happen */
85                 return 1.0;
86         }
87 }
88
89
90 /****************************************************************************/
91 /* Get grid size for desired units.                                         */
92 /****************************************************************************/
93 gdouble
94 gl_units_util_get_grid_size (lglUnits units)
95 {
96
97         switch (units) {
98         case LGL_UNITS_POINT:
99                 return 10.0;
100         case LGL_UNITS_INCH:
101                 return 0.125 * lgl_units_get_points_per_unit (units);
102         case LGL_UNITS_MM:
103                 return 5     * lgl_units_get_points_per_unit (units);
104         default:
105                 g_message ("Illegal units");    /* Should not happen */
106                 return 10;
107         }
108 }
109
110
111
112
113 /*
114  * Local Variables:       -- emacs
115  * mode: C                -- emacs
116  * c-basic-offset: 8      -- emacs
117  * tab-width: 8           -- emacs
118  * indent-tabs-mode: nil  -- emacs
119  * End:                   -- emacs
120  */