From 69ae98cb453849c6d32a1c7ea8bc057fb13deea3 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Wed, 25 Jun 2014 11:32:51 -0400 Subject: 1. make it compile (bzr r13341.5.1) --- src/document.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index f79a00178..80e9bfe4f 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -218,7 +218,7 @@ SPDocument::~SPDocument() { } if (keepalive) { - inkscape_unref(); + inkscape_unref(INKSCAPE); keepalive = FALSE; } @@ -448,7 +448,7 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, rdf_set_defaults( document ); if (keepalive) { - inkscape_ref(); + inkscape_ref(INKSCAPE); } // Check if the document already has a perspective (e.g., when opening an existing -- cgit v1.2.3 From 60f288cc584bf34c65698341427cf377b88c7138 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Wed, 25 Jun 2014 16:21:44 -0400 Subject: 2. connect signals (bzr r13341.5.2) --- src/document.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 80e9bfe4f..ee1a48eb6 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -154,6 +154,17 @@ SPDocument::~SPDocument() { router = NULL; } + if (oldSignalsConnected) { + priv->selChangeConnection.disconnect(); + priv->desktopActivatedConnection.disconnect(); + //g_signal_handlers_disconnect_by_func(G_OBJECT(INKSCAPE), + //reinterpret_cast(DocumentUndo::resetKey), + //static_cast(this)); + } else { + _selection_changed_connection.disconnect(); + _desktop_activated_connection.disconnect(); + } + if (priv) { if (priv->partial) { sp_repr_free_log(priv->partial); @@ -208,15 +219,6 @@ SPDocument::~SPDocument() { rerouting_handler_id = 0; } - if (oldSignalsConnected) { - g_signal_handlers_disconnect_by_func(G_OBJECT(INKSCAPE), - reinterpret_cast(DocumentUndo::resetKey), - static_cast(this)); - } else { - _selection_changed_connection.disconnect(); - _desktop_activated_connection.disconnect(); - } - if (keepalive) { inkscape_unref(INKSCAPE); keepalive = FALSE; @@ -463,10 +465,21 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, DocumentUndo::setUndoSensitive(document, true); // reset undo key when selection changes, so that same-key actions on different objects are not coalesced - g_signal_connect(G_OBJECT(INKSCAPE), "change_selection", + document->priv->selChangeConnection = INKSCAPE->signal_selection_changed.connect( + sigc::hide( // hide unused first and second args + sigc::hide(sigc::bind( + sigc::ptr_fun(&DocumentUndo::resetKey), document) + ))); + document->priv->desktopActivatedConnection = INKSCAPE->signal_activate_desktop.connect( + sigc::hide( // hide unused first and second args + sigc::hide(sigc::bind( + sigc::ptr_fun(&DocumentUndo::resetKey), document) + ))); + + /*g_signal_connect(G_OBJECT(INKSCAPE), "change_selection", G_CALLBACK(DocumentUndo::resetKey), document); g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", - G_CALLBACK(DocumentUndo::resetKey), document); + G_CALLBACK(DocumentUndo::resetKey), document);*/ document->oldSignalsConnected = true; return document; -- cgit v1.2.3 From cdc7587062b42c39a23451e5c9ec7da06dd6fdb3 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Wed, 25 Jun 2014 21:45:01 -0400 Subject: 3. remove dead code, refactor existing code. Connect overlooked signals. (bzr r13341.5.3) --- src/document.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index ee1a48eb6..26e59e610 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -50,7 +50,7 @@ #include "document-private.h" #include "document-undo.h" #include "id-clash.h" -#include "inkscape-private.h" +#include "inkscape.h" #include "inkscape-version.h" #include "libavoid/router.h" #include "persp3d.h" @@ -157,9 +157,6 @@ SPDocument::~SPDocument() { if (oldSignalsConnected) { priv->selChangeConnection.disconnect(); priv->desktopActivatedConnection.disconnect(); - //g_signal_handlers_disconnect_by_func(G_OBJECT(INKSCAPE), - //reinterpret_cast(DocumentUndo::resetKey), - //static_cast(this)); } else { _selection_changed_connection.disconnect(); _desktop_activated_connection.disconnect(); @@ -475,11 +472,6 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, sigc::hide(sigc::bind( sigc::ptr_fun(&DocumentUndo::resetKey), document) ))); - - /*g_signal_connect(G_OBJECT(INKSCAPE), "change_selection", - G_CALLBACK(DocumentUndo::resetKey), document); - g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", - G_CALLBACK(DocumentUndo::resetKey), document);*/ document->oldSignalsConnected = true; return document; -- cgit v1.2.3 From 6dfb9b4eade77ac55d11f05669c2192352b9b8fa Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Thu, 26 Jun 2014 13:49:17 -0400 Subject: 4. further refactor Application class; create proper singleton, encapsulate members, simplify signals (bzr r13341.5.6) --- src/document.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 26e59e610..000888772 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -463,15 +463,13 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, // reset undo key when selection changes, so that same-key actions on different objects are not coalesced document->priv->selChangeConnection = INKSCAPE->signal_selection_changed.connect( - sigc::hide( // hide unused first and second args sigc::hide(sigc::bind( sigc::ptr_fun(&DocumentUndo::resetKey), document) - ))); + )); document->priv->desktopActivatedConnection = INKSCAPE->signal_activate_desktop.connect( - sigc::hide( // hide unused first and second args sigc::hide(sigc::bind( sigc::ptr_fun(&DocumentUndo::resetKey), document) - ))); + )); document->oldSignalsConnected = true; return document; -- cgit v1.2.3 From 45f373f3319b598d8e0222fb48e9d3a4760b2044 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Fri, 27 Jun 2014 15:23:06 -0400 Subject: 5. Refactoring of Application class: make copy/assignment operators private, disallow pointers to Application (bzr r13341.5.9) --- src/document.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 000888772..c38cfa4ae 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -462,11 +462,11 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, DocumentUndo::setUndoSensitive(document, true); // reset undo key when selection changes, so that same-key actions on different objects are not coalesced - document->priv->selChangeConnection = INKSCAPE->signal_selection_changed.connect( + document->priv->selChangeConnection = INKSCAPE.signal_selection_changed.connect( sigc::hide(sigc::bind( sigc::ptr_fun(&DocumentUndo::resetKey), document) )); - document->priv->desktopActivatedConnection = INKSCAPE->signal_activate_desktop.connect( + document->priv->desktopActivatedConnection = INKSCAPE.signal_activate_desktop.connect( sigc::hide(sigc::bind( sigc::ptr_fun(&DocumentUndo::resetKey), document) )); -- cgit v1.2.3 From fa9bd6393f316dab9303569b28f6b5d179fedd61 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Sat, 27 Sep 2014 10:17:45 -0400 Subject: Update to experimental r13565 (bzr r13341.5.16) --- 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 c38cfa4ae..dd18186d4 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1373,7 +1373,7 @@ GSList *SPDocument::getItemsAtPoints(unsigned const key, std::vectorpriv != NULL, NULL); -- 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 From 970401eaa2de197733cadc350848dc5cd4c007a5 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 26 Nov 2014 20:23:03 +0100 Subject: Change default display unit to 'px'. (bzr r13773) --- 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 2625ef8fc..84ec1eda3 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -599,7 +599,7 @@ SPDocument *SPDocument::doUnref() Inkscape::Util::Unit const* SPDocument::getDefaultUnit() const { SPNamedView const* nv = sp_document_namedview(this, NULL); - return nv ? nv->getDefaultUnit() : unit_table.getUnit("pt"); + return nv ? nv->getDefaultUnit() : unit_table.getUnit("px"); } /// guaranteed not to return nullptr -- cgit v1.2.3 From c94cbdb38d7ac2f70a669035b090140eae3cc05b Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 26 Nov 2014 20:45:29 +0100 Subject: Change getDefaultUnit() to getDisplayUnit() to better reflect value returned by function. (bzr r13774) --- src/document.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 84ec1eda3..25afc1311 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -596,10 +596,10 @@ SPDocument *SPDocument::doUnref() } /// guaranteed not to return nullptr -Inkscape::Util::Unit const* SPDocument::getDefaultUnit() const +Inkscape::Util::Unit const* SPDocument::getDisplayUnit() const { SPNamedView const* nv = sp_document_namedview(this, NULL); - return nv ? nv->getDefaultUnit() : unit_table.getUnit("px"); + return nv ? nv->getDisplayUnit() : unit_table.getUnit("px"); } /// guaranteed not to return nullptr -- cgit v1.2.3 From 561b8791651a0b3f9d49dfd9809519f06039e0a4 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Fri, 28 Nov 2014 15:54:41 -0500 Subject: avoid recalculating viewbox if it is not necessary. (Bug 1384915, comment 24) Fixed bugs: - https://launchpad.net/bugs/1384915 (bzr r13776) --- src/document.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 25afc1311..c7d14727a 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -627,7 +627,7 @@ Inkscape::Util::Quantity SPDocument::getWidth() const return Inkscape::Util::Quantity(result, unit_table.getUnit(u)); } -void SPDocument::setWidth(const Inkscape::Util::Quantity &width) +void SPDocument::setWidth(const Inkscape::Util::Quantity &width, bool changeSize) { Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); if (root->width.unit) @@ -638,7 +638,7 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width) root->width.value = width.quantity; root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); - if (root->viewBox_set) + if (root->viewBox_set && changeSize) root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_converted) * root->viewBox.width(), root->viewBox.bottom())); root->updateRepr(); @@ -662,7 +662,7 @@ Inkscape::Util::Quantity SPDocument::getHeight() const return Inkscape::Util::Quantity(result, unit_table.getUnit(u)); } -void SPDocument::setHeight(const Inkscape::Util::Quantity &height) +void SPDocument::setHeight(const Inkscape::Util::Quantity &height, bool changeSize) { Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); if (root->height.unit) @@ -673,7 +673,7 @@ void SPDocument::setHeight(const Inkscape::Util::Quantity &height) root->height.value = height.quantity; root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); - if (root->viewBox_set) + if (root->viewBox_set && changeSize) root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_converted) * root->viewBox.height())); root->updateRepr(); -- cgit v1.2.3 From f8ba98f4439051bc268013a5aa0b0e2a97a45303 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 5 Jan 2015 10:35:44 +0100 Subject: Avoid calling root->updateRepr() twice when changing width and height. (bzr r13837) --- src/document.cpp | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index c7d14727a..4b074c2fa 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -610,6 +610,35 @@ Inkscape::Util::Unit const& SPDocument::getSVGUnit() const return nv ? nv->getSVGUnit() : *unit_table.getUnit("px"); } +// Avoid calling root->updateRepr() twice by combining setting width and height. +// (As done on every delete as clipboard calls this via fitToRect(). Also called in page-sizer.cpp) +void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Quantity &height, bool changeSize) +{ + Inkscape::Util::Unit const *old_width_units = unit_table.getUnit("px"); + if (root->width.unit) + old_width_units = unit_table.getUnit(root->width.unit); + gdouble old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); + + root->width.computed = width.value("px"); + root->width.value = width.quantity; + root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); + + Inkscape::Util::Unit const *old_height_units = unit_table.getUnit("px"); + if (root->height.unit) + old_height_units = unit_table.getUnit(root->height.unit); + gdouble old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); + + root->height.computed = height.value("px"); + root->height.value = height.quantity; + root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); + + if (root->viewBox_set && changeSize) + root->viewBox.setMax(Geom::Point( + root->viewBox.left() + (root->width.value / old_width_converted ) * root->viewBox.width(), + root->viewBox.top() + (root->height.value / old_height_converted) * root->viewBox.height())); + root->updateRepr(); +} + Inkscape::Util::Quantity SPDocument::getWidth() const { g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit(""))); @@ -739,9 +768,10 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) rect.min() - Geom::Point(margin_left, margin_bottom), rect.max() + Geom::Point(margin_right, margin_top)); - - setWidth(Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.width(), "px", nv_units), nv_units)); - setHeight(Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.height(), "px", nv_units), nv_units)); + setWidthAndHeight( + Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.width(), "px", nv_units), nv_units), + Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.height(), "px", nv_units), nv_units) + ); Geom::Translate const tr( Geom::Point(0, old_height - rect_with_margins.height()) -- cgit v1.2.3 From 5420b476f4668b03f4ce169494792c78b3a3235d Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 6 Jan 2015 13:37:55 +0100 Subject: Add getDocumentScale() to return "real-world" to "user-unit" scale factor. Use it to correct text postion after removing from path. (bzr r13843) --- src/document.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 4b074c2fa..2caefb4ed 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -604,12 +604,32 @@ Inkscape::Util::Unit const* SPDocument::getDisplayUnit() const /// guaranteed not to return nullptr // returns 'px' units as default, like legacy Inkscape +// THIS SHOULD NOT BE USED... INSTEAD USE DOCUMENT SCALE Inkscape::Util::Unit const& SPDocument::getSVGUnit() const { SPNamedView const* nv = sp_document_namedview(this, NULL); return nv ? nv->getSVGUnit() : *unit_table.getUnit("px"); } +/// Returns document scale as defined by width/height and viewBox (real world to user-units). +Geom::Scale SPDocument::getDocumentScale() const +{ + Geom::Scale scale; + if( root->viewBox_set ) { + double scale_x = 1.0; + double scale_y = 1.0; + if( root->viewBox.width() > 0.0 ) { + scale_x = root->width.computed / root->viewBox.width(); + } + if( root->viewBox.height() > 0.0 ) { + scale_y = root->height.computed / root->viewBox.height(); + } + scale = Geom::Scale(scale_x, scale_y); + } + // std::cout << "SPDocument::getDocumentScale():\n" << scale << std::endl; + return scale; +} + // Avoid calling root->updateRepr() twice by combining setting width and height. // (As done on every delete as clipboard calls this via fitToRect(). Also called in page-sizer.cpp) void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Quantity &height, bool changeSize) -- cgit v1.2.3 From 8d3047dd42fbe6ce43ee6d4c7bdf7abef024a0c2 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Mon, 9 Feb 2015 10:30:34 -0500 Subject: restore original behavior of 'Resize Page to Selection' for the special case where page size is in %. (Bug 1419122) Fixed bugs: - https://launchpad.net/bugs/1419122 (bzr r13912) --- src/document.cpp | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 2caefb4ed..11971e63d 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -637,7 +637,11 @@ void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Unit const *old_width_units = unit_table.getUnit("px"); if (root->width.unit) old_width_units = unit_table.getUnit(root->width.unit); - gdouble old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); + gdouble old_width_converted; // old width converted to new units + if (root->width.unit == SVGLength::PERCENT) + old_width_converted = Inkscape::Util::Quantity::convert(root->width.computed, "px", width.unit); + else + old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); root->width.computed = width.value("px"); root->width.value = width.quantity; @@ -646,7 +650,11 @@ void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Unit const *old_height_units = unit_table.getUnit("px"); if (root->height.unit) old_height_units = unit_table.getUnit(root->height.unit); - gdouble old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); + gdouble old_height_converted; // old height converted to new units + if (root->height.unit == SVGLength::PERCENT) + old_height_converted = Inkscape::Util::Quantity::convert(root->height.computed, "px", height.unit); + else + old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); root->height.computed = height.value("px"); root->height.value = height.quantity; @@ -678,17 +686,21 @@ Inkscape::Util::Quantity SPDocument::getWidth() const void SPDocument::setWidth(const Inkscape::Util::Quantity &width, bool changeSize) { - Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); + Inkscape::Util::Unit const *old_width_units = unit_table.getUnit("px"); 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); + old_width_units = unit_table.getUnit(root->width.unit); + gdouble old_width_converted; // old width converted to new units + if (root->width.unit == SVGLength::PERCENT) + old_width_converted = Inkscape::Util::Quantity::convert(root->width.computed, "px", width.unit); + else + old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); root->width.computed = width.value("px"); root->width.value = width.quantity; root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); if (root->viewBox_set && changeSize) - root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_converted) * root->viewBox.width(), root->viewBox.bottom())); + root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_width_converted) * root->viewBox.width(), root->viewBox.bottom())); root->updateRepr(); } @@ -713,17 +725,21 @@ Inkscape::Util::Quantity SPDocument::getHeight() const void SPDocument::setHeight(const Inkscape::Util::Quantity &height, bool changeSize) { - Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); + Inkscape::Util::Unit const *old_height_units = unit_table.getUnit("px"); 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); + old_height_units = unit_table.getUnit(root->height.unit); + gdouble old_height_converted; // old height converted to new units + if (root->height.unit == SVGLength::PERCENT) + old_height_converted = Inkscape::Util::Quantity::convert(root->height.computed, "px", height.unit); + else + old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); root->height.computed = height.value("px"); root->height.value = height.quantity; root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); if (root->viewBox_set && changeSize) - root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_converted) * root->viewBox.height())); + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_height_converted) * root->viewBox.height())); root->updateRepr(); } @@ -761,7 +777,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) double const old_height = getHeight().value("px"); Inkscape::Util::Unit const *nv_units = unit_table.getUnit("px"); - if (root->height.unit) + if (root->height.unit && (root->height.unit != SVGLength::PERCENT)) nv_units = unit_table.getUnit(root->height.unit); SPNamedView *nv = sp_document_namedview(this, NULL); -- cgit v1.2.3 From df7828a7a8ba0b7e6c2dd892ca5f0a62ef718bf0 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Tue, 24 Feb 2015 19:22:08 -0500 Subject: create SPObject factory (bzr r13939.1.1) --- 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 11971e63d..2a50d00bd 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -368,7 +368,7 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, // Create SPRoot element const std::string typeString = NodeTraits::get_type_string(*rroot); - SPObject* rootObj = SPFactory::instance().createObject(typeString); + SPObject* rootObj = SPFactory::createObject(typeString); document->root = dynamic_cast(rootObj); if (document->root == 0) { -- cgit v1.2.3 From e312688492eabdd9d4af9c6feadf3b1411f1541d Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 11 Mar 2015 15:01:37 +0100 Subject: Allow changing document scale (via changing viewBox). Start of GUI. (bzr r13994) --- src/document.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 2a50d00bd..62e2f5b46 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -611,7 +611,25 @@ Inkscape::Util::Unit const& SPDocument::getSVGUnit() const return nv ? nv->getSVGUnit() : *unit_table.getUnit("px"); } -/// Returns document scale as defined by width/height and viewBox (real world to user-units). +/// Sets document scale (by changing viewBox) +void SPDocument::setDocumentScale( double scaleX, double scaleY ) { + + root->viewBox = Geom::Rect::from_xywh( + root->viewBox.left(), + root->viewBox.top(), + root->width.computed * scaleX, + root->height.computed * scaleY ); + root->viewBox_set = true; + root->updateRepr(); +} + +/// Sets document scale (by changing viewBox, x and y scaling equal) +void SPDocument::setDocumentScale( double scale ) { + setDocumentScale( scale, scale ); +} + +/// Returns document scale as defined by width/height (in pixels) and viewBox (real world to +/// user-units). Geom::Scale SPDocument::getDocumentScale() const { Geom::Scale scale; @@ -660,10 +678,12 @@ void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const root->height.value = height.quantity; root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); - if (root->viewBox_set && changeSize) + // viewBox scaled by relative change in page size (maintains document scale). + if (root->viewBox_set && changeSize) { root->viewBox.setMax(Geom::Point( root->viewBox.left() + (root->width.value / old_width_converted ) * root->viewBox.width(), root->viewBox.top() + (root->height.value / old_height_converted) * root->viewBox.height())); + } root->updateRepr(); } -- cgit v1.2.3