File: units.c

package info (click to toggle)
dia 0.98%2Bgit20250126-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 52,072 kB
  • sloc: ansic: 155,381; xml: 14,056; python: 6,250; cpp: 3,598; sh: 439; perl: 137; makefile: 25
file content (166 lines) | stat: -rw-r--r-- 3,547 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* Dia -- an diagram creation/manipulation program
 * Copyright (C) 1998 Alexander Larsson
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * Copyright © 2020 Zander Brown <zbrown@gnome.org>
 */

#include "config.h"
#include "units.h"

#include <glib/gi18n-lib.h>


/**
 * dia_unit_get_name:
 * @self: the #DiaUnit
 *
 * Get the human readable localised name for @self
 *
 * Since: 0.98
 */
const char *
dia_unit_get_name (DiaUnit self)
{
  switch (self) {
    case DIA_UNIT_CENTIMETER:
      return _("Centimeter");
    case DIA_UNIT_DECIMETER:
      return _("Decimeter");
    case DIA_UNIT_FEET:
      return _("Feet");
    case DIA_UNIT_INCH:
      return _("Inch");
    case DIA_UNIT_METER:
      return _("Meter");
    case DIA_UNIT_MILLIMETER:
      return _("Millimeter");
    case DIA_UNIT_POINT:
      return _("Point");
    case DIA_UNIT_PICA:
      return _("Pica");
    case DIA_LAST_UNIT:
    default:
      g_return_val_if_reached (NULL);
  }
}


/**
 * dia_unit_get_symbol:
 * @self: the #DiaUnit
 *
 * Get the symbol for @self, e.g. cm
 *
 * Since: 0.98
 */
const char *
dia_unit_get_symbol (DiaUnit self)
{
  switch (self) {
    case DIA_UNIT_CENTIMETER:
      return "cm";
    case DIA_UNIT_DECIMETER:
      return "dm";
    case DIA_UNIT_FEET:
      return "ft";
    case DIA_UNIT_INCH:
      return "in";
    case DIA_UNIT_METER:
      return "m";
    case DIA_UNIT_MILLIMETER:
      return "mm";
    case DIA_UNIT_POINT:
      return "pt";
    case DIA_UNIT_PICA:
      return "pi";
    case DIA_LAST_UNIT:
    default:
      g_return_val_if_reached (NULL);
  }
}


/**
 * dia_unit_get_factor:
 * @self: the #DiaUnit
 *
 * The number of %DIA_UNIT_POINT per @self
 *
 * Since: 0.98
 */
double
dia_unit_get_factor (DiaUnit self)
{
  switch (self) {
    case DIA_UNIT_CENTIMETER:
      return 28.346457;
    case DIA_UNIT_DECIMETER:
      return 283.46457;
    case DIA_UNIT_FEET:
      return 864;
    case DIA_UNIT_INCH:
      return 72;
    case DIA_UNIT_METER:
      return 2834.6457;
    case DIA_UNIT_MILLIMETER:
      return 2.8346457;
    case DIA_UNIT_POINT:
      return 1;
    case DIA_UNIT_PICA:
      return 12;
    case DIA_LAST_UNIT:
    default:
      g_return_val_if_reached (-1);
  }
}


/**
 * dia_unit_get_digits:
 * @self: the #DiaUnit
 *
 * Number of digits after the decimal separator
 *
 * Since: 0.98
 */
int
dia_unit_get_digits (DiaUnit self)
{
  switch (self) {
    case DIA_UNIT_CENTIMETER:
      return 2;
    case DIA_UNIT_DECIMETER:
      return 3;
    case DIA_UNIT_FEET:
      return 4;
    case DIA_UNIT_INCH:
      return 3;
    case DIA_UNIT_METER:
      return 4;
    case DIA_UNIT_MILLIMETER:
      return 2;
    case DIA_UNIT_POINT:
      return 2;
    case DIA_UNIT_PICA:
      return 2;
    case DIA_LAST_UNIT:
    default:
      g_return_val_if_reached (-1);
  }
}