From f10048be170a45921ae8fc65ccd2588a9ad2897d Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Tue, 27 Aug 2013 12:32:55 -0400 Subject: Added viewBox implement document unit support. (bzr r12475.1.2) --- src/document.cpp | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 0b742e491..20c6fe331 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -534,16 +534,20 @@ SPDocument *SPDocument::doUnref() return NULL; } -gdouble SPDocument::getWidth() const +Inkscape::Util::Quantity SPDocument::getWidth() const { - g_return_val_if_fail(this->priv != NULL, 0.0); - g_return_val_if_fail(this->root != NULL, 0.0); + g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); + g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); - gdouble result = root->width.computed; + gdouble result = root->width.value; + SVGLength::Unit u = root->width.unit; if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { result = root->viewBox.width(); } - return result; + if (u == SVGLength::NONE) { + u = SVGLength::PX; + } + return Inkscape::Util::Quantity(result, unit_table.getUnit(u)); } void SPDocument::setWidth(const Inkscape::Util::Quantity &width) @@ -570,16 +574,20 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width) root->updateRepr(); } -gdouble SPDocument::getHeight() const +Inkscape::Util::Quantity SPDocument::getHeight() const { - g_return_val_if_fail(this->priv != NULL, 0.0); - g_return_val_if_fail(this->root != NULL, 0.0); + g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); + g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); - gdouble result = root->height.computed; + gdouble result = root->height.value; + SVGLength::Unit u = root->height.unit; if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { result = root->viewBox.height(); } - return result; + if (u == SVGLength::NONE) { + u = SVGLength::PX; + } + return Inkscape::Util::Quantity(result, unit_table.getUnit(u)); } void SPDocument::setHeight(const Inkscape::Util::Quantity &height) @@ -606,9 +614,16 @@ void SPDocument::setHeight(const Inkscape::Util::Quantity &height) root->updateRepr(); } +void SPDocument::setViewBox(const Geom::Rect &viewBox) +{ + root->viewBox_set = true; + root->viewBox = viewBox; + root->updateRepr(); +} + Geom::Point SPDocument::getDimensions() const { - return Geom::Point(getWidth(), getHeight()); + return Geom::Point(getWidth().value("px"), getHeight().value("px")); } Geom::OptRect SPDocument::preferredBounds() const @@ -630,7 +645,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) double const w = rect.width(); double const h = rect.height(); - double const old_height = getHeight(); + double const old_height = getHeight().value("px"); Inkscape::Util::Unit const px = unit_table.getUnit("px"); /* in px */ -- cgit v1.2.3 From 3bfb610bb7719d49821fe5381ae449789c3cb968 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Tue, 27 Aug 2013 23:32:14 -0400 Subject: Improve code readability. (bzr r12475.1.9) --- src/document.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 20c6fe331..a544c60c9 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -980,7 +980,7 @@ void SPDocument::setupViewport(SPItemCtx *ctx) if (root->viewBox_set) { // if set, take from viewBox ctx->viewport = root->viewBox; } else { // as a last resort, set size to A4 - ctx->viewport = Geom::Rect::from_xywh(0, 0, 210 * Inkscape::Util::Quantity::convert(1, "mm", "px"), 297 * Inkscape::Util::Quantity::convert(1, "mm", "px")); + ctx->viewport = Geom::Rect::from_xywh(0, 0, Inkscape::Util::Quantity::convert(210, "mm", "px"), Inkscape::Util::Quantity::convert(297, "mm", "px")); } ctx->i2vp = Geom::identity(); } -- cgit v1.2.3 From 4e8b8beaf879c90d59ef84548b2299151dbfb697 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 20 Sep 2013 18:13:00 -0400 Subject: Use viewBox for new documents. Fixed bugs: - https://launchpad.net/bugs/171203 - https://launchpad.net/bugs/168261 (bzr r12557) --- src/document.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 967d049c2..5e59a0a0c 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -450,6 +450,11 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, document->setCurrentPersp3DImpl(persp_impl); } + // Set viewBox if it doesn't exist + if (!document->root->viewBox_set) { + document->setViewBox(Geom::Rect::from_xywh(0, 0, document->getWidth().quantity, document->getHeight().quantity)); + } + DocumentUndo::setUndoSensitive(document, true); // reset undo key when selection changes, so that same-key actions on different objects are not coalesced -- cgit v1.2.3 From 2df0abfd438d90edb6056f0197ed9d27ce2cd1f1 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 22 Sep 2013 13:47:37 -0400 Subject: Fix adding viewBox to new documents. Fixed bugs: - https://launchpad.net/bugs/1228660 - https://launchpad.net/bugs/1228693 - https://launchpad.net/bugs/1228852 (bzr r12575) --- src/document.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 5e59a0a0c..967d049c2 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -450,11 +450,6 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, document->setCurrentPersp3DImpl(persp_impl); } - // Set viewBox if it doesn't exist - if (!document->root->viewBox_set) { - document->setViewBox(Geom::Rect::from_xywh(0, 0, document->getWidth().quantity, document->getHeight().quantity)); - } - DocumentUndo::setUndoSensitive(document, true); // reset undo key when selection changes, so that same-key actions on different objects are not coalesced -- cgit v1.2.3 From 37b7de3efa31c7aa3094aed7c849a08e7f7bedfd Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 22 Sep 2013 20:26:44 -0400 Subject: Fix percentage document size handling. Fixed bugs: - https://launchpad.net/bugs/1228852 (bzr r12577) --- src/document.cpp | 62 +++++++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 967d049c2..800f2f33d 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -557,6 +557,7 @@ Inkscape::Util::Quantity SPDocument::getWidth() const SVGLength::Unit u = root->width.unit; if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { result = root->viewBox.width(); + u = SVGLength::PX; } if (u == SVGLength::NONE) { u = SVGLength::PX; @@ -566,25 +567,21 @@ Inkscape::Util::Quantity SPDocument::getWidth() const void SPDocument::setWidth(const Inkscape::Util::Quantity &width) { - if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= - root->viewBox.setMax(Geom::Point(root->viewBox.left() + width.value("px"), root->viewBox.bottom())); - } else { // set to width= - gdouble old_computed = root->width.computed; - 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; - } else { - 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.computed / old_computed) * root->viewBox.width(), root->viewBox.bottom())); + gdouble old_computed = root->width.computed; + 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; + } else { + 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.computed / old_computed) * root->viewBox.width(), root->viewBox.bottom())); + root->updateRepr(); } @@ -597,6 +594,7 @@ Inkscape::Util::Quantity SPDocument::getHeight() const SVGLength::Unit u = root->height.unit; if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { result = root->viewBox.height(); + u = SVGLength::PX; } if (u == SVGLength::NONE) { u = SVGLength::PX; @@ -606,25 +604,21 @@ Inkscape::Util::Quantity SPDocument::getHeight() const void SPDocument::setHeight(const Inkscape::Util::Quantity &height) { - if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= - root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + height.value("px"))); - } else { // set to height= - gdouble old_computed = root->height.computed; - 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; - } else { - 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.computed / old_computed) * root->viewBox.height())); + gdouble old_computed = root->height.computed; + 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; + } else { + 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.computed / old_computed) * root->viewBox.height())); + root->updateRepr(); } -- cgit v1.2.3