Merge lp:~matthewpetroff/inkscape/gsoc-2013-unit-refactor into lp:~inkscape.dev/inkscape/trunk
- gsoc-2013-unit-refactor
- Merge into trunk
Proposed by
Matthew Petroff
Status: | Merged |
---|---|
Merged at revision: | 12471 |
Proposed branch: | lp:~matthewpetroff/inkscape/gsoc-2013-unit-refactor |
Merge into: | lp:~inkscape.dev/inkscape/trunk |
Diff against target: |
7879 lines (+1412/-2557) (has conflicts) 123 files modified
AUTHORS (+1/-0) src/CMakeLists.txt (+0/-4) src/Makefile_insert (+0/-3) src/arc-context.cpp (+4/-3) src/box3d-context.cpp (+0/-1) src/desktop-events.cpp (+0/-3) src/desktop.cpp (+0/-1) src/display/canvas-axonomgrid.cpp (+24/-77) src/display/canvas-grid.cpp (+38/-91) src/display/canvas-grid.h (+5/-1) src/document.cpp (+23/-22) src/document.h (+5/-5) src/doxygen-main.cpp (+1/-3) src/extension/internal/cairo-render-context.cpp (+2/-3) src/extension/internal/cairo-renderer-pdf-out.cpp (+2/-2) src/extension/internal/cairo-renderer.cpp (+9/-9) src/extension/internal/emf-win32-inout.cpp (+7/-7) src/extension/internal/emf-win32-print.cpp (+36/-37) src/extension/internal/gdkpixbuf-input.cpp (+2/-2) src/extension/internal/latex-pstricks.cpp (+3/-3) src/extension/internal/latex-text-renderer.cpp (+2/-2) src/extension/internal/pdfinput/pdf-parser.cpp (+4/-4) src/extension/internal/pdfinput/svg-builder.cpp (+2/-2) src/flood-context.cpp (+0/-1) src/flood-context.h (+0/-2) src/helper/Makefile_insert (+0/-12) src/helper/pixbuf-ops.cpp (+2/-2) src/helper/unit-menu.cpp (+0/-360) src/helper/unit-menu.h (+0/-60) src/helper/unit-tracker.cpp (+0/-267) src/helper/unit-tracker.h (+0/-75) src/helper/units-test.h (+0/-90) src/helper/units.cpp (+0/-261) src/helper/units.h (+0/-146) src/live_effects/lpe-path_length.cpp (+3/-3) src/live_effects/lpe-ruler.cpp (+4/-4) src/live_effects/parameter/unit.cpp (+13/-11) src/live_effects/parameter/unit.h (+9/-6) src/lpe-tool-context.cpp (+26/-5) src/lpe-tool-context.h (+0/-1) src/main.cpp (+5/-6) src/measure-context.cpp (+12/-9) src/pen-context.cpp (+8/-5) src/preferences.cpp (+2/-2) src/rect-context.cpp (+4/-3) src/selection-chemistry.cpp (+7/-8) src/seltrans.cpp (+8/-5) src/snap-preferences.h (+0/-1) src/sp-guide.cpp (+4/-5) src/sp-metric.h (+0/-28) src/sp-metrics.cpp (+0/-120) src/sp-metrics.h (+0/-20) src/sp-namedview.cpp (+22/-20) src/sp-namedview.h (+9/-8) src/sp-text.cpp (+2/-3) src/spiral-context.cpp (+2/-2) src/star-context.cpp (+2/-2) src/style.cpp (+16/-16) src/svg/svg-length.cpp (+9/-7) src/text-context.cpp (+4/-3) src/text-editing.cpp (+6/-6) src/ui/CMakeLists.txt (+2/-0) src/ui/clipboard.cpp (+4/-4) src/ui/dialog/clonetiler.cpp (+45/-32) src/ui/dialog/clonetiler.h (+18/-2) src/ui/dialog/document-properties.cpp (+1/-2) src/ui/dialog/export.cpp (+28/-49) src/ui/dialog/export.h (+7/-1) src/ui/dialog/guides.cpp (+1/-1) src/ui/dialog/inkscape-preferences.cpp (+4/-4) src/ui/dialog/print.cpp (+6/-6) src/ui/dialog/text-edit.cpp (+2/-2) src/ui/tool/node.cpp (+12/-6) src/ui/widget/Makefile_insert (+3/-1) src/ui/widget/page-sizer.cpp (+80/-89) src/ui/widget/page-sizer.h (+4/-4) src/ui/widget/registered-widget.cpp (+2/-3) src/ui/widget/registered-widget.h (+1/-2) src/ui/widget/rendering-options.cpp (+3/-3) src/ui/widget/scalar-unit.cpp (+4/-3) src/ui/widget/selected-style.cpp (+17/-12) src/ui/widget/selected-style.h (+7/-4) src/ui/widget/style-swatch.cpp (+3/-3) src/ui/widget/style-swatch.h (+6/-2) src/ui/widget/unit-menu.cpp (+9/-7) src/ui/widget/unit-menu.h (+0/-3) src/ui/widget/unit-tracker.cpp (+263/-0) src/ui/widget/unit-tracker.h (+74/-0) src/unit-constants.h (+0/-47) src/util/expression-evaluator.cpp (+2/-2) src/util/units.cpp (+169/-6) src/util/units.h (+62/-5) src/widgets/arc-toolbar.cpp (+2/-6) src/widgets/box3d-toolbar.cpp (+3/-8) src/widgets/calligraphy-toolbar.cpp (+8/-12) src/widgets/connector-toolbar.cpp (+3/-7) src/widgets/desktop-widget.cpp (+15/-13) src/widgets/dropper-toolbar.cpp (+0/-4) src/widgets/eraser-toolbar.cpp (+1/-5) src/widgets/font-selector.cpp (+0/-1) src/widgets/gradient-toolbar.cpp (+1/-1) src/widgets/lpe-toolbar.cpp (+10/-9) src/widgets/measure-toolbar.cpp (+10/-9) src/widgets/mesh-toolbar.cpp (+2/-2) src/widgets/node-toolbar.cpp (+19/-16) src/widgets/paintbucket-toolbar.cpp (+11/-10) src/widgets/pencil-toolbar.cpp (+1/-6) src/widgets/rect-toolbar.cpp (+19/-17) src/widgets/ruler.cpp (+15/-17) src/widgets/ruler.h (+8/-3) src/widgets/select-toolbar.cpp (+29/-27) src/widgets/spiral-toolbar.cpp (+3/-7) src/widgets/spray-toolbar.cpp (+6/-10) src/widgets/spw-utilities.cpp (+0/-46) src/widgets/spw-utilities.h (+0/-5) src/widgets/star-toolbar.cpp (+4/-8) src/widgets/stroke-style.cpp (+35/-90) src/widgets/stroke-style.h (+16/-8) src/widgets/text-toolbar.cpp (+0/-15) src/widgets/toolbox.cpp (+0/-8) src/widgets/toolbox.h (+0/-1) src/widgets/tweak-toolbar.cpp (+3/-7) src/widgets/zoom-toolbar.cpp (+0/-4) Text conflict in src/lpe-tool-context.cpp |
To merge this branch: | bzr merge lp:~matthewpetroff/inkscape/gsoc-2013-unit-refactor |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Inkscape Developers | Pending | ||
Review via email: mp+178151@code.launchpad.net |
Commit message
Description of the change
This branch is a refactor of Inkscape's unit support as phase one of my Google Summer of Code project. Unit support was consolidated into one implementation, residing in "util/units.*", eliminating "SPUnit", "SPMetric", and "unit-constants.h".
To post a comment you must log in.
- 12438. By Matthew Petroff
-
Fixed Windows compile bug.
- 12439. By Matthew Petroff
-
Fix UnitTracker percentage bug.
- 12440. By Matthew Petroff
-
Fixed building of tests.
- 12441. By Matthew Petroff
-
Fix handling of SVG lengths with spaces [Bug #1208002].
- 12442. By Matthew Petroff
-
Switched to global UnitTable.
- 12443. By Matthew Petroff
-
Fixed bug in page sizer.
Revision history for this message
su_v (suv-lp) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'AUTHORS' |
2 | --- AUTHORS 2013-07-18 11:21:06 +0000 |
3 | +++ AUTHORS 2013-08-06 18:46:25 +0000 |
4 | @@ -121,6 +121,7 @@ |
5 | Mitsuru Oka |
6 | Martin Owens |
7 | Alvin Penner |
8 | +Matthew Petroff |
9 | Jon Phillips |
10 | Zdenko Podobny |
11 | Alexandre Prokoudine |
12 | |
13 | === modified file 'src/CMakeLists.txt' |
14 | --- src/CMakeLists.txt 2013-07-23 17:01:25 +0000 |
15 | +++ src/CMakeLists.txt 2013-08-06 18:46:25 +0000 |
16 | @@ -46,7 +46,6 @@ |
17 | sp-mesh-patch.cpp |
18 | sp-mesh-row.cpp |
19 | sp-metadata.cpp |
20 | - sp-metrics.cpp |
21 | sp-missing-glyph.cpp |
22 | sp-namedview.cpp |
23 | sp-object-group.cpp |
24 | @@ -136,8 +135,6 @@ |
25 | sp-mesh-row-fns.h |
26 | sp-mesh-row.h |
27 | sp-metadata.h |
28 | - sp-metric.h |
29 | - sp-metrics.h |
30 | sp-missing-glyph.h |
31 | sp-namedview.h |
32 | sp-object-group.h |
33 | @@ -484,7 +481,6 @@ |
34 | unclump.h |
35 | undo-stack-observer.h |
36 | unicoderange.h |
37 | - unit-constants.h |
38 | uri-references.h |
39 | uri.h |
40 | vanishing-point.h |
41 | |
42 | === modified file 'src/Makefile_insert' |
43 | --- src/Makefile_insert 2013-08-03 15:35:41 +0000 |
44 | +++ src/Makefile_insert 2013-08-06 18:46:25 +0000 |
45 | @@ -198,8 +198,6 @@ |
46 | sp-mesh-patch.cpp sp-mesh-patch.h \ |
47 | sp-mesh-row-fns.h \ |
48 | sp-mesh-row.cpp sp-mesh-row.h \ |
49 | - sp-metric.h \ |
50 | - sp-metrics.cpp sp-metrics.h \ |
51 | sp-missing-glyph.cpp sp-missing-glyph.h \ |
52 | sp-namedview.cpp sp-namedview.h \ |
53 | sp-object.cpp sp-object.h \ |
54 | @@ -252,7 +250,6 @@ |
55 | unclump.cpp unclump.h \ |
56 | undo-stack-observer.h \ |
57 | unicoderange.cpp unicoderange.h \ |
58 | - unit-constants.h \ |
59 | uri.cpp uri.h \ |
60 | uri-references.cpp uri-references.h \ |
61 | vanishing-point.cpp vanishing-point.h \ |
62 | |
63 | === modified file 'src/arc-context.cpp' |
64 | --- src/arc-context.cpp 2013-04-28 22:48:03 +0000 |
65 | +++ src/arc-context.cpp 2013-08-06 18:46:25 +0000 |
66 | @@ -32,7 +32,6 @@ |
67 | #include "desktop-handles.h" |
68 | #include "snap.h" |
69 | #include "pixmaps/cursor-ellipse.xpm" |
70 | -#include "sp-metrics.h" |
71 | #include "xml/repr.h" |
72 | #include "xml/node-event-vector.h" |
73 | #include "preferences.h" |
74 | @@ -450,8 +449,10 @@ |
75 | |
76 | double rdimx = r.dimensions()[Geom::X]; |
77 | double rdimy = r.dimensions()[Geom::Y]; |
78 | - GString *xs = SP_PX_TO_METRIC_STRING(rdimx, desktop->namedview->getDefaultMetric()); |
79 | - GString *ys = SP_PX_TO_METRIC_STRING(rdimy, desktop->namedview->getDefaultMetric()); |
80 | + Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px"); |
81 | + Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px"); |
82 | + GString *xs = g_string_new(rdimx_q.string(*desktop->namedview->doc_units).c_str()); |
83 | + GString *ys = g_string_new(rdimy_q.string(*desktop->namedview->doc_units).c_str()); |
84 | if (state & GDK_CONTROL_MASK) { |
85 | int ratio_x, ratio_y; |
86 | if (fabs (rdimx) > fabs (rdimy)) { |
87 | |
88 | === modified file 'src/box3d-context.cpp' |
89 | --- src/box3d-context.cpp 2013-04-28 22:48:03 +0000 |
90 | +++ src/box3d-context.cpp 2013-08-06 18:46:25 +0000 |
91 | @@ -35,7 +35,6 @@ |
92 | #include "pixmaps/cursor-3dbox.xpm" |
93 | #include "box3d.h" |
94 | #include "box3d-context.h" |
95 | -#include "sp-metrics.h" |
96 | #include <glibmm/i18n.h> |
97 | #include "xml/repr.h" |
98 | #include "xml/node-event-vector.h" |
99 | |
100 | === modified file 'src/desktop-events.cpp' |
101 | --- src/desktop-events.cpp 2013-03-25 17:42:31 +0000 |
102 | +++ src/desktop-events.cpp 2013-08-06 18:46:25 +0000 |
103 | @@ -34,14 +34,11 @@ |
104 | #include "document-undo.h" |
105 | #include "event-context.h" |
106 | #include "helper/action.h" |
107 | -#include "helper/unit-menu.h" |
108 | -#include "helper/units.h" |
109 | #include "message-context.h" |
110 | #include "preferences.h" |
111 | #include "snap.h" |
112 | #include "display/sp-canvas.h" |
113 | #include "sp-guide.h" |
114 | -#include "sp-metrics.h" |
115 | #include "sp-namedview.h" |
116 | #include "tools-switch.h" |
117 | #include "verbs.h" |
118 | |
119 | === modified file 'src/desktop.cpp' |
120 | --- src/desktop.cpp 2013-07-04 14:01:44 +0000 |
121 | +++ src/desktop.cpp 2013-08-06 18:46:25 +0000 |
122 | @@ -54,7 +54,6 @@ |
123 | #include "document.h" |
124 | #include "event-log.h" |
125 | #include "helper/action-context.h" |
126 | -#include "helper/units.h" |
127 | #include "interface.h" |
128 | #include "inkscape-private.h" |
129 | #include "layer-fns.h" |
130 | |
131 | === modified file 'src/display/canvas-axonomgrid.cpp' |
132 | --- src/display/canvas-axonomgrid.cpp 2013-06-06 13:44:11 +0000 |
133 | +++ src/display/canvas-axonomgrid.cpp 2013-08-06 18:46:25 +0000 |
134 | @@ -51,8 +51,9 @@ |
135 | #include "2geom/angle.h" |
136 | #include "util/mathfns.h" |
137 | #include "round.h" |
138 | -#include "helper/units.h" |
139 | +#include "util/units.h" |
140 | |
141 | +using Inkscape::Util::unit_table; |
142 | |
143 | enum Dim3 { X=0, Y, Z }; |
144 | |
145 | @@ -160,15 +161,15 @@ |
146 | : CanvasGrid(nv, in_repr, in_doc, GRID_AXONOMETRIC) |
147 | { |
148 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
149 | - gridunit = sp_unit_get_by_abbreviation( prefs->getString("/options/grids/axonom/units").data() ); |
150 | + gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/axonom/units"))); |
151 | if (!gridunit) |
152 | - gridunit = &sp_unit_get_by_id(SP_UNIT_PX); |
153 | - origin[Geom::X] = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/origin_x", 0.0), *gridunit ); |
154 | - origin[Geom::Y] = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/origin_y", 0.0), *gridunit ); |
155 | + gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px")); |
156 | + origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_x", 0.0), *gridunit, "px"); |
157 | + origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_y", 0.0), *gridunit, "px"); |
158 | color = prefs->getInt("/options/grids/axonom/color", 0x0000ff20); |
159 | empcolor = prefs->getInt("/options/grids/axonom/empcolor", 0x0000ff40); |
160 | empspacing = prefs->getInt("/options/grids/axonom/empspacing", 5); |
161 | - lengthy = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), *gridunit ); |
162 | + lengthy = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), *gridunit, "px"); |
163 | angle_deg[X] = prefs->getDouble("/options/grids/axonom/angle_x", 30.0); |
164 | angle_deg[Z] = prefs->getDouble("/options/grids/axonom/angle_z", 30.0); |
165 | angle_deg[Y] = 0; |
166 | @@ -188,63 +189,6 @@ |
167 | if (snapper) delete snapper; |
168 | } |
169 | |
170 | - |
171 | -/* fixme: Collect all these length parsing methods and think common sane API */ |
172 | - |
173 | -static gboolean sp_nv_read_length(gchar const *str, guint base, gdouble *val, SPUnit const **unit) |
174 | -{ |
175 | - if (!str) { |
176 | - return FALSE; |
177 | - } |
178 | - |
179 | - gchar *u; |
180 | - gdouble v = g_ascii_strtod(str, &u); |
181 | - if (!u) { |
182 | - return FALSE; |
183 | - } |
184 | - while (isspace(*u)) { |
185 | - u += 1; |
186 | - } |
187 | - |
188 | - if (!*u) { |
189 | - /* No unit specified - keep default */ |
190 | - *val = v; |
191 | - return TRUE; |
192 | - } |
193 | - |
194 | - if (base & SP_UNIT_DEVICE) { |
195 | - if (u[0] && u[1] && !isalnum(u[2]) && !strncmp(u, "px", 2)) { |
196 | - *unit = &sp_unit_get_by_id(SP_UNIT_PX); |
197 | - *val = v; |
198 | - return TRUE; |
199 | - } |
200 | - } |
201 | - |
202 | - if (base & SP_UNIT_ABSOLUTE) { |
203 | - if (!strncmp(u, "pt", 2)) { |
204 | - *unit = &sp_unit_get_by_id(SP_UNIT_PT); |
205 | - } else if (!strncmp(u, "mm", 2)) { |
206 | - *unit = &sp_unit_get_by_id(SP_UNIT_MM); |
207 | - } else if (!strncmp(u, "cm", 2)) { |
208 | - *unit = &sp_unit_get_by_id(SP_UNIT_CM); |
209 | - } else if (!strncmp(u, "m", 1)) { |
210 | - *unit = &sp_unit_get_by_id(SP_UNIT_M); |
211 | - } else if (!strncmp(u, "in", 2)) { |
212 | - *unit = &sp_unit_get_by_id(SP_UNIT_IN); |
213 | - } else if (!strncmp(u, "ft", 2)) { |
214 | - *unit = &sp_unit_get_by_id(SP_UNIT_FT); |
215 | - } else if (!strncmp(u, "pc", 2)) { |
216 | - *unit = &sp_unit_get_by_id(SP_UNIT_PC); |
217 | - } else { |
218 | - return FALSE; |
219 | - } |
220 | - *val = v; |
221 | - return TRUE; |
222 | - } |
223 | - |
224 | - return FALSE; |
225 | -} |
226 | - |
227 | static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color) |
228 | { |
229 | if (!str) { |
230 | @@ -270,17 +214,20 @@ |
231 | { |
232 | gchar const *value; |
233 | if ( (value = repr->attribute("originx")) ) { |
234 | - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::X], &gridunit); |
235 | - origin[Geom::X] = sp_units_get_pixels(origin[Geom::X], *(gridunit)); |
236 | + Inkscape::Util::Quantity q = unit_table.getQuantity(value); |
237 | + gridunit = q.unit; |
238 | + origin[Geom::X] = unit_table.getQuantity(value).value("px"); |
239 | } |
240 | if ( (value = repr->attribute("originy")) ) { |
241 | - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::Y], &gridunit); |
242 | - origin[Geom::Y] = sp_units_get_pixels(origin[Geom::Y], *(gridunit)); |
243 | + Inkscape::Util::Quantity q = unit_table.getQuantity(value); |
244 | + gridunit = q.unit; |
245 | + origin[Geom::Y] = unit_table.getQuantity(value).value("px"); |
246 | } |
247 | |
248 | if ( (value = repr->attribute("spacingy")) ) { |
249 | - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &lengthy, &gridunit); |
250 | - lengthy = sp_units_get_pixels(lengthy, *(gridunit)); |
251 | + Inkscape::Util::Quantity q = unit_table.getQuantity(value); |
252 | + gridunit = q.unit; |
253 | + lengthy = q.value("px"); |
254 | if (lengthy < 0.0500) lengthy = 0.0500; |
255 | } |
256 | |
257 | @@ -419,17 +366,17 @@ |
258 | attach_all (*table, widget_array, sizeof(widget_array)); |
259 | |
260 | // set widget values |
261 | - _rumg->setUnit (gridunit); |
262 | + _rumg->setUnit (gridunit->abbr); |
263 | |
264 | gdouble val; |
265 | val = origin[Geom::X]; |
266 | - val = sp_pixels_get_units (val, *(gridunit)); |
267 | + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); |
268 | _rsu_ox->setValue (val); |
269 | val = origin[Geom::Y]; |
270 | - val = sp_pixels_get_units (val, *(gridunit)); |
271 | + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); |
272 | _rsu_oy->setValue (val); |
273 | val = lengthy; |
274 | - double gridy = sp_pixels_get_units (val, *(gridunit)); |
275 | + double gridy = Inkscape::Util::Quantity::convert(val, "px", *gridunit); |
276 | _rsu_sy->setValue (gridy); |
277 | |
278 | _rsu_ax->setValue(angle_deg[X]); |
279 | @@ -458,17 +405,17 @@ |
280 | _rcb_enabled.setActive(snapper->getEnabled()); |
281 | } |
282 | |
283 | - _rumg.setUnit (gridunit); |
284 | + _rumg.setUnit (gridunit->abbr); |
285 | |
286 | gdouble val; |
287 | val = origin[Geom::X]; |
288 | - val = sp_pixels_get_units (val, *(gridunit)); |
289 | + val = Inkscape::Util::Quantity::convert(val, &px, gridunit); |
290 | _rsu_ox.setValue (val); |
291 | val = origin[Geom::Y]; |
292 | - val = sp_pixels_get_units (val, *(gridunit)); |
293 | + val = Inkscape::Util::Quantity::convert(val, &px, gridunit); |
294 | _rsu_oy.setValue (val); |
295 | val = lengthy; |
296 | - double gridy = sp_pixels_get_units (val, *(gridunit)); |
297 | + double gridy = Inkscape::Util::Quantity::convert(val, &px, gridunit); |
298 | _rsu_sy.setValue (gridy); |
299 | |
300 | _rsu_ax.setValue(angle_deg[X]); |
301 | |
302 | === modified file 'src/display/canvas-grid.cpp' |
303 | --- src/display/canvas-grid.cpp 2013-06-06 13:44:11 +0000 |
304 | +++ src/display/canvas-grid.cpp 2013-08-06 18:46:25 +0000 |
305 | @@ -42,7 +42,7 @@ |
306 | #include "display/canvas-grid.h" |
307 | #include "display/sp-canvas-group.h" |
308 | #include "document.h" |
309 | -#include "helper/units.h" |
310 | +#include "util/units.h" |
311 | #include "inkscape.h" |
312 | #include "preferences.h" |
313 | #include "sp-namedview.h" |
314 | @@ -55,6 +55,7 @@ |
315 | #include "display/sp-canvas.h" |
316 | |
317 | using Inkscape::DocumentUndo; |
318 | +using Inkscape::Util::unit_table; |
319 | |
320 | namespace Inkscape { |
321 | |
322 | @@ -398,11 +399,11 @@ |
323 | gdouble val; |
324 | |
325 | val = origin_px[Geom::X]; |
326 | - val = sp_pixels_get_units (val, *gridunit); |
327 | - os_x << val << sp_unit_get_abbreviation(gridunit); |
328 | + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); |
329 | + os_x << val << gridunit->abbr; |
330 | val = origin_px[Geom::Y]; |
331 | - val = sp_pixels_get_units (val, *gridunit); |
332 | - os_y << val << sp_unit_get_abbreviation(gridunit); |
333 | + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); |
334 | + os_y << val << gridunit->abbr; |
335 | repr->setAttribute("originx", os_x.str().c_str()); |
336 | repr->setAttribute("originy", os_y.str().c_str()); |
337 | } |
338 | @@ -488,17 +489,17 @@ |
339 | : CanvasGrid(nv, in_repr, in_doc, GRID_RECTANGULAR) |
340 | { |
341 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
342 | - gridunit = sp_unit_get_by_abbreviation( prefs->getString("/options/grids/xy/units").data() ); |
343 | + gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/xy/units"))); |
344 | if (!gridunit) { |
345 | - gridunit = &sp_unit_get_by_id(SP_UNIT_PX); |
346 | + gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px")); |
347 | } |
348 | - origin[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_x", 0.0), *gridunit); |
349 | - origin[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_y", 0.0), *gridunit); |
350 | + origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_x", 0.0), *gridunit, "px"); |
351 | + origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_y", 0.0), *gridunit, "px"); |
352 | color = prefs->getInt("/options/grids/xy/color", 0x0000ff20); |
353 | empcolor = prefs->getInt("/options/grids/xy/empcolor", 0x0000ff40); |
354 | empspacing = prefs->getInt("/options/grids/xy/empspacing", 5); |
355 | - spacing[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), *gridunit); |
356 | - spacing[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), *gridunit); |
357 | + spacing[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), *gridunit, "px"); |
358 | + spacing[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), *gridunit, "px"); |
359 | render_dotted = prefs->getBool("/options/grids/xy/dotted", false); |
360 | |
361 | snapper = new CanvasXYGridSnapper(this, &namedview->snap_manager, 0); |
362 | @@ -511,64 +512,6 @@ |
363 | if (snapper) delete snapper; |
364 | } |
365 | |
366 | - |
367 | -/* fixme: Collect all these length parsing methods and think common sane API */ |
368 | - |
369 | -static gboolean |
370 | -sp_nv_read_length(gchar const *str, guint base, gdouble *val, SPUnit const **unit) |
371 | -{ |
372 | - if (!str) { |
373 | - return FALSE; |
374 | - } |
375 | - |
376 | - gchar *u; |
377 | - gdouble v = g_ascii_strtod(str, &u); |
378 | - if (!u) { |
379 | - return FALSE; |
380 | - } |
381 | - while (isspace(*u)) { |
382 | - u += 1; |
383 | - } |
384 | - |
385 | - if (!*u) { |
386 | - /* No unit specified - keep default */ |
387 | - *val = v; |
388 | - return TRUE; |
389 | - } |
390 | - |
391 | - if (base & SP_UNIT_DEVICE) { |
392 | - if (u[0] && u[1] && !isalnum(u[2]) && !strncmp(u, "px", 2)) { |
393 | - *unit = &sp_unit_get_by_id(SP_UNIT_PX); |
394 | - *val = v; |
395 | - return TRUE; |
396 | - } |
397 | - } |
398 | - |
399 | - if (base & SP_UNIT_ABSOLUTE) { |
400 | - if (!strncmp(u, "pt", 2)) { |
401 | - *unit = &sp_unit_get_by_id(SP_UNIT_PT); |
402 | - } else if (!strncmp(u, "mm", 2)) { |
403 | - *unit = &sp_unit_get_by_id(SP_UNIT_MM); |
404 | - } else if (!strncmp(u, "cm", 2)) { |
405 | - *unit = &sp_unit_get_by_id(SP_UNIT_CM); |
406 | - } else if (!strncmp(u, "m", 1)) { |
407 | - *unit = &sp_unit_get_by_id(SP_UNIT_M); |
408 | - } else if (!strncmp(u, "in", 2)) { |
409 | - *unit = &sp_unit_get_by_id(SP_UNIT_IN); |
410 | - } else if (!strncmp(u, "ft", 2)) { |
411 | - *unit = &sp_unit_get_by_id(SP_UNIT_FT); |
412 | - } else if (!strncmp(u, "pc", 2)) { |
413 | - *unit = &sp_unit_get_by_id(SP_UNIT_PC); |
414 | - } else { |
415 | - return FALSE; |
416 | - } |
417 | - *val = v; |
418 | - return TRUE; |
419 | - } |
420 | - |
421 | - return FALSE; |
422 | -} |
423 | - |
424 | static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color) |
425 | { |
426 | if (!str) { |
427 | @@ -645,28 +588,32 @@ |
428 | { |
429 | gchar const *value; |
430 | if ( (value = repr->attribute("originx")) ) { |
431 | - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::X], &gridunit); |
432 | - origin[Geom::X] = sp_units_get_pixels(origin[Geom::X], *(gridunit)); |
433 | + Inkscape::Util::Quantity q = unit_table.getQuantity(value); |
434 | + gridunit = q.unit; |
435 | + origin[Geom::X] = unit_table.getQuantity(value).value("px"); |
436 | } |
437 | |
438 | if ( (value = repr->attribute("originy")) ) { |
439 | - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::Y], &gridunit); |
440 | - origin[Geom::Y] = sp_units_get_pixels(origin[Geom::Y], *(gridunit)); |
441 | + Inkscape::Util::Quantity q = unit_table.getQuantity(value); |
442 | + gridunit = q.unit; |
443 | + origin[Geom::Y] = unit_table.getQuantity(value).value("px"); |
444 | } |
445 | |
446 | if ( (value = repr->attribute("spacingx")) ) { |
447 | double oldVal = spacing[Geom::X]; |
448 | - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[Geom::X], &gridunit); |
449 | - validateScalar( oldVal, &spacing[Geom::X]); |
450 | - spacing[Geom::X] = sp_units_get_pixels(spacing[Geom::X], *(gridunit)); |
451 | - |
452 | + Inkscape::Util::Quantity q = unit_table.getQuantity(value); |
453 | + gridunit = q.unit; |
454 | + spacing[Geom::X] = q.quantity; |
455 | + validateScalar(oldVal, &spacing[Geom::X]); |
456 | + spacing[Geom::X] = Inkscape::Util::Quantity::convert(spacing[Geom::X], *gridunit, "px"); |
457 | } |
458 | if ( (value = repr->attribute("spacingy")) ) { |
459 | double oldVal = spacing[Geom::Y]; |
460 | - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[Geom::Y], &gridunit); |
461 | - validateScalar( oldVal, &spacing[Geom::Y]); |
462 | - spacing[Geom::Y] = sp_units_get_pixels(spacing[Geom::Y], *(gridunit)); |
463 | - |
464 | + Inkscape::Util::Quantity q = unit_table.getQuantity(value); |
465 | + gridunit = q.unit; |
466 | + spacing[Geom::Y] = q.quantity; |
467 | + validateScalar(oldVal, &spacing[Geom::Y]); |
468 | + spacing[Geom::Y] = Inkscape::Util::Quantity::convert(spacing[Geom::Y], *gridunit, "px"); |
469 | } |
470 | |
471 | if ( (value = repr->attribute("color")) ) { |
472 | @@ -802,20 +749,20 @@ |
473 | attach_all (*table, widget_array, sizeof(widget_array)); |
474 | |
475 | // set widget values |
476 | - _rumg->setUnit (gridunit); |
477 | + _rumg->setUnit (gridunit->abbr); |
478 | |
479 | gdouble val; |
480 | val = origin[Geom::X]; |
481 | - val = sp_pixels_get_units (val, *(gridunit)); |
482 | + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); |
483 | _rsu_ox->setValue (val); |
484 | val = origin[Geom::Y]; |
485 | - val = sp_pixels_get_units (val, *(gridunit)); |
486 | + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); |
487 | _rsu_oy->setValue (val); |
488 | val = spacing[Geom::X]; |
489 | - double gridx = sp_pixels_get_units (val, *(gridunit)); |
490 | + double gridx = Inkscape::Util::Quantity::convert(val, "px", *gridunit); |
491 | _rsu_sx->setValue (gridx); |
492 | val = spacing[Geom::Y]; |
493 | - double gridy = sp_pixels_get_units (val, *(gridunit)); |
494 | + double gridy = Inkscape::Util::Quantity::convert(val, "px", *gridunit); |
495 | _rsu_sy->setValue (gridy); |
496 | |
497 | _rcp_gcol->setRgba32 (color); |
498 | @@ -851,20 +798,20 @@ |
499 | _rcb_enabled.setActive(snapper->getEnabled()); |
500 | } |
501 | |
502 | - _rumg.setUnit (gridunit); |
503 | + _rumg.setUnit (gridunit->abbr); |
504 | |
505 | gdouble val; |
506 | val = origin[Geom::X]; |
507 | - val = sp_pixels_get_units (val, *(gridunit)); |
508 | + val = Inkscape::Quantity::convert(val, "px", *gridunit); |
509 | _rsu_ox.setValue (val); |
510 | val = origin[Geom::Y]; |
511 | - val = sp_pixels_get_units (val, *(gridunit)); |
512 | + val = Inkscape::Quantity::convert(val, "px", *gridunit); |
513 | _rsu_oy.setValue (val); |
514 | val = spacing[Geom::X]; |
515 | - double gridx = sp_pixels_get_units (val, *(gridunit)); |
516 | + double gridx = Inkscape::Quantity::convert(val, "px", *gridunit); |
517 | _rsu_sx.setValue (gridx); |
518 | val = spacing[Geom::Y]; |
519 | - double gridy = sp_pixels_get_units (val, *(gridunit)); |
520 | + double gridy = Inkscape::Quantity::convert(val, "px", *gridunit); |
521 | _rsu_sy.setValue (gridy); |
522 | |
523 | _rcp_gcol.setRgba32 (color); |
524 | |
525 | === modified file 'src/display/canvas-grid.h' |
526 | --- src/display/canvas-grid.h 2013-01-17 20:07:10 +0000 |
527 | +++ src/display/canvas-grid.h 2013-08-06 18:46:25 +0000 |
528 | @@ -28,6 +28,10 @@ |
529 | class Node; |
530 | } |
531 | |
532 | +namespace Util { |
533 | +class Unit; |
534 | +} |
535 | + |
536 | enum GridType { |
537 | GRID_RECTANGULAR = 0, |
538 | GRID_AXONOMETRIC = 1 |
539 | @@ -88,7 +92,7 @@ |
540 | guint32 empcolor; /**< Color for emphasis lines */ |
541 | gint empspacing; /**< Spacing between emphasis lines */ |
542 | |
543 | - SPUnit const* gridunit; |
544 | + Inkscape::Util::Unit const* gridunit; |
545 | |
546 | Inkscape::XML::Node * repr; |
547 | SPDocument *doc; |
548 | |
549 | === modified file 'src/document.cpp' |
550 | --- src/document.cpp 2013-07-10 00:46:51 +0000 |
551 | +++ src/document.cpp 2013-08-06 18:46:25 +0000 |
552 | @@ -49,7 +49,6 @@ |
553 | #include "display/drawing-item.h" |
554 | #include "document-private.h" |
555 | #include "document-undo.h" |
556 | -#include "helper/units.h" |
557 | #include "id-clash.h" |
558 | #include "inkscape-private.h" |
559 | #include "inkscape-version.h" |
560 | @@ -63,12 +62,13 @@ |
561 | #include "sp-object-repr.h" |
562 | #include "sp-symbol.h" |
563 | #include "transf_mat_3x4.h" |
564 | -#include "unit-constants.h" |
565 | +#include "util/units.h" |
566 | #include "xml/repr.h" |
567 | #include "xml/rebase-hrefs.h" |
568 | #include "libcroco/cr-cascade.h" |
569 | |
570 | using Inkscape::DocumentUndo; |
571 | +using Inkscape::Util::unit_table; |
572 | |
573 | // Higher number means lower priority. |
574 | #define SP_DOCUMENT_UPDATE_PRIORITY (G_PRIORITY_HIGH_IDLE - 2) |
575 | @@ -546,21 +546,21 @@ |
576 | return result; |
577 | } |
578 | |
579 | -void SPDocument::setWidth(gdouble width, const SPUnit *unit) |
580 | +void SPDocument::setWidth(const Inkscape::Util::Quantity &width) |
581 | { |
582 | if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= |
583 | - root->viewBox.setMax(Geom::Point(root->viewBox.left() + sp_units_get_pixels (width, *unit), root->viewBox.bottom())); |
584 | + root->viewBox.setMax(Geom::Point(root->viewBox.left() + width.value("px"), root->viewBox.bottom())); |
585 | } else { // set to width= |
586 | gdouble old_computed = root->width.computed; |
587 | - root->width.computed = sp_units_get_pixels (width, *unit); |
588 | + root->width.computed = width.value("px"); |
589 | /* SVG does not support meters as a unit, so we must translate meters to |
590 | * cm when writing */ |
591 | - if (!strcmp(unit->abbr, "m")) { |
592 | - root->width.value = 100*width; |
593 | + if (*width.unit == unit_table.getUnit("m")) { |
594 | + root->width.value = width.value("cm"); |
595 | root->width.unit = SVGLength::CM; |
596 | } else { |
597 | - root->width.value = width; |
598 | - root->width.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit); |
599 | + root->width.value = width.quantity; |
600 | + root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); |
601 | } |
602 | |
603 | if (root->viewBox_set) |
604 | @@ -582,21 +582,21 @@ |
605 | return result; |
606 | } |
607 | |
608 | -void SPDocument::setHeight(gdouble height, const SPUnit *unit) |
609 | +void SPDocument::setHeight(const Inkscape::Util::Quantity &height) |
610 | { |
611 | if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= |
612 | - root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + sp_units_get_pixels (height, *unit))); |
613 | + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + height.value("px"))); |
614 | } else { // set to height= |
615 | gdouble old_computed = root->height.computed; |
616 | - root->height.computed = sp_units_get_pixels (height, *unit); |
617 | + root->height.computed = height.value("px"); |
618 | /* SVG does not support meters as a unit, so we must translate meters to |
619 | * cm when writing */ |
620 | - if (!strcmp(unit->abbr, "m")) { |
621 | - root->height.value = 100*height; |
622 | + if (*height.unit == unit_table.getUnit("m")) { |
623 | + root->height.value = height.value("cm"); |
624 | root->height.unit = SVGLength::CM; |
625 | } else { |
626 | - root->height.value = height; |
627 | - root->height.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit); |
628 | + root->height.value = height.quantity; |
629 | + root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); |
630 | } |
631 | |
632 | if (root->viewBox_set) |
633 | @@ -631,7 +631,7 @@ |
634 | double const h = rect.height(); |
635 | |
636 | double const old_height = getHeight(); |
637 | - SPUnit const &px(sp_unit_get_by_id(SP_UNIT_PX)); |
638 | + Inkscape::Util::Unit const px = unit_table.getUnit("px"); |
639 | |
640 | /* in px */ |
641 | double margin_top = 0.0; |
642 | @@ -644,9 +644,10 @@ |
643 | if (with_margins && nv) { |
644 | if (nv != NULL) { |
645 | gchar const * const units_abbr = nv->getAttribute("units"); |
646 | - SPUnit const *margin_units = NULL; |
647 | + Inkscape::Util::Unit const *margin_units = NULL; |
648 | if (units_abbr != NULL) { |
649 | - margin_units = sp_unit_get_by_abbreviation(units_abbr); |
650 | + Inkscape::Util::Unit mu = unit_table.getUnit(units_abbr); |
651 | + margin_units = μ |
652 | } |
653 | if (margin_units == NULL) { |
654 | margin_units = &px; |
655 | @@ -663,8 +664,8 @@ |
656 | rect.max() + Geom::Point(margin_right, margin_top)); |
657 | |
658 | |
659 | - setWidth(rect_with_margins.width(), &px); |
660 | - setHeight(rect_with_margins.height(), &px); |
661 | + setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), "px")); |
662 | + setHeight(Inkscape::Util::Quantity(rect_with_margins.height(), "px")); |
663 | |
664 | Geom::Translate const tr( |
665 | Geom::Point(0, old_height - rect_with_margins.height()) |
666 | @@ -964,7 +965,7 @@ |
667 | if (root->viewBox_set) { // if set, take from viewBox |
668 | ctx->viewport = root->viewBox; |
669 | } else { // as a last resort, set size to A4 |
670 | - ctx->viewport = Geom::Rect::from_xywh(0, 0, 210 * PX_PER_MM, 297 * PX_PER_MM); |
671 | + ctx->viewport = Geom::Rect::from_xywh(0, 0, 210 * Inkscape::Util::Quantity::convert(1, "mm", "px"), 297 * Inkscape::Util::Quantity::convert(1, "mm", "px")); |
672 | } |
673 | ctx->i2vp = Geom::identity(); |
674 | } |
675 | |
676 | === modified file 'src/document.h' |
677 | --- src/document.h 2013-07-10 00:46:51 +0000 |
678 | +++ src/document.h 2013-08-06 18:46:25 +0000 |
679 | @@ -35,7 +35,6 @@ |
680 | class SPObject; |
681 | struct SPGroup; |
682 | struct SPRoot; |
683 | -struct SPUnit; |
684 | |
685 | namespace Inkscape { |
686 | struct Application; |
687 | @@ -47,6 +46,9 @@ |
688 | struct Document; |
689 | class Node; |
690 | } |
691 | + namespace Util { |
692 | + class Quantity; |
693 | + } |
694 | } |
695 | |
696 | class SPDefs; |
697 | @@ -229,8 +231,8 @@ |
698 | gdouble getHeight() const; |
699 | Geom::Point getDimensions() const; |
700 | Geom::OptRect preferredBounds() const; |
701 | - void setWidth(gdouble width, const SPUnit *unit); |
702 | - void setHeight(gdouble height, const SPUnit *unit); |
703 | + void setWidth(const Inkscape::Util::Quantity &width); |
704 | + void setHeight(const Inkscape::Util::Quantity &height); |
705 | void requestModified(); |
706 | gint ensureUpToDate(); |
707 | bool addResource(const gchar *key, SPObject *object); |
708 | @@ -254,8 +256,6 @@ |
709 | void setupViewport(SPItemCtx *ctx); |
710 | }; |
711 | |
712 | -struct SPUnit; |
713 | - |
714 | /* |
715 | * Ideas: How to overcome style invalidation nightmare |
716 | * |
717 | |
718 | === modified file 'src/doxygen-main.cpp' |
719 | --- src/doxygen-main.cpp 2013-07-23 16:54:03 +0000 |
720 | +++ src/doxygen-main.cpp 2013-08-06 18:46:25 +0000 |
721 | @@ -334,8 +334,6 @@ |
722 | * |
723 | * Inkscape::GC |
724 | * |
725 | - * [\ref sp-metrics.cpp, \ref sp-metrics.h] |
726 | - * |
727 | * [\ref prefs-utils.cpp] [\ref print.cpp] |
728 | * |
729 | * - Inkscape::GZipBuffer [\ref streams-gzip.h] |
730 | @@ -350,7 +348,7 @@ |
731 | * Inkscape::Whiteboard::UndoStackObserver [\ref undo-stack-observer.cpp, \ref composite-undo-stack-observer.cpp] |
732 | * [\ref document-undo.cpp] |
733 | * |
734 | - * {\ref dialogs/} [\ref decimal-round.h] [\ref enums.h] [\ref unit-constants.h] |
735 | + * {\ref dialogs/} [\ref decimal-round.h] [\ref enums.h] |
736 | */ |
737 | |
738 | |
739 | |
740 | === modified file 'src/extension/internal/cairo-render-context.cpp' |
741 | --- src/extension/internal/cairo-render-context.cpp 2013-08-05 21:07:35 +0000 |
742 | +++ src/extension/internal/cairo-render-context.cpp 2013-08-06 18:46:25 +0000 |
743 | @@ -44,12 +44,11 @@ |
744 | #include "sp-pattern.h" |
745 | #include "sp-mask.h" |
746 | #include "sp-clippath.h" |
747 | +#include "util/units.h" |
748 | #ifdef WIN32 |
749 | #include "libnrtype/FontFactory.h" // USE_PANGO_WIN32 |
750 | #endif |
751 | |
752 | -#include <unit-constants.h> |
753 | - |
754 | #include "cairo-render-context.h" |
755 | #include "cairo-renderer.h" |
756 | #include "extension/system.h" |
757 | @@ -855,7 +854,7 @@ |
758 | _surface = surface; |
759 | |
760 | if (_vector_based_target) { |
761 | - cairo_scale(_cr, PT_PER_PX, PT_PER_PX); |
762 | + cairo_scale(_cr, Inkscape::Util::Quantity::convert(1, "px", "pt"), Inkscape::Util::Quantity::convert(1, "px", "pt")); |
763 | } else if (cairo_surface_get_content(_surface) != CAIRO_CONTENT_ALPHA) { |
764 | // set background color on non-alpha surfaces |
765 | // TODO: bgcolor should be derived from SPDocument |
766 | |
767 | === modified file 'src/extension/internal/cairo-renderer-pdf-out.cpp' |
768 | --- src/extension/internal/cairo-renderer-pdf-out.cpp 2013-08-05 21:07:35 +0000 |
769 | +++ src/extension/internal/cairo-renderer-pdf-out.cpp 2013-08-06 18:46:25 +0000 |
770 | @@ -39,7 +39,7 @@ |
771 | #include <2geom/affine.h> |
772 | #include "document.h" |
773 | |
774 | -#include "unit-constants.h" |
775 | +#include "util/units.h" |
776 | |
777 | namespace Inkscape { |
778 | namespace Extension { |
779 | @@ -197,7 +197,7 @@ |
780 | |
781 | float new_bleedmargin_px = 0.; |
782 | try { |
783 | - new_bleedmargin_px = mod->get_param_float("bleed") * PX_PER_MM; |
784 | + new_bleedmargin_px = mod->get_param_float("bleed") * Inkscape::Util::Quantity::convert(1, "mm", "px"); |
785 | } |
786 | catch(...) { |
787 | g_warning("Parameter <bleed> might not exist"); |
788 | |
789 | === modified file 'src/extension/internal/cairo-renderer.cpp' |
790 | --- src/extension/internal/cairo-renderer.cpp 2012-10-28 18:19:43 +0000 |
791 | +++ src/extension/internal/cairo-renderer.cpp 2013-08-06 18:46:25 +0000 |
792 | @@ -55,7 +55,7 @@ |
793 | #include "sp-mask.h" |
794 | #include "sp-clippath.h" |
795 | |
796 | -#include <unit-constants.h> |
797 | +#include "util/units.h" |
798 | #include "helper/png-write.h" |
799 | #include "helper/pixbuf-ops.h" |
800 | |
801 | @@ -442,7 +442,7 @@ |
802 | */ |
803 | res = ctx->getBitmapResolution(); |
804 | if(res == 0) { |
805 | - res = PX_PER_IN; |
806 | + res = Inkscape::Util::Quantity::convert(1, "in", "px"); |
807 | } |
808 | TRACE(("sp_asbitmap_render: resolution: %f\n", res )); |
809 | |
810 | @@ -463,8 +463,8 @@ |
811 | } |
812 | |
813 | // The width and height of the bitmap in pixels |
814 | - unsigned width = ceil(bbox->width() * (res / PX_PER_IN)); |
815 | - unsigned height = ceil(bbox->height() * (res / PX_PER_IN)); |
816 | + unsigned width = ceil(bbox->width() * (res / Inkscape::Util::Quantity::convert(1, "in", "px"))); |
817 | + unsigned height = ceil(bbox->height() * (res / Inkscape::Util::Quantity::convert(1, "in", "px"))); |
818 | |
819 | if (width == 0 || height == 0) return; |
820 | |
821 | @@ -477,7 +477,7 @@ |
822 | double shift_y = bbox->max()[Geom::Y]; |
823 | |
824 | // For default 90 dpi, snap bitmap to pixel grid |
825 | - if (res == PX_PER_IN) { |
826 | + if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { |
827 | shift_x = round (shift_x); |
828 | shift_y = -round (-shift_y); // Correct rounding despite coordinate inversion. |
829 | // Remove the negations when the inversion is gone. |
830 | @@ -629,7 +629,7 @@ |
831 | |
832 | if (ctx->_vector_based_target) { |
833 | // convert from px to pt |
834 | - d *= Geom::Scale(PT_PER_PX); |
835 | + d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "pt")); |
836 | } |
837 | |
838 | ctx->_width = d.width(); |
839 | @@ -647,11 +647,11 @@ |
840 | } else { |
841 | double high = doc->getHeight(); |
842 | if (ctx->_vector_based_target) |
843 | - high *= PT_PER_PX; |
844 | + high *= Inkscape::Util::Quantity::convert(1, "px", "pt"); |
845 | |
846 | // this transform translates the export drawing to a virtual page (0,0)-(width,height) |
847 | - Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? PX_PER_PT : 1.0), |
848 | - (d.bottom() - high) * (ctx->_vector_based_target ? PX_PER_PT : 1.0))); |
849 | + Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0), |
850 | + (d.bottom() - high) * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0))); |
851 | ctx->transform(tp); |
852 | } |
853 | } |
854 | |
855 | === modified file 'src/extension/internal/emf-win32-inout.cpp' |
856 | --- src/extension/internal/emf-win32-inout.cpp 2013-08-05 21:07:35 +0000 |
857 | +++ src/extension/internal/emf-win32-inout.cpp 2013-08-06 18:46:25 +0000 |
858 | @@ -37,9 +37,9 @@ |
859 | #include "extension/output.h" |
860 | #include "display/drawing.h" |
861 | #include "display/drawing-item.h" |
862 | -#include "unit-constants.h" |
863 | #include "clear-n_.h" |
864 | #include "document.h" |
865 | +#include "util/units.h" |
866 | |
867 | #define WIN32_LEAN_AND_MEAN |
868 | #include <windows.h> |
869 | @@ -60,7 +60,7 @@ |
870 | namespace Extension { |
871 | namespace Internal { |
872 | |
873 | -static float device_scale = DEVICESCALE; |
874 | +static float device_scale = Inkscape::Util::Quantity::convert(1, "px", "pt"); |
875 | static float device_x; |
876 | static float device_y; |
877 | static RECTL rc_old; |
878 | @@ -781,18 +781,18 @@ |
879 | |
880 | d->dc[d->level].PixelsInX = pEmr->rclFrame.right - pEmr->rclFrame.left; |
881 | d->dc[d->level].PixelsInY = pEmr->rclFrame.bottom - pEmr->rclFrame.top; |
882 | - device_x = pEmr->rclFrame.left/100.0*PX_PER_MM; |
883 | - device_y = pEmr->rclFrame.top/100.0*PX_PER_MM; |
884 | + device_x = pEmr->rclFrame.left/100.0*Inkscape::Util::Quantity::convert(1, "mm", "px"); |
885 | + device_y = pEmr->rclFrame.top/100.0*Inkscape::Util::Quantity::convert(1, "mm", "px"); |
886 | |
887 | d->MMX = d->dc[d->level].PixelsInX / 100.0; |
888 | d->MMY = d->dc[d->level].PixelsInY / 100.0; |
889 | |
890 | - d->dc[d->level].PixelsOutX = d->MMX * PX_PER_MM; |
891 | - d->dc[d->level].PixelsOutY = d->MMY * PX_PER_MM; |
892 | + d->dc[d->level].PixelsOutX = d->MMX * Inkscape::Util::Quantity::convert(1, "mm", "px"); |
893 | + d->dc[d->level].PixelsOutY = d->MMY * Inkscape::Util::Quantity::convert(1, "mm", "px"); |
894 | |
895 | // calculate ratio of Inkscape dpi/device dpi |
896 | if (pEmr->szlMillimeters.cx && pEmr->szlDevice.cx) |
897 | - device_scale = PX_PER_MM*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx; |
898 | + device_scale = Inkscape::Util::Quantity::convert(1, "mm", "px")*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx; |
899 | |
900 | tmp_outdef << |
901 | " width=\"" << d->MMX << "mm\"\n" << |
902 | |
903 | === modified file 'src/extension/internal/emf-win32-print.cpp' |
904 | --- src/extension/internal/emf-win32-print.cpp 2013-08-05 21:07:35 +0000 |
905 | +++ src/extension/internal/emf-win32-print.cpp 2013-08-06 18:46:25 +0000 |
906 | @@ -36,6 +36,7 @@ |
907 | #include "helper/geom.h" |
908 | #include "helper/geom-curves.h" |
909 | #include "sp-item.h" |
910 | +#include "util/units.h" |
911 | |
912 | #include "style.h" |
913 | #include "inkscape-version.h" |
914 | @@ -43,8 +44,6 @@ |
915 | |
916 | #include "emf-win32-print.h" |
917 | |
918 | -#include "unit-constants.h" |
919 | - |
920 | #include "extension/system.h" |
921 | #include "extension/print.h" |
922 | #include "document.h" |
923 | @@ -129,7 +128,7 @@ |
924 | if (bbox) d = *bbox; |
925 | } |
926 | |
927 | - d *= Geom::Scale(IN_PER_PX); |
928 | + d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "in")); |
929 | |
930 | float dwInchesX = d.width(); |
931 | float dwInchesY = d.height(); |
932 | @@ -196,7 +195,7 @@ |
933 | snprintf(buff, sizeof(buff)-1, "Screen=%dx%dpx, %dx%dmm", PixelsX, PixelsY, MMX, MMY); |
934 | GdiComment(hdc, strlen(buff), (BYTE*) buff); |
935 | |
936 | - snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * MM_PER_IN, dwInchesY * MM_PER_IN); |
937 | + snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * Inkscape::Util::Quantity::convert(1, "in", "mm"), dwInchesY * Inkscape::Util::Quantity::convert(1, "in", "mm")); |
938 | GdiComment(hdc, strlen(buff), (BYTE*) buff); |
939 | } |
940 | |
941 | @@ -304,7 +303,7 @@ |
942 | |
943 | double scale = sqrt( (p[X]*p[X]) + (p[Y]*p[Y]) ) / sqrt(2); |
944 | |
945 | - DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * IN_PER_PX * dwDPI) ); |
946 | + DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI) ); |
947 | |
948 | if (style->stroke_linecap.computed == 0) { |
949 | linecap = PS_ENDCAP_FLAT; |
950 | @@ -341,7 +340,7 @@ |
951 | n_dash = style->stroke_dash.n_dash; |
952 | dash = new DWORD[n_dash]; |
953 | for (i = 0; i < style->stroke_dash.n_dash; i++) { |
954 | - dash[i] = (DWORD) (style->stroke_dash.dash[i] * IN_PER_PX * dwDPI); |
955 | + dash[i] = (DWORD) (style->stroke_dash.dash[i] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
956 | } |
957 | } |
958 | } |
959 | @@ -544,8 +543,8 @@ |
960 | |
961 | Geom::Point p0 = pit->initialPoint(); |
962 | |
963 | - p0[X] = (p0[X] * IN_PER_PX * dwDPI); |
964 | - p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); |
965 | + p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
966 | + p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
967 | |
968 | LONG const x0 = (LONG) round(p0[X]); |
969 | LONG const y0 = (LONG) round(rc.bottom-p0[Y]); |
970 | @@ -564,10 +563,10 @@ |
971 | //Geom::Point p0 = cit->initialPoint(); |
972 | Geom::Point p1 = cit->finalPoint(); |
973 | |
974 | - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); |
975 | - p1[X] = (p1[X] * IN_PER_PX * dwDPI); |
976 | - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); |
977 | - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); |
978 | + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
979 | + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
980 | + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
981 | + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
982 | |
983 | //LONG const x0 = (LONG) round(p0[X]); |
984 | //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); |
985 | @@ -586,14 +585,14 @@ |
986 | Geom::Point p2 = points[2]; |
987 | Geom::Point p3 = points[3]; |
988 | |
989 | - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); |
990 | - p1[X] = (p1[X] * IN_PER_PX * dwDPI); |
991 | - p2[X] = (p2[X] * IN_PER_PX * dwDPI); |
992 | - p3[X] = (p3[X] * IN_PER_PX * dwDPI); |
993 | - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); |
994 | - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); |
995 | - p2[Y] = (p2[Y] * IN_PER_PX * dwDPI); |
996 | - p3[Y] = (p3[Y] * IN_PER_PX * dwDPI); |
997 | + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
998 | + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
999 | + p2[X] = (p2[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1000 | + p3[X] = (p3[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1001 | + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1002 | + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1003 | + p2[Y] = (p2[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1004 | + p3[Y] = (p3[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1005 | |
1006 | //LONG const x0 = (LONG) round(p0[X]); |
1007 | //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); |
1008 | @@ -716,8 +715,8 @@ |
1009 | |
1010 | Geom::Point p0 = pit->initialPoint(); |
1011 | |
1012 | - p0[X] = (p0[X] * IN_PER_PX * dwDPI); |
1013 | - p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); |
1014 | + p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1015 | + p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1016 | |
1017 | LONG const x0 = (LONG) round(p0[X]); |
1018 | LONG const y0 = (LONG) round(rc.bottom-p0[Y]); |
1019 | @@ -734,10 +733,10 @@ |
1020 | //Geom::Point p0 = cit->initialPoint(); |
1021 | Geom::Point p1 = cit->finalPoint(); |
1022 | |
1023 | - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); |
1024 | - p1[X] = (p1[X] * IN_PER_PX * dwDPI); |
1025 | - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); |
1026 | - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); |
1027 | + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1028 | + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1029 | + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1030 | + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1031 | |
1032 | //LONG const x0 = (LONG) round(p0[X]); |
1033 | //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); |
1034 | @@ -754,14 +753,14 @@ |
1035 | Geom::Point p2 = points[2]; |
1036 | Geom::Point p3 = points[3]; |
1037 | |
1038 | - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); |
1039 | - p1[X] = (p1[X] * IN_PER_PX * dwDPI); |
1040 | - p2[X] = (p2[X] * IN_PER_PX * dwDPI); |
1041 | - p3[X] = (p3[X] * IN_PER_PX * dwDPI); |
1042 | - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); |
1043 | - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); |
1044 | - p2[Y] = (p2[Y] * IN_PER_PX * dwDPI); |
1045 | - p3[Y] = (p3[Y] * IN_PER_PX * dwDPI); |
1046 | + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1047 | + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1048 | + p2[X] = (p2[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1049 | + p3[X] = (p3[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1050 | + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1051 | + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1052 | + p2[Y] = (p2[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1053 | + p3[Y] = (p3[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1054 | |
1055 | //LONG const x0 = (LONG) round(p0[X]); |
1056 | //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); |
1057 | @@ -829,7 +828,7 @@ |
1058 | LOGFONTW *lf = (LOGFONTW*)g_malloc(sizeof(LOGFONTW)); |
1059 | g_assert(lf != NULL); |
1060 | |
1061 | - lf->lfHeight = -style->font_size.computed * IN_PER_PX * dwDPI; |
1062 | + lf->lfHeight = -style->font_size.computed * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI; |
1063 | lf->lfWidth = 0; |
1064 | lf->lfEscapement = rot; |
1065 | lf->lfOrientation = rot; |
1066 | @@ -878,8 +877,8 @@ |
1067 | SetBkMode(hdc, TRANSPARENT); |
1068 | |
1069 | Geom::Point p2 = p * tf; |
1070 | - p2[Geom::X] = (p2[Geom::X] * IN_PER_PX * dwDPI); |
1071 | - p2[Geom::Y] = (p2[Geom::Y] * IN_PER_PX * dwDPI); |
1072 | + p2[Geom::X] = (p2[Geom::X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1073 | + p2[Geom::Y] = (p2[Geom::Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); |
1074 | |
1075 | LONG const xpos = (LONG) round(p2[Geom::X]); |
1076 | LONG const ypos = (LONG) round(rc.bottom - p2[Geom::Y]); |
1077 | |
1078 | === modified file 'src/extension/internal/gdkpixbuf-input.cpp' |
1079 | --- src/extension/internal/gdkpixbuf-input.cpp 2012-09-20 06:15:42 +0000 |
1080 | +++ src/extension/internal/gdkpixbuf-input.cpp 2013-08-06 18:46:25 +0000 |
1081 | @@ -12,7 +12,7 @@ |
1082 | #include "selection-chemistry.h" |
1083 | #include "sp-image.h" |
1084 | #include "document-undo.h" |
1085 | -#include "unit-constants.h" |
1086 | +#include "util/units.h" |
1087 | #include "image-resolution.h" |
1088 | #include <set> |
1089 | |
1090 | @@ -79,7 +79,7 @@ |
1091 | |
1092 | double width = gdk_pixbuf_get_width(pb); |
1093 | double height = gdk_pixbuf_get_height(pb); |
1094 | - double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", PX_PER_IN); |
1095 | + double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", Inkscape::Util::Quantity::convert(1, "in", "px")); |
1096 | bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi"); |
1097 | ImageResolution *ir = 0; |
1098 | double xscale = 1; |
1099 | |
1100 | === modified file 'src/extension/internal/latex-pstricks.cpp' |
1101 | --- src/extension/internal/latex-pstricks.cpp 2012-04-18 07:02:24 +0000 |
1102 | +++ src/extension/internal/latex-pstricks.cpp 2013-08-06 18:46:25 +0000 |
1103 | @@ -21,7 +21,7 @@ |
1104 | #include <2geom/hvlinesegment.h> |
1105 | #include <errno.h> |
1106 | #include <signal.h> |
1107 | -#include <unit-constants.h> |
1108 | +#include "util/units.h" |
1109 | #include "helper/geom-curves.h" |
1110 | |
1111 | #include "extension/print.h" |
1112 | @@ -117,8 +117,8 @@ |
1113 | } |
1114 | |
1115 | // width and height in pt |
1116 | - _width = doc->getWidth() * PT_PER_PX; |
1117 | - _height = doc->getHeight() * PT_PER_PX; |
1118 | + _width = doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt"); |
1119 | + _height = doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt"); |
1120 | |
1121 | if (res >= 0) { |
1122 | |
1123 | |
1124 | === modified file 'src/extension/internal/latex-text-renderer.cpp' |
1125 | --- src/extension/internal/latex-text-renderer.cpp 2012-10-28 14:10:22 +0000 |
1126 | +++ src/extension/internal/latex-text-renderer.cpp 2013-08-06 18:46:25 +0000 |
1127 | @@ -39,7 +39,7 @@ |
1128 | #include "sp-rect.h" |
1129 | #include "text-editing.h" |
1130 | |
1131 | -#include <unit-constants.h> |
1132 | +#include "util/units.h" |
1133 | |
1134 | #include "extension/system.h" |
1135 | |
1136 | @@ -611,7 +611,7 @@ |
1137 | // scaling of the image when including it in LaTeX |
1138 | |
1139 | os << " \\ifx\\svgwidth\\undefined%\n"; |
1140 | - os << " \\setlength{\\unitlength}{" << d.width() * PT_PER_PX << "bp}%\n"; // note: 'bp' is the Postscript pt unit in LaTeX, see LP bug #792384 |
1141 | + os << " \\setlength{\\unitlength}{" << d.width() * Inkscape::Util::Quantity::convert(1, "px", "pt") << "bp}%\n"; // note: 'bp' is the Postscript pt unit in LaTeX, see LP bug #792384 |
1142 | os << " \\ifx\\svgscale\\undefined%\n"; |
1143 | os << " \\relax%\n"; |
1144 | os << " \\else%\n"; |
1145 | |
1146 | === modified file 'src/extension/internal/pdfinput/pdf-parser.cpp' |
1147 | --- src/extension/internal/pdfinput/pdf-parser.cpp 2013-08-05 21:07:35 +0000 |
1148 | +++ src/extension/internal/pdfinput/pdf-parser.cpp 2013-08-06 18:46:25 +0000 |
1149 | @@ -34,7 +34,7 @@ |
1150 | #include "svg-builder.h" |
1151 | #include "Gfx.h" |
1152 | #include "pdf-parser.h" |
1153 | -#include "unit-constants.h" |
1154 | +#include "util/units.h" |
1155 | |
1156 | #include "goo/gmem.h" |
1157 | #include "goo/GooTimer.h" |
1158 | @@ -279,14 +279,14 @@ |
1159 | ignoreUndef = 0; |
1160 | operatorHistory = NULL; |
1161 | builder = builderA; |
1162 | - builder->setDocumentSize(state->getPageWidth()*PX_PER_PT, |
1163 | - state->getPageHeight()*PX_PER_PT); |
1164 | + builder->setDocumentSize(state->getPageWidth()*Inkscape::Util::Quantity::convert(1, "pt", "px"), |
1165 | + state->getPageHeight()*Inkscape::Util::Quantity::convert(1, "pt", "px")); |
1166 | |
1167 | double *ctm = state->getCTM(); |
1168 | double scaledCTM[6]; |
1169 | for (int i = 0; i < 6; ++i) { |
1170 | baseMatrix[i] = ctm[i]; |
1171 | - scaledCTM[i] = PX_PER_PT * ctm[i]; |
1172 | + scaledCTM[i] = Inkscape::Util::Quantity::convert(1, "pt", "px") * ctm[i]; |
1173 | } |
1174 | saveState(); |
1175 | builder->setTransform((double*)&scaledCTM); |
1176 | |
1177 | === modified file 'src/extension/internal/pdfinput/svg-builder.cpp' |
1178 | --- src/extension/internal/pdfinput/svg-builder.cpp 2013-08-05 21:07:35 +0000 |
1179 | +++ src/extension/internal/pdfinput/svg-builder.cpp 2013-08-06 18:46:25 +0000 |
1180 | @@ -33,7 +33,7 @@ |
1181 | #include "svg/css-ostringstream.h" |
1182 | #include "svg/svg-color.h" |
1183 | #include "color.h" |
1184 | -#include "unit-constants.h" |
1185 | +#include "util/units.h" |
1186 | #include "io/stringstream.h" |
1187 | #include "io/base64stream.h" |
1188 | #include "display/nr-filter-utils.h" |
1189 | @@ -793,7 +793,7 @@ |
1190 | Geom::Affine pat_matrix(matrix[0], matrix[1], matrix[2], matrix[3], |
1191 | matrix[4], matrix[5]); |
1192 | if ( !for_shading && _is_top_level ) { |
1193 | - Geom::Affine flip(1.0, 0.0, 0.0, -1.0, 0.0, _height * PT_PER_PX); |
1194 | + Geom::Affine flip(1.0, 0.0, 0.0, -1.0, 0.0, _height * Inkscape::Util::Quantity::convert(1, "px", "pt")); |
1195 | pat_matrix *= flip; |
1196 | } |
1197 | gchar *transform_text = sp_svg_transform_write(pat_matrix); |
1198 | |
1199 | === modified file 'src/flood-context.cpp' |
1200 | --- src/flood-context.cpp 2013-07-01 20:04:32 +0000 |
1201 | +++ src/flood-context.cpp 2013-08-06 18:46:25 +0000 |
1202 | @@ -54,7 +54,6 @@ |
1203 | #include "sp-defs.h" |
1204 | #include "sp-item.h" |
1205 | #include "splivarot.h" |
1206 | -#include "sp-metrics.h" |
1207 | #include "sp-namedview.h" |
1208 | #include "sp-object.h" |
1209 | #include "sp-path.h" |
1210 | |
1211 | === modified file 'src/flood-context.h' |
1212 | --- src/flood-context.h 2013-03-14 23:24:17 +0000 |
1213 | +++ src/flood-context.h 2013-08-06 18:46:25 +0000 |
1214 | @@ -15,8 +15,6 @@ |
1215 | #include <sigc++/sigc++.h> |
1216 | #include <gtk/gtk.h> |
1217 | #include "event-context.h" |
1218 | -#include "helper/unit-menu.h" |
1219 | -#include "helper/units.h" |
1220 | |
1221 | #define SP_TYPE_FLOOD_CONTEXT (sp_flood_context_get_type ()) |
1222 | #define SP_FLOOD_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_FLOOD_CONTEXT, SPFloodContext)) |
1223 | |
1224 | === modified file 'src/helper/Makefile_insert' |
1225 | --- src/helper/Makefile_insert 2013-07-01 20:04:32 +0000 |
1226 | +++ src/helper/Makefile_insert 2013-08-06 18:46:25 +0000 |
1227 | @@ -18,12 +18,6 @@ |
1228 | helper/png-write.h \ |
1229 | helper/sp-marshal.cpp \ |
1230 | helper/sp-marshal.h \ |
1231 | - helper/unit-menu.cpp \ |
1232 | - helper/unit-menu.h \ |
1233 | - helper/unit-tracker.cpp \ |
1234 | - helper/unit-tracker.h \ |
1235 | - helper/units.cpp \ |
1236 | - helper/units.h \ |
1237 | helper/window.cpp \ |
1238 | helper/window.h \ |
1239 | helper/stock-items.cpp \ |
1240 | @@ -46,9 +40,3 @@ |
1241 | else mv helper/tmp.sp-marshal.cpp helper/sp-marshal.cpp; fi |
1242 | |
1243 | helper/sp-marshal.cpp helper/sp-marshal.h: helper/sp-marshal.list |
1244 | - |
1245 | -# ###################### |
1246 | -# ### CxxTest stuff #### |
1247 | -# ###################### |
1248 | -CXXTEST_TESTSUITES += \ |
1249 | - $(srcdir)/helper/units-test.h |
1250 | |
1251 | === modified file 'src/helper/pixbuf-ops.cpp' |
1252 | --- src/helper/pixbuf-ops.cpp 2013-03-25 17:42:31 +0000 |
1253 | +++ src/helper/pixbuf-ops.cpp 2013-08-06 18:46:25 +0000 |
1254 | @@ -29,7 +29,7 @@ |
1255 | #include "sp-root.h" |
1256 | #include "sp-use.h" |
1257 | #include "sp-defs.h" |
1258 | -#include "unit-constants.h" |
1259 | +#include "util/units.h" |
1260 | |
1261 | #include "helper/pixbuf-ops.h" |
1262 | |
1263 | @@ -121,7 +121,7 @@ |
1264 | origin[Geom::X] = origin[Geom::X] + (screen[Geom::X].extent() * ((1 - padding) / 2)); |
1265 | origin[Geom::Y] = origin[Geom::Y] + (screen[Geom::Y].extent() * ((1 - padding) / 2)); |
1266 | |
1267 | - Geom::Scale scale( (xdpi / PX_PER_IN), (ydpi / PX_PER_IN)); |
1268 | + Geom::Scale scale( (xdpi / Inkscape::Util::Quantity::convert(1, "in", "px")), (ydpi / Inkscape::Util::Quantity::convert(1, "in", "px"))); |
1269 | Geom::Affine affine = scale * Geom::Translate(-origin * scale); |
1270 | |
1271 | /* Create ArenaItems and set transform */ |
1272 | |
1273 | === removed file 'src/helper/unit-menu.cpp' |
1274 | --- src/helper/unit-menu.cpp 2013-01-26 19:33:04 +0000 |
1275 | +++ src/helper/unit-menu.cpp 1970-01-01 00:00:00 +0000 |
1276 | @@ -1,360 +0,0 @@ |
1277 | -#define __SP_UNIT_MENU_C__ |
1278 | - |
1279 | -/* |
1280 | - * Unit selector with autupdate capability |
1281 | - * |
1282 | - * Authors: |
1283 | - * Lauris Kaplinski <lauris@kaplinski.com> |
1284 | - * bulia byak <buliabyak@users.sf.net> |
1285 | - * |
1286 | - * Copyright (C) 2000-2002 Authors |
1287 | - * |
1288 | - * Released under GNU GPL, read the file 'COPYING' for more information |
1289 | - */ |
1290 | - |
1291 | -#define noUNIT_SELECTOR_VERBOSE |
1292 | - |
1293 | -#ifdef HAVE_CONFIG_H |
1294 | -# include "config.h" |
1295 | -#endif |
1296 | -#include <gtk/gtk.h> |
1297 | -#include "helper/sp-marshal.h" |
1298 | -#include "helper/units.h" |
1299 | -#include "helper/unit-menu.h" |
1300 | -#include "widgets/spw-utilities.h" |
1301 | - |
1302 | -struct SPUnitSelector { |
1303 | - GtkHBox box; |
1304 | - |
1305 | - GtkWidget *combo_box; |
1306 | - GtkListStore *store; |
1307 | - |
1308 | - |
1309 | - guint bases; |
1310 | - GSList *units; |
1311 | - SPUnit const *unit; |
1312 | - gdouble ctmscale; |
1313 | - guint plural : 1; |
1314 | - guint abbr : 1; |
1315 | - |
1316 | - guint update : 1; |
1317 | - |
1318 | - GSList *adjustments; |
1319 | -}; |
1320 | - |
1321 | -enum {COMBO_COL_LABEL=0, COMBO_COL_UNIT}; |
1322 | - |
1323 | -struct SPUnitSelectorClass { |
1324 | - GtkHBoxClass parent_class; |
1325 | - |
1326 | - gboolean (* set_unit)(SPUnitSelector *us, SPUnit const *old, SPUnit const *new_unit); |
1327 | -}; |
1328 | - |
1329 | -enum {SET_UNIT, LAST_SIGNAL}; |
1330 | - |
1331 | -static void sp_unit_selector_finalize(GObject *object); |
1332 | - |
1333 | -static guint signals[LAST_SIGNAL] = {0}; |
1334 | - |
1335 | -G_DEFINE_TYPE(SPUnitSelector, sp_unit_selector, GTK_TYPE_HBOX); |
1336 | - |
1337 | -static void |
1338 | -sp_unit_selector_class_init(SPUnitSelectorClass *klass) |
1339 | -{ |
1340 | - GObjectClass *object_class = G_OBJECT_CLASS(klass); |
1341 | - |
1342 | - signals[SET_UNIT] = g_signal_new("set_unit", |
1343 | - G_TYPE_FROM_CLASS(klass), |
1344 | - G_SIGNAL_RUN_LAST, |
1345 | - G_STRUCT_OFFSET(SPUnitSelectorClass, set_unit), |
1346 | - NULL, NULL, |
1347 | - sp_marshal_BOOLEAN__POINTER_POINTER, |
1348 | - G_TYPE_BOOLEAN, 2, |
1349 | - G_TYPE_POINTER, G_TYPE_POINTER); |
1350 | - |
1351 | - object_class->finalize = sp_unit_selector_finalize; |
1352 | -} |
1353 | - |
1354 | -static void |
1355 | -sp_unit_selector_init(SPUnitSelector *us) |
1356 | -{ |
1357 | - us->ctmscale = 1.0; |
1358 | - us->abbr = FALSE; |
1359 | - us->plural = TRUE; |
1360 | - |
1361 | - /** |
1362 | - * Create a combo_box and store with 2 columns, |
1363 | - * a label and a pointer to a SPUnit |
1364 | - */ |
1365 | - us->store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); |
1366 | - us->combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (us->store)); |
1367 | - |
1368 | - GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); |
1369 | - g_object_set (renderer, "scale", 0.8, "scale-set", TRUE, NULL); |
1370 | - gtk_cell_renderer_set_padding (renderer, 2, 0); |
1371 | - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (us->combo_box), renderer, TRUE); |
1372 | - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (us->combo_box), renderer, "text", COMBO_COL_LABEL, NULL); |
1373 | - |
1374 | - gtk_widget_show (us->combo_box); |
1375 | - gtk_box_pack_start (GTK_BOX(us), us->combo_box, TRUE, TRUE, 0); |
1376 | -} |
1377 | - |
1378 | -static void |
1379 | -sp_unit_selector_finalize(GObject *object) |
1380 | -{ |
1381 | - SPUnitSelector *selector = SP_UNIT_SELECTOR(object); |
1382 | - |
1383 | - if (selector->combo_box) { |
1384 | - selector->combo_box = NULL; |
1385 | - } |
1386 | - |
1387 | - while (selector->adjustments) { |
1388 | - g_object_unref(selector->adjustments->data); |
1389 | - selector->adjustments = g_slist_remove(selector->adjustments, selector->adjustments->data); |
1390 | - } |
1391 | - |
1392 | - if (selector->units) { |
1393 | - sp_unit_free_list(selector->units); |
1394 | - } |
1395 | - |
1396 | - selector->unit = NULL; |
1397 | - |
1398 | - G_OBJECT_CLASS(sp_unit_selector_parent_class)->finalize(object); |
1399 | -} |
1400 | - |
1401 | -GtkWidget * |
1402 | -sp_unit_selector_new(guint bases) |
1403 | -{ |
1404 | - SPUnitSelector *us = SP_UNIT_SELECTOR(g_object_new(SP_TYPE_UNIT_SELECTOR, NULL)); |
1405 | - |
1406 | - sp_unit_selector_set_bases(us, bases); |
1407 | - |
1408 | - return GTK_WIDGET(us); |
1409 | -} |
1410 | - |
1411 | -void |
1412 | -sp_unit_selector_setsize(GtkWidget *us, guint w, guint h) |
1413 | -{ |
1414 | - gtk_widget_set_size_request((SP_UNIT_SELECTOR(us))->combo_box, w, h); |
1415 | -} |
1416 | - |
1417 | -SPUnit const * |
1418 | -sp_unit_selector_get_unit(SPUnitSelector const *us) |
1419 | -{ |
1420 | - g_return_val_if_fail(us != NULL, NULL); |
1421 | - g_return_val_if_fail(SP_IS_UNIT_SELECTOR(us), NULL); |
1422 | - |
1423 | - return us->unit; |
1424 | -} |
1425 | - |
1426 | - |
1427 | -static void |
1428 | -on_combo_box_changed (GtkComboBox *widget, SPUnitSelector *us) |
1429 | -{ |
1430 | - GtkTreeIter iter; |
1431 | - if (!gtk_combo_box_get_active_iter (widget, &iter)) { |
1432 | - return; |
1433 | - } |
1434 | - |
1435 | - SPUnit const *unit = NULL; |
1436 | - gtk_tree_model_get (GTK_TREE_MODEL(us->store), &iter, COMBO_COL_UNIT, &unit, -1); |
1437 | - |
1438 | - g_return_if_fail(unit != NULL); |
1439 | - |
1440 | -#ifdef UNIT_SELECTOR_VERBOSE |
1441 | - g_print("Old unit %s new unit %s\n", us->unit->name, unit->name); |
1442 | -#endif |
1443 | - |
1444 | - SPUnit const *old = us->unit; |
1445 | - us->unit = unit; |
1446 | - |
1447 | - us->update = TRUE; |
1448 | - |
1449 | - gboolean consumed = FALSE; |
1450 | - g_signal_emit(G_OBJECT(us), signals[SET_UNIT], 0, old, unit, &consumed); |
1451 | - |
1452 | - if ( !consumed |
1453 | - && ( unit->base == old->base |
1454 | - || ( unit->base == SP_UNIT_ABSOLUTE && old->base == SP_UNIT_DEVICE ) |
1455 | - || ( old->base == SP_UNIT_ABSOLUTE && unit->base == SP_UNIT_DEVICE ) ) ) { |
1456 | - // Either the same base, or absolute<->device: |
1457 | - /* Recalculate adjustments. */ |
1458 | - for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) { |
1459 | - GtkAdjustment *adj = GTK_ADJUSTMENT(l->data); |
1460 | - gdouble val = gtk_adjustment_get_value (adj); |
1461 | -#ifdef UNIT_SELECTOR_VERBOSE |
1462 | - g_print("Old val %g ... ", val); |
1463 | -#endif |
1464 | - val = sp_convert_distance_full(val, *old, *unit); |
1465 | -#ifdef UNIT_SELECTOR_VERBOSE |
1466 | - g_print("new val %g\n", val); |
1467 | -#endif |
1468 | - gtk_adjustment_set_value (adj, val); |
1469 | - } |
1470 | - /* need to separate the value changing from the notification |
1471 | - * or else the unit changes can break the calculations */ |
1472 | - for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) { |
1473 | - gtk_adjustment_value_changed(GTK_ADJUSTMENT(l->data)); |
1474 | - } |
1475 | - } else if (!consumed && unit->base != old->base) { |
1476 | - /* when the base changes, signal all the adjustments to get them |
1477 | - * to recalculate */ |
1478 | - for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) { |
1479 | - g_signal_emit_by_name(G_OBJECT(l->data), "value_changed"); |
1480 | - } |
1481 | - } |
1482 | - |
1483 | - us->update = FALSE; |
1484 | - |
1485 | -} |
1486 | - |
1487 | -static void |
1488 | -spus_rebuild_menu(SPUnitSelector *us) |
1489 | -{ |
1490 | - |
1491 | - gtk_list_store_clear(us->store); |
1492 | - |
1493 | - GtkTreeIter iter; |
1494 | - |
1495 | - gint pos = 0; |
1496 | - gint p = 0; |
1497 | - for (GSList *l = us->units; l != NULL; l = l->next) { |
1498 | - SPUnit const *u = static_cast<SPUnit const*>(l->data); |
1499 | - |
1500 | - // use only abbreviations in the menu |
1501 | - // i = gtk_menu_item_new_with_label((us->abbr) ? (us->plural) ? u->abbr_plural : u->abbr : (us->plural) ? u->plural : u->name); |
1502 | - gtk_list_store_append (us->store, &iter); |
1503 | - gtk_list_store_set (us->store, &iter, COMBO_COL_LABEL, u->abbr, COMBO_COL_UNIT, (gpointer) u, -1); |
1504 | - |
1505 | - if (u == us->unit) { |
1506 | - pos = p; |
1507 | - } |
1508 | - |
1509 | - p += 1; |
1510 | - } |
1511 | - |
1512 | - gtk_combo_box_set_active(GTK_COMBO_BOX(us->combo_box), pos); |
1513 | - g_signal_connect (G_OBJECT (us->combo_box), "changed", G_CALLBACK (on_combo_box_changed), us); |
1514 | -} |
1515 | - |
1516 | -void |
1517 | -sp_unit_selector_set_bases(SPUnitSelector *us, guint bases) |
1518 | -{ |
1519 | - g_return_if_fail(us != NULL); |
1520 | - g_return_if_fail(SP_IS_UNIT_SELECTOR(us)); |
1521 | - |
1522 | - if (bases == us->bases) return; |
1523 | - |
1524 | - GSList *units = sp_unit_get_list(bases); |
1525 | - g_return_if_fail(units != NULL); |
1526 | - sp_unit_free_list(us->units); |
1527 | - us->units = units; |
1528 | - us->unit = static_cast<SPUnit *>(units->data); |
1529 | - |
1530 | - spus_rebuild_menu(us); |
1531 | -} |
1532 | - |
1533 | -void |
1534 | -sp_unit_selector_add_unit(SPUnitSelector *us, SPUnit const *unit, int position) |
1535 | -{ |
1536 | - if (!g_slist_find(us->units, (gpointer) unit)) { |
1537 | - us->units = g_slist_insert(us->units, (gpointer) unit, position); |
1538 | - |
1539 | - spus_rebuild_menu(us); |
1540 | - } |
1541 | -} |
1542 | - |
1543 | -void |
1544 | -sp_unit_selector_set_unit(SPUnitSelector *us, SPUnit const *unit) |
1545 | -{ |
1546 | - g_return_if_fail(us != NULL); |
1547 | - g_return_if_fail(SP_IS_UNIT_SELECTOR(us)); |
1548 | - |
1549 | - if (unit == NULL) { |
1550 | - return; // silently return, by default a newly created selector uses pt |
1551 | - } |
1552 | - if (unit == us->unit) { |
1553 | - return; |
1554 | - } |
1555 | - |
1556 | - gint const pos = g_slist_index(us->units, (gpointer) unit); |
1557 | - g_return_if_fail(pos >= 0); |
1558 | - |
1559 | - gtk_combo_box_set_active(GTK_COMBO_BOX(us->combo_box), pos); |
1560 | - |
1561 | - SPUnit const *old = us->unit; |
1562 | - us->unit = unit; |
1563 | - |
1564 | - /* Recalculate adjustments */ |
1565 | - for (GSList *l = us->adjustments; l != NULL; l = l->next) { |
1566 | - GtkAdjustment *adj = GTK_ADJUSTMENT(l->data); |
1567 | - gdouble const val = sp_convert_distance_full(gtk_adjustment_get_value (adj), *old, *unit); |
1568 | - gtk_adjustment_set_value(adj, val); |
1569 | - } |
1570 | -} |
1571 | - |
1572 | -void |
1573 | -sp_unit_selector_add_adjustment(SPUnitSelector *us, GtkAdjustment *adj) |
1574 | -{ |
1575 | - g_return_if_fail(us != NULL); |
1576 | - g_return_if_fail(SP_IS_UNIT_SELECTOR(us)); |
1577 | - g_return_if_fail(adj != NULL); |
1578 | - g_return_if_fail(GTK_IS_ADJUSTMENT(adj)); |
1579 | - |
1580 | - g_return_if_fail(!g_slist_find(us->adjustments, adj)); |
1581 | - |
1582 | - g_object_ref(adj); |
1583 | - us->adjustments = g_slist_prepend(us->adjustments, adj); |
1584 | -} |
1585 | - |
1586 | -void |
1587 | -sp_unit_selector_remove_adjustment(SPUnitSelector *us, GtkAdjustment *adj) |
1588 | -{ |
1589 | - g_return_if_fail(us != NULL); |
1590 | - g_return_if_fail(SP_IS_UNIT_SELECTOR(us)); |
1591 | - g_return_if_fail(adj != NULL); |
1592 | - g_return_if_fail(GTK_IS_ADJUSTMENT(adj)); |
1593 | - |
1594 | - g_return_if_fail(g_slist_find(us->adjustments, adj)); |
1595 | - |
1596 | - us->adjustments = g_slist_remove(us->adjustments, adj); |
1597 | - g_object_unref(adj); |
1598 | -} |
1599 | - |
1600 | -gboolean |
1601 | -sp_unit_selector_update_test(SPUnitSelector const *selector) |
1602 | -{ |
1603 | - g_return_val_if_fail(selector != NULL, FALSE); |
1604 | - g_return_val_if_fail(SP_IS_UNIT_SELECTOR(selector), FALSE); |
1605 | - |
1606 | - return selector->update; |
1607 | -} |
1608 | - |
1609 | -double |
1610 | -sp_unit_selector_get_value_in_pixels(SPUnitSelector const *selector, GtkAdjustment *adj) |
1611 | -{ |
1612 | - g_return_val_if_fail(selector != NULL, gtk_adjustment_get_value (adj)); |
1613 | - g_return_val_if_fail(SP_IS_UNIT_SELECTOR(selector), gtk_adjustment_get_value (adj)); |
1614 | - |
1615 | - return sp_units_get_pixels(gtk_adjustment_get_value (adj), *(selector->unit)); |
1616 | -} |
1617 | - |
1618 | -void |
1619 | -sp_unit_selector_set_value_in_pixels(SPUnitSelector *selector, GtkAdjustment *adj, double value) |
1620 | -{ |
1621 | - g_return_if_fail(selector != NULL); |
1622 | - g_return_if_fail(SP_IS_UNIT_SELECTOR(selector)); |
1623 | - |
1624 | - gtk_adjustment_set_value(adj, sp_pixels_get_units(value, *(selector->unit))); |
1625 | -} |
1626 | - |
1627 | -/* |
1628 | - Local Variables: |
1629 | - mode:c++ |
1630 | - c-file-style:"stroustrup" |
1631 | - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
1632 | - indent-tabs-mode:nil |
1633 | - fill-column:99 |
1634 | - End: |
1635 | -*/ |
1636 | -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
1637 | |
1638 | === removed file 'src/helper/unit-menu.h' |
1639 | --- src/helper/unit-menu.h 2011-12-08 11:53:54 +0000 |
1640 | +++ src/helper/unit-menu.h 1970-01-01 00:00:00 +0000 |
1641 | @@ -1,60 +0,0 @@ |
1642 | -#ifndef SP_UNIT_MENU_H |
1643 | -#define SP_UNIT_MENU_H |
1644 | - |
1645 | -/* |
1646 | - * SPUnitMenu |
1647 | - * |
1648 | - * Generic (and quite unintelligent) grid item for gnome canvas |
1649 | - * |
1650 | - * Copyright (C) Lauris Kaplinski 2000 |
1651 | - * |
1652 | - */ |
1653 | - |
1654 | -#include <glib.h> |
1655 | -#include <gtk/gtk.h> |
1656 | - |
1657 | -struct SPUnit; |
1658 | -struct SPUnitSelector; |
1659 | -struct SPUnitSelectorClass; |
1660 | - |
1661 | -/* Unit selector Widget */ |
1662 | - |
1663 | -#define SP_TYPE_UNIT_SELECTOR (sp_unit_selector_get_type()) |
1664 | -#define SP_UNIT_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_UNIT_SELECTOR, SPUnitSelector)) |
1665 | -#define SP_UNIT_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SP_TYPE_UNIT_SELECTOR, SPUnitSelectorClass)) |
1666 | -#define SP_IS_UNIT_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_UNIT_SELECTOR)) |
1667 | -#define SP_IS_UNIT_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), SP_TYPE_UNIT_SELECTOR)) |
1668 | - |
1669 | -GType sp_unit_selector_get_type(void); |
1670 | - |
1671 | -GtkWidget *sp_unit_selector_new(guint bases); |
1672 | -void sp_unit_selector_setsize(GtkWidget *us, guint w, guint h); |
1673 | - |
1674 | -SPUnit const *sp_unit_selector_get_unit(SPUnitSelector const *selector); |
1675 | - |
1676 | -void sp_unit_selector_set_bases(SPUnitSelector *selector, guint bases); |
1677 | -void sp_unit_selector_add_unit(SPUnitSelector *selector, SPUnit const *unit, int position); |
1678 | - |
1679 | -void sp_unit_selector_set_unit(SPUnitSelector *selector, SPUnit const *unit); |
1680 | -void sp_unit_selector_add_adjustment(SPUnitSelector *selector, GtkAdjustment *adjustment); |
1681 | -void sp_unit_selector_remove_adjustment(SPUnitSelector *selector, GtkAdjustment *adjustment); |
1682 | - |
1683 | -gboolean sp_unit_selector_update_test(SPUnitSelector const *selector); |
1684 | - |
1685 | -double sp_unit_selector_get_value_in_pixels(SPUnitSelector const *selector, GtkAdjustment *adj); |
1686 | -void sp_unit_selector_set_value_in_pixels(SPUnitSelector *selector, GtkAdjustment *adj, double value); |
1687 | - |
1688 | - |
1689 | - |
1690 | -#endif // SP_UNIT_MENU_H |
1691 | - |
1692 | -/* |
1693 | - Local Variables: |
1694 | - mode:c++ |
1695 | - c-file-style:"stroustrup" |
1696 | - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
1697 | - indent-tabs-mode:nil |
1698 | - fill-column:99 |
1699 | - End: |
1700 | -*/ |
1701 | -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
1702 | |
1703 | === removed file 'src/helper/unit-tracker.cpp' |
1704 | --- src/helper/unit-tracker.cpp 2011-06-03 10:44:52 +0000 |
1705 | +++ src/helper/unit-tracker.cpp 1970-01-01 00:00:00 +0000 |
1706 | @@ -1,267 +0,0 @@ |
1707 | -/* |
1708 | - * Inkscape::UnitTracker - Simple mediator to synchronize changes to a set |
1709 | - * of possible units |
1710 | - * |
1711 | - * Authors: |
1712 | - * Jon A. Cruz <jon@joncruz.org> |
1713 | - * |
1714 | - * Copyright (C) 2007 Jon A. Cruz |
1715 | - * |
1716 | - * Released under GNU GPL, read the file 'COPYING' for more information |
1717 | - */ |
1718 | - |
1719 | -#include <gtk/gtk.h> |
1720 | - |
1721 | -#include "unit-tracker.h" |
1722 | -#include "ege-select-one-action.h" |
1723 | - |
1724 | -namespace Inkscape { |
1725 | - |
1726 | -enum { |
1727 | - COLUMN_STRING, |
1728 | - COLUMN_SPUNIT, |
1729 | - N_COLUMNS |
1730 | -}; |
1731 | - |
1732 | -UnitTracker::UnitTracker( guint bases ) : |
1733 | - _active(0), |
1734 | - _isUpdating(false), |
1735 | - _activeUnit(0), |
1736 | - _store(0), |
1737 | - _unitList(0), |
1738 | - _actionList(0), |
1739 | - _adjList(0), |
1740 | - _priorValues() |
1741 | -{ |
1742 | - _store = gtk_list_store_new( N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER ); |
1743 | - setBase( bases ); |
1744 | -} |
1745 | - |
1746 | -UnitTracker::~UnitTracker() |
1747 | -{ |
1748 | - if ( _unitList ) { |
1749 | - sp_unit_free_list( _unitList ); |
1750 | - } |
1751 | - |
1752 | - // Unhook weak references to GtkActions |
1753 | - while ( _actionList ) { |
1754 | - g_signal_handlers_disconnect_by_func( G_OBJECT(_actionList->data), (gpointer)_unitChangedCB, this ); |
1755 | - g_object_weak_unref( G_OBJECT(_actionList->data), _actionFinalizedCB, this ); |
1756 | - _actionList = g_slist_delete_link( _actionList, _actionList ); |
1757 | - } |
1758 | - |
1759 | - // Unhook wek references to GtkAdjustments |
1760 | - while ( _adjList ) { |
1761 | - g_object_weak_unref( G_OBJECT(_adjList->data), _adjustmentFinalizedCB, this ); |
1762 | - _adjList = g_slist_delete_link( _adjList, _adjList ); |
1763 | - } |
1764 | -} |
1765 | - |
1766 | -void UnitTracker::setBase( guint bases ) |
1767 | -{ |
1768 | - GtkTreeIter iter; |
1769 | - _unitList = sp_unit_get_list( bases ); |
1770 | - for ( GSList* cur = _unitList; cur; cur = g_slist_next(cur) ) { |
1771 | - SPUnit* unit = static_cast<SPUnit*>(cur->data); |
1772 | - gtk_list_store_append( _store, &iter ); |
1773 | - gtk_list_store_set( _store, &iter, COLUMN_STRING, unit->abbr, COLUMN_SPUNIT, unit, -1 ); |
1774 | - } |
1775 | - gint count = gtk_tree_model_iter_n_children( GTK_TREE_MODEL(_store), 0 ); |
1776 | - if ( (count > 0) && (_active > count) ) { |
1777 | - _setActive( count - 1 ); |
1778 | - } else { |
1779 | - _setActive( _active ); |
1780 | - } |
1781 | -} |
1782 | - |
1783 | -void UnitTracker::addUnit( SPUnitId id, gint index ) |
1784 | -{ |
1785 | - GtkTreeIter iter; |
1786 | - const SPUnit* percentUnit = &sp_unit_get_by_id( id ); |
1787 | - gtk_list_store_insert( _store, &iter, index ); |
1788 | - gtk_list_store_set( _store, &iter, COLUMN_STRING, percentUnit->abbr, COLUMN_SPUNIT, percentUnit, -1 ); |
1789 | -} |
1790 | - |
1791 | -bool UnitTracker::isUpdating() const |
1792 | -{ |
1793 | - return _isUpdating; |
1794 | -} |
1795 | - |
1796 | -SPUnit const* UnitTracker::getActiveUnit() const |
1797 | -{ |
1798 | - return _activeUnit; |
1799 | -} |
1800 | - |
1801 | -void UnitTracker::setActiveUnit( SPUnit const *unit ) |
1802 | -{ |
1803 | - if ( unit ) { |
1804 | - GtkTreeIter iter; |
1805 | - int index = 0; |
1806 | - gboolean found = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(_store), &iter ); |
1807 | - while ( found ) { |
1808 | - SPUnit* storedUnit = 0; |
1809 | - gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &storedUnit, -1 ); |
1810 | - if ( storedUnit && (storedUnit->unit_id == unit->unit_id) ) { |
1811 | - _setActive(index); |
1812 | - break; |
1813 | - } |
1814 | - |
1815 | - found = gtk_tree_model_iter_next( GTK_TREE_MODEL(_store), &iter ); |
1816 | - index++; |
1817 | - } |
1818 | - } |
1819 | -} |
1820 | - |
1821 | -void UnitTracker::addAdjustment( GtkAdjustment* adj ) |
1822 | -{ |
1823 | - if ( !g_slist_find( _adjList, adj ) ) { |
1824 | - g_object_weak_ref( G_OBJECT(adj), _adjustmentFinalizedCB, this ); |
1825 | - _adjList = g_slist_append( _adjList, adj ); |
1826 | - } |
1827 | -} |
1828 | - |
1829 | -void UnitTracker::setFullVal( GtkAdjustment* adj, gdouble val ) |
1830 | -{ |
1831 | - _priorValues[adj] = val; |
1832 | -} |
1833 | - |
1834 | -GtkAction* UnitTracker::createAction( gchar const* name, gchar const* label, gchar const* tooltip ) |
1835 | -{ |
1836 | - EgeSelectOneAction* act1 = ege_select_one_action_new( name, label, tooltip, NULL, GTK_TREE_MODEL(_store) ); |
1837 | - ege_select_one_action_set_label_column( act1, COLUMN_STRING ); |
1838 | - if ( _active ) { |
1839 | - ege_select_one_action_set_active( act1, _active ); |
1840 | - } |
1841 | - |
1842 | - ege_select_one_action_set_appearance( act1, "minimal" ); |
1843 | - g_object_weak_ref( G_OBJECT(act1), _actionFinalizedCB, this ); |
1844 | - g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK( _unitChangedCB ), this ); |
1845 | - _actionList = g_slist_append( _actionList, act1 ); |
1846 | - |
1847 | - return GTK_ACTION(act1); |
1848 | -} |
1849 | - |
1850 | -void UnitTracker::_unitChangedCB( GtkAction* action, gpointer data ) |
1851 | -{ |
1852 | - if ( action && data ) { |
1853 | - EgeSelectOneAction* act = EGE_SELECT_ONE_ACTION(action); |
1854 | - gint active = ege_select_one_action_get_active( act ); |
1855 | - UnitTracker* self = reinterpret_cast<UnitTracker*>(data); |
1856 | - self->_setActive(active); |
1857 | - } |
1858 | -} |
1859 | - |
1860 | -void UnitTracker::_actionFinalizedCB( gpointer data, GObject *where_the_object_was ) |
1861 | -{ |
1862 | - if ( data && where_the_object_was ) { |
1863 | - UnitTracker* self = reinterpret_cast<UnitTracker*>(data); |
1864 | - self->_actionFinalized( where_the_object_was ); |
1865 | - } |
1866 | -} |
1867 | - |
1868 | -void UnitTracker::_adjustmentFinalizedCB( gpointer data, GObject *where_the_object_was ) |
1869 | -{ |
1870 | - if ( data && where_the_object_was ) { |
1871 | - UnitTracker* self = reinterpret_cast<UnitTracker*>(data); |
1872 | - self->_adjustmentFinalized( where_the_object_was ); |
1873 | - } |
1874 | -} |
1875 | - |
1876 | -void UnitTracker::_actionFinalized( GObject *where_the_object_was ) |
1877 | -{ |
1878 | - GSList* target = g_slist_find( _actionList, where_the_object_was ); |
1879 | - if ( target ) { |
1880 | - _actionList = g_slist_remove( _actionList, where_the_object_was ); |
1881 | - } else { |
1882 | - g_warning("Received a finalization callback for unknown object %p", where_the_object_was ); |
1883 | - } |
1884 | -} |
1885 | - |
1886 | -void UnitTracker::_adjustmentFinalized( GObject *where_the_object_was ) |
1887 | -{ |
1888 | - GSList* target = g_slist_find( _adjList, where_the_object_was ); |
1889 | - if ( target ) { |
1890 | - _adjList = g_slist_remove( _adjList, where_the_object_was ); |
1891 | - } else { |
1892 | - g_warning("Received a finalization callback for unknown object %p", where_the_object_was ); |
1893 | - } |
1894 | -} |
1895 | - |
1896 | -void UnitTracker::_setActive( gint active ) |
1897 | -{ |
1898 | - if ( active != _active || (_activeUnit == 0) ) { |
1899 | - gint oldActive = _active; |
1900 | - |
1901 | - GtkTreeIter iter; |
1902 | - gboolean found = gtk_tree_model_iter_nth_child( GTK_TREE_MODEL(_store), &iter, NULL, oldActive ); |
1903 | - if ( found ) { |
1904 | - SPUnit* unit = 0; |
1905 | - gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &unit, -1 ); |
1906 | - |
1907 | - found = gtk_tree_model_iter_nth_child( GTK_TREE_MODEL(_store), &iter, NULL, active ); |
1908 | - if ( found ) { |
1909 | - SPUnit* newUnit = 0; |
1910 | - gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &newUnit, -1 ); |
1911 | - _activeUnit = newUnit; |
1912 | - |
1913 | - if ( _adjList ) { |
1914 | - _fixupAdjustments( unit, newUnit ); |
1915 | - } |
1916 | - |
1917 | - } else { |
1918 | - g_warning("Did not find new unit"); |
1919 | - } |
1920 | - } else { |
1921 | - g_warning("Did not find old unit"); |
1922 | - } |
1923 | - |
1924 | - _active = active; |
1925 | - |
1926 | - for ( GSList* cur = _actionList; cur; cur = g_slist_next(cur) ) { |
1927 | - if ( IS_EGE_SELECT_ONE_ACTION( cur->data ) ) { |
1928 | - EgeSelectOneAction* act = EGE_SELECT_ONE_ACTION( cur->data ); |
1929 | - ege_select_one_action_set_active( act, active ); |
1930 | - } |
1931 | - } |
1932 | - } |
1933 | -} |
1934 | - |
1935 | -void UnitTracker::_fixupAdjustments( SPUnit const* oldUnit, SPUnit const *newUnit ) |
1936 | -{ |
1937 | - _isUpdating = true; |
1938 | - for ( GSList* cur = _adjList; cur; cur = g_slist_next(cur) ) { |
1939 | - GtkAdjustment* adj = GTK_ADJUSTMENT(cur->data); |
1940 | - gdouble oldVal = gtk_adjustment_get_value(adj); |
1941 | - gdouble val = oldVal; |
1942 | - |
1943 | - if ((oldUnit->base == SP_UNIT_ABSOLUTE || oldUnit->base == SP_UNIT_DEVICE) |
1944 | - && (newUnit->base == SP_UNIT_DIMENSIONLESS)) |
1945 | - { |
1946 | - val = 1.0 / newUnit->unittobase; |
1947 | - _priorValues[adj] = sp_units_get_pixels( oldVal, *oldUnit ); |
1948 | - } else if ((oldUnit->base == SP_UNIT_DIMENSIONLESS) |
1949 | - && (newUnit->base == SP_UNIT_ABSOLUTE || newUnit->base == SP_UNIT_DEVICE)) { |
1950 | - if ( _priorValues.find(adj) != _priorValues.end() ) { |
1951 | - val = sp_pixels_get_units( _priorValues[adj], *newUnit ); |
1952 | - } |
1953 | - } else { |
1954 | - val = sp_convert_distance_full( oldVal, *oldUnit, *newUnit ); |
1955 | - } |
1956 | - |
1957 | - gtk_adjustment_set_value( adj, val ); |
1958 | - } |
1959 | - _isUpdating = false; |
1960 | -} |
1961 | - |
1962 | -} |
1963 | - |
1964 | -/* |
1965 | - Local Variables: |
1966 | - mode:c++ |
1967 | - c-file-style:"stroustrup" |
1968 | - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
1969 | - indent-tabs-mode:nil |
1970 | - fill-column:99 |
1971 | - End: |
1972 | -*/ |
1973 | -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
1974 | |
1975 | === removed file 'src/helper/unit-tracker.h' |
1976 | --- src/helper/unit-tracker.h 2011-06-03 10:44:52 +0000 |
1977 | +++ src/helper/unit-tracker.h 1970-01-01 00:00:00 +0000 |
1978 | @@ -1,75 +0,0 @@ |
1979 | -/* |
1980 | - * Inkscape::UnitTracker - Simple mediator to synchronize changes to a set |
1981 | - * of possible units |
1982 | - * |
1983 | - * Authors: |
1984 | - * Jon A. Cruz <jon@joncruz.org> |
1985 | - * |
1986 | - * Copyright (C) 2007 Jon A. Cruz |
1987 | - * |
1988 | - * Released under GNU GPL, read the file 'COPYING' for more information |
1989 | - */ |
1990 | - |
1991 | -#ifndef SEEN_INKSCAPE_UNIT_TRACKER_H |
1992 | -#define SEEN_INKSCAPE_UNIT_TRACKER_H |
1993 | - |
1994 | -#include <map> |
1995 | - |
1996 | -#include <gtk/gtk.h> |
1997 | - |
1998 | -#include "helper/units.h" |
1999 | - |
2000 | -namespace Inkscape { |
2001 | - |
2002 | -class UnitTracker |
2003 | -{ |
2004 | -public: |
2005 | - UnitTracker( guint bases = (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE) ); |
2006 | - virtual ~UnitTracker(); |
2007 | - |
2008 | - void setBase( guint bases ); // SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE |
2009 | - void addUnit( SPUnitId id, gint index ); |
2010 | - |
2011 | - bool isUpdating() const; |
2012 | - |
2013 | - void setActiveUnit( SPUnit const *unit ); |
2014 | - SPUnit const* getActiveUnit() const; |
2015 | - |
2016 | - void addAdjustment( GtkAdjustment* adj ); |
2017 | - void setFullVal( GtkAdjustment* adj, gdouble val ); |
2018 | - |
2019 | - GtkAction* createAction( gchar const* name, gchar const* label, gchar const* tooltip ); |
2020 | - |
2021 | -private: |
2022 | - static void _unitChangedCB( GtkAction* action, gpointer data ); |
2023 | - static void _actionFinalizedCB( gpointer data, GObject *where_the_object_was ); |
2024 | - static void _adjustmentFinalizedCB( gpointer data, GObject *where_the_object_was ); |
2025 | - void _setActive( gint index ); |
2026 | - void _fixupAdjustments( SPUnit const* oldUnit, SPUnit const *newUnit ); |
2027 | - void _actionFinalized( GObject *where_the_object_was ); |
2028 | - void _adjustmentFinalized( GObject *where_the_object_was ); |
2029 | - |
2030 | - gint _active; |
2031 | - bool _isUpdating; |
2032 | - SPUnit* _activeUnit; |
2033 | - GtkListStore* _store; |
2034 | - GSList* _unitList; |
2035 | - GSList* _actionList; |
2036 | - GSList* _adjList; |
2037 | - std::map <GtkAdjustment*, gdouble> _priorValues; |
2038 | -}; |
2039 | - |
2040 | -} |
2041 | - |
2042 | -#endif // SEEN_INKSCAPE_UNIT_TRACKER_H |
2043 | - |
2044 | -/* |
2045 | - Local Variables: |
2046 | - mode:c++ |
2047 | - c-file-style:"stroustrup" |
2048 | - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
2049 | - indent-tabs-mode:nil |
2050 | - fill-column:99 |
2051 | - End: |
2052 | -*/ |
2053 | -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
2054 | |
2055 | === removed file 'src/helper/units-test.h' |
2056 | --- src/helper/units-test.h 2010-11-17 02:12:56 +0000 |
2057 | +++ src/helper/units-test.h 1970-01-01 00:00:00 +0000 |
2058 | @@ -1,90 +0,0 @@ |
2059 | -#include <cxxtest/TestSuite.h> |
2060 | - |
2061 | -#include <helper/units.h> |
2062 | -#include <glibmm/i18n.h> |
2063 | -#include <math.h> |
2064 | - |
2065 | -class UnitsTest : public CxxTest::TestSuite { |
2066 | -public: |
2067 | - |
2068 | - UnitsTest() |
2069 | - { |
2070 | - } |
2071 | - virtual ~UnitsTest() {} |
2072 | - |
2073 | -// createSuite and destroySuite get us per-suite setup and teardown |
2074 | -// without us having to worry about static initialization order, etc. |
2075 | - static UnitsTest *createSuite() { return new UnitsTest(); } |
2076 | - static void destroySuite( UnitsTest *suite ) { delete suite; } |
2077 | - |
2078 | - void testConversions() |
2079 | - { |
2080 | - struct Case { double x; char const *abbr; double pts; } const tests[] = { |
2081 | - { 1.0, "pt", 1.0 }, |
2082 | - { 5.0, "pt", 5.0 }, |
2083 | - { 1.0, "in", 72.0 }, |
2084 | - { 2.0, "in", 144.0 }, |
2085 | - { 254., "mm", 720.0 }, |
2086 | - { 254., "cm", 7200. }, |
2087 | - { 254., "m", 720000. }, |
2088 | - { 1.5, "mm", (15 * 72. / 254) } |
2089 | - }; |
2090 | - for (unsigned i = 0; i < G_N_ELEMENTS(tests); ++i) { |
2091 | - Case const &c = tests[i]; |
2092 | - SPUnit const &unit = *sp_unit_get_by_abbreviation(N_(c.abbr)); |
2093 | - |
2094 | - double const calc_pts = sp_units_get_points(c.x, unit); |
2095 | - TS_ASSERT(approx_equal(calc_pts, c.pts)); |
2096 | - |
2097 | - double const calc_x = sp_points_get_units(c.pts, unit); |
2098 | - TS_ASSERT(approx_equal(calc_x, c.x)); |
2099 | - |
2100 | - double tmp = c.x; |
2101 | - bool const converted_to_pts = sp_convert_distance(&tmp, &unit, SP_PS_UNIT); |
2102 | - TS_ASSERT(converted_to_pts); |
2103 | - TS_ASSERT(approx_equal(tmp, c.pts)); |
2104 | - |
2105 | - tmp = c.pts; |
2106 | - bool const converted_from_pts = sp_convert_distance(&tmp, SP_PS_UNIT, &unit); |
2107 | - TS_ASSERT(converted_from_pts); |
2108 | - TS_ASSERT(approx_equal(tmp, c.x)); |
2109 | - } |
2110 | - } |
2111 | - |
2112 | - void testUnitTable() |
2113 | - { |
2114 | - TS_ASSERT(sp_units_table_sane()); |
2115 | - } |
2116 | - |
2117 | -private: |
2118 | - /* N.B. Wrongly returns false if both near 0. (Not a problem for current users.) */ |
2119 | - bool approx_equal(double const x, double const y) |
2120 | - { |
2121 | - return fabs(x / y - 1) < 1e-15; |
2122 | - } |
2123 | - |
2124 | - double sp_units_get_points(double const x, SPUnit const &unit) |
2125 | - { |
2126 | - SPUnit const &pt_unit = sp_unit_get_by_id(SP_UNIT_PT); |
2127 | - double const px = sp_units_get_pixels(x, unit); |
2128 | - return sp_pixels_get_units(px, pt_unit); |
2129 | - } |
2130 | - |
2131 | - double sp_points_get_units(double const pts, SPUnit const &unit) |
2132 | - { |
2133 | - SPUnit const &pt_unit = sp_unit_get_by_id(SP_UNIT_PT); |
2134 | - double const px = sp_units_get_pixels(pts, pt_unit); |
2135 | - return sp_pixels_get_units(px, unit); |
2136 | - } |
2137 | -}; |
2138 | - |
2139 | -/* |
2140 | - Local Variables: |
2141 | - mode:c++ |
2142 | - c-file-style:"stroustrup" |
2143 | - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
2144 | - indent-tabs-mode:nil |
2145 | - fill-column:99 |
2146 | - End: |
2147 | -*/ |
2148 | -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
2149 | |
2150 | === removed file 'src/helper/units.cpp' |
2151 | --- src/helper/units.cpp 2012-10-27 18:15:53 +0000 |
2152 | +++ src/helper/units.cpp 1970-01-01 00:00:00 +0000 |
2153 | @@ -1,261 +0,0 @@ |
2154 | -#define __SP_PAPER_C__ |
2155 | - |
2156 | -/* |
2157 | - * SPUnit |
2158 | - * |
2159 | - * Ported from libgnomeprint |
2160 | - * |
2161 | - * Authors: |
2162 | - * Dirk Luetjens <dirk@luedi.oche.de> |
2163 | - * Yves Arrouye <Yves.Arrouye@marin.fdn.fr> |
2164 | - * Lauris Kaplinski <lauris@ximian.com> |
2165 | - * bulia byak <buliabyak@users.sf.net> |
2166 | - * |
2167 | - * Copyright 1999-2001 Ximian, Inc. and authors |
2168 | - * |
2169 | - */ |
2170 | - |
2171 | -#ifdef HAVE_CONFIG_H |
2172 | -# include "config.h" |
2173 | -#endif |
2174 | - |
2175 | -#include "helper/units.h" |
2176 | -#include <glib.h> // g_assert() |
2177 | -#include <glibmm/i18n.h> |
2178 | -#include "unit-constants.h" |
2179 | -#include "svg/svg-length.h" |
2180 | - |
2181 | -/* todo: use some fancy unit program */ |
2182 | - |
2183 | -/* The order determines the order of the list returned by sp_unit_get_list. |
2184 | - * (It can also affect string lookups if there are any duplicates in the |
2185 | - * current locale... hopefully none.) If you re-order this list, then you must |
2186 | - * also re-order the SPUnitId enum values accordingly. Run `make check' (which |
2187 | - * calls sp_unit_table_sane) to ensure that the two are in sync. |
2188 | - */ |
2189 | -SPUnit const sp_units[] = { |
2190 | - {SP_UNIT_SCALE, SP_UNIT_DIMENSIONLESS, 1.0, SP_NONE, SVGLength::NONE, N_("Unit"), "", N_("Units"), ""}, |
2191 | - {SP_UNIT_PT, SP_UNIT_ABSOLUTE, PX_PER_PT, SP_PT, SVGLength::PT, N_("Point"), N_("pt"), N_("Points"), N_("Pt")}, |
2192 | - {SP_UNIT_PC, SP_UNIT_ABSOLUTE, PX_PER_PC, SP_PC, SVGLength::PC, N_("Pica"), N_("pc"), N_("Picas"), N_("Pc")}, |
2193 | - {SP_UNIT_PX, SP_UNIT_DEVICE, PX_PER_PX, SP_PX, SVGLength::PX, N_("Pixel"), N_("px"), N_("Pixels"), N_("Px")}, |
2194 | - /* You can add new elements from this point forward */ |
2195 | - {SP_UNIT_PERCENT, SP_UNIT_DIMENSIONLESS, 0.01, SP_NONE, SVGLength::PERCENT, N_("Percent"), N_("%"), N_("Percents"), N_("%")}, |
2196 | - {SP_UNIT_MM, SP_UNIT_ABSOLUTE, PX_PER_MM, SP_MM, SVGLength::MM, N_("Millimeter"), N_("mm"), N_("Millimeters"), N_("mm")}, |
2197 | - {SP_UNIT_CM, SP_UNIT_ABSOLUTE, PX_PER_CM, SP_CM, SVGLength::CM, N_("Centimeter"), N_("cm"), N_("Centimeters"), N_("cm")}, |
2198 | - {SP_UNIT_M, SP_UNIT_ABSOLUTE, PX_PER_M, SP_M, SVGLength::NONE, N_("Meter"), N_("m"), N_("Meters"), N_("m")}, // no svg_unit |
2199 | - {SP_UNIT_IN, SP_UNIT_ABSOLUTE, PX_PER_IN, SP_IN, SVGLength::INCH, N_("Inch"), N_("in"), N_("Inches"), N_("in")}, |
2200 | - {SP_UNIT_FT, SP_UNIT_ABSOLUTE, PX_PER_FT, SP_FT, SVGLength::FOOT, N_("Foot"), N_("ft"), N_("Feet"), N_("ft")}, |
2201 | - /* Volatiles do not have default, so there are none here */ |
2202 | - // TRANSLATORS: for info, see http://www.w3.org/TR/REC-CSS2/syndata.html#length-units |
2203 | - {SP_UNIT_EM, SP_UNIT_VOLATILE, 1.0, SP_NONE, SVGLength::EM, N_("Em square"), N_("em"), N_("Em squares"), N_("em")}, |
2204 | - // TRANSLATORS: for info, see http://www.w3.org/TR/REC-CSS2/syndata.html#length-units |
2205 | - {SP_UNIT_EX, SP_UNIT_VOLATILE, 1.0, SP_NONE, SVGLength::EX, N_("Ex square"), N_("ex"), N_("Ex squares"), N_("ex")}, |
2206 | -}; |
2207 | - |
2208 | -#define sp_num_units G_N_ELEMENTS(sp_units) |
2209 | - |
2210 | -SPUnit const * |
2211 | -sp_unit_get_by_abbreviation(gchar const *abbreviation) |
2212 | -{ |
2213 | - g_return_val_if_fail(abbreviation != NULL, NULL); |
2214 | - |
2215 | - for (unsigned i = 0 ; i < sp_num_units ; i++) { |
2216 | - if (!g_ascii_strcasecmp(abbreviation, sp_units[i].abbr)) return &sp_units[i]; |
2217 | - if (!g_ascii_strcasecmp(abbreviation, sp_units[i].abbr_plural)) return &sp_units[i]; |
2218 | - } |
2219 | - |
2220 | - return NULL; |
2221 | -} |
2222 | - |
2223 | -gchar const * |
2224 | -sp_unit_get_abbreviation(SPUnit const *unit) |
2225 | -{ |
2226 | - g_return_val_if_fail(unit != NULL, NULL); |
2227 | - |
2228 | - return unit->abbr; |
2229 | -} |
2230 | - |
2231 | -gchar const * |
2232 | -sp_unit_get_plural (SPUnit const *unit) |
2233 | -{ |
2234 | - g_return_val_if_fail(unit != NULL, NULL); |
2235 | - |
2236 | - return unit->plural; |
2237 | -} |
2238 | - |
2239 | -SPMetric sp_unit_get_metric(SPUnit const *unit) |
2240 | -{ |
2241 | - g_return_val_if_fail(unit != NULL, SP_NONE); |
2242 | - |
2243 | - return unit->metric; |
2244 | -} |
2245 | - |
2246 | -guint sp_unit_get_svg_unit(SPUnit const *unit) |
2247 | -{ |
2248 | - g_return_val_if_fail(unit != NULL, SP_NONE); |
2249 | - |
2250 | - return unit->svg_unit; |
2251 | -} |
2252 | - |
2253 | -GSList * |
2254 | -sp_unit_get_list(guint bases) |
2255 | -{ |
2256 | - g_return_val_if_fail((bases & ~SP_UNITS_ALL) == 0, NULL); |
2257 | - |
2258 | - GSList *units = NULL; |
2259 | - for (unsigned i = sp_num_units ; i--; ) { |
2260 | - if (bases & sp_units[i].base) { |
2261 | - units = g_slist_prepend(units, (gpointer) &sp_units[i]); |
2262 | - } |
2263 | - } |
2264 | - |
2265 | - return units; |
2266 | -} |
2267 | - |
2268 | -void |
2269 | -sp_unit_free_list(GSList *units) |
2270 | -{ |
2271 | - g_slist_free(units); |
2272 | -} |
2273 | - |
2274 | -/* These are pure utility */ |
2275 | -/* Return TRUE if conversion is possible */ |
2276 | -gboolean |
2277 | -sp_convert_distance(gdouble *distance, SPUnit const *from, SPUnit const *to) |
2278 | -{ |
2279 | - g_return_val_if_fail(distance != NULL, FALSE); |
2280 | - g_return_val_if_fail(from != NULL, FALSE); |
2281 | - g_return_val_if_fail(to != NULL, FALSE); |
2282 | - |
2283 | - if (from == to) return TRUE; |
2284 | - if ((from->base == SP_UNIT_DIMENSIONLESS) || (to->base == SP_UNIT_DIMENSIONLESS)) { |
2285 | - *distance = *distance * from->unittobase / to->unittobase; |
2286 | - return TRUE; |
2287 | - } |
2288 | - if ((from->base == SP_UNIT_VOLATILE) || (to->base == SP_UNIT_VOLATILE)) return FALSE; |
2289 | - |
2290 | - if ((from->base == to->base) |
2291 | - || ((from->base == SP_UNIT_DEVICE) && (to->base == SP_UNIT_ABSOLUTE)) |
2292 | - || ((from->base == SP_UNIT_ABSOLUTE) && (to->base == SP_UNIT_DEVICE))) |
2293 | - { |
2294 | - *distance = *distance * from->unittobase / to->unittobase; |
2295 | - return TRUE; |
2296 | - } |
2297 | - |
2298 | - return FALSE; |
2299 | -} |
2300 | - |
2301 | -/** @param devicetransform for device units. */ |
2302 | -/* TODO: Remove the ctmscale parameter given that we no longer have SP_UNIT_USERSPACE. */ |
2303 | -gdouble |
2304 | -sp_convert_distance_full(gdouble const from_dist, SPUnit const &from, SPUnit const &to) |
2305 | -{ |
2306 | - if (&from == &to) { |
2307 | - return from_dist; |
2308 | - } |
2309 | - if (from.base == to.base) { |
2310 | - gdouble ret = from_dist; |
2311 | - bool const succ = sp_convert_distance(&ret, &from, &to); |
2312 | - g_assert(succ); |
2313 | - return ret; |
2314 | - } |
2315 | - if ((from.base == SP_UNIT_DIMENSIONLESS) |
2316 | - || (to.base == SP_UNIT_DIMENSIONLESS)) |
2317 | - { |
2318 | - return from_dist * from.unittobase / to.unittobase; |
2319 | - } |
2320 | - g_return_val_if_fail(((from.base != SP_UNIT_VOLATILE) |
2321 | - && (to.base != SP_UNIT_VOLATILE)), |
2322 | - from_dist); |
2323 | - |
2324 | - gdouble absolute; |
2325 | - switch (from.base) { |
2326 | - case SP_UNIT_ABSOLUTE: |
2327 | - case SP_UNIT_DEVICE: |
2328 | - absolute = from_dist * from.unittobase; |
2329 | - break; |
2330 | - default: |
2331 | - g_warning("file %s: line %d: Illegal unit (base 0x%x)", __FILE__, __LINE__, from.base); |
2332 | - return from_dist; |
2333 | - } |
2334 | - |
2335 | - gdouble ret; |
2336 | - switch (to.base) { |
2337 | - default: |
2338 | - g_warning("file %s: line %d: Illegal unit (base 0x%x)", __FILE__, __LINE__, to.base); |
2339 | - /* FALL-THROUGH */ |
2340 | - case SP_UNIT_ABSOLUTE: |
2341 | - case SP_UNIT_DEVICE: |
2342 | - ret = absolute / to.unittobase; |
2343 | - break; |
2344 | - } |
2345 | - |
2346 | - return ret; |
2347 | -} |
2348 | - |
2349 | -/* Some more convenience */ |
2350 | - |
2351 | -gdouble |
2352 | -sp_units_get_pixels(gdouble const units, SPUnit const &unit) |
2353 | -{ |
2354 | - if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) { |
2355 | - return units * unit.unittobase; |
2356 | - } else { |
2357 | - g_warning("Different unit bases: No exact unit conversion available"); |
2358 | - return units * unit.unittobase; |
2359 | - } |
2360 | -} |
2361 | - |
2362 | -gdouble |
2363 | -sp_pixels_get_units(gdouble const pixels, SPUnit const &unit) |
2364 | -{ |
2365 | - if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) { |
2366 | - return pixels / unit.unittobase; |
2367 | - } else { |
2368 | - g_warning("Different unit bases: No exact unit conversion available"); |
2369 | - return pixels / unit.unittobase; |
2370 | - } |
2371 | -} |
2372 | - |
2373 | -bool |
2374 | -sp_units_table_sane() |
2375 | -{ |
2376 | - for (unsigned i = 0; i < G_N_ELEMENTS(sp_units); ++i) { |
2377 | - if (unsigned(sp_units[i].unit_id) != i) { |
2378 | - return false; |
2379 | - } |
2380 | - } |
2381 | - return true; |
2382 | -} |
2383 | - |
2384 | -/** Converts angle (in deg) to compass display */ |
2385 | -double |
2386 | -angle_to_compass(double angle) |
2387 | -{ |
2388 | - double ret = 90 - angle; |
2389 | - if (ret < 0) |
2390 | - ret = 360 + ret; |
2391 | - return ret; |
2392 | -} |
2393 | - |
2394 | -/** Converts angle (in deg) to compass display */ |
2395 | -double |
2396 | -angle_from_compass(double angle) |
2397 | -{ |
2398 | - double ret = 90 - angle; |
2399 | - if (ret > 180) |
2400 | - ret = ret - 180; |
2401 | - return ret; |
2402 | -} |
2403 | - |
2404 | - |
2405 | -/* |
2406 | - Local Variables: |
2407 | - mode:c++ |
2408 | - c-file-style:"stroustrup" |
2409 | - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
2410 | - indent-tabs-mode:nil |
2411 | - fill-column:99 |
2412 | - End: |
2413 | -*/ |
2414 | -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
2415 | |
2416 | === removed file 'src/helper/units.h' |
2417 | --- src/helper/units.h 2011-12-08 11:53:54 +0000 |
2418 | +++ src/helper/units.h 1970-01-01 00:00:00 +0000 |
2419 | @@ -1,146 +0,0 @@ |
2420 | -#ifndef __SP_UNIT_H__ |
2421 | -#define __SP_UNIT_H__ |
2422 | - |
2423 | -/* |
2424 | - * SPUnit |
2425 | - * |
2426 | - * Ported from libgnomeprint |
2427 | - * |
2428 | - * Authors: |
2429 | - * Dirk Luetjens <dirk@luedi.oche.de> |
2430 | - * Yves Arrouye <Yves.Arrouye@marin.fdn.fr> |
2431 | - * Lauris Kaplinski <lauris@ximian.com> |
2432 | - * |
2433 | - * Copyright 1999-2001 Ximian, Inc. and authors |
2434 | - * |
2435 | - */ |
2436 | - |
2437 | -#include <glib.h> |
2438 | -#include "sp-metric.h" |
2439 | - |
2440 | - |
2441 | -/* |
2442 | - * Units and conversion methods used by libgnomeprint. |
2443 | - * |
2444 | - * You need those for certain config keys (like paper size), if you are |
2445 | - * interested in using these (look at gnome-print-config.h for discussion, |
2446 | - * why you may NOT be interested in paper size). |
2447 | - * |
2448 | - * Unit bases define set of mutually unrelated measuring systems (numbers, |
2449 | - * paper, screen and dimesionless user coordinates). Still, you can convert |
2450 | - * between those, specifying scaling factors explicitly. |
2451 | - * |
2452 | - * Paper (i.e. output) coordinates are taken as absolute real world units. |
2453 | - * It has some justification, because screen unit (pixel) size changes, |
2454 | - * if you change screen resolution, while you cannot change output on paper |
2455 | - * as easily (unless you have thermally contracting paper, of course). |
2456 | - * |
2457 | - */ |
2458 | - |
2459 | -struct SPUnit; |
2460 | -struct SPDistance; |
2461 | - |
2462 | -/* |
2463 | - * The base linear ("absolute") unit is 1/72th of an inch, i.e. the base unit of postscript. |
2464 | - */ |
2465 | - |
2466 | -/* |
2467 | - * Unit bases |
2468 | - */ |
2469 | -enum SPUnitBase { |
2470 | - SP_UNIT_DIMENSIONLESS = (1 << 0), /* For percentages and like */ |
2471 | - SP_UNIT_ABSOLUTE = (1 << 1), /* Real world distances - i.e. mm, cm... */ |
2472 | - SP_UNIT_DEVICE = (1 << 2), /* Pixels in the SVG/CSS sense. */ |
2473 | - SP_UNIT_VOLATILE = (1 << 3) /* em and ex */ |
2474 | -}; |
2475 | - |
2476 | -/* |
2477 | - * Units: indexes into sp_units. |
2478 | - */ |
2479 | -enum SPUnitId { |
2480 | - SP_UNIT_SCALE, // 1.0 == 100% |
2481 | - SP_UNIT_PT, // Postscript points: exactly 72 per inch |
2482 | - SP_UNIT_PC, // Pica; there are 12 points per pica |
2483 | - SP_UNIT_PX, // "Pixels" in the CSS sense; though Inkscape assumes a constant 90 per inch. |
2484 | - SP_UNIT_PERCENT, /* Note: In Inkscape this often means "relative to current value" (for |
2485 | - users to edit a value), rather than the SVG/CSS use of percentages. */ |
2486 | - SP_UNIT_MM, // millimetres |
2487 | - SP_UNIT_CM, // centimetres |
2488 | - SP_UNIT_M, // metres |
2489 | - SP_UNIT_IN, // inches |
2490 | - SP_UNIT_FT, // foot |
2491 | - SP_UNIT_EM, // font-size of relevant font |
2492 | - SP_UNIT_EX, // x-height of relevant font |
2493 | - sp_max_unit_id = SP_UNIT_EX // For bounds-checking in sp_unit_get_by_id. |
2494 | -}; |
2495 | - |
2496 | -/* |
2497 | - * Notice, that for correct menus etc. you have to use |
2498 | - * ngettext method family yourself. For that reason we |
2499 | - * do not provide translations in unit names. |
2500 | - * I also do not know, whether to allow user-created units, |
2501 | - * because this would certainly confuse textdomain. |
2502 | - */ |
2503 | - |
2504 | -struct SPUnit { |
2505 | - SPUnitId unit_id; /* used as sanity check */ |
2506 | - SPUnitBase base; |
2507 | - gdouble unittobase; /* how many base units in this unit */ |
2508 | - SPMetric metric; // the corresponding SPMetric from sp-metrics.h |
2509 | - guint svg_unit; // the corresponding SVGLengthUnit |
2510 | - |
2511 | - /* When using, you must call "gettext" on them so they're translated */ |
2512 | - gchar const *name; |
2513 | - gchar const *abbr; |
2514 | - gchar const *plural; |
2515 | - gchar const *abbr_plural; |
2516 | -}; |
2517 | - |
2518 | -const SPUnit *sp_unit_get_by_abbreviation (const gchar *abbreviation); |
2519 | -/* When using, you must call "gettext" on them so they're translated */ |
2520 | -const gchar *sp_unit_get_abbreviation (const SPUnit *unit); |
2521 | -gchar const *sp_unit_get_plural (SPUnit const *unit); |
2522 | - |
2523 | -SPMetric sp_unit_get_metric(SPUnit const *unit); |
2524 | -guint sp_unit_get_svg_unit(SPUnit const *unit); |
2525 | - |
2526 | -extern SPUnit const sp_units[]; |
2527 | - |
2528 | -inline SPUnit const & |
2529 | -sp_unit_get_by_id(SPUnitId const id) |
2530 | -{ |
2531 | - /* inline because the compiler should optimize away the g_return_val_if_fail test in the |
2532 | - usual case that the argument value is known at compile-time, leaving just |
2533 | - "return sp_units[constant]". */ |
2534 | - unsigned const ix = unsigned(id); |
2535 | - g_return_val_if_fail(ix <= sp_max_unit_id, sp_units[SP_UNIT_PX]); |
2536 | - return sp_units[ix]; |
2537 | -} |
2538 | - |
2539 | -#define SP_PS_UNIT (&sp_unit_get_by_id(SP_UNIT_PT)) |
2540 | - |
2541 | - |
2542 | -/** Used solely by units-test.cpp. */ |
2543 | -bool sp_units_table_sane(); |
2544 | - |
2545 | -#define SP_UNITS_ALL (SP_UNIT_DIMENSIONLESS | SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE | SP_UNIT_VOLATILE) |
2546 | - |
2547 | -GSList *sp_unit_get_list (guint bases); |
2548 | -void sp_unit_free_list (GSList *units); |
2549 | - |
2550 | -/* These are pure utility */ |
2551 | -/* Return TRUE if conversion is possible, FALSE if unit bases differ */ |
2552 | -gboolean sp_convert_distance (gdouble *distance, const SPUnit *from, const SPUnit *to); |
2553 | - |
2554 | -/* If either one is NULL, transconverting to/from that base fails */ |
2555 | -/* Generic conversion between volatile units would be useless anyways */ |
2556 | -gdouble sp_convert_distance_full(gdouble const from_dist, SPUnit const &from, SPUnit const &to); |
2557 | - |
2558 | -/* Some more convenience */ |
2559 | -gdouble sp_units_get_pixels(gdouble const units, SPUnit const &unit); |
2560 | -gdouble sp_pixels_get_units(gdouble const pixels, SPUnit const &unit); |
2561 | - |
2562 | -double angle_to_compass(double angle); |
2563 | -double angle_from_compass(double angle); |
2564 | - |
2565 | -#endif |
2566 | |
2567 | === modified file 'src/live_effects/lpe-path_length.cpp' |
2568 | --- src/live_effects/lpe-path_length.cpp 2012-10-21 18:04:54 +0000 |
2569 | +++ src/live_effects/lpe-path_length.cpp 2013-08-06 18:46:25 +0000 |
2570 | @@ -14,7 +14,7 @@ |
2571 | #include <glibmm/i18n.h> |
2572 | |
2573 | #include "live_effects/lpe-path_length.h" |
2574 | -#include "sp-metrics.h" |
2575 | +#include "util/units.h" |
2576 | |
2577 | #include "2geom/sbasis-geometric.h" |
2578 | |
2579 | @@ -52,11 +52,11 @@ |
2580 | |
2581 | /* convert the measured length to the correct unit ... */ |
2582 | double lengthval = Geom::length(pwd2_in) * scale; |
2583 | - gboolean success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), unit); |
2584 | + lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit.get_abbreviation()); |
2585 | |
2586 | /* ... set it as the canvas text ... */ |
2587 | gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, |
2588 | - display_unit ? (success ? unit.get_abbreviation() : "px") : ""); |
2589 | + display_unit ? unit.get_abbreviation() : ""); |
2590 | info_text.param_setValue(arc_length); |
2591 | g_free(arc_length); |
2592 | |
2593 | |
2594 | === modified file 'src/live_effects/lpe-ruler.cpp' |
2595 | --- src/live_effects/lpe-ruler.cpp 2013-03-13 17:30:15 +0000 |
2596 | +++ src/live_effects/lpe-ruler.cpp 2013-08-06 18:46:25 +0000 |
2597 | @@ -81,9 +81,9 @@ |
2598 | using namespace Geom; |
2599 | |
2600 | double real_mark_length = mark_length; |
2601 | - sp_convert_distance(&real_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX)); |
2602 | + real_mark_length = Inkscape::Util::Quantity::convert(real_mark_length, unit.get_abbreviation(), "px"); |
2603 | double real_minor_mark_length = minor_mark_length; |
2604 | - sp_convert_distance(&real_minor_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX)); |
2605 | + real_minor_mark_length = Inkscape::Util::Quantity::convert(real_minor_mark_length, unit.get_abbreviation(), "px"); |
2606 | |
2607 | n_major = real_mark_length * n; |
2608 | n_minor = real_minor_mark_length * n; |
2609 | @@ -133,10 +133,10 @@ |
2610 | std::vector<double> s_cuts; |
2611 | |
2612 | double real_mark_distance = mark_distance; |
2613 | - sp_convert_distance(&real_mark_distance, unit, &sp_unit_get_by_id(SP_UNIT_PX)); |
2614 | + real_mark_distance = Inkscape::Util::Quantity::convert(real_mark_distance, unit.get_abbreviation(), "px"); |
2615 | |
2616 | double real_offset = offset; |
2617 | - sp_convert_distance(&real_offset, unit, &sp_unit_get_by_id(SP_UNIT_PX)); |
2618 | + real_offset = Inkscape::Util::Quantity::convert(real_offset, unit.get_abbreviation(), "px"); |
2619 | for (double s = real_offset; s<totlength; s+=real_mark_distance){ |
2620 | s_cuts.push_back(s); |
2621 | } |
2622 | |
2623 | === modified file 'src/live_effects/parameter/unit.cpp' |
2624 | --- src/live_effects/parameter/unit.cpp 2013-03-25 17:42:31 +0000 |
2625 | +++ src/live_effects/parameter/unit.cpp 2013-08-06 18:46:25 +0000 |
2626 | @@ -10,6 +10,9 @@ |
2627 | #include "live_effects/parameter/unit.h" |
2628 | #include "live_effects/effect.h" |
2629 | #include "verbs.h" |
2630 | +#include "util/units.h" |
2631 | + |
2632 | +using Inkscape::Util::unit_table; |
2633 | |
2634 | namespace Inkscape { |
2635 | |
2636 | @@ -18,10 +21,10 @@ |
2637 | |
2638 | UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip, |
2639 | const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, |
2640 | - Effect* effect, SPUnitId default_value) |
2641 | + Effect* effect, Glib::ustring default_unit) |
2642 | : Parameter(label, tip, key, wr, effect) |
2643 | { |
2644 | - defunit = &sp_unit_get_by_id(default_value);; |
2645 | + defunit = new Inkscape::Util::Unit(unit_table.getUnit(default_unit)); |
2646 | unit = defunit; |
2647 | } |
2648 | |
2649 | @@ -32,9 +35,8 @@ |
2650 | bool |
2651 | UnitParam::param_readSVGValue(const gchar * strvalue) |
2652 | { |
2653 | - SPUnit const *newval = sp_unit_get_by_abbreviation(strvalue); |
2654 | - if (newval) { |
2655 | - param_set_value(newval); |
2656 | + if (strvalue) { |
2657 | + param_set_value(unit_table.getUnit(strvalue)); |
2658 | return true; |
2659 | } |
2660 | return false; |
2661 | @@ -43,25 +45,25 @@ |
2662 | gchar * |
2663 | UnitParam::param_getSVGValue() const |
2664 | { |
2665 | - return g_strdup(sp_unit_get_abbreviation(unit)); |
2666 | + return g_strdup(unit->abbr.c_str()); |
2667 | } |
2668 | |
2669 | void |
2670 | UnitParam::param_set_default() |
2671 | { |
2672 | - param_set_value(defunit); |
2673 | + param_set_value(*defunit); |
2674 | } |
2675 | |
2676 | void |
2677 | -UnitParam::param_set_value(SPUnit const *val) |
2678 | +UnitParam::param_set_value(Inkscape::Util::Unit const &val) |
2679 | { |
2680 | - unit = val; |
2681 | + unit = new Inkscape::Util::Unit(val); |
2682 | } |
2683 | |
2684 | const gchar * |
2685 | UnitParam::get_abbreviation() const |
2686 | { |
2687 | - return sp_unit_get_abbreviation(unit); |
2688 | + return unit->abbr.c_str(); |
2689 | } |
2690 | |
2691 | Gtk::Widget * |
2692 | @@ -74,7 +76,7 @@ |
2693 | param_effect->getRepr(), |
2694 | param_effect->getSPDoc())); |
2695 | |
2696 | - unit_menu->setUnit(unit); |
2697 | + unit_menu->setUnit(unit->abbr); |
2698 | unit_menu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change unit parameter")); |
2699 | |
2700 | return dynamic_cast<Gtk::Widget *> (unit_menu); |
2701 | |
2702 | === modified file 'src/live_effects/parameter/unit.h' |
2703 | --- src/live_effects/parameter/unit.h 2013-01-17 18:23:15 +0000 |
2704 | +++ src/live_effects/parameter/unit.h 2013-08-06 18:46:25 +0000 |
2705 | @@ -10,10 +10,13 @@ |
2706 | */ |
2707 | |
2708 | #include "live_effects/parameter/parameter.h" |
2709 | -#include <helper/units.h> |
2710 | |
2711 | namespace Inkscape { |
2712 | |
2713 | +namespace Util { |
2714 | + class Unit; |
2715 | +} |
2716 | + |
2717 | namespace LivePathEffect { |
2718 | |
2719 | class UnitParam : public Parameter { |
2720 | @@ -23,22 +26,22 @@ |
2721 | const Glib::ustring& key, |
2722 | Inkscape::UI::Widget::Registry* wr, |
2723 | Effect* effect, |
2724 | - SPUnitId default_value = SP_UNIT_PX); |
2725 | + Glib::ustring default_unit = "px"); |
2726 | virtual ~UnitParam(); |
2727 | |
2728 | virtual bool param_readSVGValue(const gchar * strvalue); |
2729 | virtual gchar * param_getSVGValue() const; |
2730 | virtual void param_set_default(); |
2731 | - void param_set_value(SPUnit const *val); |
2732 | + void param_set_value(Inkscape::Util::Unit const &val); |
2733 | const gchar *get_abbreviation() const; |
2734 | |
2735 | virtual Gtk::Widget * param_newWidget(); |
2736 | |
2737 | - operator SPUnit const *() const { return unit; } |
2738 | + operator Inkscape::Util::Unit const *() const { return unit; } |
2739 | |
2740 | private: |
2741 | - SPUnit const *unit; |
2742 | - SPUnit const *defunit; |
2743 | + Inkscape::Util::Unit const *unit; |
2744 | + Inkscape::Util::Unit const *defunit; |
2745 | |
2746 | UnitParam(const UnitParam&); |
2747 | UnitParam& operator=(const UnitParam&); |
2748 | |
2749 | === modified file 'src/lpe-tool-context.cpp' |
2750 | --- src/lpe-tool-context.cpp 2013-08-03 21:30:12 +0000 |
2751 | +++ src/lpe-tool-context.cpp 2013-08-06 18:46:25 +0000 |
2752 | @@ -37,10 +37,12 @@ |
2753 | #include "display/canvas-text.h" |
2754 | #include "message-stack.h" |
2755 | #include "sp-path.h" |
2756 | -#include "helper/units.h" |
2757 | +#include "util/units.h" |
2758 | |
2759 | #include "lpe-tool-context.h" |
2760 | |
2761 | +using Inkscape::Util::unit_table; |
2762 | + |
2763 | static void sp_lpetool_context_dispose(GObject *object); |
2764 | |
2765 | static void sp_lpetool_context_setup(SPEventContext *ec); |
2766 | @@ -453,13 +455,17 @@ |
2767 | if (!show) |
2768 | sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text)); |
2769 | |
2770 | - SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX)); |
2771 | - SPUnit unit = sp_unit_get_by_id(unitid); |
2772 | + Inkscape::Util::Unit unit; |
2773 | + if (prefs->getString("/tools/lpetool/unit").compare("")) { |
2774 | + unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit")); |
2775 | + } else { |
2776 | + unit = unit_table.getUnit("px"); |
2777 | + } |
2778 | |
2779 | lengthval = Geom::length(pwd2); |
2780 | gboolean success; |
2781 | - success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); |
2782 | - arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px"); |
2783 | + lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit); |
2784 | + arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str()); |
2785 | sp_canvastext_set_text (canvas_text, arc_length); |
2786 | set_pos_and_anchor(canvas_text, pwd2, 0.5, 10); |
2787 | // TODO: must we free arc_length? |
2788 | @@ -489,12 +495,27 @@ |
2789 | SPPath *path = i->first; |
2790 | SPCurve *curve = SP_SHAPE(path)->getCurve(); |
2791 | Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = Geom::paths_to_pw(curve->get_pathvector()); |
2792 | +<<<<<<< TREE |
2793 | SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX)); |
2794 | SPUnit unit = sp_unit_get_by_id(unitid); |
2795 | double lengthval = Geom::length(pwd2); |
2796 | +======= |
2797 | + Inkscape::Util::Unit unit; |
2798 | + if (prefs->getString("/tools/lpetool/unit").compare("")) { |
2799 | + unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit")); |
2800 | + } else { |
2801 | + unit = unit_table.getUnit("px"); |
2802 | + } |
2803 | + lengthval = Geom::length(pwd2); |
2804 | +>>>>>>> MERGE-SOURCE |
2805 | gboolean success; |
2806 | +<<<<<<< TREE |
2807 | success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); |
2808 | gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px"); |
2809 | +======= |
2810 | + lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit); |
2811 | + arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str()); |
2812 | +>>>>>>> MERGE-SOURCE |
2813 | sp_canvastext_set_text (SP_CANVASTEXT(i->second), arc_length); |
2814 | set_pos_and_anchor(SP_CANVASTEXT(i->second), pwd2, 0.5, 10); |
2815 | // TODO: must we free arc_length? |
2816 | |
2817 | === modified file 'src/lpe-tool-context.h' |
2818 | --- src/lpe-tool-context.h 2013-03-14 23:24:17 +0000 |
2819 | +++ src/lpe-tool-context.h 2013-08-06 18:46:25 +0000 |
2820 | @@ -16,7 +16,6 @@ |
2821 | */ |
2822 | |
2823 | #include "pen-context.h" |
2824 | -#include "helper/units.h" |
2825 | |
2826 | #define SP_TYPE_LPETOOL_CONTEXT (sp_lpetool_context_get_type()) |
2827 | #define SP_LPETOOL_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_LPETOOL_CONTEXT, SPLPEToolContext)) |
2828 | |
2829 | === modified file 'src/main.cpp' |
2830 | --- src/main.cpp 2013-07-17 11:42:40 +0000 |
2831 | +++ src/main.cpp 2013-08-06 18:46:25 +0000 |
2832 | @@ -68,7 +68,6 @@ |
2833 | #include "color.h" |
2834 | #include "sp-item.h" |
2835 | #include "sp-root.h" |
2836 | -#include "unit-constants.h" |
2837 | |
2838 | #include "svg/svg.h" |
2839 | #include "svg/svg-color.h" |
2840 | @@ -1524,7 +1523,7 @@ |
2841 | |
2842 | // default dpi |
2843 | if (dpi == 0.0) { |
2844 | - dpi = PX_PER_IN; |
2845 | + dpi = Inkscape::Util::Quantity::convert(1, "in", "px"); |
2846 | } |
2847 | |
2848 | unsigned long int width = 0; |
2849 | @@ -1537,7 +1536,7 @@ |
2850 | g_warning("Export width %lu out of range (1 - %lu). Nothing exported.", width, (unsigned long int)PNG_UINT_31_MAX); |
2851 | return 1; |
2852 | } |
2853 | - dpi = (gdouble) width * PX_PER_IN / area.width(); |
2854 | + dpi = (gdouble) width * Inkscape::Util::Quantity::convert(1, "in", "px") / area.width(); |
2855 | } |
2856 | |
2857 | if (sp_export_height) { |
2858 | @@ -1547,15 +1546,15 @@ |
2859 | g_warning("Export height %lu out of range (1 - %lu). Nothing exported.", height, (unsigned long int)PNG_UINT_31_MAX); |
2860 | return 1; |
2861 | } |
2862 | - dpi = (gdouble) height * PX_PER_IN / area.height(); |
2863 | + dpi = (gdouble) height * Inkscape::Util::Quantity::convert(1, "in", "px") / area.height(); |
2864 | } |
2865 | |
2866 | if (!sp_export_width) { |
2867 | - width = (unsigned long int) (area.width() * dpi / PX_PER_IN + 0.5); |
2868 | + width = (unsigned long int) (area.width() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); |
2869 | } |
2870 | |
2871 | if (!sp_export_height) { |
2872 | - height = (unsigned long int) (area.height() * dpi / PX_PER_IN + 0.5); |
2873 | + height = (unsigned long int) (area.height() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); |
2874 | } |
2875 | |
2876 | guint32 bgcolor = 0x00000000; |
2877 | |
2878 | === modified file 'src/measure-context.cpp' |
2879 | --- src/measure-context.cpp 2013-08-03 21:30:12 +0000 |
2880 | +++ src/measure-context.cpp 2013-08-06 18:46:25 +0000 |
2881 | @@ -13,7 +13,7 @@ |
2882 | |
2883 | #include <gdk/gdkkeysyms.h> |
2884 | #include <boost/none_t.hpp> |
2885 | -#include "helper/units.h" |
2886 | +#include "util/units.h" |
2887 | #include "macros.h" |
2888 | #include "display/curve.h" |
2889 | #include "sp-shape.h" |
2890 | @@ -46,6 +46,7 @@ |
2891 | |
2892 | using Inkscape::ControlManager; |
2893 | using Inkscape::CTLINE_SECONDARY; |
2894 | +using Inkscape::Util::unit_table; |
2895 | |
2896 | static void sp_measure_context_setup(SPEventContext *ec); |
2897 | static void sp_measure_context_finish(SPEventContext *ec); |
2898 | @@ -514,8 +515,10 @@ |
2899 | std::sort(intersections.begin(), intersections.end(), GeomPointSortPredicate); |
2900 | } |
2901 | |
2902 | - SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/measure/unitid", SP_UNIT_PX)); |
2903 | - SPUnit unit = sp_unit_get_by_id(unitid); |
2904 | + Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); |
2905 | + if (!unit_name.compare("")) { |
2906 | + unit_name = "px"; |
2907 | + } |
2908 | |
2909 | double fontsize = prefs->getInt("/tools/measure/fontsize"); |
2910 | |
2911 | @@ -526,7 +529,7 @@ |
2912 | for (size_t idx = 1; idx < intersections.size(); ++idx) { |
2913 | LabelPlacement placement; |
2914 | placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length(); |
2915 | - sp_convert_distance(&placement.lengthVal, &sp_unit_get_by_id(SP_UNIT_PX), &unit); |
2916 | + placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, "px", unit_name); |
2917 | placement.offset = DIMENSION_OFFSET; |
2918 | placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 ); |
2919 | placement.end = placement.start - (normal * placement.offset); |
2920 | @@ -542,7 +545,7 @@ |
2921 | LabelPlacement &place = *it; |
2922 | |
2923 | // TODO cleanup memory, Glib::ustring, etc.: |
2924 | - gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit.abbr); |
2925 | + gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit_name.c_str()); |
2926 | SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), |
2927 | desktop, |
2928 | place.end, |
2929 | @@ -583,10 +586,10 @@ |
2930 | |
2931 | { |
2932 | double totallengthval = (end_point - start_point).length(); |
2933 | - sp_convert_distance(&totallengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); |
2934 | + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); |
2935 | |
2936 | // TODO cleanup memory, Glib::ustring, etc.: |
2937 | - gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr); |
2938 | + gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); |
2939 | SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), |
2940 | desktop, |
2941 | end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), |
2942 | @@ -604,10 +607,10 @@ |
2943 | |
2944 | if (intersections.size() > 2) { |
2945 | double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length(); |
2946 | - sp_convert_distance(&totallengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); |
2947 | + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); |
2948 | |
2949 | // TODO cleanup memory, Glib::ustring, etc.: |
2950 | - gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr); |
2951 | + gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); |
2952 | SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), |
2953 | desktop, |
2954 | desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60, |
2955 | |
2956 | === modified file 'src/pen-context.cpp' |
2957 | --- src/pen-context.cpp 2013-04-28 22:48:03 +0000 |
2958 | +++ src/pen-context.cpp 2013-08-06 18:46:25 +0000 |
2959 | @@ -22,7 +22,6 @@ |
2960 | |
2961 | #include "pen-context.h" |
2962 | #include "sp-namedview.h" |
2963 | -#include "sp-metrics.h" |
2964 | #include "desktop.h" |
2965 | #include "desktop-handles.h" |
2966 | #include "selection.h" |
2967 | @@ -39,7 +38,6 @@ |
2968 | #include "display/sp-ctrlline.h" |
2969 | #include "display/sodipodi-ctrl.h" |
2970 | #include <glibmm/i18n.h> |
2971 | -#include "helper/units.h" |
2972 | #include "macros.h" |
2973 | #include "context-fns.h" |
2974 | #include "tools-switch.h" |
2975 | @@ -1185,11 +1183,16 @@ |
2976 | |
2977 | SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop; |
2978 | Geom::Point rel = p - pc->p[pc_point_to_compare]; |
2979 | - GString *dist = SP_PX_TO_METRIC_STRING(Geom::L2(rel), desktop->namedview->getDefaultMetric()); |
2980 | + Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px"); |
2981 | + GString *dist = g_string_new(q.string(*desktop->namedview->doc_units).c_str()); |
2982 | double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI; |
2983 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
2984 | - if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) |
2985 | - angle = angle_to_compass (angle); |
2986 | + if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) { |
2987 | + angle = 90 - angle; |
2988 | + if (angle < 0) { |
2989 | + angle += 360; |
2990 | + } |
2991 | + } |
2992 | |
2993 | pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str); |
2994 | g_string_free(dist, FALSE); |
2995 | |
2996 | === modified file 'src/preferences.cpp' |
2997 | --- src/preferences.cpp 2013-02-11 23:34:59 +0000 |
2998 | +++ src/preferences.cpp 2013-08-06 18:46:25 +0000 |
2999 | @@ -28,6 +28,8 @@ |
3000 | |
3001 | #define PREFERENCES_FILE_NAME "preferences.xml" |
3002 | |
3003 | +using Inkscape::Util::unit_table; |
3004 | + |
3005 | namespace Inkscape { |
3006 | |
3007 | static Inkscape::XML::Document *loadImpl( std::string const& prefsFilename, Glib::ustring & errMsg ); |
3008 | @@ -777,8 +779,6 @@ |
3009 | |
3010 | double Preferences::_extractDouble(Entry const &v, Glib::ustring const &requested_unit) |
3011 | { |
3012 | - static Inkscape::Util::UnitTable unit_table; // load the unit_table once by making it static |
3013 | - |
3014 | double val = _extractDouble(v); |
3015 | Glib::ustring unit = _extractUnit(v); |
3016 | |
3017 | |
3018 | === modified file 'src/rect-context.cpp' |
3019 | --- src/rect-context.cpp 2013-04-28 22:48:03 +0000 |
3020 | +++ src/rect-context.cpp 2013-08-06 18:46:25 +0000 |
3021 | @@ -35,7 +35,6 @@ |
3022 | #include "message-context.h" |
3023 | #include "pixmaps/cursor-rect.xpm" |
3024 | #include "rect-context.h" |
3025 | -#include "sp-metrics.h" |
3026 | #include <glibmm/i18n.h> |
3027 | #include "xml/repr.h" |
3028 | #include "xml/node-event-vector.h" |
3029 | @@ -483,8 +482,10 @@ |
3030 | // status text |
3031 | double rdimx = r.dimensions()[Geom::X]; |
3032 | double rdimy = r.dimensions()[Geom::Y]; |
3033 | - GString *xs = SP_PX_TO_METRIC_STRING(rdimx, desktop->namedview->getDefaultMetric()); |
3034 | - GString *ys = SP_PX_TO_METRIC_STRING(rdimy, desktop->namedview->getDefaultMetric()); |
3035 | + Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px"); |
3036 | + Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px"); |
3037 | + GString *xs = g_string_new(rdimx_q.string(*desktop->namedview->doc_units).c_str()); |
3038 | + GString *ys = g_string_new(rdimy_q.string(*desktop->namedview->doc_units).c_str()); |
3039 | if (state & GDK_CONTROL_MASK) { |
3040 | int ratio_x, ratio_y; |
3041 | bool is_golden_ratio = false; |
3042 | |
3043 | === modified file 'src/selection-chemistry.cpp' |
3044 | --- src/selection-chemistry.cpp 2013-07-04 14:01:44 +0000 |
3045 | +++ src/selection-chemistry.cpp 2013-08-06 18:46:25 +0000 |
3046 | @@ -86,11 +86,10 @@ |
3047 | #include <map> |
3048 | #include <cstring> |
3049 | #include <string> |
3050 | -#include "helper/units.h" |
3051 | #include "sp-item.h" |
3052 | #include "box3d.h" |
3053 | #include "persp3d.h" |
3054 | -#include "unit-constants.h" |
3055 | +#include "util/units.h" |
3056 | #include "xml/simple-document.h" |
3057 | #include "sp-filter-reference.h" |
3058 | #include "gradient-drag.h" |
3059 | @@ -3398,7 +3397,7 @@ |
3060 | res = prefs_res; |
3061 | } else if (0 < prefs_min) { |
3062 | // If minsize is given, look up minimum bitmap size (default 250 pixels) and calculate resolution from it |
3063 | - res = PX_PER_IN * prefs_min / MIN(bbox->width(), bbox->height()); |
3064 | + res = Inkscape::Util::Quantity::convert(1, "in", "px") * prefs_min / MIN(bbox->width(), bbox->height()); |
3065 | } else { |
3066 | float hint_xdpi = 0, hint_ydpi = 0; |
3067 | Glib::ustring hint_filename; |
3068 | @@ -3413,14 +3412,14 @@ |
3069 | res = hint_xdpi; |
3070 | } else { |
3071 | // if all else fails, take the default 90 dpi |
3072 | - res = PX_PER_IN; |
3073 | + res = Inkscape::Util::Quantity::convert(1, "in", "px"); |
3074 | } |
3075 | } |
3076 | } |
3077 | |
3078 | // The width and height of the bitmap in pixels |
3079 | - unsigned width = (unsigned) floor(bbox->width() * res / PX_PER_IN); |
3080 | - unsigned height =(unsigned) floor(bbox->height() * res / PX_PER_IN); |
3081 | + unsigned width = (unsigned) floor(bbox->width() * res / Inkscape::Util::Quantity::convert(1, "in", "px")); |
3082 | + unsigned height =(unsigned) floor(bbox->height() * res / Inkscape::Util::Quantity::convert(1, "in", "px")); |
3083 | |
3084 | // Find out if we have to run an external filter |
3085 | gchar const *run = NULL; |
3086 | @@ -3452,7 +3451,7 @@ |
3087 | |
3088 | double shift_x = bbox->min()[Geom::X]; |
3089 | double shift_y = bbox->max()[Geom::Y]; |
3090 | - if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid |
3091 | + if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { // for default 90 dpi, snap it to pixel grid |
3092 | shift_x = round(shift_x); |
3093 | shift_y = -round(-shift_y); // this gets correct rounding despite coordinate inversion, remove the negations when the inversion is gone |
3094 | } |
3095 | @@ -3485,7 +3484,7 @@ |
3096 | // Create the repr for the image |
3097 | Inkscape::XML::Node * repr = xml_doc->createElement("svg:image"); |
3098 | sp_embed_image(repr, pb, "image/png"); |
3099 | - if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid |
3100 | + if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { // for default 90 dpi, snap it to pixel grid |
3101 | sp_repr_set_svg_double(repr, "width", width); |
3102 | sp_repr_set_svg_double(repr, "height", height); |
3103 | } else { |
3104 | |
3105 | === modified file 'src/seltrans.cpp' |
3106 | --- src/seltrans.cpp 2013-07-03 16:59:04 +0000 |
3107 | +++ src/seltrans.cpp 2013-08-06 18:46:25 +0000 |
3108 | @@ -37,7 +37,6 @@ |
3109 | #include "seltrans-handles.h" |
3110 | #include "seltrans.h" |
3111 | #include "selection-chemistry.h" |
3112 | -#include "sp-metrics.h" |
3113 | #include "verbs.h" |
3114 | #include <glibmm/i18n.h> |
3115 | #include "display/sp-ctrlline.h" |
3116 | @@ -1273,8 +1272,10 @@ |
3117 | m.unSetup(); |
3118 | |
3119 | // status text |
3120 | - GString *xs = SP_PX_TO_METRIC_STRING(pt[Geom::X], _desktop->namedview->getDefaultMetric()); |
3121 | - GString *ys = SP_PX_TO_METRIC_STRING(pt[Geom::Y], _desktop->namedview->getDefaultMetric()); |
3122 | + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(pt[Geom::X], "px"); |
3123 | + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(pt[Geom::Y], "px"); |
3124 | + GString *xs = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str()); |
3125 | + GString *ys = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str()); |
3126 | _message_context.setF(Inkscape::NORMAL_MESSAGE, _("Move <b>center</b> to %s, %s"), xs->str, ys->str); |
3127 | g_string_free(xs, FALSE); |
3128 | g_string_free(ys, FALSE); |
3129 | @@ -1425,8 +1426,10 @@ |
3130 | transform(move, norm); |
3131 | |
3132 | // status text |
3133 | - GString *xs = SP_PX_TO_METRIC_STRING(dxy[Geom::X], _desktop->namedview->getDefaultMetric()); |
3134 | - GString *ys = SP_PX_TO_METRIC_STRING(dxy[Geom::Y], _desktop->namedview->getDefaultMetric()); |
3135 | + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dxy[Geom::X], "px"); |
3136 | + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dxy[Geom::Y], "px"); |
3137 | + GString *xs = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str()); |
3138 | + GString *ys = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str()); |
3139 | _message_context.setF(Inkscape::NORMAL_MESSAGE, _("<b>Move</b> by %s, %s; with <b>Ctrl</b> to restrict to horizontal/vertical; with <b>Shift</b> to disable snapping"), xs->str, ys->str); |
3140 | g_string_free(xs, TRUE); |
3141 | g_string_free(ys, TRUE); |
3142 | |
3143 | === modified file 'src/snap-preferences.h' |
3144 | --- src/snap-preferences.h 2012-02-14 20:56:34 +0000 |
3145 | +++ src/snap-preferences.h 2013-08-06 18:46:25 +0000 |
3146 | @@ -10,7 +10,6 @@ |
3147 | * Released under GNU GPL, read the file 'COPYING' for more information |
3148 | */ |
3149 | |
3150 | -#include "helper/units.h" |
3151 | #include "snap-enums.h" |
3152 | |
3153 | namespace Inkscape |
3154 | |
3155 | === modified file 'src/sp-guide.cpp' |
3156 | --- src/sp-guide.cpp 2013-03-02 11:29:23 +0000 |
3157 | +++ src/sp-guide.cpp 2013-08-06 18:46:25 +0000 |
3158 | @@ -35,7 +35,6 @@ |
3159 | #include <glibmm/i18n.h> |
3160 | #include <xml/repr.h> |
3161 | #include <remove-last.h> |
3162 | -#include "sp-metrics.h" |
3163 | #include "inkscape.h" |
3164 | #include "desktop.h" |
3165 | #include "sp-namedview.h" |
3166 | @@ -463,10 +462,10 @@ |
3167 | } else { |
3168 | SPNamedView *namedview = sp_document_namedview(guide->document, NULL); |
3169 | |
3170 | - GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], |
3171 | - namedview->getDefaultMetric()); |
3172 | - GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], |
3173 | - namedview->getDefaultMetric()); |
3174 | + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(guide->point_on_line[X], "px"); |
3175 | + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(guide->point_on_line[Y], "px"); |
3176 | + GString *position_string_x = g_string_new(x_q.string(*namedview->doc_units).c_str()); |
3177 | + GString *position_string_y = g_string_new(y_q.string(*namedview->doc_units).c_str()); |
3178 | |
3179 | gchar *shortcuts = g_strdup_printf("; %s", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete")); |
3180 | |
3181 | |
3182 | === removed file 'src/sp-metric.h' |
3183 | --- src/sp-metric.h 2012-10-27 18:15:53 +0000 |
3184 | +++ src/sp-metric.h 1970-01-01 00:00:00 +0000 |
3185 | @@ -1,28 +0,0 @@ |
3186 | -#ifndef INKSCAPE_SP_METRIC_H |
3187 | -#define INKSCAPE_SP_METRIC_H |
3188 | - |
3189 | -/** Known metrics so far. (I don't know why this doesn't include pica.) */ |
3190 | -enum SPMetric { |
3191 | - SP_NONE, |
3192 | - SP_MM, |
3193 | - SP_CM, |
3194 | - SP_IN, |
3195 | - SP_FT, |
3196 | - SP_PT, |
3197 | - SP_PC, |
3198 | - SP_PX, |
3199 | - SP_M |
3200 | -}; |
3201 | - |
3202 | -#endif /* !INKSCAPE_SP_METRIC_H */ |
3203 | - |
3204 | -/* |
3205 | - Local Variables: |
3206 | - mode:c++ |
3207 | - c-file-style:"stroustrup" |
3208 | - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
3209 | - indent-tabs-mode:nil |
3210 | - fill-column:99 |
3211 | - End: |
3212 | -*/ |
3213 | -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
3214 | |
3215 | === removed file 'src/sp-metrics.cpp' |
3216 | --- src/sp-metrics.cpp 2012-10-27 18:15:53 +0000 |
3217 | +++ src/sp-metrics.cpp 1970-01-01 00:00:00 +0000 |
3218 | @@ -1,120 +0,0 @@ |
3219 | -#include "sp-metrics.h" |
3220 | -#include "unit-constants.h" |
3221 | - |
3222 | -/* |
3223 | - * SPMetric handling and stuff |
3224 | - * I hope this will be usefull :-) |
3225 | - */ |
3226 | - |
3227 | -gdouble |
3228 | -sp_absolute_metric_to_metric (gdouble length_src, const SPMetric metric_src, const SPMetric metric_dst) |
3229 | -{ |
3230 | - gdouble src = 1; |
3231 | - gdouble dst = 1; |
3232 | - |
3233 | - switch (metric_src) { |
3234 | - case SP_M: |
3235 | - src = M_PER_IN; |
3236 | - break; |
3237 | - case SP_MM: |
3238 | - src = MM_PER_IN; |
3239 | - break; |
3240 | - case SP_CM: |
3241 | - src = CM_PER_IN; |
3242 | - break; |
3243 | - case SP_IN: |
3244 | - src = IN_PER_IN; |
3245 | - break; |
3246 | - case SP_FT: |
3247 | - src = FT_PER_IN; |
3248 | - break; |
3249 | - case SP_PT: |
3250 | - src = PT_PER_IN; |
3251 | - break; |
3252 | - case SP_PC: |
3253 | - src = PC_PER_IN; |
3254 | - break; |
3255 | - case SP_PX: |
3256 | - src = PX_PER_IN; |
3257 | - break; |
3258 | - case SP_NONE: |
3259 | - src = 1; |
3260 | - break; |
3261 | - } |
3262 | - |
3263 | - switch (metric_dst) { |
3264 | - case SP_M: |
3265 | - dst = M_PER_IN; |
3266 | - break; |
3267 | - case SP_MM: |
3268 | - dst = MM_PER_IN; |
3269 | - break; |
3270 | - case SP_CM: |
3271 | - dst = CM_PER_IN; |
3272 | - break; |
3273 | - case SP_IN: |
3274 | - dst = IN_PER_IN; |
3275 | - break; |
3276 | - case SP_FT: |
3277 | - dst = FT_PER_IN; |
3278 | - break; |
3279 | - case SP_PT: |
3280 | - dst = PT_PER_IN; |
3281 | - break; |
3282 | - case SP_PC: |
3283 | - dst = PC_PER_IN; |
3284 | - break; |
3285 | - case SP_PX: |
3286 | - dst = PX_PER_IN; |
3287 | - break; |
3288 | - case SP_NONE: |
3289 | - dst = 1; |
3290 | - break; |
3291 | - } |
3292 | - |
3293 | - return length_src * (dst/src); |
3294 | -} |
3295 | - |
3296 | -/** |
3297 | - * Create a human-readable string suitable for status-bar display. |
3298 | - */ |
3299 | -GString * |
3300 | -sp_metric_to_metric_string(gdouble const length, |
3301 | - SPMetric const metric_src, SPMetric const metric_dst, |
3302 | - gboolean const m) |
3303 | -{ |
3304 | - gdouble const len = sp_absolute_metric_to_metric(length, metric_src, metric_dst); |
3305 | - GString *str = g_string_new(""); |
3306 | - g_string_printf(str, "%0.02f", len); |
3307 | - /* We need a fixed number of fractional digits, because otherwise the live statusbar display of |
3308 | - * lengths will be too jerky */ |
3309 | - |
3310 | - if (m) { |
3311 | - char const *unit_str; |
3312 | - switch (metric_dst) { |
3313 | - case SP_M: unit_str = " m"; break; |
3314 | - case SP_MM: unit_str = " mm"; break; |
3315 | - case SP_CM: unit_str = " cm"; break; |
3316 | - case SP_IN: unit_str = "\""; break; |
3317 | - case SP_PT: unit_str = " pt"; break; |
3318 | - case SP_PX: unit_str = " px"; break; |
3319 | - default: unit_str = NULL; break; |
3320 | - } |
3321 | - if (unit_str) { |
3322 | - g_string_append(str, unit_str); |
3323 | - } |
3324 | - } |
3325 | - return str; |
3326 | -} |
3327 | - |
3328 | - |
3329 | -/* |
3330 | - Local Variables: |
3331 | - mode:c++ |
3332 | - c-file-style:"stroustrup" |
3333 | - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
3334 | - indent-tabs-mode:nil |
3335 | - fill-column:99 |
3336 | - End: |
3337 | -*/ |
3338 | -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
3339 | |
3340 | === removed file 'src/sp-metrics.h' |
3341 | --- src/sp-metrics.h 2011-12-08 11:53:54 +0000 |
3342 | +++ src/sp-metrics.h 1970-01-01 00:00:00 +0000 |
3343 | @@ -1,20 +0,0 @@ |
3344 | -#ifndef SP_METRICS_H |
3345 | -#define SP_METRICS_H |
3346 | - |
3347 | -#include <glib.h> |
3348 | -#include "sp-metric.h" |
3349 | - |
3350 | -gdouble sp_absolute_metric_to_metric (gdouble length_src, const SPMetric metric_src, const SPMetric metric_dst); |
3351 | -GString * sp_metric_to_metric_string (gdouble length, const SPMetric metric_src, const SPMetric metric_dst, gboolean m); |
3352 | - |
3353 | -// convenience since we mostly deal with points |
3354 | -#define SP_METRIC_TO_PT(l,m) sp_absolute_metric_to_metric(l,m,SP_PT); |
3355 | -#define SP_PT_TO_METRIC(l,m) sp_absolute_metric_to_metric(l,SP_PT,m); |
3356 | - |
3357 | -#define SP_PT_TO_METRIC_STRING(l,m) sp_metric_to_metric_string(l, SP_PT, m, TRUE) |
3358 | -#define SP_PT_TO_STRING(l,m) sp_metric_to_metric_string(l, SP_PT, m, FALSE) |
3359 | - |
3360 | -#define SP_PX_TO_METRIC_STRING(l,m) sp_metric_to_metric_string(l, SP_PX, m, TRUE) |
3361 | -#define SP_PX_TO_STRING(l,m) sp_metric_to_metric_string(l, SP_PX, m, FALSE) |
3362 | - |
3363 | -#endif |
3364 | |
3365 | === modified file 'src/sp-namedview.cpp' |
3366 | --- src/sp-namedview.cpp 2013-05-01 07:46:46 +0000 |
3367 | +++ src/sp-namedview.cpp 2013-08-06 18:46:25 +0000 |
3368 | @@ -22,7 +22,7 @@ |
3369 | |
3370 | #include "display/canvas-grid.h" |
3371 | #include "display/guideline.h" |
3372 | -#include "helper/units.h" |
3373 | +#include "util/units.h" |
3374 | #include "svg/svg-color.h" |
3375 | #include "xml/repr.h" |
3376 | #include "attributes.h" |
3377 | @@ -40,6 +40,7 @@ |
3378 | #include <gtkmm/window.h> |
3379 | |
3380 | using Inkscape::DocumentUndo; |
3381 | +using Inkscape::Util::unit_table; |
3382 | |
3383 | #define DEFAULTGRIDCOLOR 0x3f3fff25 |
3384 | #define DEFAULTGRIDEMPCOLOR 0x3f3fff60 |
3385 | @@ -549,18 +550,19 @@ |
3386 | * in that they aren't in general absolute units as currently required by |
3387 | * doc_units. |
3388 | */ |
3389 | - SPUnit const *new_unit = &sp_unit_get_by_id(SP_UNIT_PX); |
3390 | + static Inkscape::Util::Unit px = unit_table.getUnit("px"); |
3391 | + Inkscape::Util::Unit const *new_unit = new Inkscape::Util::Unit(px); |
3392 | |
3393 | if (value) { |
3394 | - SPUnit const *const req_unit = sp_unit_get_by_abbreviation(value); |
3395 | - if ( req_unit == NULL ) { |
3396 | + Inkscape::Util::Unit u = unit_table.getUnit(value); |
3397 | + Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u); |
3398 | + if ( !unit_table.hasUnit(value) ) { |
3399 | g_warning("Unrecognized unit `%s'", value); |
3400 | /* fixme: Document errors should be reported in the status bar or |
3401 | * the like (e.g. as per |
3402 | * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log |
3403 | * should be only for programmer errors. */ |
3404 | - } else if ( req_unit->base == SP_UNIT_ABSOLUTE || |
3405 | - req_unit->base == SP_UNIT_DEVICE ) { |
3406 | + } else if ( req_unit->isAbsolute() ) { |
3407 | new_unit = req_unit; |
3408 | } else { |
3409 | g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'", |
3410 | @@ -573,18 +575,18 @@ |
3411 | break; |
3412 | } |
3413 | case SP_ATTR_UNITS: { |
3414 | - SPUnit const *new_unit = NULL; |
3415 | + Inkscape::Util::Unit const *new_unit = NULL; |
3416 | |
3417 | if (value) { |
3418 | - SPUnit const *const req_unit = sp_unit_get_by_abbreviation(value); |
3419 | - if ( req_unit == NULL ) { |
3420 | + Inkscape::Util::Unit u = unit_table.getUnit(value); |
3421 | + Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u); |
3422 | + if ( !unit_table.hasUnit(value) ) { |
3423 | g_warning("Unrecognized unit `%s'", value); |
3424 | /* fixme: Document errors should be reported in the status bar or |
3425 | * the like (e.g. as per |
3426 | * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log |
3427 | * should be only for programmer errors. */ |
3428 | - } else if ( req_unit->base == SP_UNIT_ABSOLUTE || |
3429 | - req_unit->base == SP_UNIT_DEVICE ) { |
3430 | + } else if ( req_unit->isAbsolute() ) { |
3431 | new_unit = req_unit; |
3432 | } else { |
3433 | g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'", |
3434 | @@ -1101,35 +1103,35 @@ |
3435 | * \return the margin size in px, else 0.0 if anything is invalid. |
3436 | */ |
3437 | double SPNamedView::getMarginLength(gchar const * const key, |
3438 | - SPUnit const * const margin_units, |
3439 | - SPUnit const * const return_units, |
3440 | + Inkscape::Util::Unit const * const margin_units, |
3441 | + Inkscape::Util::Unit const * const return_units, |
3442 | double const width, |
3443 | double const height, |
3444 | bool const use_width) |
3445 | { |
3446 | double value; |
3447 | + Inkscape::Util::Unit percent = unit_table.getUnit("%"); |
3448 | if(!this->storeAsDouble(key,&value)) { |
3449 | return 0.0; |
3450 | } |
3451 | - if (margin_units == &sp_unit_get_by_id (SP_UNIT_PERCENT)) { |
3452 | + if (*margin_units == percent) { |
3453 | return (use_width)? width * value : height * value; |
3454 | } |
3455 | - if (!sp_convert_distance (&value, margin_units, return_units)) { |
3456 | + if (!margin_units->compatibleWith(*return_units)) { |
3457 | return 0.0; |
3458 | } |
3459 | return value; |
3460 | } |
3461 | |
3462 | - |
3463 | /** |
3464 | - * Returns namedview's default metric. |
3465 | + * Returns namedview's default unit. |
3466 | */ |
3467 | -SPMetric SPNamedView::getDefaultMetric() const |
3468 | +Inkscape::Util::Unit const SPNamedView::getDefaultUnit() const |
3469 | { |
3470 | if (doc_units) { |
3471 | - return sp_unit_get_metric(doc_units); |
3472 | + return *doc_units; |
3473 | } else { |
3474 | - return SP_PT; |
3475 | + return *(new Inkscape::Util::Unit(unit_table.getUnit("pt"))); |
3476 | } |
3477 | } |
3478 | |
3479 | |
3480 | === modified file 'src/sp-namedview.h' |
3481 | --- src/sp-namedview.h 2013-01-23 12:22:14 +0000 |
3482 | +++ src/sp-namedview.h 2013-08-06 18:46:25 +0000 |
3483 | @@ -21,16 +21,17 @@ |
3484 | #define SP_IS_NAMEDVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_NAMEDVIEW)) |
3485 | |
3486 | #include "sp-object-group.h" |
3487 | -#include "sp-metric.h" |
3488 | #include "snap.h" |
3489 | #include "document.h" |
3490 | +#include "util/units.h" |
3491 | |
3492 | G_BEGIN_DECLS |
3493 | |
3494 | -struct SPUnit; |
3495 | - |
3496 | namespace Inkscape { |
3497 | -class CanvasGrid; |
3498 | + class CanvasGrid; |
3499 | + namespace Util { |
3500 | + class Unit; |
3501 | + } |
3502 | } |
3503 | |
3504 | enum { |
3505 | @@ -58,8 +59,8 @@ |
3506 | GSList * grids; |
3507 | bool grids_visible; |
3508 | |
3509 | - SPUnit const *doc_units; |
3510 | - SPUnit const *units; |
3511 | + Inkscape::Util::Unit const *doc_units; |
3512 | + Inkscape::Util::Unit const *units; |
3513 | |
3514 | GQuark default_layer_id; |
3515 | |
3516 | @@ -82,7 +83,7 @@ |
3517 | gchar const *getName() const; |
3518 | guint getViewCount(); |
3519 | GSList const *getViewList() const; |
3520 | - SPMetric getDefaultMetric() const; |
3521 | + Inkscape::Util::Unit const getDefaultUnit() const; |
3522 | |
3523 | void translateGuides(Geom::Translate const &translation); |
3524 | void translateGrids(Geom::Translate const &translation); |
3525 | @@ -94,7 +95,7 @@ |
3526 | bool getGuides(); |
3527 | |
3528 | private: |
3529 | - double getMarginLength(gchar const * const key,SPUnit const * const margin_units,SPUnit const * const return_units,double const width,double const height,bool const use_width); |
3530 | + double getMarginLength(gchar const * const key,Inkscape::Util::Unit const * const margin_units,Inkscape::Util::Unit const * const return_units,double const width,double const height,bool const use_width); |
3531 | friend class SPDocument; |
3532 | }; |
3533 | |
3534 | |
3535 | === modified file 'src/sp-text.cpp' |
3536 | --- src/sp-text.cpp 2013-08-04 14:27:59 +0000 |
3537 | +++ src/sp-text.cpp 2013-08-06 18:46:25 +0000 |
3538 | @@ -43,7 +43,6 @@ |
3539 | #include "sp-namedview.h" |
3540 | #include "style.h" |
3541 | #include "inkscape.h" |
3542 | -#include "sp-metrics.h" |
3543 | #include "xml/quote.h" |
3544 | #include "xml/repr.h" |
3545 | #include "mod360.h" |
3546 | @@ -56,7 +55,6 @@ |
3547 | #include "sp-tspan.h" |
3548 | |
3549 | #include "text-editing.h" |
3550 | -#include "unit-constants.h" |
3551 | |
3552 | /*##################################################### |
3553 | # SPTEXT |
3554 | @@ -392,7 +390,8 @@ |
3555 | n = g_strdup(_("<no name found>")); |
3556 | } |
3557 | |
3558 | - GString *xs = SP_PX_TO_METRIC_STRING(style->font_size.computed, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->getDefaultMetric()); |
3559 | + Inkscape::Util::Quantity q = Inkscape::Util::Quantity(style->font_size.computed, "px"); |
3560 | + GString *xs = g_string_new(q.string(*sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units).c_str()); |
3561 | |
3562 | char const *trunc = ""; |
3563 | Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item); |
3564 | |
3565 | === modified file 'src/spiral-context.cpp' |
3566 | --- src/spiral-context.cpp 2013-04-28 22:48:03 +0000 |
3567 | +++ src/spiral-context.cpp 2013-08-06 18:46:25 +0000 |
3568 | @@ -34,7 +34,6 @@ |
3569 | #include "message-context.h" |
3570 | #include "pixmaps/cursor-spiral.xpm" |
3571 | #include "spiral-context.h" |
3572 | -#include "sp-metrics.h" |
3573 | #include <glibmm/i18n.h> |
3574 | #include "xml/repr.h" |
3575 | #include "xml/node-event-vector.h" |
3576 | @@ -437,7 +436,8 @@ |
3577 | /*t0*/ sc->t0); |
3578 | |
3579 | /* status text */ |
3580 | - GString *rads = SP_PX_TO_METRIC_STRING(rad, desktop->namedview->getDefaultMetric()); |
3581 | + Inkscape::Util::Quantity q = Inkscape::Util::Quantity(rad, "px"); |
3582 | + GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str()); |
3583 | sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, |
3584 | _("<b>Spiral</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle"), |
3585 | rads->str, sp_round((arg + 2.0*M_PI*spiral->revo)*180/M_PI, 0.0001)); |
3586 | |
3587 | === modified file 'src/star-context.cpp' |
3588 | --- src/star-context.cpp 2013-04-28 22:48:03 +0000 |
3589 | +++ src/star-context.cpp 2013-08-06 18:46:25 +0000 |
3590 | @@ -36,7 +36,6 @@ |
3591 | #include "desktop-style.h" |
3592 | #include "message-context.h" |
3593 | #include "pixmaps/cursor-star.xpm" |
3594 | -#include "sp-metrics.h" |
3595 | #include <glibmm/i18n.h> |
3596 | #include "preferences.h" |
3597 | #include "xml/repr.h" |
3598 | @@ -450,7 +449,8 @@ |
3599 | arg1, arg1 + M_PI / sides, sc->isflatsided, sc->rounded, sc->randomized); |
3600 | |
3601 | /* status text */ |
3602 | - GString *rads = SP_PX_TO_METRIC_STRING(r1, desktop->namedview->getDefaultMetric()); |
3603 | + Inkscape::Util::Quantity q = Inkscape::Util::Quantity(r1, "px"); |
3604 | + GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str()); |
3605 | sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, |
3606 | ( sc->isflatsided? |
3607 | _("<b>Polygon</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle") |
3608 | |
3609 | === modified file 'src/style.cpp' |
3610 | --- src/style.cpp 2013-08-06 17:29:13 +0000 |
3611 | +++ src/style.cpp 2013-08-06 18:46:25 +0000 |
3612 | @@ -45,7 +45,7 @@ |
3613 | #include "svg/css-ostringstream.h" |
3614 | #include "xml/repr.h" |
3615 | #include "xml/simple-document.h" |
3616 | -#include "unit-constants.h" |
3617 | +#include "util/units.h" |
3618 | #include "macros.h" |
3619 | #include "preferences.h" |
3620 | |
3621 | @@ -2483,11 +2483,11 @@ |
3622 | |
3623 | case SP_CSS_UNIT_NONE: unit_size = size; break; |
3624 | case SP_CSS_UNIT_PX: unit_size = size; break; |
3625 | - case SP_CSS_UNIT_PT: unit_size = size * PT_PER_PX; break; |
3626 | - case SP_CSS_UNIT_PC: unit_size = size * (PT_PER_PX / PT_PER_PC); break; |
3627 | - case SP_CSS_UNIT_MM: unit_size = size * MM_PER_PX; break; |
3628 | - case SP_CSS_UNIT_CM: unit_size = size * CM_PER_PX; break; |
3629 | - case SP_CSS_UNIT_IN: unit_size = size * IN_PER_PX; break; |
3630 | + case SP_CSS_UNIT_PT: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "pt"); break; |
3631 | + case SP_CSS_UNIT_PC: unit_size = size * (Inkscape::Util::Quantity::convert(1, "px", "pt") / Inkscape::Util::Quantity::convert(1, "pc", "pt")); break; |
3632 | + case SP_CSS_UNIT_MM: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "mm"); break; |
3633 | + case SP_CSS_UNIT_CM: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "cm"); break; |
3634 | + case SP_CSS_UNIT_IN: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "in"); break; |
3635 | case SP_CSS_UNIT_EM: unit_size = size / SP_CSS_FONT_SIZE_DEFAULT; break; |
3636 | case SP_CSS_UNIT_EX: unit_size = size * 2.0 / SP_CSS_FONT_SIZE_DEFAULT ; break; |
3637 | case SP_CSS_UNIT_PERCENT: unit_size = size * 100.0 / SP_CSS_FONT_SIZE_DEFAULT; break; |
3638 | @@ -3472,19 +3472,19 @@ |
3639 | } else if (!strcmp(e, "pt")) { |
3640 | /* Userspace / DEVICESCALE */ |
3641 | val->unit = SP_CSS_UNIT_PT; |
3642 | - val->computed = value * PX_PER_PT; |
3643 | + val->computed = value * Inkscape::Util::Quantity::convert(1, "pt", "px"); |
3644 | } else if (!strcmp(e, "pc")) { |
3645 | val->unit = SP_CSS_UNIT_PC; |
3646 | - val->computed = value * PX_PER_PC; |
3647 | + val->computed = value * Inkscape::Util::Quantity::convert(1, "pc", "px"); |
3648 | } else if (!strcmp(e, "mm")) { |
3649 | val->unit = SP_CSS_UNIT_MM; |
3650 | - val->computed = value * PX_PER_MM; |
3651 | + val->computed = value * Inkscape::Util::Quantity::convert(1, "mm", "px"); |
3652 | } else if (!strcmp(e, "cm")) { |
3653 | val->unit = SP_CSS_UNIT_CM; |
3654 | - val->computed = value * PX_PER_CM; |
3655 | + val->computed = value * Inkscape::Util::Quantity::convert(1, "cm", "px"); |
3656 | } else if (!strcmp(e, "in")) { |
3657 | val->unit = SP_CSS_UNIT_IN; |
3658 | - val->computed = value * PX_PER_IN; |
3659 | + val->computed = value * Inkscape::Util::Quantity::convert(1, "in", "px"); |
3660 | } else if (!strcmp(e, "em")) { |
3661 | /* EM square */ |
3662 | val->unit = SP_CSS_UNIT_EM; |
3663 | @@ -4043,23 +4043,23 @@ |
3664 | return g_strlcpy(p, os.str().c_str(), len); |
3665 | break; |
3666 | case SP_CSS_UNIT_PT: |
3667 | - os << key << ":" << val->computed * PT_PER_PX << "pt;"; |
3668 | + os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "pt") << "pt;"; |
3669 | return g_strlcpy(p, os.str().c_str(), len); |
3670 | break; |
3671 | case SP_CSS_UNIT_PC: |
3672 | - os << key << ":" << val->computed * PT_PER_PX / 12.0 << "pc;"; |
3673 | + os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "pt") / 12.0 << "pc;"; |
3674 | return g_strlcpy(p, os.str().c_str(), len); |
3675 | break; |
3676 | case SP_CSS_UNIT_MM: |
3677 | - os << key << ":" << val->computed * MM_PER_PX << "mm;"; |
3678 | + os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "mm") << "mm;"; |
3679 | return g_strlcpy(p, os.str().c_str(), len); |
3680 | break; |
3681 | case SP_CSS_UNIT_CM: |
3682 | - os << key << ":" << val->computed * CM_PER_PX << "cm;"; |
3683 | + os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "cm") << "cm;"; |
3684 | return g_strlcpy(p, os.str().c_str(), len); |
3685 | break; |
3686 | case SP_CSS_UNIT_IN: |
3687 | - os << key << ":" << val->computed * IN_PER_PX << "in;"; |
3688 | + os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "in") << "in;"; |
3689 | return g_strlcpy(p, os.str().c_str(), len); |
3690 | break; |
3691 | case SP_CSS_UNIT_EM: |
3692 | |
3693 | === modified file 'src/svg/svg-length.cpp' |
3694 | --- src/svg/svg-length.cpp 2011-12-08 11:53:54 +0000 |
3695 | +++ src/svg/svg-length.cpp 2013-08-06 18:46:25 +0000 |
3696 | @@ -23,7 +23,7 @@ |
3697 | |
3698 | #include "svg.h" |
3699 | #include "stringstream.h" |
3700 | -#include "../unit-constants.h" |
3701 | +#include "util/units.h" |
3702 | |
3703 | |
3704 | static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, float *val, float *computed, char **next); |
3705 | @@ -330,6 +330,8 @@ |
3706 | *next = (char *) e + 1; |
3707 | } |
3708 | return 1; |
3709 | + } else if (g_ascii_isspace(e[0])) { |
3710 | + return 0; // spaces are not allowed |
3711 | } else { |
3712 | /* Unitless */ |
3713 | if (unit) { |
3714 | @@ -365,7 +367,7 @@ |
3715 | *unit = SVGLength::PT; |
3716 | } |
3717 | if (computed) { |
3718 | - *computed = v * PX_PER_PT; |
3719 | + *computed = v * Inkscape::Util::Quantity::convert(1, "pt", "px"); |
3720 | } |
3721 | break; |
3722 | case UVAL('p','c'): |
3723 | @@ -373,7 +375,7 @@ |
3724 | *unit = SVGLength::PC; |
3725 | } |
3726 | if (computed) { |
3727 | - *computed = v * PX_PER_PC; |
3728 | + *computed = v * Inkscape::Util::Quantity::convert(1, "pc", "px"); |
3729 | } |
3730 | break; |
3731 | case UVAL('m','m'): |
3732 | @@ -381,7 +383,7 @@ |
3733 | *unit = SVGLength::MM; |
3734 | } |
3735 | if (computed) { |
3736 | - *computed = v * PX_PER_MM; |
3737 | + *computed = v * Inkscape::Util::Quantity::convert(1, "mm", "px"); |
3738 | } |
3739 | break; |
3740 | case UVAL('c','m'): |
3741 | @@ -389,7 +391,7 @@ |
3742 | *unit = SVGLength::CM; |
3743 | } |
3744 | if (computed) { |
3745 | - *computed = v * PX_PER_CM; |
3746 | + *computed = v * Inkscape::Util::Quantity::convert(1, "cm", "px"); |
3747 | } |
3748 | break; |
3749 | case UVAL('i','n'): |
3750 | @@ -397,7 +399,7 @@ |
3751 | *unit = SVGLength::INCH; |
3752 | } |
3753 | if (computed) { |
3754 | - *computed = v * PX_PER_IN; |
3755 | + *computed = v * Inkscape::Util::Quantity::convert(1, "in", "px"); |
3756 | } |
3757 | break; |
3758 | case UVAL('f','t'): |
3759 | @@ -405,7 +407,7 @@ |
3760 | *unit = SVGLength::FOOT; |
3761 | } |
3762 | if (computed) { |
3763 | - *computed = v * PX_PER_FT; |
3764 | + *computed = v * Inkscape::Util::Quantity::convert(1, "ft", "px"); |
3765 | } |
3766 | break; |
3767 | case UVAL('e','m'): |
3768 | |
3769 | === modified file 'src/text-context.cpp' |
3770 | --- src/text-context.cpp 2013-05-12 10:22:42 +0000 |
3771 | +++ src/text-context.cpp 2013-08-06 18:46:25 +0000 |
3772 | @@ -42,7 +42,6 @@ |
3773 | #include "selection.h" |
3774 | #include "shape-editor.h" |
3775 | #include "sp-flowtext.h" |
3776 | -#include "sp-metrics.h" |
3777 | #include "sp-namedview.h" |
3778 | #include "sp-text.h" |
3779 | #include "style.h" |
3780 | @@ -640,8 +639,10 @@ |
3781 | gobble_motion_events(GDK_BUTTON1_MASK); |
3782 | |
3783 | // status text |
3784 | - GString *xs = SP_PX_TO_METRIC_STRING(fabs((p - tc->p0)[Geom::X]), desktop->namedview->getDefaultMetric()); |
3785 | - GString *ys = SP_PX_TO_METRIC_STRING(fabs((p - tc->p0)[Geom::Y]), desktop->namedview->getDefaultMetric()); |
3786 | + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(fabs((p - tc->p0)[Geom::X]), "px"); |
3787 | + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(fabs((p - tc->p0)[Geom::Y]), "px"); |
3788 | + GString *xs = g_string_new(x_q.string(*desktop->namedview->doc_units).c_str()); |
3789 | + GString *ys = g_string_new(y_q.string(*desktop->namedview->doc_units).c_str()); |
3790 | event_context->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Flowed text frame</b>: %s × %s"), xs->str, ys->str); |
3791 | g_string_free(xs, FALSE); |
3792 | g_string_free(ys, FALSE); |
3793 | |
3794 | === modified file 'src/text-editing.cpp' |
3795 | --- src/text-editing.cpp 2013-03-16 19:42:47 +0000 |
3796 | +++ src/text-editing.cpp 2013-08-06 18:46:25 +0000 |
3797 | @@ -24,7 +24,7 @@ |
3798 | #include "inkscape.h" |
3799 | #include "message-stack.h" |
3800 | #include "style.h" |
3801 | -#include "unit-constants.h" |
3802 | +#include "util/units.h" |
3803 | |
3804 | #include "document.h" |
3805 | #include "xml/repr.h" |
3806 | @@ -1278,23 +1278,23 @@ |
3807 | style->line_height.value = style->line_height.computed; |
3808 | break; |
3809 | case SP_CSS_UNIT_PT: |
3810 | - style->line_height.computed += zby * PT_PER_PX; |
3811 | + style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "pt"); |
3812 | style->line_height.value = style->line_height.computed; |
3813 | break; |
3814 | case SP_CSS_UNIT_PC: |
3815 | - style->line_height.computed += zby * (PT_PER_PX / 12); |
3816 | + style->line_height.computed += zby * (Inkscape::Util::Quantity::convert(1, "px", "pt") / 12); |
3817 | style->line_height.value = style->line_height.computed; |
3818 | break; |
3819 | case SP_CSS_UNIT_MM: |
3820 | - style->line_height.computed += zby * MM_PER_PX; |
3821 | + style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "mm"); |
3822 | style->line_height.value = style->line_height.computed; |
3823 | break; |
3824 | case SP_CSS_UNIT_CM: |
3825 | - style->line_height.computed += zby * CM_PER_PX; |
3826 | + style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "cm"); |
3827 | style->line_height.value = style->line_height.computed; |
3828 | break; |
3829 | case SP_CSS_UNIT_IN: |
3830 | - style->line_height.computed += zby * IN_PER_PX; |
3831 | + style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "in"); |
3832 | style->line_height.value = style->line_height.computed; |
3833 | break; |
3834 | } |
3835 | |
3836 | === modified file 'src/ui/CMakeLists.txt' |
3837 | --- src/ui/CMakeLists.txt 2013-07-23 10:54:01 +0000 |
3838 | +++ src/ui/CMakeLists.txt 2013-08-06 18:46:25 +0000 |
3839 | @@ -112,6 +112,7 @@ |
3840 | widget/text.cpp |
3841 | widget/tolerance-slider.cpp |
3842 | widget/unit-menu.cpp |
3843 | + widget/unit-tracker.cpp |
3844 | |
3845 | view/view.cpp |
3846 | view/view-widget.cpp |
3847 | @@ -240,6 +241,7 @@ |
3848 | widget/text.h |
3849 | widget/tolerance-slider.h |
3850 | widget/unit-menu.h |
3851 | + widget/unit-tracker.h |
3852 | |
3853 | view/edit-widget-interface.h |
3854 | view/view-widget.h |
3855 | |
3856 | === modified file 'src/ui/clipboard.cpp' |
3857 | --- src/ui/clipboard.cpp 2013-04-21 00:16:01 +0000 |
3858 | +++ src/ui/clipboard.cpp 2013-08-06 18:46:25 +0000 |
3859 | @@ -79,7 +79,7 @@ |
3860 | #include "text-editing.h" |
3861 | #include "tools-switch.h" |
3862 | #include "path-chemistry.h" |
3863 | -#include "unit-constants.h" |
3864 | +#include "util/units.h" |
3865 | #include "helper/png-write.h" |
3866 | #include "svg/svg-color.h" |
3867 | #include "sp-namedview.h" |
3868 | @@ -1078,14 +1078,14 @@ |
3869 | try { |
3870 | if (out == outlist.end() && target == "image/png") |
3871 | { |
3872 | - gdouble dpi = PX_PER_IN; |
3873 | + gdouble dpi = Inkscape::Util::Quantity::convert(1, "in", "px"); |
3874 | guint32 bgcolor = 0x00000000; |
3875 | |
3876 | Geom::Point origin (_clipboardSPDoc->getRoot()->x.computed, _clipboardSPDoc->getRoot()->y.computed); |
3877 | Geom::Rect area = Geom::Rect(origin, origin + _clipboardSPDoc->getDimensions()); |
3878 | |
3879 | - unsigned long int width = (unsigned long int) (area.width() * dpi / PX_PER_IN + 0.5); |
3880 | - unsigned long int height = (unsigned long int) (area.height() * dpi / PX_PER_IN + 0.5); |
3881 | + unsigned long int width = (unsigned long int) (area.width() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); |
3882 | + unsigned long int height = (unsigned long int) (area.height() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); |
3883 | |
3884 | // read from namedview |
3885 | Inkscape::XML::Node *nv = sp_repr_lookup_name (_clipboardSPDoc->rroot, "sodipodi:namedview"); |
3886 | |
3887 | === modified file 'src/ui/dialog/clonetiler.cpp' |
3888 | --- src/ui/dialog/clonetiler.cpp 2013-03-29 11:00:19 +0000 |
3889 | +++ src/ui/dialog/clonetiler.cpp 2013-08-06 18:46:25 +0000 |
3890 | @@ -34,8 +34,8 @@ |
3891 | #include "document.h" |
3892 | #include "document-undo.h" |
3893 | #include "filter-chemistry.h" |
3894 | -#include "helper/unit-menu.h" |
3895 | -#include "helper/units.h" |
3896 | +#include "ui/widget/unit-menu.h" |
3897 | +#include "util/units.h" |
3898 | #include "helper/window.h" |
3899 | #include "inkscape.h" |
3900 | #include "interface.h" |
3901 | @@ -58,6 +58,7 @@ |
3902 | #include "sp-root.h" |
3903 | |
3904 | using Inkscape::DocumentUndo; |
3905 | +using Inkscape::Util::unit_table; |
3906 | |
3907 | namespace Inkscape { |
3908 | namespace UI { |
3909 | @@ -1092,35 +1093,36 @@ |
3910 | g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb); |
3911 | |
3912 | // unitmenu |
3913 | - GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); |
3914 | - sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); |
3915 | + unit_menu = new Inkscape::UI::Widget::UnitMenu(); |
3916 | + unit_menu->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR); |
3917 | + unit_menu->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr); |
3918 | + unitChangedConn = unit_menu->signal_changed().connect(sigc::mem_fun(*this, &CloneTiler::clonetiler_unit_changed)); |
3919 | |
3920 | { |
3921 | // Width spinbutton |
3922 | #if WITH_GTKMM_3_0 |
3923 | - Glib::RefPtr<Gtk::Adjustment> a = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); |
3924 | + fill_width = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); |
3925 | #else |
3926 | - Gtk::Adjustment *a = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); |
3927 | + fill_width = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); |
3928 | #endif |
3929 | - sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a->gobj())); |
3930 | |
3931 | double value = prefs->getDouble(prefs_path + "fillwidth", 50.0); |
3932 | - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); |
3933 | - gdouble const units = sp_pixels_get_units (value, unit); |
3934 | - a->set_value (units); |
3935 | + Inkscape::Util::Unit const unit = unit_menu->getUnit(); |
3936 | + gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); |
3937 | + fill_width->set_value (units); |
3938 | |
3939 | #if WITH_GTKMM_3_0 |
3940 | - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(a, 1.0, 2); |
3941 | + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(fill_width, 1.0, 2); |
3942 | #else |
3943 | - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*a, 1.0, 2); |
3944 | + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*fill_width, 1.0, 2); |
3945 | #endif |
3946 | e->set_tooltip_text (_("Width of the rectangle to be filled")); |
3947 | e->set_width_chars (7); |
3948 | e->set_digits (4); |
3949 | gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0); |
3950 | // TODO: C++ification |
3951 | - g_signal_connect(G_OBJECT(a->gobj()), "value_changed", |
3952 | - G_CALLBACK(clonetiler_fill_width_changed), u); |
3953 | + g_signal_connect(G_OBJECT(fill_width->gobj()), "value_changed", |
3954 | + G_CALLBACK(clonetiler_fill_width_changed), unit_menu); |
3955 | } |
3956 | { |
3957 | GtkWidget *l = gtk_label_new (""); |
3958 | @@ -1132,32 +1134,31 @@ |
3959 | { |
3960 | // Height spinbutton |
3961 | #if WITH_GTKMM_3_0 |
3962 | - Glib::RefPtr<Gtk::Adjustment> a = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); |
3963 | + fill_height = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); |
3964 | #else |
3965 | - Gtk::Adjustment *a = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); |
3966 | + fill_height = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); |
3967 | #endif |
3968 | - sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a->gobj())); |
3969 | |
3970 | double value = prefs->getDouble(prefs_path + "fillheight", 50.0); |
3971 | - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); |
3972 | - gdouble const units = sp_pixels_get_units (value, unit); |
3973 | - a->set_value (units); |
3974 | + Inkscape::Util::Unit const unit = unit_menu->getUnit(); |
3975 | + gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); |
3976 | + fill_height->set_value (units); |
3977 | |
3978 | #if WITH_GTKMM_3_0 |
3979 | - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(a, 1.0, 2); |
3980 | + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(fill_height, 1.0, 2); |
3981 | #else |
3982 | - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*a, 1.0, 2); |
3983 | + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*fill_height, 1.0, 2); |
3984 | #endif |
3985 | e->set_tooltip_text (_("Height of the rectangle to be filled")); |
3986 | e->set_width_chars (7); |
3987 | e->set_digits (4); |
3988 | gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0); |
3989 | // TODO: C++ification |
3990 | - g_signal_connect(G_OBJECT(a->gobj()), "value_changed", |
3991 | - G_CALLBACK(clonetiler_fill_height_changed), u); |
3992 | + g_signal_connect(G_OBJECT(fill_height->gobj()), "value_changed", |
3993 | + G_CALLBACK(clonetiler_fill_height_changed), unit_menu); |
3994 | } |
3995 | |
3996 | - gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0); |
3997 | + gtk_box_pack_start (GTK_BOX (hb), (GtkWidget*) unit_menu->gobj(), TRUE, TRUE, 0); |
3998 | clonetiler_table_attach (table, hb, 0.0, 2, 2); |
3999 | |
4000 | } |
4001 | @@ -2944,26 +2945,39 @@ |
4002 | |
4003 | |
4004 | |
4005 | -void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, GtkWidget *u) |
4006 | +void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u) |
4007 | { |
4008 | gdouble const raw_dist = gtk_adjustment_get_value (adj); |
4009 | - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); |
4010 | - gdouble const pixels = sp_units_get_pixels (raw_dist, unit); |
4011 | + Inkscape::Util::Unit const unit = u->getUnit(); |
4012 | + gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); |
4013 | |
4014 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
4015 | prefs->setDouble(prefs_path + "fillwidth", pixels); |
4016 | } |
4017 | |
4018 | -void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, GtkWidget *u) |
4019 | +void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u) |
4020 | { |
4021 | gdouble const raw_dist = gtk_adjustment_get_value (adj); |
4022 | - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); |
4023 | - gdouble const pixels = sp_units_get_pixels (raw_dist, unit); |
4024 | + Inkscape::Util::Unit const unit = u->getUnit(); |
4025 | + gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); |
4026 | |
4027 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
4028 | prefs->setDouble(prefs_path + "fillheight", pixels); |
4029 | } |
4030 | |
4031 | +void CloneTiler::clonetiler_unit_changed() |
4032 | +{ |
4033 | + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
4034 | + gdouble width_pixels = prefs->getDouble(prefs_path + "fillwidth"); |
4035 | + gdouble height_pixels = prefs->getDouble(prefs_path + "fillheight"); |
4036 | + |
4037 | + Inkscape::Util::Unit unit = unit_menu->getUnit(); |
4038 | + |
4039 | + gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, "px", unit); |
4040 | + gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, "px", unit); |
4041 | + gtk_adjustment_set_value(fill_width->gobj(), width_value); |
4042 | + gtk_adjustment_set_value(fill_height->gobj(), height_value); |
4043 | +} |
4044 | |
4045 | void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg) |
4046 | { |
4047 | @@ -2977,7 +2991,6 @@ |
4048 | } |
4049 | } |
4050 | |
4051 | - |
4052 | } |
4053 | } |
4054 | } |
4055 | |
4056 | === modified file 'src/ui/dialog/clonetiler.h' |
4057 | --- src/ui/dialog/clonetiler.h 2013-03-29 11:00:19 +0000 |
4058 | +++ src/ui/dialog/clonetiler.h 2013-08-06 18:46:25 +0000 |
4059 | @@ -19,6 +19,11 @@ |
4060 | |
4061 | namespace Inkscape { |
4062 | namespace UI { |
4063 | + |
4064 | +namespace Widget { |
4065 | + class UnitMenu; |
4066 | +} |
4067 | + |
4068 | namespace Dialog { |
4069 | |
4070 | class CloneTiler : public Widget::Panel { |
4071 | @@ -45,8 +50,9 @@ |
4072 | static void clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg); |
4073 | static void clonetiler_pick_to(GtkToggleButton *tb, gpointer data); |
4074 | static void clonetiler_xy_changed(GtkAdjustment *adj, gpointer data); |
4075 | - static void clonetiler_fill_width_changed(GtkAdjustment *adj, GtkWidget *u); |
4076 | - static void clonetiler_fill_height_changed(GtkAdjustment *adj, GtkWidget *u); |
4077 | + static void clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u); |
4078 | + static void clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u); |
4079 | + void clonetiler_unit_changed(); |
4080 | static void clonetiler_switch_to_create(GtkToggleButton */*tb*/, GtkWidget *dlg); |
4081 | static void clonetiler_switch_to_fill(GtkToggleButton */*tb*/, GtkWidget *dlg); |
4082 | static void clonetiler_keep_bbox_toggled(GtkToggleButton *tb, gpointer /*data*/); |
4083 | @@ -112,12 +118,22 @@ |
4084 | DesktopTracker deskTrack; |
4085 | Inkscape::UI::Widget::ColorPicker *color_picker; |
4086 | GtkSizeGroup* table_row_labels; |
4087 | + Inkscape::UI::Widget::UnitMenu *unit_menu; |
4088 | + |
4089 | +#if WITH_GTKMM_3_0 |
4090 | + Glib::RefPtr<Gtk::Adjustment> fill_width; |
4091 | + Glib::RefPtr<Gtk::Adjustment> fill_height; |
4092 | +#else |
4093 | + Gtk::Adjustment *fill_width; |
4094 | + Gtk::Adjustment *fill_height; |
4095 | +#endif |
4096 | |
4097 | sigc::connection desktopChangeConn; |
4098 | sigc::connection selectChangedConn; |
4099 | sigc::connection subselChangedConn; |
4100 | sigc::connection selectModifiedConn; |
4101 | sigc::connection color_changed_connection; |
4102 | + sigc::connection unitChangedConn; |
4103 | |
4104 | /** |
4105 | * Can be invoked for setting the desktop. Currently not used. |
4106 | |
4107 | === modified file 'src/ui/dialog/document-properties.cpp' |
4108 | --- src/ui/dialog/document-properties.cpp 2013-03-16 19:42:47 +0000 |
4109 | +++ src/ui/dialog/document-properties.cpp 2013-08-06 18:46:25 +0000 |
4110 | @@ -28,7 +28,6 @@ |
4111 | #include "document.h" |
4112 | #include "desktop-handles.h" |
4113 | #include "desktop.h" |
4114 | -#include "helper/units.h" |
4115 | #include "inkscape.h" |
4116 | #include "io/sys.h" |
4117 | #include "preferences.h" |
4118 | @@ -1432,7 +1431,7 @@ |
4119 | _rcb_shad.setActive (nv->showpageshadow); |
4120 | |
4121 | if (nv->doc_units) |
4122 | - _rum_deflt.setUnit (nv->doc_units); |
4123 | + _rum_deflt.setUnit (nv->doc_units->abbr); |
4124 | |
4125 | double const doc_w_px = sp_desktop_document(dt)->getWidth(); |
4126 | double const doc_h_px = sp_desktop_document(dt)->getHeight(); |
4127 | |
4128 | === modified file 'src/ui/dialog/export.cpp' |
4129 | --- src/ui/dialog/export.cpp 2013-06-06 13:44:11 +0000 |
4130 | +++ src/ui/dialog/export.cpp 2013-08-06 18:46:25 +0000 |
4131 | @@ -48,9 +48,8 @@ |
4132 | #include <glibmm/i18n.h> |
4133 | #include <glibmm/miscutils.h> |
4134 | |
4135 | -#include "helper/unit-menu.h" |
4136 | -#include "helper/units.h" |
4137 | -#include "unit-constants.h" |
4138 | +#include "ui/widget/unit-menu.h" |
4139 | +#include "util/units.h" |
4140 | #include "helper/window.h" |
4141 | #include "inkscape-private.h" |
4142 | #include "document.h" |
4143 | @@ -98,7 +97,7 @@ |
4144 | |
4145 | #define SP_EXPORT_MIN_SIZE 1.0 |
4146 | |
4147 | -#define DPI_BASE PX_PER_IN |
4148 | +#define DPI_BASE Inkscape::Util::Quantity::convert(1, "in", "px") |
4149 | |
4150 | #define EXPORT_COORD_PRECISION 3 |
4151 | |
4152 | @@ -108,6 +107,8 @@ |
4153 | #include "verbs.h" |
4154 | #include "export.h" |
4155 | |
4156 | +using Inkscape::Util::unit_table; |
4157 | + |
4158 | namespace { |
4159 | |
4160 | class MessageCleaner |
4161 | @@ -198,10 +199,13 @@ |
4162 | /* Units box */ |
4163 | /* gets added to the vbox later, but the unit selector is needed |
4164 | earlier than that */ |
4165 | - unit_selector = Glib::wrap(sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE)); |
4166 | + unit_selector = new Inkscape::UI::Widget::UnitMenu(); |
4167 | + unit_selector->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR); |
4168 | + unitChangedConn = unit_selector->signal_changed().connect(sigc::mem_fun(*this, &Export::onUnitChanged)); |
4169 | + |
4170 | SPDesktop *desktop = SP_ACTIVE_DESKTOP; |
4171 | if (desktop) |
4172 | - sp_unit_selector_set_unit (SP_UNIT_SELECTOR(unit_selector->gobj()), sp_desktop_namedview(desktop)->doc_units); |
4173 | + unit_selector->setUnit(sp_desktop_namedview(desktop)->doc_units->abbr); |
4174 | unitbox.pack_end(*unit_selector, false, false, 0); |
4175 | unitbox.pack_end(units_label, false, false, 3); |
4176 | |
4177 | @@ -226,28 +230,28 @@ |
4178 | t->set_col_spacings (4); |
4179 | #endif |
4180 | |
4181 | - x0_adj = createSpinbutton ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(), |
4182 | + x0_adj = createSpinbutton ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(), |
4183 | t, 0, 0, _("_x0:"), "", EXPORT_COORD_PRECISION, 1, |
4184 | &Export::onAreaX0Change); |
4185 | |
4186 | - x1_adj = createSpinbutton ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(), |
4187 | + x1_adj = createSpinbutton ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(), |
4188 | t, 0, 1, _("x_1:"), "", EXPORT_COORD_PRECISION, 1, |
4189 | &Export::onAreaX1Change); |
4190 | |
4191 | width_adj = createSpinbutton ( "width", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0, |
4192 | - unit_selector->gobj(), t, 0, 2, _("Wid_th:"), "", EXPORT_COORD_PRECISION, 1, |
4193 | + ((Gtk::Widget*) unit_selector)->gobj(), t, 0, 2, _("Wid_th:"), "", EXPORT_COORD_PRECISION, 1, |
4194 | &Export::onAreaWidthChange); |
4195 | |
4196 | - y0_adj = createSpinbutton ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(), |
4197 | + y0_adj = createSpinbutton ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(), |
4198 | t, 2, 0, _("_y0:"), "", EXPORT_COORD_PRECISION, 1, |
4199 | &Export::onAreaY0Change); |
4200 | |
4201 | - y1_adj = createSpinbutton ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(), |
4202 | + y1_adj = createSpinbutton ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(), |
4203 | t, 2, 1, _("y_1:"), "", EXPORT_COORD_PRECISION, 1, |
4204 | &Export::onAreaY1Change); |
4205 | |
4206 | height_adj = createSpinbutton ( "height", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0, |
4207 | - unit_selector->gobj(), t, 2, 2, _("Hei_ght:"), "", EXPORT_COORD_PRECISION, 1, |
4208 | + ((Gtk::Widget*) unit_selector)->gobj(), t, 2, 2, _("Hei_ght:"), "", EXPORT_COORD_PRECISION, 1, |
4209 | &Export::onAreaHeightChange); |
4210 | |
4211 | area_box.pack_start(togglebox, false, false, 3); |
4212 | @@ -496,9 +500,6 @@ |
4213 | #else |
4214 | Gtk::Adjustment *adj = new Gtk::Adjustment ( val, min, max, step, page, 0 ); |
4215 | #endif |
4216 | - if (us) { |
4217 | - sp_unit_selector_add_adjustment ( SP_UNIT_SELECTOR (us), GTK_ADJUSTMENT (adj->gobj()) ); |
4218 | - } |
4219 | |
4220 | int pos = 0; |
4221 | Gtk::Label *l = NULL; |
4222 | @@ -979,6 +980,12 @@ |
4223 | return path; |
4224 | } |
4225 | |
4226 | +// Called when unit is changed |
4227 | +void Export::onUnitChanged() |
4228 | +{ |
4229 | + onAreaToggled(); |
4230 | +} |
4231 | + |
4232 | void Export::onHideExceptSelected () |
4233 | { |
4234 | prefs->setBool("/dialogs/export/hideexceptselected/value", hide_export.get_active()); |
4235 | @@ -1042,8 +1049,8 @@ |
4236 | |
4237 | Geom::OptRect area = item->desktopVisualBounds(); |
4238 | if (area) { |
4239 | - gint width = (gint) (area->width() * dpi / PX_PER_IN + 0.5); |
4240 | - gint height = (gint) (area->height() * dpi / PX_PER_IN + 0.5); |
4241 | + gint width = (gint) (area->width() * dpi / DPI_BASE + 0.5); |
4242 | + gint height = (gint) (area->height() * dpi / DPI_BASE + 0.5); |
4243 | |
4244 | if (width > 1 && height > 1) { |
4245 | // Do export |
4246 | @@ -1507,10 +1514,6 @@ |
4247 | return; |
4248 | } |
4249 | |
4250 | - if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) { |
4251 | - return; |
4252 | - } |
4253 | - |
4254 | update = true; |
4255 | |
4256 | x0 = getValuePx(x0_adj); |
4257 | @@ -1554,10 +1557,6 @@ |
4258 | return; |
4259 | } |
4260 | |
4261 | - if (sp_unit_selector_update_test (SP_UNIT_SELECTOR(unit_selector->gobj()))) { |
4262 | - return; |
4263 | - } |
4264 | - |
4265 | update = true; |
4266 | |
4267 | y0 = getValuePx(y0_adj); |
4268 | @@ -1597,10 +1596,6 @@ |
4269 | return; |
4270 | } |
4271 | |
4272 | - if (sp_unit_selector_update_test(reinterpret_cast<SPUnitSelector *>(unit_selector->gobj()))) { |
4273 | - return; |
4274 | - } |
4275 | - |
4276 | update = true; |
4277 | |
4278 | float x0 = getValuePx(x0_adj); |
4279 | @@ -1630,10 +1625,6 @@ |
4280 | return; |
4281 | } |
4282 | |
4283 | - if (sp_unit_selector_update_test(reinterpret_cast<SPUnitSelector *>(unit_selector->gobj()))) { |
4284 | - return; |
4285 | - } |
4286 | - |
4287 | update = true; |
4288 | |
4289 | float y0 = getValuePx(y0_adj); |
4290 | @@ -1709,10 +1700,6 @@ |
4291 | return; |
4292 | } |
4293 | |
4294 | - if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) { |
4295 | - return; |
4296 | - } |
4297 | - |
4298 | update = true; |
4299 | |
4300 | x0 = getValuePx(x0_adj); |
4301 | @@ -1743,10 +1730,6 @@ |
4302 | return; |
4303 | } |
4304 | |
4305 | - if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) { |
4306 | - return; |
4307 | - } |
4308 | - |
4309 | update = true; |
4310 | |
4311 | y0 = getValuePx(y0_adj); |
4312 | @@ -1803,10 +1786,6 @@ |
4313 | return; |
4314 | } |
4315 | |
4316 | - if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) { |
4317 | - return; |
4318 | - } |
4319 | - |
4320 | update = true; |
4321 | |
4322 | x0 = getValuePx(x0_adj); |
4323 | @@ -1905,9 +1884,9 @@ |
4324 | void Export::setValuePx( Gtk::Adjustment *adj, double val) |
4325 | #endif |
4326 | { |
4327 | - const SPUnit *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unit_selector->gobj()) ); |
4328 | + const Unit unit = unit_selector->getUnit(); |
4329 | |
4330 | - setValue(adj, sp_pixels_get_units (val, *unit)); |
4331 | + setValue(adj, Inkscape::Util::Quantity::convert(val, "px", unit)); |
4332 | |
4333 | return; |
4334 | } |
4335 | @@ -1955,9 +1934,9 @@ |
4336 | #endif |
4337 | { |
4338 | float value = getValue( adj); |
4339 | - const SPUnit *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unit_selector->gobj())); |
4340 | + const Unit unit = unit_selector->getUnit(); |
4341 | |
4342 | - return sp_units_get_pixels (value, *unit); |
4343 | + return Inkscape::Util::Quantity::convert(value, unit, "px"); |
4344 | } // end of sp_export_value_get_px() |
4345 | |
4346 | /** |
4347 | |
4348 | === modified file 'src/ui/dialog/export.h' |
4349 | --- src/ui/dialog/export.h 2013-03-16 12:20:26 +0000 |
4350 | +++ src/ui/dialog/export.h 2013-08-06 18:46:25 +0000 |
4351 | @@ -172,6 +172,11 @@ |
4352 | #endif |
4353 | |
4354 | /** |
4355 | + * Unit changed callback |
4356 | + */ |
4357 | + void onUnitChanged(); |
4358 | + |
4359 | + /** |
4360 | * Hide except selected callback |
4361 | */ |
4362 | void onHideExceptSelected (); |
4363 | @@ -330,7 +335,7 @@ |
4364 | |
4365 | /* Unit selector widgets */ |
4366 | Gtk::HBox unitbox; |
4367 | - Gtk::Widget* unit_selector; |
4368 | + Inkscape::UI::Widget::UnitMenu *unit_selector; |
4369 | Gtk::Label units_label; |
4370 | |
4371 | /* Filename widgets */ |
4372 | @@ -365,6 +370,7 @@ |
4373 | sigc::connection selectChangedConn; |
4374 | sigc::connection subselChangedConn; |
4375 | sigc::connection selectModifiedConn; |
4376 | + sigc::connection unitChangedConn; |
4377 | |
4378 | }; |
4379 | |
4380 | |
4381 | === modified file 'src/ui/dialog/guides.cpp' |
4382 | --- src/ui/dialog/guides.cpp 2013-03-09 17:43:14 +0000 |
4383 | +++ src/ui/dialog/guides.cpp 2013-08-06 18:46:25 +0000 |
4384 | @@ -230,7 +230,7 @@ |
4385 | _unit_menu.setUnitType(UNIT_TYPE_LINEAR); |
4386 | _unit_menu.setUnit("px"); |
4387 | if (_desktop->namedview->doc_units) { |
4388 | - _unit_menu.setUnit( sp_unit_get_abbreviation(_desktop->namedview->doc_units) ); |
4389 | + _unit_menu.setUnit( _desktop->namedview->doc_units->abbr ); |
4390 | } |
4391 | _spin_angle.setUnit(_angle_unit_status); |
4392 | |
4393 | |
4394 | === modified file 'src/ui/dialog/inkscape-preferences.cpp' |
4395 | --- src/ui/dialog/inkscape-preferences.cpp 2013-05-13 06:27:27 +0000 |
4396 | +++ src/ui/dialog/inkscape-preferences.cpp 2013-08-06 18:46:25 +0000 |
4397 | @@ -28,7 +28,7 @@ |
4398 | #include "preferences.h" |
4399 | #include "verbs.h" |
4400 | #include "selcue.h" |
4401 | -#include "unit-constants.h" |
4402 | +#include "util/units.h" |
4403 | #include <iostream> |
4404 | #include "enums.h" |
4405 | #include "desktop-handles.h" |
4406 | @@ -1428,10 +1428,10 @@ |
4407 | _("Automatically reload linked images when file is changed on disk")); |
4408 | _misc_bitmap_editor.init("/options/bitmapeditor/value", true); |
4409 | _page_bitmaps.add_line( false, _("_Bitmap editor:"), _misc_bitmap_editor, "", "", true); |
4410 | - _importexport_export_res.init("/dialogs/export/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false); |
4411 | + _importexport_export_res.init("/dialogs/export/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, Inkscape::Util::Quantity::convert(1, "in", "px"), true, false); |
4412 | _page_bitmaps.add_line( false, _("Default export _resolution:"), _importexport_export_res, _("dpi"), |
4413 | _("Default bitmap resolution (in dots per inch) in the Export dialog"), false); |
4414 | - _bitmap_copy_res.init("/options/createbitmap/resolution", 1.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false); |
4415 | + _bitmap_copy_res.init("/options/createbitmap/resolution", 1.0, 6000.0, 1.0, 1.0, Inkscape::Util::Quantity::convert(1, "in", "px"), true, false); |
4416 | _page_bitmaps.add_line( false, _("Resolution for Create Bitmap _Copy:"), _bitmap_copy_res, _("dpi"), |
4417 | _("Resolution used by the Create Bitmap Copy command"), false); |
4418 | { |
4419 | @@ -1443,7 +1443,7 @@ |
4420 | _bitmap_import_quality.init("/dialogs/import/quality", 1, 100, 1, 1, 100, true, false); |
4421 | _page_bitmaps.add_line( false, _("Bitmap import quality:"), _bitmap_import_quality, "%", "Bitmap import quality (jpeg only). 100 is best quality", false); |
4422 | } |
4423 | - _importexport_import_res.init("/dialogs/import/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false); |
4424 | + _importexport_import_res.init("/dialogs/import/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, Inkscape::Util::Quantity::convert(1, "in", "px"), true, false); |
4425 | _page_bitmaps.add_line( false, _("Default _import resolution:"), _importexport_import_res, _("dpi"), |
4426 | _("Default bitmap resolution (in dots per inch) for bitmap import"), false); |
4427 | _importexport_import_res_override.init(_("Override file resolution"), "/dialogs/import/forcexdpi", false); |
4428 | |
4429 | === modified file 'src/ui/dialog/print.cpp' |
4430 | --- src/ui/dialog/print.cpp 2012-10-28 14:10:22 +0000 |
4431 | +++ src/ui/dialog/print.cpp 2013-08-06 18:46:25 +0000 |
4432 | @@ -26,7 +26,7 @@ |
4433 | #include "ui/widget/rendering-options.h" |
4434 | #include "document.h" |
4435 | |
4436 | -#include "unit-constants.h" |
4437 | +#include "util/units.h" |
4438 | #include "helper/png-write.h" |
4439 | #include "svg/svg-color.h" |
4440 | #include "io/sys.h" |
4441 | @@ -72,8 +72,8 @@ |
4442 | |
4443 | sp_export_png_file(junk->_doc, tmp_png.c_str(), 0.0, 0.0, |
4444 | width, height, |
4445 | - (unsigned long)(width * dpi / PX_PER_IN), |
4446 | - (unsigned long)(height * dpi / PX_PER_IN), |
4447 | + (unsigned long)(width * dpi / Inkscape::Util::Quantity::convert(1, "in", "px")), |
4448 | + (unsigned long)(height * dpi / Inkscape::Util::Quantity::convert(1, "in", "px")), |
4449 | dpi, dpi, bgcolor, NULL, NULL, true, NULL); |
4450 | |
4451 | // This doesn't seem to work: |
4452 | @@ -90,7 +90,7 @@ |
4453 | cairo_t *cr = gtk_print_context_get_cairo_context (context); |
4454 | cairo_matrix_t m; |
4455 | cairo_get_matrix(cr, &m); |
4456 | - cairo_scale(cr, PT_PER_IN / dpi, PT_PER_IN / dpi); |
4457 | + cairo_scale(cr, Inkscape::Util::Quantity::convert(1, "in", "pt") / dpi, Inkscape::Util::Quantity::convert(1, "in", "pt") / dpi); |
4458 | // FIXME: why is the origin offset?? |
4459 | cairo_set_source_surface(cr, png->cobj(), -16.0, -16.0); |
4460 | cairo_paint(cr); |
4461 | @@ -195,8 +195,8 @@ |
4462 | // set up paper size to match the document size |
4463 | gtk_print_operation_set_unit (_printop, GTK_UNIT_POINTS); |
4464 | GtkPageSetup *page_setup = gtk_page_setup_new(); |
4465 | - gdouble doc_width = _doc->getWidth() * PT_PER_PX; |
4466 | - gdouble doc_height = _doc->getHeight() * PT_PER_PX; |
4467 | + gdouble doc_width = _doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt"); |
4468 | + gdouble doc_height = _doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt"); |
4469 | GtkPaperSize *paper_size; |
4470 | if (doc_width > doc_height) { |
4471 | gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE); |
4472 | |
4473 | === modified file 'src/ui/dialog/text-edit.cpp' |
4474 | --- src/ui/dialog/text-edit.cpp 2013-04-28 18:38:55 +0000 |
4475 | +++ src/ui/dialog/text-edit.cpp 2013-08-06 18:46:25 +0000 |
4476 | @@ -58,7 +58,7 @@ |
4477 | #include "widgets/font-selector.h" |
4478 | #include <glibmm/i18n.h> |
4479 | #include <glibmm/markup.h> |
4480 | -#include "unit-constants.h" |
4481 | +#include "util/units.h" |
4482 | #include "sp-textpath.h" |
4483 | |
4484 | namespace Inkscape { |
4485 | @@ -401,7 +401,7 @@ |
4486 | |
4487 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
4488 | int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); |
4489 | - double pt_size = sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit) * PT_PER_PX; |
4490 | + double pt_size = sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit) * Inkscape::Util::Quantity::convert(1, "px", "pt"); |
4491 | |
4492 | // Pango font size is in 1024ths of a point |
4493 | // C++11: Glib::ustring size = std::to_string( pt_size * PANGO_SCALE ); |
4494 | |
4495 | === modified file 'src/ui/tool/node.cpp' |
4496 | --- src/ui/tool/node.cpp 2012-10-13 21:38:45 +0000 |
4497 | +++ src/ui/tool/node.cpp 2013-08-06 18:46:25 +0000 |
4498 | @@ -22,7 +22,6 @@ |
4499 | #include "preferences.h" |
4500 | #include "snap.h" |
4501 | #include "snap-preferences.h" |
4502 | -#include "sp-metrics.h" |
4503 | #include "sp-namedview.h" |
4504 | #include "ui/control-manager.h" |
4505 | #include "ui/tool/control-point-selection.h" |
4506 | @@ -490,9 +489,13 @@ |
4507 | double angle = Geom::angle_between(Geom::Point(-1,0), position() - _parent->position()); |
4508 | angle += M_PI; // angle is (-M_PI...M_PI] - offset by +pi and scale to 0...360 |
4509 | angle *= 360.0 / (2 * M_PI); |
4510 | - GString *x = SP_PX_TO_METRIC_STRING(dist[Geom::X], _desktop->namedview->getDefaultMetric()); |
4511 | - GString *y = SP_PX_TO_METRIC_STRING(dist[Geom::Y], _desktop->namedview->getDefaultMetric()); |
4512 | - GString *len = SP_PX_TO_METRIC_STRING(length(), _desktop->namedview->getDefaultMetric()); |
4513 | + |
4514 | + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px"); |
4515 | + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px"); |
4516 | + Inkscape::Util::Quantity len_q = Inkscape::Util::Quantity(length(), "px"); |
4517 | + GString *x = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str()); |
4518 | + GString *y = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str()); |
4519 | + GString *len = g_string_new(len_q.string(*_desktop->namedview->doc_units).c_str()); |
4520 | Glib::ustring ret = format_tip(C_("Path handle tip", |
4521 | "Move handle by %s, %s; angle %.2f°, length %s"), x->str, y->str, angle, len->str); |
4522 | g_string_free(x, TRUE); |
4523 | @@ -1294,8 +1297,11 @@ |
4524 | Glib::ustring Node::_getDragTip(GdkEventMotion */*event*/) const |
4525 | { |
4526 | Geom::Point dist = position() - _last_drag_origin(); |
4527 | - GString *x = SP_PX_TO_METRIC_STRING(dist[Geom::X], _desktop->namedview->getDefaultMetric()); |
4528 | - GString *y = SP_PX_TO_METRIC_STRING(dist[Geom::Y], _desktop->namedview->getDefaultMetric()); |
4529 | + |
4530 | + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px"); |
4531 | + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px"); |
4532 | + GString *x = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str()); |
4533 | + GString *y = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str()); |
4534 | Glib::ustring ret = format_tip(C_("Path node tip", "Move node by %s, %s"), |
4535 | x->str, y->str); |
4536 | g_string_free(x, TRUE); |
4537 | |
4538 | === modified file 'src/ui/widget/Makefile_insert' |
4539 | --- src/ui/widget/Makefile_insert 2013-01-08 12:06:44 +0000 |
4540 | +++ src/ui/widget/Makefile_insert 2013-08-06 18:46:25 +0000 |
4541 | @@ -79,5 +79,7 @@ |
4542 | ui/widget/tolerance-slider.cpp \ |
4543 | ui/widget/tolerance-slider.h \ |
4544 | ui/widget/unit-menu.cpp \ |
4545 | - ui/widget/unit-menu.h |
4546 | + ui/widget/unit-menu.h \ |
4547 | + ui/widget/unit-tracker.h \ |
4548 | + ui/widget/unit-tracker.cpp |
4549 | |
4550 | |
4551 | === modified file 'src/ui/widget/page-sizer.cpp' |
4552 | --- src/ui/widget/page-sizer.cpp 2013-07-01 20:04:32 +0000 |
4553 | +++ src/ui/widget/page-sizer.cpp 2013-08-06 18:46:25 +0000 |
4554 | @@ -37,7 +37,7 @@ |
4555 | #include "desktop.h" |
4556 | #include "helper/action.h" |
4557 | #include "helper/action-context.h" |
4558 | -#include "helper/units.h" |
4559 | +#include "util/units.h" |
4560 | #include "inkscape.h" |
4561 | #include "sp-namedview.h" |
4562 | #include "sp-root.h" |
4563 | @@ -48,6 +48,7 @@ |
4564 | #include "xml/repr.h" |
4565 | |
4566 | using std::pair; |
4567 | +using Inkscape::Util::unit_table; |
4568 | |
4569 | namespace Inkscape { |
4570 | namespace UI { |
4571 | @@ -96,7 +97,7 @@ |
4572 | char const * const name; //name |
4573 | double const smaller; //lesser dimension |
4574 | double const larger; //greater dimension |
4575 | - SPUnitId const unit; //units |
4576 | + Glib::ustring const unit; //units |
4577 | }; |
4578 | |
4579 | // list of page formats that should be in landscape automatically |
4580 | @@ -114,31 +115,31 @@ |
4581 | } |
4582 | |
4583 | static PaperSizeRec const inkscape_papers[] = { |
4584 | - { "A4", 210, 297, SP_UNIT_MM }, |
4585 | - { "US Letter", 8.5, 11, SP_UNIT_IN }, |
4586 | - { "US Legal", 8.5, 14, SP_UNIT_IN }, |
4587 | - { "US Executive", 7.25, 10.5, SP_UNIT_IN }, |
4588 | - { "A0", 841, 1189, SP_UNIT_MM }, |
4589 | - { "A1", 594, 841, SP_UNIT_MM }, |
4590 | - { "A2", 420, 594, SP_UNIT_MM }, |
4591 | - { "A3", 297, 420, SP_UNIT_MM }, |
4592 | - { "A5", 148, 210, SP_UNIT_MM }, |
4593 | - { "A6", 105, 148, SP_UNIT_MM }, |
4594 | - { "A7", 74, 105, SP_UNIT_MM }, |
4595 | - { "A8", 52, 74, SP_UNIT_MM }, |
4596 | - { "A9", 37, 52, SP_UNIT_MM }, |
4597 | - { "A10", 26, 37, SP_UNIT_MM }, |
4598 | - { "B0", 1000, 1414, SP_UNIT_MM }, |
4599 | - { "B1", 707, 1000, SP_UNIT_MM }, |
4600 | - { "B2", 500, 707, SP_UNIT_MM }, |
4601 | - { "B3", 353, 500, SP_UNIT_MM }, |
4602 | - { "B4", 250, 353, SP_UNIT_MM }, |
4603 | - { "B5", 176, 250, SP_UNIT_MM }, |
4604 | - { "B6", 125, 176, SP_UNIT_MM }, |
4605 | - { "B7", 88, 125, SP_UNIT_MM }, |
4606 | - { "B8", 62, 88, SP_UNIT_MM }, |
4607 | - { "B9", 44, 62, SP_UNIT_MM }, |
4608 | - { "B10", 31, 44, SP_UNIT_MM }, |
4609 | + { "A4", 210, 297, "mm" }, |
4610 | + { "US Letter", 8.5, 11, "in" }, |
4611 | + { "US Legal", 8.5, 14, "in" }, |
4612 | + { "US Executive", 7.25, 10.5, "in" }, |
4613 | + { "A0", 841, 1189, "mm" }, |
4614 | + { "A1", 594, 841, "mm" }, |
4615 | + { "A2", 420, 594, "mm" }, |
4616 | + { "A3", 297, 420, "mm" }, |
4617 | + { "A5", 148, 210, "mm" }, |
4618 | + { "A6", 105, 148, "mm" }, |
4619 | + { "A7", 74, 105, "mm" }, |
4620 | + { "A8", 52, 74, "mm" }, |
4621 | + { "A9", 37, 52, "mm" }, |
4622 | + { "A10", 26, 37, "mm" }, |
4623 | + { "B0", 1000, 1414, "mm" }, |
4624 | + { "B1", 707, 1000, "mm" }, |
4625 | + { "B2", 500, 707, "mm" }, |
4626 | + { "B3", 353, 500, "mm" }, |
4627 | + { "B4", 250, 353, "mm" }, |
4628 | + { "B5", 176, 250, "mm" }, |
4629 | + { "B6", 125, 176, "mm" }, |
4630 | + { "B7", 88, 125, "mm" }, |
4631 | + { "B8", 62, 88, "mm" }, |
4632 | + { "B9", 44, 62, "mm" }, |
4633 | + { "B10", 31, 44, "mm" }, |
4634 | |
4635 | |
4636 | |
4637 | @@ -150,63 +151,63 @@ |
4638 | don't know what D and E series are used for. |
4639 | */ |
4640 | |
4641 | - { "C0", 917, 1297, SP_UNIT_MM }, |
4642 | - { "C1", 648, 917, SP_UNIT_MM }, |
4643 | - { "C2", 458, 648, SP_UNIT_MM }, |
4644 | - { "C3", 324, 458, SP_UNIT_MM }, |
4645 | - { "C4", 229, 324, SP_UNIT_MM }, |
4646 | - { "C5", 162, 229, SP_UNIT_MM }, |
4647 | - { "C6", 114, 162, SP_UNIT_MM }, |
4648 | - { "C7", 81, 114, SP_UNIT_MM }, |
4649 | - { "C8", 57, 81, SP_UNIT_MM }, |
4650 | - { "C9", 40, 57, SP_UNIT_MM }, |
4651 | - { "C10", 28, 40, SP_UNIT_MM }, |
4652 | - { "D1", 545, 771, SP_UNIT_MM }, |
4653 | - { "D2", 385, 545, SP_UNIT_MM }, |
4654 | - { "D3", 272, 385, SP_UNIT_MM }, |
4655 | - { "D4", 192, 272, SP_UNIT_MM }, |
4656 | - { "D5", 136, 192, SP_UNIT_MM }, |
4657 | - { "D6", 96, 136, SP_UNIT_MM }, |
4658 | - { "D7", 68, 96, SP_UNIT_MM }, |
4659 | - { "E3", 400, 560, SP_UNIT_MM }, |
4660 | - { "E4", 280, 400, SP_UNIT_MM }, |
4661 | - { "E5", 200, 280, SP_UNIT_MM }, |
4662 | - { "E6", 140, 200, SP_UNIT_MM }, |
4663 | + { "C0", 917, 1297, "mm" }, |
4664 | + { "C1", 648, 917, "mm" }, |
4665 | + { "C2", 458, 648, "mm" }, |
4666 | + { "C3", 324, 458, "mm" }, |
4667 | + { "C4", 229, 324, "mm" }, |
4668 | + { "C5", 162, 229, "mm" }, |
4669 | + { "C6", 114, 162, "mm" }, |
4670 | + { "C7", 81, 114, "mm" }, |
4671 | + { "C8", 57, 81, "mm" }, |
4672 | + { "C9", 40, 57, "mm" }, |
4673 | + { "C10", 28, 40, "mm" }, |
4674 | + { "D1", 545, 771, "mm" }, |
4675 | + { "D2", 385, 545, "mm" }, |
4676 | + { "D3", 272, 385, "mm" }, |
4677 | + { "D4", 192, 272, "mm" }, |
4678 | + { "D5", 136, 192, "mm" }, |
4679 | + { "D6", 96, 136, "mm" }, |
4680 | + { "D7", 68, 96, "mm" }, |
4681 | + { "E3", 400, 560, "mm" }, |
4682 | + { "E4", 280, 400, "mm" }, |
4683 | + { "E5", 200, 280, "mm" }, |
4684 | + { "E6", 140, 200, "mm" }, |
4685 | //#endif |
4686 | |
4687 | |
4688 | |
4689 | - { "CSE", 462, 649, SP_UNIT_PT }, |
4690 | - { "US #10 Envelope", 4.125, 9.5, SP_UNIT_IN }, |
4691 | + { "CSE", 462, 649, "pt" }, |
4692 | + { "US #10 Envelope", 4.125, 9.5, "in" }, |
4693 | /* See http://www.hbp.com/content/PCR_envelopes.cfm for a much larger list of US envelope |
4694 | sizes. */ |
4695 | - { "DL Envelope", 110, 220, SP_UNIT_MM }, |
4696 | - { "Ledger/Tabloid", 11, 17, SP_UNIT_IN }, |
4697 | + { "DL Envelope", 110, 220, "mm" }, |
4698 | + { "Ledger/Tabloid", 11, 17, "in" }, |
4699 | /* Note that `Folio' (used in QPrinter/KPrinter) is deliberately absent from this list, as it |
4700 | means different sizes to different people: different people may expect the width to be |
4701 | either 8, 8.25 or 8.5 inches, and the height to be either 13 or 13.5 inches, even |
4702 | restricting our interpretation to foolscap folio. If you wish to introduce a folio-like |
4703 | page size to the list, then please consider using a name more specific than just `Folio' or |
4704 | `Foolscap Folio'. */ |
4705 | - { "Banner 468x60", 60, 468, SP_UNIT_PX }, |
4706 | - { "Icon 16x16", 16, 16, SP_UNIT_PX }, |
4707 | - { "Icon 32x32", 32, 32, SP_UNIT_PX }, |
4708 | - { "Icon 48x48", 48, 48, SP_UNIT_PX }, |
4709 | + { "Banner 468x60", 60, 468, "px" }, |
4710 | + { "Icon 16x16", 16, 16, "px" }, |
4711 | + { "Icon 32x32", 32, 32, "px" }, |
4712 | + { "Icon 48x48", 48, 48, "px" }, |
4713 | /* business cards */ |
4714 | - { "Business Card (ISO 7810)", 53.98, 85.60, SP_UNIT_MM }, |
4715 | - { "Business Card (US)", 2, 3.5, SP_UNIT_IN }, |
4716 | - { "Business Card (Europe)", 55, 85, SP_UNIT_MM }, |
4717 | - { "Business Card (Aus/NZ)", 55, 90, SP_UNIT_MM }, |
4718 | + { "Business Card (ISO 7810)", 53.98, 85.60, "mm" }, |
4719 | + { "Business Card (US)", 2, 3.5, "in" }, |
4720 | + { "Business Card (Europe)", 55, 85, "mm" }, |
4721 | + { "Business Card (Aus/NZ)", 55, 90, "mm" }, |
4722 | |
4723 | // Start Arch Series List |
4724 | |
4725 | |
4726 | - { "Arch A", 9, 12, SP_UNIT_IN }, // 229 x 305 mm |
4727 | - { "Arch B", 12, 18, SP_UNIT_IN }, // 305 x 457 mm |
4728 | - { "Arch C", 18, 24, SP_UNIT_IN }, // 457 x 610 mm |
4729 | - { "Arch D", 24, 36, SP_UNIT_IN }, // 610 x 914 mm |
4730 | - { "Arch E", 36, 48, SP_UNIT_IN }, // 914 x 1219 mm |
4731 | - { "Arch E1", 30, 42, SP_UNIT_IN }, // 762 x 1067 mm |
4732 | + { "Arch A", 9, 12, "in" }, // 229 x 305 mm |
4733 | + { "Arch B", 12, 18, "in" }, // 305 x 457 mm |
4734 | + { "Arch C", 18, 24, "in" }, // 457 x 610 mm |
4735 | + { "Arch D", 24, 36, "in" }, // 610 x 914 mm |
4736 | + { "Arch E", 36, 48, "in" }, // 914 x 1219 mm |
4737 | + { "Arch E1", 30, 42, "in" }, // 762 x 1067 mm |
4738 | |
4739 | /* |
4740 | * The above list of Arch sizes were taken from the following site: |
4741 | @@ -217,7 +218,7 @@ |
4742 | * September 2009 - DAK |
4743 | */ |
4744 | |
4745 | - { NULL, 0, 0, SP_UNIT_PX }, |
4746 | + { NULL, 0, 0, "px" }, |
4747 | }; |
4748 | |
4749 | |
4750 | @@ -226,10 +227,6 @@ |
4751 | //# P A G E S I Z E R |
4752 | //######################################################################## |
4753 | |
4754 | -//The default unit for this widget and its calculations |
4755 | -static const SPUnit _px_unit = sp_unit_get_by_id (SP_UNIT_PX); |
4756 | - |
4757 | - |
4758 | /** |
4759 | * Constructor |
4760 | */ |
4761 | @@ -280,13 +277,8 @@ |
4762 | char formatBuf[80]; |
4763 | snprintf(formatBuf, 79, "%0.1f x %0.1f", p->smaller, p->larger); |
4764 | Glib::ustring desc = formatBuf; |
4765 | - if (p->unit == SP_UNIT_IN) |
4766 | - desc.append(" in"); |
4767 | - else if (p->unit == SP_UNIT_MM) |
4768 | - desc.append(" mm"); |
4769 | - else if (p->unit == SP_UNIT_PX) |
4770 | - desc.append(" px"); |
4771 | - PaperSize paper(name, p->smaller, p->larger, p->unit); |
4772 | + desc.append(" " + p->unit); |
4773 | + PaperSize paper(name, p->smaller, p->larger, unit_table.getUnit(p->unit)); |
4774 | _paperSizeTable[name] = paper; |
4775 | Gtk::TreeModel::Row row = *(_paperSizeListStore->append()); |
4776 | row[_paperSizeListColumns.nameColumn] = name; |
4777 | @@ -320,9 +312,9 @@ |
4778 | SPNamedView *nv = sp_desktop_namedview(dt); |
4779 | _wr.setUpdating (true); |
4780 | if (nv->units) { |
4781 | - _dimensionUnits.setUnit(nv->units); |
4782 | + _dimensionUnits.setUnit(nv->units->abbr); |
4783 | } else if (nv->doc_units) { |
4784 | - _dimensionUnits.setUnit(nv->doc_units); |
4785 | + _dimensionUnits.setUnit(nv->doc_units->abbr); |
4786 | } |
4787 | _wr.setUpdating (false); |
4788 | |
4789 | @@ -484,8 +476,8 @@ |
4790 | if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) { |
4791 | SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP); |
4792 | double const old_height = doc->getHeight(); |
4793 | - doc->setWidth (w, &_px_unit); |
4794 | - doc->setHeight (h, &_px_unit); |
4795 | + doc->setWidth (Inkscape::Util::Quantity(w, "px")); |
4796 | + doc->setHeight (Inkscape::Util::Quantity(h, "px")); |
4797 | // The origin for the user is in the lower left corner; this point should remain stationary when |
4798 | // changing the page size. The SVG's origin however is in the upper left corner, so we must compensate for this |
4799 | Geom::Translate const vert_offset(Geom::Point(0, (old_height - h))); |
4800 | @@ -569,9 +561,9 @@ |
4801 | for (iter = _paperSizeTable.begin() ; |
4802 | iter != _paperSizeTable.end() ; ++iter) { |
4803 | PaperSize paper = iter->second; |
4804 | - SPUnit const &i_unit = sp_unit_get_by_id(paper.unit); |
4805 | - double smallX = sp_units_get_pixels(paper.smaller, i_unit); |
4806 | - double largeX = sp_units_get_pixels(paper.larger, i_unit); |
4807 | + Inkscape::Util::Unit const &i_unit = paper.unit; |
4808 | + double smallX = Inkscape::Util::Quantity::convert(paper.smaller, i_unit, "px"); |
4809 | + double largeX = Inkscape::Util::Quantity::convert(paper.larger, i_unit, "px"); |
4810 | |
4811 | g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end()); |
4812 | |
4813 | @@ -662,9 +654,8 @@ |
4814 | _landscape = _landscapeButton.get_active(); |
4815 | } |
4816 | |
4817 | - SPUnit const &src_unit = sp_unit_get_by_id (paper.unit); |
4818 | - sp_convert_distance (&w, &src_unit, &_px_unit); |
4819 | - sp_convert_distance (&h, &src_unit, &_px_unit); |
4820 | + w = Inkscape::Util::Quantity::convert(w, paper.unit, "px"); |
4821 | + h = Inkscape::Util::Quantity::convert(h, paper.unit, "px"); |
4822 | |
4823 | if (_landscape) |
4824 | setDim (h, w, false); |
4825 | |
4826 | === modified file 'src/ui/widget/page-sizer.h' |
4827 | --- src/ui/widget/page-sizer.h 2012-12-16 11:57:38 +0000 |
4828 | +++ src/ui/widget/page-sizer.h 2013-08-06 18:46:25 +0000 |
4829 | @@ -18,7 +18,7 @@ |
4830 | #include "ui/widget/registered-widget.h" |
4831 | #include <sigc++/sigc++.h> |
4832 | |
4833 | -#include "helper/units.h" |
4834 | +#include "util/units.h" |
4835 | |
4836 | #include <gtkmm/alignment.h> |
4837 | #include <gtkmm/expander.h> |
4838 | @@ -64,7 +64,7 @@ |
4839 | PaperSize(const Glib::ustring &nameArg, |
4840 | double smallerArg, |
4841 | double largerArg, |
4842 | - SPUnitId unitArg) |
4843 | + Inkscape::Util::Unit unitArg) |
4844 | { |
4845 | name = nameArg; |
4846 | smaller = smallerArg; |
4847 | @@ -108,7 +108,7 @@ |
4848 | /** |
4849 | * The units (px, pt, mm, etc) of this specification |
4850 | */ |
4851 | - SPUnitId unit; |
4852 | + Inkscape::Util::Unit unit; |
4853 | |
4854 | private: |
4855 | |
4856 | @@ -117,7 +117,7 @@ |
4857 | name = ""; |
4858 | smaller = 0.0; |
4859 | larger = 0.0; |
4860 | - unit = SP_UNIT_PX; |
4861 | + unit = unit_table.getUnit("px"); |
4862 | } |
4863 | |
4864 | void assign(const PaperSize &other) |
4865 | |
4866 | === modified file 'src/ui/widget/registered-widget.cpp' |
4867 | --- src/ui/widget/registered-widget.cpp 2012-04-28 15:49:30 +0000 |
4868 | +++ src/ui/widget/registered-widget.cpp 2013-08-06 18:46:25 +0000 |
4869 | @@ -27,7 +27,6 @@ |
4870 | #include "ui/widget/random.h" |
4871 | #include "widgets/spinbutton-events.h" |
4872 | |
4873 | -#include "helper/units.h" |
4874 | #include "xml/repr.h" |
4875 | #include "svg/svg-color.h" |
4876 | #include "svg/stringstream.h" |
4877 | @@ -118,9 +117,9 @@ |
4878 | } |
4879 | |
4880 | void |
4881 | -RegisteredUnitMenu::setUnit (const SPUnit* unit) |
4882 | +RegisteredUnitMenu::setUnit (Glib::ustring unit) |
4883 | { |
4884 | - getUnitMenu()->setUnit (sp_unit_get_abbreviation (unit)); |
4885 | + getUnitMenu()->setUnit(unit); |
4886 | } |
4887 | |
4888 | void |
4889 | |
4890 | === modified file 'src/ui/widget/registered-widget.h' |
4891 | --- src/ui/widget/registered-widget.h 2013-08-03 20:45:01 +0000 |
4892 | +++ src/ui/widget/registered-widget.h 2013-08-06 18:46:25 +0000 |
4893 | @@ -32,7 +32,6 @@ |
4894 | |
4895 | #include <gtkmm/checkbutton.h> |
4896 | |
4897 | -struct SPUnit; |
4898 | class SPDocument; |
4899 | |
4900 | namespace Gtk { |
4901 | @@ -167,7 +166,7 @@ |
4902 | Inkscape::XML::Node* repr_in = NULL, |
4903 | SPDocument *doc_in = NULL ); |
4904 | |
4905 | - void setUnit (const SPUnit*); |
4906 | + void setUnit (const Glib::ustring); |
4907 | Unit getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); }; |
4908 | UnitMenu* getUnitMenu() const { return static_cast<UnitMenu*>(_widget); }; |
4909 | sigc::connection _changed_connection; |
4910 | |
4911 | === modified file 'src/ui/widget/rendering-options.cpp' |
4912 | --- src/ui/widget/rendering-options.cpp 2013-03-25 17:42:31 +0000 |
4913 | +++ src/ui/widget/rendering-options.cpp 2013-08-06 18:46:25 +0000 |
4914 | @@ -13,7 +13,7 @@ |
4915 | #endif |
4916 | |
4917 | #include "rendering-options.h" |
4918 | -#include "unit-constants.h" |
4919 | +#include "util/units.h" |
4920 | #include <glibmm/i18n.h> |
4921 | |
4922 | namespace Inkscape { |
4923 | @@ -59,8 +59,8 @@ |
4924 | _radio_bitmap.signal_toggled().connect(sigc::mem_fun(*this, &RenderingOptions::_toggled)); |
4925 | |
4926 | // configure default DPI |
4927 | - _dpi.setRange(PT_PER_IN,2400.0); |
4928 | - _dpi.setValue(PT_PER_IN); |
4929 | + _dpi.setRange(Inkscape::Util::Quantity::convert(1, "in", "pt"),2400.0); |
4930 | + _dpi.setValue(Inkscape::Util::Quantity::convert(1, "in", "pt")); |
4931 | _dpi.setIncrements(1.0,10.0); |
4932 | _dpi.setDigits(0); |
4933 | _dpi.update(); |
4934 | |
4935 | === modified file 'src/ui/widget/scalar-unit.cpp' |
4936 | --- src/ui/widget/scalar-unit.cpp 2011-10-27 04:55:51 +0000 |
4937 | +++ src/ui/widget/scalar-unit.cpp 2013-08-06 18:46:25 +0000 |
4938 | @@ -16,6 +16,8 @@ |
4939 | #include "scalar-unit.h" |
4940 | #include "spinbutton.h" |
4941 | |
4942 | +using Inkscape::Util::unit_table; |
4943 | + |
4944 | namespace Inkscape { |
4945 | namespace UI { |
4946 | namespace Widget { |
4947 | @@ -226,9 +228,8 @@ |
4948 | Glib::ustring abbr = _unit_menu->getUnitAbbr(); |
4949 | _suffix->set_label(abbr); |
4950 | |
4951 | - Inkscape::Util::UnitTable &table = _unit_menu->getUnitTable(); |
4952 | - Inkscape::Util::Unit new_unit = (table.getUnit(abbr)); |
4953 | - Inkscape::Util::Unit old_unit = (table.getUnit(lastUnits)); |
4954 | + Inkscape::Util::Unit new_unit = (unit_table.getUnit(abbr)); |
4955 | + Inkscape::Util::Unit old_unit = (unit_table.getUnit(lastUnits)); |
4956 | |
4957 | double convertedVal = 0; |
4958 | if (old_unit.type == UNIT_TYPE_DIMENSIONLESS && new_unit.type == UNIT_TYPE_LINEAR) { |
4959 | |
4960 | === modified file 'src/ui/widget/selected-style.cpp' |
4961 | --- src/ui/widget/selected-style.cpp 2013-03-09 13:24:32 +0000 |
4962 | +++ src/ui/widget/selected-style.cpp 2013-08-06 18:46:25 +0000 |
4963 | @@ -50,6 +50,9 @@ |
4964 | #include "pixmaps/cursor-adj-a.xpm" |
4965 | #include "sp-cursor.h" |
4966 | #include "gradient-chemistry.h" |
4967 | +#include "util/units.h" |
4968 | + |
4969 | +using Inkscape::Util::unit_table; |
4970 | |
4971 | static gdouble const _sw_presets[] = { 32 , 16 , 10 , 8 , 6 , 4 , 3 , 2 , 1.5 , 1 , 0.75 , 0.5 , 0.25 , 0.1 }; |
4972 | static gchar const *const _sw_presets_str[] = {"32", "16", "10", "8", "6", "4", "3", "2", "1.5", "1", "0.75", "0.5", "0.25", "0.1"}; |
4973 | @@ -306,15 +309,17 @@ |
4974 | { |
4975 | int row = 0; |
4976 | |
4977 | - // List of units should match with Fill/Stroke dialog stroke style width list |
4978 | - for (GSList *l = sp_unit_get_list(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); l != NULL; l = l->next) { |
4979 | - SPUnit const *u = static_cast<SPUnit*>(l->data); |
4980 | + Inkscape::Util::UnitTable::UnitMap m = unit_table.units(Inkscape::Util::UNIT_TYPE_LINEAR); |
4981 | + Inkscape::Util::UnitTable::UnitMap::iterator iter = m.begin(); |
4982 | + while(iter != m.end()) { |
4983 | Gtk::RadioMenuItem *mi = Gtk::manage(new Gtk::RadioMenuItem(_sw_group)); |
4984 | - mi->add(*(new Gtk::Label(u->abbr, 0.0, 0.5))); |
4985 | + mi->add(*(new Gtk::Label((*iter).first, 0.0, 0.5))); |
4986 | _unit_mis = g_slist_append(_unit_mis, mi); |
4987 | - mi->signal_activate().connect(sigc::bind<SPUnitId>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u->unit_id)); |
4988 | + Inkscape::Util::Unit const *u = new Inkscape::Util::Unit(unit_table.getUnit(iter->first)); |
4989 | + mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), *u)); |
4990 | _popup_sw.attach(*mi, 0,1, row, row+1); |
4991 | row++; |
4992 | + ++iter; |
4993 | } |
4994 | |
4995 | _popup_sw.attach(*(new Gtk::SeparatorMenuItem()), 0,1, row, row+1); |
4996 | @@ -476,13 +481,13 @@ |
4997 | this ) |
4998 | )); |
4999 | |
5000 | - _sw_unit = const_cast<SPUnit*>(sp_desktop_namedview(desktop)->doc_units); |
The diff has been truncated for viewing.
Hi Matthew - the merge of this branch has introduced a couple of regressions in trunk (3 reported so far):
- Bug #1215104: Inkscape crashes when exporting PNG if default unit is different than "px" /bugs.launchpad .net/inkscape/ +bug/1215104> /bugs.launchpad .net/inkscape/ +bug/1215575> /bugs.launchpad .net/inkscape/ +bug/1216306>
<https:/
- Bug #1215575: Manual text kerning not working since r12471
<https:/
- Bug #1216306: Grid parameters not working with comma as decimal separator
<https:/
I just tested your current branch for phase two (<lp:~matthewpetroff/inkscape/gsoc-2013-unit-improvement> r12484), and - since all of them are still reproducible - wanted to make you aware of these issues.