From 8de8047c5e30af8598646d7a66c62dbf290f7c51 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 10 Apr 2013 16:10:04 +0200 Subject: Removed old SPObject factory. (bzr r11608.1.91) --- src/document.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 706710cfc..0a8b2e674 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -58,9 +58,9 @@ #include "preferences.h" #include "profile-manager.h" #include "rdf.h" +#include "sp-factory.h" #include "sp-item-group.h" #include "sp-namedview.h" -#include "sp-object-repr.h" #include "sp-symbol.h" #include "transf_mat_3x4.h" #include "unit-constants.h" @@ -348,7 +348,20 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, } document->name = g_strdup(name); - document->root = sp_object_repr_build_tree(document, rroot); + // Create SPRoot element + SPObject* rootObj = SPFactory::instance().createObject(*rroot); + document->root = dynamic_cast(rootObj); + + if (document->root == nullptr) { + // Node is not a valid root element + delete rootObj; + + // fixme: what to do here? + throw; + } + + // Recursively build object tree + document->root->invoke_build(document, rroot, false); /* fixme: Not sure about this, but lets assume ::build updates */ rroot->setAttribute("inkscape:version", Inkscape::version_string); -- cgit v1.2.3 From fbb85064cfaaf03cc09bacedb16a8561f61f2b3d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 13 Apr 2013 00:37:18 +0200 Subject: Added prefPaths to contexts; modified SPFactory (bzr r11608.1.94) --- src/document.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 0a8b2e674..e58f581b5 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -349,10 +349,11 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, document->name = g_strdup(name); // Create SPRoot element - SPObject* rootObj = SPFactory::instance().createObject(*rroot); + const std::string typeString = NodeTraits::getTypeString(*rroot); + SPObject* rootObj = SPFactory::instance().createObject(typeString); document->root = dynamic_cast(rootObj); - if (document->root == nullptr) { + if (document->root == 0) { // Node is not a valid root element delete rootObj; -- cgit v1.2.3 From bd77ef25e9161acb007323f851ba77e106036939 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Mon, 1 Jul 2013 23:40:52 -0400 Subject: Ported "ui/widget/page-sizer.cpp" and "document.cpp" to "Util::Unit" class. (bzr r12380.1.4) --- src/document.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 706710cfc..cc1c519fc 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -49,7 +49,6 @@ #include "display/drawing-item.h" #include "document-private.h" #include "document-undo.h" -#include "helper/units.h" #include "id-clash.h" #include "inkscape-private.h" #include "inkscape-version.h" @@ -87,6 +86,8 @@ static gint doc_count = 0; static unsigned long next_serial = 0; +static Inkscape::Util::UnitTable unit_table; + SPDocument::SPDocument() : keepalive(FALSE), virgin(TRUE), @@ -546,21 +547,22 @@ gdouble SPDocument::getWidth() const return result; } -void SPDocument::setWidth(gdouble width, const SPUnit *unit) +void SPDocument::setWidth(gdouble width, const Inkscape::Util::Unit *unit) { + Inkscape::Util::Unit px = unit_table.getUnit("px"); if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= - root->viewBox.setMax(Geom::Point(root->viewBox.left() + sp_units_get_pixels (width, *unit), root->viewBox.bottom())); + root->viewBox.setMax(Geom::Point(root->viewBox.left() + Inkscape::Util::Quantity::convert(width, unit, &px), root->viewBox.bottom())); } else { // set to width= gdouble old_computed = root->width.computed; - root->width.computed = sp_units_get_pixels (width, *unit); + root->width.computed = Inkscape::Util::Quantity::convert(width, unit, &px); /* SVG does not support meters as a unit, so we must translate meters to * cm when writing */ - if (!strcmp(unit->abbr, "m")) { + if (*unit == unit_table.getUnit("m")) { root->width.value = 100*width; root->width.unit = SVGLength::CM; } else { root->width.value = width; - root->width.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit); + root->width.unit = (SVGLength::Unit) unit->svgUnit(); } if (root->viewBox_set) @@ -582,21 +584,22 @@ gdouble SPDocument::getHeight() const return result; } -void SPDocument::setHeight(gdouble height, const SPUnit *unit) +void SPDocument::setHeight(gdouble height, const Inkscape::Util::Unit *unit) { + Inkscape::Util::Unit px = unit_table.getUnit("px"); if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= - root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + sp_units_get_pixels (height, *unit))); + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + Inkscape::Util::Quantity::convert(height, unit, &px))); } else { // set to height= gdouble old_computed = root->height.computed; - root->height.computed = sp_units_get_pixels (height, *unit); + root->height.computed = Inkscape::Util::Quantity::convert(height, unit, &px); /* SVG does not support meters as a unit, so we must translate meters to * cm when writing */ - if (!strcmp(unit->abbr, "m")) { + if (*unit == unit_table.getUnit("m")) { root->height.value = 100*height; root->height.unit = SVGLength::CM; } else { root->height.value = height; - root->height.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit); + root->height.unit = (SVGLength::Unit) unit->svgUnit(); } if (root->viewBox_set) @@ -626,7 +629,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) double const h = rect.height(); double const old_height = getHeight(); - SPUnit const &px(sp_unit_get_by_id(SP_UNIT_PX)); + Inkscape::Util::Unit const px = unit_table.getUnit("px"); /* in px */ double margin_top = 0.0; @@ -639,9 +642,10 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) if (with_margins && nv) { if (nv != NULL) { gchar const * const units_abbr = nv->getAttribute("units"); - SPUnit const *margin_units = NULL; + Inkscape::Util::Unit const *margin_units = NULL; if (units_abbr != NULL) { - margin_units = sp_unit_get_by_abbreviation(units_abbr); + Inkscape::Util::Unit mu = unit_table.getUnit(units_abbr); + margin_units = μ } if (margin_units == NULL) { margin_units = &px; -- cgit v1.2.3 From d04405f745da587b2a3ccca8d2ca7bf49edf2d4d Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 6 Jul 2013 11:01:59 -0400 Subject: Switch setWidth and setHeight to use Quantity and switch to forward declaration of Inkscape::Util::Quantity in document.h. (bzr r12380.1.7) --- src/document.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index cc1c519fc..ed3d8e21b 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -547,22 +547,23 @@ gdouble SPDocument::getWidth() const return result; } -void SPDocument::setWidth(gdouble width, const Inkscape::Util::Unit *unit) +void SPDocument::setWidth(const Inkscape::Util::Quantity &width) { Inkscape::Util::Unit px = unit_table.getUnit("px"); if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= - root->viewBox.setMax(Geom::Point(root->viewBox.left() + Inkscape::Util::Quantity::convert(width, unit, &px), root->viewBox.bottom())); + 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 = Inkscape::Util::Quantity::convert(width, unit, &px); + root->width.computed = width.value(&px); /* SVG does not support meters as a unit, so we must translate meters to * cm when writing */ - if (*unit == unit_table.getUnit("m")) { - root->width.value = 100*width; + if (*width.unit == unit_table.getUnit("m")) { + Inkscape::Util::Unit cm = unit_table.getUnit("cm"); + root->width.value = width.value(&cm); root->width.unit = SVGLength::CM; } else { - root->width.value = width; - root->width.unit = (SVGLength::Unit) unit->svgUnit(); + root->width.value = width.quantity; + root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); } if (root->viewBox_set) @@ -584,22 +585,23 @@ gdouble SPDocument::getHeight() const return result; } -void SPDocument::setHeight(gdouble height, const Inkscape::Util::Unit *unit) +void SPDocument::setHeight(const Inkscape::Util::Quantity &height) { Inkscape::Util::Unit px = unit_table.getUnit("px"); if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= - root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + Inkscape::Util::Quantity::convert(height, unit, &px))); + 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 = Inkscape::Util::Quantity::convert(height, unit, &px); + root->height.computed = height.value(&px); /* SVG does not support meters as a unit, so we must translate meters to * cm when writing */ - if (*unit == unit_table.getUnit("m")) { - root->height.value = 100*height; + if (*height.unit == unit_table.getUnit("m")) { + Inkscape::Util::Unit cm = unit_table.getUnit("cm"); + root->height.value = height.value(&cm); root->height.unit = SVGLength::CM; } else { - root->height.value = height; - root->height.unit = (SVGLength::Unit) unit->svgUnit(); + root->height.value = height.quantity; + root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); } if (root->viewBox_set) @@ -662,8 +664,8 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) rect.max() + Geom::Point(margin_right, margin_top)); - setWidth(rect_with_margins.width(), &px); - setHeight(rect_with_margins.height(), &px); + setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), &px)); + setHeight(Inkscape::Util::Quantity(rect_with_margins.height(), &px)); Geom::Translate const tr( Geom::Point(0, old_height - rect_with_margins.height()) -- cgit v1.2.3 From 3772fc428950b2b946a1bd7c7c97e06219c3165f Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 18 Jul 2013 17:21:24 -0400 Subject: Switch unit functions from using pointer arguements to reference arguements. (bzr r12380.1.28) --- src/document.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 78d7018bb..a024cc790 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -549,17 +549,15 @@ gdouble SPDocument::getWidth() const void SPDocument::setWidth(const Inkscape::Util::Quantity &width) { - Inkscape::Util::Unit px = unit_table.getUnit("px"); 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())); + 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); + 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")) { - Inkscape::Util::Unit cm = unit_table.getUnit("cm"); - root->width.value = width.value(&cm); + root->width.value = width.value("cm"); root->width.unit = SVGLength::CM; } else { root->width.value = width.quantity; @@ -587,17 +585,15 @@ gdouble SPDocument::getHeight() const void SPDocument::setHeight(const Inkscape::Util::Quantity &height) { - Inkscape::Util::Unit px = unit_table.getUnit("px"); 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))); + 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); + 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")) { - Inkscape::Util::Unit cm = unit_table.getUnit("cm"); - root->height.value = height.value(&cm); + root->height.value = height.value("cm"); root->height.unit = SVGLength::CM; } else { root->height.value = height.quantity; @@ -669,8 +665,8 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) rect.max() + Geom::Point(margin_right, margin_top)); - setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), &px)); - setHeight(Inkscape::Util::Quantity(rect_with_margins.height(), &px)); + setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), "px")); + setHeight(Inkscape::Util::Quantity(rect_with_margins.height(), "px")); Geom::Translate const tr( Geom::Point(0, old_height - rect_with_margins.height()) -- cgit v1.2.3 From f1cdb3b3f47c7187d9325e8ddd8e630268dc8e8b Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 31 Jul 2013 18:33:03 -0400 Subject: Eliminate "unit-constants.h". (bzr r12380.1.54) --- 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 a024cc790..afd0a6ddc 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -62,7 +62,7 @@ #include "sp-object-repr.h" #include "sp-symbol.h" #include "transf_mat_3x4.h" -#include "unit-constants.h" +#include "util/units.h" #include "xml/repr.h" #include "xml/rebase-hrefs.h" #include "libcroco/cr-cascade.h" @@ -966,7 +966,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 * PX_PER_MM, 297 * PX_PER_MM); + 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->i2vp = Geom::identity(); } -- cgit v1.2.3 From 6ae6c0bea96eef09907091279e0678aa5f83102d Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 4 Aug 2013 18:01:18 -0400 Subject: Switched to global UnitTable. (bzr r12380.1.62) --- src/document.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index afd0a6ddc..0b742e491 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -68,6 +68,7 @@ #include "libcroco/cr-cascade.h" using Inkscape::DocumentUndo; +using Inkscape::Util::unit_table; // Higher number means lower priority. #define SP_DOCUMENT_UPDATE_PRIORITY (G_PRIORITY_HIGH_IDLE - 2) @@ -86,8 +87,6 @@ static gint doc_count = 0; static unsigned long next_serial = 0; -static Inkscape::Util::UnitTable unit_table; - SPDocument::SPDocument() : keepalive(FALSE), virgin(TRUE), -- cgit v1.2.3 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 abde5067bcfbb4c0e3ba61c6f69db7925f80600a Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 16 Sep 2013 19:32:58 +0200 Subject: Removed TypeInfo; adjusted Factory to meet code style conventions. (bzr r11608.1.124) --- 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 65c4cb10a..ec831745c 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -349,7 +349,7 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, document->name = g_strdup(name); // Create SPRoot element - const std::string typeString = NodeTraits::getTypeString(*rroot); + const std::string typeString = NodeTraits::get_type_string(*rroot); SPObject* rootObj = SPFactory::instance().createObject(typeString); document->root = dynamic_cast(rootObj); -- 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 From ae4fb171df25c328e398d0cf1909a4cbad33a897 Mon Sep 17 00:00:00 2001 From: buliabyak <> Date: Sat, 28 Sep 2013 13:58:09 -0300 Subject: dying document needs to delete its perspective (bzr r12611) --- 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 800f2f33d..dda072283 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -219,6 +219,11 @@ SPDocument::~SPDocument() { inkscape_unref(); keepalive = FALSE; } + + if (this->current_persp3d_impl) + delete this->current_persp3d_impl; + this->current_persp3d_impl = NULL; + //delete this->_whiteboard_session_manager; } -- cgit v1.2.3 From ee8f0667f84689466f68eecfb9498e7b092e168b Mon Sep 17 00:00:00 2001 From: buliabyak <> Date: Sat, 28 Sep 2013 23:09:39 -0300 Subject: collectOrphans moved to the end of destructor to prevent leaking of uncollected stuff (bzr r12625) --- src/document.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index dda072283..b94b72bda 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -139,8 +139,6 @@ SPDocument::SPDocument() : } SPDocument::~SPDocument() { - collectOrphans(); - // kill/unhook this first if ( profileManager ) { delete profileManager; @@ -224,6 +222,9 @@ SPDocument::~SPDocument() { delete this->current_persp3d_impl; this->current_persp3d_impl = NULL; + // This is at the end of the destructor, because preceding code adds new orphans to the queue + collectOrphans(); + //delete this->_whiteboard_session_manager; } -- cgit v1.2.3 From a970dc423d59ea844bdb1af48d5d9419a5e2a287 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 13 Oct 2013 00:24:05 +0200 Subject: Units: stop newing Unit objects. pass around pointers to "undeletable" Unit objects in the UnitTable. I think we should move to using indexed units, and pass around the index of the unit in the unittable, or smth like that... ? (bzr r12679) --- src/document.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index b94b72bda..4f57cf080 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -556,8 +556,8 @@ SPDocument *SPDocument::doUnref() Inkscape::Util::Quantity SPDocument::getWidth() const { - 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())); + g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit(""))); + g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit(""))); gdouble result = root->width.value; SVGLength::Unit u = root->width.unit; @@ -577,7 +577,7 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width) 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")) { + if (*width.unit == *unit_table.getUnit("m")) { root->width.value = width.value("cm"); root->width.unit = SVGLength::CM; } else { @@ -593,8 +593,8 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width) Inkscape::Util::Quantity SPDocument::getHeight() const { - 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())); + g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit(""))); + g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit(""))); gdouble result = root->height.value; SVGLength::Unit u = root->height.unit; @@ -614,7 +614,7 @@ void SPDocument::setHeight(const Inkscape::Util::Quantity &height) 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")) { + if (*height.unit == *unit_table.getUnit("m")) { root->height.value = height.value("cm"); root->height.unit = SVGLength::CM; } else { @@ -660,7 +660,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) double const h = rect.height(); double const old_height = getHeight().value("px"); - Inkscape::Util::Unit const px = unit_table.getUnit("px"); + Inkscape::Util::Unit const *px = unit_table.getUnit("px"); /* in px */ double margin_top = 0.0; @@ -674,17 +674,16 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) if (nv != NULL) { gchar const * const units_abbr = nv->getAttribute("units"); Inkscape::Util::Unit const *margin_units = NULL; - if (units_abbr != NULL) { - Inkscape::Util::Unit mu = unit_table.getUnit(units_abbr); - margin_units = μ + if (units_abbr) { + margin_units = unit_table.getUnit(units_abbr); } - if (margin_units == NULL) { - margin_units = &px; + if (!margin_units) { + margin_units = px; } - margin_top = nv->getMarginLength("fit-margin-top",margin_units, &px, w, h, false); - margin_left = nv->getMarginLength("fit-margin-left",margin_units, &px, w, h, true); - margin_right = nv->getMarginLength("fit-margin-right",margin_units, &px, w, h, true); - margin_bottom = nv->getMarginLength("fit-margin-bottom",margin_units, &px, w, h, false); + margin_top = nv->getMarginLength("fit-margin-top",margin_units, px, w, h, false); + margin_left = nv->getMarginLength("fit-margin-left",margin_units, px, w, h, true); + margin_right = nv->getMarginLength("fit-margin-right",margin_units, px, w, h, true); + margin_bottom = nv->getMarginLength("fit-margin-bottom",margin_units, px, w, h, false); } } @@ -693,8 +692,8 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) rect.max() + Geom::Point(margin_right, margin_top)); - setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), "px")); - setHeight(Inkscape::Util::Quantity(rect_with_margins.height(), "px")); + setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), px)); + setHeight(Inkscape::Util::Quantity(rect_with_margins.height(), px)); Geom::Translate const tr( Geom::Point(0, old_height - rect_with_margins.height()) -- cgit v1.2.3