summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2014-11-24 19:56:53 +0000
committerJohan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl>2014-11-24 19:56:53 +0000
commitbad0504958a10f1b99db3ae2557305541f388a52 (patch)
tree2fdec1e71db3d37d097e07cdd5b210eaaa844bcf /src/util
parentExtensions: try to calculate the SVG unit (diff)
downloadinkscape-bad0504958a10f1b99db3ae2557305541f388a52.tar.gz
inkscape-bad0504958a10f1b99db3ae2557305541f388a52.zip
Units: make it absolutely clear that Document properties unit dropdown is for UI Display Units. Upon document load, calculate the units used for SVG values, if a viewbox is available. If not, default to "px" SVG units.
Change all code to use either Display units OR svg units. (bzr r13751)
Diffstat (limited to 'src/util')
-rw-r--r--src/util/units.cpp24
-rw-r--r--src/util/units.h3
2 files changed, 27 insertions, 0 deletions
diff --git a/src/util/units.cpp b/src/util/units.cpp
index 3d635e2d2..8ad3560dd 100644
--- a/src/util/units.cpp
+++ b/src/util/units.cpp
@@ -21,6 +21,8 @@
#include <glibmm/fileutils.h>
#include <glibmm/markup.h>
+#include <2geom/coord.h>
+
#include "util/units.h"
#include "path-prefix.h"
#include "streq.h"
@@ -279,6 +281,28 @@ Unit const *UnitTable::getUnit(SVGLength::Unit u) const
return &_empty_unit;
}
+Unit const *UnitTable::findUnit(double factor, UnitType type) const
+{
+ const double eps = factor * 0.01; // allow for 1% deviation
+
+ UnitCodeMap::const_iterator cit = _unit_map.begin();
+ while (cit != _unit_map.end()) {
+ if (cit->second->type == type) {
+ if (Geom::are_near(cit->second->factor, factor, eps)) {
+ // unit found!
+ break;
+ }
+ }
+ ++cit;
+ }
+
+ if (cit != _unit_map.end()) {
+ return cit->second;
+ } else {
+ return getUnit(_primary_unit[type]);
+ }
+}
+
Quantity UnitTable::parseQuantity(Glib::ustring const &q) const
{
Glib::MatchInfo match_info;
diff --git a/src/util/units.h b/src/util/units.h
index efe1dbec7..13777fd1b 100644
--- a/src/util/units.h
+++ b/src/util/units.h
@@ -141,6 +141,9 @@ public:
/** Retrieve a given unit based on its string identifier */
Unit const *getUnit(Glib::ustring const &name) const;
Unit const *getUnit(char const *name) const;
+
+ /** Try to find a unit based on its conversion factor to the primary */
+ Unit const *findUnit(double factor, UnitType type) const;
/** Retrieve a given unit based on its SVGLength unit */
Unit const *getUnit(SVGLength::Unit u) const;