]> Pileus Git - ~andy/gtk/blob - gtk/gtkprintutils.c
Change FSF Address
[~andy/gtk] / gtk / gtkprintutils.c
1 /* GTK - The GIMP Toolkit
2  * gtkpapersize.c: Paper Size
3  * Copyright (C) 2006, Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "config.h"
20 #include "gtkprintutils.h"
21
22 gdouble
23 _gtk_print_convert_to_mm (gdouble len, 
24                           GtkUnit unit)
25 {
26   switch (unit)
27     {
28     case GTK_UNIT_MM:
29       return len;
30     case GTK_UNIT_INCH:
31       return len * MM_PER_INCH;
32     default:
33     case GTK_UNIT_PIXEL:
34       g_warning ("Unsupported unit");
35       /* Fall through */
36     case GTK_UNIT_POINTS:
37       return len * (MM_PER_INCH / POINTS_PER_INCH);
38       break;
39     }
40 }
41
42 gdouble
43 _gtk_print_convert_from_mm (gdouble len, 
44                             GtkUnit unit)
45 {
46   switch (unit)
47     {
48     case GTK_UNIT_MM:
49       return len;
50     case GTK_UNIT_INCH:
51       return len / MM_PER_INCH;
52     default:
53     case GTK_UNIT_PIXEL:
54       g_warning ("Unsupported unit");
55       /* Fall through */
56     case GTK_UNIT_POINTS:
57       return len / (MM_PER_INCH / POINTS_PER_INCH);
58       break;
59     }
60 }