7
* Ported from libgnomeprint
10
* Dirk Luetjens <dirk@luedi.oche.de>
11
* Yves Arrouye <Yves.Arrouye@marin.fdn.fr>
12
* Lauris Kaplinski <lauris@ximian.com>
14
* Copyright 1999-2001 Ximian, Inc. and authors
18
#include <glib/gmessages.h>
19
#include <glib/gslist.h>
20
#include <glib/gtypes.h>
21
#include "sp-metric.h"
25
* Units and conversion methods used by libgnomeprint.
27
* You need those for certain config keys (like paper size), if you are
28
* interested in using these (look at gnome-print-config.h for discussion,
29
* why you may NOT be interested in paper size).
31
* Unit bases define set of mutually unrelated measuring systems (numbers,
32
* paper, screen and dimesionless user coordinates). Still, you can convert
33
* between those, specifying scaling factors explicitly.
35
* Paper (i.e. output) coordinates are taken as absolute real world units.
36
* It has some justification, because screen unit (pixel) size changes,
37
* if you change screen resolution, while you cannot change output on paper
38
* as easily (unless you have thermally contracting paper, of course).
46
* The base linear ("absolute") unit is 1/72th of an inch, i.e. the base unit of postscript.
53
SP_UNIT_DIMENSIONLESS = (1 << 0), /* For percentages and like */
54
SP_UNIT_ABSOLUTE = (1 << 1), /* Real world distances - i.e. mm, cm... */
55
SP_UNIT_DEVICE = (1 << 2), /* Pixels in the SVG/CSS sense. */
56
SP_UNIT_VOLATILE = (1 << 3) /* em and ex */
60
* Units: indexes into sp_units.
63
SP_UNIT_SCALE, // 1.0 == 100%
64
SP_UNIT_PT, // Postscript points: exactly 72 per inch
65
SP_UNIT_PX, // "Pixels" in the CSS sense; though Inkscape assumes a constant 90 per inch.
66
SP_UNIT_PERCENT, /* Note: In Inkscape this often means "relative to current value" (for
67
users to edit a value), rather than the SVG/CSS use of percentages. */
68
SP_UNIT_MM, // millimetres
69
SP_UNIT_CM, // centimetres
72
SP_UNIT_EM, // font-size of relevant font
73
SP_UNIT_EX, // x-height of relevant font
74
sp_max_unit_id = SP_UNIT_EX // For bounds-checking in sp_unit_get_by_id.
78
* Notice, that for correct menus etc. you have to use
79
* ngettext method family yourself. For that reason we
80
* do not provide translations in unit names.
81
* I also do not know, whether to allow user-created units,
82
* because this would certainly confuse textdomain.
86
SPUnitId unit_id; /* used as sanity check */
88
gdouble unittobase; /* how many base units in this unit */
89
SPMetric metric; // the corresponding SPMetric from sp-metrics.h
90
guint svg_unit; // the corresponding SVGLengthUnit
92
/* When using, you must call "gettext" on them so they're translated */
96
gchar const *abbr_plural;
99
const SPUnit *sp_unit_get_by_abbreviation (const gchar *abbreviation);
100
/* When using, you must call "gettext" on them so they're translated */
101
const gchar *sp_unit_get_abbreviation (const SPUnit *unit);
102
gchar const *sp_unit_get_plural (SPUnit const *unit);
104
SPMetric sp_unit_get_metric(SPUnit const *unit);
105
guint sp_unit_get_svg_unit(SPUnit const *unit);
107
extern SPUnit const sp_units[];
109
inline SPUnit const &
110
sp_unit_get_by_id(SPUnitId const id)
112
/* inline because the compiler should optimize away the g_return_val_if_fail test in the
113
usual case that the argument value is known at compile-time, leaving just
114
"return sp_units[constant]". */
115
unsigned const ix = unsigned(id);
116
g_return_val_if_fail(ix <= sp_max_unit_id, sp_units[SP_UNIT_PX]);
120
#define SP_PS_UNIT (&sp_unit_get_by_id(SP_UNIT_PT))
123
/** Used solely by units-test.cpp. */
124
bool sp_units_table_sane();
126
#define SP_UNITS_ALL (SP_UNIT_DIMENSIONLESS | SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE | SP_UNIT_VOLATILE)
128
GSList *sp_unit_get_list (guint bases);
129
void sp_unit_free_list (GSList *units);
131
/* These are pure utility */
132
/* Return TRUE if conversion is possible, FALSE if unit bases differ */
133
gboolean sp_convert_distance (gdouble *distance, const SPUnit *from, const SPUnit *to);
135
/* If either one is NULL, transconverting to/from that base fails */
136
/* Generic conversion between volatile units would be useless anyways */
137
gdouble sp_convert_distance_full(gdouble const from_dist, SPUnit const &from, SPUnit const &to);
139
/* Some more convenience */
140
gdouble sp_units_get_pixels(gdouble const units, SPUnit const &unit);
141
gdouble sp_pixels_get_units(gdouble const pixels, SPUnit const &unit);
143
double angle_to_compass(double angle);
144
double angle_from_compass(double angle);