summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/Makefile_insert3
-rw-r--r--src/arc-context.cpp7
-rw-r--r--src/box3d-context.cpp1
-rw-r--r--src/desktop-events.cpp3
-rw-r--r--src/desktop.cpp1
-rw-r--r--src/display/canvas-axonomgrid.cpp101
-rw-r--r--src/display/canvas-grid.cpp129
-rw-r--r--src/display/canvas-grid.h6
-rw-r--r--src/document.cpp45
-rw-r--r--src/document.h10
-rw-r--r--src/doxygen-main.cpp4
-rw-r--r--src/extension/internal/cairo-render-context.cpp5
-rw-r--r--src/extension/internal/cairo-renderer-pdf-out.cpp4
-rw-r--r--src/extension/internal/cairo-renderer.cpp18
-rw-r--r--src/extension/internal/emf-win32-inout.cpp14
-rw-r--r--src/extension/internal/emf-win32-print.cpp73
-rw-r--r--src/extension/internal/gdkpixbuf-input.cpp4
-rw-r--r--src/extension/internal/latex-pstricks.cpp6
-rw-r--r--src/extension/internal/latex-text-renderer.cpp4
-rw-r--r--src/extension/internal/pdfinput/pdf-parser.cpp8
-rw-r--r--src/extension/internal/pdfinput/svg-builder.cpp4
-rw-r--r--src/flood-context.cpp1
-rw-r--r--src/flood-context.h2
-rw-r--r--src/helper/Makefile_insert12
-rw-r--r--src/helper/pixbuf-ops.cpp4
-rw-r--r--src/helper/unit-menu.cpp360
-rw-r--r--src/helper/unit-menu.h60
-rw-r--r--src/helper/unit-tracker.cpp267
-rw-r--r--src/helper/unit-tracker.h75
-rw-r--r--src/helper/units-test.h90
-rw-r--r--src/helper/units.cpp261
-rw-r--r--src/helper/units.h146
-rw-r--r--src/live_effects/lpe-path_length.cpp6
-rw-r--r--src/live_effects/lpe-ruler.cpp8
-rw-r--r--src/live_effects/parameter/unit.cpp24
-rw-r--r--src/live_effects/parameter/unit.h15
-rw-r--r--src/lpe-tool-context.cpp30
-rw-r--r--src/lpe-tool-context.h1
-rw-r--r--src/main.cpp11
-rw-r--r--src/measure-context.cpp21
-rw-r--r--src/pen-context.cpp13
-rw-r--r--src/preferences.cpp4
-rw-r--r--src/rect-context.cpp7
-rw-r--r--src/selection-chemistry.cpp15
-rw-r--r--src/seltrans.cpp13
-rw-r--r--src/snap-preferences.h1
-rw-r--r--src/sp-guide.cpp9
-rw-r--r--src/sp-metric.h28
-rw-r--r--src/sp-metrics.cpp120
-rw-r--r--src/sp-metrics.h20
-rw-r--r--src/sp-namedview.cpp42
-rw-r--r--src/sp-namedview.h17
-rw-r--r--src/sp-text.cpp5
-rw-r--r--src/spiral-context.cpp4
-rw-r--r--src/star-context.cpp4
-rw-r--r--src/style.cpp32
-rw-r--r--src/svg/svg-length.cpp16
-rw-r--r--src/text-context.cpp7
-rw-r--r--src/text-editing.cpp12
-rw-r--r--src/ui/CMakeLists.txt2
-rw-r--r--src/ui/clipboard.cpp8
-rw-r--r--src/ui/dialog/clonetiler.cpp77
-rw-r--r--src/ui/dialog/clonetiler.h20
-rw-r--r--src/ui/dialog/document-properties.cpp3
-rw-r--r--src/ui/dialog/export.cpp77
-rw-r--r--src/ui/dialog/export.h8
-rw-r--r--src/ui/dialog/guides.cpp2
-rw-r--r--src/ui/dialog/inkscape-preferences.cpp8
-rw-r--r--src/ui/dialog/print.cpp12
-rw-r--r--src/ui/dialog/text-edit.cpp4
-rw-r--r--src/ui/tool/node.cpp18
-rw-r--r--src/ui/widget/Makefile_insert4
-rw-r--r--src/ui/widget/page-sizer.cpp169
-rw-r--r--src/ui/widget/page-sizer.h8
-rw-r--r--src/ui/widget/registered-widget.cpp5
-rw-r--r--src/ui/widget/registered-widget.h3
-rw-r--r--src/ui/widget/rendering-options.cpp6
-rw-r--r--src/ui/widget/scalar-unit.cpp7
-rw-r--r--src/ui/widget/selected-style.cpp29
-rw-r--r--src/ui/widget/selected-style.h11
-rw-r--r--src/ui/widget/style-swatch.cpp6
-rw-r--r--src/ui/widget/style-swatch.h8
-rw-r--r--src/ui/widget/unit-menu.cpp16
-rw-r--r--src/ui/widget/unit-menu.h3
-rw-r--r--src/ui/widget/unit-tracker.cpp263
-rw-r--r--src/ui/widget/unit-tracker.h74
-rw-r--r--src/unit-constants.h47
-rw-r--r--src/util/expression-evaluator.cpp4
-rw-r--r--src/util/units.cpp175
-rw-r--r--src/util/units.h67
-rw-r--r--src/widgets/arc-toolbar.cpp8
-rw-r--r--src/widgets/box3d-toolbar.cpp11
-rw-r--r--src/widgets/calligraphy-toolbar.cpp20
-rw-r--r--src/widgets/connector-toolbar.cpp10
-rw-r--r--src/widgets/desktop-widget.cpp28
-rw-r--r--src/widgets/dropper-toolbar.cpp4
-rw-r--r--src/widgets/eraser-toolbar.cpp6
-rw-r--r--src/widgets/font-selector.cpp1
-rw-r--r--src/widgets/gradient-toolbar.cpp2
-rw-r--r--src/widgets/lpe-toolbar.cpp19
-rw-r--r--src/widgets/measure-toolbar.cpp19
-rw-r--r--src/widgets/mesh-toolbar.cpp4
-rw-r--r--src/widgets/node-toolbar.cpp35
-rw-r--r--src/widgets/paintbucket-toolbar.cpp21
-rw-r--r--src/widgets/pencil-toolbar.cpp7
-rw-r--r--src/widgets/rect-toolbar.cpp36
-rw-r--r--src/widgets/ruler.cpp32
-rw-r--r--src/widgets/ruler.h11
-rw-r--r--src/widgets/select-toolbar.cpp56
-rw-r--r--src/widgets/spiral-toolbar.cpp10
-rw-r--r--src/widgets/spray-toolbar.cpp16
-rw-r--r--src/widgets/spw-utilities.cpp46
-rw-r--r--src/widgets/spw-utilities.h5
-rw-r--r--src/widgets/star-toolbar.cpp12
-rw-r--r--src/widgets/stroke-style.cpp123
-rw-r--r--src/widgets/stroke-style.h24
-rw-r--r--src/widgets/text-toolbar.cpp15
-rw-r--r--src/widgets/toolbox.cpp8
-rw-r--r--src/widgets/toolbox.h1
-rw-r--r--src/widgets/tweak-toolbar.cpp10
-rw-r--r--src/widgets/zoom-toolbar.cpp4
122 files changed, 1403 insertions, 2562 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1d27eaef1..4f7592119 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -46,7 +46,6 @@ set(sp_SRC
sp-mesh-patch.cpp
sp-mesh-row.cpp
sp-metadata.cpp
- sp-metrics.cpp
sp-missing-glyph.cpp
sp-namedview.cpp
sp-object-group.cpp
@@ -136,8 +135,6 @@ set(sp_SRC
sp-mesh-row-fns.h
sp-mesh-row.h
sp-metadata.h
- sp-metric.h
- sp-metrics.h
sp-missing-glyph.h
sp-namedview.h
sp-object-group.h
@@ -484,7 +481,6 @@ set(inkscape_SRC
unclump.h
undo-stack-observer.h
unicoderange.h
- unit-constants.h
uri-references.h
uri.h
vanishing-point.h
diff --git a/src/Makefile_insert b/src/Makefile_insert
index 8fc00b2f6..0cc4e7460 100644
--- a/src/Makefile_insert
+++ b/src/Makefile_insert
@@ -198,8 +198,6 @@ ink_common_sources += \
sp-mesh-patch.cpp sp-mesh-patch.h \
sp-mesh-row-fns.h \
sp-mesh-row.cpp sp-mesh-row.h \
- sp-metric.h \
- sp-metrics.cpp sp-metrics.h \
sp-missing-glyph.cpp sp-missing-glyph.h \
sp-namedview.cpp sp-namedview.h \
sp-object.cpp sp-object.h \
@@ -252,7 +250,6 @@ ink_common_sources += \
unclump.cpp unclump.h \
undo-stack-observer.h \
unicoderange.cpp unicoderange.h \
- unit-constants.h \
uri.cpp uri.h \
uri-references.cpp uri-references.h \
vanishing-point.cpp vanishing-point.h \
diff --git a/src/arc-context.cpp b/src/arc-context.cpp
index 34e4bbeab..115f45493 100644
--- a/src/arc-context.cpp
+++ b/src/arc-context.cpp
@@ -32,7 +32,6 @@
#include "desktop-handles.h"
#include "snap.h"
#include "pixmaps/cursor-ellipse.xpm"
-#include "sp-metrics.h"
#include "xml/repr.h"
#include "xml/node-event-vector.h"
#include "preferences.h"
@@ -450,8 +449,10 @@ static void sp_arc_drag(SPArcContext *ac, Geom::Point pt, guint state)
double rdimx = r.dimensions()[Geom::X];
double rdimy = r.dimensions()[Geom::Y];
- GString *xs = SP_PX_TO_METRIC_STRING(rdimx, desktop->namedview->getDefaultMetric());
- GString *ys = SP_PX_TO_METRIC_STRING(rdimy, desktop->namedview->getDefaultMetric());
+ Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px");
+ Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px");
+ GString *xs = g_string_new(rdimx_q.string(*desktop->namedview->doc_units).c_str());
+ GString *ys = g_string_new(rdimy_q.string(*desktop->namedview->doc_units).c_str());
if (state & GDK_CONTROL_MASK) {
int ratio_x, ratio_y;
if (fabs (rdimx) > fabs (rdimy)) {
diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp
index a55aba00d..7491520de 100644
--- a/src/box3d-context.cpp
+++ b/src/box3d-context.cpp
@@ -35,7 +35,6 @@
#include "pixmaps/cursor-3dbox.xpm"
#include "box3d.h"
#include "box3d-context.h"
-#include "sp-metrics.h"
#include <glibmm/i18n.h>
#include "xml/repr.h"
#include "xml/node-event-vector.h"
diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp
index 217187553..5cb26abc0 100644
--- a/src/desktop-events.cpp
+++ b/src/desktop-events.cpp
@@ -34,14 +34,11 @@
#include "document-undo.h"
#include "event-context.h"
#include "helper/action.h"
-#include "helper/unit-menu.h"
-#include "helper/units.h"
#include "message-context.h"
#include "preferences.h"
#include "snap.h"
#include "display/sp-canvas.h"
#include "sp-guide.h"
-#include "sp-metrics.h"
#include "sp-namedview.h"
#include "tools-switch.h"
#include "verbs.h"
diff --git a/src/desktop.cpp b/src/desktop.cpp
index ce740f76f..13e339abe 100644
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
@@ -54,7 +54,6 @@
#include "document.h"
#include "event-log.h"
#include "helper/action-context.h"
-#include "helper/units.h"
#include "interface.h"
#include "inkscape-private.h"
#include "layer-fns.h"
diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp
index 1eadd3fd2..f7a7cb39a 100644
--- a/src/display/canvas-axonomgrid.cpp
+++ b/src/display/canvas-axonomgrid.cpp
@@ -51,8 +51,9 @@
#include "2geom/angle.h"
#include "util/mathfns.h"
#include "round.h"
-#include "helper/units.h"
+#include "util/units.h"
+using Inkscape::Util::unit_table;
enum Dim3 { X=0, Y, Z };
@@ -160,15 +161,15 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r
: CanvasGrid(nv, in_repr, in_doc, GRID_AXONOMETRIC)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gridunit = sp_unit_get_by_abbreviation( prefs->getString("/options/grids/axonom/units").data() );
+ gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/axonom/units")));
if (!gridunit)
- gridunit = &sp_unit_get_by_id(SP_UNIT_PX);
- origin[Geom::X] = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/origin_x", 0.0), *gridunit );
- origin[Geom::Y] = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/origin_y", 0.0), *gridunit );
+ gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px"));
+ origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_x", 0.0), *gridunit, "px");
+ origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_y", 0.0), *gridunit, "px");
color = prefs->getInt("/options/grids/axonom/color", 0x0000ff20);
empcolor = prefs->getInt("/options/grids/axonom/empcolor", 0x0000ff40);
empspacing = prefs->getInt("/options/grids/axonom/empspacing", 5);
- lengthy = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), *gridunit );
+ lengthy = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), *gridunit, "px");
angle_deg[X] = prefs->getDouble("/options/grids/axonom/angle_x", 30.0);
angle_deg[Z] = prefs->getDouble("/options/grids/axonom/angle_z", 30.0);
angle_deg[Y] = 0;
@@ -188,63 +189,6 @@ CanvasAxonomGrid::~CanvasAxonomGrid ()
if (snapper) delete snapper;
}
-
-/* fixme: Collect all these length parsing methods and think common sane API */
-
-static gboolean sp_nv_read_length(gchar const *str, guint base, gdouble *val, SPUnit const **unit)
-{
- if (!str) {
- return FALSE;
- }
-
- gchar *u;
- gdouble v = g_ascii_strtod(str, &u);
- if (!u) {
- return FALSE;
- }
- while (isspace(*u)) {
- u += 1;
- }
-
- if (!*u) {
- /* No unit specified - keep default */
- *val = v;
- return TRUE;
- }
-
- if (base & SP_UNIT_DEVICE) {
- if (u[0] && u[1] && !isalnum(u[2]) && !strncmp(u, "px", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_PX);
- *val = v;
- return TRUE;
- }
- }
-
- if (base & SP_UNIT_ABSOLUTE) {
- if (!strncmp(u, "pt", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_PT);
- } else if (!strncmp(u, "mm", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_MM);
- } else if (!strncmp(u, "cm", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_CM);
- } else if (!strncmp(u, "m", 1)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_M);
- } else if (!strncmp(u, "in", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_IN);
- } else if (!strncmp(u, "ft", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_FT);
- } else if (!strncmp(u, "pc", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_PC);
- } else {
- return FALSE;
- }
- *val = v;
- return TRUE;
- }
-
- return FALSE;
-}
-
static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color)
{
if (!str) {
@@ -270,17 +214,20 @@ CanvasAxonomGrid::readRepr()
{
gchar const *value;
if ( (value = repr->attribute("originx")) ) {
- sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::X], &gridunit);
- origin[Geom::X] = sp_units_get_pixels(origin[Geom::X], *(gridunit));
+ Inkscape::Util::Quantity q = unit_table.getQuantity(value);
+ gridunit = q.unit;
+ origin[Geom::X] = unit_table.getQuantity(value).value("px");
}
if ( (value = repr->attribute("originy")) ) {
- sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::Y], &gridunit);
- origin[Geom::Y] = sp_units_get_pixels(origin[Geom::Y], *(gridunit));
+ Inkscape::Util::Quantity q = unit_table.getQuantity(value);
+ gridunit = q.unit;
+ origin[Geom::Y] = unit_table.getQuantity(value).value("px");
}
if ( (value = repr->attribute("spacingy")) ) {
- sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &lengthy, &gridunit);
- lengthy = sp_units_get_pixels(lengthy, *(gridunit));
+ Inkscape::Util::Quantity q = unit_table.getQuantity(value);
+ gridunit = q.unit;
+ lengthy = q.value("px");
if (lengthy < 0.0500) lengthy = 0.0500;
}
@@ -419,17 +366,17 @@ _wr.setUpdating (false);
attach_all (*table, widget_array, sizeof(widget_array));
// set widget values
- _rumg->setUnit (gridunit);
+ _rumg->setUnit (gridunit->abbr);
gdouble val;
val = origin[Geom::X];
- val = sp_pixels_get_units (val, *(gridunit));
+ val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
_rsu_ox->setValue (val);
val = origin[Geom::Y];
- val = sp_pixels_get_units (val, *(gridunit));
+ val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
_rsu_oy->setValue (val);
val = lengthy;
- double gridy = sp_pixels_get_units (val, *(gridunit));
+ double gridy = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
_rsu_sy->setValue (gridy);
_rsu_ax->setValue(angle_deg[X]);
@@ -458,17 +405,17 @@ CanvasAxonomGrid::updateWidgets()
_rcb_enabled.setActive(snapper->getEnabled());
}
- _rumg.setUnit (gridunit);
+ _rumg.setUnit (gridunit->abbr);
gdouble val;
val = origin[Geom::X];
- val = sp_pixels_get_units (val, *(gridunit));
+ val = Inkscape::Util::Quantity::convert(val, &px, gridunit);
_rsu_ox.setValue (val);
val = origin[Geom::Y];
- val = sp_pixels_get_units (val, *(gridunit));
+ val = Inkscape::Util::Quantity::convert(val, &px, gridunit);
_rsu_oy.setValue (val);
val = lengthy;
- double gridy = sp_pixels_get_units (val, *(gridunit));
+ double gridy = Inkscape::Util::Quantity::convert(val, &px, gridunit);
_rsu_sy.setValue (gridy);
_rsu_ax.setValue(angle_deg[X]);
diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp
index ee5ad0945..ef32c113b 100644
--- a/src/display/canvas-grid.cpp
+++ b/src/display/canvas-grid.cpp
@@ -42,7 +42,7 @@
#include "display/canvas-grid.h"
#include "display/sp-canvas-group.h"
#include "document.h"
-#include "helper/units.h"
+#include "util/units.h"
#include "inkscape.h"
#include "preferences.h"
#include "sp-namedview.h"
@@ -55,6 +55,7 @@
#include "display/sp-canvas.h"
using Inkscape::DocumentUndo;
+using Inkscape::Util::unit_table;
namespace Inkscape {
@@ -398,11 +399,11 @@ void CanvasGrid::setOrigin(Geom::Point const &origin_px)
gdouble val;
val = origin_px[Geom::X];
- val = sp_pixels_get_units (val, *gridunit);
- os_x << val << sp_unit_get_abbreviation(gridunit);
+ val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
+ os_x << val << gridunit->abbr;
val = origin_px[Geom::Y];
- val = sp_pixels_get_units (val, *gridunit);
- os_y << val << sp_unit_get_abbreviation(gridunit);
+ val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
+ os_y << val << gridunit->abbr;
repr->setAttribute("originx", os_x.str().c_str());
repr->setAttribute("originy", os_y.str().c_str());
}
@@ -488,17 +489,17 @@ CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPD
: CanvasGrid(nv, in_repr, in_doc, GRID_RECTANGULAR)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gridunit = sp_unit_get_by_abbreviation( prefs->getString("/options/grids/xy/units").data() );
+ gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/xy/units")));
if (!gridunit) {
- gridunit = &sp_unit_get_by_id(SP_UNIT_PX);
+ gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px"));
}
- origin[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_x", 0.0), *gridunit);
- origin[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_y", 0.0), *gridunit);
+ origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_x", 0.0), *gridunit, "px");
+ origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_y", 0.0), *gridunit, "px");
color = prefs->getInt("/options/grids/xy/color", 0x0000ff20);
empcolor = prefs->getInt("/options/grids/xy/empcolor", 0x0000ff40);
empspacing = prefs->getInt("/options/grids/xy/empspacing", 5);
- spacing[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), *gridunit);
- spacing[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), *gridunit);
+ spacing[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), *gridunit, "px");
+ spacing[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), *gridunit, "px");
render_dotted = prefs->getBool("/options/grids/xy/dotted", false);
snapper = new CanvasXYGridSnapper(this, &namedview->snap_manager, 0);
@@ -511,64 +512,6 @@ CanvasXYGrid::~CanvasXYGrid ()
if (snapper) delete snapper;
}
-
-/* fixme: Collect all these length parsing methods and think common sane API */
-
-static gboolean
-sp_nv_read_length(gchar const *str, guint base, gdouble *val, SPUnit const **unit)
-{
- if (!str) {
- return FALSE;
- }
-
- gchar *u;
- gdouble v = g_ascii_strtod(str, &u);
- if (!u) {
- return FALSE;
- }
- while (isspace(*u)) {
- u += 1;
- }
-
- if (!*u) {
- /* No unit specified - keep default */
- *val = v;
- return TRUE;
- }
-
- if (base & SP_UNIT_DEVICE) {
- if (u[0] && u[1] && !isalnum(u[2]) && !strncmp(u, "px", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_PX);
- *val = v;
- return TRUE;
- }
- }
-
- if (base & SP_UNIT_ABSOLUTE) {
- if (!strncmp(u, "pt", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_PT);
- } else if (!strncmp(u, "mm", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_MM);
- } else if (!strncmp(u, "cm", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_CM);
- } else if (!strncmp(u, "m", 1)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_M);
- } else if (!strncmp(u, "in", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_IN);
- } else if (!strncmp(u, "ft", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_FT);
- } else if (!strncmp(u, "pc", 2)) {
- *unit = &sp_unit_get_by_id(SP_UNIT_PC);
- } else {
- return FALSE;
- }
- *val = v;
- return TRUE;
- }
-
- return FALSE;
-}
-
static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color)
{
if (!str) {
@@ -645,28 +588,32 @@ CanvasXYGrid::readRepr()
{
gchar const *value;
if ( (value = repr->attribute("originx")) ) {
- sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::X], &gridunit);
- origin[Geom::X] = sp_units_get_pixels(origin[Geom::X], *(gridunit));
+ Inkscape::Util::Quantity q = unit_table.getQuantity(value);
+ gridunit = q.unit;
+ origin[Geom::X] = unit_table.getQuantity(value).value("px");
}
if ( (value = repr->attribute("originy")) ) {
- sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::Y], &gridunit);
- origin[Geom::Y] = sp_units_get_pixels(origin[Geom::Y], *(gridunit));
+ Inkscape::Util::Quantity q = unit_table.getQuantity(value);
+ gridunit = q.unit;
+ origin[Geom::Y] = unit_table.getQuantity(value).value("px");
}
if ( (value = repr->attribute("spacingx")) ) {
double oldVal = spacing[Geom::X];
- sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[Geom::X], &gridunit);
- validateScalar( oldVal, &spacing[Geom::X]);
- spacing[Geom::X] = sp_units_get_pixels(spacing[Geom::X], *(gridunit));
-
+ Inkscape::Util::Quantity q = unit_table.getQuantity(value);
+ gridunit = q.unit;
+ spacing[Geom::X] = q.quantity;
+ validateScalar(oldVal, &spacing[Geom::X]);
+ spacing[Geom::X] = Inkscape::Util::Quantity::convert(spacing[Geom::X], *gridunit, "px");
}
if ( (value = repr->attribute("spacingy")) ) {
double oldVal = spacing[Geom::Y];
- sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[Geom::Y], &gridunit);
- validateScalar( oldVal, &spacing[Geom::Y]);
- spacing[Geom::Y] = sp_units_get_pixels(spacing[Geom::Y], *(gridunit));
-
+ Inkscape::Util::Quantity q = unit_table.getQuantity(value);
+ gridunit = q.unit;
+ spacing[Geom::Y] = q.quantity;
+ validateScalar(oldVal, &spacing[Geom::Y]);
+ spacing[Geom::Y] = Inkscape::Util::Quantity::convert(spacing[Geom::Y], *gridunit, "px");
}
if ( (value = repr->attribute("color")) ) {
@@ -802,20 +749,20 @@ CanvasXYGrid::newSpecificWidget()
attach_all (*table, widget_array, sizeof(widget_array));
// set widget values
- _rumg->setUnit (gridunit);
+ _rumg->setUnit (gridunit->abbr);
gdouble val;
val = origin[Geom::X];
- val = sp_pixels_get_units (val, *(gridunit));
+ val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
_rsu_ox->setValue (val);
val = origin[Geom::Y];
- val = sp_pixels_get_units (val, *(gridunit));
+ val = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
_rsu_oy->setValue (val);
val = spacing[Geom::X];
- double gridx = sp_pixels_get_units (val, *(gridunit));
+ double gridx = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
_rsu_sx->setValue (gridx);
val = spacing[Geom::Y];
- double gridy = sp_pixels_get_units (val, *(gridunit));
+ double gridy = Inkscape::Util::Quantity::convert(val, "px", *gridunit);
_rsu_sy->setValue (gridy);
_rcp_gcol->setRgba32 (color);
@@ -851,20 +798,20 @@ CanvasXYGrid::updateWidgets()
_rcb_enabled.setActive(snapper->getEnabled());
}
- _rumg.setUnit (gridunit);
+ _rumg.setUnit (gridunit->abbr);
gdouble val;
val = origin[Geom::X];
- val = sp_pixels_get_units (val, *(gridunit));
+ val = Inkscape::Quantity::convert(val, "px", *gridunit);
_rsu_ox.setValue (val);
val = origin[Geom::Y];
- val = sp_pixels_get_units (val, *(gridunit));
+ val = Inkscape::Quantity::convert(val, "px", *gridunit);
_rsu_oy.setValue (val);
val = spacing[Geom::X];
- double gridx = sp_pixels_get_units (val, *(gridunit));
+ double gridx = Inkscape::Quantity::convert(val, "px", *gridunit);
_rsu_sx.setValue (gridx);
val = spacing[Geom::Y];
- double gridy = sp_pixels_get_units (val, *(gridunit));
+ double gridy = Inkscape::Quantity::convert(val, "px", *gridunit);
_rsu_sy.setValue (gridy);
_rcp_gcol.setRgba32 (color);
diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h
index 7eaef407f..70b4bf744 100644
--- a/src/display/canvas-grid.h
+++ b/src/display/canvas-grid.h
@@ -28,6 +28,10 @@ namespace XML {
class Node;
}
+namespace Util {
+class Unit;
+}
+
enum GridType {
GRID_RECTANGULAR = 0,
GRID_AXONOMETRIC = 1
@@ -88,7 +92,7 @@ public:
guint32 empcolor; /**< Color for emphasis lines */
gint empspacing; /**< Spacing between emphasis lines */
- SPUnit const* gridunit;
+ Inkscape::Util::Unit const* gridunit;
Inkscape::XML::Node * repr;
SPDocument *doc;
diff --git a/src/document.cpp b/src/document.cpp
index 0e9c43fe4..0b742e491 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -49,7 +49,6 @@
#include "display/drawing-item.h"
#include "document-private.h"
#include "document-undo.h"
-#include "helper/units.h"
#include "id-clash.h"
#include "inkscape-private.h"
#include "inkscape-version.h"
@@ -63,12 +62,13 @@
#include "sp-object-repr.h"
#include "sp-symbol.h"
#include "transf_mat_3x4.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include "xml/repr.h"
#include "xml/rebase-hrefs.h"
#include "libcroco/cr-cascade.h"
using Inkscape::DocumentUndo;
+using Inkscape::Util::unit_table;
// Higher number means lower priority.
#define SP_DOCUMENT_UPDATE_PRIORITY (G_PRIORITY_HIGH_IDLE - 2)
@@ -546,21 +546,21 @@ gdouble SPDocument::getWidth() const
return result;
}
-void SPDocument::setWidth(gdouble width, const SPUnit *unit)
+void SPDocument::setWidth(const Inkscape::Util::Quantity &width)
{
if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox=
- root->viewBox.setMax(Geom::Point(root->viewBox.left() + sp_units_get_pixels (width, *unit), root->viewBox.bottom()));
+ root->viewBox.setMax(Geom::Point(root->viewBox.left() + width.value("px"), root->viewBox.bottom()));
} else { // set to width=
gdouble old_computed = root->width.computed;
- root->width.computed = sp_units_get_pixels (width, *unit);
+ root->width.computed = width.value("px");
/* SVG does not support meters as a unit, so we must translate meters to
* cm when writing */
- if (!strcmp(unit->abbr, "m")) {
- root->width.value = 100*width;
+ if (*width.unit == unit_table.getUnit("m")) {
+ root->width.value = width.value("cm");
root->width.unit = SVGLength::CM;
} else {
- root->width.value = width;
- root->width.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit);
+ root->width.value = width.quantity;
+ root->width.unit = (SVGLength::Unit) width.unit->svgUnit();
}
if (root->viewBox_set)
@@ -582,21 +582,21 @@ gdouble SPDocument::getHeight() const
return result;
}
-void SPDocument::setHeight(gdouble height, const SPUnit *unit)
+void SPDocument::setHeight(const Inkscape::Util::Quantity &height)
{
if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox=
- root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + sp_units_get_pixels (height, *unit)));
+ root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + height.value("px")));
} else { // set to height=
gdouble old_computed = root->height.computed;
- root->height.computed = sp_units_get_pixels (height, *unit);
+ root->height.computed = height.value("px");
/* SVG does not support meters as a unit, so we must translate meters to
* cm when writing */
- if (!strcmp(unit->abbr, "m")) {
- root->height.value = 100*height;
+ if (*height.unit == unit_table.getUnit("m")) {
+ root->height.value = height.value("cm");
root->height.unit = SVGLength::CM;
} else {
- root->height.value = height;
- root->height.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit);
+ root->height.value = height.quantity;
+ root->height.unit = (SVGLength::Unit) height.unit->svgUnit();
}
if (root->viewBox_set)
@@ -631,7 +631,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
double const h = rect.height();
double const old_height = getHeight();
- SPUnit const &px(sp_unit_get_by_id(SP_UNIT_PX));
+ Inkscape::Util::Unit const px = unit_table.getUnit("px");
/* in px */
double margin_top = 0.0;
@@ -644,9 +644,10 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
if (with_margins && nv) {
if (nv != NULL) {
gchar const * const units_abbr = nv->getAttribute("units");
- SPUnit const *margin_units = NULL;
+ Inkscape::Util::Unit const *margin_units = NULL;
if (units_abbr != NULL) {
- margin_units = sp_unit_get_by_abbreviation(units_abbr);
+ Inkscape::Util::Unit mu = unit_table.getUnit(units_abbr);
+ margin_units = &mu;
}
if (margin_units == NULL) {
margin_units = &px;
@@ -663,8 +664,8 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
rect.max() + Geom::Point(margin_right, margin_top));
- setWidth(rect_with_margins.width(), &px);
- setHeight(rect_with_margins.height(), &px);
+ setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), "px"));
+ setHeight(Inkscape::Util::Quantity(rect_with_margins.height(), "px"));
Geom::Translate const tr(
Geom::Point(0, old_height - rect_with_margins.height())
@@ -964,7 +965,7 @@ void SPDocument::setupViewport(SPItemCtx *ctx)
if (root->viewBox_set) { // if set, take from viewBox
ctx->viewport = root->viewBox;
} else { // as a last resort, set size to A4
- ctx->viewport = Geom::Rect::from_xywh(0, 0, 210 * PX_PER_MM, 297 * PX_PER_MM);
+ ctx->viewport = Geom::Rect::from_xywh(0, 0, 210 * Inkscape::Util::Quantity::convert(1, "mm", "px"), 297 * Inkscape::Util::Quantity::convert(1, "mm", "px"));
}
ctx->i2vp = Geom::identity();
}
diff --git a/src/document.h b/src/document.h
index d49067250..6782c6206 100644
--- a/src/document.h
+++ b/src/document.h
@@ -35,7 +35,6 @@ class SPItem;
class SPObject;
struct SPGroup;
struct SPRoot;
-struct SPUnit;
namespace Inkscape {
struct Application;
@@ -47,6 +46,9 @@ namespace Inkscape {
struct Document;
class Node;
}
+ namespace Util {
+ class Quantity;
+ }
}
class SPDefs;
@@ -229,8 +231,8 @@ public:
gdouble getHeight() const;
Geom::Point getDimensions() const;
Geom::OptRect preferredBounds() const;
- void setWidth(gdouble width, const SPUnit *unit);
- void setHeight(gdouble height, const SPUnit *unit);
+ void setWidth(const Inkscape::Util::Quantity &width);
+ void setHeight(const Inkscape::Util::Quantity &height);
void requestModified();
gint ensureUpToDate();
bool addResource(const gchar *key, SPObject *object);
@@ -254,8 +256,6 @@ private:
void setupViewport(SPItemCtx *ctx);
};
-struct SPUnit;
-
/*
* Ideas: How to overcome style invalidation nightmare
*
diff --git a/src/doxygen-main.cpp b/src/doxygen-main.cpp
index 1c3e5dcbb..a1d3f3604 100644
--- a/src/doxygen-main.cpp
+++ b/src/doxygen-main.cpp
@@ -334,8 +334,6 @@ namespace XML {}
*
* Inkscape::GC
*
- * [\ref sp-metrics.cpp, \ref sp-metrics.h]
- *
* [\ref prefs-utils.cpp] [\ref print.cpp]
*
* - Inkscape::GZipBuffer [\ref streams-gzip.h]
@@ -350,7 +348,7 @@ namespace XML {}
* Inkscape::Whiteboard::UndoStackObserver [\ref undo-stack-observer.cpp, \ref composite-undo-stack-observer.cpp]
* [\ref document-undo.cpp]
*
- * {\ref dialogs/} [\ref decimal-round.h] [\ref enums.h] [\ref unit-constants.h]
+ * {\ref dialogs/} [\ref decimal-round.h] [\ref enums.h]
*/
diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp
index f0461c609..0ea1fd591 100644
--- a/src/extension/internal/cairo-render-context.cpp
+++ b/src/extension/internal/cairo-render-context.cpp
@@ -44,12 +44,11 @@
#include "sp-pattern.h"
#include "sp-mask.h"
#include "sp-clippath.h"
+#include "util/units.h"
#ifdef WIN32
#include "libnrtype/FontFactory.h" // USE_PANGO_WIN32
#endif
-#include <unit-constants.h>
-
#include "cairo-render-context.h"
#include "cairo-renderer.h"
#include "extension/system.h"
@@ -855,7 +854,7 @@ CairoRenderContext::_finishSurfaceSetup(cairo_surface_t *surface, cairo_matrix_t
_surface = surface;
if (_vector_based_target) {
- cairo_scale(_cr, PT_PER_PX, PT_PER_PX);
+ cairo_scale(_cr, Inkscape::Util::Quantity::convert(1, "px", "pt"), Inkscape::Util::Quantity::convert(1, "px", "pt"));
} else if (cairo_surface_get_content(_surface) != CAIRO_CONTENT_ALPHA) {
// set background color on non-alpha surfaces
// TODO: bgcolor should be derived from SPDocument
diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp
index 8b2e8bf84..0a0c3f44a 100644
--- a/src/extension/internal/cairo-renderer-pdf-out.cpp
+++ b/src/extension/internal/cairo-renderer-pdf-out.cpp
@@ -39,7 +39,7 @@
#include <2geom/affine.h>
#include "document.h"
-#include "unit-constants.h"
+#include "util/units.h"
namespace Inkscape {
namespace Extension {
@@ -197,7 +197,7 @@ CairoRendererPdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc,
float new_bleedmargin_px = 0.;
try {
- new_bleedmargin_px = mod->get_param_float("bleed") * PX_PER_MM;
+ new_bleedmargin_px = mod->get_param_float("bleed") * Inkscape::Util::Quantity::convert(1, "mm", "px");
}
catch(...) {
g_warning("Parameter <bleed> might not exist");
diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp
index 0a3cff26a..f7ab63c98 100644
--- a/src/extension/internal/cairo-renderer.cpp
+++ b/src/extension/internal/cairo-renderer.cpp
@@ -55,7 +55,7 @@
#include "sp-mask.h"
#include "sp-clippath.h"
-#include <unit-constants.h>
+#include "util/units.h"
#include "helper/png-write.h"
#include "helper/pixbuf-ops.h"
@@ -442,7 +442,7 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx)
*/
res = ctx->getBitmapResolution();
if(res == 0) {
- res = PX_PER_IN;
+ res = Inkscape::Util::Quantity::convert(1, "in", "px");
}
TRACE(("sp_asbitmap_render: resolution: %f\n", res ));
@@ -463,8 +463,8 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx)
}
// The width and height of the bitmap in pixels
- unsigned width = ceil(bbox->width() * (res / PX_PER_IN));
- unsigned height = ceil(bbox->height() * (res / PX_PER_IN));
+ unsigned width = ceil(bbox->width() * (res / Inkscape::Util::Quantity::convert(1, "in", "px")));
+ unsigned height = ceil(bbox->height() * (res / Inkscape::Util::Quantity::convert(1, "in", "px")));
if (width == 0 || height == 0) return;
@@ -477,7 +477,7 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx)
double shift_y = bbox->max()[Geom::Y];
// For default 90 dpi, snap bitmap to pixel grid
- if (res == PX_PER_IN) {
+ if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) {
shift_x = round (shift_x);
shift_y = -round (-shift_y); // Correct rounding despite coordinate inversion.
// Remove the negations when the inversion is gone.
@@ -629,7 +629,7 @@ CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool page
if (ctx->_vector_based_target) {
// convert from px to pt
- d *= Geom::Scale(PT_PER_PX);
+ d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "pt"));
}
ctx->_width = d.width();
@@ -647,11 +647,11 @@ CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool page
} else {
double high = doc->getHeight();
if (ctx->_vector_based_target)
- high *= PT_PER_PX;
+ high *= Inkscape::Util::Quantity::convert(1, "px", "pt");
// this transform translates the export drawing to a virtual page (0,0)-(width,height)
- Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? PX_PER_PT : 1.0),
- (d.bottom() - high) * (ctx->_vector_based_target ? PX_PER_PT : 1.0)));
+ Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0),
+ (d.bottom() - high) * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0)));
ctx->transform(tp);
}
}
diff --git a/src/extension/internal/emf-win32-inout.cpp b/src/extension/internal/emf-win32-inout.cpp
index 063b1ca88..60385f455 100644
--- a/src/extension/internal/emf-win32-inout.cpp
+++ b/src/extension/internal/emf-win32-inout.cpp
@@ -37,9 +37,9 @@
#include "extension/output.h"
#include "display/drawing.h"
#include "display/drawing-item.h"
-#include "unit-constants.h"
#include "clear-n_.h"
#include "document.h"
+#include "util/units.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@@ -60,7 +60,7 @@ namespace Inkscape {
namespace Extension {
namespace Internal {
-static float device_scale = DEVICESCALE;
+static float device_scale = Inkscape::Util::Quantity::convert(1, "px", "pt");
static float device_x;
static float device_y;
static RECTL rc_old;
@@ -781,18 +781,18 @@ myEnhMetaFileProc(HDC /*hDC*/, HANDLETABLE * /*lpHTable*/, ENHMETARECORD const *
d->dc[d->level].PixelsInX = pEmr->rclFrame.right - pEmr->rclFrame.left;
d->dc[d->level].PixelsInY = pEmr->rclFrame.bottom - pEmr->rclFrame.top;
- device_x = pEmr->rclFrame.left/100.0*PX_PER_MM;
- device_y = pEmr->rclFrame.top/100.0*PX_PER_MM;
+ device_x = pEmr->rclFrame.left/100.0*Inkscape::Util::Quantity::convert(1, "mm", "px");
+ device_y = pEmr->rclFrame.top/100.0*Inkscape::Util::Quantity::convert(1, "mm", "px");
d->MMX = d->dc[d->level].PixelsInX / 100.0;
d->MMY = d->dc[d->level].PixelsInY / 100.0;
- d->dc[d->level].PixelsOutX = d->MMX * PX_PER_MM;
- d->dc[d->level].PixelsOutY = d->MMY * PX_PER_MM;
+ d->dc[d->level].PixelsOutX = d->MMX * Inkscape::Util::Quantity::convert(1, "mm", "px");
+ d->dc[d->level].PixelsOutY = d->MMY * Inkscape::Util::Quantity::convert(1, "mm", "px");
// calculate ratio of Inkscape dpi/device dpi
if (pEmr->szlMillimeters.cx && pEmr->szlDevice.cx)
- device_scale = PX_PER_MM*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx;
+ device_scale = Inkscape::Util::Quantity::convert(1, "mm", "px")*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx;
tmp_outdef <<
" width=\"" << d->MMX << "mm\"\n" <<
diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp
index e30ab390d..621954f68 100644
--- a/src/extension/internal/emf-win32-print.cpp
+++ b/src/extension/internal/emf-win32-print.cpp
@@ -36,6 +36,7 @@
#include "helper/geom.h"
#include "helper/geom-curves.h"
#include "sp-item.h"
+#include "util/units.h"
#include "style.h"
#include "inkscape-version.h"
@@ -43,8 +44,6 @@
#include "emf-win32-print.h"
-#include "unit-constants.h"
-
#include "extension/system.h"
#include "extension/print.h"
#include "document.h"
@@ -129,7 +128,7 @@ unsigned int PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument *
if (bbox) d = *bbox;
}
- d *= Geom::Scale(IN_PER_PX);
+ d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "in"));
float dwInchesX = d.width();
float dwInchesY = d.height();
@@ -196,7 +195,7 @@ unsigned int PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument *
snprintf(buff, sizeof(buff)-1, "Screen=%dx%dpx, %dx%dmm", PixelsX, PixelsY, MMX, MMY);
GdiComment(hdc, strlen(buff), (BYTE*) buff);
- snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * MM_PER_IN, dwInchesY * MM_PER_IN);
+ 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"));
GdiComment(hdc, strlen(buff), (BYTE*) buff);
}
@@ -304,7 +303,7 @@ void PrintEmfWin32::create_pen(SPStyle const *style, const Geom::Affine &transfo
double scale = sqrt( (p[X]*p[X]) + (p[Y]*p[Y]) ) / sqrt(2);
- DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * IN_PER_PX * dwDPI) );
+ DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI) );
if (style->stroke_linecap.computed == 0) {
linecap = PS_ENDCAP_FLAT;
@@ -341,7 +340,7 @@ void PrintEmfWin32::create_pen(SPStyle const *style, const Geom::Affine &transfo
n_dash = style->stroke_dash.n_dash;
dash = new DWORD[n_dash];
for (i = 0; i < style->stroke_dash.n_dash; i++) {
- dash[i] = (DWORD) (style->stroke_dash.dash[i] * IN_PER_PX * dwDPI);
+ dash[i] = (DWORD) (style->stroke_dash.dash[i] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
}
}
}
@@ -544,8 +543,8 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom
Geom::Point p0 = pit->initialPoint();
- p0[X] = (p0[X] * IN_PER_PX * dwDPI);
- p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);
+ p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
LONG const x0 = (LONG) round(p0[X]);
LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -564,10 +563,10 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom
//Geom::Point p0 = cit->initialPoint();
Geom::Point p1 = cit->finalPoint();
- //p0[X] = (p0[X] * IN_PER_PX * dwDPI);
- p1[X] = (p1[X] * IN_PER_PX * dwDPI);
- //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);
- p1[Y] = (p1[Y] * IN_PER_PX * dwDPI);
+ //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
//LONG const x0 = (LONG) round(p0[X]);
//LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -586,14 +585,14 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom
Geom::Point p2 = points[2];
Geom::Point p3 = points[3];
- //p0[X] = (p0[X] * IN_PER_PX * dwDPI);
- p1[X] = (p1[X] * IN_PER_PX * dwDPI);
- p2[X] = (p2[X] * IN_PER_PX * dwDPI);
- p3[X] = (p3[X] * IN_PER_PX * dwDPI);
- //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);
- p1[Y] = (p1[Y] * IN_PER_PX * dwDPI);
- p2[Y] = (p2[Y] * IN_PER_PX * dwDPI);
- p3[Y] = (p3[Y] * IN_PER_PX * dwDPI);
+ //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p2[X] = (p2[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p3[X] = (p3[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p2[Y] = (p2[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p3[Y] = (p3[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
//LONG const x0 = (LONG) round(p0[X]);
//LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -716,8 +715,8 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo
Geom::Point p0 = pit->initialPoint();
- p0[X] = (p0[X] * IN_PER_PX * dwDPI);
- p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);
+ p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
LONG const x0 = (LONG) round(p0[X]);
LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -734,10 +733,10 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo
//Geom::Point p0 = cit->initialPoint();
Geom::Point p1 = cit->finalPoint();
- //p0[X] = (p0[X] * IN_PER_PX * dwDPI);
- p1[X] = (p1[X] * IN_PER_PX * dwDPI);
- //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);
- p1[Y] = (p1[Y] * IN_PER_PX * dwDPI);
+ //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
//LONG const x0 = (LONG) round(p0[X]);
//LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -754,14 +753,14 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo
Geom::Point p2 = points[2];
Geom::Point p3 = points[3];
- //p0[X] = (p0[X] * IN_PER_PX * dwDPI);
- p1[X] = (p1[X] * IN_PER_PX * dwDPI);
- p2[X] = (p2[X] * IN_PER_PX * dwDPI);
- p3[X] = (p3[X] * IN_PER_PX * dwDPI);
- //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI);
- p1[Y] = (p1[Y] * IN_PER_PX * dwDPI);
- p2[Y] = (p2[Y] * IN_PER_PX * dwDPI);
- p3[Y] = (p3[Y] * IN_PER_PX * dwDPI);
+ //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p2[X] = (p2[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p3[X] = (p3[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p2[Y] = (p2[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p3[Y] = (p3[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
//LONG const x0 = (LONG) round(p0[X]);
//LONG const y0 = (LONG) round(rc.bottom-p0[Y]);
@@ -829,7 +828,7 @@ unsigned int PrintEmfWin32::text(Inkscape::Extension::Print * /*mod*/, char cons
LOGFONTW *lf = (LOGFONTW*)g_malloc(sizeof(LOGFONTW));
g_assert(lf != NULL);
- lf->lfHeight = -style->font_size.computed * IN_PER_PX * dwDPI;
+ lf->lfHeight = -style->font_size.computed * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI;
lf->lfWidth = 0;
lf->lfEscapement = rot;
lf->lfOrientation = rot;
@@ -878,8 +877,8 @@ unsigned int PrintEmfWin32::text(Inkscape::Extension::Print * /*mod*/, char cons
SetBkMode(hdc, TRANSPARENT);
Geom::Point p2 = p * tf;
- p2[Geom::X] = (p2[Geom::X] * IN_PER_PX * dwDPI);
- p2[Geom::Y] = (p2[Geom::Y] * IN_PER_PX * dwDPI);
+ p2[Geom::X] = (p2[Geom::X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
+ p2[Geom::Y] = (p2[Geom::Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI);
LONG const xpos = (LONG) round(p2[Geom::X]);
LONG const ypos = (LONG) round(rc.bottom - p2[Geom::Y]);
diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp
index abfad518f..994258ccc 100644
--- a/src/extension/internal/gdkpixbuf-input.cpp
+++ b/src/extension/internal/gdkpixbuf-input.cpp
@@ -12,7 +12,7 @@
#include "selection-chemistry.h"
#include "sp-image.h"
#include "document-undo.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include "image-resolution.h"
#include <set>
@@ -79,7 +79,7 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
double width = gdk_pixbuf_get_width(pb);
double height = gdk_pixbuf_get_height(pb);
- double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", PX_PER_IN);
+ double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", Inkscape::Util::Quantity::convert(1, "in", "px"));
bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi");
ImageResolution *ir = 0;
double xscale = 1;
diff --git a/src/extension/internal/latex-pstricks.cpp b/src/extension/internal/latex-pstricks.cpp
index c1eddf539..2ece1ba87 100644
--- a/src/extension/internal/latex-pstricks.cpp
+++ b/src/extension/internal/latex-pstricks.cpp
@@ -21,7 +21,7 @@
#include <2geom/hvlinesegment.h>
#include <errno.h>
#include <signal.h>
-#include <unit-constants.h>
+#include "util/units.h"
#include "helper/geom-curves.h"
#include "extension/print.h"
@@ -117,8 +117,8 @@ unsigned int PrintLatex::begin (Inkscape::Extension::Print *mod, SPDocument *doc
}
// width and height in pt
- _width = doc->getWidth() * PT_PER_PX;
- _height = doc->getHeight() * PT_PER_PX;
+ _width = doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt");
+ _height = doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt");
if (res >= 0) {
diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp
index ecc201733..57a71b467 100644
--- a/src/extension/internal/latex-text-renderer.cpp
+++ b/src/extension/internal/latex-text-renderer.cpp
@@ -39,7 +39,7 @@
#include "sp-rect.h"
#include "text-editing.h"
-#include <unit-constants.h>
+#include "util/units.h"
#include "extension/system.h"
@@ -611,7 +611,7 @@ LaTeXTextRenderer::setupDocument(SPDocument *doc, bool pageBoundingBox, float bl
// scaling of the image when including it in LaTeX
os << " \\ifx\\svgwidth\\undefined%\n";
- os << " \\setlength{\\unitlength}{" << d.width() * PT_PER_PX << "bp}%\n"; // note: 'bp' is the Postscript pt unit in LaTeX, see LP bug #792384
+ 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
os << " \\ifx\\svgscale\\undefined%\n";
os << " \\relax%\n";
os << " \\else%\n";
diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp
index 4e50f02f6..6e57f6278 100644
--- a/src/extension/internal/pdfinput/pdf-parser.cpp
+++ b/src/extension/internal/pdfinput/pdf-parser.cpp
@@ -34,7 +34,7 @@ extern "C" {
#include "svg-builder.h"
#include "Gfx.h"
#include "pdf-parser.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include "goo/gmem.h"
#include "goo/GooTimer.h"
@@ -279,14 +279,14 @@ PdfParser::PdfParser(XRef *xrefA, Inkscape::Extension::Internal::SvgBuilder *bui
ignoreUndef = 0;
operatorHistory = NULL;
builder = builderA;
- builder->setDocumentSize(state->getPageWidth()*PX_PER_PT,
- state->getPageHeight()*PX_PER_PT);
+ builder->setDocumentSize(state->getPageWidth()*Inkscape::Util::Quantity::convert(1, "pt", "px"),
+ state->getPageHeight()*Inkscape::Util::Quantity::convert(1, "pt", "px"));
double *ctm = state->getCTM();
double scaledCTM[6];
for (int i = 0; i < 6; ++i) {
baseMatrix[i] = ctm[i];
- scaledCTM[i] = PX_PER_PT * ctm[i];
+ scaledCTM[i] = Inkscape::Util::Quantity::convert(1, "pt", "px") * ctm[i];
}
saveState();
builder->setTransform((double*)&scaledCTM);
diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp
index dee7d8afb..a1a309a87 100644
--- a/src/extension/internal/pdfinput/svg-builder.cpp
+++ b/src/extension/internal/pdfinput/svg-builder.cpp
@@ -33,7 +33,7 @@
#include "svg/css-ostringstream.h"
#include "svg/svg-color.h"
#include "color.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include "io/stringstream.h"
#include "io/base64stream.h"
#include "display/nr-filter-utils.h"
@@ -793,7 +793,7 @@ gchar *SvgBuilder::_createGradient(GfxShading *shading, double *matrix, bool for
Geom::Affine pat_matrix(matrix[0], matrix[1], matrix[2], matrix[3],
matrix[4], matrix[5]);
if ( !for_shading && _is_top_level ) {
- Geom::Affine flip(1.0, 0.0, 0.0, -1.0, 0.0, _height * PT_PER_PX);
+ Geom::Affine flip(1.0, 0.0, 0.0, -1.0, 0.0, _height * Inkscape::Util::Quantity::convert(1, "px", "pt"));
pat_matrix *= flip;
}
gchar *transform_text = sp_svg_transform_write(pat_matrix);
diff --git a/src/flood-context.cpp b/src/flood-context.cpp
index 8fde11f88..a719f1202 100644
--- a/src/flood-context.cpp
+++ b/src/flood-context.cpp
@@ -54,7 +54,6 @@
#include "sp-defs.h"
#include "sp-item.h"
#include "splivarot.h"
-#include "sp-metrics.h"
#include "sp-namedview.h"
#include "sp-object.h"
#include "sp-path.h"
diff --git a/src/flood-context.h b/src/flood-context.h
index 3e81cd01e..810a3b48f 100644
--- a/src/flood-context.h
+++ b/src/flood-context.h
@@ -15,8 +15,6 @@
#include <sigc++/sigc++.h>
#include <gtk/gtk.h>
#include "event-context.h"
-#include "helper/unit-menu.h"
-#include "helper/units.h"
#define SP_TYPE_FLOOD_CONTEXT (sp_flood_context_get_type ())
#define SP_FLOOD_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_FLOOD_CONTEXT, SPFloodContext))
diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert
index 790d87b14..4c6437f13 100644
--- a/src/helper/Makefile_insert
+++ b/src/helper/Makefile_insert
@@ -18,12 +18,6 @@ ink_common_sources += \
helper/png-write.h \
helper/sp-marshal.cpp \
helper/sp-marshal.h \
- helper/unit-menu.cpp \
- helper/unit-menu.h \
- helper/unit-tracker.cpp \
- helper/unit-tracker.h \
- helper/units.cpp \
- helper/units.h \
helper/window.cpp \
helper/window.h \
helper/stock-items.cpp \
@@ -46,9 +40,3 @@ helper/sp-marshal.cpp: helper/sp-marshal.list helper/sp-marshal.h
else mv helper/tmp.sp-marshal.cpp helper/sp-marshal.cpp; fi
helper/sp-marshal.cpp helper/sp-marshal.h: helper/sp-marshal.list
-
-# ######################
-# ### CxxTest stuff ####
-# ######################
-CXXTEST_TESTSUITES += \
- $(srcdir)/helper/units-test.h
diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp
index 9cd1967d8..75c002c57 100644
--- a/src/helper/pixbuf-ops.cpp
+++ b/src/helper/pixbuf-ops.cpp
@@ -29,7 +29,7 @@
#include "sp-root.h"
#include "sp-use.h"
#include "sp-defs.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include "helper/pixbuf-ops.h"
@@ -121,7 +121,7 @@ GdkPixbuf *sp_generate_internal_bitmap(SPDocument *doc, gchar const */*filename*
origin[Geom::X] = origin[Geom::X] + (screen[Geom::X].extent() * ((1 - padding) / 2));
origin[Geom::Y] = origin[Geom::Y] + (screen[Geom::Y].extent() * ((1 - padding) / 2));
- Geom::Scale scale( (xdpi / PX_PER_IN), (ydpi / PX_PER_IN));
+ Geom::Scale scale( (xdpi / Inkscape::Util::Quantity::convert(1, "in", "px")), (ydpi / Inkscape::Util::Quantity::convert(1, "in", "px")));
Geom::Affine affine = scale * Geom::Translate(-origin * scale);
/* Create ArenaItems and set transform */
diff --git a/src/helper/unit-menu.cpp b/src/helper/unit-menu.cpp
deleted file mode 100644
index af07c03c1..000000000
--- a/src/helper/unit-menu.cpp
+++ /dev/null
@@ -1,360 +0,0 @@
-#define __SP_UNIT_MENU_C__
-
-/*
- * Unit selector with autupdate capability
- *
- * Authors:
- * Lauris Kaplinski <lauris@kaplinski.com>
- * bulia byak <buliabyak@users.sf.net>
- *
- * Copyright (C) 2000-2002 Authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#define noUNIT_SELECTOR_VERBOSE
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-#include <gtk/gtk.h>
-#include "helper/sp-marshal.h"
-#include "helper/units.h"
-#include "helper/unit-menu.h"
-#include "widgets/spw-utilities.h"
-
-struct SPUnitSelector {
- GtkHBox box;
-
- GtkWidget *combo_box;
- GtkListStore *store;
-
-
- guint bases;
- GSList *units;
- SPUnit const *unit;
- gdouble ctmscale;
- guint plural : 1;
- guint abbr : 1;
-
- guint update : 1;
-
- GSList *adjustments;
-};
-
-enum {COMBO_COL_LABEL=0, COMBO_COL_UNIT};
-
-struct SPUnitSelectorClass {
- GtkHBoxClass parent_class;
-
- gboolean (* set_unit)(SPUnitSelector *us, SPUnit const *old, SPUnit const *new_unit);
-};
-
-enum {SET_UNIT, LAST_SIGNAL};
-
-static void sp_unit_selector_finalize(GObject *object);
-
-static guint signals[LAST_SIGNAL] = {0};
-
-G_DEFINE_TYPE(SPUnitSelector, sp_unit_selector, GTK_TYPE_HBOX);
-
-static void
-sp_unit_selector_class_init(SPUnitSelectorClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- signals[SET_UNIT] = g_signal_new("set_unit",
- G_TYPE_FROM_CLASS(klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(SPUnitSelectorClass, set_unit),
- NULL, NULL,
- sp_marshal_BOOLEAN__POINTER_POINTER,
- G_TYPE_BOOLEAN, 2,
- G_TYPE_POINTER, G_TYPE_POINTER);
-
- object_class->finalize = sp_unit_selector_finalize;
-}
-
-static void
-sp_unit_selector_init(SPUnitSelector *us)
-{
- us->ctmscale = 1.0;
- us->abbr = FALSE;
- us->plural = TRUE;
-
- /**
- * Create a combo_box and store with 2 columns,
- * a label and a pointer to a SPUnit
- */
- us->store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
- us->combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (us->store));
-
- GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
- g_object_set (renderer, "scale", 0.8, "scale-set", TRUE, NULL);
- gtk_cell_renderer_set_padding (renderer, 2, 0);
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (us->combo_box), renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (us->combo_box), renderer, "text", COMBO_COL_LABEL, NULL);
-
- gtk_widget_show (us->combo_box);
- gtk_box_pack_start (GTK_BOX(us), us->combo_box, TRUE, TRUE, 0);
-}
-
-static void
-sp_unit_selector_finalize(GObject *object)
-{
- SPUnitSelector *selector = SP_UNIT_SELECTOR(object);
-
- if (selector->combo_box) {
- selector->combo_box = NULL;
- }
-
- while (selector->adjustments) {
- g_object_unref(selector->adjustments->data);
- selector->adjustments = g_slist_remove(selector->adjustments, selector->adjustments->data);
- }
-
- if (selector->units) {
- sp_unit_free_list(selector->units);
- }
-
- selector->unit = NULL;
-
- G_OBJECT_CLASS(sp_unit_selector_parent_class)->finalize(object);
-}
-
-GtkWidget *
-sp_unit_selector_new(guint bases)
-{
- SPUnitSelector *us = SP_UNIT_SELECTOR(g_object_new(SP_TYPE_UNIT_SELECTOR, NULL));
-
- sp_unit_selector_set_bases(us, bases);
-
- return GTK_WIDGET(us);
-}
-
-void
-sp_unit_selector_setsize(GtkWidget *us, guint w, guint h)
-{
- gtk_widget_set_size_request((SP_UNIT_SELECTOR(us))->combo_box, w, h);
-}
-
-SPUnit const *
-sp_unit_selector_get_unit(SPUnitSelector const *us)
-{
- g_return_val_if_fail(us != NULL, NULL);
- g_return_val_if_fail(SP_IS_UNIT_SELECTOR(us), NULL);
-
- return us->unit;
-}
-
-
-static void
-on_combo_box_changed (GtkComboBox *widget, SPUnitSelector *us)
-{
- GtkTreeIter iter;
- if (!gtk_combo_box_get_active_iter (widget, &iter)) {
- return;
- }
-
- SPUnit const *unit = NULL;
- gtk_tree_model_get (GTK_TREE_MODEL(us->store), &iter, COMBO_COL_UNIT, &unit, -1);
-
- g_return_if_fail(unit != NULL);
-
-#ifdef UNIT_SELECTOR_VERBOSE
- g_print("Old unit %s new unit %s\n", us->unit->name, unit->name);
-#endif
-
- SPUnit const *old = us->unit;
- us->unit = unit;
-
- us->update = TRUE;
-
- gboolean consumed = FALSE;
- g_signal_emit(G_OBJECT(us), signals[SET_UNIT], 0, old, unit, &consumed);
-
- if ( !consumed
- && ( unit->base == old->base
- || ( unit->base == SP_UNIT_ABSOLUTE && old->base == SP_UNIT_DEVICE )
- || ( old->base == SP_UNIT_ABSOLUTE && unit->base == SP_UNIT_DEVICE ) ) ) {
- // Either the same base, or absolute<->device:
- /* Recalculate adjustments. */
- for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) {
- GtkAdjustment *adj = GTK_ADJUSTMENT(l->data);
- gdouble val = gtk_adjustment_get_value (adj);
-#ifdef UNIT_SELECTOR_VERBOSE
- g_print("Old val %g ... ", val);
-#endif
- val = sp_convert_distance_full(val, *old, *unit);
-#ifdef UNIT_SELECTOR_VERBOSE
- g_print("new val %g\n", val);
-#endif
- gtk_adjustment_set_value (adj, val);
- }
- /* need to separate the value changing from the notification
- * or else the unit changes can break the calculations */
- for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) {
- gtk_adjustment_value_changed(GTK_ADJUSTMENT(l->data));
- }
- } else if (!consumed && unit->base != old->base) {
- /* when the base changes, signal all the adjustments to get them
- * to recalculate */
- for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) {
- g_signal_emit_by_name(G_OBJECT(l->data), "value_changed");
- }
- }
-
- us->update = FALSE;
-
-}
-
-static void
-spus_rebuild_menu(SPUnitSelector *us)
-{
-
- gtk_list_store_clear(us->store);
-
- GtkTreeIter iter;
-
- gint pos = 0;
- gint p = 0;
- for (GSList *l = us->units; l != NULL; l = l->next) {
- SPUnit const *u = static_cast<SPUnit const*>(l->data);
-
- // use only abbreviations in the menu
- // i = gtk_menu_item_new_with_label((us->abbr) ? (us->plural) ? u->abbr_plural : u->abbr : (us->plural) ? u->plural : u->name);
- gtk_list_store_append (us->store, &iter);
- gtk_list_store_set (us->store, &iter, COMBO_COL_LABEL, u->abbr, COMBO_COL_UNIT, (gpointer) u, -1);
-
- if (u == us->unit) {
- pos = p;
- }
-
- p += 1;
- }
-
- gtk_combo_box_set_active(GTK_COMBO_BOX(us->combo_box), pos);
- g_signal_connect (G_OBJECT (us->combo_box), "changed", G_CALLBACK (on_combo_box_changed), us);
-}
-
-void
-sp_unit_selector_set_bases(SPUnitSelector *us, guint bases)
-{
- g_return_if_fail(us != NULL);
- g_return_if_fail(SP_IS_UNIT_SELECTOR(us));
-
- if (bases == us->bases) return;
-
- GSList *units = sp_unit_get_list(bases);
- g_return_if_fail(units != NULL);
- sp_unit_free_list(us->units);
- us->units = units;
- us->unit = static_cast<SPUnit *>(units->data);
-
- spus_rebuild_menu(us);
-}
-
-void
-sp_unit_selector_add_unit(SPUnitSelector *us, SPUnit const *unit, int position)
-{
- if (!g_slist_find(us->units, (gpointer) unit)) {
- us->units = g_slist_insert(us->units, (gpointer) unit, position);
-
- spus_rebuild_menu(us);
- }
-}
-
-void
-sp_unit_selector_set_unit(SPUnitSelector *us, SPUnit const *unit)
-{
- g_return_if_fail(us != NULL);
- g_return_if_fail(SP_IS_UNIT_SELECTOR(us));
-
- if (unit == NULL) {
- return; // silently return, by default a newly created selector uses pt
- }
- if (unit == us->unit) {
- return;
- }
-
- gint const pos = g_slist_index(us->units, (gpointer) unit);
- g_return_if_fail(pos >= 0);
-
- gtk_combo_box_set_active(GTK_COMBO_BOX(us->combo_box), pos);
-
- SPUnit const *old = us->unit;
- us->unit = unit;
-
- /* Recalculate adjustments */
- for (GSList *l = us->adjustments; l != NULL; l = l->next) {
- GtkAdjustment *adj = GTK_ADJUSTMENT(l->data);
- gdouble const val = sp_convert_distance_full(gtk_adjustment_get_value (adj), *old, *unit);
- gtk_adjustment_set_value(adj, val);
- }
-}
-
-void
-sp_unit_selector_add_adjustment(SPUnitSelector *us, GtkAdjustment *adj)
-{
- g_return_if_fail(us != NULL);
- g_return_if_fail(SP_IS_UNIT_SELECTOR(us));
- g_return_if_fail(adj != NULL);
- g_return_if_fail(GTK_IS_ADJUSTMENT(adj));
-
- g_return_if_fail(!g_slist_find(us->adjustments, adj));
-
- g_object_ref(adj);
- us->adjustments = g_slist_prepend(us->adjustments, adj);
-}
-
-void
-sp_unit_selector_remove_adjustment(SPUnitSelector *us, GtkAdjustment *adj)
-{
- g_return_if_fail(us != NULL);
- g_return_if_fail(SP_IS_UNIT_SELECTOR(us));
- g_return_if_fail(adj != NULL);
- g_return_if_fail(GTK_IS_ADJUSTMENT(adj));
-
- g_return_if_fail(g_slist_find(us->adjustments, adj));
-
- us->adjustments = g_slist_remove(us->adjustments, adj);
- g_object_unref(adj);
-}
-
-gboolean
-sp_unit_selector_update_test(SPUnitSelector const *selector)
-{
- g_return_val_if_fail(selector != NULL, FALSE);
- g_return_val_if_fail(SP_IS_UNIT_SELECTOR(selector), FALSE);
-
- return selector->update;
-}
-
-double
-sp_unit_selector_get_value_in_pixels(SPUnitSelector const *selector, GtkAdjustment *adj)
-{
- g_return_val_if_fail(selector != NULL, gtk_adjustment_get_value (adj));
- g_return_val_if_fail(SP_IS_UNIT_SELECTOR(selector), gtk_adjustment_get_value (adj));
-
- return sp_units_get_pixels(gtk_adjustment_get_value (adj), *(selector->unit));
-}
-
-void
-sp_unit_selector_set_value_in_pixels(SPUnitSelector *selector, GtkAdjustment *adj, double value)
-{
- g_return_if_fail(selector != NULL);
- g_return_if_fail(SP_IS_UNIT_SELECTOR(selector));
-
- gtk_adjustment_set_value(adj, sp_pixels_get_units(value, *(selector->unit)));
-}
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/unit-menu.h b/src/helper/unit-menu.h
deleted file mode 100644
index b3ee6bcd1..000000000
--- a/src/helper/unit-menu.h
+++ /dev/null
@@ -1,60 +0,0 @@
-#ifndef SP_UNIT_MENU_H
-#define SP_UNIT_MENU_H
-
-/*
- * SPUnitMenu
- *
- * Generic (and quite unintelligent) grid item for gnome canvas
- *
- * Copyright (C) Lauris Kaplinski 2000
- *
- */
-
-#include <glib.h>
-#include <gtk/gtk.h>
-
-struct SPUnit;
-struct SPUnitSelector;
-struct SPUnitSelectorClass;
-
-/* Unit selector Widget */
-
-#define SP_TYPE_UNIT_SELECTOR (sp_unit_selector_get_type())
-#define SP_UNIT_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_UNIT_SELECTOR, SPUnitSelector))
-#define SP_UNIT_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SP_TYPE_UNIT_SELECTOR, SPUnitSelectorClass))
-#define SP_IS_UNIT_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_UNIT_SELECTOR))
-#define SP_IS_UNIT_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), SP_TYPE_UNIT_SELECTOR))
-
-GType sp_unit_selector_get_type(void);
-
-GtkWidget *sp_unit_selector_new(guint bases);
-void sp_unit_selector_setsize(GtkWidget *us, guint w, guint h);
-
-SPUnit const *sp_unit_selector_get_unit(SPUnitSelector const *selector);
-
-void sp_unit_selector_set_bases(SPUnitSelector *selector, guint bases);
-void sp_unit_selector_add_unit(SPUnitSelector *selector, SPUnit const *unit, int position);
-
-void sp_unit_selector_set_unit(SPUnitSelector *selector, SPUnit const *unit);
-void sp_unit_selector_add_adjustment(SPUnitSelector *selector, GtkAdjustment *adjustment);
-void sp_unit_selector_remove_adjustment(SPUnitSelector *selector, GtkAdjustment *adjustment);
-
-gboolean sp_unit_selector_update_test(SPUnitSelector const *selector);
-
-double sp_unit_selector_get_value_in_pixels(SPUnitSelector const *selector, GtkAdjustment *adj);
-void sp_unit_selector_set_value_in_pixels(SPUnitSelector *selector, GtkAdjustment *adj, double value);
-
-
-
-#endif // SP_UNIT_MENU_H
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/unit-tracker.cpp b/src/helper/unit-tracker.cpp
deleted file mode 100644
index 609c2f292..000000000
--- a/src/helper/unit-tracker.cpp
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Inkscape::UnitTracker - Simple mediator to synchronize changes to a set
- * of possible units
- *
- * Authors:
- * Jon A. Cruz <jon@joncruz.org>
- *
- * Copyright (C) 2007 Jon A. Cruz
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#include <gtk/gtk.h>
-
-#include "unit-tracker.h"
-#include "ege-select-one-action.h"
-
-namespace Inkscape {
-
-enum {
- COLUMN_STRING,
- COLUMN_SPUNIT,
- N_COLUMNS
-};
-
-UnitTracker::UnitTracker( guint bases ) :
- _active(0),
- _isUpdating(false),
- _activeUnit(0),
- _store(0),
- _unitList(0),
- _actionList(0),
- _adjList(0),
- _priorValues()
-{
- _store = gtk_list_store_new( N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER );
- setBase( bases );
-}
-
-UnitTracker::~UnitTracker()
-{
- if ( _unitList ) {
- sp_unit_free_list( _unitList );
- }
-
- // Unhook weak references to GtkActions
- while ( _actionList ) {
- g_signal_handlers_disconnect_by_func( G_OBJECT(_actionList->data), (gpointer)_unitChangedCB, this );
- g_object_weak_unref( G_OBJECT(_actionList->data), _actionFinalizedCB, this );
- _actionList = g_slist_delete_link( _actionList, _actionList );
- }
-
- // Unhook wek references to GtkAdjustments
- while ( _adjList ) {
- g_object_weak_unref( G_OBJECT(_adjList->data), _adjustmentFinalizedCB, this );
- _adjList = g_slist_delete_link( _adjList, _adjList );
- }
-}
-
-void UnitTracker::setBase( guint bases )
-{
- GtkTreeIter iter;
- _unitList = sp_unit_get_list( bases );
- for ( GSList* cur = _unitList; cur; cur = g_slist_next(cur) ) {
- SPUnit* unit = static_cast<SPUnit*>(cur->data);
- gtk_list_store_append( _store, &iter );
- gtk_list_store_set( _store, &iter, COLUMN_STRING, unit->abbr, COLUMN_SPUNIT, unit, -1 );
- }
- gint count = gtk_tree_model_iter_n_children( GTK_TREE_MODEL(_store), 0 );
- if ( (count > 0) && (_active > count) ) {
- _setActive( count - 1 );
- } else {
- _setActive( _active );
- }
-}
-
-void UnitTracker::addUnit( SPUnitId id, gint index )
-{
- GtkTreeIter iter;
- const SPUnit* percentUnit = &sp_unit_get_by_id( id );
- gtk_list_store_insert( _store, &iter, index );
- gtk_list_store_set( _store, &iter, COLUMN_STRING, percentUnit->abbr, COLUMN_SPUNIT, percentUnit, -1 );
-}
-
-bool UnitTracker::isUpdating() const
-{
- return _isUpdating;
-}
-
-SPUnit const* UnitTracker::getActiveUnit() const
-{
- return _activeUnit;
-}
-
-void UnitTracker::setActiveUnit( SPUnit const *unit )
-{
- if ( unit ) {
- GtkTreeIter iter;
- int index = 0;
- gboolean found = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(_store), &iter );
- while ( found ) {
- SPUnit* storedUnit = 0;
- gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &storedUnit, -1 );
- if ( storedUnit && (storedUnit->unit_id == unit->unit_id) ) {
- _setActive(index);
- break;
- }
-
- found = gtk_tree_model_iter_next( GTK_TREE_MODEL(_store), &iter );
- index++;
- }
- }
-}
-
-void UnitTracker::addAdjustment( GtkAdjustment* adj )
-{
- if ( !g_slist_find( _adjList, adj ) ) {
- g_object_weak_ref( G_OBJECT(adj), _adjustmentFinalizedCB, this );
- _adjList = g_slist_append( _adjList, adj );
- }
-}
-
-void UnitTracker::setFullVal( GtkAdjustment* adj, gdouble val )
-{
- _priorValues[adj] = val;
-}
-
-GtkAction* UnitTracker::createAction( gchar const* name, gchar const* label, gchar const* tooltip )
-{
- EgeSelectOneAction* act1 = ege_select_one_action_new( name, label, tooltip, NULL, GTK_TREE_MODEL(_store) );
- ege_select_one_action_set_label_column( act1, COLUMN_STRING );
- if ( _active ) {
- ege_select_one_action_set_active( act1, _active );
- }
-
- ege_select_one_action_set_appearance( act1, "minimal" );
- g_object_weak_ref( G_OBJECT(act1), _actionFinalizedCB, this );
- g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK( _unitChangedCB ), this );
- _actionList = g_slist_append( _actionList, act1 );
-
- return GTK_ACTION(act1);
-}
-
-void UnitTracker::_unitChangedCB( GtkAction* action, gpointer data )
-{
- if ( action && data ) {
- EgeSelectOneAction* act = EGE_SELECT_ONE_ACTION(action);
- gint active = ege_select_one_action_get_active( act );
- UnitTracker* self = reinterpret_cast<UnitTracker*>(data);
- self->_setActive(active);
- }
-}
-
-void UnitTracker::_actionFinalizedCB( gpointer data, GObject *where_the_object_was )
-{
- if ( data && where_the_object_was ) {
- UnitTracker* self = reinterpret_cast<UnitTracker*>(data);
- self->_actionFinalized( where_the_object_was );
- }
-}
-
-void UnitTracker::_adjustmentFinalizedCB( gpointer data, GObject *where_the_object_was )
-{
- if ( data && where_the_object_was ) {
- UnitTracker* self = reinterpret_cast<UnitTracker*>(data);
- self->_adjustmentFinalized( where_the_object_was );
- }
-}
-
-void UnitTracker::_actionFinalized( GObject *where_the_object_was )
-{
- GSList* target = g_slist_find( _actionList, where_the_object_was );
- if ( target ) {
- _actionList = g_slist_remove( _actionList, where_the_object_was );
- } else {
- g_warning("Received a finalization callback for unknown object %p", where_the_object_was );
- }
-}
-
-void UnitTracker::_adjustmentFinalized( GObject *where_the_object_was )
-{
- GSList* target = g_slist_find( _adjList, where_the_object_was );
- if ( target ) {
- _adjList = g_slist_remove( _adjList, where_the_object_was );
- } else {
- g_warning("Received a finalization callback for unknown object %p", where_the_object_was );
- }
-}
-
-void UnitTracker::_setActive( gint active )
-{
- if ( active != _active || (_activeUnit == 0) ) {
- gint oldActive = _active;
-
- GtkTreeIter iter;
- gboolean found = gtk_tree_model_iter_nth_child( GTK_TREE_MODEL(_store), &iter, NULL, oldActive );
- if ( found ) {
- SPUnit* unit = 0;
- gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &unit, -1 );
-
- found = gtk_tree_model_iter_nth_child( GTK_TREE_MODEL(_store), &iter, NULL, active );
- if ( found ) {
- SPUnit* newUnit = 0;
- gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &newUnit, -1 );
- _activeUnit = newUnit;
-
- if ( _adjList ) {
- _fixupAdjustments( unit, newUnit );
- }
-
- } else {
- g_warning("Did not find new unit");
- }
- } else {
- g_warning("Did not find old unit");
- }
-
- _active = active;
-
- for ( GSList* cur = _actionList; cur; cur = g_slist_next(cur) ) {
- if ( IS_EGE_SELECT_ONE_ACTION( cur->data ) ) {
- EgeSelectOneAction* act = EGE_SELECT_ONE_ACTION( cur->data );
- ege_select_one_action_set_active( act, active );
- }
- }
- }
-}
-
-void UnitTracker::_fixupAdjustments( SPUnit const* oldUnit, SPUnit const *newUnit )
-{
- _isUpdating = true;
- for ( GSList* cur = _adjList; cur; cur = g_slist_next(cur) ) {
- GtkAdjustment* adj = GTK_ADJUSTMENT(cur->data);
- gdouble oldVal = gtk_adjustment_get_value(adj);
- gdouble val = oldVal;
-
- if ((oldUnit->base == SP_UNIT_ABSOLUTE || oldUnit->base == SP_UNIT_DEVICE)
- && (newUnit->base == SP_UNIT_DIMENSIONLESS))
- {
- val = 1.0 / newUnit->unittobase;
- _priorValues[adj] = sp_units_get_pixels( oldVal, *oldUnit );
- } else if ((oldUnit->base == SP_UNIT_DIMENSIONLESS)
- && (newUnit->base == SP_UNIT_ABSOLUTE || newUnit->base == SP_UNIT_DEVICE)) {
- if ( _priorValues.find(adj) != _priorValues.end() ) {
- val = sp_pixels_get_units( _priorValues[adj], *newUnit );
- }
- } else {
- val = sp_convert_distance_full( oldVal, *oldUnit, *newUnit );
- }
-
- gtk_adjustment_set_value( adj, val );
- }
- _isUpdating = false;
-}
-
-}
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/unit-tracker.h b/src/helper/unit-tracker.h
deleted file mode 100644
index a15a0a6ca..000000000
--- a/src/helper/unit-tracker.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Inkscape::UnitTracker - Simple mediator to synchronize changes to a set
- * of possible units
- *
- * Authors:
- * Jon A. Cruz <jon@joncruz.org>
- *
- * Copyright (C) 2007 Jon A. Cruz
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef SEEN_INKSCAPE_UNIT_TRACKER_H
-#define SEEN_INKSCAPE_UNIT_TRACKER_H
-
-#include <map>
-
-#include <gtk/gtk.h>
-
-#include "helper/units.h"
-
-namespace Inkscape {
-
-class UnitTracker
-{
-public:
- UnitTracker( guint bases = (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE) );
- virtual ~UnitTracker();
-
- void setBase( guint bases ); // SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE
- void addUnit( SPUnitId id, gint index );
-
- bool isUpdating() const;
-
- void setActiveUnit( SPUnit const *unit );
- SPUnit const* getActiveUnit() const;
-
- void addAdjustment( GtkAdjustment* adj );
- void setFullVal( GtkAdjustment* adj, gdouble val );
-
- GtkAction* createAction( gchar const* name, gchar const* label, gchar const* tooltip );
-
-private:
- static void _unitChangedCB( GtkAction* action, gpointer data );
- static void _actionFinalizedCB( gpointer data, GObject *where_the_object_was );
- static void _adjustmentFinalizedCB( gpointer data, GObject *where_the_object_was );
- void _setActive( gint index );
- void _fixupAdjustments( SPUnit const* oldUnit, SPUnit const *newUnit );
- void _actionFinalized( GObject *where_the_object_was );
- void _adjustmentFinalized( GObject *where_the_object_was );
-
- gint _active;
- bool _isUpdating;
- SPUnit* _activeUnit;
- GtkListStore* _store;
- GSList* _unitList;
- GSList* _actionList;
- GSList* _adjList;
- std::map <GtkAdjustment*, gdouble> _priorValues;
-};
-
-}
-
-#endif // SEEN_INKSCAPE_UNIT_TRACKER_H
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/units-test.h b/src/helper/units-test.h
deleted file mode 100644
index 05bc75eff..000000000
--- a/src/helper/units-test.h
+++ /dev/null
@@ -1,90 +0,0 @@
-#include <cxxtest/TestSuite.h>
-
-#include <helper/units.h>
-#include <glibmm/i18n.h>
-#include <math.h>
-
-class UnitsTest : public CxxTest::TestSuite {
-public:
-
- UnitsTest()
- {
- }
- virtual ~UnitsTest() {}
-
-// createSuite and destroySuite get us per-suite setup and teardown
-// without us having to worry about static initialization order, etc.
- static UnitsTest *createSuite() { return new UnitsTest(); }
- static void destroySuite( UnitsTest *suite ) { delete suite; }
-
- void testConversions()
- {
- struct Case { double x; char const *abbr; double pts; } const tests[] = {
- { 1.0, "pt", 1.0 },
- { 5.0, "pt", 5.0 },
- { 1.0, "in", 72.0 },
- { 2.0, "in", 144.0 },
- { 254., "mm", 720.0 },
- { 254., "cm", 7200. },
- { 254., "m", 720000. },
- { 1.5, "mm", (15 * 72. / 254) }
- };
- for (unsigned i = 0; i < G_N_ELEMENTS(tests); ++i) {
- Case const &c = tests[i];
- SPUnit const &unit = *sp_unit_get_by_abbreviation(N_(c.abbr));
-
- double const calc_pts = sp_units_get_points(c.x, unit);
- TS_ASSERT(approx_equal(calc_pts, c.pts));
-
- double const calc_x = sp_points_get_units(c.pts, unit);
- TS_ASSERT(approx_equal(calc_x, c.x));
-
- double tmp = c.x;
- bool const converted_to_pts = sp_convert_distance(&tmp, &unit, SP_PS_UNIT);
- TS_ASSERT(converted_to_pts);
- TS_ASSERT(approx_equal(tmp, c.pts));
-
- tmp = c.pts;
- bool const converted_from_pts = sp_convert_distance(&tmp, SP_PS_UNIT, &unit);
- TS_ASSERT(converted_from_pts);
- TS_ASSERT(approx_equal(tmp, c.x));
- }
- }
-
- void testUnitTable()
- {
- TS_ASSERT(sp_units_table_sane());
- }
-
-private:
- /* N.B. Wrongly returns false if both near 0. (Not a problem for current users.) */
- bool approx_equal(double const x, double const y)
- {
- return fabs(x / y - 1) < 1e-15;
- }
-
- double sp_units_get_points(double const x, SPUnit const &unit)
- {
- SPUnit const &pt_unit = sp_unit_get_by_id(SP_UNIT_PT);
- double const px = sp_units_get_pixels(x, unit);
- return sp_pixels_get_units(px, pt_unit);
- }
-
- double sp_points_get_units(double const pts, SPUnit const &unit)
- {
- SPUnit const &pt_unit = sp_unit_get_by_id(SP_UNIT_PT);
- double const px = sp_units_get_pixels(pts, pt_unit);
- return sp_pixels_get_units(px, unit);
- }
-};
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/units.cpp b/src/helper/units.cpp
deleted file mode 100644
index 1593fc131..000000000
--- a/src/helper/units.cpp
+++ /dev/null
@@ -1,261 +0,0 @@
-#define __SP_PAPER_C__
-
-/*
- * SPUnit
- *
- * Ported from libgnomeprint
- *
- * Authors:
- * Dirk Luetjens <dirk@luedi.oche.de>
- * Yves Arrouye <Yves.Arrouye@marin.fdn.fr>
- * Lauris Kaplinski <lauris@ximian.com>
- * bulia byak <buliabyak@users.sf.net>
- *
- * Copyright 1999-2001 Ximian, Inc. and authors
- *
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "helper/units.h"
-#include <glib.h> // g_assert()
-#include <glibmm/i18n.h>
-#include "unit-constants.h"
-#include "svg/svg-length.h"
-
-/* todo: use some fancy unit program */
-
-/* The order determines the order of the list returned by sp_unit_get_list.
- * (It can also affect string lookups if there are any duplicates in the
- * current locale... hopefully none.) If you re-order this list, then you must
- * also re-order the SPUnitId enum values accordingly. Run `make check' (which
- * calls sp_unit_table_sane) to ensure that the two are in sync.
- */
-SPUnit const sp_units[] = {
- {SP_UNIT_SCALE, SP_UNIT_DIMENSIONLESS, 1.0, SP_NONE, SVGLength::NONE, N_("Unit"), "", N_("Units"), ""},
- {SP_UNIT_PT, SP_UNIT_ABSOLUTE, PX_PER_PT, SP_PT, SVGLength::PT, N_("Point"), N_("pt"), N_("Points"), N_("Pt")},
- {SP_UNIT_PC, SP_UNIT_ABSOLUTE, PX_PER_PC, SP_PC, SVGLength::PC, N_("Pica"), N_("pc"), N_("Picas"), N_("Pc")},
- {SP_UNIT_PX, SP_UNIT_DEVICE, PX_PER_PX, SP_PX, SVGLength::PX, N_("Pixel"), N_("px"), N_("Pixels"), N_("Px")},
- /* You can add new elements from this point forward */
- {SP_UNIT_PERCENT, SP_UNIT_DIMENSIONLESS, 0.01, SP_NONE, SVGLength::PERCENT, N_("Percent"), N_("%"), N_("Percents"), N_("%")},
- {SP_UNIT_MM, SP_UNIT_ABSOLUTE, PX_PER_MM, SP_MM, SVGLength::MM, N_("Millimeter"), N_("mm"), N_("Millimeters"), N_("mm")},
- {SP_UNIT_CM, SP_UNIT_ABSOLUTE, PX_PER_CM, SP_CM, SVGLength::CM, N_("Centimeter"), N_("cm"), N_("Centimeters"), N_("cm")},
- {SP_UNIT_M, SP_UNIT_ABSOLUTE, PX_PER_M, SP_M, SVGLength::NONE, N_("Meter"), N_("m"), N_("Meters"), N_("m")}, // no svg_unit
- {SP_UNIT_IN, SP_UNIT_ABSOLUTE, PX_PER_IN, SP_IN, SVGLength::INCH, N_("Inch"), N_("in"), N_("Inches"), N_("in")},
- {SP_UNIT_FT, SP_UNIT_ABSOLUTE, PX_PER_FT, SP_FT, SVGLength::FOOT, N_("Foot"), N_("ft"), N_("Feet"), N_("ft")},
- /* Volatiles do not have default, so there are none here */
- // TRANSLATORS: for info, see http://www.w3.org/TR/REC-CSS2/syndata.html#length-units
- {SP_UNIT_EM, SP_UNIT_VOLATILE, 1.0, SP_NONE, SVGLength::EM, N_("Em square"), N_("em"), N_("Em squares"), N_("em")},
- // TRANSLATORS: for info, see http://www.w3.org/TR/REC-CSS2/syndata.html#length-units
- {SP_UNIT_EX, SP_UNIT_VOLATILE, 1.0, SP_NONE, SVGLength::EX, N_("Ex square"), N_("ex"), N_("Ex squares"), N_("ex")},
-};
-
-#define sp_num_units G_N_ELEMENTS(sp_units)
-
-SPUnit const *
-sp_unit_get_by_abbreviation(gchar const *abbreviation)
-{
- g_return_val_if_fail(abbreviation != NULL, NULL);
-
- for (unsigned i = 0 ; i < sp_num_units ; i++) {
- if (!g_ascii_strcasecmp(abbreviation, sp_units[i].abbr)) return &sp_units[i];
- if (!g_ascii_strcasecmp(abbreviation, sp_units[i].abbr_plural)) return &sp_units[i];
- }
-
- return NULL;
-}
-
-gchar const *
-sp_unit_get_abbreviation(SPUnit const *unit)
-{
- g_return_val_if_fail(unit != NULL, NULL);
-
- return unit->abbr;
-}
-
-gchar const *
-sp_unit_get_plural (SPUnit const *unit)
-{
- g_return_val_if_fail(unit != NULL, NULL);
-
- return unit->plural;
-}
-
-SPMetric sp_unit_get_metric(SPUnit const *unit)
-{
- g_return_val_if_fail(unit != NULL, SP_NONE);
-
- return unit->metric;
-}
-
-guint sp_unit_get_svg_unit(SPUnit const *unit)
-{
- g_return_val_if_fail(unit != NULL, SP_NONE);
-
- return unit->svg_unit;
-}
-
-GSList *
-sp_unit_get_list(guint bases)
-{
- g_return_val_if_fail((bases & ~SP_UNITS_ALL) == 0, NULL);
-
- GSList *units = NULL;
- for (unsigned i = sp_num_units ; i--; ) {
- if (bases & sp_units[i].base) {
- units = g_slist_prepend(units, (gpointer) &sp_units[i]);
- }
- }
-
- return units;
-}
-
-void
-sp_unit_free_list(GSList *units)
-{
- g_slist_free(units);
-}
-
-/* These are pure utility */
-/* Return TRUE if conversion is possible */
-gboolean
-sp_convert_distance(gdouble *distance, SPUnit const *from, SPUnit const *to)
-{
- g_return_val_if_fail(distance != NULL, FALSE);
- g_return_val_if_fail(from != NULL, FALSE);
- g_return_val_if_fail(to != NULL, FALSE);
-
- if (from == to) return TRUE;
- if ((from->base == SP_UNIT_DIMENSIONLESS) || (to->base == SP_UNIT_DIMENSIONLESS)) {
- *distance = *distance * from->unittobase / to->unittobase;
- return TRUE;
- }
- if ((from->base == SP_UNIT_VOLATILE) || (to->base == SP_UNIT_VOLATILE)) return FALSE;
-
- if ((from->base == to->base)
- || ((from->base == SP_UNIT_DEVICE) && (to->base == SP_UNIT_ABSOLUTE))
- || ((from->base == SP_UNIT_ABSOLUTE) && (to->base == SP_UNIT_DEVICE)))
- {
- *distance = *distance * from->unittobase / to->unittobase;
- return TRUE;
- }
-
- return FALSE;
-}
-
-/** @param devicetransform for device units. */
-/* TODO: Remove the ctmscale parameter given that we no longer have SP_UNIT_USERSPACE. */
-gdouble
-sp_convert_distance_full(gdouble const from_dist, SPUnit const &from, SPUnit const &to)
-{
- if (&from == &to) {
- return from_dist;
- }
- if (from.base == to.base) {
- gdouble ret = from_dist;
- bool const succ = sp_convert_distance(&ret, &from, &to);
- g_assert(succ);
- return ret;
- }
- if ((from.base == SP_UNIT_DIMENSIONLESS)
- || (to.base == SP_UNIT_DIMENSIONLESS))
- {
- return from_dist * from.unittobase / to.unittobase;
- }
- g_return_val_if_fail(((from.base != SP_UNIT_VOLATILE)
- && (to.base != SP_UNIT_VOLATILE)),
- from_dist);
-
- gdouble absolute;
- switch (from.base) {
- case SP_UNIT_ABSOLUTE:
- case SP_UNIT_DEVICE:
- absolute = from_dist * from.unittobase;
- break;
- default:
- g_warning("file %s: line %d: Illegal unit (base 0x%x)", __FILE__, __LINE__, from.base);
- return from_dist;
- }
-
- gdouble ret;
- switch (to.base) {
- default:
- g_warning("file %s: line %d: Illegal unit (base 0x%x)", __FILE__, __LINE__, to.base);
- /* FALL-THROUGH */
- case SP_UNIT_ABSOLUTE:
- case SP_UNIT_DEVICE:
- ret = absolute / to.unittobase;
- break;
- }
-
- return ret;
-}
-
-/* Some more convenience */
-
-gdouble
-sp_units_get_pixels(gdouble const units, SPUnit const &unit)
-{
- if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
- return units * unit.unittobase;
- } else {
- g_warning("Different unit bases: No exact unit conversion available");
- return units * unit.unittobase;
- }
-}
-
-gdouble
-sp_pixels_get_units(gdouble const pixels, SPUnit const &unit)
-{
- if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
- return pixels / unit.unittobase;
- } else {
- g_warning("Different unit bases: No exact unit conversion available");
- return pixels / unit.unittobase;
- }
-}
-
-bool
-sp_units_table_sane()
-{
- for (unsigned i = 0; i < G_N_ELEMENTS(sp_units); ++i) {
- if (unsigned(sp_units[i].unit_id) != i) {
- return false;
- }
- }
- return true;
-}
-
-/** Converts angle (in deg) to compass display */
-double
-angle_to_compass(double angle)
-{
- double ret = 90 - angle;
- if (ret < 0)
- ret = 360 + ret;
- return ret;
-}
-
-/** Converts angle (in deg) to compass display */
-double
-angle_from_compass(double angle)
-{
- double ret = 90 - angle;
- if (ret > 180)
- ret = ret - 180;
- return ret;
-}
-
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/units.h b/src/helper/units.h
deleted file mode 100644
index 93bd70615..000000000
--- a/src/helper/units.h
+++ /dev/null
@@ -1,146 +0,0 @@
-#ifndef __SP_UNIT_H__
-#define __SP_UNIT_H__
-
-/*
- * SPUnit
- *
- * Ported from libgnomeprint
- *
- * Authors:
- * Dirk Luetjens <dirk@luedi.oche.de>
- * Yves Arrouye <Yves.Arrouye@marin.fdn.fr>
- * Lauris Kaplinski <lauris@ximian.com>
- *
- * Copyright 1999-2001 Ximian, Inc. and authors
- *
- */
-
-#include <glib.h>
-#include "sp-metric.h"
-
-
-/*
- * Units and conversion methods used by libgnomeprint.
- *
- * You need those for certain config keys (like paper size), if you are
- * interested in using these (look at gnome-print-config.h for discussion,
- * why you may NOT be interested in paper size).
- *
- * Unit bases define set of mutually unrelated measuring systems (numbers,
- * paper, screen and dimesionless user coordinates). Still, you can convert
- * between those, specifying scaling factors explicitly.
- *
- * Paper (i.e. output) coordinates are taken as absolute real world units.
- * It has some justification, because screen unit (pixel) size changes,
- * if you change screen resolution, while you cannot change output on paper
- * as easily (unless you have thermally contracting paper, of course).
- *
- */
-
-struct SPUnit;
-struct SPDistance;
-
-/*
- * The base linear ("absolute") unit is 1/72th of an inch, i.e. the base unit of postscript.
- */
-
-/*
- * Unit bases
- */
-enum SPUnitBase {
- SP_UNIT_DIMENSIONLESS = (1 << 0), /* For percentages and like */
- SP_UNIT_ABSOLUTE = (1 << 1), /* Real world distances - i.e. mm, cm... */
- SP_UNIT_DEVICE = (1 << 2), /* Pixels in the SVG/CSS sense. */
- SP_UNIT_VOLATILE = (1 << 3) /* em and ex */
-};
-
-/*
- * Units: indexes into sp_units.
- */
-enum SPUnitId {
- SP_UNIT_SCALE, // 1.0 == 100%
- SP_UNIT_PT, // Postscript points: exactly 72 per inch
- SP_UNIT_PC, // Pica; there are 12 points per pica
- SP_UNIT_PX, // "Pixels" in the CSS sense; though Inkscape assumes a constant 90 per inch.
- SP_UNIT_PERCENT, /* Note: In Inkscape this often means "relative to current value" (for
- users to edit a value), rather than the SVG/CSS use of percentages. */
- SP_UNIT_MM, // millimetres
- SP_UNIT_CM, // centimetres
- SP_UNIT_M, // metres
- SP_UNIT_IN, // inches
- SP_UNIT_FT, // foot
- SP_UNIT_EM, // font-size of relevant font
- SP_UNIT_EX, // x-height of relevant font
- sp_max_unit_id = SP_UNIT_EX // For bounds-checking in sp_unit_get_by_id.
-};
-
-/*
- * Notice, that for correct menus etc. you have to use
- * ngettext method family yourself. For that reason we
- * do not provide translations in unit names.
- * I also do not know, whether to allow user-created units,
- * because this would certainly confuse textdomain.
- */
-
-struct SPUnit {
- SPUnitId unit_id; /* used as sanity check */
- SPUnitBase base;
- gdouble unittobase; /* how many base units in this unit */
- SPMetric metric; // the corresponding SPMetric from sp-metrics.h
- guint svg_unit; // the corresponding SVGLengthUnit
-
- /* When using, you must call "gettext" on them so they're translated */
- gchar const *name;
- gchar const *abbr;
- gchar const *plural;
- gchar const *abbr_plural;
-};
-
-const SPUnit *sp_unit_get_by_abbreviation (const gchar *abbreviation);
-/* When using, you must call "gettext" on them so they're translated */
-const gchar *sp_unit_get_abbreviation (const SPUnit *unit);
-gchar const *sp_unit_get_plural (SPUnit const *unit);
-
-SPMetric sp_unit_get_metric(SPUnit const *unit);
-guint sp_unit_get_svg_unit(SPUnit const *unit);
-
-extern SPUnit const sp_units[];
-
-inline SPUnit const &
-sp_unit_get_by_id(SPUnitId const id)
-{
- /* inline because the compiler should optimize away the g_return_val_if_fail test in the
- usual case that the argument value is known at compile-time, leaving just
- "return sp_units[constant]". */
- unsigned const ix = unsigned(id);
- g_return_val_if_fail(ix <= sp_max_unit_id, sp_units[SP_UNIT_PX]);
- return sp_units[ix];
-}
-
-#define SP_PS_UNIT (&sp_unit_get_by_id(SP_UNIT_PT))
-
-
-/** Used solely by units-test.cpp. */
-bool sp_units_table_sane();
-
-#define SP_UNITS_ALL (SP_UNIT_DIMENSIONLESS | SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE | SP_UNIT_VOLATILE)
-
-GSList *sp_unit_get_list (guint bases);
-void sp_unit_free_list (GSList *units);
-
-/* These are pure utility */
-/* Return TRUE if conversion is possible, FALSE if unit bases differ */
-gboolean sp_convert_distance (gdouble *distance, const SPUnit *from, const SPUnit *to);
-
-/* If either one is NULL, transconverting to/from that base fails */
-/* Generic conversion between volatile units would be useless anyways */
-gdouble sp_convert_distance_full(gdouble const from_dist, SPUnit const &from, SPUnit const &to);
-
-/* Some more convenience */
-gdouble sp_units_get_pixels(gdouble const units, SPUnit const &unit);
-gdouble sp_pixels_get_units(gdouble const pixels, SPUnit const &unit);
-
-double angle_to_compass(double angle);
-double angle_from_compass(double angle);
-
-#endif
diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp
index d3edcda27..4ca380c15 100644
--- a/src/live_effects/lpe-path_length.cpp
+++ b/src/live_effects/lpe-path_length.cpp
@@ -14,7 +14,7 @@
#include <glibmm/i18n.h>
#include "live_effects/lpe-path_length.h"
-#include "sp-metrics.h"
+#include "util/units.h"
#include "2geom/sbasis-geometric.h"
@@ -52,11 +52,11 @@ LPEPathLength::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & p
/* convert the measured length to the correct unit ... */
double lengthval = Geom::length(pwd2_in) * scale;
- gboolean success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), unit);
+ lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit.get_abbreviation());
/* ... set it as the canvas text ... */
gchar *arc_length = g_strdup_printf("%.2f %s", lengthval,
- display_unit ? (success ? unit.get_abbreviation() : "px") : "");
+ display_unit ? unit.get_abbreviation() : "");
info_text.param_setValue(arc_length);
g_free(arc_length);
diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp
index fefdad95a..788ab593a 100644
--- a/src/live_effects/lpe-ruler.cpp
+++ b/src/live_effects/lpe-ruler.cpp
@@ -81,9 +81,9 @@ LPERuler::ruler_mark(Geom::Point const &A, Geom::Point const &n, MarkType const
using namespace Geom;
double real_mark_length = mark_length;
- sp_convert_distance(&real_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_mark_length = Inkscape::Util::Quantity::convert(real_mark_length, unit.get_abbreviation(), "px");
double real_minor_mark_length = minor_mark_length;
- sp_convert_distance(&real_minor_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_minor_mark_length = Inkscape::Util::Quantity::convert(real_minor_mark_length, unit.get_abbreviation(), "px");
n_major = real_mark_length * n;
n_minor = real_minor_mark_length * n;
@@ -133,10 +133,10 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_i
std::vector<double> s_cuts;
double real_mark_distance = mark_distance;
- sp_convert_distance(&real_mark_distance, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_mark_distance = Inkscape::Util::Quantity::convert(real_mark_distance, unit.get_abbreviation(), "px");
double real_offset = offset;
- sp_convert_distance(&real_offset, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_offset = Inkscape::Util::Quantity::convert(real_offset, unit.get_abbreviation(), "px");
for (double s = real_offset; s<totlength; s+=real_mark_distance){
s_cuts.push_back(s);
}
diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp
index 602d806a0..561766920 100644
--- a/src/live_effects/parameter/unit.cpp
+++ b/src/live_effects/parameter/unit.cpp
@@ -10,6 +10,9 @@
#include "live_effects/parameter/unit.h"
#include "live_effects/effect.h"
#include "verbs.h"
+#include "util/units.h"
+
+using Inkscape::Util::unit_table;
namespace Inkscape {
@@ -18,10 +21,10 @@ namespace LivePathEffect {
UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip,
const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
- Effect* effect, SPUnitId default_value)
+ Effect* effect, Glib::ustring default_unit)
: Parameter(label, tip, key, wr, effect)
{
- defunit = &sp_unit_get_by_id(default_value);;
+ defunit = new Inkscape::Util::Unit(unit_table.getUnit(default_unit));
unit = defunit;
}
@@ -32,9 +35,8 @@ UnitParam::~UnitParam()
bool
UnitParam::param_readSVGValue(const gchar * strvalue)
{
- SPUnit const *newval = sp_unit_get_by_abbreviation(strvalue);
- if (newval) {
- param_set_value(newval);
+ if (strvalue) {
+ param_set_value(unit_table.getUnit(strvalue));
return true;
}
return false;
@@ -43,25 +45,25 @@ UnitParam::param_readSVGValue(const gchar * strvalue)
gchar *
UnitParam::param_getSVGValue() const
{
- return g_strdup(sp_unit_get_abbreviation(unit));
+ return g_strdup(unit->abbr.c_str());
}
void
UnitParam::param_set_default()
{
- param_set_value(defunit);
+ param_set_value(*defunit);
}
void
-UnitParam::param_set_value(SPUnit const *val)
+UnitParam::param_set_value(Inkscape::Util::Unit const &val)
{
- unit = val;
+ unit = new Inkscape::Util::Unit(val);
}
const gchar *
UnitParam::get_abbreviation() const
{
- return sp_unit_get_abbreviation(unit);
+ return unit->abbr.c_str();
}
Gtk::Widget *
@@ -74,7 +76,7 @@ UnitParam::param_newWidget()
param_effect->getRepr(),
param_effect->getSPDoc()));
- unit_menu->setUnit(unit);
+ unit_menu->setUnit(unit->abbr);
unit_menu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change unit parameter"));
return dynamic_cast<Gtk::Widget *> (unit_menu);
diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h
index ea7a0112a..59a483018 100644
--- a/src/live_effects/parameter/unit.h
+++ b/src/live_effects/parameter/unit.h
@@ -10,10 +10,13 @@
*/
#include "live_effects/parameter/parameter.h"
-#include <helper/units.h>
namespace Inkscape {
+namespace Util {
+ class Unit;
+}
+
namespace LivePathEffect {
class UnitParam : public Parameter {
@@ -23,22 +26,22 @@ public:
const Glib::ustring& key,
Inkscape::UI::Widget::Registry* wr,
Effect* effect,
- SPUnitId default_value = SP_UNIT_PX);
+ Glib::ustring default_unit = "px");
virtual ~UnitParam();
virtual bool param_readSVGValue(const gchar * strvalue);
virtual gchar * param_getSVGValue() const;
virtual void param_set_default();
- void param_set_value(SPUnit const *val);
+ void param_set_value(Inkscape::Util::Unit const &val);
const gchar *get_abbreviation() const;
virtual Gtk::Widget * param_newWidget();
- operator SPUnit const *() const { return unit; }
+ operator Inkscape::Util::Unit const *() const { return unit; }
private:
- SPUnit const *unit;
- SPUnit const *defunit;
+ Inkscape::Util::Unit const *unit;
+ Inkscape::Util::Unit const *defunit;
UnitParam(const UnitParam&);
UnitParam& operator=(const UnitParam&);
diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp
index e7393b97b..062a75a7b 100644
--- a/src/lpe-tool-context.cpp
+++ b/src/lpe-tool-context.cpp
@@ -37,10 +37,12 @@
#include "display/canvas-text.h"
#include "message-stack.h"
#include "sp-path.h"
-#include "helper/units.h"
+#include "util/units.h"
#include "lpe-tool-context.h"
+using Inkscape::Util::unit_table;
+
static void sp_lpetool_context_dispose(GObject *object);
static void sp_lpetool_context_setup(SPEventContext *ec);
@@ -453,13 +455,16 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select
if (!show)
sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text));
- SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX));
- SPUnit unit = sp_unit_get_by_id(unitid);
+ Inkscape::Util::Unit unit;
+ if (prefs->getString("/tools/lpetool/unit").compare("")) {
+ unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit"));
+ } else {
+ unit = unit_table.getUnit("px");
+ }
lengthval = Geom::length(pwd2);
- gboolean success;
- success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
- arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px");
+ lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
+ arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str());
sp_canvastext_set_text (canvas_text, arc_length);
set_pos_and_anchor(canvas_text, pwd2, 0.5, 10);
// TODO: must we free arc_length?
@@ -489,12 +494,15 @@ lpetool_update_measuring_items(SPLPEToolContext *lc)
SPPath *path = i->first;
SPCurve *curve = SP_SHAPE(path)->getCurve();
Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = Geom::paths_to_pw(curve->get_pathvector());
- SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX));
- SPUnit unit = sp_unit_get_by_id(unitid);
+ Inkscape::Util::Unit unit;
+ if (prefs->getString("/tools/lpetool/unit").compare("")) {
+ unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit"));
+ } else {
+ unit = unit_table.getUnit("px");
+ }
double lengthval = Geom::length(pwd2);
- gboolean success;
- success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
- gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px");
+ lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
+ gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str());
sp_canvastext_set_text (SP_CANVASTEXT(i->second), arc_length);
set_pos_and_anchor(SP_CANVASTEXT(i->second), pwd2, 0.5, 10);
// TODO: must we free arc_length?
diff --git a/src/lpe-tool-context.h b/src/lpe-tool-context.h
index fb3a5d4e2..7b85b09f2 100644
--- a/src/lpe-tool-context.h
+++ b/src/lpe-tool-context.h
@@ -16,7 +16,6 @@
*/
#include "pen-context.h"
-#include "helper/units.h"
#define SP_TYPE_LPETOOL_CONTEXT (sp_lpetool_context_get_type())
#define SP_LPETOOL_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_LPETOOL_CONTEXT, SPLPEToolContext))
diff --git a/src/main.cpp b/src/main.cpp
index d425b88bb..29f431aa8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -68,7 +68,6 @@
#include "color.h"
#include "sp-item.h"
#include "sp-root.h"
-#include "unit-constants.h"
#include "svg/svg.h"
#include "svg/svg-color.h"
@@ -1524,7 +1523,7 @@ static int sp_do_export_png(SPDocument *doc)
// default dpi
if (dpi == 0.0) {
- dpi = PX_PER_IN;
+ dpi = Inkscape::Util::Quantity::convert(1, "in", "px");
}
unsigned long int width = 0;
@@ -1537,7 +1536,7 @@ static int sp_do_export_png(SPDocument *doc)
g_warning("Export width %lu out of range (1 - %lu). Nothing exported.", width, (unsigned long int)PNG_UINT_31_MAX);
return 1;
}
- dpi = (gdouble) width * PX_PER_IN / area.width();
+ dpi = (gdouble) width * Inkscape::Util::Quantity::convert(1, "in", "px") / area.width();
}
if (sp_export_height) {
@@ -1547,15 +1546,15 @@ static int sp_do_export_png(SPDocument *doc)
g_warning("Export height %lu out of range (1 - %lu). Nothing exported.", height, (unsigned long int)PNG_UINT_31_MAX);
return 1;
}
- dpi = (gdouble) height * PX_PER_IN / area.height();
+ dpi = (gdouble) height * Inkscape::Util::Quantity::convert(1, "in", "px") / area.height();
}
if (!sp_export_width) {
- width = (unsigned long int) (area.width() * dpi / PX_PER_IN + 0.5);
+ width = (unsigned long int) (area.width() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5);
}
if (!sp_export_height) {
- height = (unsigned long int) (area.height() * dpi / PX_PER_IN + 0.5);
+ height = (unsigned long int) (area.height() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5);
}
guint32 bgcolor = 0x00000000;
diff --git a/src/measure-context.cpp b/src/measure-context.cpp
index 771125b7f..37e87d3d9 100644
--- a/src/measure-context.cpp
+++ b/src/measure-context.cpp
@@ -13,7 +13,7 @@
#include <gdk/gdkkeysyms.h>
#include <boost/none_t.hpp>
-#include "helper/units.h"
+#include "util/units.h"
#include "macros.h"
#include "display/curve.h"
#include "sp-shape.h"
@@ -46,6 +46,7 @@
using Inkscape::ControlManager;
using Inkscape::CTLINE_SECONDARY;
+using Inkscape::Util::unit_table;
static void sp_measure_context_setup(SPEventContext *ec);
static void sp_measure_context_finish(SPEventContext *ec);
@@ -514,8 +515,10 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
std::sort(intersections.begin(), intersections.end(), GeomPointSortPredicate);
}
- SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/measure/unitid", SP_UNIT_PX));
- SPUnit unit = sp_unit_get_by_id(unitid);
+ Glib::ustring unit_name = prefs->getString("/tools/measure/unit");
+ if (!unit_name.compare("")) {
+ unit_name = "px";
+ }
double fontsize = prefs->getInt("/tools/measure/fontsize");
@@ -526,7 +529,7 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
for (size_t idx = 1; idx < intersections.size(); ++idx) {
LabelPlacement placement;
placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length();
- sp_convert_distance(&placement.lengthVal, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
+ placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, "px", unit_name);
placement.offset = DIMENSION_OFFSET;
placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 );
placement.end = placement.start - (normal * placement.offset);
@@ -542,7 +545,7 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
LabelPlacement &place = *it;
// TODO cleanup memory, Glib::ustring, etc.:
- gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit.abbr);
+ gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit_name.c_str());
SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),
desktop,
place.end,
@@ -583,10 +586,10 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
{
double totallengthval = (end_point - start_point).length();
- sp_convert_distance(&totallengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
+ totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name);
// TODO cleanup memory, Glib::ustring, etc.:
- gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr);
+ gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str());
SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),
desktop,
end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)),
@@ -604,10 +607,10 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv
if (intersections.size() > 2) {
double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length();
- sp_convert_distance(&totallengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
+ totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name);
// TODO cleanup memory, Glib::ustring, etc.:
- gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr);
+ gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str());
SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop),
desktop,
desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60,
diff --git a/src/pen-context.cpp b/src/pen-context.cpp
index 5972a6ca8..69abf3513 100644
--- a/src/pen-context.cpp
+++ b/src/pen-context.cpp
@@ -22,7 +22,6 @@
#include "pen-context.h"
#include "sp-namedview.h"
-#include "sp-metrics.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "selection.h"
@@ -39,7 +38,6 @@
#include "display/sp-ctrlline.h"
#include "display/sodipodi-ctrl.h"
#include <glibmm/i18n.h>
-#include "helper/units.h"
#include "macros.h"
#include "context-fns.h"
#include "tools-switch.h"
@@ -1185,11 +1183,16 @@ static void spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, G
SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop;
Geom::Point rel = p - pc->p[pc_point_to_compare];
- GString *dist = SP_PX_TO_METRIC_STRING(Geom::L2(rel), desktop->namedview->getDefaultMetric());
+ Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px");
+ GString *dist = g_string_new(q.string(*desktop->namedview->doc_units).c_str());
double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- if (prefs->getBool("/options/compassangledisplay/value", 0) != 0)
- angle = angle_to_compass (angle);
+ if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) {
+ angle = 90 - angle;
+ if (angle < 0) {
+ angle += 360;
+ }
+ }
pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str);
g_string_free(dist, FALSE);
diff --git a/src/preferences.cpp b/src/preferences.cpp
index 1d7009a99..0dc6f1ec4 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -28,6 +28,8 @@
#define PREFERENCES_FILE_NAME "preferences.xml"
+using Inkscape::Util::unit_table;
+
namespace Inkscape {
static Inkscape::XML::Document *loadImpl( std::string const& prefsFilename, Glib::ustring & errMsg );
@@ -777,8 +779,6 @@ double Preferences::_extractDouble(Entry const &v)
double Preferences::_extractDouble(Entry const &v, Glib::ustring const &requested_unit)
{
- static Inkscape::Util::UnitTable unit_table; // load the unit_table once by making it static
-
double val = _extractDouble(v);
Glib::ustring unit = _extractUnit(v);
diff --git a/src/rect-context.cpp b/src/rect-context.cpp
index 06745564f..17675745f 100644
--- a/src/rect-context.cpp
+++ b/src/rect-context.cpp
@@ -35,7 +35,6 @@
#include "message-context.h"
#include "pixmaps/cursor-rect.xpm"
#include "rect-context.h"
-#include "sp-metrics.h"
#include <glibmm/i18n.h>
#include "xml/repr.h"
#include "xml/node-event-vector.h"
@@ -483,8 +482,10 @@ static void sp_rect_drag(SPRectContext &rc, Geom::Point const pt, guint state)
// status text
double rdimx = r.dimensions()[Geom::X];
double rdimy = r.dimensions()[Geom::Y];
- GString *xs = SP_PX_TO_METRIC_STRING(rdimx, desktop->namedview->getDefaultMetric());
- GString *ys = SP_PX_TO_METRIC_STRING(rdimy, desktop->namedview->getDefaultMetric());
+ Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px");
+ Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px");
+ GString *xs = g_string_new(rdimx_q.string(*desktop->namedview->doc_units).c_str());
+ GString *ys = g_string_new(rdimy_q.string(*desktop->namedview->doc_units).c_str());
if (state & GDK_CONTROL_MASK) {
int ratio_x, ratio_y;
bool is_golden_ratio = false;
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp
index 29cb208d9..5976555f4 100644
--- a/src/selection-chemistry.cpp
+++ b/src/selection-chemistry.cpp
@@ -86,11 +86,10 @@ SPCycleType SP_CYCLING = SP_CYCLE_FOCUS;
#include <map>
#include <cstring>
#include <string>
-#include "helper/units.h"
#include "sp-item.h"
#include "box3d.h"
#include "persp3d.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include "xml/simple-document.h"
#include "sp-filter-reference.h"
#include "gradient-drag.h"
@@ -3398,7 +3397,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop)
res = prefs_res;
} else if (0 < prefs_min) {
// If minsize is given, look up minimum bitmap size (default 250 pixels) and calculate resolution from it
- res = PX_PER_IN * prefs_min / MIN(bbox->width(), bbox->height());
+ res = Inkscape::Util::Quantity::convert(1, "in", "px") * prefs_min / MIN(bbox->width(), bbox->height());
} else {
float hint_xdpi = 0, hint_ydpi = 0;
Glib::ustring hint_filename;
@@ -3413,14 +3412,14 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop)
res = hint_xdpi;
} else {
// if all else fails, take the default 90 dpi
- res = PX_PER_IN;
+ res = Inkscape::Util::Quantity::convert(1, "in", "px");
}
}
}
// The width and height of the bitmap in pixels
- unsigned width = (unsigned) floor(bbox->width() * res / PX_PER_IN);
- unsigned height =(unsigned) floor(bbox->height() * res / PX_PER_IN);
+ unsigned width = (unsigned) floor(bbox->width() * res / Inkscape::Util::Quantity::convert(1, "in", "px"));
+ unsigned height =(unsigned) floor(bbox->height() * res / Inkscape::Util::Quantity::convert(1, "in", "px"));
// Find out if we have to run an external filter
gchar const *run = NULL;
@@ -3452,7 +3451,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop)
double shift_x = bbox->min()[Geom::X];
double shift_y = bbox->max()[Geom::Y];
- if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid
+ if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { // for default 90 dpi, snap it to pixel grid
shift_x = round(shift_x);
shift_y = -round(-shift_y); // this gets correct rounding despite coordinate inversion, remove the negations when the inversion is gone
}
@@ -3485,7 +3484,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop)
// Create the repr for the image
Inkscape::XML::Node * repr = xml_doc->createElement("svg:image");
sp_embed_image(repr, pb, "image/png");
- if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid
+ if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { // for default 90 dpi, snap it to pixel grid
sp_repr_set_svg_double(repr, "width", width);
sp_repr_set_svg_double(repr, "height", height);
} else {
diff --git a/src/seltrans.cpp b/src/seltrans.cpp
index 33bfe3e4a..f614853bc 100644
--- a/src/seltrans.cpp
+++ b/src/seltrans.cpp
@@ -37,7 +37,6 @@
#include "seltrans-handles.h"
#include "seltrans.h"
#include "selection-chemistry.h"
-#include "sp-metrics.h"
#include "verbs.h"
#include <glibmm/i18n.h>
#include "display/sp-ctrlline.h"
@@ -1273,8 +1272,10 @@ gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state)
m.unSetup();
// status text
- GString *xs = SP_PX_TO_METRIC_STRING(pt[Geom::X], _desktop->namedview->getDefaultMetric());
- GString *ys = SP_PX_TO_METRIC_STRING(pt[Geom::Y], _desktop->namedview->getDefaultMetric());
+ Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(pt[Geom::X], "px");
+ Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(pt[Geom::Y], "px");
+ GString *xs = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
+ GString *ys = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
_message_context.setF(Inkscape::NORMAL_MESSAGE, _("Move <b>center</b> to %s, %s"), xs->str, ys->str);
g_string_free(xs, FALSE);
g_string_free(ys, FALSE);
@@ -1425,8 +1426,10 @@ void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state)
transform(move, norm);
// status text
- GString *xs = SP_PX_TO_METRIC_STRING(dxy[Geom::X], _desktop->namedview->getDefaultMetric());
- GString *ys = SP_PX_TO_METRIC_STRING(dxy[Geom::Y], _desktop->namedview->getDefaultMetric());
+ Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dxy[Geom::X], "px");
+ Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dxy[Geom::Y], "px");
+ GString *xs = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
+ GString *ys = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
_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);
g_string_free(xs, TRUE);
g_string_free(ys, TRUE);
diff --git a/src/snap-preferences.h b/src/snap-preferences.h
index c2db0b432..a7a2e2926 100644
--- a/src/snap-preferences.h
+++ b/src/snap-preferences.h
@@ -10,7 +10,6 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-#include "helper/units.h"
#include "snap-enums.h"
namespace Inkscape
diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp
index 48596cbc0..961e53e04 100644
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
@@ -35,7 +35,6 @@
#include <glibmm/i18n.h>
#include <xml/repr.h>
#include <remove-last.h>
-#include "sp-metrics.h"
#include "inkscape.h"
#include "desktop.h"
#include "sp-namedview.h"
@@ -463,10 +462,10 @@ char *sp_guide_description(SPGuide const *guide, const bool verbose)
} else {
SPNamedView *namedview = sp_document_namedview(guide->document, NULL);
- GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X],
- namedview->getDefaultMetric());
- GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y],
- namedview->getDefaultMetric());
+ Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(guide->point_on_line[X], "px");
+ Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(guide->point_on_line[Y], "px");
+ GString *position_string_x = g_string_new(x_q.string(*namedview->doc_units).c_str());
+ GString *position_string_y = g_string_new(y_q.string(*namedview->doc_units).c_str());
gchar *shortcuts = g_strdup_printf("; %s", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete"));
diff --git a/src/sp-metric.h b/src/sp-metric.h
deleted file mode 100644
index 31f3330fa..000000000
--- a/src/sp-metric.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef INKSCAPE_SP_METRIC_H
-#define INKSCAPE_SP_METRIC_H
-
-/** Known metrics so far. (I don't know why this doesn't include pica.) */
-enum SPMetric {
- SP_NONE,
- SP_MM,
- SP_CM,
- SP_IN,
- SP_FT,
- SP_PT,
- SP_PC,
- SP_PX,
- SP_M
-};
-
-#endif /* !INKSCAPE_SP_METRIC_H */
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/sp-metrics.cpp b/src/sp-metrics.cpp
deleted file mode 100644
index 2b421cf05..000000000
--- a/src/sp-metrics.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-#include "sp-metrics.h"
-#include "unit-constants.h"
-
-/*
- * SPMetric handling and stuff
- * I hope this will be usefull :-)
- */
-
-gdouble
-sp_absolute_metric_to_metric (gdouble length_src, const SPMetric metric_src, const SPMetric metric_dst)
-{
- gdouble src = 1;
- gdouble dst = 1;
-
- switch (metric_src) {
- case SP_M:
- src = M_PER_IN;
- break;
- case SP_MM:
- src = MM_PER_IN;
- break;
- case SP_CM:
- src = CM_PER_IN;
- break;
- case SP_IN:
- src = IN_PER_IN;
- break;
- case SP_FT:
- src = FT_PER_IN;
- break;
- case SP_PT:
- src = PT_PER_IN;
- break;
- case SP_PC:
- src = PC_PER_IN;
- break;
- case SP_PX:
- src = PX_PER_IN;
- break;
- case SP_NONE:
- src = 1;
- break;
- }
-
- switch (metric_dst) {
- case SP_M:
- dst = M_PER_IN;
- break;
- case SP_MM:
- dst = MM_PER_IN;
- break;
- case SP_CM:
- dst = CM_PER_IN;
- break;
- case SP_IN:
- dst = IN_PER_IN;
- break;
- case SP_FT:
- dst = FT_PER_IN;
- break;
- case SP_PT:
- dst = PT_PER_IN;
- break;
- case SP_PC:
- dst = PC_PER_IN;
- break;
- case SP_PX:
- dst = PX_PER_IN;
- break;
- case SP_NONE:
- dst = 1;
- break;
- }
-
- return length_src * (dst/src);
-}
-
-/**
- * Create a human-readable string suitable for status-bar display.
- */
-GString *
-sp_metric_to_metric_string(gdouble const length,
- SPMetric const metric_src, SPMetric const metric_dst,
- gboolean const m)
-{
- gdouble const len = sp_absolute_metric_to_metric(length, metric_src, metric_dst);
- GString *str = g_string_new("");
- g_string_printf(str, "%0.02f", len);
- /* We need a fixed number of fractional digits, because otherwise the live statusbar display of
- * lengths will be too jerky */
-
- if (m) {
- char const *unit_str;
- switch (metric_dst) {
- case SP_M: unit_str = " m"; break;
- case SP_MM: unit_str = " mm"; break;
- case SP_CM: unit_str = " cm"; break;
- case SP_IN: unit_str = "\""; break;
- case SP_PT: unit_str = " pt"; break;
- case SP_PX: unit_str = " px"; break;
- default: unit_str = NULL; break;
- }
- if (unit_str) {
- g_string_append(str, unit_str);
- }
- }
- return str;
-}
-
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/sp-metrics.h b/src/sp-metrics.h
deleted file mode 100644
index c2f968797..000000000
--- a/src/sp-metrics.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef SP_METRICS_H
-#define SP_METRICS_H
-
-#include <glib.h>
-#include "sp-metric.h"
-
-gdouble sp_absolute_metric_to_metric (gdouble length_src, const SPMetric metric_src, const SPMetric metric_dst);
-GString * sp_metric_to_metric_string (gdouble length, const SPMetric metric_src, const SPMetric metric_dst, gboolean m);
-
-// convenience since we mostly deal with points
-#define SP_METRIC_TO_PT(l,m) sp_absolute_metric_to_metric(l,m,SP_PT);
-#define SP_PT_TO_METRIC(l,m) sp_absolute_metric_to_metric(l,SP_PT,m);
-
-#define SP_PT_TO_METRIC_STRING(l,m) sp_metric_to_metric_string(l, SP_PT, m, TRUE)
-#define SP_PT_TO_STRING(l,m) sp_metric_to_metric_string(l, SP_PT, m, FALSE)
-
-#define SP_PX_TO_METRIC_STRING(l,m) sp_metric_to_metric_string(l, SP_PX, m, TRUE)
-#define SP_PX_TO_STRING(l,m) sp_metric_to_metric_string(l, SP_PX, m, FALSE)
-
-#endif
diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp
index 452f57425..48f8eba2a 100644
--- a/src/sp-namedview.cpp
+++ b/src/sp-namedview.cpp
@@ -22,7 +22,7 @@
#include "display/canvas-grid.h"
#include "display/guideline.h"
-#include "helper/units.h"
+#include "util/units.h"
#include "svg/svg-color.h"
#include "xml/repr.h"
#include "attributes.h"
@@ -40,6 +40,7 @@
#include <gtkmm/window.h>
using Inkscape::DocumentUndo;
+using Inkscape::Util::unit_table;
#define DEFAULTGRIDCOLOR 0x3f3fff25
#define DEFAULTGRIDEMPCOLOR 0x3f3fff60
@@ -549,18 +550,19 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va
* in that they aren't in general absolute units as currently required by
* doc_units.
*/
- SPUnit const *new_unit = &sp_unit_get_by_id(SP_UNIT_PX);
+ static Inkscape::Util::Unit px = unit_table.getUnit("px");
+ Inkscape::Util::Unit const *new_unit = new Inkscape::Util::Unit(px);
if (value) {
- SPUnit const *const req_unit = sp_unit_get_by_abbreviation(value);
- if ( req_unit == NULL ) {
+ Inkscape::Util::Unit u = unit_table.getUnit(value);
+ Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u);
+ if ( !unit_table.hasUnit(value) ) {
g_warning("Unrecognized unit `%s'", value);
/* fixme: Document errors should be reported in the status bar or
* the like (e.g. as per
* http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log
* should be only for programmer errors. */
- } else if ( req_unit->base == SP_UNIT_ABSOLUTE ||
- req_unit->base == SP_UNIT_DEVICE ) {
+ } else if ( req_unit->isAbsolute() ) {
new_unit = req_unit;
} else {
g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'",
@@ -573,18 +575,18 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va
break;
}
case SP_ATTR_UNITS: {
- SPUnit const *new_unit = NULL;
+ Inkscape::Util::Unit const *new_unit = NULL;
if (value) {
- SPUnit const *const req_unit = sp_unit_get_by_abbreviation(value);
- if ( req_unit == NULL ) {
+ Inkscape::Util::Unit u = unit_table.getUnit(value);
+ Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u);
+ if ( !unit_table.hasUnit(value) ) {
g_warning("Unrecognized unit `%s'", value);
/* fixme: Document errors should be reported in the status bar or
* the like (e.g. as per
* http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log
* should be only for programmer errors. */
- } else if ( req_unit->base == SP_UNIT_ABSOLUTE ||
- req_unit->base == SP_UNIT_DEVICE ) {
+ } else if ( req_unit->isAbsolute() ) {
new_unit = req_unit;
} else {
g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'",
@@ -1101,35 +1103,35 @@ bool SPNamedView::getGuides()
* \return the margin size in px, else 0.0 if anything is invalid.
*/
double SPNamedView::getMarginLength(gchar const * const key,
- SPUnit const * const margin_units,
- SPUnit const * const return_units,
+ Inkscape::Util::Unit const * const margin_units,
+ Inkscape::Util::Unit const * const return_units,
double const width,
double const height,
bool const use_width)
{
double value;
+ Inkscape::Util::Unit percent = unit_table.getUnit("%");
if(!this->storeAsDouble(key,&value)) {
return 0.0;
}
- if (margin_units == &sp_unit_get_by_id (SP_UNIT_PERCENT)) {
+ if (*margin_units == percent) {
return (use_width)? width * value : height * value;
}
- if (!sp_convert_distance (&value, margin_units, return_units)) {
+ if (!margin_units->compatibleWith(*return_units)) {
return 0.0;
}
return value;
}
-
/**
- * Returns namedview's default metric.
+ * Returns namedview's default unit.
*/
-SPMetric SPNamedView::getDefaultMetric() const
+Inkscape::Util::Unit const SPNamedView::getDefaultUnit() const
{
if (doc_units) {
- return sp_unit_get_metric(doc_units);
+ return *doc_units;
} else {
- return SP_PT;
+ return *(new Inkscape::Util::Unit(unit_table.getUnit("pt")));
}
}
diff --git a/src/sp-namedview.h b/src/sp-namedview.h
index 8191ef6d6..26febd7d3 100644
--- a/src/sp-namedview.h
+++ b/src/sp-namedview.h
@@ -21,16 +21,17 @@
#define SP_IS_NAMEDVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_NAMEDVIEW))
#include "sp-object-group.h"
-#include "sp-metric.h"
#include "snap.h"
#include "document.h"
+#include "util/units.h"
G_BEGIN_DECLS
-struct SPUnit;
-
namespace Inkscape {
-class CanvasGrid;
+ class CanvasGrid;
+ namespace Util {
+ class Unit;
+ }
}
enum {
@@ -58,8 +59,8 @@ struct SPNamedView : public SPObjectGroup {
GSList * grids;
bool grids_visible;
- SPUnit const *doc_units;
- SPUnit const *units;
+ Inkscape::Util::Unit const *doc_units;
+ Inkscape::Util::Unit const *units;
GQuark default_layer_id;
@@ -82,7 +83,7 @@ struct SPNamedView : public SPObjectGroup {
gchar const *getName() const;
guint getViewCount();
GSList const *getViewList() const;
- SPMetric getDefaultMetric() const;
+ Inkscape::Util::Unit const getDefaultUnit() const;
void translateGuides(Geom::Translate const &translation);
void translateGrids(Geom::Translate const &translation);
@@ -94,7 +95,7 @@ struct SPNamedView : public SPObjectGroup {
bool getGuides();
private:
- 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);
+ 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);
friend class SPDocument;
};
diff --git a/src/sp-text.cpp b/src/sp-text.cpp
index e43a34762..2e2bf15bc 100644
--- a/src/sp-text.cpp
+++ b/src/sp-text.cpp
@@ -43,7 +43,6 @@
#include "sp-namedview.h"
#include "style.h"
#include "inkscape.h"
-#include "sp-metrics.h"
#include "xml/quote.h"
#include "xml/repr.h"
#include "mod360.h"
@@ -56,7 +55,6 @@
#include "sp-tspan.h"
#include "text-editing.h"
-#include "unit-constants.h"
/*#####################################################
# SPTEXT
@@ -392,7 +390,8 @@ static char * sp_text_description(SPItem *item)
n = g_strdup(_("&lt;no name found&gt;"));
}
- GString *xs = SP_PX_TO_METRIC_STRING(style->font_size.computed, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->getDefaultMetric());
+ Inkscape::Util::Quantity q = Inkscape::Util::Quantity(style->font_size.computed, "px");
+ GString *xs = g_string_new(q.string(*sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units).c_str());
char const *trunc = "";
Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item);
diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp
index b7bf5aead..a6cdc6bc4 100644
--- a/src/spiral-context.cpp
+++ b/src/spiral-context.cpp
@@ -34,7 +34,6 @@
#include "message-context.h"
#include "pixmaps/cursor-spiral.xpm"
#include "spiral-context.h"
-#include "sp-metrics.h"
#include <glibmm/i18n.h>
#include "xml/repr.h"
#include "xml/node-event-vector.h"
@@ -437,7 +436,8 @@ static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point const &p, guint stat
/*t0*/ sc->t0);
/* status text */
- GString *rads = SP_PX_TO_METRIC_STRING(rad, desktop->namedview->getDefaultMetric());
+ Inkscape::Util::Quantity q = Inkscape::Util::Quantity(rad, "px");
+ GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str());
sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE,
_("<b>Spiral</b>: radius %s, angle %5g&#176;; with <b>Ctrl</b> to snap angle"),
rads->str, sp_round((arg + 2.0*M_PI*spiral->revo)*180/M_PI, 0.0001));
diff --git a/src/star-context.cpp b/src/star-context.cpp
index 5fb33a180..d4996e189 100644
--- a/src/star-context.cpp
+++ b/src/star-context.cpp
@@ -36,7 +36,6 @@
#include "desktop-style.h"
#include "message-context.h"
#include "pixmaps/cursor-star.xpm"
-#include "sp-metrics.h"
#include <glibmm/i18n.h>
#include "preferences.h"
#include "xml/repr.h"
@@ -450,7 +449,8 @@ static void sp_star_drag(SPStarContext *sc, Geom::Point p, guint state)
arg1, arg1 + M_PI / sides, sc->isflatsided, sc->rounded, sc->randomized);
/* status text */
- GString *rads = SP_PX_TO_METRIC_STRING(r1, desktop->namedview->getDefaultMetric());
+ Inkscape::Util::Quantity q = Inkscape::Util::Quantity(r1, "px");
+ GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str());
sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE,
( sc->isflatsided?
_("<b>Polygon</b>: radius %s, angle %5g&#176;; with <b>Ctrl</b> to snap angle")
diff --git a/src/style.cpp b/src/style.cpp
index ce5460164..4a808fac6 100644
--- a/src/style.cpp
+++ b/src/style.cpp
@@ -45,7 +45,7 @@
#include "svg/css-ostringstream.h"
#include "xml/repr.h"
#include "xml/simple-document.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include "macros.h"
#include "preferences.h"
@@ -2483,11 +2483,11 @@ sp_style_css_size_px_to_units(double size, int unit)
case SP_CSS_UNIT_NONE: unit_size = size; break;
case SP_CSS_UNIT_PX: unit_size = size; break;
- case SP_CSS_UNIT_PT: unit_size = size * PT_PER_PX; break;
- case SP_CSS_UNIT_PC: unit_size = size * (PT_PER_PX / PT_PER_PC); break;
- case SP_CSS_UNIT_MM: unit_size = size * MM_PER_PX; break;
- case SP_CSS_UNIT_CM: unit_size = size * CM_PER_PX; break;
- case SP_CSS_UNIT_IN: unit_size = size * IN_PER_PX; break;
+ case SP_CSS_UNIT_PT: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "pt"); break;
+ case SP_CSS_UNIT_PC: unit_size = size * (Inkscape::Util::Quantity::convert(1, "px", "pt") / Inkscape::Util::Quantity::convert(1, "pc", "pt")); break;
+ case SP_CSS_UNIT_MM: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "mm"); break;
+ case SP_CSS_UNIT_CM: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "cm"); break;
+ case SP_CSS_UNIT_IN: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "in"); break;
case SP_CSS_UNIT_EM: unit_size = size / SP_CSS_FONT_SIZE_DEFAULT; break;
case SP_CSS_UNIT_EX: unit_size = size * 2.0 / SP_CSS_FONT_SIZE_DEFAULT ; break;
case SP_CSS_UNIT_PERCENT: unit_size = size * 100.0 / SP_CSS_FONT_SIZE_DEFAULT; break;
@@ -3472,19 +3472,19 @@ sp_style_read_ilength(SPILength *val, gchar const *str)
} else if (!strcmp(e, "pt")) {
/* Userspace / DEVICESCALE */
val->unit = SP_CSS_UNIT_PT;
- val->computed = value * PX_PER_PT;
+ val->computed = value * Inkscape::Util::Quantity::convert(1, "pt", "px");
} else if (!strcmp(e, "pc")) {
val->unit = SP_CSS_UNIT_PC;
- val->computed = value * PX_PER_PC;
+ val->computed = value * Inkscape::Util::Quantity::convert(1, "pc", "px");
} else if (!strcmp(e, "mm")) {
val->unit = SP_CSS_UNIT_MM;
- val->computed = value * PX_PER_MM;
+ val->computed = value * Inkscape::Util::Quantity::convert(1, "mm", "px");
} else if (!strcmp(e, "cm")) {
val->unit = SP_CSS_UNIT_CM;
- val->computed = value * PX_PER_CM;
+ val->computed = value * Inkscape::Util::Quantity::convert(1, "cm", "px");
} else if (!strcmp(e, "in")) {
val->unit = SP_CSS_UNIT_IN;
- val->computed = value * PX_PER_IN;
+ val->computed = value * Inkscape::Util::Quantity::convert(1, "in", "px");
} else if (!strcmp(e, "em")) {
/* EM square */
val->unit = SP_CSS_UNIT_EM;
@@ -4043,23 +4043,23 @@ sp_style_write_ilength(gchar *p, gint const len, gchar const *const key,
return g_strlcpy(p, os.str().c_str(), len);
break;
case SP_CSS_UNIT_PT:
- os << key << ":" << val->computed * PT_PER_PX << "pt;";
+ os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "pt") << "pt;";
return g_strlcpy(p, os.str().c_str(), len);
break;
case SP_CSS_UNIT_PC:
- os << key << ":" << val->computed * PT_PER_PX / 12.0 << "pc;";
+ os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "pt") / 12.0 << "pc;";
return g_strlcpy(p, os.str().c_str(), len);
break;
case SP_CSS_UNIT_MM:
- os << key << ":" << val->computed * MM_PER_PX << "mm;";
+ os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "mm") << "mm;";
return g_strlcpy(p, os.str().c_str(), len);
break;
case SP_CSS_UNIT_CM:
- os << key << ":" << val->computed * CM_PER_PX << "cm;";
+ os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "cm") << "cm;";
return g_strlcpy(p, os.str().c_str(), len);
break;
case SP_CSS_UNIT_IN:
- os << key << ":" << val->computed * IN_PER_PX << "in;";
+ os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "in") << "in;";
return g_strlcpy(p, os.str().c_str(), len);
break;
case SP_CSS_UNIT_EM:
diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp
index d2f4332d8..ea438e91a 100644
--- a/src/svg/svg-length.cpp
+++ b/src/svg/svg-length.cpp
@@ -23,7 +23,7 @@
#include "svg.h"
#include "stringstream.h"
-#include "../unit-constants.h"
+#include "util/units.h"
static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, float *val, float *computed, char **next);
@@ -330,6 +330,8 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit,
*next = (char *) e + 1;
}
return 1;
+ } else if (g_ascii_isspace(e[0])) {
+ return 0; // spaces are not allowed
} else {
/* Unitless */
if (unit) {
@@ -365,7 +367,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit,
*unit = SVGLength::PT;
}
if (computed) {
- *computed = v * PX_PER_PT;
+ *computed = v * Inkscape::Util::Quantity::convert(1, "pt", "px");
}
break;
case UVAL('p','c'):
@@ -373,7 +375,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit,
*unit = SVGLength::PC;
}
if (computed) {
- *computed = v * PX_PER_PC;
+ *computed = v * Inkscape::Util::Quantity::convert(1, "pc", "px");
}
break;
case UVAL('m','m'):
@@ -381,7 +383,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit,
*unit = SVGLength::MM;
}
if (computed) {
- *computed = v * PX_PER_MM;
+ *computed = v * Inkscape::Util::Quantity::convert(1, "mm", "px");
}
break;
case UVAL('c','m'):
@@ -389,7 +391,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit,
*unit = SVGLength::CM;
}
if (computed) {
- *computed = v * PX_PER_CM;
+ *computed = v * Inkscape::Util::Quantity::convert(1, "cm", "px");
}
break;
case UVAL('i','n'):
@@ -397,7 +399,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit,
*unit = SVGLength::INCH;
}
if (computed) {
- *computed = v * PX_PER_IN;
+ *computed = v * Inkscape::Util::Quantity::convert(1, "in", "px");
}
break;
case UVAL('f','t'):
@@ -405,7 +407,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit,
*unit = SVGLength::FOOT;
}
if (computed) {
- *computed = v * PX_PER_FT;
+ *computed = v * Inkscape::Util::Quantity::convert(1, "ft", "px");
}
break;
case UVAL('e','m'):
diff --git a/src/text-context.cpp b/src/text-context.cpp
index 862c50737..719a82156 100644
--- a/src/text-context.cpp
+++ b/src/text-context.cpp
@@ -42,7 +42,6 @@
#include "selection.h"
#include "shape-editor.h"
#include "sp-flowtext.h"
-#include "sp-metrics.h"
#include "sp-namedview.h"
#include "sp-text.h"
#include "style.h"
@@ -640,8 +639,10 @@ static gint sp_text_context_root_handler(SPEventContext *const event_context, Gd
gobble_motion_events(GDK_BUTTON1_MASK);
// status text
- GString *xs = SP_PX_TO_METRIC_STRING(fabs((p - tc->p0)[Geom::X]), desktop->namedview->getDefaultMetric());
- GString *ys = SP_PX_TO_METRIC_STRING(fabs((p - tc->p0)[Geom::Y]), desktop->namedview->getDefaultMetric());
+ Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(fabs((p - tc->p0)[Geom::X]), "px");
+ Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(fabs((p - tc->p0)[Geom::Y]), "px");
+ GString *xs = g_string_new(x_q.string(*desktop->namedview->doc_units).c_str());
+ GString *ys = g_string_new(y_q.string(*desktop->namedview->doc_units).c_str());
event_context->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Flowed text frame</b>: %s &#215; %s"), xs->str, ys->str);
g_string_free(xs, FALSE);
g_string_free(ys, FALSE);
diff --git a/src/text-editing.cpp b/src/text-editing.cpp
index 401f56bb2..0d30863d9 100644
--- a/src/text-editing.cpp
+++ b/src/text-editing.cpp
@@ -24,7 +24,7 @@
#include "inkscape.h"
#include "message-stack.h"
#include "style.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include "document.h"
#include "xml/repr.h"
@@ -1278,23 +1278,23 @@ sp_te_adjust_linespacing_screen (SPItem *text, Inkscape::Text::Layout::iterator
style->line_height.value = style->line_height.computed;
break;
case SP_CSS_UNIT_PT:
- style->line_height.computed += zby * PT_PER_PX;
+ style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "pt");
style->line_height.value = style->line_height.computed;
break;
case SP_CSS_UNIT_PC:
- style->line_height.computed += zby * (PT_PER_PX / 12);
+ style->line_height.computed += zby * (Inkscape::Util::Quantity::convert(1, "px", "pt") / 12);
style->line_height.value = style->line_height.computed;
break;
case SP_CSS_UNIT_MM:
- style->line_height.computed += zby * MM_PER_PX;
+ style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "mm");
style->line_height.value = style->line_height.computed;
break;
case SP_CSS_UNIT_CM:
- style->line_height.computed += zby * CM_PER_PX;
+ style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "cm");
style->line_height.value = style->line_height.computed;
break;
case SP_CSS_UNIT_IN:
- style->line_height.computed += zby * IN_PER_PX;
+ style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "in");
style->line_height.value = style->line_height.computed;
break;
}
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index e831bcf69..b592d2527 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -112,6 +112,7 @@ set(ui_SRC
widget/text.cpp
widget/tolerance-slider.cpp
widget/unit-menu.cpp
+ widget/unit-tracker.cpp
view/view.cpp
view/view-widget.cpp
@@ -240,6 +241,7 @@ set(ui_SRC
widget/text.h
widget/tolerance-slider.h
widget/unit-menu.h
+ widget/unit-tracker.h
view/edit-widget-interface.h
view/view-widget.h
diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp
index 72ddd90a9..629960613 100644
--- a/src/ui/clipboard.cpp
+++ b/src/ui/clipboard.cpp
@@ -79,7 +79,7 @@
#include "text-editing.h"
#include "tools-switch.h"
#include "path-chemistry.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include "helper/png-write.h"
#include "svg/svg-color.h"
#include "sp-namedview.h"
@@ -1078,14 +1078,14 @@ void ClipboardManagerImpl::_onGet(Gtk::SelectionData &sel, guint /*info*/)
try {
if (out == outlist.end() && target == "image/png")
{
- gdouble dpi = PX_PER_IN;
+ gdouble dpi = Inkscape::Util::Quantity::convert(1, "in", "px");
guint32 bgcolor = 0x00000000;
Geom::Point origin (_clipboardSPDoc->getRoot()->x.computed, _clipboardSPDoc->getRoot()->y.computed);
Geom::Rect area = Geom::Rect(origin, origin + _clipboardSPDoc->getDimensions());
- unsigned long int width = (unsigned long int) (area.width() * dpi / PX_PER_IN + 0.5);
- unsigned long int height = (unsigned long int) (area.height() * dpi / PX_PER_IN + 0.5);
+ unsigned long int width = (unsigned long int) (area.width() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5);
+ unsigned long int height = (unsigned long int) (area.height() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5);
// read from namedview
Inkscape::XML::Node *nv = sp_repr_lookup_name (_clipboardSPDoc->rroot, "sodipodi:namedview");
diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp
index 753320ab9..b3675440b 100644
--- a/src/ui/dialog/clonetiler.cpp
+++ b/src/ui/dialog/clonetiler.cpp
@@ -34,8 +34,8 @@
#include "document.h"
#include "document-undo.h"
#include "filter-chemistry.h"
-#include "helper/unit-menu.h"
-#include "helper/units.h"
+#include "ui/widget/unit-menu.h"
+#include "util/units.h"
#include "helper/window.h"
#include "inkscape.h"
#include "interface.h"
@@ -58,6 +58,7 @@
#include "sp-root.h"
using Inkscape::DocumentUndo;
+using Inkscape::Util::unit_table;
namespace Inkscape {
namespace UI {
@@ -1092,35 +1093,36 @@ CloneTiler::CloneTiler (void) :
g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb);
// unitmenu
- GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
- sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
+ unit_menu = new Inkscape::UI::Widget::UnitMenu();
+ unit_menu->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR);
+ unit_menu->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr);
+ unitChangedConn = unit_menu->signal_changed().connect(sigc::mem_fun(*this, &CloneTiler::clonetiler_unit_changed));
{
// Width spinbutton
#if WITH_GTKMM_3_0
- Glib::RefPtr<Gtk::Adjustment> a = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0);
+ fill_width = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0);
#else
- Gtk::Adjustment *a = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0);
+ fill_width = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0);
#endif
- sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a->gobj()));
double value = prefs->getDouble(prefs_path + "fillwidth", 50.0);
- SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
- gdouble const units = sp_pixels_get_units (value, unit);
- a->set_value (units);
+ Inkscape::Util::Unit const unit = unit_menu->getUnit();
+ gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit);
+ fill_width->set_value (units);
#if WITH_GTKMM_3_0
- Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(a, 1.0, 2);
+ Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(fill_width, 1.0, 2);
#else
- Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*a, 1.0, 2);
+ Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*fill_width, 1.0, 2);
#endif
e->set_tooltip_text (_("Width of the rectangle to be filled"));
e->set_width_chars (7);
e->set_digits (4);
gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0);
// TODO: C++ification
- g_signal_connect(G_OBJECT(a->gobj()), "value_changed",
- G_CALLBACK(clonetiler_fill_width_changed), u);
+ g_signal_connect(G_OBJECT(fill_width->gobj()), "value_changed",
+ G_CALLBACK(clonetiler_fill_width_changed), unit_menu);
}
{
GtkWidget *l = gtk_label_new ("");
@@ -1132,32 +1134,31 @@ CloneTiler::CloneTiler (void) :
{
// Height spinbutton
#if WITH_GTKMM_3_0
- Glib::RefPtr<Gtk::Adjustment> a = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0);
+ fill_height = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0);
#else
- Gtk::Adjustment *a = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0);
+ fill_height = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0);
#endif
- sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a->gobj()));
double value = prefs->getDouble(prefs_path + "fillheight", 50.0);
- SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
- gdouble const units = sp_pixels_get_units (value, unit);
- a->set_value (units);
+ Inkscape::Util::Unit const unit = unit_menu->getUnit();
+ gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit);
+ fill_height->set_value (units);
#if WITH_GTKMM_3_0
- Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(a, 1.0, 2);
+ Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(fill_height, 1.0, 2);
#else
- Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*a, 1.0, 2);
+ Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*fill_height, 1.0, 2);
#endif
e->set_tooltip_text (_("Height of the rectangle to be filled"));
e->set_width_chars (7);
e->set_digits (4);
gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0);
// TODO: C++ification
- g_signal_connect(G_OBJECT(a->gobj()), "value_changed",
- G_CALLBACK(clonetiler_fill_height_changed), u);
+ g_signal_connect(G_OBJECT(fill_height->gobj()), "value_changed",
+ G_CALLBACK(clonetiler_fill_height_changed), unit_menu);
}
- gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (hb), (GtkWidget*) unit_menu->gobj(), TRUE, TRUE, 0);
clonetiler_table_attach (table, hb, 0.0, 2, 2);
}
@@ -2944,26 +2945,39 @@ void CloneTiler::clonetiler_switch_to_fill(GtkToggleButton * /*tb*/, GtkWidget *
-void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, GtkWidget *u)
+void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u)
{
gdouble const raw_dist = gtk_adjustment_get_value (adj);
- SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
- gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
+ Inkscape::Util::Unit const unit = u->getUnit();
+ gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px");
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setDouble(prefs_path + "fillwidth", pixels);
}
-void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, GtkWidget *u)
+void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u)
{
gdouble const raw_dist = gtk_adjustment_get_value (adj);
- SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u));
- gdouble const pixels = sp_units_get_pixels (raw_dist, unit);
+ Inkscape::Util::Unit const unit = u->getUnit();
+ gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px");
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setDouble(prefs_path + "fillheight", pixels);
}
+void CloneTiler::clonetiler_unit_changed()
+{
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ gdouble width_pixels = prefs->getDouble(prefs_path + "fillwidth");
+ gdouble height_pixels = prefs->getDouble(prefs_path + "fillheight");
+
+ Inkscape::Util::Unit unit = unit_menu->getUnit();
+
+ gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, "px", unit);
+ gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, "px", unit);
+ gtk_adjustment_set_value(fill_width->gobj(), width_value);
+ gtk_adjustment_set_value(fill_height->gobj(), height_value);
+}
void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg)
{
@@ -2977,7 +2991,6 @@ void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg)
}
}
-
}
}
}
diff --git a/src/ui/dialog/clonetiler.h b/src/ui/dialog/clonetiler.h
index 7ec30cfaa..e2a0240ee 100644
--- a/src/ui/dialog/clonetiler.h
+++ b/src/ui/dialog/clonetiler.h
@@ -19,6 +19,11 @@
namespace Inkscape {
namespace UI {
+
+namespace Widget {
+ class UnitMenu;
+}
+
namespace Dialog {
class CloneTiler : public Widget::Panel {
@@ -45,8 +50,9 @@ protected:
static void clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg);
static void clonetiler_pick_to(GtkToggleButton *tb, gpointer data);
static void clonetiler_xy_changed(GtkAdjustment *adj, gpointer data);
- static void clonetiler_fill_width_changed(GtkAdjustment *adj, GtkWidget *u);
- static void clonetiler_fill_height_changed(GtkAdjustment *adj, GtkWidget *u);
+ static void clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u);
+ static void clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u);
+ void clonetiler_unit_changed();
static void clonetiler_switch_to_create(GtkToggleButton */*tb*/, GtkWidget *dlg);
static void clonetiler_switch_to_fill(GtkToggleButton */*tb*/, GtkWidget *dlg);
static void clonetiler_keep_bbox_toggled(GtkToggleButton *tb, gpointer /*data*/);
@@ -112,12 +118,22 @@ private:
DesktopTracker deskTrack;
Inkscape::UI::Widget::ColorPicker *color_picker;
GtkSizeGroup* table_row_labels;
+ Inkscape::UI::Widget::UnitMenu *unit_menu;
+
+#if WITH_GTKMM_3_0
+ Glib::RefPtr<Gtk::Adjustment> fill_width;
+ Glib::RefPtr<Gtk::Adjustment> fill_height;
+#else
+ Gtk::Adjustment *fill_width;
+ Gtk::Adjustment *fill_height;
+#endif
sigc::connection desktopChangeConn;
sigc::connection selectChangedConn;
sigc::connection subselChangedConn;
sigc::connection selectModifiedConn;
sigc::connection color_changed_connection;
+ sigc::connection unitChangedConn;
/**
* Can be invoked for setting the desktop. Currently not used.
diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp
index d335fb303..77fb182e5 100644
--- a/src/ui/dialog/document-properties.cpp
+++ b/src/ui/dialog/document-properties.cpp
@@ -28,7 +28,6 @@
#include "document.h"
#include "desktop-handles.h"
#include "desktop.h"
-#include "helper/units.h"
#include "inkscape.h"
#include "io/sys.h"
#include "preferences.h"
@@ -1432,7 +1431,7 @@ void DocumentProperties::update()
_rcb_shad.setActive (nv->showpageshadow);
if (nv->doc_units)
- _rum_deflt.setUnit (nv->doc_units);
+ _rum_deflt.setUnit (nv->doc_units->abbr);
double const doc_w_px = sp_desktop_document(dt)->getWidth();
double const doc_h_px = sp_desktop_document(dt)->getHeight();
diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp
index a851503fe..2c92608d7 100644
--- a/src/ui/dialog/export.cpp
+++ b/src/ui/dialog/export.cpp
@@ -48,9 +48,8 @@
#include <glibmm/i18n.h>
#include <glibmm/miscutils.h>
-#include "helper/unit-menu.h"
-#include "helper/units.h"
-#include "unit-constants.h"
+#include "ui/widget/unit-menu.h"
+#include "util/units.h"
#include "helper/window.h"
#include "inkscape-private.h"
#include "document.h"
@@ -98,7 +97,7 @@
#define SP_EXPORT_MIN_SIZE 1.0
-#define DPI_BASE PX_PER_IN
+#define DPI_BASE Inkscape::Util::Quantity::convert(1, "in", "px")
#define EXPORT_COORD_PRECISION 3
@@ -108,6 +107,8 @@
#include "verbs.h"
#include "export.h"
+using Inkscape::Util::unit_table;
+
namespace {
class MessageCleaner
@@ -198,10 +199,13 @@ Export::Export (void) :
/* Units box */
/* gets added to the vbox later, but the unit selector is needed
earlier than that */
- unit_selector = Glib::wrap(sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE));
+ unit_selector = new Inkscape::UI::Widget::UnitMenu();
+ unit_selector->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR);
+ unitChangedConn = unit_selector->signal_changed().connect(sigc::mem_fun(*this, &Export::onUnitChanged));
+
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
if (desktop)
- sp_unit_selector_set_unit (SP_UNIT_SELECTOR(unit_selector->gobj()), sp_desktop_namedview(desktop)->doc_units);
+ unit_selector->setUnit(sp_desktop_namedview(desktop)->doc_units->abbr);
unitbox.pack_end(*unit_selector, false, false, 0);
unitbox.pack_end(units_label, false, false, 3);
@@ -226,28 +230,28 @@ Export::Export (void) :
t->set_col_spacings (4);
#endif
- x0_adj = createSpinbutton ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(),
+ x0_adj = createSpinbutton ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(),
t, 0, 0, _("_x0:"), "", EXPORT_COORD_PRECISION, 1,
&Export::onAreaX0Change);
- x1_adj = createSpinbutton ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(),
+ x1_adj = createSpinbutton ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(),
t, 0, 1, _("x_1:"), "", EXPORT_COORD_PRECISION, 1,
&Export::onAreaX1Change);
width_adj = createSpinbutton ( "width", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0,
- unit_selector->gobj(), t, 0, 2, _("Wid_th:"), "", EXPORT_COORD_PRECISION, 1,
+ ((Gtk::Widget*) unit_selector)->gobj(), t, 0, 2, _("Wid_th:"), "", EXPORT_COORD_PRECISION, 1,
&Export::onAreaWidthChange);
- y0_adj = createSpinbutton ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(),
+ y0_adj = createSpinbutton ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(),
t, 2, 0, _("_y0:"), "", EXPORT_COORD_PRECISION, 1,
&Export::onAreaY0Change);
- y1_adj = createSpinbutton ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(),
+ y1_adj = createSpinbutton ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(),
t, 2, 1, _("y_1:"), "", EXPORT_COORD_PRECISION, 1,
&Export::onAreaY1Change);
height_adj = createSpinbutton ( "height", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0,
- unit_selector->gobj(), t, 2, 2, _("Hei_ght:"), "", EXPORT_COORD_PRECISION, 1,
+ ((Gtk::Widget*) unit_selector)->gobj(), t, 2, 2, _("Hei_ght:"), "", EXPORT_COORD_PRECISION, 1,
&Export::onAreaHeightChange);
area_box.pack_start(togglebox, false, false, 3);
@@ -496,9 +500,6 @@ Gtk::Adjustment * Export::createSpinbutton( gchar const * /*key*/, float val, fl
#else
Gtk::Adjustment *adj = new Gtk::Adjustment ( val, min, max, step, page, 0 );
#endif
- if (us) {
- sp_unit_selector_add_adjustment ( SP_UNIT_SELECTOR (us), GTK_ADJUSTMENT (adj->gobj()) );
- }
int pos = 0;
Gtk::Label *l = NULL;
@@ -979,6 +980,12 @@ Glib::ustring Export::absolutize_path_from_document_location (SPDocument *doc, c
return path;
}
+// Called when unit is changed
+void Export::onUnitChanged()
+{
+ onAreaToggled();
+}
+
void Export::onHideExceptSelected ()
{
prefs->setBool("/dialogs/export/hideexceptselected/value", hide_export.get_active());
@@ -1042,8 +1049,8 @@ void Export::onExport ()
Geom::OptRect area = item->desktopVisualBounds();
if (area) {
- gint width = (gint) (area->width() * dpi / PX_PER_IN + 0.5);
- gint height = (gint) (area->height() * dpi / PX_PER_IN + 0.5);
+ gint width = (gint) (area->width() * dpi / DPI_BASE + 0.5);
+ gint height = (gint) (area->height() * dpi / DPI_BASE + 0.5);
if (width > 1 && height > 1) {
// Do export
@@ -1507,10 +1514,6 @@ void Export::areaXChange (Gtk::Adjustment *adj)
return;
}
- if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) {
- return;
- }
-
update = true;
x0 = getValuePx(x0_adj);
@@ -1554,10 +1557,6 @@ void Export::areaYChange (Gtk::Adjustment *adj)
return;
}
- if (sp_unit_selector_update_test (SP_UNIT_SELECTOR(unit_selector->gobj()))) {
- return;
- }
-
update = true;
y0 = getValuePx(y0_adj);
@@ -1597,10 +1596,6 @@ void Export::onAreaWidthChange()
return;
}
- if (sp_unit_selector_update_test(reinterpret_cast<SPUnitSelector *>(unit_selector->gobj()))) {
- return;
- }
-
update = true;
float x0 = getValuePx(x0_adj);
@@ -1630,10 +1625,6 @@ void Export::onAreaHeightChange()
return;
}
- if (sp_unit_selector_update_test(reinterpret_cast<SPUnitSelector *>(unit_selector->gobj()))) {
- return;
- }
-
update = true;
float y0 = getValuePx(y0_adj);
@@ -1709,10 +1700,6 @@ void Export::onBitmapWidthChange ()
return;
}
- if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) {
- return;
- }
-
update = true;
x0 = getValuePx(x0_adj);
@@ -1743,10 +1730,6 @@ void Export::onBitmapHeightChange ()
return;
}
- if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) {
- return;
- }
-
update = true;
y0 = getValuePx(y0_adj);
@@ -1803,10 +1786,6 @@ void Export::onExportXdpiChange()
return;
}
- if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) {
- return;
- }
-
update = true;
x0 = getValuePx(x0_adj);
@@ -1905,9 +1884,9 @@ void Export::setValuePx(Glib::RefPtr<Gtk::Adjustment>& adj, double val)
void Export::setValuePx( Gtk::Adjustment *adj, double val)
#endif
{
- const SPUnit *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unit_selector->gobj()) );
+ const Unit unit = unit_selector->getUnit();
- setValue(adj, sp_pixels_get_units (val, *unit));
+ setValue(adj, Inkscape::Util::Quantity::convert(val, "px", unit));
return;
}
@@ -1955,9 +1934,9 @@ float Export::getValuePx( Gtk::Adjustment *adj )
#endif
{
float value = getValue( adj);
- const SPUnit *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unit_selector->gobj()));
+ const Unit unit = unit_selector->getUnit();
- return sp_units_get_pixels (value, *unit);
+ return Inkscape::Util::Quantity::convert(value, unit, "px");
} // end of sp_export_value_get_px()
/**
diff --git a/src/ui/dialog/export.h b/src/ui/dialog/export.h
index b10c98fd2..f324f5dc5 100644
--- a/src/ui/dialog/export.h
+++ b/src/ui/dialog/export.h
@@ -172,6 +172,11 @@ private:
#endif
/**
+ * Unit changed callback
+ */
+ void onUnitChanged();
+
+ /**
* Hide except selected callback
*/
void onHideExceptSelected ();
@@ -330,7 +335,7 @@ private:
/* Unit selector widgets */
Gtk::HBox unitbox;
- Gtk::Widget* unit_selector;
+ Inkscape::UI::Widget::UnitMenu *unit_selector;
Gtk::Label units_label;
/* Filename widgets */
@@ -365,6 +370,7 @@ private:
sigc::connection selectChangedConn;
sigc::connection subselChangedConn;
sigc::connection selectModifiedConn;
+ sigc::connection unitChangedConn;
};
diff --git a/src/ui/dialog/guides.cpp b/src/ui/dialog/guides.cpp
index 51bbc7d9a..2de387364 100644
--- a/src/ui/dialog/guides.cpp
+++ b/src/ui/dialog/guides.cpp
@@ -230,7 +230,7 @@ void GuidelinePropertiesDialog::_setup() {
_unit_menu.setUnitType(UNIT_TYPE_LINEAR);
_unit_menu.setUnit("px");
if (_desktop->namedview->doc_units) {
- _unit_menu.setUnit( sp_unit_get_abbreviation(_desktop->namedview->doc_units) );
+ _unit_menu.setUnit( _desktop->namedview->doc_units->abbr );
}
_spin_angle.setUnit(_angle_unit_status);
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp
index bc648002d..7890b0b4c 100644
--- a/src/ui/dialog/inkscape-preferences.cpp
+++ b/src/ui/dialog/inkscape-preferences.cpp
@@ -28,7 +28,7 @@
#include "preferences.h"
#include "verbs.h"
#include "selcue.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include <iostream>
#include "enums.h"
#include "desktop-handles.h"
@@ -1428,10 +1428,10 @@ void InkscapePreferences::initPageBitmaps()
_("Automatically reload linked images when file is changed on disk"));
_misc_bitmap_editor.init("/options/bitmapeditor/value", true);
_page_bitmaps.add_line( false, _("_Bitmap editor:"), _misc_bitmap_editor, "", "", true);
- _importexport_export_res.init("/dialogs/export/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false);
+ _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);
_page_bitmaps.add_line( false, _("Default export _resolution:"), _importexport_export_res, _("dpi"),
_("Default bitmap resolution (in dots per inch) in the Export dialog"), false);
- _bitmap_copy_res.init("/options/createbitmap/resolution", 1.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false);
+ _bitmap_copy_res.init("/options/createbitmap/resolution", 1.0, 6000.0, 1.0, 1.0, Inkscape::Util::Quantity::convert(1, "in", "px"), true, false);
_page_bitmaps.add_line( false, _("Resolution for Create Bitmap _Copy:"), _bitmap_copy_res, _("dpi"),
_("Resolution used by the Create Bitmap Copy command"), false);
{
@@ -1443,7 +1443,7 @@ void InkscapePreferences::initPageBitmaps()
_bitmap_import_quality.init("/dialogs/import/quality", 1, 100, 1, 1, 100, true, false);
_page_bitmaps.add_line( false, _("Bitmap import quality:"), _bitmap_import_quality, "%", "Bitmap import quality (jpeg only). 100 is best quality", false);
}
- _importexport_import_res.init("/dialogs/import/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false);
+ _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);
_page_bitmaps.add_line( false, _("Default _import resolution:"), _importexport_import_res, _("dpi"),
_("Default bitmap resolution (in dots per inch) for bitmap import"), false);
_importexport_import_res_override.init(_("Override file resolution"), "/dialogs/import/forcexdpi", false);
diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp
index 2ab8cf121..4c8c77f96 100644
--- a/src/ui/dialog/print.cpp
+++ b/src/ui/dialog/print.cpp
@@ -26,7 +26,7 @@
#include "ui/widget/rendering-options.h"
#include "document.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include "helper/png-write.h"
#include "svg/svg-color.h"
#include "io/sys.h"
@@ -72,8 +72,8 @@ static void draw_page(
sp_export_png_file(junk->_doc, tmp_png.c_str(), 0.0, 0.0,
width, height,
- (unsigned long)(width * dpi / PX_PER_IN),
- (unsigned long)(height * dpi / PX_PER_IN),
+ (unsigned long)(width * dpi / Inkscape::Util::Quantity::convert(1, "in", "px")),
+ (unsigned long)(height * dpi / Inkscape::Util::Quantity::convert(1, "in", "px")),
dpi, dpi, bgcolor, NULL, NULL, true, NULL);
// This doesn't seem to work:
@@ -90,7 +90,7 @@ static void draw_page(
cairo_t *cr = gtk_print_context_get_cairo_context (context);
cairo_matrix_t m;
cairo_get_matrix(cr, &m);
- cairo_scale(cr, PT_PER_IN / dpi, PT_PER_IN / dpi);
+ cairo_scale(cr, Inkscape::Util::Quantity::convert(1, "in", "pt") / dpi, Inkscape::Util::Quantity::convert(1, "in", "pt") / dpi);
// FIXME: why is the origin offset??
cairo_set_source_surface(cr, png->cobj(), -16.0, -16.0);
cairo_paint(cr);
@@ -195,8 +195,8 @@ Print::Print(SPDocument *doc, SPItem *base) :
// set up paper size to match the document size
gtk_print_operation_set_unit (_printop, GTK_UNIT_POINTS);
GtkPageSetup *page_setup = gtk_page_setup_new();
- gdouble doc_width = _doc->getWidth() * PT_PER_PX;
- gdouble doc_height = _doc->getHeight() * PT_PER_PX;
+ gdouble doc_width = _doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt");
+ gdouble doc_height = _doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt");
GtkPaperSize *paper_size;
if (doc_width > doc_height) {
gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE);
diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp
index a662495a0..4a25f723b 100644
--- a/src/ui/dialog/text-edit.cpp
+++ b/src/ui/dialog/text-edit.cpp
@@ -58,7 +58,7 @@ extern "C" {
#include "widgets/font-selector.h"
#include <glibmm/i18n.h>
#include <glibmm/markup.h>
-#include "unit-constants.h"
+#include "util/units.h"
#include "sp-textpath.h"
namespace Inkscape {
@@ -401,7 +401,7 @@ void TextEdit::setPreviewText (Glib::ustring font_spec, Glib::ustring phrase)
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
- double pt_size = sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit) * PT_PER_PX;
+ double pt_size = sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit) * Inkscape::Util::Quantity::convert(1, "px", "pt");
// Pango font size is in 1024ths of a point
// C++11: Glib::ustring size = std::to_string( pt_size * PANGO_SCALE );
diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp
index dc6e0fbae..82eb697bd 100644
--- a/src/ui/tool/node.cpp
+++ b/src/ui/tool/node.cpp
@@ -22,7 +22,6 @@
#include "preferences.h"
#include "snap.h"
#include "snap-preferences.h"
-#include "sp-metrics.h"
#include "sp-namedview.h"
#include "ui/control-manager.h"
#include "ui/tool/control-point-selection.h"
@@ -490,9 +489,13 @@ Glib::ustring Handle::_getDragTip(GdkEventMotion */*event*/) const
double angle = Geom::angle_between(Geom::Point(-1,0), position() - _parent->position());
angle += M_PI; // angle is (-M_PI...M_PI] - offset by +pi and scale to 0...360
angle *= 360.0 / (2 * M_PI);
- GString *x = SP_PX_TO_METRIC_STRING(dist[Geom::X], _desktop->namedview->getDefaultMetric());
- GString *y = SP_PX_TO_METRIC_STRING(dist[Geom::Y], _desktop->namedview->getDefaultMetric());
- GString *len = SP_PX_TO_METRIC_STRING(length(), _desktop->namedview->getDefaultMetric());
+
+ Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px");
+ Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px");
+ Inkscape::Util::Quantity len_q = Inkscape::Util::Quantity(length(), "px");
+ GString *x = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
+ GString *y = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
+ GString *len = g_string_new(len_q.string(*_desktop->namedview->doc_units).c_str());
Glib::ustring ret = format_tip(C_("Path handle tip",
"Move handle by %s, %s; angle %.2f°, length %s"), x->str, y->str, angle, len->str);
g_string_free(x, TRUE);
@@ -1294,8 +1297,11 @@ Glib::ustring Node::_getTip(unsigned state) const
Glib::ustring Node::_getDragTip(GdkEventMotion */*event*/) const
{
Geom::Point dist = position() - _last_drag_origin();
- GString *x = SP_PX_TO_METRIC_STRING(dist[Geom::X], _desktop->namedview->getDefaultMetric());
- GString *y = SP_PX_TO_METRIC_STRING(dist[Geom::Y], _desktop->namedview->getDefaultMetric());
+
+ Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px");
+ Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px");
+ GString *x = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str());
+ GString *y = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str());
Glib::ustring ret = format_tip(C_("Path node tip", "Move node by %s, %s"),
x->str, y->str);
g_string_free(x, TRUE);
diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert
index 2de954674..710b95c2b 100644
--- a/src/ui/widget/Makefile_insert
+++ b/src/ui/widget/Makefile_insert
@@ -79,5 +79,7 @@ ink_common_sources += \
ui/widget/tolerance-slider.cpp \
ui/widget/tolerance-slider.h \
ui/widget/unit-menu.cpp \
- ui/widget/unit-menu.h
+ ui/widget/unit-menu.h \
+ ui/widget/unit-tracker.h \
+ ui/widget/unit-tracker.cpp
diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp
index 988c4e5de..8287452d7 100644
--- a/src/ui/widget/page-sizer.cpp
+++ b/src/ui/widget/page-sizer.cpp
@@ -37,7 +37,7 @@
#include "desktop.h"
#include "helper/action.h"
#include "helper/action-context.h"
-#include "helper/units.h"
+#include "util/units.h"
#include "inkscape.h"
#include "sp-namedview.h"
#include "sp-root.h"
@@ -48,6 +48,7 @@
#include "xml/repr.h"
using std::pair;
+using Inkscape::Util::unit_table;
namespace Inkscape {
namespace UI {
@@ -96,7 +97,7 @@ struct PaperSizeRec {
char const * const name; //name
double const smaller; //lesser dimension
double const larger; //greater dimension
- SPUnitId const unit; //units
+ Glib::ustring const unit; //units
};
// list of page formats that should be in landscape automatically
@@ -114,31 +115,31 @@ fill_landscape_papers() {
}
static PaperSizeRec const inkscape_papers[] = {
- { "A4", 210, 297, SP_UNIT_MM },
- { "US Letter", 8.5, 11, SP_UNIT_IN },
- { "US Legal", 8.5, 14, SP_UNIT_IN },
- { "US Executive", 7.25, 10.5, SP_UNIT_IN },
- { "A0", 841, 1189, SP_UNIT_MM },
- { "A1", 594, 841, SP_UNIT_MM },
- { "A2", 420, 594, SP_UNIT_MM },
- { "A3", 297, 420, SP_UNIT_MM },
- { "A5", 148, 210, SP_UNIT_MM },
- { "A6", 105, 148, SP_UNIT_MM },
- { "A7", 74, 105, SP_UNIT_MM },
- { "A8", 52, 74, SP_UNIT_MM },
- { "A9", 37, 52, SP_UNIT_MM },
- { "A10", 26, 37, SP_UNIT_MM },
- { "B0", 1000, 1414, SP_UNIT_MM },
- { "B1", 707, 1000, SP_UNIT_MM },
- { "B2", 500, 707, SP_UNIT_MM },
- { "B3", 353, 500, SP_UNIT_MM },
- { "B4", 250, 353, SP_UNIT_MM },
- { "B5", 176, 250, SP_UNIT_MM },
- { "B6", 125, 176, SP_UNIT_MM },
- { "B7", 88, 125, SP_UNIT_MM },
- { "B8", 62, 88, SP_UNIT_MM },
- { "B9", 44, 62, SP_UNIT_MM },
- { "B10", 31, 44, SP_UNIT_MM },
+ { "A4", 210, 297, "mm" },
+ { "US Letter", 8.5, 11, "in" },
+ { "US Legal", 8.5, 14, "in" },
+ { "US Executive", 7.25, 10.5, "in" },
+ { "A0", 841, 1189, "mm" },
+ { "A1", 594, 841, "mm" },
+ { "A2", 420, 594, "mm" },
+ { "A3", 297, 420, "mm" },
+ { "A5", 148, 210, "mm" },
+ { "A6", 105, 148, "mm" },
+ { "A7", 74, 105, "mm" },
+ { "A8", 52, 74, "mm" },
+ { "A9", 37, 52, "mm" },
+ { "A10", 26, 37, "mm" },
+ { "B0", 1000, 1414, "mm" },
+ { "B1", 707, 1000, "mm" },
+ { "B2", 500, 707, "mm" },
+ { "B3", 353, 500, "mm" },
+ { "B4", 250, 353, "mm" },
+ { "B5", 176, 250, "mm" },
+ { "B6", 125, 176, "mm" },
+ { "B7", 88, 125, "mm" },
+ { "B8", 62, 88, "mm" },
+ { "B9", 44, 62, "mm" },
+ { "B10", 31, 44, "mm" },
@@ -150,63 +151,63 @@ static PaperSizeRec const inkscape_papers[] = {
don't know what D and E series are used for.
*/
- { "C0", 917, 1297, SP_UNIT_MM },
- { "C1", 648, 917, SP_UNIT_MM },
- { "C2", 458, 648, SP_UNIT_MM },
- { "C3", 324, 458, SP_UNIT_MM },
- { "C4", 229, 324, SP_UNIT_MM },
- { "C5", 162, 229, SP_UNIT_MM },
- { "C6", 114, 162, SP_UNIT_MM },
- { "C7", 81, 114, SP_UNIT_MM },
- { "C8", 57, 81, SP_UNIT_MM },
- { "C9", 40, 57, SP_UNIT_MM },
- { "C10", 28, 40, SP_UNIT_MM },
- { "D1", 545, 771, SP_UNIT_MM },
- { "D2", 385, 545, SP_UNIT_MM },
- { "D3", 272, 385, SP_UNIT_MM },
- { "D4", 192, 272, SP_UNIT_MM },
- { "D5", 136, 192, SP_UNIT_MM },
- { "D6", 96, 136, SP_UNIT_MM },
- { "D7", 68, 96, SP_UNIT_MM },
- { "E3", 400, 560, SP_UNIT_MM },
- { "E4", 280, 400, SP_UNIT_MM },
- { "E5", 200, 280, SP_UNIT_MM },
- { "E6", 140, 200, SP_UNIT_MM },
+ { "C0", 917, 1297, "mm" },
+ { "C1", 648, 917, "mm" },
+ { "C2", 458, 648, "mm" },
+ { "C3", 324, 458, "mm" },
+ { "C4", 229, 324, "mm" },
+ { "C5", 162, 229, "mm" },
+ { "C6", 114, 162, "mm" },
+ { "C7", 81, 114, "mm" },
+ { "C8", 57, 81, "mm" },
+ { "C9", 40, 57, "mm" },
+ { "C10", 28, 40, "mm" },
+ { "D1", 545, 771, "mm" },
+ { "D2", 385, 545, "mm" },
+ { "D3", 272, 385, "mm" },
+ { "D4", 192, 272, "mm" },
+ { "D5", 136, 192, "mm" },
+ { "D6", 96, 136, "mm" },
+ { "D7", 68, 96, "mm" },
+ { "E3", 400, 560, "mm" },
+ { "E4", 280, 400, "mm" },
+ { "E5", 200, 280, "mm" },
+ { "E6", 140, 200, "mm" },
//#endif
- { "CSE", 462, 649, SP_UNIT_PT },
- { "US #10 Envelope", 4.125, 9.5, SP_UNIT_IN },
+ { "CSE", 462, 649, "pt" },
+ { "US #10 Envelope", 4.125, 9.5, "in" },
/* See http://www.hbp.com/content/PCR_envelopes.cfm for a much larger list of US envelope
sizes. */
- { "DL Envelope", 110, 220, SP_UNIT_MM },
- { "Ledger/Tabloid", 11, 17, SP_UNIT_IN },
+ { "DL Envelope", 110, 220, "mm" },
+ { "Ledger/Tabloid", 11, 17, "in" },
/* Note that `Folio' (used in QPrinter/KPrinter) is deliberately absent from this list, as it
means different sizes to different people: different people may expect the width to be
either 8, 8.25 or 8.5 inches, and the height to be either 13 or 13.5 inches, even
restricting our interpretation to foolscap folio. If you wish to introduce a folio-like
page size to the list, then please consider using a name more specific than just `Folio' or
`Foolscap Folio'. */
- { "Banner 468x60", 60, 468, SP_UNIT_PX },
- { "Icon 16x16", 16, 16, SP_UNIT_PX },
- { "Icon 32x32", 32, 32, SP_UNIT_PX },
- { "Icon 48x48", 48, 48, SP_UNIT_PX },
+ { "Banner 468x60", 60, 468, "px" },
+ { "Icon 16x16", 16, 16, "px" },
+ { "Icon 32x32", 32, 32, "px" },
+ { "Icon 48x48", 48, 48, "px" },
/* business cards */
- { "Business Card (ISO 7810)", 53.98, 85.60, SP_UNIT_MM },
- { "Business Card (US)", 2, 3.5, SP_UNIT_IN },
- { "Business Card (Europe)", 55, 85, SP_UNIT_MM },
- { "Business Card (Aus/NZ)", 55, 90, SP_UNIT_MM },
+ { "Business Card (ISO 7810)", 53.98, 85.60, "mm" },
+ { "Business Card (US)", 2, 3.5, "in" },
+ { "Business Card (Europe)", 55, 85, "mm" },
+ { "Business Card (Aus/NZ)", 55, 90, "mm" },
// Start Arch Series List
- { "Arch A", 9, 12, SP_UNIT_IN }, // 229 x 305 mm
- { "Arch B", 12, 18, SP_UNIT_IN }, // 305 x 457 mm
- { "Arch C", 18, 24, SP_UNIT_IN }, // 457 x 610 mm
- { "Arch D", 24, 36, SP_UNIT_IN }, // 610 x 914 mm
- { "Arch E", 36, 48, SP_UNIT_IN }, // 914 x 1219 mm
- { "Arch E1", 30, 42, SP_UNIT_IN }, // 762 x 1067 mm
+ { "Arch A", 9, 12, "in" }, // 229 x 305 mm
+ { "Arch B", 12, 18, "in" }, // 305 x 457 mm
+ { "Arch C", 18, 24, "in" }, // 457 x 610 mm
+ { "Arch D", 24, 36, "in" }, // 610 x 914 mm
+ { "Arch E", 36, 48, "in" }, // 914 x 1219 mm
+ { "Arch E1", 30, 42, "in" }, // 762 x 1067 mm
/*
* The above list of Arch sizes were taken from the following site:
@@ -217,7 +218,7 @@ static PaperSizeRec const inkscape_papers[] = {
* September 2009 - DAK
*/
- { NULL, 0, 0, SP_UNIT_PX },
+ { NULL, 0, 0, "px" },
};
@@ -226,10 +227,6 @@ static PaperSizeRec const inkscape_papers[] = {
//# P A G E S I Z E R
//########################################################################
-//The default unit for this widget and its calculations
-static const SPUnit _px_unit = sp_unit_get_by_id (SP_UNIT_PX);
-
-
/**
* Constructor
*/
@@ -280,13 +277,8 @@ PageSizer::PageSizer(Registry & _wr)
char formatBuf[80];
snprintf(formatBuf, 79, "%0.1f x %0.1f", p->smaller, p->larger);
Glib::ustring desc = formatBuf;
- if (p->unit == SP_UNIT_IN)
- desc.append(" in");
- else if (p->unit == SP_UNIT_MM)
- desc.append(" mm");
- else if (p->unit == SP_UNIT_PX)
- desc.append(" px");
- PaperSize paper(name, p->smaller, p->larger, p->unit);
+ desc.append(" " + p->unit);
+ PaperSize paper(name, p->smaller, p->larger, unit_table.getUnit(p->unit));
_paperSizeTable[name] = paper;
Gtk::TreeModel::Row row = *(_paperSizeListStore->append());
row[_paperSizeListColumns.nameColumn] = name;
@@ -320,9 +312,9 @@ PageSizer::PageSizer(Registry & _wr)
SPNamedView *nv = sp_desktop_namedview(dt);
_wr.setUpdating (true);
if (nv->units) {
- _dimensionUnits.setUnit(nv->units);
+ _dimensionUnits.setUnit(nv->units->abbr);
} else if (nv->doc_units) {
- _dimensionUnits.setUnit(nv->doc_units);
+ _dimensionUnits.setUnit(nv->doc_units->abbr);
}
_wr.setUpdating (false);
@@ -484,8 +476,8 @@ PageSizer::setDim (double w, double h, bool changeList)
if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) {
SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP);
double const old_height = doc->getHeight();
- doc->setWidth (w, &_px_unit);
- doc->setHeight (h, &_px_unit);
+ doc->setWidth (Inkscape::Util::Quantity(w, "px"));
+ doc->setHeight (Inkscape::Util::Quantity(h, "px"));
// The origin for the user is in the lower left corner; this point should remain stationary when
// changing the page size. The SVG's origin however is in the upper left corner, so we must compensate for this
Geom::Translate const vert_offset(Geom::Point(0, (old_height - h)));
@@ -569,9 +561,9 @@ PageSizer::find_paper_size (double w, double h) const
for (iter = _paperSizeTable.begin() ;
iter != _paperSizeTable.end() ; ++iter) {
PaperSize paper = iter->second;
- SPUnit const &i_unit = sp_unit_get_by_id(paper.unit);
- double smallX = sp_units_get_pixels(paper.smaller, i_unit);
- double largeX = sp_units_get_pixels(paper.larger, i_unit);
+ Inkscape::Util::Unit const &i_unit = paper.unit;
+ double smallX = Inkscape::Util::Quantity::convert(paper.smaller, i_unit, "px");
+ double largeX = Inkscape::Util::Quantity::convert(paper.larger, i_unit, "px");
g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end());
@@ -662,9 +654,8 @@ PageSizer::on_paper_size_list_changed()
_landscape = _landscapeButton.get_active();
}
- SPUnit const &src_unit = sp_unit_get_by_id (paper.unit);
- sp_convert_distance (&w, &src_unit, &_px_unit);
- sp_convert_distance (&h, &src_unit, &_px_unit);
+ w = Inkscape::Util::Quantity::convert(w, paper.unit, "px");
+ h = Inkscape::Util::Quantity::convert(h, paper.unit, "px");
if (_landscape)
setDim (h, w, false);
diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h
index d1fbb56e0..34ed7592d 100644
--- a/src/ui/widget/page-sizer.h
+++ b/src/ui/widget/page-sizer.h
@@ -18,7 +18,7 @@
#include "ui/widget/registered-widget.h"
#include <sigc++/sigc++.h>
-#include "helper/units.h"
+#include "util/units.h"
#include <gtkmm/alignment.h>
#include <gtkmm/expander.h>
@@ -64,7 +64,7 @@ public:
PaperSize(const Glib::ustring &nameArg,
double smallerArg,
double largerArg,
- SPUnitId unitArg)
+ Inkscape::Util::Unit unitArg)
{
name = nameArg;
smaller = smallerArg;
@@ -108,7 +108,7 @@ public:
/**
* The units (px, pt, mm, etc) of this specification
*/
- SPUnitId unit;
+ Inkscape::Util::Unit unit;
private:
@@ -117,7 +117,7 @@ private:
name = "";
smaller = 0.0;
larger = 0.0;
- unit = SP_UNIT_PX;
+ unit = unit_table.getUnit("px");
}
void assign(const PaperSize &other)
diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp
index ea2bac867..ae6a7d1e0 100644
--- a/src/ui/widget/registered-widget.cpp
+++ b/src/ui/widget/registered-widget.cpp
@@ -27,7 +27,6 @@
#include "ui/widget/random.h"
#include "widgets/spinbutton-events.h"
-#include "helper/units.h"
#include "xml/repr.h"
#include "svg/svg-color.h"
#include "svg/stringstream.h"
@@ -118,9 +117,9 @@ RegisteredUnitMenu::RegisteredUnitMenu (const Glib::ustring& label, const Glib::
}
void
-RegisteredUnitMenu::setUnit (const SPUnit* unit)
+RegisteredUnitMenu::setUnit (Glib::ustring unit)
{
- getUnitMenu()->setUnit (sp_unit_get_abbreviation (unit));
+ getUnitMenu()->setUnit(unit);
}
void
diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h
index 18a84ea05..93b0cef4e 100644
--- a/src/ui/widget/registered-widget.h
+++ b/src/ui/widget/registered-widget.h
@@ -32,7 +32,6 @@
#include <gtkmm/checkbutton.h>
-struct SPUnit;
class SPDocument;
namespace Gtk {
@@ -167,7 +166,7 @@ public:
Inkscape::XML::Node* repr_in = NULL,
SPDocument *doc_in = NULL );
- void setUnit (const SPUnit*);
+ void setUnit (const Glib::ustring);
Unit getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); };
UnitMenu* getUnitMenu() const { return static_cast<UnitMenu*>(_widget); };
sigc::connection _changed_connection;
diff --git a/src/ui/widget/rendering-options.cpp b/src/ui/widget/rendering-options.cpp
index f26e71553..d6248df69 100644
--- a/src/ui/widget/rendering-options.cpp
+++ b/src/ui/widget/rendering-options.cpp
@@ -13,7 +13,7 @@
#endif
#include "rendering-options.h"
-#include "unit-constants.h"
+#include "util/units.h"
#include <glibmm/i18n.h>
namespace Inkscape {
@@ -59,8 +59,8 @@ RenderingOptions::RenderingOptions () :
_radio_bitmap.signal_toggled().connect(sigc::mem_fun(*this, &RenderingOptions::_toggled));
// configure default DPI
- _dpi.setRange(PT_PER_IN,2400.0);
- _dpi.setValue(PT_PER_IN);
+ _dpi.setRange(Inkscape::Util::Quantity::convert(1, "in", "pt"),2400.0);
+ _dpi.setValue(Inkscape::Util::Quantity::convert(1, "in", "pt"));
_dpi.setIncrements(1.0,10.0);
_dpi.setDigits(0);
_dpi.update();
diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp
index 99ff70846..2f4c1f341 100644
--- a/src/ui/widget/scalar-unit.cpp
+++ b/src/ui/widget/scalar-unit.cpp
@@ -16,6 +16,8 @@
#include "scalar-unit.h"
#include "spinbutton.h"
+using Inkscape::Util::unit_table;
+
namespace Inkscape {
namespace UI {
namespace Widget {
@@ -226,9 +228,8 @@ void ScalarUnit::on_unit_changed()
Glib::ustring abbr = _unit_menu->getUnitAbbr();
_suffix->set_label(abbr);
- Inkscape::Util::UnitTable &table = _unit_menu->getUnitTable();
- Inkscape::Util::Unit new_unit = (table.getUnit(abbr));
- Inkscape::Util::Unit old_unit = (table.getUnit(lastUnits));
+ Inkscape::Util::Unit new_unit = (unit_table.getUnit(abbr));
+ Inkscape::Util::Unit old_unit = (unit_table.getUnit(lastUnits));
double convertedVal = 0;
if (old_unit.type == UNIT_TYPE_DIMENSIONLESS && new_unit.type == UNIT_TYPE_LINEAR) {
diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp
index 18dbb984b..388a0bcea 100644
--- a/src/ui/widget/selected-style.cpp
+++ b/src/ui/widget/selected-style.cpp
@@ -50,6 +50,9 @@
#include "pixmaps/cursor-adj-a.xpm"
#include "sp-cursor.h"
#include "gradient-chemistry.h"
+#include "util/units.h"
+
+using Inkscape::Util::unit_table;
static gdouble const _sw_presets[] = { 32 , 16 , 10 , 8 , 6 , 4 , 3 , 2 , 1.5 , 1 , 0.75 , 0.5 , 0.25 , 0.1 };
static gchar const *const _sw_presets_str[] = {"32", "16", "10", "8", "6", "4", "3", "2", "1.5", "1", "0.75", "0.5", "0.25", "0.1"};
@@ -306,15 +309,17 @@ SelectedStyle::SelectedStyle(bool /*layout*/)
{
int row = 0;
- // List of units should match with Fill/Stroke dialog stroke style width list
- for (GSList *l = sp_unit_get_list(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); l != NULL; l = l->next) {
- SPUnit const *u = static_cast<SPUnit*>(l->data);
+ Inkscape::Util::UnitTable::UnitMap m = unit_table.units(Inkscape::Util::UNIT_TYPE_LINEAR);
+ Inkscape::Util::UnitTable::UnitMap::iterator iter = m.begin();
+ while(iter != m.end()) {
Gtk::RadioMenuItem *mi = Gtk::manage(new Gtk::RadioMenuItem(_sw_group));
- mi->add(*(new Gtk::Label(u->abbr, 0.0, 0.5)));
+ mi->add(*(new Gtk::Label((*iter).first, 0.0, 0.5)));
_unit_mis = g_slist_append(_unit_mis, mi);
- mi->signal_activate().connect(sigc::bind<SPUnitId>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u->unit_id));
+ Inkscape::Util::Unit const *u = new Inkscape::Util::Unit(unit_table.getUnit(iter->first));
+ mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), *u));
_popup_sw.attach(*mi, 0,1, row, row+1);
row++;
+ ++iter;
}
_popup_sw.attach(*(new Gtk::SeparatorMenuItem()), 0,1, row, row+1);
@@ -476,13 +481,13 @@ SelectedStyle::setDesktop(SPDesktop *desktop)
this )
));
- _sw_unit = const_cast<SPUnit*>(sp_desktop_namedview(desktop)->doc_units);
+ _sw_unit = const_cast<Inkscape::Util::Unit*>(sp_desktop_namedview(desktop)->doc_units);
// Set the doc default unit active in the units list
gint length = g_slist_length(_unit_mis);
for (int i = 0; i < length; i++) {
Gtk::RadioMenuItem *mi = (Gtk::RadioMenuItem *) g_slist_nth_data(_unit_mis, i);
- if (mi && mi->get_label() == Glib::ustring(_sw_unit->abbr)) {
+ if (mi && mi->get_label() == _sw_unit->abbr) {
mi->set_active();
break;
}
@@ -926,8 +931,8 @@ SelectedStyle::on_opacity_click(GdkEventButton *event)
return false;
}
-void SelectedStyle::on_popup_units(SPUnitId id) {
- _sw_unit = (SPUnit *) &(sp_unit_get_by_id(id));
+void SelectedStyle::on_popup_units(Inkscape::Util::Unit &unit) {
+ _sw_unit = new Inkscape::Util::Unit(unit);
update();
}
@@ -935,7 +940,7 @@ void SelectedStyle::on_popup_preset(int i) {
SPCSSAttr *css = sp_repr_css_attr_new ();
gdouble w;
if (_sw_unit) {
- w = sp_units_get_pixels (_sw_presets[i], *_sw_unit);
+ w = Inkscape::Util::Quantity::convert(_sw_presets[i], *_sw_unit, "px");
} else {
w = _sw_presets[i];
}
@@ -1114,7 +1119,7 @@ SelectedStyle::update()
{
double w;
if (_sw_unit) {
- w = sp_pixels_get_units(query->stroke_width.computed, *_sw_unit);
+ w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *_sw_unit);
} else {
w = query->stroke_width.computed;
}
@@ -1128,7 +1133,7 @@ SelectedStyle::update()
{
gchar *str = g_strdup_printf(_("Stroke width: %.5g%s%s"),
w,
- _sw_unit? sp_unit_get_abbreviation(_sw_unit) : "px",
+ _sw_unit? _sw_unit->abbr.c_str() : "px",
(result_sw == QUERY_STYLE_MULTIPLE_AVERAGED)?
_(" (averaged)") : "");
_stroke_width_place.set_tooltip_text(str);
diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h
index e5bc4f883..0a907f1fd 100644
--- a/src/ui/widget/selected-style.h
+++ b/src/ui/widget/selected-style.h
@@ -41,12 +41,15 @@
#include <sigc++/sigc++.h>
#include "rotateable.h"
-#include "helper/units.h"
class SPDesktop;
-struct SPUnit;
namespace Inkscape {
+
+namespace Util {
+ class Unit;
+}
+
namespace UI {
namespace Widget {
@@ -273,11 +276,11 @@ protected:
Gtk::Menu _popup_sw;
Gtk::RadioButtonGroup _sw_group;
GSList *_unit_mis;
- void on_popup_units(SPUnitId id);
+ void on_popup_units(Inkscape::Util::Unit &u);
void on_popup_preset(int i);
Gtk::MenuItem _popup_sw_remove;
- SPUnit *_sw_unit;
+ Inkscape::Util::Unit *_sw_unit;
void *_drop[2];
bool _dropEnabled[2];
diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp
index aedab3fa5..682457bed 100644
--- a/src/ui/widget/style-swatch.cpp
+++ b/src/ui/widget/style-swatch.cpp
@@ -26,7 +26,7 @@
#include "xml/repr.h"
#include "xml/sp-css-attr.h"
#include "widgets/widget-sizes.h"
-#include "helper/units.h"
+#include "util/units.h"
#include "helper/action.h"
#include "helper/action-context.h"
#include "preferences.h"
@@ -333,7 +333,7 @@ void StyleSwatch::setStyle(SPStyle *query)
if (has_stroke) {
double w;
if (_sw_unit) {
- w = sp_pixels_get_units(query->stroke_width.computed, *_sw_unit);
+ w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *_sw_unit);
} else {
w = query->stroke_width.computed;
}
@@ -346,7 +346,7 @@ void StyleSwatch::setStyle(SPStyle *query)
{
gchar *str = g_strdup_printf(_("Stroke width: %.5g%s"),
w,
- _sw_unit? sp_unit_get_abbreviation(_sw_unit) : "px");
+ _sw_unit? _sw_unit->abbr.c_str() : "px");
_stroke_width_place.set_tooltip_text(str);
g_free (str);
}
diff --git a/src/ui/widget/style-swatch.h b/src/ui/widget/style-swatch.h
index 6bdb5e248..6da58a2dd 100644
--- a/src/ui/widget/style-swatch.h
+++ b/src/ui/widget/style-swatch.h
@@ -30,7 +30,6 @@
#include "button.h"
#include "preferences.h"
-struct SPUnit;
struct SPStyle;
class SPCSSAttr;
@@ -43,6 +42,11 @@ class Table;
}
namespace Inkscape {
+
+namespace Util {
+ class Unit;
+}
+
namespace UI {
namespace Widget {
@@ -93,7 +97,7 @@ private:
Gtk::EventBox _stroke_width_place;
Gtk::Label _stroke_width;
- SPUnit *_sw_unit;
+ Inkscape::Util::Unit *_sw_unit;
friend class ToolObserver;
};
diff --git a/src/ui/widget/unit-menu.cpp b/src/ui/widget/unit-menu.cpp
index 18b7bcab9..111226774 100644
--- a/src/ui/widget/unit-menu.cpp
+++ b/src/ui/widget/unit-menu.cpp
@@ -15,6 +15,8 @@
#include "unit-menu.h"
+using Inkscape::Util::unit_table;
+
namespace Inkscape {
namespace UI {
namespace Widget {
@@ -30,7 +32,7 @@ UnitMenu::~UnitMenu() {
bool UnitMenu::setUnitType(UnitType unit_type)
{
// Expand the unit widget with unit entries from the unit table
- UnitTable::UnitMap m = _unit_table.units(unit_type);
+ UnitTable::UnitMap m = unit_table.units(unit_type);
UnitTable::UnitMap::iterator iter = m.begin();
while(iter != m.end()) {
Glib::ustring text = (*iter).first;
@@ -38,7 +40,7 @@ bool UnitMenu::setUnitType(UnitType unit_type)
++iter;
}
_type = unit_type;
- set_active_text(_unit_table.primary(unit_type));
+ set_active_text(unit_table.primary(unit_type));
return true;
}
@@ -52,7 +54,7 @@ bool UnitMenu::resetUnitType(UnitType unit_type)
void UnitMenu::addUnit(Unit const& u)
{
- _unit_table.addUnit(u, false);
+ unit_table.addUnit(u, false);
append(u.abbr);
}
@@ -60,9 +62,9 @@ Unit UnitMenu::getUnit() const
{
if (get_active_text() == "") {
g_assert(_type != UNIT_TYPE_NONE);
- return _unit_table.getUnit(_unit_table.primary(_type));
+ return unit_table.getUnit(unit_table.primary(_type));
}
- return _unit_table.getUnit(get_active_text());
+ return unit_table.getUnit(get_active_text());
}
bool UnitMenu::setUnit(Glib::ustring const & unit)
@@ -112,8 +114,8 @@ double UnitMenu::getConversion(Glib::ustring const &new_unit_abbr, Glib::ustring
{
double old_factor = getUnit().factor;
if (old_unit_abbr != "no_unit")
- old_factor = _unit_table.getUnit(old_unit_abbr).factor;
- Unit new_unit = _unit_table.getUnit(new_unit_abbr);
+ old_factor = unit_table.getUnit(old_unit_abbr).factor;
+ Unit new_unit = unit_table.getUnit(new_unit_abbr);
// Catch the case of zero or negative unit factors (error!)
if (old_factor < 0.0000001 ||
diff --git a/src/ui/widget/unit-menu.h b/src/ui/widget/unit-menu.h
index 3104d5aef..3f4df6bf9 100644
--- a/src/ui/widget/unit-menu.h
+++ b/src/ui/widget/unit-menu.h
@@ -127,10 +127,7 @@ public:
*/
bool isRadial() const;
- UnitTable &getUnitTable() {return _unit_table;}
-
protected:
- UnitTable _unit_table;
UnitType _type;
};
diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp
new file mode 100644
index 000000000..5b2dc031b
--- /dev/null
+++ b/src/ui/widget/unit-tracker.cpp
@@ -0,0 +1,263 @@
+/*
+ * Inkscape::UI::Widget::UnitTracker
+ * Simple mediator to synchronize changes to unit menus
+ *
+ * Authors:
+ * Jon A. Cruz <jon@joncruz.org>
+ * Matthew Petroff <matthew@mpetroff.net>
+ *
+ * Copyright (C) 2007 Jon A. Cruz
+ * Copyright (C) 2013 Matthew Petroff
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "unit-tracker.h"
+#include "ege-select-one-action.h"
+
+#define COLUMN_STRING 0
+
+using Inkscape::Util::UnitTable;
+using Inkscape::Util::unit_table;
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+UnitTracker::UnitTracker(UnitType unit_type) :
+ _active(0),
+ _isUpdating(false),
+ _activeUnitInitialized(false),
+ _store(0),
+ _unitList(0),
+ _actionList(0),
+ _adjList(0),
+ _priorValues()
+{
+ _store = gtk_list_store_new(1, G_TYPE_STRING);
+
+ GtkTreeIter iter;
+ UnitTable::UnitMap m = unit_table.units(unit_type);
+ UnitTable::UnitMap::iterator m_iter = m.begin();
+ while(m_iter != m.end()) {
+ Glib::ustring text = (*m_iter).first;
+ m_iter++;
+ gtk_list_store_append(_store, &iter);
+ gtk_list_store_set(_store, &iter, COLUMN_STRING, text.c_str(), -1);
+ }
+ gint count = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(_store), 0);
+ if ((count > 0) && (_active > count)) {
+ _setActive(--count);
+ } else {
+ _setActive(_active);
+ }
+}
+
+UnitTracker::~UnitTracker()
+{
+ // Unhook weak references to GtkActions
+ while (_actionList) {
+ g_signal_handlers_disconnect_by_func(G_OBJECT(_actionList->data), (gpointer) _unitChangedCB, this);
+ g_object_weak_unref(G_OBJECT(_actionList->data), _actionFinalizedCB, this);
+ _actionList = g_slist_delete_link(_actionList, _actionList);
+ }
+
+ // Unhook weak references to GtkAdjustments
+ while (_adjList) {
+ g_object_weak_unref(G_OBJECT(_adjList->data), _adjustmentFinalizedCB, this);
+ _adjList = g_slist_delete_link(_adjList, _adjList);
+ }
+}
+
+bool UnitTracker::isUpdating() const
+{
+ return _isUpdating;
+}
+
+Inkscape::Util::Unit UnitTracker::getActiveUnit() const
+{
+ return _activeUnit;
+}
+
+void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit)
+{
+ if (unit) {
+ GtkTreeIter iter;
+ int index = 0;
+ gboolean found = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(_store), &iter);
+ while (found) {
+ gchar *storedUnit = 0;
+ gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &storedUnit, -1);
+ if (storedUnit && (!unit->abbr.compare(storedUnit))) {
+ _setActive(index);
+ break;
+ }
+
+ found = gtk_tree_model_iter_next(GTK_TREE_MODEL(_store), &iter);
+ index++;
+ }
+ }
+}
+
+void UnitTracker::setActiveUnitByAbbr(gchar const *abbr)
+{
+ Inkscape::Util::Unit u = unit_table.getUnit(abbr);
+ setActiveUnit(&u);
+}
+
+void UnitTracker::addAdjustment(GtkAdjustment *adj)
+{
+ if (!g_slist_find(_adjList, adj)) {
+ g_object_weak_ref(G_OBJECT(adj), _adjustmentFinalizedCB, this);
+ _adjList = g_slist_append(_adjList, adj);
+ }
+}
+
+void UnitTracker::addUnit(Inkscape::Util::Unit const &u)
+{
+ GtkTreeIter iter;
+ gtk_list_store_append(_store, &iter);
+ gtk_list_store_set(_store, &iter, COLUMN_STRING, u.abbr.c_str(), -1);
+}
+
+void UnitTracker::setFullVal(GtkAdjustment *adj, gdouble val)
+{
+ _priorValues[adj] = val;
+}
+
+GtkAction *UnitTracker::createAction(gchar const *name, gchar const *label, gchar const *tooltip)
+{
+ EgeSelectOneAction *act1 = ege_select_one_action_new(name, label, tooltip, NULL, GTK_TREE_MODEL(_store));
+ ege_select_one_action_set_label_column(act1, COLUMN_STRING);
+ if (_active) {
+ ege_select_one_action_set_active(act1, _active);
+ }
+
+ ege_select_one_action_set_appearance(act1, "minimal");
+ g_object_weak_ref(G_OBJECT(act1), _actionFinalizedCB, this);
+ g_signal_connect(G_OBJECT(act1), "changed", G_CALLBACK(_unitChangedCB), this);
+ _actionList = g_slist_append(_actionList, act1);
+
+ return GTK_ACTION(act1);
+}
+
+void UnitTracker::_unitChangedCB(GtkAction *action, gpointer data)
+{
+ if (action && data) {
+ EgeSelectOneAction *act = EGE_SELECT_ONE_ACTION(action);
+ gint active = ege_select_one_action_get_active(act);
+ UnitTracker *self = reinterpret_cast<UnitTracker *>(data);
+ self->_setActive(active);
+ }
+}
+
+void UnitTracker::_actionFinalizedCB(gpointer data, GObject *where_the_object_was)
+{
+ if (data && where_the_object_was) {
+ UnitTracker *self = reinterpret_cast<UnitTracker *>(data);
+ self->_actionFinalized(where_the_object_was);
+ }
+}
+
+void UnitTracker::_adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was)
+{
+ if (data && where_the_object_was) {
+ UnitTracker *self = reinterpret_cast<UnitTracker *>(data);
+ self->_adjustmentFinalized(where_the_object_was);
+ }
+}
+
+void UnitTracker::_actionFinalized(GObject *where_the_object_was)
+{
+ GSList *target = g_slist_find(_actionList, where_the_object_was);
+ if (target) {
+ _actionList = g_slist_remove(_actionList, where_the_object_was);
+ } else {
+ g_warning("Received a finalization callback for unknown object %p", where_the_object_was);
+ }
+}
+
+void UnitTracker::_adjustmentFinalized(GObject *where_the_object_was)
+{
+ GSList *target = g_slist_find(_adjList, where_the_object_was);
+ if (target) {
+ _adjList = g_slist_remove(_adjList, where_the_object_was);
+ } else {
+ g_warning("Received a finalization callback for unknown object %p", where_the_object_was);
+ }
+}
+
+void UnitTracker::_setActive(gint active)
+{
+ if ( active != _active || !_activeUnitInitialized ) {
+ gint oldActive = _active;
+
+ GtkTreeIter iter;
+ gboolean found = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(_store), &iter, NULL, oldActive);
+ if (found) {
+ gchar *abbr;
+ gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &abbr, -1);
+ Inkscape::Util::Unit unit = unit_table.getUnit(abbr);
+
+ found = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(_store), &iter, NULL, active);
+ if (found) {
+ gchar *newAbbr;
+ gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &newAbbr, -1);
+ Inkscape::Util::Unit newUnit = unit_table.getUnit(newAbbr);
+ _activeUnit = newUnit;
+
+ if (_adjList) {
+ _fixupAdjustments(unit, newUnit);
+ }
+
+ } else {
+ g_warning("Did not find new unit");
+ }
+ } else {
+ g_warning("Did not find old unit");
+ }
+
+ _active = active;
+
+ for ( GSList *cur = _actionList ; cur ; cur = g_slist_next(cur) ) {
+ if (IS_EGE_SELECT_ONE_ACTION(cur->data)) {
+ EgeSelectOneAction *act = EGE_SELECT_ONE_ACTION(cur->data);
+ ege_select_one_action_set_active(act, active);
+ }
+ }
+
+ _activeUnitInitialized = true;
+ }
+}
+
+void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape::Util::Unit const newUnit)
+{
+ _isUpdating = true;
+ for ( GSList *cur = _adjList ; cur ; cur = g_slist_next(cur) ) {
+ GtkAdjustment *adj = GTK_ADJUSTMENT(cur->data);
+ gdouble oldVal = gtk_adjustment_get_value(adj);
+ gdouble val = oldVal;
+
+ if ( (oldUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS)
+ && (newUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) )
+ {
+ val = newUnit.factor * 100;
+ _priorValues[adj] = Inkscape::Util::Quantity::convert(oldVal, oldUnit, "px");
+ } else if ( (oldUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS)
+ && (newUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) )
+ {
+ if (_priorValues.find(adj) != _priorValues.end()) {
+ val = Inkscape::Util::Quantity::convert(_priorValues[adj], "px", newUnit);
+ }
+ } else {
+ val = Inkscape::Util::Quantity::convert(oldVal, oldUnit, newUnit);
+ }
+
+ gtk_adjustment_set_value(adj, val);
+ }
+ _isUpdating = false;
+}
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h
new file mode 100644
index 000000000..19559ae1c
--- /dev/null
+++ b/src/ui/widget/unit-tracker.h
@@ -0,0 +1,74 @@
+/*
+ * Inkscape::UI::Widget::UnitTracker
+ * Simple mediator to synchronize changes to unit menus
+ *
+ * Authors:
+ * Jon A. Cruz <jon@joncruz.org>
+ * Matthew Petroff <matthew@mpetroff.net>
+ *
+ * Copyright (C) 2007 Jon A. Cruz
+ * Copyright (C) 2013 Matthew Petroff
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef INKSCAPE_UI_WIDGET_UNIT_TRACKER_H
+#define INKSCAPE_UI_WIDGET_UNIT_TRACKER_H
+
+#include <map>
+#include <gtk/gtk.h>
+
+#include "util/units.h"
+
+using Inkscape::Util::Unit;
+using Inkscape::Util::UnitType;
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class UnitTracker {
+public:
+ UnitTracker(UnitType unit_type);
+ virtual ~UnitTracker();
+
+ bool isUpdating() const;
+
+ void setActiveUnit(Inkscape::Util::Unit const *unit);
+ void setActiveUnitByAbbr(gchar const *abbr);
+ Inkscape::Util::Unit getActiveUnit() const;
+
+ void addUnit(Inkscape::Util::Unit const &u);
+ void addAdjustment(GtkAdjustment *adj);
+ void setFullVal(GtkAdjustment *adj, gdouble val);
+
+ GtkAction *createAction(gchar const *name, gchar const *label, gchar const *tooltip);
+
+protected:
+ UnitType _type;
+
+private:
+ static void _unitChangedCB(GtkAction *action, gpointer data);
+ static void _actionFinalizedCB(gpointer data, GObject *where_the_object_was);
+ static void _adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was);
+ void _setActive(gint index);
+ void _fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape::Util::Unit const newUnit);
+ void _actionFinalized(GObject *where_the_object_was);
+ void _adjustmentFinalized(GObject *where_the_object_was);
+
+ gint _active;
+ bool _isUpdating;
+ Inkscape::Util::Unit _activeUnit;
+ bool _activeUnitInitialized;
+ GtkListStore *_store;
+ GSList *_unitList;
+ GSList *_actionList;
+ GSList *_adjList;
+ std::map <GtkAdjustment *, gdouble> _priorValues;
+};
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_WIDGET_UNIT_TRACKER_H
diff --git a/src/unit-constants.h b/src/unit-constants.h
deleted file mode 100644
index c56c0a6e8..000000000
--- a/src/unit-constants.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#ifndef INKSCAPE_UNIT_CONSTANTS_H
-#define INKSCAPE_UNIT_CONSTANTS_H
-
-// 72 points per inch divided by the SVG-recommended value of 90 pixels per inch for computer screen
-// For now it is constant throughout Inkscape, later we may make it changeable.
-// Ideally this should be the only place to change it, but this is not guaranteed (be careful!)
-#define DEVICESCALE 0.8
-
-#define PT_PER_IN 72.0
-#define PT_PER_PX DEVICESCALE
-#define PT_PER_PC 12.0
-#define PX_PER_PT (1/DEVICESCALE)
-#define PX_PER_PC (PX_PER_PT * PT_PER_PC)
-#define PX_PER_IN (PT_PER_IN / PT_PER_PX)
-#define PC_PER_IN (PT_PER_IN / PT_PER_PC)
-#define M_PER_IN 0.0254
-#define M_PER_PX (M_PER_IN / PX_PER_IN)
-#define CM_PER_IN 2.54
-#define MM_PER_IN 25.4
-#define MM_PER_MM 1.0
-#define MM_PER_CM 10.0
-#define MM_PER_M 1000.0
-#define IN_PER_PT (1 / PT_PER_IN)
-#define IN_PER_PX (1 / PX_PER_IN)
-#define IN_PER_CM (1 / CM_PER_IN)
-#define IN_PER_MM (1 / MM_PER_IN)
-#define IN_PER_FT 12.0
-#define FT_PER_IN (1 / IN_PER_FT)
-#define PT_PER_CM (PT_PER_IN / CM_PER_IN)
-#define PX_PER_CM (PX_PER_IN / CM_PER_IN)
-#define M_PER_PT (M_PER_IN / PT_PER_IN)
-#define PT_PER_M (PT_PER_IN / M_PER_IN)
-#define PX_PER_M (PX_PER_IN / M_PER_IN)
-#define CM_PER_PT (CM_PER_IN / PT_PER_IN)
-#define CM_PER_PX (CM_PER_IN / PX_PER_IN)
-#define MM_PER_PT (MM_PER_IN / PT_PER_IN)
-#define PT_PER_MM (PT_PER_IN / MM_PER_IN)
-#define PX_PER_MM (PX_PER_IN / MM_PER_IN)
-#define MM_PER_PX (MM_PER_IN / PX_PER_IN)
-#define PX_PER_FT (PX_PER_IN / FT_PER_IN)
-#define PT_PER_PT 1.0
-#define PC_PER_PC 1.0
-#define IN_PER_IN 1.0
-#define PX_PER_PX 1.0
-#define FT_PER_FT 1.0
-
-#endif /* !INKSCAPE_UNIT_CONSTANTS_H */
diff --git a/src/util/expression-evaluator.cpp b/src/util/expression-evaluator.cpp
index 3e1bab6bc..dc59c67f4 100644
--- a/src/util/expression-evaluator.cpp
+++ b/src/util/expression-evaluator.cpp
@@ -29,6 +29,8 @@
#include <string.h>
+using Inkscape::Util::unit_table;
+
namespace Inkscape {
namespace Util {
@@ -77,8 +79,6 @@ typedef struct
*/
static bool unitresolverproc (const gchar* identifier, GimpEevlQuantity *result, Unit* unit)
{
- static UnitTable unit_table;
-
if (!unit) {
result->value = 1;
result->dimension = 1;
diff --git a/src/util/units.cpp b/src/util/units.cpp
index f8ebc5c1a..7bc910fcc 100644
--- a/src/util/units.cpp
+++ b/src/util/units.cpp
@@ -1,10 +1,23 @@
+/*
+ * Inkscape Units
+ *
+ * Authors:
+ * Matthew Petroff <matthew@mpetroff.net>
+ *
+ * Copyright (C) 2013 Matthew Petroff
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <cmath>
#include <cerrno>
+#include <iomanip>
#include <glib.h>
+#include <glibmm/regex.h>
#include <glibmm/fileutils.h>
#include <glibmm/markup.h>
@@ -108,7 +121,8 @@ void Unit::clear()
*this = Unit();
}
-int Unit::defaultDigits() const {
+int Unit::defaultDigits() const
+{
int factor_digits = int(log10(factor));
if (factor_digits < 0) {
g_warning("factor = %f, factor_digits = %d", factor, factor_digits);
@@ -118,6 +132,62 @@ int Unit::defaultDigits() const {
return factor_digits;
}
+bool Unit::compatibleWith(const Unit &u) const
+{
+ // Percentages
+ if (type == UNIT_TYPE_DIMENSIONLESS || u.type == UNIT_TYPE_DIMENSIONLESS) {
+ return true;
+ }
+
+ // Other units with same type
+ if (type == u.type) {
+ return true;
+ }
+
+ // Different, incompatible types
+ return false;
+}
+bool Unit::compatibleWith(const Glib::ustring u) const
+{
+ static UnitTable unit_table;
+ return compatibleWith(unit_table.getUnit(u));
+}
+
+bool operator== (const Unit &u1, const Unit &u2)
+{
+ return (u1.type == u2.type && u1.name.compare(u2.name) == 0);
+}
+
+bool operator!= (const Unit &u1, const Unit &u2)
+{
+ return !(u1 == u2);
+}
+
+int Unit::svgUnit() const
+{
+ if (!abbr.compare("px"))
+ return 1;
+ if (!abbr.compare("pt"))
+ return 2;
+ if (!abbr.compare("pc"))
+ return 3;
+ if (!abbr.compare("mm"))
+ return 4;
+ if (!abbr.compare("cm"))
+ return 5;
+ if (!abbr.compare("in"))
+ return 6;
+ if (!abbr.compare("ft"))
+ return 7;
+ if (!abbr.compare("em"))
+ return 8;
+ if (!abbr.compare("ex"))
+ return 9;
+ if (!abbr.compare("%"))
+ return 10;
+ return 0;
+}
+
UnitTable::UnitTable()
{
gchar *filename = g_build_filename(INKSCAPE_UIDIR, "units.xml", NULL);
@@ -125,21 +195,24 @@ UnitTable::UnitTable()
g_free(filename);
}
-UnitTable::~UnitTable() {
+UnitTable::~UnitTable()
+{
for (UnitMap::iterator iter = _unit_map.begin(); iter != _unit_map.end(); ++iter)
{
delete (*iter).second;
}
}
-void UnitTable::addUnit(Unit const &u, bool primary) {
+void UnitTable::addUnit(Unit const &u, bool primary)
+{
_unit_map[u.abbr] = new Unit(u);
if (primary) {
_primary_unit[u.type] = u.abbr;
}
}
-Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const {
+Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const
+{
UnitMap::const_iterator iter = _unit_map.find(unit_abbr);
if (iter != _unit_map.end()) {
return *((*iter).second);
@@ -148,7 +221,29 @@ Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const {
}
}
-bool UnitTable::deleteUnit(Unit const &u) {
+Quantity UnitTable::getQuantity(Glib::ustring const& q) const
+{
+ Glib::MatchInfo match_info;
+
+ // Extract value
+ double value = 0;
+ Glib::RefPtr<Glib::Regex> value_regex = Glib::Regex::create("[-+]*[\\d+]*\\.*[\\d+]*[eE]*[-+]*\\d+");
+ if (value_regex->match(q, match_info)) {
+ value = atof(match_info.fetch(0).c_str());
+ }
+
+ // Extract unit abbreviation
+ Glib::ustring abbr;
+ Glib::RefPtr<Glib::Regex> unit_regex = Glib::Regex::create("[A-z%]+");
+ if (unit_regex->match(q, match_info)) {
+ abbr = match_info.fetch(0);
+ }
+
+ return Quantity(value, abbr);
+}
+
+bool UnitTable::deleteUnit(Unit const &u)
+{
bool deleted = false;
// Cannot delete the primary unit type since it's
// used for conversions
@@ -208,6 +303,8 @@ bool UnitTable::save(std::string const &filename) {
return true;
}
+Inkscape::Util::UnitTable unit_table;
+
void UnitParser::on_start_element(Ctx &ctx, Glib::ustring const &name, AttrMap const &attrs)
{
if (name == "unit") {
@@ -256,10 +353,76 @@ void UnitParser::on_end_element(Ctx &ctx, Glib::ustring const &name)
}
}
+Quantity::Quantity(double q, const Unit &u)
+{
+ unit = new Unit(u);
+ quantity = q;
+}
+Quantity::Quantity(double q, const Glib::ustring u)
+{
+ unit = new Unit(unit_table.getUnit(u));
+ quantity = q;
+}
+
+bool Quantity::compatibleWith(const Unit &u) const
+{
+ return unit->compatibleWith(u);
+}
+bool Quantity::compatibleWith(const Glib::ustring u) const
+{
+ return compatibleWith(unit_table.getUnit(u));
+}
+
+double Quantity::value(const Unit &u) const
+{
+ return convert(quantity, *unit, u);
+}
+double Quantity::value(const Glib::ustring u) const
+{
+ return value(unit_table.getUnit(u));
+}
+
+Glib::ustring Quantity::string(const Unit &u) const {
+ return Glib::ustring::format(std::fixed, std::setprecision(2), value(u)) + " " + unit->abbr;
+}
+Glib::ustring Quantity::string(const Glib::ustring u) const {
+ return string(unit_table.getUnit(u));
+}
+Glib::ustring Quantity::string() const {
+ return string(*unit);
+}
+
+double Quantity::convert(const double from_dist, const Unit &from, const Unit &to)
+{
+ // Percentage
+ if (to.type == UNIT_TYPE_DIMENSIONLESS) {
+ return from_dist * to.factor;
+ }
+
+ // Incompatible units
+ if (from.type != to.type) {
+ return -1;
+ }
+
+ // Compatible units
+ return from_dist * from.factor / to.factor;
+}
+double Quantity::convert(const double from_dist, const Glib::ustring from, const Unit &to)
+{
+ return convert(from_dist, unit_table.getUnit(from), to);
+}
+double Quantity::convert(const double from_dist, const Unit &from, const Glib::ustring to)
+{
+ return convert(from_dist, from, unit_table.getUnit(to));
+}
+double Quantity::convert(const double from_dist, const Glib::ustring from, const Glib::ustring to)
+{
+ return convert(from_dist, unit_table.getUnit(from), unit_table.getUnit(to));
+}
+
} // namespace Util
} // namespace Inkscape
-
/*
Local Variables:
mode:c++
diff --git a/src/util/units.h b/src/util/units.h
index 4b2d782e3..bb202b96a 100644
--- a/src/util/units.h
+++ b/src/util/units.h
@@ -1,4 +1,15 @@
/*
+ * Inkscape Units
+ *
+ * Authors:
+ * Matthew Petroff <matthew@mpetroff.net>
+ *
+ * Copyright (C) 2013 Matthew Petroff
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+/*
This is a rough draft of a global 'units' thingee, to allow dialogs and
the ruler to share info about unit systems... Dunno if this is the
right kind of object though, so we may have to redo this or shift things
@@ -54,12 +65,53 @@ class Unit {
*/
int defaultDigits() const;
+ /** Checks if a unit is compatible with the specified unit. */
+ bool compatibleWith(const Unit &u) const;
+ bool compatibleWith(const Glib::ustring) const;
+
UnitType type;
double factor;
Glib::ustring name;
Glib::ustring name_plural;
Glib::ustring abbr;
Glib::ustring description;
+
+ /** Check if units are equal. */
+ friend bool operator== (const Unit &u1, const Unit &u2);
+ /** Check if units are not equal. */
+ friend bool operator!= (const Unit &u1, const Unit &u2);
+
+ /** Get SVG unit. */
+ int svgUnit() const;
+};
+
+class Quantity {
+public:
+ const Unit *unit;
+ double quantity;
+
+ /** Initialize a quantity. */
+ Quantity(double q, const Unit &u); // constructor
+ Quantity(double q, const Glib::ustring u); // constructor
+
+ /** Checks if a quantity is compatible with the specified unit. */
+ bool compatibleWith(const Unit &u) const;
+ bool compatibleWith(const Glib::ustring u) const;
+
+ /** Return the quantity's value in the specified unit. */
+ double value(const Unit &u) const;
+ double value(const Glib::ustring u) const;
+
+ /** Return a printable string of the value in the specified unit. */
+ Glib::ustring string(const Unit &u) const;
+ Glib::ustring string(const Glib::ustring u) const;
+ Glib::ustring string() const;
+
+ /** Convert distances. */
+ static double convert(const double from_dist, const Unit &from, const Unit &to);
+ static double convert(const double from_dist, const Glib::ustring from, const Unit &to);
+ static double convert(const double from_dist, const Unit &from, const Glib::ustring to);
+ static double convert(const double from_dist, const Glib::ustring from, const Glib::ustring to);
};
class UnitTable {
@@ -75,13 +127,16 @@ class UnitTable {
typedef std::map<Glib::ustring, Unit*> UnitMap;
/** Add a new unit to the table */
- void addUnit(Unit const& u, bool primary);
+ void addUnit(Unit const &u, bool primary);
/** Retrieve a given unit based on its string identifier */
- Unit getUnit(Glib::ustring const& name) const;
+ Unit getUnit(Glib::ustring const &name) const;
+
+ /** Retrieve a quantity based on its string identifier */
+ Quantity getQuantity(Glib::ustring const &q) const;
/** Remove a unit definition from the given unit type table */
- bool deleteUnit(Unit const& u);
+ bool deleteUnit(Unit const &u);
/** Returns true if the given string 'name' is a valid unit in the table */
bool hasUnit(Glib::ustring const &name) const;
@@ -115,11 +170,13 @@ class UnitTable {
double _linear_scale;
private:
- UnitTable(UnitTable const& t);
- UnitTable operator=(UnitTable const& t);
+ UnitTable(UnitTable const &t);
+ UnitTable operator=(UnitTable const &t);
};
+extern UnitTable unit_table;
+
} // namespace Util
} // namespace Inkscape
diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp
index 809050ad9..42f696bec 100644
--- a/src/widgets/arc-toolbar.cpp
+++ b/src/widgets/arc-toolbar.cpp
@@ -56,14 +56,10 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
#include "../sp-ellipse.h"
#include "../mod360.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -341,7 +337,7 @@ void sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObjec
_("Start"), _("Start:"),
_("The angle (in degrees) from the horizontal to the arc's start point"),
"/tools/shapes/arc/start", 0.0,
- GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-arc",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-arc",
-360.0, 360.0, 1.0, 10.0,
0, 0, 0,
sp_arctb_start_value_changed);
@@ -354,7 +350,7 @@ void sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObjec
_("End"), _("End:"),
_("The angle (in degrees) from the horizontal to the arc's end point"),
"/tools/shapes/arc/end", 0.0,
- GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
-360.0, 360.0, 1.0, 10.0,
0, 0, 0,
sp_arctb_end_value_changed);
diff --git a/src/widgets/box3d-toolbar.cpp b/src/widgets/box3d-toolbar.cpp
index e8b330375..91d4ebdec 100644
--- a/src/widgets/box3d-toolbar.cpp
+++ b/src/widgets/box3d-toolbar.cpp
@@ -58,16 +58,11 @@
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
-
#include "../pen-context.h"
#include "../box3d-context.h"
#include "../box3d.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -321,7 +316,7 @@ void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject
// Translators: PL is short for 'perspective line'
_("Angle of PLs in X direction"),
"/tools/shapes/3dbox/box3d_angle_x", 30,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-box3d",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-box3d",
-360.0, 360.0, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
box3d_angle_x_value_changed );
@@ -361,7 +356,7 @@ void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject
// Translators: PL is short for 'perspective line'
_("Angle of PLs in Y direction"),
"/tools/shapes/3dbox/box3d_angle_y", 30,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
-360.0, 360.0, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
box3d_angle_y_value_changed );
@@ -400,7 +395,7 @@ void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject
// Translators: PL is short for 'perspective line'
_("Angle of PLs in Z direction"),
"/tools/shapes/3dbox/box3d_angle_z", 30,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
-360.0, 360.0, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
box3d_angle_z_value_changed );
diff --git a/src/widgets/calligraphy-toolbar.cpp b/src/widgets/calligraphy-toolbar.cpp
index 4cb4813b5..1f91b9fe2 100644
--- a/src/widgets/calligraphy-toolbar.cpp
+++ b/src/widgets/calligraphy-toolbar.cpp
@@ -56,13 +56,9 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -451,7 +447,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
_("Pen Width"), _("Width:"),
_("The width of the calligraphic pen (relative to the visible canvas area)"),
"/tools/calligraphic/width", 15,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-calligraphy",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-calligraphy",
1, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_ddc_width_value_changed, 1, 0 );
@@ -468,7 +464,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
_("Stroke Thinning"), _("Thinning:"),
_("How much velocity thins the stroke (> 0 makes fast strokes thinner, < 0 makes them broader, 0 makes width independent of velocity)"),
"/tools/calligraphic/thinning", 10,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
-100, 100, 1, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_ddc_velthin_value_changed, 1, 0);
@@ -484,7 +480,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
_("Pen Angle"), _("Angle:"),
_("The angle of the pen's nib (in degrees; 0 = horizontal; has no effect if fixation = 0)"),
"/tools/calligraphic/angle", 30,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "calligraphy-angle",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "calligraphy-angle",
-90.0, 90.0, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_ddc_angle_value_changed, 1, 0 );
@@ -502,7 +498,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
_("Fixation"), _("Fixation:"),
_("Angle behavior (0 = nib always perpendicular to stroke direction, 100 = fixed angle)"),
"/tools/calligraphic/flatness", 90,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0.0, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_ddc_flatness_value_changed, 1, 0);
@@ -519,7 +515,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
_("Cap rounding"), _("Caps:"),
_("Increase to make caps at the ends of strokes protrude more (0 = no caps, 1 = round caps)"),
"/tools/calligraphic/cap_rounding", 0.0,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0.0, 5.0, 0.01, 0.1,
labels, values, G_N_ELEMENTS(labels),
sp_ddc_cap_rounding_value_changed, 0.01, 2 );
@@ -535,7 +531,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
_("Stroke Tremor"), _("Tremor:"),
_("Increase to make strokes rugged and trembling"),
"/tools/calligraphic/tremor", 0.0,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0.0, 100, 1, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_ddc_tremor_value_changed, 1, 0);
@@ -553,7 +549,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
_("Pen Wiggle"), _("Wiggle:"),
_("Increase to make the pen waver and wiggle"),
"/tools/calligraphic/wiggle", 0.0,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0.0, 100, 1, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_ddc_wiggle_value_changed, 1, 0);
@@ -570,7 +566,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
_("Pen Mass"), _("Mass:"),
_("Increase to make the pen drag behind, as if slowed by inertia"),
"/tools/calligraphic/mass", 2.0,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0.0, 100, 1, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_ddc_mass_value_changed, 1, 0);
diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp
index 7c72f8e0c..54344e446 100644
--- a/src/widgets/connector-toolbar.cpp
+++ b/src/widgets/connector-toolbar.cpp
@@ -55,9 +55,6 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
#include "../sp-namedview.h"
#include "../conn-avoid-ref.h"
@@ -66,7 +63,6 @@
#include "../sp-path.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -365,7 +361,7 @@ void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions,
_("Connector Curvature"), _("Curvature:"),
_("The amount of connectors curvature"),
"/tools/connector/curvature", defaultConnCurvature,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-curvature",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:connector-curvature",
0, 100, 1.0, 10.0,
0, 0, 0,
connector_curvature_changed, 1, 0 );
@@ -376,7 +372,7 @@ void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions,
_("Connector Spacing"), _("Spacing:"),
_("The amount of space left around objects by auto-routing connectors"),
"/tools/connector/spacing", defaultConnSpacing,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-spacing",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:connector-spacing",
0, 100, 1.0, 10.0,
0, 0, 0,
connector_spacing_changed, 1, 0 );
@@ -398,7 +394,7 @@ void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions,
_("Connector Length"), _("Length:"),
_("Ideal length for connectors when layout is applied"),
"/tools/connector/length", 100,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-length",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:connector-length",
10, 1000, 10.0, 100.0,
0, 0, 0,
connector_length_changed, 1, 0 );
diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp
index c1214c1a4..6493da84d 100644
--- a/src/widgets/desktop-widget.cpp
+++ b/src/widgets/desktop-widget.cpp
@@ -43,8 +43,8 @@
#include "file.h"
#include "helper/action.h"
#include "helper/action-context.h"
-#include "helper/units.h"
-#include "helper/unit-tracker.h"
+#include "util/units.h"
+#include "ui/widget/unit-tracker.h"
#include "inkscape-private.h"
#include "interface.h"
#include "macros.h"
@@ -79,10 +79,11 @@
using Inkscape::round;
#endif
-using Inkscape::UnitTracker;
+using Inkscape::UI::Widget::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::UI::ToolboxFactory;
using ege::AppearTimeTracker;
+using Inkscape::Util::unit_table;
enum {
ACTIVATE,
@@ -393,8 +394,9 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
GtkWidget *eventbox = gtk_event_box_new ();
dtw->hruler = sp_ruler_new(GTK_ORIENTATION_HORIZONTAL);
dtw->hruler_box = eventbox;
- sp_ruler_set_unit(SP_RULER(dtw->hruler), SP_PT);
- gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT))));
+ Inkscape::Util::Unit pt = unit_table.getUnit("pt");
+ sp_ruler_set_unit(SP_RULER(dtw->hruler), pt);
+ gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(pt.name_plural.c_str()));
gtk_container_add (GTK_CONTAINER (eventbox), dtw->hruler);
g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_hruler_event), dtw);
g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_hruler_event), dtw);
@@ -422,8 +424,8 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
eventbox = gtk_event_box_new ();
dtw->vruler = sp_ruler_new(GTK_ORIENTATION_VERTICAL);
dtw->vruler_box = eventbox;
- sp_ruler_set_unit (SP_RULER (dtw->vruler), SP_PT);
- gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT))));
+ sp_ruler_set_unit (SP_RULER (dtw->vruler), pt);
+ gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(pt.name_plural.c_str()));
gtk_container_add (GTK_CONTAINER (eventbox), GTK_WIDGET (dtw->vruler));
#if GTK_CHECK_VERSION(3,0,0)
@@ -1674,7 +1676,7 @@ SPDesktopWidget* SPDesktopWidget::createInstance(SPNamedView *namedview)
{
SPDesktopWidget *dtw = static_cast<SPDesktopWidget*>(g_object_new(SP_TYPE_DESKTOP_WIDGET, NULL));
- dtw->dt2r = 1.0 / namedview->doc_units->unittobase;
+ dtw->dt2r = 1. / namedview->doc_units->factor;
dtw->ruler_origin = Geom::Point(0,0); //namedview->gridorigin; Why was the grid origin used here?
@@ -1746,11 +1748,11 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags)
SPNamedView *nv=SP_NAMEDVIEW(obj);
if (flags & SP_OBJECT_MODIFIED_FLAG) {
- this->dt2r = 1.0 / nv->doc_units->unittobase;
+ this->dt2r = 1. / nv->doc_units->factor;
this->ruler_origin = Geom::Point(0,0); //nv->gridorigin; Why was the grid origin used here?
- sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDefaultMetric());
- sp_ruler_set_unit(SP_RULER (this->hruler), nv->getDefaultMetric());
+ sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDefaultUnit());
+ sp_ruler_set_unit(SP_RULER (this->hruler), nv->getDefaultUnit());
/* This loops through all the grandchildren of aux toolbox,
* and for each that it finds, it performs an sp_search_by_data_recursive(),
@@ -1786,8 +1788,8 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags)
} // children
} // if aux_toolbox is a container
- gtk_widget_set_tooltip_text(this->hruler_box, gettext(sp_unit_get_plural (nv->doc_units)));
- gtk_widget_set_tooltip_text(this->vruler_box, gettext(sp_unit_get_plural (nv->doc_units)));
+ gtk_widget_set_tooltip_text(this->hruler_box, gettext(nv->doc_units->name_plural.c_str()));
+ gtk_widget_set_tooltip_text(this->vruler_box, gettext(nv->doc_units->name_plural.c_str()));
sp_desktop_widget_update_rulers(this);
ToolboxFactory::updateSnapToolbox(this->desktop, 0, this->snap_toolbox);
diff --git a/src/widgets/dropper-toolbar.cpp b/src/widgets/dropper-toolbar.cpp
index cf58aa507..054955d8f 100644
--- a/src/widgets/dropper-toolbar.cpp
+++ b/src/widgets/dropper-toolbar.cpp
@@ -54,13 +54,9 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
#include "../tools-switch.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp
index aca960c00..3f5e60780 100644
--- a/src/widgets/eraser-toolbar.cpp
+++ b/src/widgets/eraser-toolbar.cpp
@@ -55,13 +55,9 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -149,7 +145,7 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
_("Pen Width"), _("Width:"),
_("The width of the eraser pen (relative to the visible canvas area)"),
"/tools/eraser/width", 15,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-eraser",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-eraser",
1, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_erc_width_value_changed, 1, 0);
diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp
index 7fa848f1e..5f9098d44 100644
--- a/src/widgets/font-selector.cpp
+++ b/src/widgets/font-selector.cpp
@@ -33,7 +33,6 @@
#include "desktop.h"
#include "widgets/font-selector.h"
#include "preferences.h"
-#include "unit-constants.h"
/* SPFontSelector */
diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp
index ea125a380..c1eb13ceb 100644
--- a/src/widgets/gradient-toolbar.cpp
+++ b/src/widgets/gradient-toolbar.cpp
@@ -1171,7 +1171,7 @@ void sp_gradient_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions,
eact = create_adjustment_action( "GradientEditOffsetAction",
_("Offset"), _("Offset:"), _("Offset of selected stop"),
"/tools/gradient/stopoffset", 0,
- GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0.0, 1.0, 0.01, 0.1,
0, 0, 0,
gr_stop_offset_adjustment_changed
diff --git a/src/widgets/lpe-toolbar.cpp b/src/widgets/lpe-toolbar.cpp
index c7659ab42..55cce90cd 100644
--- a/src/widgets/lpe-toolbar.cpp
+++ b/src/widgets/lpe-toolbar.cpp
@@ -57,9 +57,8 @@
#include "../ui/icon-names.h"
#include "../helper/action.h"
#include "../helper/action-context.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
+#include "util/units.h"
+#include "ui/widget/unit-tracker.h"
#include "../pen-context.h"
#include "../sp-namedview.h"
#include "../tools-switch.h"
@@ -67,7 +66,9 @@
#include "../live_effects/lpe-angle_bisector.h"
#include "../lpe-tool-context.h"
-using Inkscape::UnitTracker;
+using Inkscape::UI::Widget::UnitTracker;
+using Inkscape::Util::Unit;
+using Inkscape::Util::Quantity;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -197,9 +198,9 @@ static void lpetool_toggle_show_measuring_info(GtkToggleAction *act, GObject *tb
static void lpetool_unit_changed(GtkAction* /*act*/, GObject* tbl)
{
UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
- SPUnit const *unit = tracker->getActiveUnit();
+ Unit const unit = tracker->getActiveUnit();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->setInt("/tools/lpetool/unitid", unit->unit_id);
+ prefs->setString("/tools/lpetool/unit", unit.abbr);
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
if (SP_IS_LPETOOL_CONTEXT(desktop->event_context)) {
@@ -295,13 +296,13 @@ static void lpetool_open_lpe_dialog(GtkToggleAction *act, gpointer data)
void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
{
- UnitTracker* tracker = new UnitTracker(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
+ UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
tracker->setActiveUnit(sp_desktop_namedview(desktop)->doc_units);
g_object_set_data(holder, "tracker", tracker);
- SPUnit const *unit = tracker->getActiveUnit();
+ Unit const unit = tracker->getActiveUnit();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->setInt("/tools/lpetool/unitid", unit->unit_id);
+ prefs->setString("/tools/lpetool/unit", unit.abbr);
/** Automatically create a list of LPEs that get added to the toolbar **/
{
diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp
index 21df4c6d9..53ed2d275 100644
--- a/src/widgets/measure-toolbar.cpp
+++ b/src/widgets/measure-toolbar.cpp
@@ -52,13 +52,12 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
#include "../sp-namedview.h"
+#include "ui/widget/unit-tracker.h"
-using Inkscape::UnitTracker;
+using Inkscape::UI::Widget::UnitTracker;
+using Inkscape::Util::Unit;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -83,15 +82,17 @@ sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl)
static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl)
{
UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
- SPUnit const *unit = tracker->getActiveUnit();
+ Glib::ustring const unit = tracker->getActiveUnit().abbr;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->setInt("/tools/measure/unitid", unit->unit_id);
+ prefs->setString("/tools/measure/unit", unit);
}
void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder)
{
- UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
- tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
+ UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ tracker->setActiveUnitByAbbr(prefs->getString("/tools/measure/unit").c_str());
+
g_object_set_data( holder, "tracker", tracker );
EgeAdjustmentAction *eact = 0;
@@ -102,7 +103,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G
_("Font Size"), _("Font Size:"),
_("The font size to be used in the measurement labels"),
"/tools/measure/fontsize", 0.0,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
10, 36, 1.0, 4.0,
0, 0, 0,
sp_measure_fontsize_value_changed);
diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp
index 99a34fbda..37763ab34 100644
--- a/src/widgets/mesh-toolbar.cpp
+++ b/src/widgets/mesh-toolbar.cpp
@@ -262,7 +262,7 @@ void sp_mesh_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObj
eact = create_adjustment_action( "MeshRowAction",
_("Rows"), _("Rows:"), _("Number of rows in new mesh"),
"/tools/mesh/mesh_rows", 1,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
1, 20, 1, 1,
labels, values, G_N_ELEMENTS(labels),
ms_row_changed,
@@ -278,7 +278,7 @@ void sp_mesh_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObj
eact = create_adjustment_action( "MeshColumnAction",
_("Columns"), _("Columns:"), _("Number of columns in new mesh"),
"/tools/mesh/mesh_cols", 1,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
1, 20, 1, 1,
labels, values, G_N_ELEMENTS(labels),
ms_col_changed,
diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp
index 849de874d..a9e298f1d 100644
--- a/src/widgets/node-toolbar.cpp
+++ b/src/widgets/node-toolbar.cpp
@@ -58,17 +58,19 @@
#include "../ui/tool/node-tool.h"
#include "../ui/tool/multi-path-manipulator.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
+#include "util/units.h"
+#include "ui/widget/unit-tracker.h"
#include "../lpe-tool-context.h"
#include "../sp-namedview.h"
-using Inkscape::UnitTracker;
+using Inkscape::UI::Widget::UnitTracker;
+using Inkscape::Util::Unit;
+using Inkscape::Util::Quantity;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
using Inkscape::UI::PrefPusher;
+using Inkscape::Util::unit_table;
//####################################
//# node editing callbacks
@@ -238,7 +240,7 @@ static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tb
if (!tracker) {
return;
}
- SPUnit const *unit = tracker->getActiveUnit();
+ Unit const unit = tracker->getActiveUnit();
InkNodeTool *nt = get_node_tool();
if (!nt || nt->_selected_nodes->empty()) {
@@ -248,15 +250,15 @@ static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tb
} else {
gtk_action_set_sensitive(xact, TRUE);
gtk_action_set_sensitive(yact, TRUE);
- Geom::Coord oldx = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit);
- Geom::Coord oldy = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit);
+ Geom::Coord oldx = Quantity::convert(gtk_adjustment_get_value(xadj), unit, "px");
+ Geom::Coord oldy = Quantity::convert(gtk_adjustment_get_value(yadj), unit, "px");
Geom::Point mid = nt->_selected_nodes->pointwiseBounds()->midpoint();
if (oldx != mid[Geom::X]) {
- gtk_adjustment_set_value(xadj, sp_pixels_get_units(mid[Geom::X], *unit));
+ gtk_adjustment_set_value(xadj, Quantity::convert(mid[Geom::X], "px", unit));
}
if (oldy != mid[Geom::Y]) {
- gtk_adjustment_set_value(yadj, sp_pixels_get_units(mid[Geom::Y], *unit));
+ gtk_adjustment_set_value(yadj, Quantity::convert(mid[Geom::Y], "px", unit));
}
}
@@ -272,11 +274,11 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D
if (!tracker) {
return;
}
- SPUnit const *unit = tracker->getActiveUnit();
+ Unit const unit = tracker->getActiveUnit();
if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) {
prefs->setDouble(Glib::ustring("/tools/nodes/") + (d == Geom::X ? "x" : "y"),
- sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit));
+ Quantity::convert(gtk_adjustment_get_value(adj), unit, "px"));
}
// quit if run by the attr_changed listener
@@ -289,7 +291,7 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D
InkNodeTool *nt = get_node_tool();
if (nt && !nt->_selected_nodes->empty()) {
- double val = sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit);
+ double val = Quantity::convert(gtk_adjustment_get_value(adj), unit, "px");
double oldval = nt->_selected_nodes->pointwiseBounds()->midpoint()[d];
Geom::Point delta(0,0);
delta[d] = val - oldval;
@@ -339,8 +341,9 @@ static void sp_node_toolbox_sel_modified(Inkscape::Selection *selection, guint /
void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
{
- UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
- tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
+ UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
+ Unit doc_units = *sp_desktop_namedview(desktop)->doc_units;
+ tracker->setActiveUnit(&doc_units);
g_object_set_data( holder, "tracker", tracker );
Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
@@ -589,7 +592,7 @@ void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
eact = create_adjustment_action( "NodeXAction",
_("X coordinate:"), _("X:"), _("X coordinate of selected node(s)"),
"/tools/nodes/Xcoord", 0,
- GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-nodes",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-nodes",
-1e6, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
labels, values, G_N_ELEMENTS(labels),
sp_node_path_x_value_changed );
@@ -607,7 +610,7 @@ void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
eact = create_adjustment_action( "NodeYAction",
_("Y coordinate:"), _("Y:"), _("Y coordinate of selected node(s)"),
"/tools/nodes/Ycoord", 0,
- GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
-1e6, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
labels, values, G_N_ELEMENTS(labels),
sp_node_path_y_value_changed );
diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp
index 73815b86d..7c23379cd 100644
--- a/src/widgets/paintbucket-toolbar.cpp
+++ b/src/widgets/paintbucket-toolbar.cpp
@@ -54,9 +54,8 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
+#include "util/units.h"
+#include "ui/widget/unit-tracker.h"
#include "../pen-context.h"
#include "../sp-namedview.h"
#include "../flood-context.h"
@@ -64,11 +63,12 @@
#include <gtk/gtk.h>
-using Inkscape::UnitTracker;
+using Inkscape::UI::Widget::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
using Inkscape::UI::PrefPusher;
+using Inkscape::Util::unit_table;
@@ -97,13 +97,13 @@ static void paintbucket_autogap_changed(EgeSelectOneAction* act, GObject * /*tbl
static void paintbucket_offset_changed(GtkAdjustment *adj, GObject *tbl)
{
UnitTracker* tracker = static_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" ));
- SPUnit const *unit = tracker->getActiveUnit();
+ Unit const unit = tracker->getActiveUnit();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
// Don't adjust the offset value because we're saving the
// unit and it'll be correctly handled on load.
prefs->setDouble("/tools/paintbucket/offset", (gdouble)gtk_adjustment_get_value(adj));
- prefs->setString("/tools/paintbucket/offsetunits", sp_unit_get_abbreviation(unit));
+ prefs->setString("/tools/paintbucket/offsetunits", unit.abbr);
}
static void paintbucket_defaults(GtkWidget *, GObject *tbl)
@@ -165,7 +165,7 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
"ThresholdAction",
_("Fill Threshold"), _("Threshold:"),
_("The maximum allowed difference between the clicked pixel and the neighboring pixels to be counted in the fill"),
- "/tools/paintbucket/threshold", 5, GTK_WIDGET(desktop->canvas), NULL, holder, TRUE,
+ "/tools/paintbucket/threshold", 5, GTK_WIDGET(desktop->canvas), holder, TRUE,
"inkscape:paintbucket-threshold", 0, 100.0, 1.0, 10.0,
0, 0, 0,
paintbucket_threshold_changed, 1, 0 );
@@ -175,10 +175,11 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
}
// Create the units menu.
- UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
+ UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
Glib::ustring stored_unit = prefs->getString("/tools/paintbucket/offsetunits");
if (!stored_unit.empty()) {
- tracker->setActiveUnit(sp_unit_get_by_abbreviation(stored_unit.data()));
+ Unit u = unit_table.getUnit(stored_unit);
+ tracker->setActiveUnit(&u);
}
g_object_set_data( holder, "tracker", tracker );
{
@@ -192,7 +193,7 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions
"OffsetAction",
_("Grow/shrink by"), _("Grow/shrink by:"),
_("The amount to grow (positive) or shrink (negative) the created fill path"),
- "/tools/paintbucket/offset", 0, GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE,
+ "/tools/paintbucket/offset", 0, GTK_WIDGET(desktop->canvas), holder, TRUE,
"inkscape:paintbucket-offset", -1e4, 1e4, 0.1, 0.5,
0, 0, 0,
paintbucket_offset_changed, 1, 2);
diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp
index e0cf67bd0..851ad7134 100644
--- a/src/widgets/pencil-toolbar.cpp
+++ b/src/widgets/pencil-toolbar.cpp
@@ -67,15 +67,10 @@
//#include "../ui/tool/multi-path-manipulator.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
-
#include "../pen-context.h"
//#include "../sp-namedview.h"
#include "../tools-switch.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -307,7 +302,7 @@ void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
_("How much smoothing (simplifying) is applied to the line"),
"/tools/freehand/pencil/tolerance",
3.0,
- GTK_WIDGET(desktop->canvas), NULL,
+ GTK_WIDGET(desktop->canvas),
holder, TRUE, "altx-pencil",
1, 100.0, 0.5, 1.0,
labels, values, G_N_ELEMENTS(labels),
diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp
index 8c1a735c5..6dfd9cfcb 100644
--- a/src/widgets/rect-toolbar.cpp
+++ b/src/widgets/rect-toolbar.cpp
@@ -53,18 +53,20 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
+#include "util/units.h"
+#include "ui/widget/unit-tracker.h"
#include "../pen-context.h"
#include "../sp-namedview.h"
#include "../sp-rect.h"
-using Inkscape::UnitTracker;
+using Inkscape::UI::Widget::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
using Inkscape::UI::PrefPusher;
+using Inkscape::Util::Unit;
+using Inkscape::Util::Quantity;
+using Inkscape::Util::unit_table;
//########################
@@ -91,12 +93,12 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" ));
- SPUnit const *unit = tracker->getActiveUnit();
+ Unit const unit = tracker->getActiveUnit();
if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setDouble(Glib::ustring("/tools/shapes/rect/") + value_name,
- sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit));
+ Quantity::convert(gtk_adjustment_get_value(adj), unit, "px"));
}
// quit if run by the attr_changed listener
@@ -113,7 +115,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *
if (SP_IS_RECT(items->data)) {
if (gtk_adjustment_get_value(adj) != 0) {
setter(SP_RECT(items->data),
- sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit));
+ Quantity::convert(gtk_adjustment_get_value(adj), unit, "px"));
} else {
SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL);
}
@@ -184,32 +186,32 @@ static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar con
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
UnitTracker* tracker = reinterpret_cast<UnitTracker*>( g_object_get_data( tbl, "tracker" ) );
- SPUnit const *unit = tracker->getActiveUnit();
+ Unit const unit = tracker->getActiveUnit();
gpointer item = g_object_get_data( tbl, "item" );
if (item && SP_IS_RECT(item)) {
{
GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "rx" ) );
gdouble rx = sp_rect_get_visible_rx(SP_RECT(item));
- gtk_adjustment_set_value(adj, sp_pixels_get_units(rx, *unit));
+ gtk_adjustment_set_value(adj, Quantity::convert(rx, "px", unit));
}
{
GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "ry" ) );
gdouble ry = sp_rect_get_visible_ry(SP_RECT(item));
- gtk_adjustment_set_value(adj, sp_pixels_get_units(ry, *unit));
+ gtk_adjustment_set_value(adj, Quantity::convert(ry, "px", unit));
}
{
GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "width" ) );
gdouble width = sp_rect_get_visible_width (SP_RECT(item));
- gtk_adjustment_set_value(adj, sp_pixels_get_units(width, *unit));
+ gtk_adjustment_set_value(adj, Quantity::convert(width, "px", unit));
}
{
GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "height" ) );
gdouble height = sp_rect_get_visible_height (SP_RECT(item));
- gtk_adjustment_set_value(adj, sp_pixels_get_units(height, *unit));
+ gtk_adjustment_set_value(adj, Quantity::convert(height, "px", unit));
}
}
@@ -301,7 +303,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
}
// rx/ry units menu: create
- UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
+ UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
//tracker->addUnit( SP_UNIT_PERCENT, 0 );
// fixme: add % meaning per cent of the width/height
tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
@@ -314,7 +316,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
eact = create_adjustment_action( "RectWidthAction",
_("Width"), _("W:"), _("Width of rectangle"),
"/tools/shapes/rect/width", 0,
- GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-rect",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-rect",
0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
labels, values, G_N_ELEMENTS(labels),
sp_rtb_width_value_changed );
@@ -331,7 +333,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
eact = create_adjustment_action( "RectHeightAction",
_("Height"), _("H:"), _("Height of rectangle"),
"/tools/shapes/rect/height", 0,
- GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
labels, values, G_N_ELEMENTS(labels),
sp_rtb_height_value_changed );
@@ -348,7 +350,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
eact = create_adjustment_action( "RadiusXAction",
_("Horizontal radius"), _("Rx:"), _("Horizontal radius of rounded corners"),
"/tools/shapes/rect/rx", 0,
- GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
labels, values, G_N_ELEMENTS(labels),
sp_rtb_rx_value_changed);
@@ -363,7 +365,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
eact = create_adjustment_action( "RadiusYAction",
_("Vertical radius"), _("Ry:"), _("Vertical radius of rounded corners"),
"/tools/shapes/rect/ry", 0,
- GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
labels, values, G_N_ELEMENTS(labels),
sp_rtb_ry_value_changed);
diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp
index c1f9be2a5..e4e72d86e 100644
--- a/src/widgets/ruler.cpp
+++ b/src/widgets/ruler.cpp
@@ -33,9 +33,9 @@
#include "widget-sizes.h"
#include "ruler.h"
-#include "unit-constants.h"
#include "round.h"
#include <glibmm/i18n.h>
+#include "util/units.h"
#define ROUND(x) ((int) ((x) + 0.5))
@@ -44,6 +44,7 @@
#define DEFAULT_RULER_FONT_SCALE PANGO_SCALE_X_SMALL
#define MINIMUM_INCR 5
+using Inkscape::Util::unit_table;
enum {
PROP_0,
@@ -62,7 +63,7 @@ enum {
typedef struct
{
GtkOrientation orientation;
- SPMetric unit;
+ Inkscape::Util::Unit *unit;
gdouble lower;
gdouble upper;
gdouble position;
@@ -196,11 +197,10 @@ sp_ruler_class_init (SPRulerClass *klass)
/* FIXME: Should probably use g_param_spec_enum */
g_object_class_install_property (object_class,
PROP_UNIT,
- g_param_spec_uint ("unit",
+ g_param_spec_string ("unit",
_("Unit"),
_("Unit of the ruler"),
- 0, 8,
- SP_PX,
+ "px",
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
g_object_class_install_property (object_class,
@@ -260,7 +260,7 @@ sp_ruler_init (SPRuler *ruler)
gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE);
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
- priv->unit = SP_PX;
+ priv->unit = new Inkscape::Util::Unit(unit_table.getUnit("px"));
priv->lower = 0;
priv->upper = 0;
priv->position = 0;
@@ -387,7 +387,7 @@ sp_ruler_set_property (GObject *object,
break;
case PROP_UNIT:
- sp_ruler_set_unit (ruler, static_cast<SPMetric>(g_value_get_int (value)));
+ sp_ruler_set_unit (ruler, unit_table.getUnit(g_value_get_string (value)));
break;
case PROP_LOWER:
@@ -436,7 +436,7 @@ sp_ruler_get_property (GObject *object,
break;
case PROP_UNIT:
- g_value_set_int (value, priv->unit);
+ g_value_set_string (value, priv->unit->abbr.c_str());
break;
case PROP_LOWER:
g_value_set_double (value, priv->lower);
@@ -1071,15 +1071,15 @@ sp_ruler_remove_track_widget (SPRuler *ruler,
*/
void
sp_ruler_set_unit (SPRuler *ruler,
- SPMetric unit)
+ const Inkscape::Util::Unit &unit)
{
SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler);
g_return_if_fail (SP_IS_RULER (ruler));
- if (priv->unit != unit)
+ if (*priv->unit != unit)
{
- priv->unit = unit;
+ priv->unit = new Inkscape::Util::Unit(unit);
g_object_notify(G_OBJECT(ruler), "unit");
gtk_widget_queue_draw (GTK_WIDGET (ruler));
@@ -1092,11 +1092,9 @@ sp_ruler_set_unit (SPRuler *ruler,
*
* Return value: the unit currently used in the @ruler widget.
**/
-SPMetric
+Inkscape::Util::Unit*
sp_ruler_get_unit (SPRuler *ruler)
{
- g_return_val_if_fail(SP_IS_RULER(ruler), static_cast<SPMetric>(0));
-
return SP_RULER_GET_PRIVATE (ruler)->unit;
}
@@ -1184,7 +1182,7 @@ sp_ruler_draw_ticks (SPRuler *ruler)
gint text_size;
gint pos;
gdouble max_size;
- SPMetric unit;
+ Inkscape::Util::Unit *unit;
SPRulerMetric ruler_metric = ruler_metric_general; /* The metric to use for this unit system */
PangoLayout *layout;
PangoRectangle logical_rect, ink_rect;
@@ -1300,7 +1298,7 @@ sp_ruler_draw_ticks (SPRuler *ruler)
/* Inkscape change to ruler: Use a 1,2,4,8... scale for inches
* or a 1,2,5,10... scale for everything else */
- if (sp_ruler_get_unit (ruler) == SP_IN)
+ if (*sp_ruler_get_unit (ruler) == unit_table.getUnit("in"))
ruler_metric = ruler_metric_inches;
for (scale = 0; scale < G_N_ELEMENTS (ruler_metric.ruler_scale); scale++)
@@ -1319,7 +1317,7 @@ sp_ruler_draw_ticks (SPRuler *ruler)
gdouble subd_incr;
/* hack to get proper subdivisions at full pixels */
- if (unit == SP_PX && scale == 1 && i == 1)
+ if (*unit == unit_table.getUnit("px") && scale == 1 && i == 1)
subd_incr = 1.0;
else
subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] /
diff --git a/src/widgets/ruler.h b/src/widgets/ruler.h
index f0d866fff..08760f584 100644
--- a/src/widgets/ruler.h
+++ b/src/widgets/ruler.h
@@ -14,10 +14,15 @@
*/
#include <gtk/gtk.h>
-#include "sp-metric.h"
#include <iostream>
#include <glib.h>
+namespace Inkscape {
+ namespace Util {
+ class Unit;
+ }
+}
+
G_BEGIN_DECLS
#define SP_TYPE_RULER (sp_ruler_get_type ())
@@ -51,8 +56,8 @@ void sp_ruler_remove_track_widget (SPRuler *ruler,
GtkWidget *widget);
void sp_ruler_set_unit (SPRuler *ruler,
- SPMetric unit);
-SPMetric sp_ruler_get_unit (SPRuler *ruler);
+ const Inkscape::Util::Unit &unit);
+Inkscape::Util::Unit *sp_ruler_get_unit (SPRuler *ruler);
void sp_ruler_set_position (SPRuler *ruler,
gdouble set_position);
gdouble sp_ruler_get_position (SPRuler *ruler);
diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp
index 1bfc841e3..e4a5a2905 100644
--- a/src/widgets/select-toolbar.cpp
+++ b/src/widgets/select-toolbar.cpp
@@ -39,8 +39,7 @@
#include <glibmm/i18n.h>
#include "helper/action.h"
#include "helper/action-context.h"
-#include "helper/unit-menu.h"
-#include "helper/units.h"
+#include "util/units.h"
#include "inkscape.h"
#include "verbs.h"
#include "selection.h"
@@ -48,7 +47,7 @@
#include "sp-item-transform.h"
#include "message-stack.h"
#include "display/sp-canvas.h"
-#include "helper/unit-tracker.h"
+#include "ui/widget/unit-tracker.h"
#include "ege-adjustment-action.h"
#include "ege-output-action.h"
#include "ink-action.h"
@@ -56,8 +55,11 @@
#include "ui/icon-names.h"
#include "select-toolbar.h"
-using Inkscape::UnitTracker;
+using Inkscape::UI::Widget::UnitTracker;
+using Inkscape::Util::Unit;
+using Inkscape::Util::Quantity;
using Inkscape::DocumentUndo;
+using Inkscape::Util::unit_table;
static void
sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel)
@@ -78,7 +80,7 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel)
Geom::OptRect const bbox(sel->bounds(bbox_type));
if ( bbox ) {
UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker"));
- SPUnit const &unit = *tracker->getActiveUnit();
+ Unit const unit = tracker->getActiveUnit();
struct { char const *key; double val; } const keyval[] = {
{ "X", bbox->min()[X] },
@@ -87,8 +89,8 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel)
{ "height", bbox->dimensions()[Y] }
};
- if (unit.base == SP_UNIT_DIMENSIONLESS) {
- double const val = 1. / unit.unittobase;
+ if (unit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) {
+ double const val = unit.factor * 100;
for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) {
GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key));
gtk_adjustment_set_value(a, val);
@@ -97,7 +99,7 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel)
} else {
for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) {
GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key));
- gtk_adjustment_set_value(a, sp_pixels_get_units(keyval[i].val, unit));
+ gtk_adjustment_set_value(a, Quantity::convert(keyval[i].val, "px", unit));
}
}
}
@@ -183,28 +185,28 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
gdouble y1 = 0;
gdouble xrel = 0;
gdouble yrel = 0;
- SPUnit const &unit = *tracker->getActiveUnit();
+ Unit const unit = tracker->getActiveUnit();
GtkAdjustment* a_x = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "X" ) );
GtkAdjustment* a_y = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "Y" ) );
GtkAdjustment* a_w = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "width" ) );
GtkAdjustment* a_h = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "height" ) );
- if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
- x0 = sp_units_get_pixels (gtk_adjustment_get_value (a_x), unit);
- y0 = sp_units_get_pixels (gtk_adjustment_get_value (a_y), unit);
- x1 = x0 + sp_units_get_pixels (gtk_adjustment_get_value (a_w), unit);
- xrel = sp_units_get_pixels (gtk_adjustment_get_value (a_w), unit) / bbox_user->dimensions()[Geom::X];
- y1 = y0 + sp_units_get_pixels (gtk_adjustment_get_value (a_h), unit);
- yrel = sp_units_get_pixels (gtk_adjustment_get_value (a_h), unit) / bbox_user->dimensions()[Geom::Y];
+ if (unit.type == Inkscape::Util::UNIT_TYPE_LINEAR) {
+ x0 = Quantity::convert(gtk_adjustment_get_value(a_x), unit, "px");
+ y0 = Quantity::convert(gtk_adjustment_get_value(a_y), unit, "px");
+ x1 = x0 + Quantity::convert(gtk_adjustment_get_value(a_w), unit, "px");
+ xrel = Quantity::convert(gtk_adjustment_get_value(a_w), unit, "px") / bbox_user->dimensions()[Geom::X];
+ y1 = y0 + Quantity::convert(gtk_adjustment_get_value(a_h), unit, "px");;
+ yrel = Quantity::convert(gtk_adjustment_get_value(a_h), unit, "px") / bbox_user->dimensions()[Geom::Y];
} else {
- double const x0_propn = gtk_adjustment_get_value (a_x) * unit.unittobase;
+ double const x0_propn = gtk_adjustment_get_value (a_x) / 100 / unit.factor;
x0 = bbox_user->min()[Geom::X] * x0_propn;
- double const y0_propn = gtk_adjustment_get_value (a_y) * unit.unittobase;
+ double const y0_propn = gtk_adjustment_get_value (a_y) / 100 / unit.factor;
y0 = y0_propn * bbox_user->min()[Geom::Y];
- xrel = gtk_adjustment_get_value (a_w) * unit.unittobase;
+ xrel = gtk_adjustment_get_value (a_w) / (100 / unit.factor);
x1 = x0 + xrel * bbox_user->dimensions()[Geom::X];
- yrel = gtk_adjustment_get_value (a_h) * unit.unittobase;
+ yrel = gtk_adjustment_get_value (a_h) / (100 / unit.factor);
y1 = y0 + yrel * bbox_user->dimensions()[Geom::Y];
}
@@ -225,11 +227,11 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
double sv = fabs(y1 - bbox_user->max()[Geom::Y]);
// unless the unit is %, convert the scales and moves to the unit
- if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) {
- mh = sp_pixels_get_units (mh, unit);
- sh = sp_pixels_get_units (sh, unit);
- mv = sp_pixels_get_units (mv, unit);
- sv = sp_pixels_get_units (sv, unit);
+ if (unit.type == Inkscape::Util::UNIT_TYPE_LINEAR) {
+ mh = Quantity::convert(mh, "px", unit);
+ sh = Quantity::convert(sh, "px", unit);
+ mv = Quantity::convert(mv, "px", unit);
+ sv = Quantity::convert(sv, "px", unit);
}
// do the action only if one of the scales/moves is greater than half the last significant
@@ -488,8 +490,8 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
gtk_container_add(GTK_CONTAINER(spw), vb);
// Create the units menu.
- UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
- tracker->addUnit( SP_UNIT_PERCENT, 0 );
+ UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
+ tracker->addUnit(unit_table.getUnit("%"));
tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
g_object_set_data( G_OBJECT(spw), "tracker", tracker );
diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp
index 08d26f3d1..cccaf5154 100644
--- a/src/widgets/spiral-toolbar.cpp
+++ b/src/widgets/spiral-toolbar.cpp
@@ -53,13 +53,9 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
#include "../sp-spiral.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -263,7 +259,7 @@ void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
eact = create_adjustment_action( "SpiralRevolutionAction",
_("Number of turns"), _("Turns:"), _("Number of revolutions"),
"/tools/shapes/spiral/revolution", 3.0,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-spiral",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-spiral",
0.01, 1024.0, 0.1, 1.0,
labels, values, G_N_ELEMENTS(labels),
sp_spl_tb_revolution_value_changed, 1, 2);
@@ -277,7 +273,7 @@ void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
eact = create_adjustment_action( "SpiralExpansionAction",
_("Divergence"), _("Divergence:"), _("How much denser/sparser are outer revolutions; 1 = uniform"),
"/tools/shapes/spiral/expansion", 1.0,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0.0, 1000.0, 0.01, 1.0,
labels, values, G_N_ELEMENTS(labels),
sp_spl_tb_expansion_value_changed);
@@ -291,7 +287,7 @@ void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
eact = create_adjustment_action( "SpiralT0Action",
_("Inner radius"), _("Inner radius:"), _("Radius of the innermost revolution (relative to the spiral size)"),
"/tools/shapes/spiral/t0", 0.0,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0.0, 0.999, 0.01, 1.0,
labels, values, G_N_ELEMENTS(labels),
sp_spl_tb_t0_value_changed);
diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp
index 06850d261..fe221f695 100644
--- a/src/widgets/spray-toolbar.cpp
+++ b/src/widgets/spray-toolbar.cpp
@@ -52,13 +52,9 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
#include "../spray-context.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -131,7 +127,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj
EgeAdjustmentAction *eact = create_adjustment_action( "SprayWidthAction",
_("Width"), _("Width:"), _("The width of the spray area (relative to the visible canvas area)"),
"/tools/spray/width", 15,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-spray",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-spray",
1, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_spray_width_value_changed, 1, 0 );
@@ -147,7 +143,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj
EgeAdjustmentAction *eact = create_adjustment_action( "SprayMeanAction",
_("Focus"), _("Focus:"), _("0 to spray a spot; increase to enlarge the ring radius"),
"/tools/spray/mean", 0,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-mean",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-mean",
0, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_spray_mean_value_changed, 1, 0 );
@@ -163,7 +159,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj
EgeAdjustmentAction *eact = create_adjustment_action( "SprayStandard_deviationAction",
C_("Spray tool", "Scatter"), C_("Spray tool", "Scatter:"), _("Increase to scatter sprayed objects"),
"/tools/spray/standard_deviation", 70,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-standard_deviation",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-standard_deviation",
1, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_spray_standard_deviation_value_changed, 1, 0 );
@@ -224,7 +220,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj
_("Amount"), _("Amount:"),
_("Adjusts the number of items sprayed per click"),
"/tools/spray/population", 70,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-population",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-population",
1, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_spray_population_value_changed, 1, 0 );
@@ -255,7 +251,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj
// xgettext:no-c-format
_("Variation of the rotation of the sprayed objects; 0% for the same rotation than the original object"),
"/tools/spray/rotation_variation", 0,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-rotation",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-rotation",
0, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_spray_rotation_value_changed, 1, 0 );
@@ -273,7 +269,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj
// xgettext:no-c-format
_("Variation in the scale of the sprayed objects; 0% for the same scale than the original object"),
"/tools/spray/scale_variation", 0,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-scale",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-scale",
0, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_spray_scale_value_changed, 1, 0 );
diff --git a/src/widgets/spw-utilities.cpp b/src/widgets/spw-utilities.cpp
index 87ca80f2f..d0a3ed1c5 100644
--- a/src/widgets/spw-utilities.cpp
+++ b/src/widgets/spw-utilities.cpp
@@ -32,7 +32,6 @@
#include "selection.h"
-#include "helper/unit-menu.h"
#include "spw-utilities.h"
#include <gtk/gtk.h>
@@ -231,51 +230,6 @@ spw_dropdown(GtkWidget * dialog, GtkWidget * table,
return selector;
}
-/**
- * Creates a unit selector widget, used for selecting whether one wishes
- * to measure screen elements in millimeters, points, etc. This is a
- * compound unit that includes a label as well as the dropdown selector.
- */
-GtkWidget *
-spw_unit_selector(GtkWidget * dialog, GtkWidget * table,
- const gchar * label_text, gchar * key, int row,
- GtkWidget * us, GCallback cb, bool can_be_negative)
-{
- g_assert(dialog != NULL);
- g_assert(table != NULL);
- g_assert(us != NULL);
-
- spw_label_old(table, label_text, 0, row);
-
-#if GTK_CHECK_VERSION(3,0,0)
- GtkAdjustment * a = gtk_adjustment_new(0.0, can_be_negative?-1e6:0, 1e6, 1.0, 10.0, 10.0);
-#else
- GtkObject * a = gtk_adjustment_new(0.0, can_be_negative?-1e6:0, 1e6, 1.0, 10.0, 10.0);
-#endif
-
- g_assert(a != NULL);
- g_object_set_data (G_OBJECT (a), "key", key);
- g_object_set_data (G_OBJECT (a), "unit_selector", us);
- g_object_set_data (G_OBJECT (dialog), key, a);
- sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (us), GTK_ADJUSTMENT (a));
- GtkWidget * sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 4);
- g_assert(sb != NULL);
- gtk_widget_show (sb);
-
-#if GTK_CHECK_VERSION(3,0,0)
- gtk_widget_set_halign(sb, GTK_ALIGN_FILL);
- gtk_widget_set_hexpand(sb, TRUE);
- gtk_widget_set_valign(sb, GTK_ALIGN_CENTER);
- gtk_grid_attach(GTK_GRID(table), sb, 1, row, 1, 1);
-#else
- gtk_table_attach (GTK_TABLE (table), sb, 1, 2, row, row+1,
- (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 0, 0);
-#endif
-
- g_signal_connect (G_OBJECT (a), "value_changed", cb, dialog);
- return sb;
-}
-
static void
sp_set_font_size_recursive (GtkWidget *w, gpointer font)
{
diff --git a/src/widgets/spw-utilities.h b/src/widgets/spw-utilities.h
index fb8c04ebf..d52cbd888 100644
--- a/src/widgets/spw-utilities.h
+++ b/src/widgets/spw-utilities.h
@@ -56,11 +56,6 @@ spw_dropdown(GtkWidget *dialog, GtkWidget *table,
GtkWidget *selector
);
-GtkWidget *
-spw_unit_selector(GtkWidget *dialog, GtkWidget *table,
- gchar const *label, gchar *key, int row,
- GtkWidget *us, GCallback cb, bool can_be_negative = false);
-
void sp_set_font_size (GtkWidget *w, guint font);
void sp_set_font_size_smaller (GtkWidget *w);
diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp
index 8c07c6473..9f7dd95e0 100644
--- a/src/widgets/star-toolbar.cpp
+++ b/src/widgets/star-toolbar.cpp
@@ -53,14 +53,10 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
#include "../sp-star.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -505,7 +501,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
eact = create_adjustment_action( "MagnitudeAction",
_("Corners"), _("Corners:"), _("Number of corners of a polygon or star"),
"/tools/shapes/star/magnitude", 3,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
3, 1024, 1, 5,
labels, values, G_N_ELEMENTS(labels),
sp_stb_magnitude_value_changed,
@@ -524,7 +520,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
// Base radius is the same for the closest handle.
_("Base radius to tip radius ratio"),
"/tools/shapes/star/proportion", 0.5,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
0.01, 1.0, 0.01, 0.1,
labels, values, G_N_ELEMENTS(labels),
sp_stb_proportion_value_changed );
@@ -545,7 +541,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
eact = create_adjustment_action( "RoundednessAction",
_("Rounded"), _("Rounded:"), _("How much rounded are the corners (0 for sharp)"),
"/tools/shapes/star/rounded", 0.0,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
-10.0, 10.0, 0.01, 0.1,
labels, values, G_N_ELEMENTS(labels),
sp_stb_rounded_value_changed );
@@ -560,7 +556,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
eact = create_adjustment_action( "RandomizationAction",
_("Randomized"), _("Randomized:"), _("Scatter randomly the corners and angles"),
"/tools/shapes/star/randomized", 0.0,
- GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL,
+ GTK_WIDGET(desktop->canvas), holder, FALSE, NULL,
-10.0, 10.0, 0.001, 0.01,
labels, values, G_N_ELEMENTS(labels),
sp_stb_randomized_value_changed, 0.1, 3 );
diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp
index 0a5b3781b..12d4002b8 100644
--- a/src/widgets/stroke-style.cpp
+++ b/src/widgets/stroke-style.cpp
@@ -22,8 +22,11 @@
#include "sp-gradient.h"
#include "sp-stop.h"
#include "svg/svg-color.h"
+#include "util/units.h"
+#include "ui/widget/unit-menu.h"
using Inkscape::DocumentUndo;
+using Inkscape::Util::unit_table;
/**
* Creates a new widget for the line stroke paint.
@@ -189,22 +192,22 @@ StrokeStyle::StrokeStyle() :
sp_dialog_defocus_on_enter_cpp(widthSpin);
hb->pack_start(*widthSpin, false, false, 0);
- unitSelector = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
- Gtk::Widget *us = manage(Glib::wrap(unitSelector));
+ unitSelector = new Inkscape::UI::Widget::UnitMenu();
+ unitSelector->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR);
+ Gtk::Widget *us = manage(unitSelector);
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- if (desktop)
- sp_unit_selector_set_unit (SP_UNIT_SELECTOR(unitSelector), sp_desktop_namedview(desktop)->doc_units);
- sp_unit_selector_add_unit(SP_UNIT_SELECTOR(unitSelector), &sp_unit_get_by_id(SP_UNIT_PERCENT), 0);
- g_signal_connect ( G_OBJECT (unitSelector), "set_unit", G_CALLBACK (StrokeStyle::setStrokeWidthUnit), this );
+ unitSelector->addUnit(unit_table.getUnit("%"));
+ if (desktop) {
+ unitSelector->setUnit(sp_desktop_namedview(desktop)->doc_units->abbr);
+ _old_unit = new Inkscape::Util::Unit(*sp_desktop_namedview(desktop)->doc_units);
+ }
+ _old_unit = new Inkscape::Util::Unit(unitSelector->getUnit());
+ widthSpin->setUnitMenu(unitSelector);
+ unitChangedConn = unitSelector->signal_changed().connect(sigc::mem_fun(*this, &StrokeStyle::unitChangedCB));
+
us->show();
-#if WITH_GTKMM_3_0
- sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(unitSelector), GTK_ADJUSTMENT((*widthAdj)->gobj()) );
-#else
- sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(unitSelector), GTK_ADJUSTMENT(widthAdj->gobj()) );
-#endif
-
hb->pack_start(*us, FALSE, FALSE, 0);
#if WITH_GTKMM_3_0
@@ -519,75 +522,17 @@ void StrokeStyle::updateMarkerHist(SPMarkerLoc const which)
}
/**
- * Sets the stroke width units for all selected items.
- * Also handles absolute and dimensionless units.
+ * Callback for when UnitMenu widget is modified.
+ * Triggers update action.
*/
-gboolean StrokeStyle::setStrokeWidthUnit(SPUnitSelector *,
- SPUnit const *old,
- SPUnit const *new_units,
- StrokeStyle *spw)
+void StrokeStyle::unitChangedCB()
{
- if (spw->update) {
- return FALSE;
- }
-
- if (!spw->desktop) {
- return FALSE;
+ Inkscape::Util::Unit new_unit = unitSelector->getUnit();
+ if (new_unit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) {
+ widthSpin->set_value(100);
}
-
- Inkscape::Selection *selection = sp_desktop_selection (spw->desktop);
-
- if (selection->isEmpty())
- return FALSE;
-
- GSList const *objects = selection->itemList();
-
- if ((old->base == SP_UNIT_ABSOLUTE || old->base == SP_UNIT_DEVICE) &&
- (new_units->base == SP_UNIT_DIMENSIONLESS)) {
-
- /* Absolute to percentage */
- spw->update = true;
-
-#if WITH_GTKMM_3_0
- float w = sp_units_get_pixels( (*spw->widthAdj)->get_value(), *old);
-#else
- float w = sp_units_get_pixels(spw->widthAdj->get_value(), *old);
-#endif
-
- gdouble average = stroke_average_width (objects);
-
- if ((average == Geom::infinity()) || (average < 1e-8)){ //less than 1e-8: to campare against zero, while taking numeric accuracy into account
- return FALSE;
- }
-
-#if WITH_GTKMM_3_0
- (*spw->widthAdj)->set_value(100.0 * w / average);
-#else
- spw->widthAdj->set_value(100.0 * w / average);
-#endif
-
- spw->update = false;
- return TRUE;
-
- } else if ((old->base == SP_UNIT_DIMENSIONLESS) &&
- (new_units->base == SP_UNIT_ABSOLUTE || new_units->base == SP_UNIT_DEVICE)) {
-
- /* Percentage to absolute */
- spw->update = true;
-
- gdouble average = stroke_average_width (objects);
-
-#if WITH_GTKMM_3_0
- (*spw->widthAdj)->set_value (sp_pixels_get_units (0.01 * (*spw->widthAdj)->get_value() * average, *new_units));
-#else
- spw->widthAdj->set_value (sp_pixels_get_units (0.01 * spw->widthAdj->get_value() * average, *new_units));
-#endif
-
- spw->update = false;
- return TRUE;
- }
-
- return FALSE;
+ widthSpin->set_value(Inkscape::Util::Quantity::convert(widthSpin->get_value(), *_old_unit, new_unit));
+ _old_unit = new Inkscape::Util::Unit(new_unit);
}
/**
@@ -877,21 +822,21 @@ StrokeStyle::updateLine()
} else {
table->set_sensitive(true);
- SPUnit const *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unitSelector));
+ Inkscape::Util::Unit const *unit = new Inkscape::Util::Unit(unitSelector->getUnit());
if (result_sw == QUERY_STYLE_MULTIPLE_AVERAGED) {
- sp_unit_selector_set_unit(SP_UNIT_SELECTOR(unitSelector), &sp_unit_get_by_id(SP_UNIT_PERCENT));
+ unitSelector->setUnit("%");
} else {
// same width, or only one object; no sense to keep percent, switch to absolute
- if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) {
- sp_unit_selector_set_unit(SP_UNIT_SELECTOR(unitSelector), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units);
+ if (unit->type != Inkscape::Util::UNIT_TYPE_LINEAR) {
+ unitSelector->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr);
}
}
- unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unitSelector));
+ unit = new Inkscape::Util::Unit(unitSelector->getUnit());
- if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) {
- double avgwidth = sp_pixels_get_units (query->stroke_width.computed, *unit);
+ if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) {
+ double avgwidth = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *unit);
#if WITH_GTKMM_3_0
(*widthAdj)->set_value(avgwidth);
#else
@@ -1017,7 +962,7 @@ StrokeStyle::scaleLine()
double const miterlimit = miterLimitAdj->get_value();
#endif
- SPUnit const *const unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unitSelector));
+ Inkscape::Util::Unit const *const unit = new Inkscape::Util::Unit(unitSelector->getUnit());
double *dash, offset;
int ndash;
@@ -1026,8 +971,8 @@ StrokeStyle::scaleLine()
for (GSList const *i = items; i != NULL; i = i->next) {
/* Set stroke width */
double width;
- if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) {
- width = sp_units_get_pixels (width_typed, *unit);
+ if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) {
+ width = Inkscape::Util::Quantity::convert(width_typed, *unit, "px");
} else { // percentage
gdouble old_w = SP_OBJECT(i->data)->style->stroke_width.computed;
width = old_w * width_typed / 100;
@@ -1053,7 +998,7 @@ StrokeStyle::scaleLine()
g_free(dash);
- if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) {
+ if (unit->type != Inkscape::Util::UNIT_TYPE_LINEAR) {
// reset to 100 percent
#if WITH_GTKMM_3_0
(*widthAdj)->set_value(100.0);
diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h
index fd9940db1..440881c6d 100644
--- a/src/widgets/stroke-style.h
+++ b/src/widgets/stroke-style.h
@@ -40,8 +40,6 @@
#include "document-undo.h"
#include "gradient-chemistry.h"
#include "helper/stock-items.h"
-#include "helper/unit-menu.h"
-#include "helper/units.h"
#include "inkscape.h"
#include "io/sys.h"
#include "marker.h"
@@ -77,6 +75,17 @@ class Widget;
class Container;
}
+namespace Inkscape {
+ namespace Util {
+ class Unit;
+ }
+ namespace UI {
+ namespace Widget {
+ class UnitMenu;
+ }
+ }
+}
+
struct { gchar const *key; gint value; } const SPMarkerNames[] = {
{"marker-all", SP_MARKER_LOC},
{"marker-start", SP_MARKER_LOC_START},
@@ -162,17 +171,13 @@ private:
StrokeStyleButtonType button_type,
gchar const *stroke_style);
- static gboolean setStrokeWidthUnit(SPUnitSelector *,
- SPUnit const *old,
- SPUnit const *new_units,
- StrokeStyle *spw);
-
// Callback functions
void selectionModifiedCB(guint flags);
void selectionChangedCB();
void widthChangedCB();
void miterLimitChangedCB();
void lineDashChangedCB();
+ void unitChangedCB();
static void markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, SPMarkerLoc const which);
static void buttonToggledCB(StrokeStyleButton *tb, StrokeStyle *spw);
@@ -191,7 +196,7 @@ private:
#endif
Inkscape::UI::Widget::SpinButton *miterLimitSpin;
Inkscape::UI::Widget::SpinButton *widthSpin;
- GtkWidget *unitSelector;
+ Inkscape::UI::Widget::UnitMenu *unitSelector;
StrokeStyleButton *joinMiter;
StrokeStyleButton *joinRound;
StrokeStyleButton *joinBevel;
@@ -207,6 +212,9 @@ private:
sigc::connection startMarkerConn;
sigc::connection midMarkerConn;
sigc::connection endMarkerConn;
+ sigc::connection unitChangedConn;
+
+ Inkscape::Util::Unit *_old_unit;
};
} // namespace Inkscape
diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp
index 87cb54d10..7554f4faf 100644
--- a/src/widgets/text-toolbar.cpp
+++ b/src/widgets/text-toolbar.cpp
@@ -56,9 +56,6 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
#include "../sp-namedview.h"
#include "../svg/css-ostringstream.h"
@@ -72,7 +69,6 @@
#include "widgets/font-selector.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -1217,11 +1213,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
- // Is this used?
- UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE );
- tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units );
- g_object_set_data( holder, "tracker", tracker );
-
/* Font family */
{
// Font list
@@ -1462,7 +1453,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
"/tools/text/lineheight", /* preferences path */
0.0, /* default */
GTK_WIDGET(desktop->canvas), /* focusTarget */
- NULL, /* unit selector */
holder, /* dataKludge */
FALSE, /* set alt-x keyboard shortcut? */
NULL, /* altx_mark */
@@ -1493,7 +1483,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
"/tools/text/wordspacing", /* preferences path */
0.0, /* default */
GTK_WIDGET(desktop->canvas), /* focusTarget */
- NULL, /* unit selector */
holder, /* dataKludge */
FALSE, /* set alt-x keyboard shortcut? */
NULL, /* altx_mark */
@@ -1524,7 +1513,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
"/tools/text/letterspacing", /* preferences path */
0.0, /* default */
GTK_WIDGET(desktop->canvas), /* focusTarget */
- NULL, /* unit selector */
holder, /* dataKludge */
FALSE, /* set alt-x keyboard shortcut? */
NULL, /* altx_mark */
@@ -1555,7 +1543,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
"/tools/text/dx", /* preferences path */
0.0, /* default */
GTK_WIDGET(desktop->canvas), /* focusTarget */
- NULL, /* unit selector */
holder, /* dataKludge */
FALSE, /* set alt-x keyboard shortcut? */
NULL, /* altx_mark */
@@ -1586,7 +1573,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
"/tools/text/dy", /* preferences path */
0.0, /* default */
GTK_WIDGET(desktop->canvas), /* focusTarget */
- NULL, /* unit selector */
holder, /* dataKludge */
FALSE, /* set alt-x keyboard shortcut? */
NULL, /* altx_mark */
@@ -1617,7 +1603,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
"/tools/text/rotation", /* preferences path */
0.0, /* default */
GTK_WIDGET(desktop->canvas), /* focusTarget */
- NULL, /* unit selector */
holder, /* dataKludge */
FALSE, /* set alt-x keyboard shortcut? */
NULL, /* altx_mark */
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index 98a0ff51e..f3a83e84a 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -49,9 +49,6 @@
#include "../graphlayout.h"
#include "../helper/action.h"
#include "../helper/action-context.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "icon.h"
#include "../ink-action.h"
#include "../ink-comboboxentry-action.h"
@@ -101,7 +98,6 @@
//#define DEBUG_TEXT
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::PrefPusher;
@@ -1031,7 +1027,6 @@ EgeAdjustmentAction * create_adjustment_action( gchar const *name,
gchar const *label, gchar const *shortLabel, gchar const *tooltip,
Glib::ustring const &path, gdouble def,
GtkWidget *focusTarget,
- GtkWidget *us,
GObject *dataKludge,
gboolean altx, gchar const *altx_mark,
gdouble lower, gdouble upper, gdouble step, gdouble page,
@@ -1048,9 +1043,6 @@ EgeAdjustmentAction * create_adjustment_action( gchar const *name,
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( prefs->getDouble(path, def) * factor,
lower, upper, step, page, 0 ) );
- if (us) {
- sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(us), adj );
- }
g_signal_connect( G_OBJECT(adj), "value-changed", G_CALLBACK(callback), dataKludge );
diff --git a/src/widgets/toolbox.h b/src/widgets/toolbox.h
index 9c839a8fe..197f0fb5e 100644
--- a/src/widgets/toolbox.h
+++ b/src/widgets/toolbox.h
@@ -118,7 +118,6 @@ void delete_connection(GObject * /*obj*/, sigc::connection *connection);
gchar const *label, gchar const *shortLabel, gchar const *tooltip,
Glib::ustring const &path, gdouble def,
GtkWidget *focusTarget,
- GtkWidget *us,
GObject *dataKludge,
gboolean altx, gchar const *altx_mark,
gdouble lower, gdouble upper, gdouble step, gdouble page,
diff --git a/src/widgets/tweak-toolbar.cpp b/src/widgets/tweak-toolbar.cpp
index beb527a17..d5fe67ef7 100644
--- a/src/widgets/tweak-toolbar.cpp
+++ b/src/widgets/tweak-toolbar.cpp
@@ -52,13 +52,9 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
#include "../tweak-context.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
@@ -145,7 +141,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj
EgeAdjustmentAction *eact = create_adjustment_action( "TweakWidthAction",
_("Width"), _("Width:"), _("The width of the tweak area (relative to the visible canvas area)"),
"/tools/tweak/width", 15,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-tweak",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-tweak",
1, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_tweak_width_value_changed, 0.01, 0, 100 );
@@ -162,7 +158,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj
EgeAdjustmentAction *eact = create_adjustment_action( "TweakForceAction",
_("Force"), _("Force:"), _("The force of the tweak action"),
"/tools/tweak/force", 20,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-force",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "tweak-force",
1, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_tweak_force_value_changed, 0.01, 0, 100 );
@@ -371,7 +367,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj
_("Fidelity"), _("Fidelity:"),
_("Low fidelity simplifies paths; high fidelity preserves path features but may generate a lot of new nodes"),
"/tools/tweak/fidelity", 50,
- GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-fidelity",
+ GTK_WIDGET(desktop->canvas), holder, TRUE, "tweak-fidelity",
1, 100, 1.0, 10.0,
labels, values, G_N_ELEMENTS(labels),
sp_tweak_fidelity_value_changed, 0.01, 0, 100 );
diff --git a/src/widgets/zoom-toolbar.cpp b/src/widgets/zoom-toolbar.cpp
index 7d7f2c774..9cdbc3d6a 100644
--- a/src/widgets/zoom-toolbar.cpp
+++ b/src/widgets/zoom-toolbar.cpp
@@ -51,14 +51,10 @@
#include "../xml/repr.h"
#include "ui/uxmanager.h"
#include "../ui/icon-names.h"
-#include "../helper/unit-menu.h"
-#include "../helper/units.h"
-#include "../helper/unit-tracker.h"
#include "../pen-context.h"
#include "../tweak-context.h"
-using Inkscape::UnitTracker;
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;