From bad0504958a10f1b99db3ae2557305541f388a52 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 24 Nov 2014 20:56:53 +0100 Subject: 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) --- src/document.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index f5269eab3..3715d8e6e 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -599,6 +599,14 @@ Inkscape::Util::Unit const* SPDocument::getDefaultUnit() const return nv ? nv->getDefaultUnit() : unit_table.getUnit("pt"); } +/// guaranteed not to return nullptr +// returns 'px' units as default, like legacy Inkscape +Inkscape::Util::Unit const& SPDocument::getSVGUnit() const +{ + SPNamedView const* nv = sp_document_namedview(this, NULL); + return nv ? nv->getSVGUnit() : *unit_table.getUnit("px"); +} + Inkscape::Util::Quantity SPDocument::getWidth() const { g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit(""))); -- cgit v1.2.3 From 6c4685e18a2672ceb73c6f5d0bd03914ffa746f9 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Mon, 24 Nov 2014 18:22:58 -0500 Subject: fix bug in rev 13632 when page size units = 'm'. (Bug 1395637) Fixed bugs: - https://launchpad.net/bugs/1395637 (bzr r13753) --- src/document.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 3715d8e6e..f69e830ff 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -636,6 +636,7 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width) if (*width.unit == *unit_table.getUnit("m")) { root->width.value = width.value("cm"); root->width.unit = SVGLength::CM; + old_converted = Inkscape::Util::Quantity::convert(old_converted, "m", "cm"); } else { root->width.value = width.quantity; root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); @@ -677,6 +678,7 @@ void SPDocument::setHeight(const Inkscape::Util::Quantity &height) if (*height.unit == *unit_table.getUnit("m")) { root->height.value = height.value("cm"); root->height.unit = SVGLength::CM; + old_converted = Inkscape::Util::Quantity::convert(old_converted, "m", "cm"); } else { root->height.value = height.quantity; root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); -- cgit v1.2.3 From 9827a6723d62935725b67b1bf55eea08bbbab527 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 25 Nov 2014 15:20:24 +0100 Subject: Move 'm' handling code from document.cpp to svg-length.cpp and units.cpp to match handling of 'ft'. (bzr r13758) --- src/document.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index f69e830ff..e24af8fa8 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -630,17 +630,10 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width) if (root->width.unit) old_units = unit_table.getUnit(root->width.unit); gdouble old_converted = Inkscape::Util::Quantity::convert(root->width.value, old_units, width.unit); + root->width.computed = width.value("px"); - /* SVG does not support meters as a unit, so we must translate meters to - * cm when writing */ - if (*width.unit == *unit_table.getUnit("m")) { - root->width.value = width.value("cm"); - root->width.unit = SVGLength::CM; - old_converted = Inkscape::Util::Quantity::convert(old_converted, "m", "cm"); - } else { - root->width.value = width.quantity; - root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); - } + root->width.value = width.quantity; + root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); if (root->viewBox_set) root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_converted) * root->viewBox.width(), root->viewBox.bottom())); @@ -672,17 +665,10 @@ void SPDocument::setHeight(const Inkscape::Util::Quantity &height) if (root->height.unit) old_units = unit_table.getUnit(root->height.unit); gdouble old_converted = Inkscape::Util::Quantity::convert(root->height.value, old_units, height.unit); + root->height.computed = height.value("px"); - /* SVG does not support meters as a unit, so we must translate meters to - * cm when writing */ - if (*height.unit == *unit_table.getUnit("m")) { - root->height.value = height.value("cm"); - root->height.unit = SVGLength::CM; - old_converted = Inkscape::Util::Quantity::convert(old_converted, "m", "cm"); - } else { - root->height.value = height.quantity; - root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); - } + root->height.value = height.quantity; + root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); if (root->viewBox_set) root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_converted) * root->viewBox.height())); -- cgit v1.2.3