From 77f61343ff18f29f05331131c2fe2bd810a64498 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 25 Aug 2013 19:42:22 -0400 Subject: Use real world units for page sizes. (bzr r12475.1.1) --- src/util/units.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/util/units.cpp') diff --git a/src/util/units.cpp b/src/util/units.cpp index 7bc910fcc..e7be3f5e6 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -220,6 +220,36 @@ Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const return Unit(); } } +Unit UnitTable::getUnit(SVGLength::Unit const u) const +{ + Glib::ustring u_str; + switch(u) { + case 1: + u_str = "px"; break; + case 2: + u_str = "pt"; break; + case 3: + u_str = "pc"; break; + case 4: + u_str = "mm"; break; + case 5: + u_str = "cm"; break; + case 6: + u_str = "in"; break; + case 7: + u_str = "ft"; break; + case 8: + u_str = "em"; break; + case 9: + u_str = "ex"; break; + case 10: + u_str = "%"; break; + default: + u_str = ""; + } + + return getUnit(u_str); +} Quantity UnitTable::getQuantity(Glib::ustring const& q) const { -- cgit v1.2.3 From fcd3b1af971172bf0fbe6eabcd97eaf1223267ba Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Tue, 27 Aug 2013 22:14:56 -0400 Subject: Use enum names instead of numbers. (bzr r12475.1.6) --- src/util/units.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/util/units.cpp') diff --git a/src/util/units.cpp b/src/util/units.cpp index e7be3f5e6..8bae9c419 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -166,25 +166,25 @@ bool operator!= (const Unit &u1, const Unit &u2) int Unit::svgUnit() const { if (!abbr.compare("px")) - return 1; + return SVGLength::PX; if (!abbr.compare("pt")) - return 2; + return SVGLength::PT; if (!abbr.compare("pc")) - return 3; + return SVGLength::PC; if (!abbr.compare("mm")) - return 4; + return SVGLength::MM; if (!abbr.compare("cm")) - return 5; + return SVGLength::CM; if (!abbr.compare("in")) - return 6; + return SVGLength::INCH; if (!abbr.compare("ft")) - return 7; + return SVGLength::FOOT; if (!abbr.compare("em")) - return 8; + return SVGLength::EM; if (!abbr.compare("ex")) - return 9; + return SVGLength::EX; if (!abbr.compare("%")) - return 10; + return SVGLength::PERCENT; return 0; } @@ -224,25 +224,25 @@ Unit UnitTable::getUnit(SVGLength::Unit const u) const { Glib::ustring u_str; switch(u) { - case 1: + case SVGLength::PX: u_str = "px"; break; - case 2: + case SVGLength::PT: u_str = "pt"; break; - case 3: + case SVGLength::PC: u_str = "pc"; break; - case 4: + case SVGLength::MM: u_str = "mm"; break; - case 5: + case SVGLength::CM: u_str = "cm"; break; - case 6: + case SVGLength::INCH: u_str = "in"; break; - case 7: + case SVGLength::FOOT: u_str = "ft"; break; - case 8: + case SVGLength::EM: u_str = "em"; break; - case 9: + case SVGLength::EX: u_str = "ex"; break; - case 10: + case SVGLength::PERCENT: u_str = "%"; break; default: u_str = ""; -- cgit v1.2.3 From bdb32f3606bca79275b0aafce4a2c722de88fd5d Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Tue, 27 Aug 2013 22:53:31 -0400 Subject: Added Quantity comparison functions. (bzr r12475.1.7) --- src/util/units.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/util/units.cpp') diff --git a/src/util/units.cpp b/src/util/units.cpp index 8bae9c419..2b09337b6 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -450,6 +450,27 @@ double Quantity::convert(const double from_dist, const Glib::ustring from, const return convert(from_dist, unit_table.getUnit(from), unit_table.getUnit(to)); } +bool operator< (const Quantity &ql, const Quantity &qr) +{ + if (ql.unit->type != qr.unit->type) { + g_warning("Incompatible units"); + return false; + } + return ql.quantity < qr.value(*ql.unit); +} +bool operator> (const Quantity &ql, const Quantity &qr) +{ + if (ql.unit->type != qr.unit->type) { + g_warning("Incompatible units"); + return false; + } + return ql.quantity > qr.value(*ql.unit); +} +bool operator!= (const Quantity &q1, const Quantity &q2) +{ + return (*q1.unit != *q2.unit) || (q1.quantity != q2.quantity); +} + } // namespace Util } // namespace Inkscape -- cgit v1.2.3 From f55a53ef2d861b634ad83622edc5e26430baeae0 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 15 Sep 2013 23:59:14 -0400 Subject: C++ify expression evaluator. (bzr r12475.1.23) --- src/util/units.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/util/units.cpp') diff --git a/src/util/units.cpp b/src/util/units.cpp index 414885040..e5c6f74fb 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -114,6 +114,7 @@ Unit::Unit(UnitType type, abbr(abbr), description(description) { + g_return_if_fail(factor <= 0); } void Unit::clear() -- cgit v1.2.3