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
22double
23_gtk_print_convert_to_mm (double 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 case GTK_UNIT_NONE:
33 default:
34 g_warning ("Unsupported unit");
35 G_GNUC_FALLTHROUGH;
36 case GTK_UNIT_POINTS:
37 return len * (MM_PER_INCH / POINTS_PER_INCH);
38 break;
39 }
40}
41
42double
43_gtk_print_convert_from_mm (double 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 case GTK_UNIT_NONE:
53 default:
54 g_warning ("Unsupported unit");
55 G_GNUC_FALLTHROUGH;
56 case GTK_UNIT_POINTS:
57 return len / (MM_PER_INCH / POINTS_PER_INCH);
58 break;
59 }
60}
61

source code of gtk/gtk/gtkprintutils.c