From bd77ef25e9161acb007323f851ba77e106036939 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Mon, 1 Jul 2013 23:40:52 -0400 Subject: Ported "ui/widget/page-sizer.cpp" and "document.cpp" to "Util::Unit" class. (bzr r12380.1.4) --- src/sp-namedview.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/sp-namedview.cpp') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 452f57425..5184d37a9 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -1101,20 +1101,23 @@ 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; + static Inkscape::Util::UnitTable unit_table; + 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 (!sp_convert_distance (&value, margin_units, return_units)) { + if (!margin_units->compatibleWith(return_units)) { return 0.0; } return value; -- cgit v1.2.3 From 9dc7b786c9ef31060012ea4ae13a8188548b4f62 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Tue, 9 Jul 2013 16:42:04 -0400 Subject: Ported sp-namedview.cpp (todo: fix a bunch of things). (bzr r12380.1.8) --- src/sp-namedview.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/sp-namedview.cpp') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 5184d37a9..c7301f9bd 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" @@ -287,6 +287,8 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va { SPNamedView *nv = SP_NAMEDVIEW(object); + static Inkscape::Util::UnitTable unit_table; + switch (key) { case SP_ATTR_VIEWONLY: nv->editable = (!value); @@ -549,18 +551,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 = &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 = &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 +576,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 = &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'", @@ -1130,7 +1133,7 @@ double SPNamedView::getMarginLength(gchar const * const key, SPMetric SPNamedView::getDefaultMetric() const { if (doc_units) { - return sp_unit_get_metric(doc_units); + return (SPMetric) doc_units->metric(); } else { return SP_PT; } -- cgit v1.2.3 From c99f5b02fce8b98463d7868c61bc77f8bf675665 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 00:48:43 -0400 Subject: Fixed memory corruption introduced in a previous commit. (bzr r12380.1.14) --- src/sp-namedview.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/sp-namedview.cpp') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index c7301f9bd..0833d93bf 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -552,11 +552,11 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va * doc_units. */ static Inkscape::Util::Unit px = unit_table.getUnit("px"); - Inkscape::Util::Unit const *new_unit = &px; + Inkscape::Util::Unit const *new_unit = new Inkscape::Util::Unit(px); if (value) { Inkscape::Util::Unit u = unit_table.getUnit(value); - Inkscape::Util::Unit const *const req_unit = &u; + 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 @@ -580,7 +580,7 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va if (value) { Inkscape::Util::Unit u = unit_table.getUnit(value); - Inkscape::Util::Unit const *const req_unit = &u; + 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 -- cgit v1.2.3 From 3772fc428950b2b946a1bd7c7c97e06219c3165f Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 18 Jul 2013 17:21:24 -0400 Subject: Switch unit functions from using pointer arguements to reference arguements. (bzr r12380.1.28) --- src/sp-namedview.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/sp-namedview.cpp') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 0833d93bf..bf3adf816 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -1119,8 +1119,7 @@ double SPNamedView::getMarginLength(gchar const * const key, 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)) { + if (!margin_units->compatibleWith(*return_units)) { return 0.0; } return value; -- cgit v1.2.3 From 4deb0f64f3bdab48475819a4d236f125594244f4 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 21 Jul 2013 23:38:29 -0400 Subject: Ported "widgets/ruler.*" away from SPMetric. (bzr r12380.1.48) --- src/sp-namedview.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/sp-namedview.cpp') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index bf3adf816..d01185981 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -1138,6 +1138,19 @@ SPMetric SPNamedView::getDefaultMetric() const } } +/** + * Returns namedview's default unit. + */ +Inkscape::Util::Unit const SPNamedView::getDefaultUnit() const +{ + if (doc_units) { + return *doc_units; + } else { + Inkscape::Util::UnitTable unit_table; + return *(new Inkscape::Util::Unit(unit_table.getUnit("pt"))); + } +} + /** * Returns the first grid it could find that isEnabled(). Returns NULL, if none is enabled */ -- cgit v1.2.3 From 0b2190b4a186f4b1a2265c85b4baa801d49e5534 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 21 Jul 2013 23:50:53 -0400 Subject: Removed SPMetric. (bzr r12380.1.49) --- src/sp-namedview.cpp | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'src/sp-namedview.cpp') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index d01185981..dde205eed 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -1125,19 +1125,6 @@ double SPNamedView::getMarginLength(gchar const * const key, return value; } - -/** - * Returns namedview's default metric. - */ -SPMetric SPNamedView::getDefaultMetric() const -{ - if (doc_units) { - return (SPMetric) doc_units->metric(); - } else { - return SP_PT; - } -} - /** * Returns namedview's default unit. */ -- cgit v1.2.3 From 6ae6c0bea96eef09907091279e0678aa5f83102d Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 4 Aug 2013 18:01:18 -0400 Subject: Switched to global UnitTable. (bzr r12380.1.62) --- src/sp-namedview.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/sp-namedview.cpp') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index dde205eed..48f8eba2a 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -40,6 +40,7 @@ #include using Inkscape::DocumentUndo; +using Inkscape::Util::unit_table; #define DEFAULTGRIDCOLOR 0x3f3fff25 #define DEFAULTGRIDEMPCOLOR 0x3f3fff60 @@ -287,8 +288,6 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va { SPNamedView *nv = SP_NAMEDVIEW(object); - static Inkscape::Util::UnitTable unit_table; - switch (key) { case SP_ATTR_VIEWONLY: nv->editable = (!value); @@ -1111,7 +1110,6 @@ double SPNamedView::getMarginLength(gchar const * const key, bool const use_width) { double value; - static Inkscape::Util::UnitTable unit_table; Inkscape::Util::Unit percent = unit_table.getUnit("%"); if(!this->storeAsDouble(key,&value)) { return 0.0; @@ -1133,7 +1131,6 @@ Inkscape::Util::Unit const SPNamedView::getDefaultUnit() const if (doc_units) { return *doc_units; } else { - Inkscape::Util::UnitTable unit_table; return *(new Inkscape::Util::Unit(unit_table.getUnit("pt"))); } } -- cgit v1.2.3