diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2014-11-24 19:56:53 +0000 |
|---|---|---|
| committer | Johan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl> | 2014-11-24 19:56:53 +0000 |
| commit | bad0504958a10f1b99db3ae2557305541f388a52 (patch) | |
| tree | 2fdec1e71db3d37d097e07cdd5b210eaaa844bcf /src/util/units.cpp | |
| parent | Extensions: try to calculate the SVG unit (diff) | |
| download | inkscape-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/units.cpp')
| -rw-r--r-- | src/util/units.cpp | 24 |
1 files changed, 24 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; |
