summaryrefslogtreecommitdiffstats
path: root/src/util/units.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-03-18 18:13:01 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-03-18 18:13:01 +0000
commit0d3d7f676b29f9d9a9cd53f08ced76e6588b856a (patch)
tree12a2646048750e49e7edee42046b8aa138207f2c /src/util/units.cpp
parentwarping into a layer (diff)
parentReplace sp_style_xxx functions with SPStyle member functions. (diff)
downloadinkscape-0d3d7f676b29f9d9a9cd53f08ced76e6588b856a.tar.gz
inkscape-0d3d7f676b29f9d9a9cd53f08ced76e6588b856a.zip
update to trunk
(bzr r13682.1.22)
Diffstat (limited to 'src/util/units.cpp')
-rw-r--r--src/util/units.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/util/units.cpp b/src/util/units.cpp
index 3d635e2d2..2c72ec3ae 100644
--- a/src/util/units.cpp
+++ b/src/util/units.cpp
@@ -16,11 +16,14 @@
#include <cmath>
#include <cerrno>
#include <iomanip>
+#include <iostream>
#include <glib.h>
#include <glibmm/regex.h>
#include <glibmm/fileutils.h>
#include <glibmm/markup.h>
+#include <2geom/coord.h>
+
#include "util/units.h"
#include "path-prefix.h"
#include "streq.h"
@@ -44,6 +47,7 @@ enum UnitCode {
UNIT_CODE_CM = MAKE_UNIT_CODE('c','m'),
UNIT_CODE_IN = MAKE_UNIT_CODE('i','n'),
UNIT_CODE_FT = MAKE_UNIT_CODE('f','t'),
+ UNIT_CODE_MT = MAKE_UNIT_CODE('m',' '),
UNIT_CODE_EM = MAKE_UNIT_CODE('e','m'),
UNIT_CODE_EX = MAKE_UNIT_CODE('e','x'),
UNIT_CODE_PERCENT = MAKE_UNIT_CODE('%',0)
@@ -71,6 +75,7 @@ unsigned const svg_length_lookup[] = {
UNIT_CODE_CM,
UNIT_CODE_IN,
UNIT_CODE_FT,
+ UNIT_CODE_MT,
UNIT_CODE_EM,
UNIT_CODE_EX,
UNIT_CODE_PERCENT
@@ -279,6 +284,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;