Merge lp:~matthewpetroff/inkscape/gsoc-2013-unit-refactor into lp:~inkscape.dev/inkscape/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
Reviewer Review Type Date Requested Status
Inkscape Developers Pending
Review via email: mp+178151@code.launchpad.net

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 :

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"
  <https://bugs.launchpad.net/inkscape/+bug/1215104>
- Bug #1215575: Manual text kerning not working since r12471
  <https://bugs.launchpad.net/inkscape/+bug/1215575>
- Bug #1216306: Grid parameters not working with comma as decimal separator
  <https://bugs.launchpad.net/inkscape/+bug/1216306>

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.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'AUTHORS'
--- AUTHORS 2013-07-18 11:21:06 +0000
+++ AUTHORS 2013-08-06 18:46:25 +0000
@@ -121,6 +121,7 @@
121Mitsuru Oka121Mitsuru Oka
122Martin Owens122Martin Owens
123Alvin Penner123Alvin Penner
124Matthew Petroff
124Jon Phillips125Jon Phillips
125Zdenko Podobny126Zdenko Podobny
126Alexandre Prokoudine127Alexandre Prokoudine
127128
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2013-07-23 17:01:25 +0000
+++ src/CMakeLists.txt 2013-08-06 18:46:25 +0000
@@ -46,7 +46,6 @@
46 sp-mesh-patch.cpp46 sp-mesh-patch.cpp
47 sp-mesh-row.cpp47 sp-mesh-row.cpp
48 sp-metadata.cpp48 sp-metadata.cpp
49 sp-metrics.cpp
50 sp-missing-glyph.cpp49 sp-missing-glyph.cpp
51 sp-namedview.cpp50 sp-namedview.cpp
52 sp-object-group.cpp51 sp-object-group.cpp
@@ -136,8 +135,6 @@
136 sp-mesh-row-fns.h135 sp-mesh-row-fns.h
137 sp-mesh-row.h136 sp-mesh-row.h
138 sp-metadata.h137 sp-metadata.h
139 sp-metric.h
140 sp-metrics.h
141 sp-missing-glyph.h138 sp-missing-glyph.h
142 sp-namedview.h139 sp-namedview.h
143 sp-object-group.h140 sp-object-group.h
@@ -484,7 +481,6 @@
484 unclump.h481 unclump.h
485 undo-stack-observer.h482 undo-stack-observer.h
486 unicoderange.h483 unicoderange.h
487 unit-constants.h
488 uri-references.h484 uri-references.h
489 uri.h485 uri.h
490 vanishing-point.h486 vanishing-point.h
491487
=== modified file 'src/Makefile_insert'
--- src/Makefile_insert 2013-08-03 15:35:41 +0000
+++ src/Makefile_insert 2013-08-06 18:46:25 +0000
@@ -198,8 +198,6 @@
198 sp-mesh-patch.cpp sp-mesh-patch.h \198 sp-mesh-patch.cpp sp-mesh-patch.h \
199 sp-mesh-row-fns.h \199 sp-mesh-row-fns.h \
200 sp-mesh-row.cpp sp-mesh-row.h \200 sp-mesh-row.cpp sp-mesh-row.h \
201 sp-metric.h \
202 sp-metrics.cpp sp-metrics.h \
203 sp-missing-glyph.cpp sp-missing-glyph.h \201 sp-missing-glyph.cpp sp-missing-glyph.h \
204 sp-namedview.cpp sp-namedview.h \202 sp-namedview.cpp sp-namedview.h \
205 sp-object.cpp sp-object.h \203 sp-object.cpp sp-object.h \
@@ -252,7 +250,6 @@
252 unclump.cpp unclump.h \250 unclump.cpp unclump.h \
253 undo-stack-observer.h \251 undo-stack-observer.h \
254 unicoderange.cpp unicoderange.h \252 unicoderange.cpp unicoderange.h \
255 unit-constants.h \
256 uri.cpp uri.h \253 uri.cpp uri.h \
257 uri-references.cpp uri-references.h \254 uri-references.cpp uri-references.h \
258 vanishing-point.cpp vanishing-point.h \255 vanishing-point.cpp vanishing-point.h \
259256
=== modified file 'src/arc-context.cpp'
--- src/arc-context.cpp 2013-04-28 22:48:03 +0000
+++ src/arc-context.cpp 2013-08-06 18:46:25 +0000
@@ -32,7 +32,6 @@
32#include "desktop-handles.h"32#include "desktop-handles.h"
33#include "snap.h"33#include "snap.h"
34#include "pixmaps/cursor-ellipse.xpm"34#include "pixmaps/cursor-ellipse.xpm"
35#include "sp-metrics.h"
36#include "xml/repr.h"35#include "xml/repr.h"
37#include "xml/node-event-vector.h"36#include "xml/node-event-vector.h"
38#include "preferences.h"37#include "preferences.h"
@@ -450,8 +449,10 @@
450449
451 double rdimx = r.dimensions()[Geom::X];450 double rdimx = r.dimensions()[Geom::X];
452 double rdimy = r.dimensions()[Geom::Y];451 double rdimy = r.dimensions()[Geom::Y];
453 GString *xs = SP_PX_TO_METRIC_STRING(rdimx, desktop->namedview->getDefaultMetric());452 Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px");
454 GString *ys = SP_PX_TO_METRIC_STRING(rdimy, desktop->namedview->getDefaultMetric());453 Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px");
454 GString *xs = g_string_new(rdimx_q.string(*desktop->namedview->doc_units).c_str());
455 GString *ys = g_string_new(rdimy_q.string(*desktop->namedview->doc_units).c_str());
455 if (state & GDK_CONTROL_MASK) {456 if (state & GDK_CONTROL_MASK) {
456 int ratio_x, ratio_y;457 int ratio_x, ratio_y;
457 if (fabs (rdimx) > fabs (rdimy)) {458 if (fabs (rdimx) > fabs (rdimy)) {
458459
=== modified file 'src/box3d-context.cpp'
--- src/box3d-context.cpp 2013-04-28 22:48:03 +0000
+++ src/box3d-context.cpp 2013-08-06 18:46:25 +0000
@@ -35,7 +35,6 @@
35#include "pixmaps/cursor-3dbox.xpm"35#include "pixmaps/cursor-3dbox.xpm"
36#include "box3d.h"36#include "box3d.h"
37#include "box3d-context.h"37#include "box3d-context.h"
38#include "sp-metrics.h"
39#include <glibmm/i18n.h>38#include <glibmm/i18n.h>
40#include "xml/repr.h"39#include "xml/repr.h"
41#include "xml/node-event-vector.h"40#include "xml/node-event-vector.h"
4241
=== modified file 'src/desktop-events.cpp'
--- src/desktop-events.cpp 2013-03-25 17:42:31 +0000
+++ src/desktop-events.cpp 2013-08-06 18:46:25 +0000
@@ -34,14 +34,11 @@
34#include "document-undo.h"34#include "document-undo.h"
35#include "event-context.h"35#include "event-context.h"
36#include "helper/action.h"36#include "helper/action.h"
37#include "helper/unit-menu.h"
38#include "helper/units.h"
39#include "message-context.h"37#include "message-context.h"
40#include "preferences.h"38#include "preferences.h"
41#include "snap.h"39#include "snap.h"
42#include "display/sp-canvas.h"40#include "display/sp-canvas.h"
43#include "sp-guide.h"41#include "sp-guide.h"
44#include "sp-metrics.h"
45#include "sp-namedview.h"42#include "sp-namedview.h"
46#include "tools-switch.h"43#include "tools-switch.h"
47#include "verbs.h"44#include "verbs.h"
4845
=== modified file 'src/desktop.cpp'
--- src/desktop.cpp 2013-07-04 14:01:44 +0000
+++ src/desktop.cpp 2013-08-06 18:46:25 +0000
@@ -54,7 +54,6 @@
54#include "document.h"54#include "document.h"
55#include "event-log.h"55#include "event-log.h"
56#include "helper/action-context.h"56#include "helper/action-context.h"
57#include "helper/units.h"
58#include "interface.h"57#include "interface.h"
59#include "inkscape-private.h"58#include "inkscape-private.h"
60#include "layer-fns.h"59#include "layer-fns.h"
6160
=== modified file 'src/display/canvas-axonomgrid.cpp'
--- src/display/canvas-axonomgrid.cpp 2013-06-06 13:44:11 +0000
+++ src/display/canvas-axonomgrid.cpp 2013-08-06 18:46:25 +0000
@@ -51,8 +51,9 @@
51#include "2geom/angle.h"51#include "2geom/angle.h"
52#include "util/mathfns.h"52#include "util/mathfns.h"
53#include "round.h"53#include "round.h"
54#include "helper/units.h"54#include "util/units.h"
5555
56using Inkscape::Util::unit_table;
5657
57enum Dim3 { X=0, Y, Z };58enum Dim3 { X=0, Y, Z };
5859
@@ -160,15 +161,15 @@
160 : CanvasGrid(nv, in_repr, in_doc, GRID_AXONOMETRIC)161 : CanvasGrid(nv, in_repr, in_doc, GRID_AXONOMETRIC)
161{162{
162 Inkscape::Preferences *prefs = Inkscape::Preferences::get();163 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
163 gridunit = sp_unit_get_by_abbreviation( prefs->getString("/options/grids/axonom/units").data() );164 gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/axonom/units")));
164 if (!gridunit)165 if (!gridunit)
165 gridunit = &sp_unit_get_by_id(SP_UNIT_PX);166 gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px"));
166 origin[Geom::X] = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/origin_x", 0.0), *gridunit );167 origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_x", 0.0), *gridunit, "px");
167 origin[Geom::Y] = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/origin_y", 0.0), *gridunit );168 origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_y", 0.0), *gridunit, "px");
168 color = prefs->getInt("/options/grids/axonom/color", 0x0000ff20);169 color = prefs->getInt("/options/grids/axonom/color", 0x0000ff20);
169 empcolor = prefs->getInt("/options/grids/axonom/empcolor", 0x0000ff40);170 empcolor = prefs->getInt("/options/grids/axonom/empcolor", 0x0000ff40);
170 empspacing = prefs->getInt("/options/grids/axonom/empspacing", 5);171 empspacing = prefs->getInt("/options/grids/axonom/empspacing", 5);
171 lengthy = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), *gridunit );172 lengthy = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), *gridunit, "px");
172 angle_deg[X] = prefs->getDouble("/options/grids/axonom/angle_x", 30.0);173 angle_deg[X] = prefs->getDouble("/options/grids/axonom/angle_x", 30.0);
173 angle_deg[Z] = prefs->getDouble("/options/grids/axonom/angle_z", 30.0);174 angle_deg[Z] = prefs->getDouble("/options/grids/axonom/angle_z", 30.0);
174 angle_deg[Y] = 0;175 angle_deg[Y] = 0;
@@ -188,63 +189,6 @@
188 if (snapper) delete snapper;189 if (snapper) delete snapper;
189}190}
190191
191
192/* fixme: Collect all these length parsing methods and think common sane API */
193
194static gboolean sp_nv_read_length(gchar const *str, guint base, gdouble *val, SPUnit const **unit)
195{
196 if (!str) {
197 return FALSE;
198 }
199
200 gchar *u;
201 gdouble v = g_ascii_strtod(str, &u);
202 if (!u) {
203 return FALSE;
204 }
205 while (isspace(*u)) {
206 u += 1;
207 }
208
209 if (!*u) {
210 /* No unit specified - keep default */
211 *val = v;
212 return TRUE;
213 }
214
215 if (base & SP_UNIT_DEVICE) {
216 if (u[0] && u[1] && !isalnum(u[2]) && !strncmp(u, "px", 2)) {
217 *unit = &sp_unit_get_by_id(SP_UNIT_PX);
218 *val = v;
219 return TRUE;
220 }
221 }
222
223 if (base & SP_UNIT_ABSOLUTE) {
224 if (!strncmp(u, "pt", 2)) {
225 *unit = &sp_unit_get_by_id(SP_UNIT_PT);
226 } else if (!strncmp(u, "mm", 2)) {
227 *unit = &sp_unit_get_by_id(SP_UNIT_MM);
228 } else if (!strncmp(u, "cm", 2)) {
229 *unit = &sp_unit_get_by_id(SP_UNIT_CM);
230 } else if (!strncmp(u, "m", 1)) {
231 *unit = &sp_unit_get_by_id(SP_UNIT_M);
232 } else if (!strncmp(u, "in", 2)) {
233 *unit = &sp_unit_get_by_id(SP_UNIT_IN);
234 } else if (!strncmp(u, "ft", 2)) {
235 *unit = &sp_unit_get_by_id(SP_UNIT_FT);
236 } else if (!strncmp(u, "pc", 2)) {
237 *unit = &sp_unit_get_by_id(SP_UNIT_PC);
238 } else {
239 return FALSE;
240 }
241 *val = v;
242 return TRUE;
243 }
244
245 return FALSE;
246}
247
248static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color)192static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color)
249{193{
250 if (!str) {194 if (!str) {
@@ -270,17 +214,20 @@
270{214{
271 gchar const *value;215 gchar const *value;
272 if ( (value = repr->attribute("originx")) ) {216 if ( (value = repr->attribute("originx")) ) {
273 sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::X], &gridunit);217 Inkscape::Util::Quantity q = unit_table.getQuantity(value);
274 origin[Geom::X] = sp_units_get_pixels(origin[Geom::X], *(gridunit));218 gridunit = q.unit;
219 origin[Geom::X] = unit_table.getQuantity(value).value("px");
275 }220 }
276 if ( (value = repr->attribute("originy")) ) {221 if ( (value = repr->attribute("originy")) ) {
277 sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::Y], &gridunit);222 Inkscape::Util::Quantity q = unit_table.getQuantity(value);
278 origin[Geom::Y] = sp_units_get_pixels(origin[Geom::Y], *(gridunit));223 gridunit = q.unit;
224 origin[Geom::Y] = unit_table.getQuantity(value).value("px");
279 }225 }
280226
281 if ( (value = repr->attribute("spacingy")) ) {227 if ( (value = repr->attribute("spacingy")) ) {
282 sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &lengthy, &gridunit);228 Inkscape::Util::Quantity q = unit_table.getQuantity(value);
283 lengthy = sp_units_get_pixels(lengthy, *(gridunit));229 gridunit = q.unit;
230 lengthy = q.value("px");
284 if (lengthy < 0.0500) lengthy = 0.0500;231 if (lengthy < 0.0500) lengthy = 0.0500;
285 }232 }
286233
@@ -419,17 +366,17 @@
419 attach_all (*table, widget_array, sizeof(widget_array));366 attach_all (*table, widget_array, sizeof(widget_array));
420367
421 // set widget values368 // set widget values
422 _rumg->setUnit (gridunit);369 _rumg->setUnit (gridunit->abbr);
423370
424 gdouble val;371 gdouble val;
425 val = origin[Geom::X];372 val = origin[Geom::X];
426 val = sp_pixels_get_units (val, *(gridunit));373 val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
427 _rsu_ox->setValue (val);374 _rsu_ox->setValue (val);
428 val = origin[Geom::Y];375 val = origin[Geom::Y];
429 val = sp_pixels_get_units (val, *(gridunit));376 val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
430 _rsu_oy->setValue (val);377 _rsu_oy->setValue (val);
431 val = lengthy;378 val = lengthy;
432 double gridy = sp_pixels_get_units (val, *(gridunit));379 double gridy = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
433 _rsu_sy->setValue (gridy);380 _rsu_sy->setValue (gridy);
434381
435 _rsu_ax->setValue(angle_deg[X]);382 _rsu_ax->setValue(angle_deg[X]);
@@ -458,17 +405,17 @@
458 _rcb_enabled.setActive(snapper->getEnabled());405 _rcb_enabled.setActive(snapper->getEnabled());
459 }406 }
460407
461 _rumg.setUnit (gridunit);408 _rumg.setUnit (gridunit->abbr);
462409
463 gdouble val;410 gdouble val;
464 val = origin[Geom::X];411 val = origin[Geom::X];
465 val = sp_pixels_get_units (val, *(gridunit));412 val = Inkscape::Util::Quantity::convert(val, &px, gridunit);
466 _rsu_ox.setValue (val);413 _rsu_ox.setValue (val);
467 val = origin[Geom::Y];414 val = origin[Geom::Y];
468 val = sp_pixels_get_units (val, *(gridunit));415 val = Inkscape::Util::Quantity::convert(val, &px, gridunit);
469 _rsu_oy.setValue (val);416 _rsu_oy.setValue (val);
470 val = lengthy;417 val = lengthy;
471 double gridy = sp_pixels_get_units (val, *(gridunit));418 double gridy = Inkscape::Util::Quantity::convert(val, &px, gridunit);
472 _rsu_sy.setValue (gridy);419 _rsu_sy.setValue (gridy);
473420
474 _rsu_ax.setValue(angle_deg[X]);421 _rsu_ax.setValue(angle_deg[X]);
475422
=== modified file 'src/display/canvas-grid.cpp'
--- src/display/canvas-grid.cpp 2013-06-06 13:44:11 +0000
+++ src/display/canvas-grid.cpp 2013-08-06 18:46:25 +0000
@@ -42,7 +42,7 @@
42#include "display/canvas-grid.h"42#include "display/canvas-grid.h"
43#include "display/sp-canvas-group.h"43#include "display/sp-canvas-group.h"
44#include "document.h"44#include "document.h"
45#include "helper/units.h"45#include "util/units.h"
46#include "inkscape.h"46#include "inkscape.h"
47#include "preferences.h"47#include "preferences.h"
48#include "sp-namedview.h"48#include "sp-namedview.h"
@@ -55,6 +55,7 @@
55#include "display/sp-canvas.h"55#include "display/sp-canvas.h"
5656
57using Inkscape::DocumentUndo;57using Inkscape::DocumentUndo;
58using Inkscape::Util::unit_table;
5859
59namespace Inkscape {60namespace Inkscape {
6061
@@ -398,11 +399,11 @@
398 gdouble val;399 gdouble val;
399400
400 val = origin_px[Geom::X];401 val = origin_px[Geom::X];
401 val = sp_pixels_get_units (val, *gridunit);402 val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
402 os_x << val << sp_unit_get_abbreviation(gridunit);403 os_x << val << gridunit->abbr;
403 val = origin_px[Geom::Y];404 val = origin_px[Geom::Y];
404 val = sp_pixels_get_units (val, *gridunit);405 val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
405 os_y << val << sp_unit_get_abbreviation(gridunit);406 os_y << val << gridunit->abbr;
406 repr->setAttribute("originx", os_x.str().c_str());407 repr->setAttribute("originx", os_x.str().c_str());
407 repr->setAttribute("originy", os_y.str().c_str());408 repr->setAttribute("originy", os_y.str().c_str());
408}409}
@@ -488,17 +489,17 @@
488 : CanvasGrid(nv, in_repr, in_doc, GRID_RECTANGULAR)489 : CanvasGrid(nv, in_repr, in_doc, GRID_RECTANGULAR)
489{490{
490 Inkscape::Preferences *prefs = Inkscape::Preferences::get();491 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
491 gridunit = sp_unit_get_by_abbreviation( prefs->getString("/options/grids/xy/units").data() );492 gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/xy/units")));
492 if (!gridunit) {493 if (!gridunit) {
493 gridunit = &sp_unit_get_by_id(SP_UNIT_PX);494 gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px"));
494 }495 }
495 origin[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_x", 0.0), *gridunit);496 origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_x", 0.0), *gridunit, "px");
496 origin[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_y", 0.0), *gridunit);497 origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_y", 0.0), *gridunit, "px");
497 color = prefs->getInt("/options/grids/xy/color", 0x0000ff20);498 color = prefs->getInt("/options/grids/xy/color", 0x0000ff20);
498 empcolor = prefs->getInt("/options/grids/xy/empcolor", 0x0000ff40);499 empcolor = prefs->getInt("/options/grids/xy/empcolor", 0x0000ff40);
499 empspacing = prefs->getInt("/options/grids/xy/empspacing", 5);500 empspacing = prefs->getInt("/options/grids/xy/empspacing", 5);
500 spacing[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), *gridunit);501 spacing[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), *gridunit, "px");
501 spacing[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), *gridunit);502 spacing[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), *gridunit, "px");
502 render_dotted = prefs->getBool("/options/grids/xy/dotted", false);503 render_dotted = prefs->getBool("/options/grids/xy/dotted", false);
503504
504 snapper = new CanvasXYGridSnapper(this, &namedview->snap_manager, 0);505 snapper = new CanvasXYGridSnapper(this, &namedview->snap_manager, 0);
@@ -511,64 +512,6 @@
511 if (snapper) delete snapper;512 if (snapper) delete snapper;
512}513}
513514
514
515/* fixme: Collect all these length parsing methods and think common sane API */
516
517static gboolean
518sp_nv_read_length(gchar const *str, guint base, gdouble *val, SPUnit const **unit)
519{
520 if (!str) {
521 return FALSE;
522 }
523
524 gchar *u;
525 gdouble v = g_ascii_strtod(str, &u);
526 if (!u) {
527 return FALSE;
528 }
529 while (isspace(*u)) {
530 u += 1;
531 }
532
533 if (!*u) {
534 /* No unit specified - keep default */
535 *val = v;
536 return TRUE;
537 }
538
539 if (base & SP_UNIT_DEVICE) {
540 if (u[0] && u[1] && !isalnum(u[2]) && !strncmp(u, "px", 2)) {
541 *unit = &sp_unit_get_by_id(SP_UNIT_PX);
542 *val = v;
543 return TRUE;
544 }
545 }
546
547 if (base & SP_UNIT_ABSOLUTE) {
548 if (!strncmp(u, "pt", 2)) {
549 *unit = &sp_unit_get_by_id(SP_UNIT_PT);
550 } else if (!strncmp(u, "mm", 2)) {
551 *unit = &sp_unit_get_by_id(SP_UNIT_MM);
552 } else if (!strncmp(u, "cm", 2)) {
553 *unit = &sp_unit_get_by_id(SP_UNIT_CM);
554 } else if (!strncmp(u, "m", 1)) {
555 *unit = &sp_unit_get_by_id(SP_UNIT_M);
556 } else if (!strncmp(u, "in", 2)) {
557 *unit = &sp_unit_get_by_id(SP_UNIT_IN);
558 } else if (!strncmp(u, "ft", 2)) {
559 *unit = &sp_unit_get_by_id(SP_UNIT_FT);
560 } else if (!strncmp(u, "pc", 2)) {
561 *unit = &sp_unit_get_by_id(SP_UNIT_PC);
562 } else {
563 return FALSE;
564 }
565 *val = v;
566 return TRUE;
567 }
568
569 return FALSE;
570}
571
572static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color)515static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color)
573{516{
574 if (!str) {517 if (!str) {
@@ -645,28 +588,32 @@
645{588{
646 gchar const *value;589 gchar const *value;
647 if ( (value = repr->attribute("originx")) ) {590 if ( (value = repr->attribute("originx")) ) {
648 sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::X], &gridunit);591 Inkscape::Util::Quantity q = unit_table.getQuantity(value);
649 origin[Geom::X] = sp_units_get_pixels(origin[Geom::X], *(gridunit));592 gridunit = q.unit;
593 origin[Geom::X] = unit_table.getQuantity(value).value("px");
650 }594 }
651595
652 if ( (value = repr->attribute("originy")) ) {596 if ( (value = repr->attribute("originy")) ) {
653 sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::Y], &gridunit);597 Inkscape::Util::Quantity q = unit_table.getQuantity(value);
654 origin[Geom::Y] = sp_units_get_pixels(origin[Geom::Y], *(gridunit));598 gridunit = q.unit;
599 origin[Geom::Y] = unit_table.getQuantity(value).value("px");
655 }600 }
656601
657 if ( (value = repr->attribute("spacingx")) ) {602 if ( (value = repr->attribute("spacingx")) ) {
658 double oldVal = spacing[Geom::X];603 double oldVal = spacing[Geom::X];
659 sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[Geom::X], &gridunit);604 Inkscape::Util::Quantity q = unit_table.getQuantity(value);
660 validateScalar( oldVal, &spacing[Geom::X]);605 gridunit = q.unit;
661 spacing[Geom::X] = sp_units_get_pixels(spacing[Geom::X], *(gridunit));606 spacing[Geom::X] = q.quantity;
662607 validateScalar(oldVal, &spacing[Geom::X]);
608 spacing[Geom::X] = Inkscape::Util::Quantity::convert(spacing[Geom::X], *gridunit, "px");
663 }609 }
664 if ( (value = repr->attribute("spacingy")) ) {610 if ( (value = repr->attribute("spacingy")) ) {
665 double oldVal = spacing[Geom::Y];611 double oldVal = spacing[Geom::Y];
666 sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[Geom::Y], &gridunit);612 Inkscape::Util::Quantity q = unit_table.getQuantity(value);
667 validateScalar( oldVal, &spacing[Geom::Y]);613 gridunit = q.unit;
668 spacing[Geom::Y] = sp_units_get_pixels(spacing[Geom::Y], *(gridunit));614 spacing[Geom::Y] = q.quantity;
669615 validateScalar(oldVal, &spacing[Geom::Y]);
616 spacing[Geom::Y] = Inkscape::Util::Quantity::convert(spacing[Geom::Y], *gridunit, "px");
670 }617 }
671618
672 if ( (value = repr->attribute("color")) ) {619 if ( (value = repr->attribute("color")) ) {
@@ -802,20 +749,20 @@
802 attach_all (*table, widget_array, sizeof(widget_array));749 attach_all (*table, widget_array, sizeof(widget_array));
803750
804 // set widget values751 // set widget values
805 _rumg->setUnit (gridunit);752 _rumg->setUnit (gridunit->abbr);
806753
807 gdouble val;754 gdouble val;
808 val = origin[Geom::X];755 val = origin[Geom::X];
809 val = sp_pixels_get_units (val, *(gridunit));756 val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
810 _rsu_ox->setValue (val);757 _rsu_ox->setValue (val);
811 val = origin[Geom::Y];758 val = origin[Geom::Y];
812 val = sp_pixels_get_units (val, *(gridunit));759 val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
813 _rsu_oy->setValue (val);760 _rsu_oy->setValue (val);
814 val = spacing[Geom::X];761 val = spacing[Geom::X];
815 double gridx = sp_pixels_get_units (val, *(gridunit));762 double gridx = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
816 _rsu_sx->setValue (gridx);763 _rsu_sx->setValue (gridx);
817 val = spacing[Geom::Y];764 val = spacing[Geom::Y];
818 double gridy = sp_pixels_get_units (val, *(gridunit));765 double gridy = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
819 _rsu_sy->setValue (gridy);766 _rsu_sy->setValue (gridy);
820767
821 _rcp_gcol->setRgba32 (color);768 _rcp_gcol->setRgba32 (color);
@@ -851,20 +798,20 @@
851 _rcb_enabled.setActive(snapper->getEnabled());798 _rcb_enabled.setActive(snapper->getEnabled());
852 }799 }
853800
854 _rumg.setUnit (gridunit);801 _rumg.setUnit (gridunit->abbr);
855802
856 gdouble val;803 gdouble val;
857 val = origin[Geom::X];804 val = origin[Geom::X];
858 val = sp_pixels_get_units (val, *(gridunit));805 val = Inkscape::Quantity::convert(val, "px", *gridunit);
859 _rsu_ox.setValue (val);806 _rsu_ox.setValue (val);
860 val = origin[Geom::Y];807 val = origin[Geom::Y];
861 val = sp_pixels_get_units (val, *(gridunit));808 val = Inkscape::Quantity::convert(val, "px", *gridunit);
862 _rsu_oy.setValue (val);809 _rsu_oy.setValue (val);
863 val = spacing[Geom::X];810 val = spacing[Geom::X];
864 double gridx = sp_pixels_get_units (val, *(gridunit));811 double gridx = Inkscape::Quantity::convert(val, "px", *gridunit);
865 _rsu_sx.setValue (gridx);812 _rsu_sx.setValue (gridx);
866 val = spacing[Geom::Y];813 val = spacing[Geom::Y];
867 double gridy = sp_pixels_get_units (val, *(gridunit));814 double gridy = Inkscape::Quantity::convert(val, "px", *gridunit);
868 _rsu_sy.setValue (gridy);815 _rsu_sy.setValue (gridy);
869816
870 _rcp_gcol.setRgba32 (color);817 _rcp_gcol.setRgba32 (color);
871818
=== modified file 'src/display/canvas-grid.h'
--- src/display/canvas-grid.h 2013-01-17 20:07:10 +0000
+++ src/display/canvas-grid.h 2013-08-06 18:46:25 +0000
@@ -28,6 +28,10 @@
28class Node;28class Node;
29}29}
3030
31namespace Util {
32class Unit;
33}
34
31enum GridType {35enum GridType {
32 GRID_RECTANGULAR = 0,36 GRID_RECTANGULAR = 0,
33 GRID_AXONOMETRIC = 137 GRID_AXONOMETRIC = 1
@@ -88,7 +92,7 @@
88 guint32 empcolor; /**< Color for emphasis lines */92 guint32 empcolor; /**< Color for emphasis lines */
89 gint empspacing; /**< Spacing between emphasis lines */93 gint empspacing; /**< Spacing between emphasis lines */
9094
91 SPUnit const* gridunit;95 Inkscape::Util::Unit const* gridunit;
9296
93 Inkscape::XML::Node * repr;97 Inkscape::XML::Node * repr;
94 SPDocument *doc;98 SPDocument *doc;
9599
=== modified file 'src/document.cpp'
--- src/document.cpp 2013-07-10 00:46:51 +0000
+++ src/document.cpp 2013-08-06 18:46:25 +0000
@@ -49,7 +49,6 @@
49#include "display/drawing-item.h"49#include "display/drawing-item.h"
50#include "document-private.h"50#include "document-private.h"
51#include "document-undo.h"51#include "document-undo.h"
52#include "helper/units.h"
53#include "id-clash.h"52#include "id-clash.h"
54#include "inkscape-private.h"53#include "inkscape-private.h"
55#include "inkscape-version.h"54#include "inkscape-version.h"
@@ -63,12 +62,13 @@
63#include "sp-object-repr.h"62#include "sp-object-repr.h"
64#include "sp-symbol.h"63#include "sp-symbol.h"
65#include "transf_mat_3x4.h"64#include "transf_mat_3x4.h"
66#include "unit-constants.h"65#include "util/units.h"
67#include "xml/repr.h"66#include "xml/repr.h"
68#include "xml/rebase-hrefs.h"67#include "xml/rebase-hrefs.h"
69#include "libcroco/cr-cascade.h"68#include "libcroco/cr-cascade.h"
7069
71using Inkscape::DocumentUndo;70using Inkscape::DocumentUndo;
71using Inkscape::Util::unit_table;
7272
73// Higher number means lower priority.73// Higher number means lower priority.
74#define SP_DOCUMENT_UPDATE_PRIORITY (G_PRIORITY_HIGH_IDLE - 2)74#define SP_DOCUMENT_UPDATE_PRIORITY (G_PRIORITY_HIGH_IDLE - 2)
@@ -546,21 +546,21 @@
546 return result;546 return result;
547}547}
548548
549void SPDocument::setWidth(gdouble width, const SPUnit *unit)549void SPDocument::setWidth(const Inkscape::Util::Quantity &width)
550{550{
551 if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox=551 if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox=
552 root->viewBox.setMax(Geom::Point(root->viewBox.left() + sp_units_get_pixels (width, *unit), root->viewBox.bottom()));552 root->viewBox.setMax(Geom::Point(root->viewBox.left() + width.value("px"), root->viewBox.bottom()));
553 } else { // set to width=553 } else { // set to width=
554 gdouble old_computed = root->width.computed;554 gdouble old_computed = root->width.computed;
555 root->width.computed = sp_units_get_pixels (width, *unit);555 root->width.computed = width.value("px");
556 /* SVG does not support meters as a unit, so we must translate meters to556 /* SVG does not support meters as a unit, so we must translate meters to
557 * cm when writing */557 * cm when writing */
558 if (!strcmp(unit->abbr, "m")) {558 if (*width.unit == unit_table.getUnit("m")) {
559 root->width.value = 100*width;559 root->width.value = width.value("cm");
560 root->width.unit = SVGLength::CM;560 root->width.unit = SVGLength::CM;
561 } else {561 } else {
562 root->width.value = width;562 root->width.value = width.quantity;
563 root->width.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit);563 root->width.unit = (SVGLength::Unit) width.unit->svgUnit();
564 }564 }
565565
566 if (root->viewBox_set)566 if (root->viewBox_set)
@@ -582,21 +582,21 @@
582 return result;582 return result;
583}583}
584584
585void SPDocument::setHeight(gdouble height, const SPUnit *unit)585void SPDocument::setHeight(const Inkscape::Util::Quantity &height)
586{586{
587 if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox=587 if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox=
588 root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + sp_units_get_pixels (height, *unit)));588 root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + height.value("px")));
589 } else { // set to height=589 } else { // set to height=
590 gdouble old_computed = root->height.computed;590 gdouble old_computed = root->height.computed;
591 root->height.computed = sp_units_get_pixels (height, *unit);591 root->height.computed = height.value("px");
592 /* SVG does not support meters as a unit, so we must translate meters to592 /* SVG does not support meters as a unit, so we must translate meters to
593 * cm when writing */593 * cm when writing */
594 if (!strcmp(unit->abbr, "m")) {594 if (*height.unit == unit_table.getUnit("m")) {
595 root->height.value = 100*height;595 root->height.value = height.value("cm");
596 root->height.unit = SVGLength::CM;596 root->height.unit = SVGLength::CM;
597 } else {597 } else {
598 root->height.value = height;598 root->height.value = height.quantity;
599 root->height.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit);599 root->height.unit = (SVGLength::Unit) height.unit->svgUnit();
600 }600 }
601601
602 if (root->viewBox_set)602 if (root->viewBox_set)
@@ -631,7 +631,7 @@
631 double const h = rect.height();631 double const h = rect.height();
632632
633 double const old_height = getHeight();633 double const old_height = getHeight();
634 SPUnit const &px(sp_unit_get_by_id(SP_UNIT_PX));634 Inkscape::Util::Unit const px = unit_table.getUnit("px");
635 635
636 /* in px */636 /* in px */
637 double margin_top = 0.0;637 double margin_top = 0.0;
@@ -644,9 +644,10 @@
644 if (with_margins && nv) {644 if (with_margins && nv) {
645 if (nv != NULL) {645 if (nv != NULL) {
646 gchar const * const units_abbr = nv->getAttribute("units");646 gchar const * const units_abbr = nv->getAttribute("units");
647 SPUnit const *margin_units = NULL;647 Inkscape::Util::Unit const *margin_units = NULL;
648 if (units_abbr != NULL) {648 if (units_abbr != NULL) {
649 margin_units = sp_unit_get_by_abbreviation(units_abbr);649 Inkscape::Util::Unit mu = unit_table.getUnit(units_abbr);
650 margin_units = &mu;
650 }651 }
651 if (margin_units == NULL) {652 if (margin_units == NULL) {
652 margin_units = &px;653 margin_units = &px;
@@ -663,8 +664,8 @@
663 rect.max() + Geom::Point(margin_right, margin_top));664 rect.max() + Geom::Point(margin_right, margin_top));
664 665
665 666
666 setWidth(rect_with_margins.width(), &px);667 setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), "px"));
667 setHeight(rect_with_margins.height(), &px);668 setHeight(Inkscape::Util::Quantity(rect_with_margins.height(), "px"));
668669
669 Geom::Translate const tr(670 Geom::Translate const tr(
670 Geom::Point(0, old_height - rect_with_margins.height())671 Geom::Point(0, old_height - rect_with_margins.height())
@@ -964,7 +965,7 @@
964 if (root->viewBox_set) { // if set, take from viewBox965 if (root->viewBox_set) { // if set, take from viewBox
965 ctx->viewport = root->viewBox;966 ctx->viewport = root->viewBox;
966 } else { // as a last resort, set size to A4967 } else { // as a last resort, set size to A4
967 ctx->viewport = Geom::Rect::from_xywh(0, 0, 210 * PX_PER_MM, 297 * PX_PER_MM);968 ctx->viewport = Geom::Rect::from_xywh(0, 0, 210 * Inkscape::Util::Quantity::convert(1, "mm", "px"), 297 * Inkscape::Util::Quantity::convert(1, "mm", "px"));
968 }969 }
969 ctx->i2vp = Geom::identity();970 ctx->i2vp = Geom::identity();
970}971}
971972
=== modified file 'src/document.h'
--- src/document.h 2013-07-10 00:46:51 +0000
+++ src/document.h 2013-08-06 18:46:25 +0000
@@ -35,7 +35,6 @@
35class SPObject;35class SPObject;
36struct SPGroup;36struct SPGroup;
37struct SPRoot;37struct SPRoot;
38struct SPUnit;
3938
40namespace Inkscape {39namespace Inkscape {
41 struct Application;40 struct Application;
@@ -47,6 +46,9 @@
47 struct Document;46 struct Document;
48 class Node;47 class Node;
49 }48 }
49 namespace Util {
50 class Quantity;
51 }
50}52}
5153
52class SPDefs;54class SPDefs;
@@ -229,8 +231,8 @@
229 gdouble getHeight() const;231 gdouble getHeight() const;
230 Geom::Point getDimensions() const;232 Geom::Point getDimensions() const;
231 Geom::OptRect preferredBounds() const;233 Geom::OptRect preferredBounds() const;
232 void setWidth(gdouble width, const SPUnit *unit);234 void setWidth(const Inkscape::Util::Quantity &width);
233 void setHeight(gdouble height, const SPUnit *unit);235 void setHeight(const Inkscape::Util::Quantity &height);
234 void requestModified();236 void requestModified();
235 gint ensureUpToDate();237 gint ensureUpToDate();
236 bool addResource(const gchar *key, SPObject *object);238 bool addResource(const gchar *key, SPObject *object);
@@ -254,8 +256,6 @@
254 void setupViewport(SPItemCtx *ctx);256 void setupViewport(SPItemCtx *ctx);
255};257};
256258
257struct SPUnit;
258
259/*259/*
260 * Ideas: How to overcome style invalidation nightmare260 * Ideas: How to overcome style invalidation nightmare
261 *261 *
262262
=== modified file 'src/doxygen-main.cpp'
--- src/doxygen-main.cpp 2013-07-23 16:54:03 +0000
+++ src/doxygen-main.cpp 2013-08-06 18:46:25 +0000
@@ -334,8 +334,6 @@
334 *334 *
335 * Inkscape::GC335 * Inkscape::GC
336 *336 *
337 * [\ref sp-metrics.cpp, \ref sp-metrics.h]
338 *
339 * [\ref prefs-utils.cpp] [\ref print.cpp]337 * [\ref prefs-utils.cpp] [\ref print.cpp]
340 *338 *
341 * - Inkscape::GZipBuffer [\ref streams-gzip.h]339 * - Inkscape::GZipBuffer [\ref streams-gzip.h]
@@ -350,7 +348,7 @@
350 * Inkscape::Whiteboard::UndoStackObserver [\ref undo-stack-observer.cpp, \ref composite-undo-stack-observer.cpp]348 * Inkscape::Whiteboard::UndoStackObserver [\ref undo-stack-observer.cpp, \ref composite-undo-stack-observer.cpp]
351 * [\ref document-undo.cpp]349 * [\ref document-undo.cpp]
352 *350 *
353 * {\ref dialogs/} [\ref decimal-round.h] [\ref enums.h] [\ref unit-constants.h]351 * {\ref dialogs/} [\ref decimal-round.h] [\ref enums.h]
354 */352 */
355353
356354
357355
=== modified file 'src/extension/internal/cairo-render-context.cpp'
--- src/extension/internal/cairo-render-context.cpp 2013-08-05 21:07:35 +0000
+++ src/extension/internal/cairo-render-context.cpp 2013-08-06 18:46:25 +0000
@@ -44,12 +44,11 @@
44#include "sp-pattern.h"44#include "sp-pattern.h"
45#include "sp-mask.h"45#include "sp-mask.h"
46#include "sp-clippath.h"46#include "sp-clippath.h"
47#include "util/units.h"
47#ifdef WIN3248#ifdef WIN32
48#include "libnrtype/FontFactory.h" // USE_PANGO_WIN3249#include "libnrtype/FontFactory.h" // USE_PANGO_WIN32
49#endif50#endif
5051
51#include <unit-constants.h>
52
53#include "cairo-render-context.h"52#include "cairo-render-context.h"
54#include "cairo-renderer.h"53#include "cairo-renderer.h"
55#include "extension/system.h"54#include "extension/system.h"
@@ -855,7 +854,7 @@
855 _surface = surface;854 _surface = surface;
856855
857 if (_vector_based_target) {856 if (_vector_based_target) {
858 cairo_scale(_cr, PT_PER_PX, PT_PER_PX);857 cairo_scale(_cr, Inkscape::Util::Quantity::convert(1, "px", "pt"), Inkscape::Util::Quantity::convert(1, "px", "pt"));
859 } else if (cairo_surface_get_content(_surface) != CAIRO_CONTENT_ALPHA) {858 } else if (cairo_surface_get_content(_surface) != CAIRO_CONTENT_ALPHA) {
860 // set background color on non-alpha surfaces859 // set background color on non-alpha surfaces
861 // TODO: bgcolor should be derived from SPDocument860 // TODO: bgcolor should be derived from SPDocument
862861
=== modified file 'src/extension/internal/cairo-renderer-pdf-out.cpp'
--- src/extension/internal/cairo-renderer-pdf-out.cpp 2013-08-05 21:07:35 +0000
+++ src/extension/internal/cairo-renderer-pdf-out.cpp 2013-08-06 18:46:25 +0000
@@ -39,7 +39,7 @@
39#include <2geom/affine.h>39#include <2geom/affine.h>
40#include "document.h"40#include "document.h"
4141
42#include "unit-constants.h"42#include "util/units.h"
4343
44namespace Inkscape {44namespace Inkscape {
45namespace Extension {45namespace Extension {
@@ -197,7 +197,7 @@
197197
198 float new_bleedmargin_px = 0.;198 float new_bleedmargin_px = 0.;
199 try {199 try {
200 new_bleedmargin_px = mod->get_param_float("bleed") * PX_PER_MM;200 new_bleedmargin_px = mod->get_param_float("bleed") * Inkscape::Util::Quantity::convert(1, "mm", "px");
201 }201 }
202 catch(...) {202 catch(...) {
203 g_warning("Parameter <bleed> might not exist");203 g_warning("Parameter <bleed> might not exist");
204204
=== modified file 'src/extension/internal/cairo-renderer.cpp'
--- src/extension/internal/cairo-renderer.cpp 2012-10-28 18:19:43 +0000
+++ src/extension/internal/cairo-renderer.cpp 2013-08-06 18:46:25 +0000
@@ -55,7 +55,7 @@
55#include "sp-mask.h"55#include "sp-mask.h"
56#include "sp-clippath.h"56#include "sp-clippath.h"
5757
58#include <unit-constants.h>58#include "util/units.h"
59#include "helper/png-write.h"59#include "helper/png-write.h"
60#include "helper/pixbuf-ops.h"60#include "helper/pixbuf-ops.h"
6161
@@ -442,7 +442,7 @@
442 */442 */
443 res = ctx->getBitmapResolution();443 res = ctx->getBitmapResolution();
444 if(res == 0) {444 if(res == 0) {
445 res = PX_PER_IN;445 res = Inkscape::Util::Quantity::convert(1, "in", "px");
446 }446 }
447 TRACE(("sp_asbitmap_render: resolution: %f\n", res ));447 TRACE(("sp_asbitmap_render: resolution: %f\n", res ));
448448
@@ -463,8 +463,8 @@
463 }463 }
464464
465 // The width and height of the bitmap in pixels465 // The width and height of the bitmap in pixels
466 unsigned width = ceil(bbox->width() * (res / PX_PER_IN));466 unsigned width = ceil(bbox->width() * (res / Inkscape::Util::Quantity::convert(1, "in", "px")));
467 unsigned height = ceil(bbox->height() * (res / PX_PER_IN));467 unsigned height = ceil(bbox->height() * (res / Inkscape::Util::Quantity::convert(1, "in", "px")));
468468
469 if (width == 0 || height == 0) return;469 if (width == 0 || height == 0) return;
470470
@@ -477,7 +477,7 @@
477 double shift_y = bbox->max()[Geom::Y];477 double shift_y = bbox->max()[Geom::Y];
478478
479 // For default 90 dpi, snap bitmap to pixel grid479 // For default 90 dpi, snap bitmap to pixel grid
480 if (res == PX_PER_IN) { 480 if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) {
481 shift_x = round (shift_x);481 shift_x = round (shift_x);
482 shift_y = -round (-shift_y); // Correct rounding despite coordinate inversion.482 shift_y = -round (-shift_y); // Correct rounding despite coordinate inversion.
483 // Remove the negations when the inversion is gone.483 // Remove the negations when the inversion is gone.
@@ -629,7 +629,7 @@
629629
630 if (ctx->_vector_based_target) {630 if (ctx->_vector_based_target) {
631 // convert from px to pt631 // convert from px to pt
632 d *= Geom::Scale(PT_PER_PX);632 d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "pt"));
633 }633 }
634634
635 ctx->_width = d.width();635 ctx->_width = d.width();
@@ -647,11 +647,11 @@
647 } else {647 } else {
648 double high = doc->getHeight();648 double high = doc->getHeight();
649 if (ctx->_vector_based_target)649 if (ctx->_vector_based_target)
650 high *= PT_PER_PX;650 high *= Inkscape::Util::Quantity::convert(1, "px", "pt");
651651
652 // this transform translates the export drawing to a virtual page (0,0)-(width,height)652 // this transform translates the export drawing to a virtual page (0,0)-(width,height)
653 Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? PX_PER_PT : 1.0),653 Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0),
654 (d.bottom() - high) * (ctx->_vector_based_target ? PX_PER_PT : 1.0)));654 (d.bottom() - high) * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0)));
655 ctx->transform(tp);655 ctx->transform(tp);
656 }656 }
657 }657 }
658658
=== modified file 'src/extension/internal/emf-win32-inout.cpp'
--- src/extension/internal/emf-win32-inout.cpp 2013-08-05 21:07:35 +0000
+++ src/extension/internal/emf-win32-inout.cpp 2013-08-06 18:46:25 +0000
@@ -37,9 +37,9 @@
37#include "extension/output.h"37#include "extension/output.h"
38#include "display/drawing.h"38#include "display/drawing.h"
39#include "display/drawing-item.h"39#include "display/drawing-item.h"
40#include "unit-constants.h"
41#include "clear-n_.h"40#include "clear-n_.h"
42#include "document.h"41#include "document.h"
42#include "util/units.h"
4343
44#define WIN32_LEAN_AND_MEAN44#define WIN32_LEAN_AND_MEAN
45#include <windows.h>45#include <windows.h>
@@ -60,7 +60,7 @@
60namespace Extension {60namespace Extension {
61namespace Internal {61namespace Internal {
6262
63static float device_scale = DEVICESCALE;63static float device_scale = Inkscape::Util::Quantity::convert(1, "px", "pt");
64static float device_x;64static float device_x;
65static float device_y;65static float device_y;
66static RECTL rc_old;66static RECTL rc_old;
@@ -781,18 +781,18 @@
781781
782 d->dc[d->level].PixelsInX = pEmr->rclFrame.right - pEmr->rclFrame.left;782 d->dc[d->level].PixelsInX = pEmr->rclFrame.right - pEmr->rclFrame.left;
783 d->dc[d->level].PixelsInY = pEmr->rclFrame.bottom - pEmr->rclFrame.top;783 d->dc[d->level].PixelsInY = pEmr->rclFrame.bottom - pEmr->rclFrame.top;
784 device_x = pEmr->rclFrame.left/100.0*PX_PER_MM;784 device_x = pEmr->rclFrame.left/100.0*Inkscape::Util::Quantity::convert(1, "mm", "px");
785 device_y = pEmr->rclFrame.top/100.0*PX_PER_MM;785 device_y = pEmr->rclFrame.top/100.0*Inkscape::Util::Quantity::convert(1, "mm", "px");
786786
787 d->MMX = d->dc[d->level].PixelsInX / 100.0;787 d->MMX = d->dc[d->level].PixelsInX / 100.0;
788 d->MMY = d->dc[d->level].PixelsInY / 100.0;788 d->MMY = d->dc[d->level].PixelsInY / 100.0;
789789
790 d->dc[d->level].PixelsOutX = d->MMX * PX_PER_MM;790 d->dc[d->level].PixelsOutX = d->MMX * Inkscape::Util::Quantity::convert(1, "mm", "px");
791 d->dc[d->level].PixelsOutY = d->MMY * PX_PER_MM;791 d->dc[d->level].PixelsOutY = d->MMY * Inkscape::Util::Quantity::convert(1, "mm", "px");
792792
793 // calculate ratio of Inkscape dpi/device dpi793 // calculate ratio of Inkscape dpi/device dpi
794 if (pEmr->szlMillimeters.cx && pEmr->szlDevice.cx)794 if (pEmr->szlMillimeters.cx && pEmr->szlDevice.cx)
795 device_scale = PX_PER_MM*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx;795 device_scale = Inkscape::Util::Quantity::convert(1, "mm", "px")*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx;
796 796
797 tmp_outdef <<797 tmp_outdef <<
798 " width=\"" << d->MMX << "mm\"\n" <<798 " width=\"" << d->MMX << "mm\"\n" <<
799799
=== modified file 'src/extension/internal/emf-win32-print.cpp'
--- src/extension/internal/emf-win32-print.cpp 2013-08-05 21:07:35 +0000
+++ src/extension/internal/emf-win32-print.cpp 2013-08-06 18:46:25 +0000
@@ -36,6 +36,7 @@
36#include "helper/geom.h"36#include "helper/geom.h"
37#include "helper/geom-curves.h"37#include "helper/geom-curves.h"
38#include "sp-item.h"38#include "sp-item.h"
39#include "util/units.h"
3940
40#include "style.h"41#include "style.h"
41#include "inkscape-version.h"42#include "inkscape-version.h"
@@ -43,8 +44,6 @@
4344
44#include "emf-win32-print.h"45#include "emf-win32-print.h"
4546
46#include "unit-constants.h"
47
48#include "extension/system.h"47#include "extension/system.h"
49#include "extension/print.h"48#include "extension/print.h"
50#include "document.h"49#include "document.h"
@@ -129,7 +128,7 @@
129 if (bbox) d = *bbox;128 if (bbox) d = *bbox;
130 }129 }
131130
132 d *= Geom::Scale(IN_PER_PX);131 d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "in"));
133132
134 float dwInchesX = d.width();133 float dwInchesX = d.width();
135 float dwInchesY = d.height();134 float dwInchesY = d.height();
@@ -196,7 +195,7 @@
196 snprintf(buff, sizeof(buff)-1, "Screen=%dx%dpx, %dx%dmm", PixelsX, PixelsY, MMX, MMY);195 snprintf(buff, sizeof(buff)-1, "Screen=%dx%dpx, %dx%dmm", PixelsX, PixelsY, MMX, MMY);
197 GdiComment(hdc, strlen(buff), (BYTE*) buff);196 GdiComment(hdc, strlen(buff), (BYTE*) buff);
198197
199 snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * MM_PER_IN, dwInchesY * MM_PER_IN);198 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"));
200 GdiComment(hdc, strlen(buff), (BYTE*) buff);199 GdiComment(hdc, strlen(buff), (BYTE*) buff);
201 }200 }
202201
@@ -304,7 +303,7 @@
304303
305 double scale = sqrt( (p[X]*p[X]) + (p[Y]*p[Y]) ) / sqrt(2);304 double scale = sqrt( (p[X]*p[X]) + (p[Y]*p[Y]) ) / sqrt(2);
306305
307 DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * IN_PER_PX * dwDPI) );306 DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI) );
308307
309 if (style->stroke_linecap.computed == 0) {308 if (style->stroke_linecap.computed == 0) {
310 linecap = PS_ENDCAP_FLAT;309 linecap = PS_ENDCAP_FLAT;
@@ -341,7 +340,7 @@
341 n_dash = style->stroke_dash.n_dash;340 n_dash = style->stroke_dash.n_dash;
342 dash = new DWORD[n_dash];341 dash = new DWORD[n_dash];
343 for (i = 0; i < style->stroke_dash.n_dash; i++) {342 for (i = 0; i < style->stroke_dash.n_dash; i++) {
344 dash[i] = (DWORD) (style->stroke_dash.dash[i] * IN_PER_PX * dwDPI);343 dash[i] = (DWORD) (style->stroke_dash.dash[i] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
345 }344 }
346 }345 }
347 }346 }
@@ -544,8 +543,8 @@
544543
545 Geom::Point p0 = pit->initialPoint();544 Geom::Point p0 = pit->initialPoint();
546545
547 p0[X] = (p0[X] * IN_PER_PX * dwDPI);546 p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
548 p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);547 p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
549 548
550 LONG const x0 = (LONG) round(p0[X]);549 LONG const x0 = (LONG) round(p0[X]);
551 LONG const y0 = (LONG) round(rc.bottom-p0[Y]);550 LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -564,10 +563,10 @@
564 //Geom::Point p0 = cit->initialPoint();563 //Geom::Point p0 = cit->initialPoint();
565 Geom::Point p1 = cit->finalPoint();564 Geom::Point p1 = cit->finalPoint();
566565
567 //p0[X] = (p0[X] * IN_PER_PX * dwDPI);566 //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
568 p1[X] = (p1[X] * IN_PER_PX * dwDPI);567 p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
569 //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);568 //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
570 p1[Y] = (p1[Y] * IN_PER_PX * dwDPI);569 p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
571 570
572 //LONG const x0 = (LONG) round(p0[X]);571 //LONG const x0 = (LONG) round(p0[X]);
573 //LONG const y0 = (LONG) round(rc.bottom-p0[Y]);572 //LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -586,14 +585,14 @@
586 Geom::Point p2 = points[2];585 Geom::Point p2 = points[2];
587 Geom::Point p3 = points[3];586 Geom::Point p3 = points[3];
588587
589 //p0[X] = (p0[X] * IN_PER_PX * dwDPI);588 //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
590 p1[X] = (p1[X] * IN_PER_PX * dwDPI);589 p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
591 p2[X] = (p2[X] * IN_PER_PX * dwDPI);590 p2[X] = (p2[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
592 p3[X] = (p3[X] * IN_PER_PX * dwDPI);591 p3[X] = (p3[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
593 //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);592 //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
594 p1[Y] = (p1[Y] * IN_PER_PX * dwDPI);593 p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
595 p2[Y] = (p2[Y] * IN_PER_PX * dwDPI);594 p2[Y] = (p2[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
596 p3[Y] = (p3[Y] * IN_PER_PX * dwDPI);595 p3[Y] = (p3[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
597 596
598 //LONG const x0 = (LONG) round(p0[X]);597 //LONG const x0 = (LONG) round(p0[X]);
599 //LONG const y0 = (LONG) round(rc.bottom-p0[Y]);598 //LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -716,8 +715,8 @@
716715
717 Geom::Point p0 = pit->initialPoint();716 Geom::Point p0 = pit->initialPoint();
718717
719 p0[X] = (p0[X] * IN_PER_PX * dwDPI);718 p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
720 p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);719 p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
721 720
722 LONG const x0 = (LONG) round(p0[X]);721 LONG const x0 = (LONG) round(p0[X]);
723 LONG const y0 = (LONG) round(rc.bottom-p0[Y]);722 LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -734,10 +733,10 @@
734 //Geom::Point p0 = cit->initialPoint();733 //Geom::Point p0 = cit->initialPoint();
735 Geom::Point p1 = cit->finalPoint();734 Geom::Point p1 = cit->finalPoint();
736735
737 //p0[X] = (p0[X] * IN_PER_PX * dwDPI);736 //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
738 p1[X] = (p1[X] * IN_PER_PX * dwDPI);737 p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
739 //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);738 //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
740 p1[Y] = (p1[Y] * IN_PER_PX * dwDPI);739 p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
741 740
742 //LONG const x0 = (LONG) round(p0[X]);741 //LONG const x0 = (LONG) round(p0[X]);
743 //LONG const y0 = (LONG) round(rc.bottom-p0[Y]);742 //LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -754,14 +753,14 @@
754 Geom::Point p2 = points[2];753 Geom::Point p2 = points[2];
755 Geom::Point p3 = points[3];754 Geom::Point p3 = points[3];
756755
757 //p0[X] = (p0[X] * IN_PER_PX * dwDPI);756 //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
758 p1[X] = (p1[X] * IN_PER_PX * dwDPI);757 p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
759 p2[X] = (p2[X] * IN_PER_PX * dwDPI);758 p2[X] = (p2[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
760 p3[X] = (p3[X] * IN_PER_PX * dwDPI);759 p3[X] = (p3[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
761 //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);760 //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
762 p1[Y] = (p1[Y] * IN_PER_PX * dwDPI);761 p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
763 p2[Y] = (p2[Y] * IN_PER_PX * dwDPI);762 p2[Y] = (p2[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
764 p3[Y] = (p3[Y] * IN_PER_PX * dwDPI);763 p3[Y] = (p3[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
765 764
766 //LONG const x0 = (LONG) round(p0[X]);765 //LONG const x0 = (LONG) round(p0[X]);
767 //LONG const y0 = (LONG) round(rc.bottom-p0[Y]);766 //LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -829,7 +828,7 @@
829 LOGFONTW *lf = (LOGFONTW*)g_malloc(sizeof(LOGFONTW));828 LOGFONTW *lf = (LOGFONTW*)g_malloc(sizeof(LOGFONTW));
830 g_assert(lf != NULL);829 g_assert(lf != NULL);
831 830
832 lf->lfHeight = -style->font_size.computed * IN_PER_PX * dwDPI;831 lf->lfHeight = -style->font_size.computed * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI;
833 lf->lfWidth = 0;832 lf->lfWidth = 0;
834 lf->lfEscapement = rot;833 lf->lfEscapement = rot;
835 lf->lfOrientation = rot;834 lf->lfOrientation = rot;
@@ -878,8 +877,8 @@
878 SetBkMode(hdc, TRANSPARENT);877 SetBkMode(hdc, TRANSPARENT);
879878
880 Geom::Point p2 = p * tf;879 Geom::Point p2 = p * tf;
881 p2[Geom::X] = (p2[Geom::X] * IN_PER_PX * dwDPI);880 p2[Geom::X] = (p2[Geom::X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
882 p2[Geom::Y] = (p2[Geom::Y] * IN_PER_PX * dwDPI);881 p2[Geom::Y] = (p2[Geom::Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
883882
884 LONG const xpos = (LONG) round(p2[Geom::X]);883 LONG const xpos = (LONG) round(p2[Geom::X]);
885 LONG const ypos = (LONG) round(rc.bottom - p2[Geom::Y]);884 LONG const ypos = (LONG) round(rc.bottom - p2[Geom::Y]);
886885
=== modified file 'src/extension/internal/gdkpixbuf-input.cpp'
--- src/extension/internal/gdkpixbuf-input.cpp 2012-09-20 06:15:42 +0000
+++ src/extension/internal/gdkpixbuf-input.cpp 2013-08-06 18:46:25 +0000
@@ -12,7 +12,7 @@
12#include "selection-chemistry.h"12#include "selection-chemistry.h"
13#include "sp-image.h"13#include "sp-image.h"
14#include "document-undo.h"14#include "document-undo.h"
15#include "unit-constants.h"15#include "util/units.h"
16#include "image-resolution.h"16#include "image-resolution.h"
17#include <set>17#include <set>
1818
@@ -79,7 +79,7 @@
7979
80 double width = gdk_pixbuf_get_width(pb);80 double width = gdk_pixbuf_get_width(pb);
81 double height = gdk_pixbuf_get_height(pb);81 double height = gdk_pixbuf_get_height(pb);
82 double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", PX_PER_IN);82 double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", Inkscape::Util::Quantity::convert(1, "in", "px"));
83 bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi");83 bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi");
84 ImageResolution *ir = 0;84 ImageResolution *ir = 0;
85 double xscale = 1;85 double xscale = 1;
8686
=== modified file 'src/extension/internal/latex-pstricks.cpp'
--- src/extension/internal/latex-pstricks.cpp 2012-04-18 07:02:24 +0000
+++ src/extension/internal/latex-pstricks.cpp 2013-08-06 18:46:25 +0000
@@ -21,7 +21,7 @@
21#include <2geom/hvlinesegment.h>21#include <2geom/hvlinesegment.h>
22#include <errno.h>22#include <errno.h>
23#include <signal.h>23#include <signal.h>
24#include <unit-constants.h>24#include "util/units.h"
25#include "helper/geom-curves.h"25#include "helper/geom-curves.h"
2626
27#include "extension/print.h"27#include "extension/print.h"
@@ -117,8 +117,8 @@
117 }117 }
118118
119 // width and height in pt119 // width and height in pt
120 _width = doc->getWidth() * PT_PER_PX;120 _width = doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt");
121 _height = doc->getHeight() * PT_PER_PX;121 _height = doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt");
122122
123 if (res >= 0) {123 if (res >= 0) {
124124
125125
=== modified file 'src/extension/internal/latex-text-renderer.cpp'
--- src/extension/internal/latex-text-renderer.cpp 2012-10-28 14:10:22 +0000
+++ src/extension/internal/latex-text-renderer.cpp 2013-08-06 18:46:25 +0000
@@ -39,7 +39,7 @@
39#include "sp-rect.h"39#include "sp-rect.h"
40#include "text-editing.h"40#include "text-editing.h"
4141
42#include <unit-constants.h>42#include "util/units.h"
4343
44#include "extension/system.h"44#include "extension/system.h"
4545
@@ -611,7 +611,7 @@
611 // scaling of the image when including it in LaTeX611 // scaling of the image when including it in LaTeX
612612
613 os << " \\ifx\\svgwidth\\undefined%\n";613 os << " \\ifx\\svgwidth\\undefined%\n";
614 os << " \\setlength{\\unitlength}{" << d.width() * PT_PER_PX << "bp}%\n"; // note: 'bp' is the Postscript pt unit in LaTeX, see LP bug #792384614 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
615 os << " \\ifx\\svgscale\\undefined%\n";615 os << " \\ifx\\svgscale\\undefined%\n";
616 os << " \\relax%\n";616 os << " \\relax%\n";
617 os << " \\else%\n";617 os << " \\else%\n";
618618
=== modified file 'src/extension/internal/pdfinput/pdf-parser.cpp'
--- src/extension/internal/pdfinput/pdf-parser.cpp 2013-08-05 21:07:35 +0000
+++ src/extension/internal/pdfinput/pdf-parser.cpp 2013-08-06 18:46:25 +0000
@@ -34,7 +34,7 @@
34#include "svg-builder.h"34#include "svg-builder.h"
35#include "Gfx.h"35#include "Gfx.h"
36#include "pdf-parser.h"36#include "pdf-parser.h"
37#include "unit-constants.h"37#include "util/units.h"
3838
39#include "goo/gmem.h"39#include "goo/gmem.h"
40#include "goo/GooTimer.h"40#include "goo/GooTimer.h"
@@ -279,14 +279,14 @@
279 ignoreUndef = 0;279 ignoreUndef = 0;
280 operatorHistory = NULL;280 operatorHistory = NULL;
281 builder = builderA;281 builder = builderA;
282 builder->setDocumentSize(state->getPageWidth()*PX_PER_PT,282 builder->setDocumentSize(state->getPageWidth()*Inkscape::Util::Quantity::convert(1, "pt", "px"),
283 state->getPageHeight()*PX_PER_PT);283 state->getPageHeight()*Inkscape::Util::Quantity::convert(1, "pt", "px"));
284284
285 double *ctm = state->getCTM();285 double *ctm = state->getCTM();
286 double scaledCTM[6];286 double scaledCTM[6];
287 for (int i = 0; i < 6; ++i) {287 for (int i = 0; i < 6; ++i) {
288 baseMatrix[i] = ctm[i];288 baseMatrix[i] = ctm[i];
289 scaledCTM[i] = PX_PER_PT * ctm[i];289 scaledCTM[i] = Inkscape::Util::Quantity::convert(1, "pt", "px") * ctm[i];
290 }290 }
291 saveState();291 saveState();
292 builder->setTransform((double*)&scaledCTM);292 builder->setTransform((double*)&scaledCTM);
293293
=== modified file 'src/extension/internal/pdfinput/svg-builder.cpp'
--- src/extension/internal/pdfinput/svg-builder.cpp 2013-08-05 21:07:35 +0000
+++ src/extension/internal/pdfinput/svg-builder.cpp 2013-08-06 18:46:25 +0000
@@ -33,7 +33,7 @@
33#include "svg/css-ostringstream.h"33#include "svg/css-ostringstream.h"
34#include "svg/svg-color.h"34#include "svg/svg-color.h"
35#include "color.h"35#include "color.h"
36#include "unit-constants.h"36#include "util/units.h"
37#include "io/stringstream.h"37#include "io/stringstream.h"
38#include "io/base64stream.h"38#include "io/base64stream.h"
39#include "display/nr-filter-utils.h"39#include "display/nr-filter-utils.h"
@@ -793,7 +793,7 @@
793 Geom::Affine pat_matrix(matrix[0], matrix[1], matrix[2], matrix[3],793 Geom::Affine pat_matrix(matrix[0], matrix[1], matrix[2], matrix[3],
794 matrix[4], matrix[5]);794 matrix[4], matrix[5]);
795 if ( !for_shading && _is_top_level ) {795 if ( !for_shading && _is_top_level ) {
796 Geom::Affine flip(1.0, 0.0, 0.0, -1.0, 0.0, _height * PT_PER_PX);796 Geom::Affine flip(1.0, 0.0, 0.0, -1.0, 0.0, _height * Inkscape::Util::Quantity::convert(1, "px", "pt"));
797 pat_matrix *= flip;797 pat_matrix *= flip;
798 }798 }
799 gchar *transform_text = sp_svg_transform_write(pat_matrix);799 gchar *transform_text = sp_svg_transform_write(pat_matrix);
800800
=== modified file 'src/flood-context.cpp'
--- src/flood-context.cpp 2013-07-01 20:04:32 +0000
+++ src/flood-context.cpp 2013-08-06 18:46:25 +0000
@@ -54,7 +54,6 @@
54#include "sp-defs.h"54#include "sp-defs.h"
55#include "sp-item.h"55#include "sp-item.h"
56#include "splivarot.h"56#include "splivarot.h"
57#include "sp-metrics.h"
58#include "sp-namedview.h"57#include "sp-namedview.h"
59#include "sp-object.h"58#include "sp-object.h"
60#include "sp-path.h"59#include "sp-path.h"
6160
=== modified file 'src/flood-context.h'
--- src/flood-context.h 2013-03-14 23:24:17 +0000
+++ src/flood-context.h 2013-08-06 18:46:25 +0000
@@ -15,8 +15,6 @@
15#include <sigc++/sigc++.h>15#include <sigc++/sigc++.h>
16#include <gtk/gtk.h>16#include <gtk/gtk.h>
17#include "event-context.h"17#include "event-context.h"
18#include "helper/unit-menu.h"
19#include "helper/units.h"
2018
21#define SP_TYPE_FLOOD_CONTEXT (sp_flood_context_get_type ())19#define SP_TYPE_FLOOD_CONTEXT (sp_flood_context_get_type ())
22#define SP_FLOOD_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_FLOOD_CONTEXT, SPFloodContext))20#define SP_FLOOD_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_FLOOD_CONTEXT, SPFloodContext))
2321
=== modified file 'src/helper/Makefile_insert'
--- src/helper/Makefile_insert 2013-07-01 20:04:32 +0000
+++ src/helper/Makefile_insert 2013-08-06 18:46:25 +0000
@@ -18,12 +18,6 @@
18 helper/png-write.h \18 helper/png-write.h \
19 helper/sp-marshal.cpp \19 helper/sp-marshal.cpp \
20 helper/sp-marshal.h \20 helper/sp-marshal.h \
21 helper/unit-menu.cpp \
22 helper/unit-menu.h \
23 helper/unit-tracker.cpp \
24 helper/unit-tracker.h \
25 helper/units.cpp \
26 helper/units.h \
27 helper/window.cpp \21 helper/window.cpp \
28 helper/window.h \22 helper/window.h \
29 helper/stock-items.cpp \23 helper/stock-items.cpp \
@@ -46,9 +40,3 @@
46 else mv helper/tmp.sp-marshal.cpp helper/sp-marshal.cpp; fi40 else mv helper/tmp.sp-marshal.cpp helper/sp-marshal.cpp; fi
4741
48helper/sp-marshal.cpp helper/sp-marshal.h: helper/sp-marshal.list42helper/sp-marshal.cpp helper/sp-marshal.h: helper/sp-marshal.list
49
50# ######################
51# ### CxxTest stuff ####
52# ######################
53CXXTEST_TESTSUITES += \
54 $(srcdir)/helper/units-test.h
5543
=== modified file 'src/helper/pixbuf-ops.cpp'
--- src/helper/pixbuf-ops.cpp 2013-03-25 17:42:31 +0000
+++ src/helper/pixbuf-ops.cpp 2013-08-06 18:46:25 +0000
@@ -29,7 +29,7 @@
29#include "sp-root.h"29#include "sp-root.h"
30#include "sp-use.h"30#include "sp-use.h"
31#include "sp-defs.h"31#include "sp-defs.h"
32#include "unit-constants.h"32#include "util/units.h"
3333
34#include "helper/pixbuf-ops.h"34#include "helper/pixbuf-ops.h"
3535
@@ -121,7 +121,7 @@
121 origin[Geom::X] = origin[Geom::X] + (screen[Geom::X].extent() * ((1 - padding) / 2));121 origin[Geom::X] = origin[Geom::X] + (screen[Geom::X].extent() * ((1 - padding) / 2));
122 origin[Geom::Y] = origin[Geom::Y] + (screen[Geom::Y].extent() * ((1 - padding) / 2));122 origin[Geom::Y] = origin[Geom::Y] + (screen[Geom::Y].extent() * ((1 - padding) / 2));
123123
124 Geom::Scale scale( (xdpi / PX_PER_IN), (ydpi / PX_PER_IN));124 Geom::Scale scale( (xdpi / Inkscape::Util::Quantity::convert(1, "in", "px")), (ydpi / Inkscape::Util::Quantity::convert(1, "in", "px")));
125 Geom::Affine affine = scale * Geom::Translate(-origin * scale);125 Geom::Affine affine = scale * Geom::Translate(-origin * scale);
126126
127 /* Create ArenaItems and set transform */127 /* Create ArenaItems and set transform */
128128
=== removed file 'src/helper/unit-menu.cpp'
--- src/helper/unit-menu.cpp 2013-01-26 19:33:04 +0000
+++ src/helper/unit-menu.cpp 1970-01-01 00:00:00 +0000
@@ -1,360 +0,0 @@
1#define __SP_UNIT_MENU_C__
2
3/*
4 * Unit selector with autupdate capability
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
9 *
10 * Copyright (C) 2000-2002 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
14
15#define noUNIT_SELECTOR_VERBOSE
16
17#ifdef HAVE_CONFIG_H
18# include "config.h"
19#endif
20#include <gtk/gtk.h>
21#include "helper/sp-marshal.h"
22#include "helper/units.h"
23#include "helper/unit-menu.h"
24#include "widgets/spw-utilities.h"
25
26struct SPUnitSelector {
27 GtkHBox box;
28
29 GtkWidget *combo_box;
30 GtkListStore *store;
31
32
33 guint bases;
34 GSList *units;
35 SPUnit const *unit;
36 gdouble ctmscale;
37 guint plural : 1;
38 guint abbr : 1;
39
40 guint update : 1;
41
42 GSList *adjustments;
43};
44
45enum {COMBO_COL_LABEL=0, COMBO_COL_UNIT};
46
47struct SPUnitSelectorClass {
48 GtkHBoxClass parent_class;
49
50 gboolean (* set_unit)(SPUnitSelector *us, SPUnit const *old, SPUnit const *new_unit);
51};
52
53enum {SET_UNIT, LAST_SIGNAL};
54
55static void sp_unit_selector_finalize(GObject *object);
56
57static guint signals[LAST_SIGNAL] = {0};
58
59G_DEFINE_TYPE(SPUnitSelector, sp_unit_selector, GTK_TYPE_HBOX);
60
61static void
62sp_unit_selector_class_init(SPUnitSelectorClass *klass)
63{
64 GObjectClass *object_class = G_OBJECT_CLASS(klass);
65
66 signals[SET_UNIT] = g_signal_new("set_unit",
67 G_TYPE_FROM_CLASS(klass),
68 G_SIGNAL_RUN_LAST,
69 G_STRUCT_OFFSET(SPUnitSelectorClass, set_unit),
70 NULL, NULL,
71 sp_marshal_BOOLEAN__POINTER_POINTER,
72 G_TYPE_BOOLEAN, 2,
73 G_TYPE_POINTER, G_TYPE_POINTER);
74
75 object_class->finalize = sp_unit_selector_finalize;
76}
77
78static void
79sp_unit_selector_init(SPUnitSelector *us)
80{
81 us->ctmscale = 1.0;
82 us->abbr = FALSE;
83 us->plural = TRUE;
84
85 /**
86 * Create a combo_box and store with 2 columns,
87 * a label and a pointer to a SPUnit
88 */
89 us->store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
90 us->combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (us->store));
91
92 GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
93 g_object_set (renderer, "scale", 0.8, "scale-set", TRUE, NULL);
94 gtk_cell_renderer_set_padding (renderer, 2, 0);
95 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (us->combo_box), renderer, TRUE);
96 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (us->combo_box), renderer, "text", COMBO_COL_LABEL, NULL);
97
98 gtk_widget_show (us->combo_box);
99 gtk_box_pack_start (GTK_BOX(us), us->combo_box, TRUE, TRUE, 0);
100}
101
102static void
103sp_unit_selector_finalize(GObject *object)
104{
105 SPUnitSelector *selector = SP_UNIT_SELECTOR(object);
106
107 if (selector->combo_box) {
108 selector->combo_box = NULL;
109 }
110
111 while (selector->adjustments) {
112 g_object_unref(selector->adjustments->data);
113 selector->adjustments = g_slist_remove(selector->adjustments, selector->adjustments->data);
114 }
115
116 if (selector->units) {
117 sp_unit_free_list(selector->units);
118 }
119
120 selector->unit = NULL;
121
122 G_OBJECT_CLASS(sp_unit_selector_parent_class)->finalize(object);
123}
124
125GtkWidget *
126sp_unit_selector_new(guint bases)
127{
128 SPUnitSelector *us = SP_UNIT_SELECTOR(g_object_new(SP_TYPE_UNIT_SELECTOR, NULL));
129
130 sp_unit_selector_set_bases(us, bases);
131
132 return GTK_WIDGET(us);
133}
134
135void
136sp_unit_selector_setsize(GtkWidget *us, guint w, guint h)
137{
138 gtk_widget_set_size_request((SP_UNIT_SELECTOR(us))->combo_box, w, h);
139}
140
141SPUnit const *
142sp_unit_selector_get_unit(SPUnitSelector const *us)
143{
144 g_return_val_if_fail(us != NULL, NULL);
145 g_return_val_if_fail(SP_IS_UNIT_SELECTOR(us), NULL);
146
147 return us->unit;
148}
149
150
151static void
152on_combo_box_changed (GtkComboBox *widget, SPUnitSelector *us)
153{
154 GtkTreeIter iter;
155 if (!gtk_combo_box_get_active_iter (widget, &iter)) {
156 return;
157 }
158
159 SPUnit const *unit = NULL;
160 gtk_tree_model_get (GTK_TREE_MODEL(us->store), &iter, COMBO_COL_UNIT, &unit, -1);
161
162 g_return_if_fail(unit != NULL);
163
164#ifdef UNIT_SELECTOR_VERBOSE
165 g_print("Old unit %s new unit %s\n", us->unit->name, unit->name);
166#endif
167
168 SPUnit const *old = us->unit;
169 us->unit = unit;
170
171 us->update = TRUE;
172
173 gboolean consumed = FALSE;
174 g_signal_emit(G_OBJECT(us), signals[SET_UNIT], 0, old, unit, &consumed);
175
176 if ( !consumed
177 && ( unit->base == old->base
178 || ( unit->base == SP_UNIT_ABSOLUTE && old->base == SP_UNIT_DEVICE )
179 || ( old->base == SP_UNIT_ABSOLUTE && unit->base == SP_UNIT_DEVICE ) ) ) {
180 // Either the same base, or absolute<->device:
181 /* Recalculate adjustments. */
182 for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) {
183 GtkAdjustment *adj = GTK_ADJUSTMENT(l->data);
184 gdouble val = gtk_adjustment_get_value (adj);
185#ifdef UNIT_SELECTOR_VERBOSE
186 g_print("Old val %g ... ", val);
187#endif
188 val = sp_convert_distance_full(val, *old, *unit);
189#ifdef UNIT_SELECTOR_VERBOSE
190 g_print("new val %g\n", val);
191#endif
192 gtk_adjustment_set_value (adj, val);
193 }
194 /* need to separate the value changing from the notification
195 * or else the unit changes can break the calculations */
196 for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) {
197 gtk_adjustment_value_changed(GTK_ADJUSTMENT(l->data));
198 }
199 } else if (!consumed && unit->base != old->base) {
200 /* when the base changes, signal all the adjustments to get them
201 * to recalculate */
202 for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) {
203 g_signal_emit_by_name(G_OBJECT(l->data), "value_changed");
204 }
205 }
206
207 us->update = FALSE;
208
209}
210
211static void
212spus_rebuild_menu(SPUnitSelector *us)
213{
214
215 gtk_list_store_clear(us->store);
216
217 GtkTreeIter iter;
218
219 gint pos = 0;
220 gint p = 0;
221 for (GSList *l = us->units; l != NULL; l = l->next) {
222 SPUnit const *u = static_cast<SPUnit const*>(l->data);
223
224 // use only abbreviations in the menu
225 // i = gtk_menu_item_new_with_label((us->abbr) ? (us->plural) ? u->abbr_plural : u->abbr : (us->plural) ? u->plural : u->name);
226 gtk_list_store_append (us->store, &iter);
227 gtk_list_store_set (us->store, &iter, COMBO_COL_LABEL, u->abbr, COMBO_COL_UNIT, (gpointer) u, -1);
228
229 if (u == us->unit) {
230 pos = p;
231 }
232
233 p += 1;
234 }
235
236 gtk_combo_box_set_active(GTK_COMBO_BOX(us->combo_box), pos);
237 g_signal_connect (G_OBJECT (us->combo_box), "changed", G_CALLBACK (on_combo_box_changed), us);
238}
239
240void
241sp_unit_selector_set_bases(SPUnitSelector *us, guint bases)
242{
243 g_return_if_fail(us != NULL);
244 g_return_if_fail(SP_IS_UNIT_SELECTOR(us));
245
246 if (bases == us->bases) return;
247
248 GSList *units = sp_unit_get_list(bases);
249 g_return_if_fail(units != NULL);
250 sp_unit_free_list(us->units);
251 us->units = units;
252 us->unit = static_cast<SPUnit *>(units->data);
253
254 spus_rebuild_menu(us);
255}
256
257void
258sp_unit_selector_add_unit(SPUnitSelector *us, SPUnit const *unit, int position)
259{
260 if (!g_slist_find(us->units, (gpointer) unit)) {
261 us->units = g_slist_insert(us->units, (gpointer) unit, position);
262
263 spus_rebuild_menu(us);
264 }
265}
266
267void
268sp_unit_selector_set_unit(SPUnitSelector *us, SPUnit const *unit)
269{
270 g_return_if_fail(us != NULL);
271 g_return_if_fail(SP_IS_UNIT_SELECTOR(us));
272
273 if (unit == NULL) {
274 return; // silently return, by default a newly created selector uses pt
275 }
276 if (unit == us->unit) {
277 return;
278 }
279
280 gint const pos = g_slist_index(us->units, (gpointer) unit);
281 g_return_if_fail(pos >= 0);
282
283 gtk_combo_box_set_active(GTK_COMBO_BOX(us->combo_box), pos);
284
285 SPUnit const *old = us->unit;
286 us->unit = unit;
287
288 /* Recalculate adjustments */
289 for (GSList *l = us->adjustments; l != NULL; l = l->next) {
290 GtkAdjustment *adj = GTK_ADJUSTMENT(l->data);
291 gdouble const val = sp_convert_distance_full(gtk_adjustment_get_value (adj), *old, *unit);
292 gtk_adjustment_set_value(adj, val);
293 }
294}
295
296void
297sp_unit_selector_add_adjustment(SPUnitSelector *us, GtkAdjustment *adj)
298{
299 g_return_if_fail(us != NULL);
300 g_return_if_fail(SP_IS_UNIT_SELECTOR(us));
301 g_return_if_fail(adj != NULL);
302 g_return_if_fail(GTK_IS_ADJUSTMENT(adj));
303
304 g_return_if_fail(!g_slist_find(us->adjustments, adj));
305
306 g_object_ref(adj);
307 us->adjustments = g_slist_prepend(us->adjustments, adj);
308}
309
310void
311sp_unit_selector_remove_adjustment(SPUnitSelector *us, GtkAdjustment *adj)
312{
313 g_return_if_fail(us != NULL);
314 g_return_if_fail(SP_IS_UNIT_SELECTOR(us));
315 g_return_if_fail(adj != NULL);
316 g_return_if_fail(GTK_IS_ADJUSTMENT(adj));
317
318 g_return_if_fail(g_slist_find(us->adjustments, adj));
319
320 us->adjustments = g_slist_remove(us->adjustments, adj);
321 g_object_unref(adj);
322}
323
324gboolean
325sp_unit_selector_update_test(SPUnitSelector const *selector)
326{
327 g_return_val_if_fail(selector != NULL, FALSE);
328 g_return_val_if_fail(SP_IS_UNIT_SELECTOR(selector), FALSE);
329
330 return selector->update;
331}
332
333double
334sp_unit_selector_get_value_in_pixels(SPUnitSelector const *selector, GtkAdjustment *adj)
335{
336 g_return_val_if_fail(selector != NULL, gtk_adjustment_get_value (adj));
337 g_return_val_if_fail(SP_IS_UNIT_SELECTOR(selector), gtk_adjustment_get_value (adj));
338
339 return sp_units_get_pixels(gtk_adjustment_get_value (adj), *(selector->unit));
340}
341
342void
343sp_unit_selector_set_value_in_pixels(SPUnitSelector *selector, GtkAdjustment *adj, double value)
344{
345 g_return_if_fail(selector != NULL);
346 g_return_if_fail(SP_IS_UNIT_SELECTOR(selector));
347
348 gtk_adjustment_set_value(adj, sp_pixels_get_units(value, *(selector->unit)));
349}
350
351/*
352 Local Variables:
353 mode:c++
354 c-file-style:"stroustrup"
355 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
356 indent-tabs-mode:nil
357 fill-column:99
358 End:
359*/
360// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
3610
=== removed file 'src/helper/unit-menu.h'
--- src/helper/unit-menu.h 2011-12-08 11:53:54 +0000
+++ src/helper/unit-menu.h 1970-01-01 00:00:00 +0000
@@ -1,60 +0,0 @@
1#ifndef SP_UNIT_MENU_H
2#define SP_UNIT_MENU_H
3
4/*
5 * SPUnitMenu
6 *
7 * Generic (and quite unintelligent) grid item for gnome canvas
8 *
9 * Copyright (C) Lauris Kaplinski 2000
10 *
11 */
12
13#include <glib.h>
14#include <gtk/gtk.h>
15
16struct SPUnit;
17struct SPUnitSelector;
18struct SPUnitSelectorClass;
19
20/* Unit selector Widget */
21
22#define SP_TYPE_UNIT_SELECTOR (sp_unit_selector_get_type())
23#define SP_UNIT_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_UNIT_SELECTOR, SPUnitSelector))
24#define SP_UNIT_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SP_TYPE_UNIT_SELECTOR, SPUnitSelectorClass))
25#define SP_IS_UNIT_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_UNIT_SELECTOR))
26#define SP_IS_UNIT_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), SP_TYPE_UNIT_SELECTOR))
27
28GType sp_unit_selector_get_type(void);
29
30GtkWidget *sp_unit_selector_new(guint bases);
31void sp_unit_selector_setsize(GtkWidget *us, guint w, guint h);
32
33SPUnit const *sp_unit_selector_get_unit(SPUnitSelector const *selector);
34
35void sp_unit_selector_set_bases(SPUnitSelector *selector, guint bases);
36void sp_unit_selector_add_unit(SPUnitSelector *selector, SPUnit const *unit, int position);
37
38void sp_unit_selector_set_unit(SPUnitSelector *selector, SPUnit const *unit);
39void sp_unit_selector_add_adjustment(SPUnitSelector *selector, GtkAdjustment *adjustment);
40void sp_unit_selector_remove_adjustment(SPUnitSelector *selector, GtkAdjustment *adjustment);
41
42gboolean sp_unit_selector_update_test(SPUnitSelector const *selector);
43
44double sp_unit_selector_get_value_in_pixels(SPUnitSelector const *selector, GtkAdjustment *adj);
45void sp_unit_selector_set_value_in_pixels(SPUnitSelector *selector, GtkAdjustment *adj, double value);
46
47
48
49#endif // SP_UNIT_MENU_H
50
51/*
52 Local Variables:
53 mode:c++
54 c-file-style:"stroustrup"
55 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
56 indent-tabs-mode:nil
57 fill-column:99
58 End:
59*/
60// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
610
=== removed file 'src/helper/unit-tracker.cpp'
--- src/helper/unit-tracker.cpp 2011-06-03 10:44:52 +0000
+++ src/helper/unit-tracker.cpp 1970-01-01 00:00:00 +0000
@@ -1,267 +0,0 @@
1/*
2 * Inkscape::UnitTracker - Simple mediator to synchronize changes to a set
3 * of possible units
4 *
5 * Authors:
6 * Jon A. Cruz <jon@joncruz.org>
7 *
8 * Copyright (C) 2007 Jon A. Cruz
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
12
13#include <gtk/gtk.h>
14
15#include "unit-tracker.h"
16#include "ege-select-one-action.h"
17
18namespace Inkscape {
19
20enum {
21 COLUMN_STRING,
22 COLUMN_SPUNIT,
23 N_COLUMNS
24};
25
26UnitTracker::UnitTracker( guint bases ) :
27 _active(0),
28 _isUpdating(false),
29 _activeUnit(0),
30 _store(0),
31 _unitList(0),
32 _actionList(0),
33 _adjList(0),
34 _priorValues()
35{
36 _store = gtk_list_store_new( N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER );
37 setBase( bases );
38}
39
40UnitTracker::~UnitTracker()
41{
42 if ( _unitList ) {
43 sp_unit_free_list( _unitList );
44 }
45
46 // Unhook weak references to GtkActions
47 while ( _actionList ) {
48 g_signal_handlers_disconnect_by_func( G_OBJECT(_actionList->data), (gpointer)_unitChangedCB, this );
49 g_object_weak_unref( G_OBJECT(_actionList->data), _actionFinalizedCB, this );
50 _actionList = g_slist_delete_link( _actionList, _actionList );
51 }
52
53 // Unhook wek references to GtkAdjustments
54 while ( _adjList ) {
55 g_object_weak_unref( G_OBJECT(_adjList->data), _adjustmentFinalizedCB, this );
56 _adjList = g_slist_delete_link( _adjList, _adjList );
57 }
58}
59
60void UnitTracker::setBase( guint bases )
61{
62 GtkTreeIter iter;
63 _unitList = sp_unit_get_list( bases );
64 for ( GSList* cur = _unitList; cur; cur = g_slist_next(cur) ) {
65 SPUnit* unit = static_cast<SPUnit*>(cur->data);
66 gtk_list_store_append( _store, &iter );
67 gtk_list_store_set( _store, &iter, COLUMN_STRING, unit->abbr, COLUMN_SPUNIT, unit, -1 );
68 }
69 gint count = gtk_tree_model_iter_n_children( GTK_TREE_MODEL(_store), 0 );
70 if ( (count > 0) && (_active > count) ) {
71 _setActive( count - 1 );
72 } else {
73 _setActive( _active );
74 }
75}
76
77void UnitTracker::addUnit( SPUnitId id, gint index )
78{
79 GtkTreeIter iter;
80 const SPUnit* percentUnit = &sp_unit_get_by_id( id );
81 gtk_list_store_insert( _store, &iter, index );
82 gtk_list_store_set( _store, &iter, COLUMN_STRING, percentUnit->abbr, COLUMN_SPUNIT, percentUnit, -1 );
83}
84
85bool UnitTracker::isUpdating() const
86{
87 return _isUpdating;
88}
89
90SPUnit const* UnitTracker::getActiveUnit() const
91{
92 return _activeUnit;
93}
94
95void UnitTracker::setActiveUnit( SPUnit const *unit )
96{
97 if ( unit ) {
98 GtkTreeIter iter;
99 int index = 0;
100 gboolean found = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(_store), &iter );
101 while ( found ) {
102 SPUnit* storedUnit = 0;
103 gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &storedUnit, -1 );
104 if ( storedUnit && (storedUnit->unit_id == unit->unit_id) ) {
105 _setActive(index);
106 break;
107 }
108
109 found = gtk_tree_model_iter_next( GTK_TREE_MODEL(_store), &iter );
110 index++;
111 }
112 }
113}
114
115void UnitTracker::addAdjustment( GtkAdjustment* adj )
116{
117 if ( !g_slist_find( _adjList, adj ) ) {
118 g_object_weak_ref( G_OBJECT(adj), _adjustmentFinalizedCB, this );
119 _adjList = g_slist_append( _adjList, adj );
120 }
121}
122
123void UnitTracker::setFullVal( GtkAdjustment* adj, gdouble val )
124{
125 _priorValues[adj] = val;
126}
127
128GtkAction* UnitTracker::createAction( gchar const* name, gchar const* label, gchar const* tooltip )
129{
130 EgeSelectOneAction* act1 = ege_select_one_action_new( name, label, tooltip, NULL, GTK_TREE_MODEL(_store) );
131 ege_select_one_action_set_label_column( act1, COLUMN_STRING );
132 if ( _active ) {
133 ege_select_one_action_set_active( act1, _active );
134 }
135
136 ege_select_one_action_set_appearance( act1, "minimal" );
137 g_object_weak_ref( G_OBJECT(act1), _actionFinalizedCB, this );
138 g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK( _unitChangedCB ), this );
139 _actionList = g_slist_append( _actionList, act1 );
140
141 return GTK_ACTION(act1);
142}
143
144void UnitTracker::_unitChangedCB( GtkAction* action, gpointer data )
145{
146 if ( action && data ) {
147 EgeSelectOneAction* act = EGE_SELECT_ONE_ACTION(action);
148 gint active = ege_select_one_action_get_active( act );
149 UnitTracker* self = reinterpret_cast<UnitTracker*>(data);
150 self->_setActive(active);
151 }
152}
153
154void UnitTracker::_actionFinalizedCB( gpointer data, GObject *where_the_object_was )
155{
156 if ( data && where_the_object_was ) {
157 UnitTracker* self = reinterpret_cast<UnitTracker*>(data);
158 self->_actionFinalized( where_the_object_was );
159 }
160}
161
162void UnitTracker::_adjustmentFinalizedCB( gpointer data, GObject *where_the_object_was )
163{
164 if ( data && where_the_object_was ) {
165 UnitTracker* self = reinterpret_cast<UnitTracker*>(data);
166 self->_adjustmentFinalized( where_the_object_was );
167 }
168}
169
170void UnitTracker::_actionFinalized( GObject *where_the_object_was )
171{
172 GSList* target = g_slist_find( _actionList, where_the_object_was );
173 if ( target ) {
174 _actionList = g_slist_remove( _actionList, where_the_object_was );
175 } else {
176 g_warning("Received a finalization callback for unknown object %p", where_the_object_was );
177 }
178}
179
180void UnitTracker::_adjustmentFinalized( GObject *where_the_object_was )
181{
182 GSList* target = g_slist_find( _adjList, where_the_object_was );
183 if ( target ) {
184 _adjList = g_slist_remove( _adjList, where_the_object_was );
185 } else {
186 g_warning("Received a finalization callback for unknown object %p", where_the_object_was );
187 }
188}
189
190void UnitTracker::_setActive( gint active )
191{
192 if ( active != _active || (_activeUnit == 0) ) {
193 gint oldActive = _active;
194
195 GtkTreeIter iter;
196 gboolean found = gtk_tree_model_iter_nth_child( GTK_TREE_MODEL(_store), &iter, NULL, oldActive );
197 if ( found ) {
198 SPUnit* unit = 0;
199 gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &unit, -1 );
200
201 found = gtk_tree_model_iter_nth_child( GTK_TREE_MODEL(_store), &iter, NULL, active );
202 if ( found ) {
203 SPUnit* newUnit = 0;
204 gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &newUnit, -1 );
205 _activeUnit = newUnit;
206
207 if ( _adjList ) {
208 _fixupAdjustments( unit, newUnit );
209 }
210
211 } else {
212 g_warning("Did not find new unit");
213 }
214 } else {
215 g_warning("Did not find old unit");
216 }
217
218 _active = active;
219
220 for ( GSList* cur = _actionList; cur; cur = g_slist_next(cur) ) {
221 if ( IS_EGE_SELECT_ONE_ACTION( cur->data ) ) {
222 EgeSelectOneAction* act = EGE_SELECT_ONE_ACTION( cur->data );
223 ege_select_one_action_set_active( act, active );
224 }
225 }
226 }
227}
228
229void UnitTracker::_fixupAdjustments( SPUnit const* oldUnit, SPUnit const *newUnit )
230{
231 _isUpdating = true;
232 for ( GSList* cur = _adjList; cur; cur = g_slist_next(cur) ) {
233 GtkAdjustment* adj = GTK_ADJUSTMENT(cur->data);
234 gdouble oldVal = gtk_adjustment_get_value(adj);
235 gdouble val = oldVal;
236
237 if ((oldUnit->base == SP_UNIT_ABSOLUTE || oldUnit->base == SP_UNIT_DEVICE)
238 && (newUnit->base == SP_UNIT_DIMENSIONLESS))
239 {
240 val = 1.0 / newUnit->unittobase;
241 _priorValues[adj] = sp_units_get_pixels( oldVal, *oldUnit );
242 } else if ((oldUnit->base == SP_UNIT_DIMENSIONLESS)
243 && (newUnit->base == SP_UNIT_ABSOLUTE || newUnit->base == SP_UNIT_DEVICE)) {
244 if ( _priorValues.find(adj) != _priorValues.end() ) {
245 val = sp_pixels_get_units( _priorValues[adj], *newUnit );
246 }
247 } else {
248 val = sp_convert_distance_full( oldVal, *oldUnit, *newUnit );
249 }
250
251 gtk_adjustment_set_value( adj, val );
252 }
253 _isUpdating = false;
254}
255
256}
257
258/*
259 Local Variables:
260 mode:c++
261 c-file-style:"stroustrup"
262 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
263 indent-tabs-mode:nil
264 fill-column:99
265 End:
266*/
267// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
2680
=== removed file 'src/helper/unit-tracker.h'
--- src/helper/unit-tracker.h 2011-06-03 10:44:52 +0000
+++ src/helper/unit-tracker.h 1970-01-01 00:00:00 +0000
@@ -1,75 +0,0 @@
1/*
2 * Inkscape::UnitTracker - Simple mediator to synchronize changes to a set
3 * of possible units
4 *
5 * Authors:
6 * Jon A. Cruz <jon@joncruz.org>
7 *
8 * Copyright (C) 2007 Jon A. Cruz
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
12
13#ifndef SEEN_INKSCAPE_UNIT_TRACKER_H
14#define SEEN_INKSCAPE_UNIT_TRACKER_H
15
16#include <map>
17
18#include <gtk/gtk.h>
19
20#include "helper/units.h"
21
22namespace Inkscape {
23
24class UnitTracker
25{
26public:
27 UnitTracker( guint bases = (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE) );
28 virtual ~UnitTracker();
29
30 void setBase( guint bases ); // SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE
31 void addUnit( SPUnitId id, gint index );
32
33 bool isUpdating() const;
34
35 void setActiveUnit( SPUnit const *unit );
36 SPUnit const* getActiveUnit() const;
37
38 void addAdjustment( GtkAdjustment* adj );
39 void setFullVal( GtkAdjustment* adj, gdouble val );
40
41 GtkAction* createAction( gchar const* name, gchar const* label, gchar const* tooltip );
42
43private:
44 static void _unitChangedCB( GtkAction* action, gpointer data );
45 static void _actionFinalizedCB( gpointer data, GObject *where_the_object_was );
46 static void _adjustmentFinalizedCB( gpointer data, GObject *where_the_object_was );
47 void _setActive( gint index );
48 void _fixupAdjustments( SPUnit const* oldUnit, SPUnit const *newUnit );
49 void _actionFinalized( GObject *where_the_object_was );
50 void _adjustmentFinalized( GObject *where_the_object_was );
51
52 gint _active;
53 bool _isUpdating;
54 SPUnit* _activeUnit;
55 GtkListStore* _store;
56 GSList* _unitList;
57 GSList* _actionList;
58 GSList* _adjList;
59 std::map <GtkAdjustment*, gdouble> _priorValues;
60};
61
62}
63
64#endif // SEEN_INKSCAPE_UNIT_TRACKER_H
65
66/*
67 Local Variables:
68 mode:c++
69 c-file-style:"stroustrup"
70 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
71 indent-tabs-mode:nil
72 fill-column:99
73 End:
74*/
75// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
760
=== removed file 'src/helper/units-test.h'
--- src/helper/units-test.h 2010-11-17 02:12:56 +0000
+++ src/helper/units-test.h 1970-01-01 00:00:00 +0000
@@ -1,90 +0,0 @@
1#include <cxxtest/TestSuite.h>
2
3#include <helper/units.h>
4#include <glibmm/i18n.h>
5#include <math.h>
6
7class UnitsTest : public CxxTest::TestSuite {
8public:
9
10 UnitsTest()
11 {
12 }
13 virtual ~UnitsTest() {}
14
15// createSuite and destroySuite get us per-suite setup and teardown
16// without us having to worry about static initialization order, etc.
17 static UnitsTest *createSuite() { return new UnitsTest(); }
18 static void destroySuite( UnitsTest *suite ) { delete suite; }
19
20 void testConversions()
21 {
22 struct Case { double x; char const *abbr; double pts; } const tests[] = {
23 { 1.0, "pt", 1.0 },
24 { 5.0, "pt", 5.0 },
25 { 1.0, "in", 72.0 },
26 { 2.0, "in", 144.0 },
27 { 254., "mm", 720.0 },
28 { 254., "cm", 7200. },
29 { 254., "m", 720000. },
30 { 1.5, "mm", (15 * 72. / 254) }
31 };
32 for (unsigned i = 0; i < G_N_ELEMENTS(tests); ++i) {
33 Case const &c = tests[i];
34 SPUnit const &unit = *sp_unit_get_by_abbreviation(N_(c.abbr));
35
36 double const calc_pts = sp_units_get_points(c.x, unit);
37 TS_ASSERT(approx_equal(calc_pts, c.pts));
38
39 double const calc_x = sp_points_get_units(c.pts, unit);
40 TS_ASSERT(approx_equal(calc_x, c.x));
41
42 double tmp = c.x;
43 bool const converted_to_pts = sp_convert_distance(&tmp, &unit, SP_PS_UNIT);
44 TS_ASSERT(converted_to_pts);
45 TS_ASSERT(approx_equal(tmp, c.pts));
46
47 tmp = c.pts;
48 bool const converted_from_pts = sp_convert_distance(&tmp, SP_PS_UNIT, &unit);
49 TS_ASSERT(converted_from_pts);
50 TS_ASSERT(approx_equal(tmp, c.x));
51 }
52 }
53
54 void testUnitTable()
55 {
56 TS_ASSERT(sp_units_table_sane());
57 }
58
59private:
60 /* N.B. Wrongly returns false if both near 0. (Not a problem for current users.) */
61 bool approx_equal(double const x, double const y)
62 {
63 return fabs(x / y - 1) < 1e-15;
64 }
65
66 double sp_units_get_points(double const x, SPUnit const &unit)
67 {
68 SPUnit const &pt_unit = sp_unit_get_by_id(SP_UNIT_PT);
69 double const px = sp_units_get_pixels(x, unit);
70 return sp_pixels_get_units(px, pt_unit);
71 }
72
73 double sp_points_get_units(double const pts, SPUnit const &unit)
74 {
75 SPUnit const &pt_unit = sp_unit_get_by_id(SP_UNIT_PT);
76 double const px = sp_units_get_pixels(pts, pt_unit);
77 return sp_pixels_get_units(px, unit);
78 }
79};
80
81/*
82 Local Variables:
83 mode:c++
84 c-file-style:"stroustrup"
85 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
86 indent-tabs-mode:nil
87 fill-column:99
88 End:
89*/
90// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
910
=== removed file 'src/helper/units.cpp'
--- src/helper/units.cpp 2012-10-27 18:15:53 +0000
+++ src/helper/units.cpp 1970-01-01 00:00:00 +0000
@@ -1,261 +0,0 @@
1#define __SP_PAPER_C__
2
3/*
4 * SPUnit
5 *
6 * Ported from libgnomeprint
7 *
8 * Authors:
9 * Dirk Luetjens <dirk@luedi.oche.de>
10 * Yves Arrouye <Yves.Arrouye@marin.fdn.fr>
11 * Lauris Kaplinski <lauris@ximian.com>
12 * bulia byak <buliabyak@users.sf.net>
13 *
14 * Copyright 1999-2001 Ximian, Inc. and authors
15 *
16 */
17
18#ifdef HAVE_CONFIG_H
19# include "config.h"
20#endif
21
22#include "helper/units.h"
23#include <glib.h> // g_assert()
24#include <glibmm/i18n.h>
25#include "unit-constants.h"
26#include "svg/svg-length.h"
27
28/* todo: use some fancy unit program */
29
30/* The order determines the order of the list returned by sp_unit_get_list.
31 * (It can also affect string lookups if there are any duplicates in the
32 * current locale... hopefully none.) If you re-order this list, then you must
33 * also re-order the SPUnitId enum values accordingly. Run `make check' (which
34 * calls sp_unit_table_sane) to ensure that the two are in sync.
35 */
36SPUnit const sp_units[] = {
37 {SP_UNIT_SCALE, SP_UNIT_DIMENSIONLESS, 1.0, SP_NONE, SVGLength::NONE, N_("Unit"), "", N_("Units"), ""},
38 {SP_UNIT_PT, SP_UNIT_ABSOLUTE, PX_PER_PT, SP_PT, SVGLength::PT, N_("Point"), N_("pt"), N_("Points"), N_("Pt")},
39 {SP_UNIT_PC, SP_UNIT_ABSOLUTE, PX_PER_PC, SP_PC, SVGLength::PC, N_("Pica"), N_("pc"), N_("Picas"), N_("Pc")},
40 {SP_UNIT_PX, SP_UNIT_DEVICE, PX_PER_PX, SP_PX, SVGLength::PX, N_("Pixel"), N_("px"), N_("Pixels"), N_("Px")},
41 /* You can add new elements from this point forward */
42 {SP_UNIT_PERCENT, SP_UNIT_DIMENSIONLESS, 0.01, SP_NONE, SVGLength::PERCENT, N_("Percent"), N_("%"), N_("Percents"), N_("%")},
43 {SP_UNIT_MM, SP_UNIT_ABSOLUTE, PX_PER_MM, SP_MM, SVGLength::MM, N_("Millimeter"), N_("mm"), N_("Millimeters"), N_("mm")},
44 {SP_UNIT_CM, SP_UNIT_ABSOLUTE, PX_PER_CM, SP_CM, SVGLength::CM, N_("Centimeter"), N_("cm"), N_("Centimeters"), N_("cm")},
45 {SP_UNIT_M, SP_UNIT_ABSOLUTE, PX_PER_M, SP_M, SVGLength::NONE, N_("Meter"), N_("m"), N_("Meters"), N_("m")}, // no svg_unit
46 {SP_UNIT_IN, SP_UNIT_ABSOLUTE, PX_PER_IN, SP_IN, SVGLength::INCH, N_("Inch"), N_("in"), N_("Inches"), N_("in")},
47 {SP_UNIT_FT, SP_UNIT_ABSOLUTE, PX_PER_FT, SP_FT, SVGLength::FOOT, N_("Foot"), N_("ft"), N_("Feet"), N_("ft")},
48 /* Volatiles do not have default, so there are none here */
49 // TRANSLATORS: for info, see http://www.w3.org/TR/REC-CSS2/syndata.html#length-units
50 {SP_UNIT_EM, SP_UNIT_VOLATILE, 1.0, SP_NONE, SVGLength::EM, N_("Em square"), N_("em"), N_("Em squares"), N_("em")},
51 // TRANSLATORS: for info, see http://www.w3.org/TR/REC-CSS2/syndata.html#length-units
52 {SP_UNIT_EX, SP_UNIT_VOLATILE, 1.0, SP_NONE, SVGLength::EX, N_("Ex square"), N_("ex"), N_("Ex squares"), N_("ex")},
53};
54
55#define sp_num_units G_N_ELEMENTS(sp_units)
56
57SPUnit const *
58sp_unit_get_by_abbreviation(gchar const *abbreviation)
59{
60 g_return_val_if_fail(abbreviation != NULL, NULL);
61
62 for (unsigned i = 0 ; i < sp_num_units ; i++) {
63 if (!g_ascii_strcasecmp(abbreviation, sp_units[i].abbr)) return &sp_units[i];
64 if (!g_ascii_strcasecmp(abbreviation, sp_units[i].abbr_plural)) return &sp_units[i];
65 }
66
67 return NULL;
68}
69
70gchar const *
71sp_unit_get_abbreviation(SPUnit const *unit)
72{
73 g_return_val_if_fail(unit != NULL, NULL);
74
75 return unit->abbr;
76}
77
78gchar const *
79sp_unit_get_plural (SPUnit const *unit)
80{
81 g_return_val_if_fail(unit != NULL, NULL);
82
83 return unit->plural;
84}
85
86SPMetric sp_unit_get_metric(SPUnit const *unit)
87{
88 g_return_val_if_fail(unit != NULL, SP_NONE);
89
90 return unit->metric;
91}
92
93guint sp_unit_get_svg_unit(SPUnit const *unit)
94{
95 g_return_val_if_fail(unit != NULL, SP_NONE);
96
97 return unit->svg_unit;
98}
99
100GSList *
101sp_unit_get_list(guint bases)
102{
103 g_return_val_if_fail((bases & ~SP_UNITS_ALL) == 0, NULL);
104
105 GSList *units = NULL;
106 for (unsigned i = sp_num_units ; i--; ) {
107 if (bases & sp_units[i].base) {
108 units = g_slist_prepend(units, (gpointer) &sp_units[i]);
109 }
110 }
111
112 return units;
113}
114
115void
116sp_unit_free_list(GSList *units)
117{
118 g_slist_free(units);
119}
120
121/* These are pure utility */
122/* Return TRUE if conversion is possible */
123gboolean
124sp_convert_distance(gdouble *distance, SPUnit const *from, SPUnit const *to)
125{
126 g_return_val_if_fail(distance != NULL, FALSE);
127 g_return_val_if_fail(from != NULL, FALSE);
128 g_return_val_if_fail(to != NULL, FALSE);
129
130 if (from == to) return TRUE;
131 if ((from->base == SP_UNIT_DIMENSIONLESS) || (to->base == SP_UNIT_DIMENSIONLESS)) {
132 *distance = *distance * from->unittobase / to->unittobase;
133 return TRUE;
134 }
135 if ((from->base == SP_UNIT_VOLATILE) || (to->base == SP_UNIT_VOLATILE)) return FALSE;
136
137 if ((from->base == to->base)
138 || ((from->base == SP_UNIT_DEVICE) && (to->base == SP_UNIT_ABSOLUTE))
139 || ((from->base == SP_UNIT_ABSOLUTE) && (to->base == SP_UNIT_DEVICE)))
140 {
141 *distance = *distance * from->unittobase / to->unittobase;
142 return TRUE;
143 }
144
145 return FALSE;
146}
147
148/** @param devicetransform for device units. */
149/* TODO: Remove the ctmscale parameter given that we no longer have SP_UNIT_USERSPACE. */
150gdouble
151sp_convert_distance_full(gdouble const from_dist, SPUnit const &from, SPUnit const &to)
152{
153 if (&from == &to) {
154 return from_dist;
155 }
156 if (from.base == to.base) {
157 gdouble ret = from_dist;
158 bool const succ = sp_convert_distance(&ret, &from, &to);
159 g_assert(succ);
160 return ret;
161 }
162 if ((from.base == SP_UNIT_DIMENSIONLESS)
163 || (to.base == SP_UNIT_DIMENSIONLESS))
164 {
165 return from_dist * from.unittobase / to.unittobase;
166 }
167 g_return_val_if_fail(((from.base != SP_UNIT_VOLATILE)
168 && (to.base != SP_UNIT_VOLATILE)),
169 from_dist);
170
171 gdouble absolute;
172 switch (from.base) {
173 case SP_UNIT_ABSOLUTE:
174 case SP_UNIT_DEVICE:
175 absolute = from_dist * from.unittobase;
176 break;
177 default:
178 g_warning("file %s: line %d: Illegal unit (base 0x%x)", __FILE__, __LINE__, from.base);
179 return from_dist;
180 }
181
182 gdouble ret;
183 switch (to.base) {
184 default:
185 g_warning("file %s: line %d: Illegal unit (base 0x%x)", __FILE__, __LINE__, to.base);
186 /* FALL-THROUGH */
187 case SP_UNIT_ABSOLUTE:
188 case SP_UNIT_DEVICE:
189 ret = absolute / to.unittobase;
190 break;
191 }
192
193 return ret;
194}
195
196/* Some more convenience */
197
198gdouble
199sp_units_get_pixels(gdouble const units, SPUnit const &unit)
200{
201 if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
202 return units * unit.unittobase;
203 } else {
204 g_warning("Different unit bases: No exact unit conversion available");
205 return units * unit.unittobase;
206 }
207}
208
209gdouble
210sp_pixels_get_units(gdouble const pixels, SPUnit const &unit)
211{
212 if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
213 return pixels / unit.unittobase;
214 } else {
215 g_warning("Different unit bases: No exact unit conversion available");
216 return pixels / unit.unittobase;
217 }
218}
219
220bool
221sp_units_table_sane()
222{
223 for (unsigned i = 0; i < G_N_ELEMENTS(sp_units); ++i) {
224 if (unsigned(sp_units[i].unit_id) != i) {
225 return false;
226 }
227 }
228 return true;
229}
230
231/** Converts angle (in deg) to compass display */
232double
233angle_to_compass(double angle)
234{
235 double ret = 90 - angle;
236 if (ret < 0)
237 ret = 360 + ret;
238 return ret;
239}
240
241/** Converts angle (in deg) to compass display */
242double
243angle_from_compass(double angle)
244{
245 double ret = 90 - angle;
246 if (ret > 180)
247 ret = ret - 180;
248 return ret;
249}
250
251
252/*
253 Local Variables:
254 mode:c++
255 c-file-style:"stroustrup"
256 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
257 indent-tabs-mode:nil
258 fill-column:99
259 End:
260*/
261// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
2620
=== removed file 'src/helper/units.h'
--- src/helper/units.h 2011-12-08 11:53:54 +0000
+++ src/helper/units.h 1970-01-01 00:00:00 +0000
@@ -1,146 +0,0 @@
1#ifndef __SP_UNIT_H__
2#define __SP_UNIT_H__
3
4/*
5 * SPUnit
6 *
7 * Ported from libgnomeprint
8 *
9 * Authors:
10 * Dirk Luetjens <dirk@luedi.oche.de>
11 * Yves Arrouye <Yves.Arrouye@marin.fdn.fr>
12 * Lauris Kaplinski <lauris@ximian.com>
13 *
14 * Copyright 1999-2001 Ximian, Inc. and authors
15 *
16 */
17
18#include <glib.h>
19#include "sp-metric.h"
20
21
22/*
23 * Units and conversion methods used by libgnomeprint.
24 *
25 * You need those for certain config keys (like paper size), if you are
26 * interested in using these (look at gnome-print-config.h for discussion,
27 * why you may NOT be interested in paper size).
28 *
29 * Unit bases define set of mutually unrelated measuring systems (numbers,
30 * paper, screen and dimesionless user coordinates). Still, you can convert
31 * between those, specifying scaling factors explicitly.
32 *
33 * Paper (i.e. output) coordinates are taken as absolute real world units.
34 * It has some justification, because screen unit (pixel) size changes,
35 * if you change screen resolution, while you cannot change output on paper
36 * as easily (unless you have thermally contracting paper, of course).
37 *
38 */
39
40struct SPUnit;
41struct SPDistance;
42
43/*
44 * The base linear ("absolute") unit is 1/72th of an inch, i.e. the base unit of postscript.
45 */
46
47/*
48 * Unit bases
49 */
50enum SPUnitBase {
51 SP_UNIT_DIMENSIONLESS = (1 << 0), /* For percentages and like */
52 SP_UNIT_ABSOLUTE = (1 << 1), /* Real world distances - i.e. mm, cm... */
53 SP_UNIT_DEVICE = (1 << 2), /* Pixels in the SVG/CSS sense. */
54 SP_UNIT_VOLATILE = (1 << 3) /* em and ex */
55};
56
57/*
58 * Units: indexes into sp_units.
59 */
60enum SPUnitId {
61 SP_UNIT_SCALE, // 1.0 == 100%
62 SP_UNIT_PT, // Postscript points: exactly 72 per inch
63 SP_UNIT_PC, // Pica; there are 12 points per pica
64 SP_UNIT_PX, // "Pixels" in the CSS sense; though Inkscape assumes a constant 90 per inch.
65 SP_UNIT_PERCENT, /* Note: In Inkscape this often means "relative to current value" (for
66 users to edit a value), rather than the SVG/CSS use of percentages. */
67 SP_UNIT_MM, // millimetres
68 SP_UNIT_CM, // centimetres
69 SP_UNIT_M, // metres
70 SP_UNIT_IN, // inches
71 SP_UNIT_FT, // foot
72 SP_UNIT_EM, // font-size of relevant font
73 SP_UNIT_EX, // x-height of relevant font
74 sp_max_unit_id = SP_UNIT_EX // For bounds-checking in sp_unit_get_by_id.
75};
76
77/*
78 * Notice, that for correct menus etc. you have to use
79 * ngettext method family yourself. For that reason we
80 * do not provide translations in unit names.
81 * I also do not know, whether to allow user-created units,
82 * because this would certainly confuse textdomain.
83 */
84
85struct SPUnit {
86 SPUnitId unit_id; /* used as sanity check */
87 SPUnitBase base;
88 gdouble unittobase; /* how many base units in this unit */
89 SPMetric metric; // the corresponding SPMetric from sp-metrics.h
90 guint svg_unit; // the corresponding SVGLengthUnit
91
92 /* When using, you must call "gettext" on them so they're translated */
93 gchar const *name;
94 gchar const *abbr;
95 gchar const *plural;
96 gchar const *abbr_plural;
97};
98
99const SPUnit *sp_unit_get_by_abbreviation (const gchar *abbreviation);
100/* When using, you must call "gettext" on them so they're translated */
101const gchar *sp_unit_get_abbreviation (const SPUnit *unit);
102gchar const *sp_unit_get_plural (SPUnit const *unit);
103
104SPMetric sp_unit_get_metric(SPUnit const *unit);
105guint sp_unit_get_svg_unit(SPUnit const *unit);
106
107extern SPUnit const sp_units[];
108
109inline SPUnit const &
110sp_unit_get_by_id(SPUnitId const id)
111{
112 /* inline because the compiler should optimize away the g_return_val_if_fail test in the
113 usual case that the argument value is known at compile-time, leaving just
114 "return sp_units[constant]". */
115 unsigned const ix = unsigned(id);
116 g_return_val_if_fail(ix <= sp_max_unit_id, sp_units[SP_UNIT_PX]);
117 return sp_units[ix];
118}
119
120#define SP_PS_UNIT (&sp_unit_get_by_id(SP_UNIT_PT))
121
122
123/** Used solely by units-test.cpp. */
124bool sp_units_table_sane();
125
126#define SP_UNITS_ALL (SP_UNIT_DIMENSIONLESS | SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE | SP_UNIT_VOLATILE)
127
128GSList *sp_unit_get_list (guint bases);
129void sp_unit_free_list (GSList *units);
130
131/* These are pure utility */
132/* Return TRUE if conversion is possible, FALSE if unit bases differ */
133gboolean sp_convert_distance (gdouble *distance, const SPUnit *from, const SPUnit *to);
134
135/* If either one is NULL, transconverting to/from that base fails */
136/* Generic conversion between volatile units would be useless anyways */
137gdouble sp_convert_distance_full(gdouble const from_dist, SPUnit const &from, SPUnit const &to);
138
139/* Some more convenience */
140gdouble sp_units_get_pixels(gdouble const units, SPUnit const &unit);
141gdouble sp_pixels_get_units(gdouble const pixels, SPUnit const &unit);
142
143double angle_to_compass(double angle);
144double angle_from_compass(double angle);
145
146#endif
1470
=== modified file 'src/live_effects/lpe-path_length.cpp'
--- src/live_effects/lpe-path_length.cpp 2012-10-21 18:04:54 +0000
+++ src/live_effects/lpe-path_length.cpp 2013-08-06 18:46:25 +0000
@@ -14,7 +14,7 @@
14#include <glibmm/i18n.h>14#include <glibmm/i18n.h>
1515
16#include "live_effects/lpe-path_length.h"16#include "live_effects/lpe-path_length.h"
17#include "sp-metrics.h"17#include "util/units.h"
1818
19#include "2geom/sbasis-geometric.h"19#include "2geom/sbasis-geometric.h"
2020
@@ -52,11 +52,11 @@
5252
53 /* convert the measured length to the correct unit ... */53 /* convert the measured length to the correct unit ... */
54 double lengthval = Geom::length(pwd2_in) * scale;54 double lengthval = Geom::length(pwd2_in) * scale;
55 gboolean success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), unit);55 lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit.get_abbreviation());
5656
57 /* ... set it as the canvas text ... */57 /* ... set it as the canvas text ... */
58 gchar *arc_length = g_strdup_printf("%.2f %s", lengthval,58 gchar *arc_length = g_strdup_printf("%.2f %s", lengthval,
59 display_unit ? (success ? unit.get_abbreviation() : "px") : "");59 display_unit ? unit.get_abbreviation() : "");
60 info_text.param_setValue(arc_length);60 info_text.param_setValue(arc_length);
61 g_free(arc_length);61 g_free(arc_length);
6262
6363
=== modified file 'src/live_effects/lpe-ruler.cpp'
--- src/live_effects/lpe-ruler.cpp 2013-03-13 17:30:15 +0000
+++ src/live_effects/lpe-ruler.cpp 2013-08-06 18:46:25 +0000
@@ -81,9 +81,9 @@
81 using namespace Geom;81 using namespace Geom;
8282
83 double real_mark_length = mark_length;83 double real_mark_length = mark_length;
84 sp_convert_distance(&real_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX));84 real_mark_length = Inkscape::Util::Quantity::convert(real_mark_length, unit.get_abbreviation(), "px");
85 double real_minor_mark_length = minor_mark_length;85 double real_minor_mark_length = minor_mark_length;
86 sp_convert_distance(&real_minor_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX));86 real_minor_mark_length = Inkscape::Util::Quantity::convert(real_minor_mark_length, unit.get_abbreviation(), "px");
8787
88 n_major = real_mark_length * n;88 n_major = real_mark_length * n;
89 n_minor = real_minor_mark_length * n;89 n_minor = real_minor_mark_length * n;
@@ -133,10 +133,10 @@
133 std::vector<double> s_cuts;133 std::vector<double> s_cuts;
134134
135 double real_mark_distance = mark_distance;135 double real_mark_distance = mark_distance;
136 sp_convert_distance(&real_mark_distance, unit, &sp_unit_get_by_id(SP_UNIT_PX));136 real_mark_distance = Inkscape::Util::Quantity::convert(real_mark_distance, unit.get_abbreviation(), "px");
137137
138 double real_offset = offset;138 double real_offset = offset;
139 sp_convert_distance(&real_offset, unit, &sp_unit_get_by_id(SP_UNIT_PX));139 real_offset = Inkscape::Util::Quantity::convert(real_offset, unit.get_abbreviation(), "px");
140 for (double s = real_offset; s<totlength; s+=real_mark_distance){140 for (double s = real_offset; s<totlength; s+=real_mark_distance){
141 s_cuts.push_back(s);141 s_cuts.push_back(s);
142 }142 }
143143
=== modified file 'src/live_effects/parameter/unit.cpp'
--- src/live_effects/parameter/unit.cpp 2013-03-25 17:42:31 +0000
+++ src/live_effects/parameter/unit.cpp 2013-08-06 18:46:25 +0000
@@ -10,6 +10,9 @@
10#include "live_effects/parameter/unit.h"10#include "live_effects/parameter/unit.h"
11#include "live_effects/effect.h"11#include "live_effects/effect.h"
12#include "verbs.h"12#include "verbs.h"
13#include "util/units.h"
14
15using Inkscape::Util::unit_table;
1316
14namespace Inkscape {17namespace Inkscape {
1518
@@ -18,10 +21,10 @@
1821
19UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip,22UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip,
20 const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,23 const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
21 Effect* effect, SPUnitId default_value)24 Effect* effect, Glib::ustring default_unit)
22 : Parameter(label, tip, key, wr, effect)25 : Parameter(label, tip, key, wr, effect)
23{26{
24 defunit = &sp_unit_get_by_id(default_value);;27 defunit = new Inkscape::Util::Unit(unit_table.getUnit(default_unit));
25 unit = defunit;28 unit = defunit;
26}29}
2730
@@ -32,9 +35,8 @@
32bool35bool
33UnitParam::param_readSVGValue(const gchar * strvalue)36UnitParam::param_readSVGValue(const gchar * strvalue)
34{37{
35 SPUnit const *newval = sp_unit_get_by_abbreviation(strvalue);38 if (strvalue) {
36 if (newval) {39 param_set_value(unit_table.getUnit(strvalue));
37 param_set_value(newval);
38 return true;40 return true;
39 }41 }
40 return false;42 return false;
@@ -43,25 +45,25 @@
43gchar *45gchar *
44UnitParam::param_getSVGValue() const46UnitParam::param_getSVGValue() const
45{47{
46 return g_strdup(sp_unit_get_abbreviation(unit));48 return g_strdup(unit->abbr.c_str());
47}49}
4850
49void51void
50UnitParam::param_set_default()52UnitParam::param_set_default()
51{53{
52 param_set_value(defunit);54 param_set_value(*defunit);
53}55}
5456
55void57void
56UnitParam::param_set_value(SPUnit const *val)58UnitParam::param_set_value(Inkscape::Util::Unit const &val)
57{59{
58 unit = val;60 unit = new Inkscape::Util::Unit(val);
59}61}
6062
61const gchar *63const gchar *
62UnitParam::get_abbreviation() const64UnitParam::get_abbreviation() const
63{65{
64 return sp_unit_get_abbreviation(unit);66 return unit->abbr.c_str();
65}67}
6668
67Gtk::Widget *69Gtk::Widget *
@@ -74,7 +76,7 @@
74 param_effect->getRepr(),76 param_effect->getRepr(),
75 param_effect->getSPDoc()));77 param_effect->getSPDoc()));
7678
77 unit_menu->setUnit(unit);79 unit_menu->setUnit(unit->abbr);
78 unit_menu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change unit parameter"));80 unit_menu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change unit parameter"));
7981
80 return dynamic_cast<Gtk::Widget *> (unit_menu);82 return dynamic_cast<Gtk::Widget *> (unit_menu);
8183
=== modified file 'src/live_effects/parameter/unit.h'
--- src/live_effects/parameter/unit.h 2013-01-17 18:23:15 +0000
+++ src/live_effects/parameter/unit.h 2013-08-06 18:46:25 +0000
@@ -10,10 +10,13 @@
10 */10 */
1111
12#include "live_effects/parameter/parameter.h"12#include "live_effects/parameter/parameter.h"
13#include <helper/units.h>
1413
15namespace Inkscape {14namespace Inkscape {
1615
16namespace Util {
17 class Unit;
18}
19
17namespace LivePathEffect {20namespace LivePathEffect {
1821
19class UnitParam : public Parameter {22class UnitParam : public Parameter {
@@ -23,22 +26,22 @@
23 const Glib::ustring& key, 26 const Glib::ustring& key,
24 Inkscape::UI::Widget::Registry* wr,27 Inkscape::UI::Widget::Registry* wr,
25 Effect* effect,28 Effect* effect,
26 SPUnitId default_value = SP_UNIT_PX);29 Glib::ustring default_unit = "px");
27 virtual ~UnitParam();30 virtual ~UnitParam();
2831
29 virtual bool param_readSVGValue(const gchar * strvalue);32 virtual bool param_readSVGValue(const gchar * strvalue);
30 virtual gchar * param_getSVGValue() const;33 virtual gchar * param_getSVGValue() const;
31 virtual void param_set_default();34 virtual void param_set_default();
32 void param_set_value(SPUnit const *val);35 void param_set_value(Inkscape::Util::Unit const &val);
33 const gchar *get_abbreviation() const;36 const gchar *get_abbreviation() const;
3437
35 virtual Gtk::Widget * param_newWidget();38 virtual Gtk::Widget * param_newWidget();
3639
37 operator SPUnit const *() const { return unit; }40 operator Inkscape::Util::Unit const *() const { return unit; }
3841
39private:42private:
40 SPUnit const *unit;43 Inkscape::Util::Unit const *unit;
41 SPUnit const *defunit;44 Inkscape::Util::Unit const *defunit;
4245
43 UnitParam(const UnitParam&);46 UnitParam(const UnitParam&);
44 UnitParam& operator=(const UnitParam&);47 UnitParam& operator=(const UnitParam&);
4548
=== modified file 'src/lpe-tool-context.cpp'
--- src/lpe-tool-context.cpp 2013-08-03 21:30:12 +0000
+++ src/lpe-tool-context.cpp 2013-08-06 18:46:25 +0000
@@ -37,10 +37,12 @@
37#include "display/canvas-text.h"37#include "display/canvas-text.h"
38#include "message-stack.h"38#include "message-stack.h"
39#include "sp-path.h"39#include "sp-path.h"
40#include "helper/units.h"40#include "util/units.h"
4141
42#include "lpe-tool-context.h"42#include "lpe-tool-context.h"
4343
44using Inkscape::Util::unit_table;
45
44static void sp_lpetool_context_dispose(GObject *object);46static void sp_lpetool_context_dispose(GObject *object);
4547
46static void sp_lpetool_context_setup(SPEventContext *ec);48static void sp_lpetool_context_setup(SPEventContext *ec);
@@ -453,13 +455,17 @@
453 if (!show)455 if (!show)
454 sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text));456 sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text));
455457
456 SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX));458 Inkscape::Util::Unit unit;
457 SPUnit unit = sp_unit_get_by_id(unitid);459 if (prefs->getString("/tools/lpetool/unit").compare("")) {
460 unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit"));
461 } else {
462 unit = unit_table.getUnit("px");
463 }
458464
459 lengthval = Geom::length(pwd2);465 lengthval = Geom::length(pwd2);
460 gboolean success;466 gboolean success;
461 success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);467 lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
462 arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px");468 arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str());
463 sp_canvastext_set_text (canvas_text, arc_length);469 sp_canvastext_set_text (canvas_text, arc_length);
464 set_pos_and_anchor(canvas_text, pwd2, 0.5, 10);470 set_pos_and_anchor(canvas_text, pwd2, 0.5, 10);
465 // TODO: must we free arc_length?471 // TODO: must we free arc_length?
@@ -489,12 +495,27 @@
489 SPPath *path = i->first;495 SPPath *path = i->first;
490 SPCurve *curve = SP_SHAPE(path)->getCurve();496 SPCurve *curve = SP_SHAPE(path)->getCurve();
491 Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = Geom::paths_to_pw(curve->get_pathvector());497 Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = Geom::paths_to_pw(curve->get_pathvector());
498<<<<<<< TREE
492 SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX));499 SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX));
493 SPUnit unit = sp_unit_get_by_id(unitid);500 SPUnit unit = sp_unit_get_by_id(unitid);
494 double lengthval = Geom::length(pwd2);501 double lengthval = Geom::length(pwd2);
502=======
503 Inkscape::Util::Unit unit;
504 if (prefs->getString("/tools/lpetool/unit").compare("")) {
505 unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit"));
506 } else {
507 unit = unit_table.getUnit("px");
508 }
509 lengthval = Geom::length(pwd2);
510>>>>>>> MERGE-SOURCE
495 gboolean success;511 gboolean success;
512<<<<<<< TREE
496 success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);513 success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
497 gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px");514 gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px");
515=======
516 lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
517 arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str());
518>>>>>>> MERGE-SOURCE
498 sp_canvastext_set_text (SP_CANVASTEXT(i->second), arc_length);519 sp_canvastext_set_text (SP_CANVASTEXT(i->second), arc_length);
499 set_pos_and_anchor(SP_CANVASTEXT(i->second), pwd2, 0.5, 10);520 set_pos_and_anchor(SP_CANVASTEXT(i->second), pwd2, 0.5, 10);
500 // TODO: must we free arc_length?521 // TODO: must we free arc_length?
501522
=== modified file 'src/lpe-tool-context.h'
--- src/lpe-tool-context.h 2013-03-14 23:24:17 +0000
+++ src/lpe-tool-context.h 2013-08-06 18:46:25 +0000
@@ -16,7 +16,6 @@
16 */16 */
1717
18#include "pen-context.h"18#include "pen-context.h"
19#include "helper/units.h"
2019
21#define SP_TYPE_LPETOOL_CONTEXT (sp_lpetool_context_get_type())20#define SP_TYPE_LPETOOL_CONTEXT (sp_lpetool_context_get_type())
22#define SP_LPETOOL_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_LPETOOL_CONTEXT, SPLPEToolContext))21#define SP_LPETOOL_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_LPETOOL_CONTEXT, SPLPEToolContext))
2322
=== modified file 'src/main.cpp'
--- src/main.cpp 2013-07-17 11:42:40 +0000
+++ src/main.cpp 2013-08-06 18:46:25 +0000
@@ -68,7 +68,6 @@
68#include "color.h"68#include "color.h"
69#include "sp-item.h"69#include "sp-item.h"
70#include "sp-root.h"70#include "sp-root.h"
71#include "unit-constants.h"
7271
73#include "svg/svg.h"72#include "svg/svg.h"
74#include "svg/svg-color.h"73#include "svg/svg-color.h"
@@ -1524,7 +1523,7 @@
15241523
1525 // default dpi1524 // default dpi
1526 if (dpi == 0.0) {1525 if (dpi == 0.0) {
1527 dpi = PX_PER_IN;1526 dpi = Inkscape::Util::Quantity::convert(1, "in", "px");
1528 }1527 }
15291528
1530 unsigned long int width = 0;1529 unsigned long int width = 0;
@@ -1537,7 +1536,7 @@
1537 g_warning("Export width %lu out of range (1 - %lu). Nothing exported.", width, (unsigned long int)PNG_UINT_31_MAX);1536 g_warning("Export width %lu out of range (1 - %lu). Nothing exported.", width, (unsigned long int)PNG_UINT_31_MAX);
1538 return 1;1537 return 1;
1539 }1538 }
1540 dpi = (gdouble) width * PX_PER_IN / area.width();1539 dpi = (gdouble) width * Inkscape::Util::Quantity::convert(1, "in", "px") / area.width();
1541 }1540 }
15421541
1543 if (sp_export_height) {1542 if (sp_export_height) {
@@ -1547,15 +1546,15 @@
1547 g_warning("Export height %lu out of range (1 - %lu). Nothing exported.", height, (unsigned long int)PNG_UINT_31_MAX);1546 g_warning("Export height %lu out of range (1 - %lu). Nothing exported.", height, (unsigned long int)PNG_UINT_31_MAX);
1548 return 1;1547 return 1;
1549 }1548 }
1550 dpi = (gdouble) height * PX_PER_IN / area.height();1549 dpi = (gdouble) height * Inkscape::Util::Quantity::convert(1, "in", "px") / area.height();
1551 }1550 }
15521551
1553 if (!sp_export_width) {1552 if (!sp_export_width) {
1554 width = (unsigned long int) (area.width() * dpi / PX_PER_IN + 0.5);1553 width = (unsigned long int) (area.width() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5);
1555 }1554 }
15561555
1557 if (!sp_export_height) {1556 if (!sp_export_height) {
1558 height = (unsigned long int) (area.height() * dpi / PX_PER_IN + 0.5);1557 height = (unsigned long int) (area.height() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5);
1559 }1558 }
15601559
1561 guint32 bgcolor = 0x00000000;1560 guint32 bgcolor = 0x00000000;
15621561
=== modified file 'src/measure-context.cpp'
--- src/measure-context.cpp 2013-08-03 21:30:12 +0000
+++ src/measure-context.cpp 2013-08-06 18:46:25 +0000
@@ -13,7 +13,7 @@
1313
14#include <gdk/gdkkeysyms.h>14#include <gdk/gdkkeysyms.h>
15#include <boost/none_t.hpp>15#include <boost/none_t.hpp>
16#include "helper/units.h"16#include "util/units.h"
17#include "macros.h"17#include "macros.h"
18#include "display/curve.h"18#include "display/curve.h"
19#include "sp-shape.h"19#include "sp-shape.h"
@@ -46,6 +46,7 @@
4646
47using Inkscape::ControlManager;47using Inkscape::ControlManager;
48using Inkscape::CTLINE_SECONDARY;48using Inkscape::CTLINE_SECONDARY;
49using Inkscape::Util::unit_table;
4950
50static void sp_measure_context_setup(SPEventContext *ec);51static void sp_measure_context_setup(SPEventContext *ec);
51static void sp_measure_context_finish(SPEventContext *ec);52static void sp_measure_context_finish(SPEventContext *ec);
@@ -514,8 +515,10 @@
514 std::sort(intersections.begin(), intersections.end(), GeomPointSortPredicate);515 std::sort(intersections.begin(), intersections.end(), GeomPointSortPredicate);
515 }516 }
516517
517 SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/measure/unitid", SP_UNIT_PX));518 Glib::ustring unit_name = prefs->getString("/tools/measure/unit");
518 SPUnit unit = sp_unit_get_by_id(unitid);519 if (!unit_name.compare("")) {
520 unit_name = "px";
521 }
519522
520 double fontsize = prefs->getInt("/tools/measure/fontsize");523 double fontsize = prefs->getInt("/tools/measure/fontsize");
521524
@@ -526,7 +529,7 @@
526 for (size_t idx = 1; idx < intersections.size(); ++idx) {529 for (size_t idx = 1; idx < intersections.size(); ++idx) {
527 LabelPlacement placement;530 LabelPlacement placement;
528 placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length();531 placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length();
529 sp_convert_distance(&placement.lengthVal, &sp_unit_get_by_id(SP_UNIT_PX), &unit);532 placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, "px", unit_name);
530 placement.offset = DIMENSION_OFFSET;533 placement.offset = DIMENSION_OFFSET;
531 placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 );534 placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 );
532 placement.end = placement.start - (normal * placement.offset);535 placement.end = placement.start - (normal * placement.offset);
@@ -542,7 +545,7 @@
542 LabelPlacement &place = *it;545 LabelPlacement &place = *it;
543546
544 // TODO cleanup memory, Glib::ustring, etc.:547 // TODO cleanup memory, Glib::ustring, etc.:
545 gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit.abbr);548 gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit_name.c_str());
546 SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),549 SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),
547 desktop,550 desktop,
548 place.end,551 place.end,
@@ -583,10 +586,10 @@
583586
584 {587 {
585 double totallengthval = (end_point - start_point).length();588 double totallengthval = (end_point - start_point).length();
586 sp_convert_distance(&totallengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);589 totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name);
587590
588 // TODO cleanup memory, Glib::ustring, etc.:591 // TODO cleanup memory, Glib::ustring, etc.:
589 gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr);592 gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str());
590 SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),593 SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),
591 desktop,594 desktop,
592 end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)),595 end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)),
@@ -604,10 +607,10 @@
604607
605 if (intersections.size() > 2) {608 if (intersections.size() > 2) {
606 double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length();609 double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length();
607 sp_convert_distance(&totallengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);610 totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name);
608611
609 // TODO cleanup memory, Glib::ustring, etc.:612 // TODO cleanup memory, Glib::ustring, etc.:
610 gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr);613 gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str());
611 SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),614 SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),
612 desktop,615 desktop,
613 desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60,616 desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60,
614617
=== modified file 'src/pen-context.cpp'
--- src/pen-context.cpp 2013-04-28 22:48:03 +0000
+++ src/pen-context.cpp 2013-08-06 18:46:25 +0000
@@ -22,7 +22,6 @@
2222
23#include "pen-context.h"23#include "pen-context.h"
24#include "sp-namedview.h"24#include "sp-namedview.h"
25#include "sp-metrics.h"
26#include "desktop.h"25#include "desktop.h"
27#include "desktop-handles.h"26#include "desktop-handles.h"
28#include "selection.h"27#include "selection.h"
@@ -39,7 +38,6 @@
39#include "display/sp-ctrlline.h"38#include "display/sp-ctrlline.h"
40#include "display/sodipodi-ctrl.h"39#include "display/sodipodi-ctrl.h"
41#include <glibmm/i18n.h>40#include <glibmm/i18n.h>
42#include "helper/units.h"
43#include "macros.h"41#include "macros.h"
44#include "context-fns.h"42#include "context-fns.h"
45#include "tools-switch.h"43#include "tools-switch.h"
@@ -1185,11 +1183,16 @@
11851183
1186 SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop;1184 SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop;
1187 Geom::Point rel = p - pc->p[pc_point_to_compare];1185 Geom::Point rel = p - pc->p[pc_point_to_compare];
1188 GString *dist = SP_PX_TO_METRIC_STRING(Geom::L2(rel), desktop->namedview->getDefaultMetric());1186 Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px");
1187 GString *dist = g_string_new(q.string(*desktop->namedview->doc_units).c_str());
1189 double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI;1188 double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI;
1190 Inkscape::Preferences *prefs = Inkscape::Preferences::get();1189 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
1191 if (prefs->getBool("/options/compassangledisplay/value", 0) != 0)1190 if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) {
1192 angle = angle_to_compass (angle);1191 angle = 90 - angle;
1192 if (angle < 0) {
1193 angle += 360;
1194 }
1195 }
11931196
1194 pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str);1197 pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str);
1195 g_string_free(dist, FALSE);1198 g_string_free(dist, FALSE);
11961199
=== modified file 'src/preferences.cpp'
--- src/preferences.cpp 2013-02-11 23:34:59 +0000
+++ src/preferences.cpp 2013-08-06 18:46:25 +0000
@@ -28,6 +28,8 @@
2828
29#define PREFERENCES_FILE_NAME "preferences.xml"29#define PREFERENCES_FILE_NAME "preferences.xml"
3030
31using Inkscape::Util::unit_table;
32
31namespace Inkscape {33namespace Inkscape {
3234
33static Inkscape::XML::Document *loadImpl( std::string const& prefsFilename, Glib::ustring & errMsg );35static Inkscape::XML::Document *loadImpl( std::string const& prefsFilename, Glib::ustring & errMsg );
@@ -777,8 +779,6 @@
777779
778double Preferences::_extractDouble(Entry const &v, Glib::ustring const &requested_unit)780double Preferences::_extractDouble(Entry const &v, Glib::ustring const &requested_unit)
779{781{
780 static Inkscape::Util::UnitTable unit_table; // load the unit_table once by making it static
781
782 double val = _extractDouble(v);782 double val = _extractDouble(v);
783 Glib::ustring unit = _extractUnit(v);783 Glib::ustring unit = _extractUnit(v);
784784
785785
=== modified file 'src/rect-context.cpp'
--- src/rect-context.cpp 2013-04-28 22:48:03 +0000
+++ src/rect-context.cpp 2013-08-06 18:46:25 +0000
@@ -35,7 +35,6 @@
35#include "message-context.h"35#include "message-context.h"
36#include "pixmaps/cursor-rect.xpm"36#include "pixmaps/cursor-rect.xpm"
37#include "rect-context.h"37#include "rect-context.h"
38#include "sp-metrics.h"
39#include <glibmm/i18n.h>38#include <glibmm/i18n.h>
40#include "xml/repr.h"39#include "xml/repr.h"
41#include "xml/node-event-vector.h"40#include "xml/node-event-vector.h"
@@ -483,8 +482,10 @@
483 // status text482 // status text
484 double rdimx = r.dimensions()[Geom::X];483 double rdimx = r.dimensions()[Geom::X];
485 double rdimy = r.dimensions()[Geom::Y];484 double rdimy = r.dimensions()[Geom::Y];
486 GString *xs = SP_PX_TO_METRIC_STRING(rdimx, desktop->namedview->getDefaultMetric());485 Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px");
487 GString *ys = SP_PX_TO_METRIC_STRING(rdimy, desktop->namedview->getDefaultMetric());486 Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px");
487 GString *xs = g_string_new(rdimx_q.string(*desktop->namedview->doc_units).c_str());
488 GString *ys = g_string_new(rdimy_q.string(*desktop->namedview->doc_units).c_str());
488 if (state & GDK_CONTROL_MASK) {489 if (state & GDK_CONTROL_MASK) {
489 int ratio_x, ratio_y;490 int ratio_x, ratio_y;
490 bool is_golden_ratio = false;491 bool is_golden_ratio = false;
491492
=== modified file 'src/selection-chemistry.cpp'
--- src/selection-chemistry.cpp 2013-07-04 14:01:44 +0000
+++ src/selection-chemistry.cpp 2013-08-06 18:46:25 +0000
@@ -86,11 +86,10 @@
86#include <map>86#include <map>
87#include <cstring>87#include <cstring>
88#include <string>88#include <string>
89#include "helper/units.h"
90#include "sp-item.h"89#include "sp-item.h"
91#include "box3d.h"90#include "box3d.h"
92#include "persp3d.h"91#include "persp3d.h"
93#include "unit-constants.h"92#include "util/units.h"
94#include "xml/simple-document.h"93#include "xml/simple-document.h"
95#include "sp-filter-reference.h"94#include "sp-filter-reference.h"
96#include "gradient-drag.h"95#include "gradient-drag.h"
@@ -3398,7 +3397,7 @@
3398 res = prefs_res;3397 res = prefs_res;
3399 } else if (0 < prefs_min) {3398 } else if (0 < prefs_min) {
3400 // If minsize is given, look up minimum bitmap size (default 250 pixels) and calculate resolution from it3399 // If minsize is given, look up minimum bitmap size (default 250 pixels) and calculate resolution from it
3401 res = PX_PER_IN * prefs_min / MIN(bbox->width(), bbox->height());3400 res = Inkscape::Util::Quantity::convert(1, "in", "px") * prefs_min / MIN(bbox->width(), bbox->height());
3402 } else {3401 } else {
3403 float hint_xdpi = 0, hint_ydpi = 0;3402 float hint_xdpi = 0, hint_ydpi = 0;
3404 Glib::ustring hint_filename;3403 Glib::ustring hint_filename;
@@ -3413,14 +3412,14 @@
3413 res = hint_xdpi;3412 res = hint_xdpi;
3414 } else {3413 } else {
3415 // if all else fails, take the default 90 dpi3414 // if all else fails, take the default 90 dpi
3416 res = PX_PER_IN;3415 res = Inkscape::Util::Quantity::convert(1, "in", "px");
3417 }3416 }
3418 }3417 }
3419 }3418 }
34203419
3421 // The width and height of the bitmap in pixels3420 // The width and height of the bitmap in pixels
3422 unsigned width = (unsigned) floor(bbox->width() * res / PX_PER_IN);3421 unsigned width = (unsigned) floor(bbox->width() * res / Inkscape::Util::Quantity::convert(1, "in", "px"));
3423 unsigned height =(unsigned) floor(bbox->height() * res / PX_PER_IN);3422 unsigned height =(unsigned) floor(bbox->height() * res / Inkscape::Util::Quantity::convert(1, "in", "px"));
34243423
3425 // Find out if we have to run an external filter3424 // Find out if we have to run an external filter
3426 gchar const *run = NULL;3425 gchar const *run = NULL;
@@ -3452,7 +3451,7 @@
34523451
3453 double shift_x = bbox->min()[Geom::X];3452 double shift_x = bbox->min()[Geom::X];
3454 double shift_y = bbox->max()[Geom::Y];3453 double shift_y = bbox->max()[Geom::Y];
3455 if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid3454 if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { // for default 90 dpi, snap it to pixel grid
3456 shift_x = round(shift_x);3455 shift_x = round(shift_x);
3457 shift_y = -round(-shift_y); // this gets correct rounding despite coordinate inversion, remove the negations when the inversion is gone3456 shift_y = -round(-shift_y); // this gets correct rounding despite coordinate inversion, remove the negations when the inversion is gone
3458 }3457 }
@@ -3485,7 +3484,7 @@
3485 // Create the repr for the image3484 // Create the repr for the image
3486 Inkscape::XML::Node * repr = xml_doc->createElement("svg:image");3485 Inkscape::XML::Node * repr = xml_doc->createElement("svg:image");
3487 sp_embed_image(repr, pb, "image/png");3486 sp_embed_image(repr, pb, "image/png");
3488 if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid3487 if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { // for default 90 dpi, snap it to pixel grid
3489 sp_repr_set_svg_double(repr, "width", width);3488 sp_repr_set_svg_double(repr, "width", width);
3490 sp_repr_set_svg_double(repr, "height", height);3489 sp_repr_set_svg_double(repr, "height", height);
3491 } else {3490 } else {
34923491
=== modified file 'src/seltrans.cpp'
--- src/seltrans.cpp 2013-07-03 16:59:04 +0000
+++ src/seltrans.cpp 2013-08-06 18:46:25 +0000
@@ -37,7 +37,6 @@
37#include "seltrans-handles.h"37#include "seltrans-handles.h"
38#include "seltrans.h"38#include "seltrans.h"
39#include "selection-chemistry.h"39#include "selection-chemistry.h"
40#include "sp-metrics.h"
41#include "verbs.h"40#include "verbs.h"
42#include <glibmm/i18n.h>41#include <glibmm/i18n.h>
43#include "display/sp-ctrlline.h"42#include "display/sp-ctrlline.h"
@@ -1273,8 +1272,10 @@
1273 m.unSetup();1272 m.unSetup();
12741273
1275 // status text1274 // status text
1276 GString *xs = SP_PX_TO_METRIC_STRING(pt[Geom::X], _desktop->namedview->getDefaultMetric());1275 Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(pt[Geom::X], "px");
1277 GString *ys = SP_PX_TO_METRIC_STRING(pt[Geom::Y], _desktop->namedview->getDefaultMetric());1276 Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(pt[Geom::Y], "px");
1277 GString *xs = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
1278 GString *ys = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
1278 _message_context.setF(Inkscape::NORMAL_MESSAGE, _("Move <b>center</b> to %s, %s"), xs->str, ys->str);1279 _message_context.setF(Inkscape::NORMAL_MESSAGE, _("Move <b>center</b> to %s, %s"), xs->str, ys->str);
1279 g_string_free(xs, FALSE);1280 g_string_free(xs, FALSE);
1280 g_string_free(ys, FALSE);1281 g_string_free(ys, FALSE);
@@ -1425,8 +1426,10 @@
1425 transform(move, norm);1426 transform(move, norm);
14261427
1427 // status text1428 // status text
1428 GString *xs = SP_PX_TO_METRIC_STRING(dxy[Geom::X], _desktop->namedview->getDefaultMetric());1429 Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dxy[Geom::X], "px");
1429 GString *ys = SP_PX_TO_METRIC_STRING(dxy[Geom::Y], _desktop->namedview->getDefaultMetric());1430 Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dxy[Geom::Y], "px");
1431 GString *xs = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
1432 GString *ys = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
1430 _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);1433 _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);
1431 g_string_free(xs, TRUE);1434 g_string_free(xs, TRUE);
1432 g_string_free(ys, TRUE);1435 g_string_free(ys, TRUE);
14331436
=== modified file 'src/snap-preferences.h'
--- src/snap-preferences.h 2012-02-14 20:56:34 +0000
+++ src/snap-preferences.h 2013-08-06 18:46:25 +0000
@@ -10,7 +10,6 @@
10 * Released under GNU GPL, read the file 'COPYING' for more information10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */11 */
1212
13#include "helper/units.h"
14#include "snap-enums.h"13#include "snap-enums.h"
1514
16namespace Inkscape15namespace Inkscape
1716
=== modified file 'src/sp-guide.cpp'
--- src/sp-guide.cpp 2013-03-02 11:29:23 +0000
+++ src/sp-guide.cpp 2013-08-06 18:46:25 +0000
@@ -35,7 +35,6 @@
35#include <glibmm/i18n.h>35#include <glibmm/i18n.h>
36#include <xml/repr.h>36#include <xml/repr.h>
37#include <remove-last.h>37#include <remove-last.h>
38#include "sp-metrics.h"
39#include "inkscape.h"38#include "inkscape.h"
40#include "desktop.h"39#include "desktop.h"
41#include "sp-namedview.h"40#include "sp-namedview.h"
@@ -463,10 +462,10 @@
463 } else {462 } else {
464 SPNamedView *namedview = sp_document_namedview(guide->document, NULL);463 SPNamedView *namedview = sp_document_namedview(guide->document, NULL);
465464
466 GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X],465 Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(guide->point_on_line[X], "px");
467 namedview->getDefaultMetric());466 Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(guide->point_on_line[Y], "px");
468 GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y],467 GString *position_string_x = g_string_new(x_q.string(*namedview->doc_units).c_str());
469 namedview->getDefaultMetric());468 GString *position_string_y = g_string_new(y_q.string(*namedview->doc_units).c_str());
470469
471 gchar *shortcuts = g_strdup_printf("; %s", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete"));470 gchar *shortcuts = g_strdup_printf("; %s", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete"));
472471
473472
=== removed file 'src/sp-metric.h'
--- src/sp-metric.h 2012-10-27 18:15:53 +0000
+++ src/sp-metric.h 1970-01-01 00:00:00 +0000
@@ -1,28 +0,0 @@
1#ifndef INKSCAPE_SP_METRIC_H
2#define INKSCAPE_SP_METRIC_H
3
4/** Known metrics so far. (I don't know why this doesn't include pica.) */
5enum SPMetric {
6 SP_NONE,
7 SP_MM,
8 SP_CM,
9 SP_IN,
10 SP_FT,
11 SP_PT,
12 SP_PC,
13 SP_PX,
14 SP_M
15};
16
17#endif /* !INKSCAPE_SP_METRIC_H */
18
19/*
20 Local Variables:
21 mode:c++
22 c-file-style:"stroustrup"
23 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
24 indent-tabs-mode:nil
25 fill-column:99
26 End:
27*/
28// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
290
=== removed file 'src/sp-metrics.cpp'
--- src/sp-metrics.cpp 2012-10-27 18:15:53 +0000
+++ src/sp-metrics.cpp 1970-01-01 00:00:00 +0000
@@ -1,120 +0,0 @@
1#include "sp-metrics.h"
2#include "unit-constants.h"
3
4/*
5 * SPMetric handling and stuff
6 * I hope this will be usefull :-)
7 */
8
9gdouble
10sp_absolute_metric_to_metric (gdouble length_src, const SPMetric metric_src, const SPMetric metric_dst)
11{
12 gdouble src = 1;
13 gdouble dst = 1;
14
15 switch (metric_src) {
16 case SP_M:
17 src = M_PER_IN;
18 break;
19 case SP_MM:
20 src = MM_PER_IN;
21 break;
22 case SP_CM:
23 src = CM_PER_IN;
24 break;
25 case SP_IN:
26 src = IN_PER_IN;
27 break;
28 case SP_FT:
29 src = FT_PER_IN;
30 break;
31 case SP_PT:
32 src = PT_PER_IN;
33 break;
34 case SP_PC:
35 src = PC_PER_IN;
36 break;
37 case SP_PX:
38 src = PX_PER_IN;
39 break;
40 case SP_NONE:
41 src = 1;
42 break;
43 }
44
45 switch (metric_dst) {
46 case SP_M:
47 dst = M_PER_IN;
48 break;
49 case SP_MM:
50 dst = MM_PER_IN;
51 break;
52 case SP_CM:
53 dst = CM_PER_IN;
54 break;
55 case SP_IN:
56 dst = IN_PER_IN;
57 break;
58 case SP_FT:
59 dst = FT_PER_IN;
60 break;
61 case SP_PT:
62 dst = PT_PER_IN;
63 break;
64 case SP_PC:
65 dst = PC_PER_IN;
66 break;
67 case SP_PX:
68 dst = PX_PER_IN;
69 break;
70 case SP_NONE:
71 dst = 1;
72 break;
73 }
74
75 return length_src * (dst/src);
76}
77
78/**
79 * Create a human-readable string suitable for status-bar display.
80 */
81GString *
82sp_metric_to_metric_string(gdouble const length,
83 SPMetric const metric_src, SPMetric const metric_dst,
84 gboolean const m)
85{
86 gdouble const len = sp_absolute_metric_to_metric(length, metric_src, metric_dst);
87 GString *str = g_string_new("");
88 g_string_printf(str, "%0.02f", len);
89 /* We need a fixed number of fractional digits, because otherwise the live statusbar display of
90 * lengths will be too jerky */
91
92 if (m) {
93 char const *unit_str;
94 switch (metric_dst) {
95 case SP_M: unit_str = " m"; break;
96 case SP_MM: unit_str = " mm"; break;
97 case SP_CM: unit_str = " cm"; break;
98 case SP_IN: unit_str = "\""; break;
99 case SP_PT: unit_str = " pt"; break;
100 case SP_PX: unit_str = " px"; break;
101 default: unit_str = NULL; break;
102 }
103 if (unit_str) {
104 g_string_append(str, unit_str);
105 }
106 }
107 return str;
108}
109
110
111/*
112 Local Variables:
113 mode:c++
114 c-file-style:"stroustrup"
115 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
116 indent-tabs-mode:nil
117 fill-column:99
118 End:
119*/
120// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
1210
=== removed file 'src/sp-metrics.h'
--- src/sp-metrics.h 2011-12-08 11:53:54 +0000
+++ src/sp-metrics.h 1970-01-01 00:00:00 +0000
@@ -1,20 +0,0 @@
1#ifndef SP_METRICS_H
2#define SP_METRICS_H
3
4#include <glib.h>
5#include "sp-metric.h"
6
7gdouble sp_absolute_metric_to_metric (gdouble length_src, const SPMetric metric_src, const SPMetric metric_dst);
8GString * sp_metric_to_metric_string (gdouble length, const SPMetric metric_src, const SPMetric metric_dst, gboolean m);
9
10// convenience since we mostly deal with points
11#define SP_METRIC_TO_PT(l,m) sp_absolute_metric_to_metric(l,m,SP_PT);
12#define SP_PT_TO_METRIC(l,m) sp_absolute_metric_to_metric(l,SP_PT,m);
13
14#define SP_PT_TO_METRIC_STRING(l,m) sp_metric_to_metric_string(l, SP_PT, m, TRUE)
15#define SP_PT_TO_STRING(l,m) sp_metric_to_metric_string(l, SP_PT, m, FALSE)
16
17#define SP_PX_TO_METRIC_STRING(l,m) sp_metric_to_metric_string(l, SP_PX, m, TRUE)
18#define SP_PX_TO_STRING(l,m) sp_metric_to_metric_string(l, SP_PX, m, FALSE)
19
20#endif
210
=== modified file 'src/sp-namedview.cpp'
--- src/sp-namedview.cpp 2013-05-01 07:46:46 +0000
+++ src/sp-namedview.cpp 2013-08-06 18:46:25 +0000
@@ -22,7 +22,7 @@
2222
23#include "display/canvas-grid.h"23#include "display/canvas-grid.h"
24#include "display/guideline.h"24#include "display/guideline.h"
25#include "helper/units.h"25#include "util/units.h"
26#include "svg/svg-color.h"26#include "svg/svg-color.h"
27#include "xml/repr.h"27#include "xml/repr.h"
28#include "attributes.h"28#include "attributes.h"
@@ -40,6 +40,7 @@
40#include <gtkmm/window.h>40#include <gtkmm/window.h>
4141
42using Inkscape::DocumentUndo;42using Inkscape::DocumentUndo;
43using Inkscape::Util::unit_table;
4344
44#define DEFAULTGRIDCOLOR 0x3f3fff2545#define DEFAULTGRIDCOLOR 0x3f3fff25
45#define DEFAULTGRIDEMPCOLOR 0x3f3fff6046#define DEFAULTGRIDEMPCOLOR 0x3f3fff60
@@ -549,18 +550,19 @@
549 * in that they aren't in general absolute units as currently required by550 * in that they aren't in general absolute units as currently required by
550 * doc_units.551 * doc_units.
551 */552 */
552 SPUnit const *new_unit = &sp_unit_get_by_id(SP_UNIT_PX);553 static Inkscape::Util::Unit px = unit_table.getUnit("px");
554 Inkscape::Util::Unit const *new_unit = new Inkscape::Util::Unit(px);
553555
554 if (value) {556 if (value) {
555 SPUnit const *const req_unit = sp_unit_get_by_abbreviation(value);557 Inkscape::Util::Unit u = unit_table.getUnit(value);
556 if ( req_unit == NULL ) {558 Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u);
559 if ( !unit_table.hasUnit(value) ) {
557 g_warning("Unrecognized unit `%s'", value);560 g_warning("Unrecognized unit `%s'", value);
558 /* fixme: Document errors should be reported in the status bar or561 /* fixme: Document errors should be reported in the status bar or
559 * the like (e.g. as per562 * the like (e.g. as per
560 * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log563 * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log
561 * should be only for programmer errors. */564 * should be only for programmer errors. */
562 } else if ( req_unit->base == SP_UNIT_ABSOLUTE ||565 } else if ( req_unit->isAbsolute() ) {
563 req_unit->base == SP_UNIT_DEVICE ) {
564 new_unit = req_unit;566 new_unit = req_unit;
565 } else {567 } else {
566 g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'",568 g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'",
@@ -573,18 +575,18 @@
573 break;575 break;
574 }576 }
575 case SP_ATTR_UNITS: {577 case SP_ATTR_UNITS: {
576 SPUnit const *new_unit = NULL;578 Inkscape::Util::Unit const *new_unit = NULL;
577579
578 if (value) {580 if (value) {
579 SPUnit const *const req_unit = sp_unit_get_by_abbreviation(value);581 Inkscape::Util::Unit u = unit_table.getUnit(value);
580 if ( req_unit == NULL ) {582 Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u);
583 if ( !unit_table.hasUnit(value) ) {
581 g_warning("Unrecognized unit `%s'", value);584 g_warning("Unrecognized unit `%s'", value);
582 /* fixme: Document errors should be reported in the status bar or585 /* fixme: Document errors should be reported in the status bar or
583 * the like (e.g. as per586 * the like (e.g. as per
584 * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log587 * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log
585 * should be only for programmer errors. */588 * should be only for programmer errors. */
586 } else if ( req_unit->base == SP_UNIT_ABSOLUTE ||589 } else if ( req_unit->isAbsolute() ) {
587 req_unit->base == SP_UNIT_DEVICE ) {
588 new_unit = req_unit;590 new_unit = req_unit;
589 } else {591 } else {
590 g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'",592 g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'",
@@ -1101,35 +1103,35 @@
1101 * \return the margin size in px, else 0.0 if anything is invalid.1103 * \return the margin size in px, else 0.0 if anything is invalid.
1102 */1104 */
1103double SPNamedView::getMarginLength(gchar const * const key,1105double SPNamedView::getMarginLength(gchar const * const key,
1104 SPUnit const * const margin_units,1106 Inkscape::Util::Unit const * const margin_units,
1105 SPUnit const * const return_units,1107 Inkscape::Util::Unit const * const return_units,
1106 double const width,1108 double const width,
1107 double const height,1109 double const height,
1108 bool const use_width)1110 bool const use_width)
1109{1111{
1110 double value;1112 double value;
1113 Inkscape::Util::Unit percent = unit_table.getUnit("%");
1111 if(!this->storeAsDouble(key,&value)) {1114 if(!this->storeAsDouble(key,&value)) {
1112 return 0.0;1115 return 0.0;
1113 }1116 }
1114 if (margin_units == &sp_unit_get_by_id (SP_UNIT_PERCENT)) {1117 if (*margin_units == percent) {
1115 return (use_width)? width * value : height * value; 1118 return (use_width)? width * value : height * value;
1116 }1119 }
1117 if (!sp_convert_distance (&value, margin_units, return_units)) {1120 if (!margin_units->compatibleWith(*return_units)) {
1118 return 0.0;1121 return 0.0;
1119 }1122 }
1120 return value;1123 return value;
1121}1124}
11221125
1123
1124/**1126/**
1125 * Returns namedview's default metric.1127 * Returns namedview's default unit.
1126 */1128 */
1127SPMetric SPNamedView::getDefaultMetric() const1129Inkscape::Util::Unit const SPNamedView::getDefaultUnit() const
1128{1130{
1129 if (doc_units) {1131 if (doc_units) {
1130 return sp_unit_get_metric(doc_units);1132 return *doc_units;
1131 } else {1133 } else {
1132 return SP_PT;1134 return *(new Inkscape::Util::Unit(unit_table.getUnit("pt")));
1133 }1135 }
1134}1136}
11351137
11361138
=== modified file 'src/sp-namedview.h'
--- src/sp-namedview.h 2013-01-23 12:22:14 +0000
+++ src/sp-namedview.h 2013-08-06 18:46:25 +0000
@@ -21,16 +21,17 @@
21#define SP_IS_NAMEDVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_NAMEDVIEW))21#define SP_IS_NAMEDVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_NAMEDVIEW))
2222
23#include "sp-object-group.h"23#include "sp-object-group.h"
24#include "sp-metric.h"
25#include "snap.h"24#include "snap.h"
26#include "document.h"25#include "document.h"
26#include "util/units.h"
2727
28G_BEGIN_DECLS28G_BEGIN_DECLS
2929
30struct SPUnit;
31
32namespace Inkscape {30namespace Inkscape {
33class CanvasGrid;31 class CanvasGrid;
32 namespace Util {
33 class Unit;
34 }
34}35}
3536
36enum {37enum {
@@ -58,8 +59,8 @@
58 GSList * grids;59 GSList * grids;
59 bool grids_visible;60 bool grids_visible;
6061
61 SPUnit const *doc_units;62 Inkscape::Util::Unit const *doc_units;
62 SPUnit const *units;63 Inkscape::Util::Unit const *units;
63 64
64 GQuark default_layer_id;65 GQuark default_layer_id;
6566
@@ -82,7 +83,7 @@
82 gchar const *getName() const;83 gchar const *getName() const;
83 guint getViewCount();84 guint getViewCount();
84 GSList const *getViewList() const;85 GSList const *getViewList() const;
85 SPMetric getDefaultMetric() const;86 Inkscape::Util::Unit const getDefaultUnit() const;
8687
87 void translateGuides(Geom::Translate const &translation);88 void translateGuides(Geom::Translate const &translation);
88 void translateGrids(Geom::Translate const &translation);89 void translateGrids(Geom::Translate const &translation);
@@ -94,7 +95,7 @@
94 bool getGuides();95 bool getGuides();
9596
96private:97private:
97 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);98 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);
98 friend class SPDocument;99 friend class SPDocument;
99};100};
100101
101102
=== modified file 'src/sp-text.cpp'
--- src/sp-text.cpp 2013-08-04 14:27:59 +0000
+++ src/sp-text.cpp 2013-08-06 18:46:25 +0000
@@ -43,7 +43,6 @@
43#include "sp-namedview.h"43#include "sp-namedview.h"
44#include "style.h"44#include "style.h"
45#include "inkscape.h"45#include "inkscape.h"
46#include "sp-metrics.h"
47#include "xml/quote.h"46#include "xml/quote.h"
48#include "xml/repr.h"47#include "xml/repr.h"
49#include "mod360.h"48#include "mod360.h"
@@ -56,7 +55,6 @@
56#include "sp-tspan.h"55#include "sp-tspan.h"
5756
58#include "text-editing.h"57#include "text-editing.h"
59#include "unit-constants.h"
6058
61/*#####################################################59/*#####################################################
62# SPTEXT60# SPTEXT
@@ -392,7 +390,8 @@
392 n = g_strdup(_("&lt;no name found&gt;"));390 n = g_strdup(_("&lt;no name found&gt;"));
393 }391 }
394392
395 GString *xs = SP_PX_TO_METRIC_STRING(style->font_size.computed, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->getDefaultMetric());393 Inkscape::Util::Quantity q = Inkscape::Util::Quantity(style->font_size.computed, "px");
394 GString *xs = g_string_new(q.string(*sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units).c_str());
396395
397 char const *trunc = "";396 char const *trunc = "";
398 Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item);397 Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item);
399398
=== modified file 'src/spiral-context.cpp'
--- src/spiral-context.cpp 2013-04-28 22:48:03 +0000
+++ src/spiral-context.cpp 2013-08-06 18:46:25 +0000
@@ -34,7 +34,6 @@
34#include "message-context.h"34#include "message-context.h"
35#include "pixmaps/cursor-spiral.xpm"35#include "pixmaps/cursor-spiral.xpm"
36#include "spiral-context.h"36#include "spiral-context.h"
37#include "sp-metrics.h"
38#include <glibmm/i18n.h>37#include <glibmm/i18n.h>
39#include "xml/repr.h"38#include "xml/repr.h"
40#include "xml/node-event-vector.h"39#include "xml/node-event-vector.h"
@@ -437,7 +436,8 @@
437 /*t0*/ sc->t0);436 /*t0*/ sc->t0);
438437
439 /* status text */438 /* status text */
440 GString *rads = SP_PX_TO_METRIC_STRING(rad, desktop->namedview->getDefaultMetric());439 Inkscape::Util::Quantity q = Inkscape::Util::Quantity(rad, "px");
440 GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str());
441 sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE,441 sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE,
442 _("<b>Spiral</b>: radius %s, angle %5g&#176;; with <b>Ctrl</b> to snap angle"),442 _("<b>Spiral</b>: radius %s, angle %5g&#176;; with <b>Ctrl</b> to snap angle"),
443 rads->str, sp_round((arg + 2.0*M_PI*spiral->revo)*180/M_PI, 0.0001));443 rads->str, sp_round((arg + 2.0*M_PI*spiral->revo)*180/M_PI, 0.0001));
444444
=== modified file 'src/star-context.cpp'
--- src/star-context.cpp 2013-04-28 22:48:03 +0000
+++ src/star-context.cpp 2013-08-06 18:46:25 +0000
@@ -36,7 +36,6 @@
36#include "desktop-style.h"36#include "desktop-style.h"
37#include "message-context.h"37#include "message-context.h"
38#include "pixmaps/cursor-star.xpm"38#include "pixmaps/cursor-star.xpm"
39#include "sp-metrics.h"
40#include <glibmm/i18n.h>39#include <glibmm/i18n.h>
41#include "preferences.h"40#include "preferences.h"
42#include "xml/repr.h"41#include "xml/repr.h"
@@ -450,7 +449,8 @@
450 arg1, arg1 + M_PI / sides, sc->isflatsided, sc->rounded, sc->randomized);449 arg1, arg1 + M_PI / sides, sc->isflatsided, sc->rounded, sc->randomized);
451450
452 /* status text */451 /* status text */
453 GString *rads = SP_PX_TO_METRIC_STRING(r1, desktop->namedview->getDefaultMetric());452 Inkscape::Util::Quantity q = Inkscape::Util::Quantity(r1, "px");
453 GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str());
454 sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE,454 sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE,
455 ( sc->isflatsided?455 ( sc->isflatsided?
456 _("<b>Polygon</b>: radius %s, angle %5g&#176;; with <b>Ctrl</b> to snap angle")456 _("<b>Polygon</b>: radius %s, angle %5g&#176;; with <b>Ctrl</b> to snap angle")
457457
=== modified file 'src/style.cpp'
--- src/style.cpp 2013-08-06 17:29:13 +0000
+++ src/style.cpp 2013-08-06 18:46:25 +0000
@@ -45,7 +45,7 @@
45#include "svg/css-ostringstream.h"45#include "svg/css-ostringstream.h"
46#include "xml/repr.h"46#include "xml/repr.h"
47#include "xml/simple-document.h"47#include "xml/simple-document.h"
48#include "unit-constants.h"48#include "util/units.h"
49#include "macros.h"49#include "macros.h"
50#include "preferences.h"50#include "preferences.h"
5151
@@ -2483,11 +2483,11 @@
24832483
2484 case SP_CSS_UNIT_NONE: unit_size = size; break;2484 case SP_CSS_UNIT_NONE: unit_size = size; break;
2485 case SP_CSS_UNIT_PX: unit_size = size; break;2485 case SP_CSS_UNIT_PX: unit_size = size; break;
2486 case SP_CSS_UNIT_PT: unit_size = size * PT_PER_PX; break;2486 case SP_CSS_UNIT_PT: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "pt"); break;
2487 case SP_CSS_UNIT_PC: unit_size = size * (PT_PER_PX / PT_PER_PC); break;2487 case SP_CSS_UNIT_PC: unit_size = size * (Inkscape::Util::Quantity::convert(1, "px", "pt") / Inkscape::Util::Quantity::convert(1, "pc", "pt")); break;
2488 case SP_CSS_UNIT_MM: unit_size = size * MM_PER_PX; break;2488 case SP_CSS_UNIT_MM: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "mm"); break;
2489 case SP_CSS_UNIT_CM: unit_size = size * CM_PER_PX; break;2489 case SP_CSS_UNIT_CM: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "cm"); break;
2490 case SP_CSS_UNIT_IN: unit_size = size * IN_PER_PX; break;2490 case SP_CSS_UNIT_IN: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "in"); break;
2491 case SP_CSS_UNIT_EM: unit_size = size / SP_CSS_FONT_SIZE_DEFAULT; break;2491 case SP_CSS_UNIT_EM: unit_size = size / SP_CSS_FONT_SIZE_DEFAULT; break;
2492 case SP_CSS_UNIT_EX: unit_size = size * 2.0 / SP_CSS_FONT_SIZE_DEFAULT ; break;2492 case SP_CSS_UNIT_EX: unit_size = size * 2.0 / SP_CSS_FONT_SIZE_DEFAULT ; break;
2493 case SP_CSS_UNIT_PERCENT: unit_size = size * 100.0 / SP_CSS_FONT_SIZE_DEFAULT; break;2493 case SP_CSS_UNIT_PERCENT: unit_size = size * 100.0 / SP_CSS_FONT_SIZE_DEFAULT; break;
@@ -3472,19 +3472,19 @@
3472 } else if (!strcmp(e, "pt")) {3472 } else if (!strcmp(e, "pt")) {
3473 /* Userspace / DEVICESCALE */3473 /* Userspace / DEVICESCALE */
3474 val->unit = SP_CSS_UNIT_PT;3474 val->unit = SP_CSS_UNIT_PT;
3475 val->computed = value * PX_PER_PT;3475 val->computed = value * Inkscape::Util::Quantity::convert(1, "pt", "px");
3476 } else if (!strcmp(e, "pc")) {3476 } else if (!strcmp(e, "pc")) {
3477 val->unit = SP_CSS_UNIT_PC;3477 val->unit = SP_CSS_UNIT_PC;
3478 val->computed = value * PX_PER_PC;3478 val->computed = value * Inkscape::Util::Quantity::convert(1, "pc", "px");
3479 } else if (!strcmp(e, "mm")) {3479 } else if (!strcmp(e, "mm")) {
3480 val->unit = SP_CSS_UNIT_MM;3480 val->unit = SP_CSS_UNIT_MM;
3481 val->computed = value * PX_PER_MM;3481 val->computed = value * Inkscape::Util::Quantity::convert(1, "mm", "px");
3482 } else if (!strcmp(e, "cm")) {3482 } else if (!strcmp(e, "cm")) {
3483 val->unit = SP_CSS_UNIT_CM;3483 val->unit = SP_CSS_UNIT_CM;
3484 val->computed = value * PX_PER_CM;3484 val->computed = value * Inkscape::Util::Quantity::convert(1, "cm", "px");
3485 } else if (!strcmp(e, "in")) {3485 } else if (!strcmp(e, "in")) {
3486 val->unit = SP_CSS_UNIT_IN;3486 val->unit = SP_CSS_UNIT_IN;
3487 val->computed = value * PX_PER_IN;3487 val->computed = value * Inkscape::Util::Quantity::convert(1, "in", "px");
3488 } else if (!strcmp(e, "em")) {3488 } else if (!strcmp(e, "em")) {
3489 /* EM square */3489 /* EM square */
3490 val->unit = SP_CSS_UNIT_EM;3490 val->unit = SP_CSS_UNIT_EM;
@@ -4043,23 +4043,23 @@
4043 return g_strlcpy(p, os.str().c_str(), len);4043 return g_strlcpy(p, os.str().c_str(), len);
4044 break;4044 break;
4045 case SP_CSS_UNIT_PT:4045 case SP_CSS_UNIT_PT:
4046 os << key << ":" << val->computed * PT_PER_PX << "pt;";4046 os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "pt") << "pt;";
4047 return g_strlcpy(p, os.str().c_str(), len);4047 return g_strlcpy(p, os.str().c_str(), len);
4048 break;4048 break;
4049 case SP_CSS_UNIT_PC:4049 case SP_CSS_UNIT_PC:
4050 os << key << ":" << val->computed * PT_PER_PX / 12.0 << "pc;";4050 os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "pt") / 12.0 << "pc;";
4051 return g_strlcpy(p, os.str().c_str(), len);4051 return g_strlcpy(p, os.str().c_str(), len);
4052 break;4052 break;
4053 case SP_CSS_UNIT_MM:4053 case SP_CSS_UNIT_MM:
4054 os << key << ":" << val->computed * MM_PER_PX << "mm;";4054 os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "mm") << "mm;";
4055 return g_strlcpy(p, os.str().c_str(), len);4055 return g_strlcpy(p, os.str().c_str(), len);
4056 break;4056 break;
4057 case SP_CSS_UNIT_CM:4057 case SP_CSS_UNIT_CM:
4058 os << key << ":" << val->computed * CM_PER_PX << "cm;";4058 os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "cm") << "cm;";
4059 return g_strlcpy(p, os.str().c_str(), len);4059 return g_strlcpy(p, os.str().c_str(), len);
4060 break;4060 break;
4061 case SP_CSS_UNIT_IN:4061 case SP_CSS_UNIT_IN:
4062 os << key << ":" << val->computed * IN_PER_PX << "in;";4062 os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "in") << "in;";
4063 return g_strlcpy(p, os.str().c_str(), len);4063 return g_strlcpy(p, os.str().c_str(), len);
4064 break;4064 break;
4065 case SP_CSS_UNIT_EM:4065 case SP_CSS_UNIT_EM:
40664066
=== modified file 'src/svg/svg-length.cpp'
--- src/svg/svg-length.cpp 2011-12-08 11:53:54 +0000
+++ src/svg/svg-length.cpp 2013-08-06 18:46:25 +0000
@@ -23,7 +23,7 @@
2323
24#include "svg.h"24#include "svg.h"
25#include "stringstream.h"25#include "stringstream.h"
26#include "../unit-constants.h"26#include "util/units.h"
2727
2828
29static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, float *val, float *computed, char **next);29static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, float *val, float *computed, char **next);
@@ -330,6 +330,8 @@
330 *next = (char *) e + 1;330 *next = (char *) e + 1;
331 }331 }
332 return 1;332 return 1;
333 } else if (g_ascii_isspace(e[0])) {
334 return 0; // spaces are not allowed
333 } else {335 } else {
334 /* Unitless */336 /* Unitless */
335 if (unit) {337 if (unit) {
@@ -365,7 +367,7 @@
365 *unit = SVGLength::PT;367 *unit = SVGLength::PT;
366 }368 }
367 if (computed) {369 if (computed) {
368 *computed = v * PX_PER_PT;370 *computed = v * Inkscape::Util::Quantity::convert(1, "pt", "px");
369 }371 }
370 break;372 break;
371 case UVAL('p','c'):373 case UVAL('p','c'):
@@ -373,7 +375,7 @@
373 *unit = SVGLength::PC;375 *unit = SVGLength::PC;
374 }376 }
375 if (computed) {377 if (computed) {
376 *computed = v * PX_PER_PC;378 *computed = v * Inkscape::Util::Quantity::convert(1, "pc", "px");
377 }379 }
378 break;380 break;
379 case UVAL('m','m'):381 case UVAL('m','m'):
@@ -381,7 +383,7 @@
381 *unit = SVGLength::MM;383 *unit = SVGLength::MM;
382 }384 }
383 if (computed) {385 if (computed) {
384 *computed = v * PX_PER_MM;386 *computed = v * Inkscape::Util::Quantity::convert(1, "mm", "px");
385 }387 }
386 break;388 break;
387 case UVAL('c','m'):389 case UVAL('c','m'):
@@ -389,7 +391,7 @@
389 *unit = SVGLength::CM;391 *unit = SVGLength::CM;
390 }392 }
391 if (computed) {393 if (computed) {
392 *computed = v * PX_PER_CM;394 *computed = v * Inkscape::Util::Quantity::convert(1, "cm", "px");
393 }395 }
394 break;396 break;
395 case UVAL('i','n'):397 case UVAL('i','n'):
@@ -397,7 +399,7 @@
397 *unit = SVGLength::INCH;399 *unit = SVGLength::INCH;
398 }400 }
399 if (computed) {401 if (computed) {
400 *computed = v * PX_PER_IN;402 *computed = v * Inkscape::Util::Quantity::convert(1, "in", "px");
401 }403 }
402 break;404 break;
403 case UVAL('f','t'):405 case UVAL('f','t'):
@@ -405,7 +407,7 @@
405 *unit = SVGLength::FOOT;407 *unit = SVGLength::FOOT;
406 }408 }
407 if (computed) {409 if (computed) {
408 *computed = v * PX_PER_FT;410 *computed = v * Inkscape::Util::Quantity::convert(1, "ft", "px");
409 }411 }
410 break;412 break;
411 case UVAL('e','m'):413 case UVAL('e','m'):
412414
=== modified file 'src/text-context.cpp'
--- src/text-context.cpp 2013-05-12 10:22:42 +0000
+++ src/text-context.cpp 2013-08-06 18:46:25 +0000
@@ -42,7 +42,6 @@
42#include "selection.h"42#include "selection.h"
43#include "shape-editor.h"43#include "shape-editor.h"
44#include "sp-flowtext.h"44#include "sp-flowtext.h"
45#include "sp-metrics.h"
46#include "sp-namedview.h"45#include "sp-namedview.h"
47#include "sp-text.h"46#include "sp-text.h"
48#include "style.h"47#include "style.h"
@@ -640,8 +639,10 @@
640 gobble_motion_events(GDK_BUTTON1_MASK);639 gobble_motion_events(GDK_BUTTON1_MASK);
641640
642 // status text641 // status text
643 GString *xs = SP_PX_TO_METRIC_STRING(fabs((p - tc->p0)[Geom::X]), desktop->namedview->getDefaultMetric());642 Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(fabs((p - tc->p0)[Geom::X]), "px");
644 GString *ys = SP_PX_TO_METRIC_STRING(fabs((p - tc->p0)[Geom::Y]), desktop->namedview->getDefaultMetric());643 Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(fabs((p - tc->p0)[Geom::Y]), "px");
644 GString *xs = g_string_new(x_q.string(*desktop->namedview->doc_units).c_str());
645 GString *ys = g_string_new(y_q.string(*desktop->namedview->doc_units).c_str());
645 event_context->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Flowed text frame</b>: %s &#215; %s"), xs->str, ys->str);646 event_context->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Flowed text frame</b>: %s &#215; %s"), xs->str, ys->str);
646 g_string_free(xs, FALSE);647 g_string_free(xs, FALSE);
647 g_string_free(ys, FALSE);648 g_string_free(ys, FALSE);
648649
=== modified file 'src/text-editing.cpp'
--- src/text-editing.cpp 2013-03-16 19:42:47 +0000
+++ src/text-editing.cpp 2013-08-06 18:46:25 +0000
@@ -24,7 +24,7 @@
24#include "inkscape.h"24#include "inkscape.h"
25#include "message-stack.h"25#include "message-stack.h"
26#include "style.h"26#include "style.h"
27#include "unit-constants.h"27#include "util/units.h"
2828
29#include "document.h"29#include "document.h"
30#include "xml/repr.h"30#include "xml/repr.h"
@@ -1278,23 +1278,23 @@
1278 style->line_height.value = style->line_height.computed;1278 style->line_height.value = style->line_height.computed;
1279 break;1279 break;
1280 case SP_CSS_UNIT_PT:1280 case SP_CSS_UNIT_PT:
1281 style->line_height.computed += zby * PT_PER_PX;1281 style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "pt");
1282 style->line_height.value = style->line_height.computed;1282 style->line_height.value = style->line_height.computed;
1283 break;1283 break;
1284 case SP_CSS_UNIT_PC:1284 case SP_CSS_UNIT_PC:
1285 style->line_height.computed += zby * (PT_PER_PX / 12);1285 style->line_height.computed += zby * (Inkscape::Util::Quantity::convert(1, "px", "pt") / 12);
1286 style->line_height.value = style->line_height.computed;1286 style->line_height.value = style->line_height.computed;
1287 break;1287 break;
1288 case SP_CSS_UNIT_MM:1288 case SP_CSS_UNIT_MM:
1289 style->line_height.computed += zby * MM_PER_PX;1289 style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "mm");
1290 style->line_height.value = style->line_height.computed;1290 style->line_height.value = style->line_height.computed;
1291 break;1291 break;
1292 case SP_CSS_UNIT_CM:1292 case SP_CSS_UNIT_CM:
1293 style->line_height.computed += zby * CM_PER_PX;1293 style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "cm");
1294 style->line_height.value = style->line_height.computed;1294 style->line_height.value = style->line_height.computed;
1295 break;1295 break;
1296 case SP_CSS_UNIT_IN:1296 case SP_CSS_UNIT_IN:
1297 style->line_height.computed += zby * IN_PER_PX;1297 style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "in");
1298 style->line_height.value = style->line_height.computed;1298 style->line_height.value = style->line_height.computed;
1299 break;1299 break;
1300 }1300 }
13011301
=== modified file 'src/ui/CMakeLists.txt'
--- src/ui/CMakeLists.txt 2013-07-23 10:54:01 +0000
+++ src/ui/CMakeLists.txt 2013-08-06 18:46:25 +0000
@@ -112,6 +112,7 @@
112 widget/text.cpp112 widget/text.cpp
113 widget/tolerance-slider.cpp113 widget/tolerance-slider.cpp
114 widget/unit-menu.cpp114 widget/unit-menu.cpp
115 widget/unit-tracker.cpp
115116
116 view/view.cpp117 view/view.cpp
117 view/view-widget.cpp118 view/view-widget.cpp
@@ -240,6 +241,7 @@
240 widget/text.h241 widget/text.h
241 widget/tolerance-slider.h242 widget/tolerance-slider.h
242 widget/unit-menu.h243 widget/unit-menu.h
244 widget/unit-tracker.h
243245
244 view/edit-widget-interface.h246 view/edit-widget-interface.h
245 view/view-widget.h247 view/view-widget.h
246248
=== modified file 'src/ui/clipboard.cpp'
--- src/ui/clipboard.cpp 2013-04-21 00:16:01 +0000
+++ src/ui/clipboard.cpp 2013-08-06 18:46:25 +0000
@@ -79,7 +79,7 @@
79#include "text-editing.h"79#include "text-editing.h"
80#include "tools-switch.h"80#include "tools-switch.h"
81#include "path-chemistry.h"81#include "path-chemistry.h"
82#include "unit-constants.h"82#include "util/units.h"
83#include "helper/png-write.h"83#include "helper/png-write.h"
84#include "svg/svg-color.h"84#include "svg/svg-color.h"
85#include "sp-namedview.h"85#include "sp-namedview.h"
@@ -1078,14 +1078,14 @@
1078 try {1078 try {
1079 if (out == outlist.end() && target == "image/png")1079 if (out == outlist.end() && target == "image/png")
1080 {1080 {
1081 gdouble dpi = PX_PER_IN;1081 gdouble dpi = Inkscape::Util::Quantity::convert(1, "in", "px");
1082 guint32 bgcolor = 0x00000000;1082 guint32 bgcolor = 0x00000000;
10831083
1084 Geom::Point origin (_clipboardSPDoc->getRoot()->x.computed, _clipboardSPDoc->getRoot()->y.computed);1084 Geom::Point origin (_clipboardSPDoc->getRoot()->x.computed, _clipboardSPDoc->getRoot()->y.computed);
1085 Geom::Rect area = Geom::Rect(origin, origin + _clipboardSPDoc->getDimensions());1085 Geom::Rect area = Geom::Rect(origin, origin + _clipboardSPDoc->getDimensions());
10861086
1087 unsigned long int width = (unsigned long int) (area.width() * dpi / PX_PER_IN + 0.5);1087 unsigned long int width = (unsigned long int) (area.width() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5);
1088 unsigned long int height = (unsigned long int) (area.height() * dpi / PX_PER_IN + 0.5);1088 unsigned long int height = (unsigned long int) (area.height() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5);
10891089
1090 // read from namedview1090 // read from namedview
1091 Inkscape::XML::Node *nv = sp_repr_lookup_name (_clipboardSPDoc->rroot, "sodipodi:namedview");1091 Inkscape::XML::Node *nv = sp_repr_lookup_name (_clipboardSPDoc->rroot, "sodipodi:namedview");
10921092
=== modified file 'src/ui/dialog/clonetiler.cpp'
--- src/ui/dialog/clonetiler.cpp 2013-03-29 11:00:19 +0000
+++ src/ui/dialog/clonetiler.cpp 2013-08-06 18:46:25 +0000
@@ -34,8 +34,8 @@
34#include "document.h"34#include "document.h"
35#include "document-undo.h"35#include "document-undo.h"
36#include "filter-chemistry.h"36#include "filter-chemistry.h"
37#include "helper/unit-menu.h"37#include "ui/widget/unit-menu.h"
38#include "helper/units.h"38#include "util/units.h"
39#include "helper/window.h"39#include "helper/window.h"
40#include "inkscape.h"40#include "inkscape.h"
41#include "interface.h"41#include "interface.h"
@@ -58,6 +58,7 @@
58#include "sp-root.h"58#include "sp-root.h"
5959
60using Inkscape::DocumentUndo;60using Inkscape::DocumentUndo;
61using Inkscape::Util::unit_table;
6162
62namespace Inkscape {63namespace Inkscape {
63namespace UI {64namespace UI {
@@ -1092,35 +1093,36 @@
1092 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);1093 g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
10931094
1094 // unitmenu1095 // unitmenu
1095 GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);1096 unit_menu = new Inkscape::UI::Widget::UnitMenu();
1096 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);1097 unit_menu->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR);
1098 unit_menu->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr);
1099 unitChangedConn = unit_menu->signal_changed().connect(sigc::mem_fun(*this, &CloneTiler::clonetiler_unit_changed));
10971100
1098 {1101 {
1099 // Width spinbutton1102 // Width spinbutton
1100#if WITH_GTKMM_3_01103#if WITH_GTKMM_3_0
1101 Glib::RefPtr<Gtk::Adjustment> a = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0);1104 fill_width = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0);
1102#else1105#else
1103 Gtk::Adjustment *a = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0);1106 fill_width = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0);
1104#endif1107#endif
1105 sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a->gobj()));
11061108
1107 double value = prefs->getDouble(prefs_path + "fillwidth", 50.0);1109 double value = prefs->getDouble(prefs_path + "fillwidth", 50.0);
1108 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));1110 Inkscape::Util::Unit const unit = unit_menu->getUnit();
1109 gdouble const units = sp_pixels_get_units (value, unit);1111 gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit);
1110 a->set_value (units);1112 fill_width->set_value (units);
11111113
1112#if WITH_GTKMM_3_01114#if WITH_GTKMM_3_0
1113 Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(a, 1.0, 2);1115 Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(fill_width, 1.0, 2);
1114#else1116#else
1115 Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*a, 1.0, 2);1117 Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*fill_width, 1.0, 2);
1116#endif1118#endif
1117 e->set_tooltip_text (_("Width of the rectangle to be filled"));1119 e->set_tooltip_text (_("Width of the rectangle to be filled"));
1118 e->set_width_chars (7);1120 e->set_width_chars (7);
1119 e->set_digits (4);1121 e->set_digits (4);
1120 gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0);1122 gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0);
1121 // TODO: C++ification1123 // TODO: C++ification
1122 g_signal_connect(G_OBJECT(a->gobj()), "value_changed",1124 g_signal_connect(G_OBJECT(fill_width->gobj()), "value_changed",
1123 G_CALLBACK(clonetiler_fill_width_changed), u);1125 G_CALLBACK(clonetiler_fill_width_changed), unit_menu);
1124 }1126 }
1125 {1127 {
1126 GtkWidget *l = gtk_label_new ("");1128 GtkWidget *l = gtk_label_new ("");
@@ -1132,32 +1134,31 @@
1132 {1134 {
1133 // Height spinbutton1135 // Height spinbutton
1134#if WITH_GTKMM_3_01136#if WITH_GTKMM_3_0
1135 Glib::RefPtr<Gtk::Adjustment> a = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0);1137 fill_height = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0);
1136#else1138#else
1137 Gtk::Adjustment *a = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0);1139 fill_height = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0);
1138#endif1140#endif
1139 sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a->gobj()));
11401141
1141 double value = prefs->getDouble(prefs_path + "fillheight", 50.0);1142 double value = prefs->getDouble(prefs_path + "fillheight", 50.0);
1142 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));1143 Inkscape::Util::Unit const unit = unit_menu->getUnit();
1143 gdouble const units = sp_pixels_get_units (value, unit);1144 gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit);
1144 a->set_value (units);1145 fill_height->set_value (units);
11451146
1146#if WITH_GTKMM_3_01147#if WITH_GTKMM_3_0
1147 Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(a, 1.0, 2);1148 Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(fill_height, 1.0, 2);
1148#else1149#else
1149 Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*a, 1.0, 2);1150 Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*fill_height, 1.0, 2);
1150#endif1151#endif
1151 e->set_tooltip_text (_("Height of the rectangle to be filled"));1152 e->set_tooltip_text (_("Height of the rectangle to be filled"));
1152 e->set_width_chars (7);1153 e->set_width_chars (7);
1153 e->set_digits (4);1154 e->set_digits (4);
1154 gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0);1155 gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0);
1155 // TODO: C++ification1156 // TODO: C++ification
1156 g_signal_connect(G_OBJECT(a->gobj()), "value_changed",1157 g_signal_connect(G_OBJECT(fill_height->gobj()), "value_changed",
1157 G_CALLBACK(clonetiler_fill_height_changed), u);1158 G_CALLBACK(clonetiler_fill_height_changed), unit_menu);
1158 }1159 }
11591160
1160 gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);1161 gtk_box_pack_start (GTK_BOX (hb), (GtkWidget*) unit_menu->gobj(), TRUE, TRUE, 0);
1161 clonetiler_table_attach (table, hb, 0.0, 2, 2);1162 clonetiler_table_attach (table, hb, 0.0, 2, 2);
11621163
1163 }1164 }
@@ -2944,26 +2945,39 @@
29442945
29452946
29462947
2947void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, GtkWidget *u)2948void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u)
2948{2949{
2949 gdouble const raw_dist = gtk_adjustment_get_value (adj);2950 gdouble const raw_dist = gtk_adjustment_get_value (adj);
2950 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));2951 Inkscape::Util::Unit const unit = u->getUnit();
2951 gdouble const pixels = sp_units_get_pixels (raw_dist, unit);2952 gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px");
29522953
2953 Inkscape::Preferences *prefs = Inkscape::Preferences::get();2954 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
2954 prefs->setDouble(prefs_path + "fillwidth", pixels);2955 prefs->setDouble(prefs_path + "fillwidth", pixels);
2955}2956}
29562957
2957void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, GtkWidget *u)2958void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u)
2958{2959{
2959 gdouble const raw_dist = gtk_adjustment_get_value (adj);2960 gdouble const raw_dist = gtk_adjustment_get_value (adj);
2960 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));2961 Inkscape::Util::Unit const unit = u->getUnit();
2961 gdouble const pixels = sp_units_get_pixels (raw_dist, unit);2962 gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px");
29622963
2963 Inkscape::Preferences *prefs = Inkscape::Preferences::get();2964 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
2964 prefs->setDouble(prefs_path + "fillheight", pixels);2965 prefs->setDouble(prefs_path + "fillheight", pixels);
2965}2966}
29662967
2968void CloneTiler::clonetiler_unit_changed()
2969{
2970 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
2971 gdouble width_pixels = prefs->getDouble(prefs_path + "fillwidth");
2972 gdouble height_pixels = prefs->getDouble(prefs_path + "fillheight");
2973
2974 Inkscape::Util::Unit unit = unit_menu->getUnit();
2975
2976 gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, "px", unit);
2977 gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, "px", unit);
2978 gtk_adjustment_set_value(fill_width->gobj(), width_value);
2979 gtk_adjustment_set_value(fill_height->gobj(), height_value);
2980}
29672981
2968void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg)2982void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg)
2969{2983{
@@ -2977,7 +2991,6 @@
2977 }2991 }
2978}2992}
29792993
2980
2981}2994}
2982}2995}
2983}2996}
29842997
=== modified file 'src/ui/dialog/clonetiler.h'
--- src/ui/dialog/clonetiler.h 2013-03-29 11:00:19 +0000
+++ src/ui/dialog/clonetiler.h 2013-08-06 18:46:25 +0000
@@ -19,6 +19,11 @@
1919
20namespace Inkscape {20namespace Inkscape {
21namespace UI {21namespace UI {
22
23namespace Widget {
24 class UnitMenu;
25}
26
22namespace Dialog {27namespace Dialog {
2328
24class CloneTiler : public Widget::Panel {29class CloneTiler : public Widget::Panel {
@@ -45,8 +50,9 @@
45 static void clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg);50 static void clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg);
46 static void clonetiler_pick_to(GtkToggleButton *tb, gpointer data);51 static void clonetiler_pick_to(GtkToggleButton *tb, gpointer data);
47 static void clonetiler_xy_changed(GtkAdjustment *adj, gpointer data);52 static void clonetiler_xy_changed(GtkAdjustment *adj, gpointer data);
48 static void clonetiler_fill_width_changed(GtkAdjustment *adj, GtkWidget *u);53 static void clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u);
49 static void clonetiler_fill_height_changed(GtkAdjustment *adj, GtkWidget *u);54 static void clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u);
55 void clonetiler_unit_changed();
50 static void clonetiler_switch_to_create(GtkToggleButton */*tb*/, GtkWidget *dlg);56 static void clonetiler_switch_to_create(GtkToggleButton */*tb*/, GtkWidget *dlg);
51 static void clonetiler_switch_to_fill(GtkToggleButton */*tb*/, GtkWidget *dlg);57 static void clonetiler_switch_to_fill(GtkToggleButton */*tb*/, GtkWidget *dlg);
52 static void clonetiler_keep_bbox_toggled(GtkToggleButton *tb, gpointer /*data*/);58 static void clonetiler_keep_bbox_toggled(GtkToggleButton *tb, gpointer /*data*/);
@@ -112,12 +118,22 @@
112 DesktopTracker deskTrack;118 DesktopTracker deskTrack;
113 Inkscape::UI::Widget::ColorPicker *color_picker;119 Inkscape::UI::Widget::ColorPicker *color_picker;
114 GtkSizeGroup* table_row_labels;120 GtkSizeGroup* table_row_labels;
121 Inkscape::UI::Widget::UnitMenu *unit_menu;
122
123#if WITH_GTKMM_3_0
124 Glib::RefPtr<Gtk::Adjustment> fill_width;
125 Glib::RefPtr<Gtk::Adjustment> fill_height;
126#else
127 Gtk::Adjustment *fill_width;
128 Gtk::Adjustment *fill_height;
129#endif
115130
116 sigc::connection desktopChangeConn;131 sigc::connection desktopChangeConn;
117 sigc::connection selectChangedConn;132 sigc::connection selectChangedConn;
118 sigc::connection subselChangedConn;133 sigc::connection subselChangedConn;
119 sigc::connection selectModifiedConn;134 sigc::connection selectModifiedConn;
120 sigc::connection color_changed_connection;135 sigc::connection color_changed_connection;
136 sigc::connection unitChangedConn;
121137
122 /**138 /**
123 * Can be invoked for setting the desktop. Currently not used.139 * Can be invoked for setting the desktop. Currently not used.
124140
=== modified file 'src/ui/dialog/document-properties.cpp'
--- src/ui/dialog/document-properties.cpp 2013-03-16 19:42:47 +0000
+++ src/ui/dialog/document-properties.cpp 2013-08-06 18:46:25 +0000
@@ -28,7 +28,6 @@
28#include "document.h"28#include "document.h"
29#include "desktop-handles.h"29#include "desktop-handles.h"
30#include "desktop.h"30#include "desktop.h"
31#include "helper/units.h"
32#include "inkscape.h"31#include "inkscape.h"
33#include "io/sys.h"32#include "io/sys.h"
34#include "preferences.h"33#include "preferences.h"
@@ -1432,7 +1431,7 @@
1432 _rcb_shad.setActive (nv->showpageshadow);1431 _rcb_shad.setActive (nv->showpageshadow);
14331432
1434 if (nv->doc_units)1433 if (nv->doc_units)
1435 _rum_deflt.setUnit (nv->doc_units);1434 _rum_deflt.setUnit (nv->doc_units->abbr);
14361435
1437 double const doc_w_px = sp_desktop_document(dt)->getWidth();1436 double const doc_w_px = sp_desktop_document(dt)->getWidth();
1438 double const doc_h_px = sp_desktop_document(dt)->getHeight();1437 double const doc_h_px = sp_desktop_document(dt)->getHeight();
14391438
=== modified file 'src/ui/dialog/export.cpp'
--- src/ui/dialog/export.cpp 2013-06-06 13:44:11 +0000
+++ src/ui/dialog/export.cpp 2013-08-06 18:46:25 +0000
@@ -48,9 +48,8 @@
48#include <glibmm/i18n.h>48#include <glibmm/i18n.h>
49#include <glibmm/miscutils.h>49#include <glibmm/miscutils.h>
5050
51#include "helper/unit-menu.h"51#include "ui/widget/unit-menu.h"
52#include "helper/units.h"52#include "util/units.h"
53#include "unit-constants.h"
54#include "helper/window.h"53#include "helper/window.h"
55#include "inkscape-private.h"54#include "inkscape-private.h"
56#include "document.h"55#include "document.h"
@@ -98,7 +97,7 @@
9897
99#define SP_EXPORT_MIN_SIZE 1.098#define SP_EXPORT_MIN_SIZE 1.0
10099
101#define DPI_BASE PX_PER_IN100#define DPI_BASE Inkscape::Util::Quantity::convert(1, "in", "px")
102101
103#define EXPORT_COORD_PRECISION 3102#define EXPORT_COORD_PRECISION 3
104103
@@ -108,6 +107,8 @@
108#include "verbs.h"107#include "verbs.h"
109#include "export.h"108#include "export.h"
110109
110using Inkscape::Util::unit_table;
111
111namespace {112namespace {
112113
113class MessageCleaner114class MessageCleaner
@@ -198,10 +199,13 @@
198 /* Units box */199 /* Units box */
199 /* gets added to the vbox later, but the unit selector is needed200 /* gets added to the vbox later, but the unit selector is needed
200 earlier than that */201 earlier than that */
201 unit_selector = Glib::wrap(sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE));202 unit_selector = new Inkscape::UI::Widget::UnitMenu();
203 unit_selector->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR);
204 unitChangedConn = unit_selector->signal_changed().connect(sigc::mem_fun(*this, &Export::onUnitChanged));
205
202 SPDesktop *desktop = SP_ACTIVE_DESKTOP;206 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
203 if (desktop)207 if (desktop)
204 sp_unit_selector_set_unit (SP_UNIT_SELECTOR(unit_selector->gobj()), sp_desktop_namedview(desktop)->doc_units);208 unit_selector->setUnit(sp_desktop_namedview(desktop)->doc_units->abbr);
205 unitbox.pack_end(*unit_selector, false, false, 0);209 unitbox.pack_end(*unit_selector, false, false, 0);
206 unitbox.pack_end(units_label, false, false, 3);210 unitbox.pack_end(units_label, false, false, 3);
207211
@@ -226,28 +230,28 @@
226 t->set_col_spacings (4);230 t->set_col_spacings (4);
227#endif231#endif
228232
229 x0_adj = createSpinbutton ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(),233 x0_adj = createSpinbutton ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(),
230 t, 0, 0, _("_x0:"), "", EXPORT_COORD_PRECISION, 1,234 t, 0, 0, _("_x0:"), "", EXPORT_COORD_PRECISION, 1,
231 &Export::onAreaX0Change);235 &Export::onAreaX0Change);
232236
233 x1_adj = createSpinbutton ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(),237 x1_adj = createSpinbutton ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(),
234 t, 0, 1, _("x_1:"), "", EXPORT_COORD_PRECISION, 1,238 t, 0, 1, _("x_1:"), "", EXPORT_COORD_PRECISION, 1,
235 &Export::onAreaX1Change);239 &Export::onAreaX1Change);
236240
237 width_adj = createSpinbutton ( "width", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0,241 width_adj = createSpinbutton ( "width", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0,
238 unit_selector->gobj(), t, 0, 2, _("Wid_th:"), "", EXPORT_COORD_PRECISION, 1,242 ((Gtk::Widget*) unit_selector)->gobj(), t, 0, 2, _("Wid_th:"), "", EXPORT_COORD_PRECISION, 1,
239 &Export::onAreaWidthChange);243 &Export::onAreaWidthChange);
240244
241 y0_adj = createSpinbutton ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(),245 y0_adj = createSpinbutton ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(),
242 t, 2, 0, _("_y0:"), "", EXPORT_COORD_PRECISION, 1,246 t, 2, 0, _("_y0:"), "", EXPORT_COORD_PRECISION, 1,
243 &Export::onAreaY0Change);247 &Export::onAreaY0Change);
244248
245 y1_adj = createSpinbutton ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(),249 y1_adj = createSpinbutton ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(),
246 t, 2, 1, _("y_1:"), "", EXPORT_COORD_PRECISION, 1,250 t, 2, 1, _("y_1:"), "", EXPORT_COORD_PRECISION, 1,
247 &Export::onAreaY1Change);251 &Export::onAreaY1Change);
248252
249 height_adj = createSpinbutton ( "height", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0,253 height_adj = createSpinbutton ( "height", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0,
250 unit_selector->gobj(), t, 2, 2, _("Hei_ght:"), "", EXPORT_COORD_PRECISION, 1,254 ((Gtk::Widget*) unit_selector)->gobj(), t, 2, 2, _("Hei_ght:"), "", EXPORT_COORD_PRECISION, 1,
251 &Export::onAreaHeightChange);255 &Export::onAreaHeightChange);
252256
253 area_box.pack_start(togglebox, false, false, 3);257 area_box.pack_start(togglebox, false, false, 3);
@@ -496,9 +500,6 @@
496#else500#else
497 Gtk::Adjustment *adj = new Gtk::Adjustment ( val, min, max, step, page, 0 );501 Gtk::Adjustment *adj = new Gtk::Adjustment ( val, min, max, step, page, 0 );
498#endif502#endif
499 if (us) {
500 sp_unit_selector_add_adjustment ( SP_UNIT_SELECTOR (us), GTK_ADJUSTMENT (adj->gobj()) );
501 }
502503
503 int pos = 0;504 int pos = 0;
504 Gtk::Label *l = NULL;505 Gtk::Label *l = NULL;
@@ -979,6 +980,12 @@
979 return path;980 return path;
980}981}
981982
983// Called when unit is changed
984void Export::onUnitChanged()
985{
986 onAreaToggled();
987}
988
982void Export::onHideExceptSelected ()989void Export::onHideExceptSelected ()
983{990{
984 prefs->setBool("/dialogs/export/hideexceptselected/value", hide_export.get_active());991 prefs->setBool("/dialogs/export/hideexceptselected/value", hide_export.get_active());
@@ -1042,8 +1049,8 @@
10421049
1043 Geom::OptRect area = item->desktopVisualBounds();1050 Geom::OptRect area = item->desktopVisualBounds();
1044 if (area) {1051 if (area) {
1045 gint width = (gint) (area->width() * dpi / PX_PER_IN + 0.5);1052 gint width = (gint) (area->width() * dpi / DPI_BASE + 0.5);
1046 gint height = (gint) (area->height() * dpi / PX_PER_IN + 0.5);1053 gint height = (gint) (area->height() * dpi / DPI_BASE + 0.5);
10471054
1048 if (width > 1 && height > 1) {1055 if (width > 1 && height > 1) {
1049 // Do export1056 // Do export
@@ -1507,10 +1514,6 @@
1507 return;1514 return;
1508 }1515 }
15091516
1510 if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) {
1511 return;
1512 }
1513
1514 update = true;1517 update = true;
15151518
1516 x0 = getValuePx(x0_adj);1519 x0 = getValuePx(x0_adj);
@@ -1554,10 +1557,6 @@
1554 return;1557 return;
1555 }1558 }
15561559
1557 if (sp_unit_selector_update_test (SP_UNIT_SELECTOR(unit_selector->gobj()))) {
1558 return;
1559 }
1560
1561 update = true;1560 update = true;
15621561
1563 y0 = getValuePx(y0_adj);1562 y0 = getValuePx(y0_adj);
@@ -1597,10 +1596,6 @@
1597 return;1596 return;
1598 }1597 }
15991598
1600 if (sp_unit_selector_update_test(reinterpret_cast<SPUnitSelector *>(unit_selector->gobj()))) {
1601 return;
1602 }
1603
1604 update = true;1599 update = true;
16051600
1606 float x0 = getValuePx(x0_adj);1601 float x0 = getValuePx(x0_adj);
@@ -1630,10 +1625,6 @@
1630 return;1625 return;
1631 }1626 }
16321627
1633 if (sp_unit_selector_update_test(reinterpret_cast<SPUnitSelector *>(unit_selector->gobj()))) {
1634 return;
1635 }
1636
1637 update = true;1628 update = true;
16381629
1639 float y0 = getValuePx(y0_adj);1630 float y0 = getValuePx(y0_adj);
@@ -1709,10 +1700,6 @@
1709 return;1700 return;
1710 }1701 }
17111702
1712 if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) {
1713 return;
1714 }
1715
1716 update = true;1703 update = true;
17171704
1718 x0 = getValuePx(x0_adj);1705 x0 = getValuePx(x0_adj);
@@ -1743,10 +1730,6 @@
1743 return;1730 return;
1744 }1731 }
17451732
1746 if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) {
1747 return;
1748 }
1749
1750 update = true;1733 update = true;
17511734
1752 y0 = getValuePx(y0_adj);1735 y0 = getValuePx(y0_adj);
@@ -1803,10 +1786,6 @@
1803 return;1786 return;
1804 }1787 }
18051788
1806 if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) {
1807 return;
1808 }
1809
1810 update = true;1789 update = true;
18111790
1812 x0 = getValuePx(x0_adj);1791 x0 = getValuePx(x0_adj);
@@ -1905,9 +1884,9 @@
1905void Export::setValuePx( Gtk::Adjustment *adj, double val)1884void Export::setValuePx( Gtk::Adjustment *adj, double val)
1906#endif1885#endif
1907{1886{
1908 const SPUnit *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unit_selector->gobj()) );1887 const Unit unit = unit_selector->getUnit();
19091888
1910 setValue(adj, sp_pixels_get_units (val, *unit));1889 setValue(adj, Inkscape::Util::Quantity::convert(val, "px", unit));
19111890
1912 return;1891 return;
1913}1892}
@@ -1955,9 +1934,9 @@
1955#endif1934#endif
1956{1935{
1957 float value = getValue( adj);1936 float value = getValue( adj);
1958 const SPUnit *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unit_selector->gobj()));1937 const Unit unit = unit_selector->getUnit();
19591938
1960 return sp_units_get_pixels (value, *unit);1939 return Inkscape::Util::Quantity::convert(value, unit, "px");
1961} // end of sp_export_value_get_px()1940} // end of sp_export_value_get_px()
19621941
1963/**1942/**
19641943
=== modified file 'src/ui/dialog/export.h'
--- src/ui/dialog/export.h 2013-03-16 12:20:26 +0000
+++ src/ui/dialog/export.h 2013-08-06 18:46:25 +0000
@@ -172,6 +172,11 @@
172#endif172#endif
173173
174 /**174 /**
175 * Unit changed callback
176 */
177 void onUnitChanged();
178
179 /**
175 * Hide except selected callback180 * Hide except selected callback
176 */181 */
177 void onHideExceptSelected ();182 void onHideExceptSelected ();
@@ -330,7 +335,7 @@
330335
331 /* Unit selector widgets */336 /* Unit selector widgets */
332 Gtk::HBox unitbox;337 Gtk::HBox unitbox;
333 Gtk::Widget* unit_selector;338 Inkscape::UI::Widget::UnitMenu *unit_selector;
334 Gtk::Label units_label;339 Gtk::Label units_label;
335340
336 /* Filename widgets */341 /* Filename widgets */
@@ -365,6 +370,7 @@
365 sigc::connection selectChangedConn;370 sigc::connection selectChangedConn;
366 sigc::connection subselChangedConn;371 sigc::connection subselChangedConn;
367 sigc::connection selectModifiedConn;372 sigc::connection selectModifiedConn;
373 sigc::connection unitChangedConn;
368374
369};375};
370376
371377
=== modified file 'src/ui/dialog/guides.cpp'
--- src/ui/dialog/guides.cpp 2013-03-09 17:43:14 +0000
+++ src/ui/dialog/guides.cpp 2013-08-06 18:46:25 +0000
@@ -230,7 +230,7 @@
230 _unit_menu.setUnitType(UNIT_TYPE_LINEAR);230 _unit_menu.setUnitType(UNIT_TYPE_LINEAR);
231 _unit_menu.setUnit("px");231 _unit_menu.setUnit("px");
232 if (_desktop->namedview->doc_units) {232 if (_desktop->namedview->doc_units) {
233 _unit_menu.setUnit( sp_unit_get_abbreviation(_desktop->namedview->doc_units) );233 _unit_menu.setUnit( _desktop->namedview->doc_units->abbr );
234 }234 }
235 _spin_angle.setUnit(_angle_unit_status);235 _spin_angle.setUnit(_angle_unit_status);
236236
237237
=== modified file 'src/ui/dialog/inkscape-preferences.cpp'
--- src/ui/dialog/inkscape-preferences.cpp 2013-05-13 06:27:27 +0000
+++ src/ui/dialog/inkscape-preferences.cpp 2013-08-06 18:46:25 +0000
@@ -28,7 +28,7 @@
28#include "preferences.h"28#include "preferences.h"
29#include "verbs.h"29#include "verbs.h"
30#include "selcue.h"30#include "selcue.h"
31#include "unit-constants.h"31#include "util/units.h"
32#include <iostream>32#include <iostream>
33#include "enums.h"33#include "enums.h"
34#include "desktop-handles.h"34#include "desktop-handles.h"
@@ -1428,10 +1428,10 @@
1428 _("Automatically reload linked images when file is changed on disk"));1428 _("Automatically reload linked images when file is changed on disk"));
1429 _misc_bitmap_editor.init("/options/bitmapeditor/value", true);1429 _misc_bitmap_editor.init("/options/bitmapeditor/value", true);
1430 _page_bitmaps.add_line( false, _("_Bitmap editor:"), _misc_bitmap_editor, "", "", true);1430 _page_bitmaps.add_line( false, _("_Bitmap editor:"), _misc_bitmap_editor, "", "", true);
1431 _importexport_export_res.init("/dialogs/export/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false);1431 _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);
1432 _page_bitmaps.add_line( false, _("Default export _resolution:"), _importexport_export_res, _("dpi"),1432 _page_bitmaps.add_line( false, _("Default export _resolution:"), _importexport_export_res, _("dpi"),
1433 _("Default bitmap resolution (in dots per inch) in the Export dialog"), false);1433 _("Default bitmap resolution (in dots per inch) in the Export dialog"), false);
1434 _bitmap_copy_res.init("/options/createbitmap/resolution", 1.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false);1434 _bitmap_copy_res.init("/options/createbitmap/resolution", 1.0, 6000.0, 1.0, 1.0, Inkscape::Util::Quantity::convert(1, "in", "px"), true, false);
1435 _page_bitmaps.add_line( false, _("Resolution for Create Bitmap _Copy:"), _bitmap_copy_res, _("dpi"),1435 _page_bitmaps.add_line( false, _("Resolution for Create Bitmap _Copy:"), _bitmap_copy_res, _("dpi"),
1436 _("Resolution used by the Create Bitmap Copy command"), false);1436 _("Resolution used by the Create Bitmap Copy command"), false);
1437 {1437 {
@@ -1443,7 +1443,7 @@
1443 _bitmap_import_quality.init("/dialogs/import/quality", 1, 100, 1, 1, 100, true, false);1443 _bitmap_import_quality.init("/dialogs/import/quality", 1, 100, 1, 1, 100, true, false);
1444 _page_bitmaps.add_line( false, _("Bitmap import quality:"), _bitmap_import_quality, "%", "Bitmap import quality (jpeg only). 100 is best quality", false);1444 _page_bitmaps.add_line( false, _("Bitmap import quality:"), _bitmap_import_quality, "%", "Bitmap import quality (jpeg only). 100 is best quality", false);
1445 }1445 }
1446 _importexport_import_res.init("/dialogs/import/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false);1446 _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);
1447 _page_bitmaps.add_line( false, _("Default _import resolution:"), _importexport_import_res, _("dpi"),1447 _page_bitmaps.add_line( false, _("Default _import resolution:"), _importexport_import_res, _("dpi"),
1448 _("Default bitmap resolution (in dots per inch) for bitmap import"), false);1448 _("Default bitmap resolution (in dots per inch) for bitmap import"), false);
1449 _importexport_import_res_override.init(_("Override file resolution"), "/dialogs/import/forcexdpi", false);1449 _importexport_import_res_override.init(_("Override file resolution"), "/dialogs/import/forcexdpi", false);
14501450
=== modified file 'src/ui/dialog/print.cpp'
--- src/ui/dialog/print.cpp 2012-10-28 14:10:22 +0000
+++ src/ui/dialog/print.cpp 2013-08-06 18:46:25 +0000
@@ -26,7 +26,7 @@
26#include "ui/widget/rendering-options.h"26#include "ui/widget/rendering-options.h"
27#include "document.h"27#include "document.h"
2828
29#include "unit-constants.h"29#include "util/units.h"
30#include "helper/png-write.h"30#include "helper/png-write.h"
31#include "svg/svg-color.h"31#include "svg/svg-color.h"
32#include "io/sys.h"32#include "io/sys.h"
@@ -72,8 +72,8 @@
7272
73 sp_export_png_file(junk->_doc, tmp_png.c_str(), 0.0, 0.0,73 sp_export_png_file(junk->_doc, tmp_png.c_str(), 0.0, 0.0,
74 width, height,74 width, height,
75 (unsigned long)(width * dpi / PX_PER_IN),75 (unsigned long)(width * dpi / Inkscape::Util::Quantity::convert(1, "in", "px")),
76 (unsigned long)(height * dpi / PX_PER_IN),76 (unsigned long)(height * dpi / Inkscape::Util::Quantity::convert(1, "in", "px")),
77 dpi, dpi, bgcolor, NULL, NULL, true, NULL);77 dpi, dpi, bgcolor, NULL, NULL, true, NULL);
7878
79 // This doesn't seem to work:79 // This doesn't seem to work:
@@ -90,7 +90,7 @@
90 cairo_t *cr = gtk_print_context_get_cairo_context (context);90 cairo_t *cr = gtk_print_context_get_cairo_context (context);
91 cairo_matrix_t m;91 cairo_matrix_t m;
92 cairo_get_matrix(cr, &m);92 cairo_get_matrix(cr, &m);
93 cairo_scale(cr, PT_PER_IN / dpi, PT_PER_IN / dpi);93 cairo_scale(cr, Inkscape::Util::Quantity::convert(1, "in", "pt") / dpi, Inkscape::Util::Quantity::convert(1, "in", "pt") / dpi);
94 // FIXME: why is the origin offset??94 // FIXME: why is the origin offset??
95 cairo_set_source_surface(cr, png->cobj(), -16.0, -16.0);95 cairo_set_source_surface(cr, png->cobj(), -16.0, -16.0);
96 cairo_paint(cr);96 cairo_paint(cr);
@@ -195,8 +195,8 @@
195 // set up paper size to match the document size195 // set up paper size to match the document size
196 gtk_print_operation_set_unit (_printop, GTK_UNIT_POINTS);196 gtk_print_operation_set_unit (_printop, GTK_UNIT_POINTS);
197 GtkPageSetup *page_setup = gtk_page_setup_new();197 GtkPageSetup *page_setup = gtk_page_setup_new();
198 gdouble doc_width = _doc->getWidth() * PT_PER_PX;198 gdouble doc_width = _doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt");
199 gdouble doc_height = _doc->getHeight() * PT_PER_PX;199 gdouble doc_height = _doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt");
200 GtkPaperSize *paper_size;200 GtkPaperSize *paper_size;
201 if (doc_width > doc_height) {201 if (doc_width > doc_height) {
202 gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE);202 gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE);
203203
=== modified file 'src/ui/dialog/text-edit.cpp'
--- src/ui/dialog/text-edit.cpp 2013-04-28 18:38:55 +0000
+++ src/ui/dialog/text-edit.cpp 2013-08-06 18:46:25 +0000
@@ -58,7 +58,7 @@
58#include "widgets/font-selector.h"58#include "widgets/font-selector.h"
59#include <glibmm/i18n.h>59#include <glibmm/i18n.h>
60#include <glibmm/markup.h>60#include <glibmm/markup.h>
61#include "unit-constants.h"61#include "util/units.h"
62#include "sp-textpath.h"62#include "sp-textpath.h"
6363
64namespace Inkscape {64namespace Inkscape {
@@ -401,7 +401,7 @@
401401
402 Inkscape::Preferences *prefs = Inkscape::Preferences::get();402 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
403 int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);403 int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
404 double pt_size = sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit) * PT_PER_PX;404 double pt_size = sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit) * Inkscape::Util::Quantity::convert(1, "px", "pt");
405405
406 // Pango font size is in 1024ths of a point406 // Pango font size is in 1024ths of a point
407 // C++11: Glib::ustring size = std::to_string( pt_size * PANGO_SCALE );407 // C++11: Glib::ustring size = std::to_string( pt_size * PANGO_SCALE );
408408
=== modified file 'src/ui/tool/node.cpp'
--- src/ui/tool/node.cpp 2012-10-13 21:38:45 +0000
+++ src/ui/tool/node.cpp 2013-08-06 18:46:25 +0000
@@ -22,7 +22,6 @@
22#include "preferences.h"22#include "preferences.h"
23#include "snap.h"23#include "snap.h"
24#include "snap-preferences.h"24#include "snap-preferences.h"
25#include "sp-metrics.h"
26#include "sp-namedview.h"25#include "sp-namedview.h"
27#include "ui/control-manager.h"26#include "ui/control-manager.h"
28#include "ui/tool/control-point-selection.h"27#include "ui/tool/control-point-selection.h"
@@ -490,9 +489,13 @@
490 double angle = Geom::angle_between(Geom::Point(-1,0), position() - _parent->position());489 double angle = Geom::angle_between(Geom::Point(-1,0), position() - _parent->position());
491 angle += M_PI; // angle is (-M_PI...M_PI] - offset by +pi and scale to 0...360490 angle += M_PI; // angle is (-M_PI...M_PI] - offset by +pi and scale to 0...360
492 angle *= 360.0 / (2 * M_PI);491 angle *= 360.0 / (2 * M_PI);
493 GString *x = SP_PX_TO_METRIC_STRING(dist[Geom::X], _desktop->namedview->getDefaultMetric());492
494 GString *y = SP_PX_TO_METRIC_STRING(dist[Geom::Y], _desktop->namedview->getDefaultMetric());493 Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px");
495 GString *len = SP_PX_TO_METRIC_STRING(length(), _desktop->namedview->getDefaultMetric());494 Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px");
495 Inkscape::Util::Quantity len_q = Inkscape::Util::Quantity(length(), "px");
496 GString *x = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
497 GString *y = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
498 GString *len = g_string_new(len_q.string(*_desktop->namedview->doc_units).c_str());
496 Glib::ustring ret = format_tip(C_("Path handle tip",499 Glib::ustring ret = format_tip(C_("Path handle tip",
497 "Move handle by %s, %s; angle %.2f°, length %s"), x->str, y->str, angle, len->str);500 "Move handle by %s, %s; angle %.2f°, length %s"), x->str, y->str, angle, len->str);
498 g_string_free(x, TRUE);501 g_string_free(x, TRUE);
@@ -1294,8 +1297,11 @@
1294Glib::ustring Node::_getDragTip(GdkEventMotion */*event*/) const1297Glib::ustring Node::_getDragTip(GdkEventMotion */*event*/) const
1295{1298{
1296 Geom::Point dist = position() - _last_drag_origin();1299 Geom::Point dist = position() - _last_drag_origin();
1297 GString *x = SP_PX_TO_METRIC_STRING(dist[Geom::X], _desktop->namedview->getDefaultMetric());1300
1298 GString *y = SP_PX_TO_METRIC_STRING(dist[Geom::Y], _desktop->namedview->getDefaultMetric());1301 Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px");
1302 Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px");
1303 GString *x = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
1304 GString *y = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
1299 Glib::ustring ret = format_tip(C_("Path node tip", "Move node by %s, %s"),1305 Glib::ustring ret = format_tip(C_("Path node tip", "Move node by %s, %s"),
1300 x->str, y->str);1306 x->str, y->str);
1301 g_string_free(x, TRUE);1307 g_string_free(x, TRUE);
13021308
=== modified file 'src/ui/widget/Makefile_insert'
--- src/ui/widget/Makefile_insert 2013-01-08 12:06:44 +0000
+++ src/ui/widget/Makefile_insert 2013-08-06 18:46:25 +0000
@@ -79,5 +79,7 @@
79 ui/widget/tolerance-slider.cpp \79 ui/widget/tolerance-slider.cpp \
80 ui/widget/tolerance-slider.h \80 ui/widget/tolerance-slider.h \
81 ui/widget/unit-menu.cpp \81 ui/widget/unit-menu.cpp \
82 ui/widget/unit-menu.h82 ui/widget/unit-menu.h \
83 ui/widget/unit-tracker.h \
84 ui/widget/unit-tracker.cpp
8385
8486
=== modified file 'src/ui/widget/page-sizer.cpp'
--- src/ui/widget/page-sizer.cpp 2013-07-01 20:04:32 +0000
+++ src/ui/widget/page-sizer.cpp 2013-08-06 18:46:25 +0000
@@ -37,7 +37,7 @@
37#include "desktop.h"37#include "desktop.h"
38#include "helper/action.h"38#include "helper/action.h"
39#include "helper/action-context.h"39#include "helper/action-context.h"
40#include "helper/units.h"40#include "util/units.h"
41#include "inkscape.h"41#include "inkscape.h"
42#include "sp-namedview.h"42#include "sp-namedview.h"
43#include "sp-root.h"43#include "sp-root.h"
@@ -48,6 +48,7 @@
48#include "xml/repr.h"48#include "xml/repr.h"
4949
50using std::pair;50using std::pair;
51using Inkscape::Util::unit_table;
5152
52namespace Inkscape {53namespace Inkscape {
53namespace UI {54namespace UI {
@@ -96,7 +97,7 @@
96 char const * const name; //name97 char const * const name; //name
97 double const smaller; //lesser dimension98 double const smaller; //lesser dimension
98 double const larger; //greater dimension99 double const larger; //greater dimension
99 SPUnitId const unit; //units100 Glib::ustring const unit; //units
100};101};
101102
102// list of page formats that should be in landscape automatically103// list of page formats that should be in landscape automatically
@@ -114,31 +115,31 @@
114}115}
115116
116static PaperSizeRec const inkscape_papers[] = {117static PaperSizeRec const inkscape_papers[] = {
117 { "A4", 210, 297, SP_UNIT_MM },118 { "A4", 210, 297, "mm" },
118 { "US Letter", 8.5, 11, SP_UNIT_IN },119 { "US Letter", 8.5, 11, "in" },
119 { "US Legal", 8.5, 14, SP_UNIT_IN },120 { "US Legal", 8.5, 14, "in" },
120 { "US Executive", 7.25, 10.5, SP_UNIT_IN },121 { "US Executive", 7.25, 10.5, "in" },
121 { "A0", 841, 1189, SP_UNIT_MM },122 { "A0", 841, 1189, "mm" },
122 { "A1", 594, 841, SP_UNIT_MM },123 { "A1", 594, 841, "mm" },
123 { "A2", 420, 594, SP_UNIT_MM },124 { "A2", 420, 594, "mm" },
124 { "A3", 297, 420, SP_UNIT_MM },125 { "A3", 297, 420, "mm" },
125 { "A5", 148, 210, SP_UNIT_MM },126 { "A5", 148, 210, "mm" },
126 { "A6", 105, 148, SP_UNIT_MM },127 { "A6", 105, 148, "mm" },
127 { "A7", 74, 105, SP_UNIT_MM },128 { "A7", 74, 105, "mm" },
128 { "A8", 52, 74, SP_UNIT_MM },129 { "A8", 52, 74, "mm" },
129 { "A9", 37, 52, SP_UNIT_MM },130 { "A9", 37, 52, "mm" },
130 { "A10", 26, 37, SP_UNIT_MM },131 { "A10", 26, 37, "mm" },
131 { "B0", 1000, 1414, SP_UNIT_MM },132 { "B0", 1000, 1414, "mm" },
132 { "B1", 707, 1000, SP_UNIT_MM },133 { "B1", 707, 1000, "mm" },
133 { "B2", 500, 707, SP_UNIT_MM },134 { "B2", 500, 707, "mm" },
134 { "B3", 353, 500, SP_UNIT_MM },135 { "B3", 353, 500, "mm" },
135 { "B4", 250, 353, SP_UNIT_MM },136 { "B4", 250, 353, "mm" },
136 { "B5", 176, 250, SP_UNIT_MM },137 { "B5", 176, 250, "mm" },
137 { "B6", 125, 176, SP_UNIT_MM },138 { "B6", 125, 176, "mm" },
138 { "B7", 88, 125, SP_UNIT_MM },139 { "B7", 88, 125, "mm" },
139 { "B8", 62, 88, SP_UNIT_MM },140 { "B8", 62, 88, "mm" },
140 { "B9", 44, 62, SP_UNIT_MM },141 { "B9", 44, 62, "mm" },
141 { "B10", 31, 44, SP_UNIT_MM },142 { "B10", 31, 44, "mm" },
142143
143144
144145
@@ -150,63 +151,63 @@
150 don't know what D and E series are used for.151 don't know what D and E series are used for.
151 */152 */
152153
153 { "C0", 917, 1297, SP_UNIT_MM },154 { "C0", 917, 1297, "mm" },
154 { "C1", 648, 917, SP_UNIT_MM },155 { "C1", 648, 917, "mm" },
155 { "C2", 458, 648, SP_UNIT_MM },156 { "C2", 458, 648, "mm" },
156 { "C3", 324, 458, SP_UNIT_MM },157 { "C3", 324, 458, "mm" },
157 { "C4", 229, 324, SP_UNIT_MM },158 { "C4", 229, 324, "mm" },
158 { "C5", 162, 229, SP_UNIT_MM },159 { "C5", 162, 229, "mm" },
159 { "C6", 114, 162, SP_UNIT_MM },160 { "C6", 114, 162, "mm" },
160 { "C7", 81, 114, SP_UNIT_MM },161 { "C7", 81, 114, "mm" },
161 { "C8", 57, 81, SP_UNIT_MM },162 { "C8", 57, 81, "mm" },
162 { "C9", 40, 57, SP_UNIT_MM },163 { "C9", 40, 57, "mm" },
163 { "C10", 28, 40, SP_UNIT_MM },164 { "C10", 28, 40, "mm" },
164 { "D1", 545, 771, SP_UNIT_MM },165 { "D1", 545, 771, "mm" },
165 { "D2", 385, 545, SP_UNIT_MM },166 { "D2", 385, 545, "mm" },
166 { "D3", 272, 385, SP_UNIT_MM },167 { "D3", 272, 385, "mm" },
167 { "D4", 192, 272, SP_UNIT_MM },168 { "D4", 192, 272, "mm" },
168 { "D5", 136, 192, SP_UNIT_MM },169 { "D5", 136, 192, "mm" },
169 { "D6", 96, 136, SP_UNIT_MM },170 { "D6", 96, 136, "mm" },
170 { "D7", 68, 96, SP_UNIT_MM },171 { "D7", 68, 96, "mm" },
171 { "E3", 400, 560, SP_UNIT_MM },172 { "E3", 400, 560, "mm" },
172 { "E4", 280, 400, SP_UNIT_MM },173 { "E4", 280, 400, "mm" },
173 { "E5", 200, 280, SP_UNIT_MM },174 { "E5", 200, 280, "mm" },
174 { "E6", 140, 200, SP_UNIT_MM },175 { "E6", 140, 200, "mm" },
175//#endif176//#endif
176177
177178
178179
179 { "CSE", 462, 649, SP_UNIT_PT },180 { "CSE", 462, 649, "pt" },
180 { "US #10 Envelope", 4.125, 9.5, SP_UNIT_IN },181 { "US #10 Envelope", 4.125, 9.5, "in" },
181 /* See http://www.hbp.com/content/PCR_envelopes.cfm for a much larger list of US envelope182 /* See http://www.hbp.com/content/PCR_envelopes.cfm for a much larger list of US envelope
182 sizes. */183 sizes. */
183 { "DL Envelope", 110, 220, SP_UNIT_MM },184 { "DL Envelope", 110, 220, "mm" },
184 { "Ledger/Tabloid", 11, 17, SP_UNIT_IN },185 { "Ledger/Tabloid", 11, 17, "in" },
185 /* Note that `Folio' (used in QPrinter/KPrinter) is deliberately absent from this list, as it186 /* Note that `Folio' (used in QPrinter/KPrinter) is deliberately absent from this list, as it
186 means different sizes to different people: different people may expect the width to be187 means different sizes to different people: different people may expect the width to be
187 either 8, 8.25 or 8.5 inches, and the height to be either 13 or 13.5 inches, even188 either 8, 8.25 or 8.5 inches, and the height to be either 13 or 13.5 inches, even
188 restricting our interpretation to foolscap folio. If you wish to introduce a folio-like189 restricting our interpretation to foolscap folio. If you wish to introduce a folio-like
189 page size to the list, then please consider using a name more specific than just `Folio' or190 page size to the list, then please consider using a name more specific than just `Folio' or
190 `Foolscap Folio'. */191 `Foolscap Folio'. */
191 { "Banner 468x60", 60, 468, SP_UNIT_PX },192 { "Banner 468x60", 60, 468, "px" },
192 { "Icon 16x16", 16, 16, SP_UNIT_PX },193 { "Icon 16x16", 16, 16, "px" },
193 { "Icon 32x32", 32, 32, SP_UNIT_PX },194 { "Icon 32x32", 32, 32, "px" },
194 { "Icon 48x48", 48, 48, SP_UNIT_PX },195 { "Icon 48x48", 48, 48, "px" },
195 /* business cards */196 /* business cards */
196 { "Business Card (ISO 7810)", 53.98, 85.60, SP_UNIT_MM },197 { "Business Card (ISO 7810)", 53.98, 85.60, "mm" },
197 { "Business Card (US)", 2, 3.5, SP_UNIT_IN },198 { "Business Card (US)", 2, 3.5, "in" },
198 { "Business Card (Europe)", 55, 85, SP_UNIT_MM },199 { "Business Card (Europe)", 55, 85, "mm" },
199 { "Business Card (Aus/NZ)", 55, 90, SP_UNIT_MM },200 { "Business Card (Aus/NZ)", 55, 90, "mm" },
200201
201 // Start Arch Series List202 // Start Arch Series List
202203
203204
204 { "Arch A", 9, 12, SP_UNIT_IN }, // 229 x 305 mm205 { "Arch A", 9, 12, "in" }, // 229 x 305 mm
205 { "Arch B", 12, 18, SP_UNIT_IN }, // 305 x 457 mm206 { "Arch B", 12, 18, "in" }, // 305 x 457 mm
206 { "Arch C", 18, 24, SP_UNIT_IN }, // 457 x 610 mm207 { "Arch C", 18, 24, "in" }, // 457 x 610 mm
207 { "Arch D", 24, 36, SP_UNIT_IN }, // 610 x 914 mm208 { "Arch D", 24, 36, "in" }, // 610 x 914 mm
208 { "Arch E", 36, 48, SP_UNIT_IN }, // 914 x 1219 mm209 { "Arch E", 36, 48, "in" }, // 914 x 1219 mm
209 { "Arch E1", 30, 42, SP_UNIT_IN }, // 762 x 1067 mm210 { "Arch E1", 30, 42, "in" }, // 762 x 1067 mm
210211
211 /*212 /*
212 * The above list of Arch sizes were taken from the following site:213 * The above list of Arch sizes were taken from the following site:
@@ -217,7 +218,7 @@
217 * September 2009 - DAK218 * September 2009 - DAK
218 */219 */
219220
220 { NULL, 0, 0, SP_UNIT_PX },221 { NULL, 0, 0, "px" },
221};222};
222223
223224
@@ -226,10 +227,6 @@
226//# P A G E S I Z E R227//# P A G E S I Z E R
227//########################################################################228//########################################################################
228229
229//The default unit for this widget and its calculations
230static const SPUnit _px_unit = sp_unit_get_by_id (SP_UNIT_PX);
231
232
233/**230/**
234 * Constructor231 * Constructor
235 */232 */
@@ -280,13 +277,8 @@
280 char formatBuf[80];277 char formatBuf[80];
281 snprintf(formatBuf, 79, "%0.1f x %0.1f", p->smaller, p->larger);278 snprintf(formatBuf, 79, "%0.1f x %0.1f", p->smaller, p->larger);
282 Glib::ustring desc = formatBuf;279 Glib::ustring desc = formatBuf;
283 if (p->unit == SP_UNIT_IN)280 desc.append(" " + p->unit);
284 desc.append(" in");281 PaperSize paper(name, p->smaller, p->larger, unit_table.getUnit(p->unit));
285 else if (p->unit == SP_UNIT_MM)
286 desc.append(" mm");
287 else if (p->unit == SP_UNIT_PX)
288 desc.append(" px");
289 PaperSize paper(name, p->smaller, p->larger, p->unit);
290 _paperSizeTable[name] = paper;282 _paperSizeTable[name] = paper;
291 Gtk::TreeModel::Row row = *(_paperSizeListStore->append());283 Gtk::TreeModel::Row row = *(_paperSizeListStore->append());
292 row[_paperSizeListColumns.nameColumn] = name;284 row[_paperSizeListColumns.nameColumn] = name;
@@ -320,9 +312,9 @@
320 SPNamedView *nv = sp_desktop_namedview(dt);312 SPNamedView *nv = sp_desktop_namedview(dt);
321 _wr.setUpdating (true);313 _wr.setUpdating (true);
322 if (nv->units) {314 if (nv->units) {
323 _dimensionUnits.setUnit(nv->units);315 _dimensionUnits.setUnit(nv->units->abbr);
324 } else if (nv->doc_units) {316 } else if (nv->doc_units) {
325 _dimensionUnits.setUnit(nv->doc_units);317 _dimensionUnits.setUnit(nv->doc_units->abbr);
326 }318 }
327 _wr.setUpdating (false);319 _wr.setUpdating (false);
328 320
@@ -484,8 +476,8 @@
484 if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) {476 if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) {
485 SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP);477 SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP);
486 double const old_height = doc->getHeight();478 double const old_height = doc->getHeight();
487 doc->setWidth (w, &_px_unit);479 doc->setWidth (Inkscape::Util::Quantity(w, "px"));
488 doc->setHeight (h, &_px_unit);480 doc->setHeight (Inkscape::Util::Quantity(h, "px"));
489 // The origin for the user is in the lower left corner; this point should remain stationary when481 // The origin for the user is in the lower left corner; this point should remain stationary when
490 // changing the page size. The SVG's origin however is in the upper left corner, so we must compensate for this482 // changing the page size. The SVG's origin however is in the upper left corner, so we must compensate for this
491 Geom::Translate const vert_offset(Geom::Point(0, (old_height - h)));483 Geom::Translate const vert_offset(Geom::Point(0, (old_height - h)));
@@ -569,9 +561,9 @@
569 for (iter = _paperSizeTable.begin() ;561 for (iter = _paperSizeTable.begin() ;
570 iter != _paperSizeTable.end() ; ++iter) {562 iter != _paperSizeTable.end() ; ++iter) {
571 PaperSize paper = iter->second;563 PaperSize paper = iter->second;
572 SPUnit const &i_unit = sp_unit_get_by_id(paper.unit);564 Inkscape::Util::Unit const &i_unit = paper.unit;
573 double smallX = sp_units_get_pixels(paper.smaller, i_unit);565 double smallX = Inkscape::Util::Quantity::convert(paper.smaller, i_unit, "px");
574 double largeX = sp_units_get_pixels(paper.larger, i_unit);566 double largeX = Inkscape::Util::Quantity::convert(paper.larger, i_unit, "px");
575567
576 g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end());568 g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end());
577569
@@ -662,9 +654,8 @@
662 _landscape = _landscapeButton.get_active();654 _landscape = _landscapeButton.get_active();
663 }655 }
664656
665 SPUnit const &src_unit = sp_unit_get_by_id (paper.unit);657 w = Inkscape::Util::Quantity::convert(w, paper.unit, "px");
666 sp_convert_distance (&w, &src_unit, &_px_unit);658 h = Inkscape::Util::Quantity::convert(h, paper.unit, "px");
667 sp_convert_distance (&h, &src_unit, &_px_unit);
668659
669 if (_landscape)660 if (_landscape)
670 setDim (h, w, false);661 setDim (h, w, false);
671662
=== modified file 'src/ui/widget/page-sizer.h'
--- src/ui/widget/page-sizer.h 2012-12-16 11:57:38 +0000
+++ src/ui/widget/page-sizer.h 2013-08-06 18:46:25 +0000
@@ -18,7 +18,7 @@
18#include "ui/widget/registered-widget.h"18#include "ui/widget/registered-widget.h"
19#include <sigc++/sigc++.h>19#include <sigc++/sigc++.h>
2020
21#include "helper/units.h"21#include "util/units.h"
2222
23#include <gtkmm/alignment.h>23#include <gtkmm/alignment.h>
24#include <gtkmm/expander.h>24#include <gtkmm/expander.h>
@@ -64,7 +64,7 @@
64 PaperSize(const Glib::ustring &nameArg,64 PaperSize(const Glib::ustring &nameArg,
65 double smallerArg,65 double smallerArg,
66 double largerArg,66 double largerArg,
67 SPUnitId unitArg)67 Inkscape::Util::Unit unitArg)
68 {68 {
69 name = nameArg;69 name = nameArg;
70 smaller = smallerArg;70 smaller = smallerArg;
@@ -108,7 +108,7 @@
108 /**108 /**
109 * The units (px, pt, mm, etc) of this specification109 * The units (px, pt, mm, etc) of this specification
110 */ 110 */
111 SPUnitId unit;111 Inkscape::Util::Unit unit;
112112
113private:113private:
114114
@@ -117,7 +117,7 @@
117 name = "";117 name = "";
118 smaller = 0.0;118 smaller = 0.0;
119 larger = 0.0;119 larger = 0.0;
120 unit = SP_UNIT_PX;120 unit = unit_table.getUnit("px");
121 }121 }
122122
123 void assign(const PaperSize &other)123 void assign(const PaperSize &other)
124124
=== modified file 'src/ui/widget/registered-widget.cpp'
--- src/ui/widget/registered-widget.cpp 2012-04-28 15:49:30 +0000
+++ src/ui/widget/registered-widget.cpp 2013-08-06 18:46:25 +0000
@@ -27,7 +27,6 @@
27#include "ui/widget/random.h"27#include "ui/widget/random.h"
28#include "widgets/spinbutton-events.h"28#include "widgets/spinbutton-events.h"
2929
30#include "helper/units.h"
31#include "xml/repr.h"30#include "xml/repr.h"
32#include "svg/svg-color.h"31#include "svg/svg-color.h"
33#include "svg/stringstream.h"32#include "svg/stringstream.h"
@@ -118,9 +117,9 @@
118}117}
119118
120void119void
121RegisteredUnitMenu::setUnit (const SPUnit* unit)120RegisteredUnitMenu::setUnit (Glib::ustring unit)
122{121{
123 getUnitMenu()->setUnit (sp_unit_get_abbreviation (unit));122 getUnitMenu()->setUnit(unit);
124}123}
125124
126void125void
127126
=== modified file 'src/ui/widget/registered-widget.h'
--- src/ui/widget/registered-widget.h 2013-08-03 20:45:01 +0000
+++ src/ui/widget/registered-widget.h 2013-08-06 18:46:25 +0000
@@ -32,7 +32,6 @@
3232
33#include <gtkmm/checkbutton.h>33#include <gtkmm/checkbutton.h>
3434
35struct SPUnit;
36class SPDocument;35class SPDocument;
3736
38namespace Gtk {37namespace Gtk {
@@ -167,7 +166,7 @@
167 Inkscape::XML::Node* repr_in = NULL,166 Inkscape::XML::Node* repr_in = NULL,
168 SPDocument *doc_in = NULL );167 SPDocument *doc_in = NULL );
169168
170 void setUnit (const SPUnit*);169 void setUnit (const Glib::ustring);
171 Unit getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); };170 Unit getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); };
172 UnitMenu* getUnitMenu() const { return static_cast<UnitMenu*>(_widget); };171 UnitMenu* getUnitMenu() const { return static_cast<UnitMenu*>(_widget); };
173 sigc::connection _changed_connection;172 sigc::connection _changed_connection;
174173
=== modified file 'src/ui/widget/rendering-options.cpp'
--- src/ui/widget/rendering-options.cpp 2013-03-25 17:42:31 +0000
+++ src/ui/widget/rendering-options.cpp 2013-08-06 18:46:25 +0000
@@ -13,7 +13,7 @@
13#endif13#endif
1414
15#include "rendering-options.h"15#include "rendering-options.h"
16#include "unit-constants.h"16#include "util/units.h"
17#include <glibmm/i18n.h>17#include <glibmm/i18n.h>
1818
19namespace Inkscape {19namespace Inkscape {
@@ -59,8 +59,8 @@
59 _radio_bitmap.signal_toggled().connect(sigc::mem_fun(*this, &RenderingOptions::_toggled));59 _radio_bitmap.signal_toggled().connect(sigc::mem_fun(*this, &RenderingOptions::_toggled));
6060
61 // configure default DPI61 // configure default DPI
62 _dpi.setRange(PT_PER_IN,2400.0);62 _dpi.setRange(Inkscape::Util::Quantity::convert(1, "in", "pt"),2400.0);
63 _dpi.setValue(PT_PER_IN);63 _dpi.setValue(Inkscape::Util::Quantity::convert(1, "in", "pt"));
64 _dpi.setIncrements(1.0,10.0);64 _dpi.setIncrements(1.0,10.0);
65 _dpi.setDigits(0);65 _dpi.setDigits(0);
66 _dpi.update();66 _dpi.update();
6767
=== modified file 'src/ui/widget/scalar-unit.cpp'
--- src/ui/widget/scalar-unit.cpp 2011-10-27 04:55:51 +0000
+++ src/ui/widget/scalar-unit.cpp 2013-08-06 18:46:25 +0000
@@ -16,6 +16,8 @@
16#include "scalar-unit.h"16#include "scalar-unit.h"
17#include "spinbutton.h"17#include "spinbutton.h"
1818
19using Inkscape::Util::unit_table;
20
19namespace Inkscape {21namespace Inkscape {
20namespace UI {22namespace UI {
21namespace Widget {23namespace Widget {
@@ -226,9 +228,8 @@
226 Glib::ustring abbr = _unit_menu->getUnitAbbr();228 Glib::ustring abbr = _unit_menu->getUnitAbbr();
227 _suffix->set_label(abbr);229 _suffix->set_label(abbr);
228230
229 Inkscape::Util::UnitTable &table = _unit_menu->getUnitTable();231 Inkscape::Util::Unit new_unit = (unit_table.getUnit(abbr));
230 Inkscape::Util::Unit new_unit = (table.getUnit(abbr));232 Inkscape::Util::Unit old_unit = (unit_table.getUnit(lastUnits));
231 Inkscape::Util::Unit old_unit = (table.getUnit(lastUnits));
232233
233 double convertedVal = 0;234 double convertedVal = 0;
234 if (old_unit.type == UNIT_TYPE_DIMENSIONLESS && new_unit.type == UNIT_TYPE_LINEAR) {235 if (old_unit.type == UNIT_TYPE_DIMENSIONLESS && new_unit.type == UNIT_TYPE_LINEAR) {
235236
=== modified file 'src/ui/widget/selected-style.cpp'
--- src/ui/widget/selected-style.cpp 2013-03-09 13:24:32 +0000
+++ src/ui/widget/selected-style.cpp 2013-08-06 18:46:25 +0000
@@ -50,6 +50,9 @@
50#include "pixmaps/cursor-adj-a.xpm"50#include "pixmaps/cursor-adj-a.xpm"
51#include "sp-cursor.h"51#include "sp-cursor.h"
52#include "gradient-chemistry.h"52#include "gradient-chemistry.h"
53#include "util/units.h"
54
55using Inkscape::Util::unit_table;
5356
54static gdouble const _sw_presets[] = { 32 , 16 , 10 , 8 , 6 , 4 , 3 , 2 , 1.5 , 1 , 0.75 , 0.5 , 0.25 , 0.1 };57static gdouble const _sw_presets[] = { 32 , 16 , 10 , 8 , 6 , 4 , 3 , 2 , 1.5 , 1 , 0.75 , 0.5 , 0.25 , 0.1 };
55static 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"};58static 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"};
@@ -306,15 +309,17 @@
306 {309 {
307 int row = 0;310 int row = 0;
308311
309 // List of units should match with Fill/Stroke dialog stroke style width list312 Inkscape::Util::UnitTable::UnitMap m = unit_table.units(Inkscape::Util::UNIT_TYPE_LINEAR);
310 for (GSList *l = sp_unit_get_list(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); l != NULL; l = l->next) {313 Inkscape::Util::UnitTable::UnitMap::iterator iter = m.begin();
311 SPUnit const *u = static_cast<SPUnit*>(l->data);314 while(iter != m.end()) {
312 Gtk::RadioMenuItem *mi = Gtk::manage(new Gtk::RadioMenuItem(_sw_group));315 Gtk::RadioMenuItem *mi = Gtk::manage(new Gtk::RadioMenuItem(_sw_group));
313 mi->add(*(new Gtk::Label(u->abbr, 0.0, 0.5)));316 mi->add(*(new Gtk::Label((*iter).first, 0.0, 0.5)));
314 _unit_mis = g_slist_append(_unit_mis, mi);317 _unit_mis = g_slist_append(_unit_mis, mi);
315 mi->signal_activate().connect(sigc::bind<SPUnitId>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u->unit_id));318 Inkscape::Util::Unit const *u = new Inkscape::Util::Unit(unit_table.getUnit(iter->first));
319 mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), *u));
316 _popup_sw.attach(*mi, 0,1, row, row+1);320 _popup_sw.attach(*mi, 0,1, row, row+1);
317 row++;321 row++;
322 ++iter;
318 }323 }
319324
320 _popup_sw.attach(*(new Gtk::SeparatorMenuItem()), 0,1, row, row+1);325 _popup_sw.attach(*(new Gtk::SeparatorMenuItem()), 0,1, row, row+1);
@@ -476,13 +481,13 @@
476 this )481 this )
477 ));482 ));
478483
479 _sw_unit = const_cast<SPUnit*>(sp_desktop_namedview(desktop)->doc_units);
The diff has been truncated for viewing.