From 00937eed288b622e9ae70d0c4bf63606052db3cf Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 5 Oct 2017 15:39:49 +0300 Subject: Merge double assignment + eliminate trail space. --- src/sp-root.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 34047054a..f5e0a7eb9 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -355,9 +355,7 @@ Inkscape::XML::Node *SPRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::X Inkscape::DrawingItem *SPRoot::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { - Inkscape::DrawingItem *ai = 0; - - ai = SPGroup::show(drawing, key, flags); + Inkscape::DrawingItem *ai = SPGroup::show(drawing, key, flags); if (ai) { Inkscape::DrawingGroup *g = dynamic_cast(ai); @@ -366,10 +364,10 @@ Inkscape::DrawingItem *SPRoot::show(Inkscape::Drawing &drawing, unsigned int key // Uncomment to print out XML tree // getRepr()->recursivePrintTree(0); - + // Uncomment to print out SP Object tree // recursivePrintTree(0); - + // Uncomment to print out Display Item tree // ai->recursivePrintTree(0); -- cgit v1.2.3 From f7f5f977b7b7107eaf719bb27dd68b43e7b011a2 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 5 Oct 2017 16:03:19 +0300 Subject: Extract unset_x_and_y(). --- src/sp-root.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index f5e0a7eb9..fc35e26e9 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -40,8 +40,7 @@ SPRoot::SPRoot() : SPGroup(), SPViewBox() this->version.inkscape = zero_version; this->original.inkscape = zero_version; - this->x.unset(SVGLength::PERCENT, 0.0, 0.0); // Ignored for root SVG element - this->y.unset(SVGLength::PERCENT, 0.0, 0.0); + this->unset_x_and_y(); this->width.unset(SVGLength::PERCENT, 1.0, 1.0); this->height.unset(SVGLength::PERCENT, 1.0, 1.0); @@ -52,6 +51,12 @@ SPRoot::~SPRoot() { } +void SPRoot::unset_x_and_y() +{ + this->x.unset(SVGLength::PERCENT, 0.0, 0.0); // Ignored for root SVG element + this->y.unset(SVGLength::PERCENT, 0.0, 0.0); +} + void SPRoot::build(SPDocument *document, Inkscape::XML::Node *repr) { //XML Tree being used directly here while it shouldn't be. @@ -254,8 +259,7 @@ void SPRoot::update(SPCtx *ctx, guint flags) } // Ignore x, y values for root element - this->x.unset(SVGLength::PERCENT, 0.0, 0.0); - this->y.unset(SVGLength::PERCENT, 0.0, 0.0); + this->unset_x_and_y(); } // Calculate x, y, width, height from parent/initial viewport -- cgit v1.2.3 From 3207522f0f2597248f479075c395e9e9d589e181 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 5 Oct 2017 16:21:22 +0300 Subject: Extract SPRoot::setRootDimensions . --- src/sp-root.cpp | 82 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 39 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index fc35e26e9..d69f5300d 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -211,55 +211,59 @@ void SPRoot::remove_child(Inkscape::XML::Node *child) SPGroup::remove_child(child); } -void SPRoot::update(SPCtx *ctx, guint flags) +void SPRoot::setRootDimensions() { - SPItemCtx const *ictx = (SPItemCtx const *) ctx; - - if( !this->parent ) { + /* + * This is the root SVG element: + * + * x, y, width, and height apply to positioning the SVG element inside a parent. + * For the root SVG in Inkscape there is no parent, thus special rules apply: + * If width, height not set, width = 100%, height = 100% (as always). + * If width and height are in percent, they are percent of viewBox width/height. + * If width, height, and viewBox are not set... pick "random" width/height. + * x, y are ignored. + * initial viewport = (0 0 width height) + */ + if( this->viewBox_set ) { - /* - * This is the root SVG element: - * - * x, y, width, and height apply to positioning the SVG element inside a parent. - * For the root SVG in Inkscape there is no parent, thus special rules apply: - * If width, height not set, width = 100%, height = 100% (as always). - * If width and height are in percent, they are percent of viewBox width/height. - * If width, height, and viewBox are not set... pick "random" width/height. - * x, y are ignored. - * initial viewport = (0 0 width height) - */ - if( this->viewBox_set ) { - - if( this->width._set ) { - // Check if this is necessary - if (this->width.unit == SVGLength::PERCENT) { - this->width.computed = this->width.value * this->viewBox.width(); - } - } else { - this->width.set( SVGLength::PX, this->viewBox.width(), this->viewBox.width() ); + if( this->width._set ) { + // Check if this is necessary + if (this->width.unit == SVGLength::PERCENT) { + this->width.computed = this->width.value * this->viewBox.width(); } + } else { + this->width.set( SVGLength::PX, this->viewBox.width(), this->viewBox.width() ); + } - if( this->height._set ) { - if (this->height.unit == SVGLength::PERCENT) { - this->height.computed = this->height.value * this->viewBox.height(); - } - } else { - this->height.set(SVGLength::PX, this->viewBox.height(), this->viewBox.height() ); + if( this->height._set ) { + if (this->height.unit == SVGLength::PERCENT) { + this->height.computed = this->height.value * this->viewBox.height(); } - } else { + this->height.set(SVGLength::PX, this->viewBox.height(), this->viewBox.height() ); + } - if( !this->width._set ) { - this->width.set( SVGLength::PX, 100, 100 ); // Random default - } + } else { - if( !this->height._set ) { - this->height.set( SVGLength::PX, 100, 100 ); // Random default - } + if( !this->width._set ) { + this->width.set( SVGLength::PX, 100, 100 ); // Random default } - // Ignore x, y values for root element - this->unset_x_and_y(); + if( !this->height._set ) { + this->height.set( SVGLength::PX, 100, 100 ); // Random default + } + } + + // Ignore x, y values for root element + this->unset_x_and_y(); +} + +void SPRoot::update(SPCtx *ctx, guint flags) +{ + SPItemCtx const *ictx = (SPItemCtx const *) ctx; + + if( !this->parent ) { + this->setRootDimensions(); } // Calculate x, y, width, height from parent/initial viewport -- cgit v1.2.3 From 3eae8aa890673270d0907d55395ccaf5368cea37 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 5 Oct 2017 17:33:06 +0300 Subject: Extract a base class, SPDimensions. From two places getting rid of duplicate code. --- src/sp-root.cpp | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index d69f5300d..9ea1aa976 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -267,21 +267,7 @@ void SPRoot::update(SPCtx *ctx, guint flags) } // Calculate x, y, width, height from parent/initial viewport - if (this->x.unit == SVGLength::PERCENT) { - this->x.computed = this->x.value * ictx->viewport.width(); - } - - if (this->y.unit == SVGLength::PERCENT) { - this->y.computed = this->y.value * ictx->viewport.height(); - } - - if (this->width.unit == SVGLength::PERCENT) { - this->width.computed = this->width.value * ictx->viewport.width(); - } - - if (this->height.unit == SVGLength::PERCENT) { - this->height.computed = this->height.value * ictx->viewport.height(); - } + this->calcDimsFromParentViewport(ictx); // std::cout << "SPRoot::update: final:" // << " x: " << x.computed -- cgit v1.2.3 From d9c86888f170593390da648af3ba444acd177d54 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 24 Oct 2017 13:48:52 +0200 Subject: Give drawing a reasonable(?) default size if dimensions are in % and there is no view box. This prevents a GTK3 crash in file preview (#1611672). --- src/sp-root.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/sp-root.cpp') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 9ea1aa976..3f31588cc 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -245,12 +245,12 @@ void SPRoot::setRootDimensions() } else { - if( !this->width._set ) { - this->width.set( SVGLength::PX, 100, 100 ); // Random default + if( !this->width._set || this->width.unit == SVGLength::PERCENT) { + this->width.set( SVGLength::PX, 300, 300 ); // CSS/SVG default } - if( !this->height._set ) { - this->height.set( SVGLength::PX, 100, 100 ); // Random default + if( !this->height._set || this->height.unit == SVGLength::PERCENT) { + this->height.set( SVGLength::PX, 150, 150 ); // CSS/SVG default } } -- cgit v1.2.3