diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2013-10-12 22:24:05 +0000 |
|---|---|---|
| committer | Johan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl> | 2013-10-12 22:24:05 +0000 |
| commit | a970dc423d59ea844bdb1af48d5d9419a5e2a287 (patch) | |
| tree | 8f6a51df0574fe048ae7e791f276e72716aa090c /src/sp-namedview.cpp | |
| parent | Fix crash with experimental lpe tool. (diff) | |
| download | inkscape-a970dc423d59ea844bdb1af48d5d9419a5e2a287.tar.gz inkscape-a970dc423d59ea844bdb1af48d5d9419a5e2a287.zip | |
Units: stop newing Unit objects. pass around pointers to "undeletable" Unit objects in the UnitTable. I think we should move to using indexed units, and pass around the index of the unit in the unittable, or smth like that... ?
(bzr r12679)
Diffstat (limited to 'src/sp-namedview.cpp')
| -rw-r--r-- | src/sp-namedview.cpp | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 4464a0be2..ad497ff2f 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -557,12 +557,11 @@ void SPNamedView::set(unsigned int key, const gchar* value) { * in that they aren't in general absolute units as currently required by * doc_units. */ - static Inkscape::Util::Unit px = unit_table.getUnit("px"); - Inkscape::Util::Unit const *new_unit = new Inkscape::Util::Unit(px); + static Inkscape::Util::Unit const *px = unit_table.getUnit("px"); + Inkscape::Util::Unit const *new_unit = px; if (value) { - Inkscape::Util::Unit u = unit_table.getUnit(value); - Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u); + Inkscape::Util::Unit const *const req_unit = unit_table.getUnit(value); if ( !unit_table.hasUnit(value) ) { g_warning("Unrecognized unit `%s'", value); /* fixme: Document errors should be reported in the status bar or @@ -585,8 +584,7 @@ void SPNamedView::set(unsigned int key, const gchar* value) { Inkscape::Util::Unit const *new_unit = NULL; if (value) { - Inkscape::Util::Unit u = unit_table.getUnit(value); - Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u); + Inkscape::Util::Unit const *const req_unit = unit_table.getUnit(value); if ( !unit_table.hasUnit(value) ) { g_warning("Unrecognized unit `%s'", value); /* fixme: Document errors should be reported in the status bar or @@ -1114,14 +1112,14 @@ double SPNamedView::getMarginLength(gchar const * const key, bool const use_width) { double value; - Inkscape::Util::Unit percent = unit_table.getUnit("%"); + static Inkscape::Util::Unit const *percent = unit_table.getUnit("%"); if(!this->storeAsDouble(key,&value)) { return 0.0; } - if (*margin_units == percent) { + if (*margin_units == *percent) { return (use_width)? width * value : height * value; } - if (!margin_units->compatibleWith(*return_units)) { + if (!margin_units->compatibleWith(return_units)) { return 0.0; } return value; @@ -1129,14 +1127,11 @@ double SPNamedView::getMarginLength(gchar const * const key, /** * Returns namedview's default unit. + * If no default unit is set, "pt" is returned */ -Inkscape::Util::Unit const SPNamedView::getDefaultUnit() const +Inkscape::Util::Unit const * SPNamedView::getDefaultUnit() const { - if (doc_units) { - return *doc_units; - } else { - return *(new Inkscape::Util::Unit(unit_table.getUnit("pt"))); - } + return doc_units ? doc_units : unit_table.getUnit("pt"); } /** |
