diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2014-11-24 21:38:54 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2014-11-24 21:38:54 +0000 |
| commit | 5497de6e39d4fc31a6824eb9f9e638635de4521b (patch) | |
| tree | d1e5d867d3b9f618846bdfe65e147b23df8ed58a /src/util | |
| parent | Fixing bend from clipboard to trunk 0.92 (diff) | |
| parent | Fix a bug in pen/cil modes triangle in/out (diff) | |
| download | inkscape-5497de6e39d4fc31a6824eb9f9e638635de4521b.tar.gz inkscape-5497de6e39d4fc31a6824eb9f9e638635de4521b.zip | |
update to trunk
(bzr r12588.1.37)
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/units.cpp | 24 | ||||
| -rw-r--r-- | src/util/units.h | 3 |
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; |
