diff options
| author | Martin Owens <doctormo@gmail.com> | 2016-03-12 23:50:04 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2016-03-12 23:50:04 +0000 |
| commit | 1c9e7ee09d40b8e06b80d0a09eca17d1b0fb8357 (patch) | |
| tree | c660c2c4b4002e3c142d386582afeddd5f5b35b3 /src/util/units.cpp | |
| parent | Add new TTF to the logo in seamless pattern extension (diff) | |
| download | inkscape-1c9e7ee09d40b8e06b80d0a09eca17d1b0fb8357.tar.gz inkscape-1c9e7ee09d40b8e06b80d0a09eca17d1b0fb8357.zip | |
Add a units box to line height and wire in the style units, plus some cleanup
(bzr r14701)
Diffstat (limited to 'src/util/units.cpp')
| -rw-r--r-- | src/util/units.cpp | 70 |
1 files changed, 56 insertions, 14 deletions
diff --git a/src/util/units.cpp b/src/util/units.cpp index 2c72ec3ae..2e7a3b1d2 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -81,7 +81,21 @@ 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; @@ -213,6 +227,10 @@ 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 { @@ -231,7 +249,29 @@ 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; @@ -283,6 +323,19 @@ 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 { @@ -505,18 +558,7 @@ Glib::ustring Quantity::string() const { double Quantity::convert(double from_dist, Unit const *from, Unit const *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; + return from->convert(from_dist, to); } double Quantity::convert(double from_dist, Glib::ustring const &from, Unit const *to) { |
