diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2016-03-18 10:23:29 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2016-03-18 10:23:29 +0000 |
| commit | a714c688d60a3a62114591984f57f26cd41dbed9 (patch) | |
| tree | 3ad1c84aaf1097272b8ee2d4fca5db70f9c4edd3 /src/util/units.cpp | |
| parent | Revert 14707 (diff) | |
| download | inkscape-a714c688d60a3a62114591984f57f26cd41dbed9.tar.gz inkscape-a714c688d60a3a62114591984f57f26cd41dbed9.zip | |
Reverting 14701.
(bzr r14716.1.2)
Diffstat (limited to 'src/util/units.cpp')
| -rw-r--r-- | src/util/units.cpp | 70 |
1 files changed, 14 insertions, 56 deletions
diff --git a/src/util/units.cpp b/src/util/units.cpp index 2e7a3b1d2..2c72ec3ae 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -81,21 +81,7 @@ unsigned const svg_length_lookup[] = { UNIT_CODE_PERCENT }; -/* From SP_CSS_UNIT_* to unit */ -unsigned const sp_css_unit_lookup[] = { - 0, - UNIT_CODE_PX, - UNIT_CODE_PT, - UNIT_CODE_PC, - UNIT_CODE_MM, - UNIT_CODE_CM, - UNIT_CODE_IN, - UNIT_CODE_EM, - UNIT_CODE_EX, - UNIT_CODE_PERCENT - // UNIT_CODE_FT Missing, - // UNIT_CODE_MT Missing, -}; + // maps unit codes obtained from their abbreviations to their SVGLength unit indexes typedef INK_UNORDERED_MAP<unsigned, SVGLength::Unit> UnitCodeLookup; @@ -227,10 +213,6 @@ bool Unit::compatibleWith(Glib::ustring const &u) const { return compatibleWith(unit_table.getUnit(u)); } -bool Unit::compatibleWith(char const *u) const -{ - return compatibleWith(unit_table.getUnit(u)); -} bool Unit::operator==(Unit const &other) const { @@ -249,29 +231,7 @@ int Unit::svgUnit() const return 0; } -double Unit::convert(double from_dist, Unit const *to) const -{ - // Percentage - if (to->type == UNIT_TYPE_DIMENSIONLESS) { - return from_dist * to->factor; - } - - // Incompatible units - if (type != to->type) { - return -1; - } - - // Compatible units - return from_dist * factor / to->factor; -} -double Unit::convert(double from_dist, Glib::ustring const &to) const -{ - return convert(from_dist, unit_table.getUnit(to)); -} -double Unit::convert(double from_dist, char const *to) const -{ - return convert(from_dist, unit_table.getUnit(to)); -} + Unit UnitTable::_empty_unit; @@ -323,19 +283,6 @@ Unit const *UnitTable::getUnit(SVGLength::Unit u) const } return &_empty_unit; } -/* SP_CSS_UNIT lookup */ -Unit const *UnitTable::getUnit(unsigned int u) const -{ - if (u == 0 || u > 9) { - return &_empty_unit; - } - - UnitCodeMap::const_iterator f = _unit_map.find(sp_css_unit_lookup[u]); - if (f != _unit_map.end()) { - return &(*f->second); - } - return &_empty_unit; -} Unit const *UnitTable::findUnit(double factor, UnitType type) const { @@ -558,7 +505,18 @@ Glib::ustring Quantity::string() const { double Quantity::convert(double from_dist, Unit const *from, Unit const *to) { - return from->convert(from_dist, to); + // Percentage + if (to->type == UNIT_TYPE_DIMENSIONLESS) { + return from_dist * to->factor; + } + + // Incompatible units + if (from->type != to->type) { + return -1; + } + + // Compatible units + return from_dist * from->factor / to->factor; } double Quantity::convert(double from_dist, Glib::ustring const &from, Unit const *to) { |
