From c62bc930f1e85d3ab19fb474653ad2db9a41eca5 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Wed, 8 Oct 2014 13:05:26 -0400 Subject: avoid round-off error when calculating viewbox transform c2p (Bug 1374614 and Bug 1235279) Fixed bugs: - https://launchpad.net/bugs/1374614 (bzr r13581) --- src/viewbox.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/viewbox.cpp b/src/viewbox.cpp index f59909abc..6d677d57d 100644 --- a/src/viewbox.cpp +++ b/src/viewbox.cpp @@ -164,16 +164,16 @@ void SPViewBox::set_preserveAspectRatio(const gchar* value) { void SPViewBox::apply_viewbox(const Geom::Rect& in) { /* Determine actual viewbox in viewport coordinates */ - double x = 0.0; - double y = 0.0; - double width = in.width(); - double height = in.height(); + float x = 0.0; + float y = 0.0; + float width = in.width(); + float height = in.height(); // std::cout << " width: " << width << " height: " << height << std::endl; if (this->aspect_align != SP_ASPECT_NONE) { /* Things are getting interesting */ - double scalex = in.width() / this->viewBox.width(); - double scaley = in.height() / this->viewBox.height(); + double scalex = in.width() / ((float) this->viewBox.width()); + double scaley = in.height() / ((float) this->viewBox.height()); double scale = (this->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley); width = this->viewBox.width() * scale; height = this->viewBox.height() * scale; @@ -217,12 +217,12 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in) { /* Viewbox transform from scale and position */ Geom::Affine q; - q[0] = width / this->viewBox.width(); + q[0] = width / ((float) this->viewBox.width()); q[1] = 0.0; q[2] = 0.0; - q[3] = height / this->viewBox.height(); - q[4] = x - q[0] * this->viewBox.left(); - q[5] = y - q[3] * this->viewBox.top(); + q[3] = height / ((float) this->viewBox.height()); + q[4] = x - q[0] * ((float) this->viewBox.left()); + q[5] = y - q[3] * ((float) this->viewBox.top()); // std::cout << " q\n" << q << std::endl; -- cgit v1.2.3 From 0dc05429417f53ea871f40505f65de97480d71a3 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 9 Oct 2014 11:06:21 +0200 Subject: Add comment. (bzr r13582) --- src/viewbox.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/viewbox.cpp b/src/viewbox.cpp index 6d677d57d..662b05686 100644 --- a/src/viewbox.cpp +++ b/src/viewbox.cpp @@ -164,6 +164,7 @@ void SPViewBox::set_preserveAspectRatio(const gchar* value) { void SPViewBox::apply_viewbox(const Geom::Rect& in) { /* Determine actual viewbox in viewport coordinates */ + /* These are floats since SVGLength is a float: See bug 1374614 */ float x = 0.0; float y = 0.0; float width = in.width(); -- cgit v1.2.3 From 7245058959fe4437b76b481e8ee32ceeaee78a38 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 9 Oct 2014 11:10:01 +0200 Subject: Allow attributes to be set by scripts. (bzr r13583) --- src/extension/implementation/script.cpp | 144 ++++++++++++++++++-------------- 1 file changed, 82 insertions(+), 62 deletions(-) diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index f0fd3711b..f9241b1b7 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -1,28 +1,18 @@ -/** \file - * Code for handling extensions (i.e.\ scripts). - */ -/* +/** + * Code for handling extensions (i.e. scripts). + * * Authors: * Bryce Harrington * Ted Gould * Jon A. Cruz * Abhishek Sharma * - * Copyright (C) 2002-2005,2007 Authors + * Copyright (C) 2002-2007 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ -#define __INKSCAPE_EXTENSION_IMPLEMENTATION_SCRIPT_C__ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H -#include -#endif - +#include #include #include #include @@ -32,44 +22,38 @@ #include #include -#include #include -#include "ui/view/view.h" #include "desktop-handles.h" #include "desktop.h" -#include "selection.h" -#include "sp-namedview.h" -#include "io/sys.h" -#include "preferences.h" -#include "../system.h" +#include "dialogs/dialog-events.h" #include "extension/effect.h" #include "extension/output.h" #include "extension/input.h" #include "extension/db.h" -#include "script.h" -#include "dialogs/dialog-events.h" #include "inkscape.h" +#include "io/sys.h" +#include "preferences.h" +#include "script.h" +#include "selection.h" +#include "sp-namedview.h" +#include "extension/system.h" +#include "ui/view/view.h" #include "xml/node.h" #include "xml/attribute-record.h" #include "util/glib-list-iterators.h" #include "path-prefix.h" - #ifdef WIN32 #include #include #include "registrytool.h" #endif - - /** This is the command buffer that gets allocated from the stack */ #define BUFSIZE (255) - - /* Namespaces */ namespace Inkscape { namespace Extension { @@ -742,12 +726,12 @@ void Script::effect(Inkscape::Extension::Effect *module, vd->emitReconstructionStart(); copy_doc(vd->rroot, mydoc->rroot); vd->emitReconstructionFinish(); - SPObject *layer = NULL; - + // Getting the named view from the document generated by the extension SPNamedView *nv = sp_document_namedview(mydoc, NULL); //Check if it has a default layer set up + SPObject *layer = NULL; if ( nv != NULL) { if( nv->default_layer_id != 0 ) { @@ -776,19 +760,21 @@ void Script::effect(Inkscape::Extension::Effect *module, /** - \brief A function to take all the svg elements from one document - and put them in another. - \param oldroot The root node of the document to be replaced - \param newroot The root node of the document to replace it with - - This function first deletes all of the data in the old document. It - does this by creating a list of what needs to be deleted, and then - goes through the list. This two pass approach removes issues with - the list being change while parsing through it. Lots of nasty bugs. - - Then, it goes through the new document, duplicating all of the - elements and putting them into the old document. The copy - is then complete. + \brief A function to replace all the elements in an old document + by those from a new document. + document and repinserts them into an emptied old document. + \param oldroot The root node of the old (destination) document. + \param newroot The root node of the new (source) document. + + This function first deletes all the elements in the old document by + making two pass, the first to create a list of the old elements and + the second to actually delete them. This two pass approach removes issues + with the list being change while parsing through it... lots of nasty bugs. + + Then, it copies all the element in the new document into the old document. + + Finally, it replaces the attributes in the root element of the old document + by the attributes in root of the new document. */ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newroot) { @@ -797,9 +783,21 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr g_warning("Error on copy_doc: NULL pointer input."); return; } + + // For copying attributes in root and in namedview + using Inkscape::Util::List; + using Inkscape::XML::AttributeRecord; + + // Question: Why is the "sodipodi:namedview" special? Treating it as a normal + // elmement results in crashes. + // Seems to be a bug: + // http://inkscape.13.x6.nabble.com/Effect-that-modifies-the-document-properties-tt2822126.html + std::vector delete_list; Inkscape::XML::Node * oldroot_namedview = NULL; + Inkscape::XML::Node * newroot_namedview = NULL; + // Make list for (Inkscape::XML::Node * child = oldroot->firstChild(); child != NULL; child = child->next()) { @@ -814,14 +812,18 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr delete_list.push_back(child); } } + + // Unparent (delete) for (unsigned int i = 0; i < delete_list.size(); i++) { sp_repr_unparent(delete_list[i]); } + // Copy for (Inkscape::XML::Node * child = newroot->firstChild(); child != NULL; child = child->next()) { if (!strcmp("sodipodi:namedview", child->name())) { + newroot_namedview = child; if (oldroot_namedview != NULL) { for (Inkscape::XML::Node * newroot_namedview_child = child->firstChild(); newroot_namedview_child != NULL; @@ -834,26 +836,44 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr } } - { - using Inkscape::Util::List; - using Inkscape::XML::AttributeRecord; - std::vector attribs; + std::vector attribs; - // Make a list of all attributes of the old root node. - for (List iter = oldroot->attributeList(); iter; ++iter) { - attribs.push_back(g_quark_to_string(iter->key)); - } + // Must explicitly copy root attributes. - // Delete the attributes of the old root nodes. - for (std::vector::const_iterator it = attribs.begin(); it != attribs.end(); ++it) { - oldroot->setAttribute(*it, NULL); - } + // Make a list of all attributes of the old root node. + for (List iter = oldroot->attributeList(); iter; ++iter) { + attribs.push_back(g_quark_to_string(iter->key)); + } - // Set the new attributes. - for (List iter = newroot->attributeList(); iter; ++iter) { - gchar const *name = g_quark_to_string(iter->key); - oldroot->setAttribute(name, newroot->attribute(name)); - } + // Delete the attributes of the old root node. + for (std::vector::const_iterator it = attribs.begin(); it != attribs.end(); ++it) { + oldroot->setAttribute(*it, NULL); + } + + // Set the new attributes. + for (List iter = newroot->attributeList(); iter; ++iter) { + gchar const *name = g_quark_to_string(iter->key); + oldroot->setAttribute(name, newroot->attribute(name)); + } + + attribs.clear(); + + // Must explicitly copy namedview attributes. + + // Make a list of all attributes of the old namedview node. + for (List iter = oldroot_namedview->attributeList(); iter; ++iter) { + attribs.push_back(g_quark_to_string(iter->key)); + } + + // Delete the attributes of the old namedview node. + for (std::vector::const_iterator it = attribs.begin(); it != attribs.end(); ++it) { + oldroot_namedview->setAttribute(*it, NULL); + } + + // Set the new attributes. + for (List iter = newroot_namedview->attributeList(); iter; ++iter) { + gchar const *name = g_quark_to_string(iter->key); + oldroot_namedview->setAttribute(name, newroot_namedview->attribute(name)); } /** \todo Restore correct layer */ @@ -1063,4 +1083,4 @@ int Script::execute (const std::list &in_command, fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 : -- cgit v1.2.3 From e78edc8f66d94a44d0cb4e4c9db9a14690ef10b9 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 9 Oct 2014 11:21:47 +0200 Subject: Fix 'viewBox' and 'inkscape:document-units', add 'inkscape:cx' and 'inkscape:cy'. (bzr r13584) --- share/extensions/empty_page.py | 77 ++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/share/extensions/empty_page.py b/share/extensions/empty_page.py index dc16bab97..34dee7fc4 100644 --- a/share/extensions/empty_page.py +++ b/share/extensions/empty_page.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +# Rewritten by Tavmjong Bah to add correct viewBox, inkscape:cx, etc. attributes + import inkex class C(inkex.Effect): @@ -8,37 +10,52 @@ class C(inkex.Effect): self.OptionParser.add_option("-s", "--size", action="store", type="string", dest="page_size", default="a4", help="Page size") self.OptionParser.add_option("-o", "--orientation", action="store", type="string", dest="page_orientation", default="vertical", help="Page orientation") - def effect(self): + def effect(self): + + width = 300 + height = 300 + units = 'px' + + if self.options.page_size == "a5": + width = 148 + height= 210 + units = 'mm' + + if self.options.page_size == "a4": + width = 210 + height= 297 + units = 'mm' + + if self.options.page_size == "a3": + width = 297 + height= 420 + units = 'mm' + + if self.options.page_size == "letter": + width = 8.5 + height = 11 + units = 'in' + + if self.options.page_orientation == "horizontal": + width, height = height, width + + root = self.document.getroot() - root.set("width", "12in") - root.set("height", "12in") - if self.options.page_size == "a4" and self.options.page_orientation == "vertical": - root.set("width", "210mm") - root.set("height", "297mm") - if self.options.page_size == "a4" and self.options.page_orientation == "horizontal": - root.set("height", "210mm") - root.set("width", "297mm") - - if self.options.page_size == "a5" and self.options.page_orientation == "vertical": - root.set("width", "148mm") - root.set("height", "210mm") - if self.options.page_size == "a5" and self.options.page_orientation == "horizontal": - root.set("width", "210mm") - root.set("height", "148mm") - - if self.options.page_size == "a3" and self.options.page_orientation == "vertical": - root.set("width", "297mm") - root.set("height", "420mm") - if self.options.page_size == "a3" and self.options.page_orientation == "horizontal": - root.set("width", "420mm") - root.set("height", "297mm") - - if self.options.page_size == "letter" and self.options.page_orientation == "vertical": - root.set("width", "8.5in") - root.set("height", "11in") - if self.options.page_size == "letter" and self.options.page_orientation == "horizontal": - root.set("width", "11in") - root.set("height", "8.5in") + root.set("id", "SVGRoot") + root.set("width", str(width) + units) + root.set("height", str(height) + units) + root.set("viewBox", "0 0 " + str(width) + " " + str(height) ) + + namedview = root.find(inkex.addNS('namedview', 'sodipodi')) + if namedview is None: + namedview = inkex.etree.SubElement( root, inkex.addNS('namedview', 'sodipodi') ); + + namedview.set(inkex.addNS('document-units', 'inkscape'), units) + + # Until units are supported in 'cx', etc. + namedview.set(inkex.addNS('cx', 'inkscape'), str(self.uutounit( width, 'px' )/2.0 ) ) + namedview.set(inkex.addNS('cy', 'inkscape'), str(self.uutounit( height, 'px' )/2.0 ) ) + c = C() c.affect() -- cgit v1.2.3 From 19bb109f2149cc856f8d87b49b230f161a8880b3 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 9 Oct 2014 11:25:39 +0200 Subject: Add proper 'viewBox', set 'inkscape:document-units', set maximum em-size to 2048 as is typical in TrueType. (bzr r13585) --- share/extensions/setup_typography_canvas.inx | 10 +++++----- share/extensions/setup_typography_canvas.py | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/share/extensions/setup_typography_canvas.inx b/share/extensions/setup_typography_canvas.inx index 332a14ade..8e7739b5c 100644 --- a/share/extensions/setup_typography_canvas.inx +++ b/share/extensions/setup_typography_canvas.inx @@ -4,11 +4,11 @@ org.inkscape.typography.setuptypographycanvas inkex.py setup_typography_canvas.py - 1000 - 750 - 700 - 500 - 250 + 1000 + 750 + 700 + 500 + 250 all diff --git a/share/extensions/setup_typography_canvas.py b/share/extensions/setup_typography_canvas.py index 197aeb77e..a1000f2d1 100755 --- a/share/extensions/setup_typography_canvas.py +++ b/share/extensions/setup_typography_canvas.py @@ -69,6 +69,7 @@ class SetupTypographyCanvas(inkex.Effect): self.svg = self.document.getroot() self.svg.set("width", str(emsize)) self.svg.set("height", str(emsize)) + self.svg.set("viewBox", "0 0 " + str(emsize) + " " + str(emsize) ) baseline = descender # Create guidelines @@ -78,6 +79,12 @@ class SetupTypographyCanvas(inkex.Effect): self.create_horizontal_guideline("xheight", baseline+xheight) self.create_horizontal_guideline("descender", baseline-descender) + namedview = self.svg.find(inkex.addNS('namedview', 'sodipodi')) + namedview.set(inkex.addNS('document-units', 'inkscape'), 'px') + namedview.set(inkex.addNS('cx', 'inkscape'), str(emsize/2.0 )) + namedview.set(inkex.addNS('cy', 'inkscape'), str(emsize/2.0 )) + + if __name__ == '__main__': e = SetupTypographyCanvas() e.affect() -- cgit v1.2.3 From 01a8acb49126aa37fee65b3e350ce69e87abecc8 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 9 Oct 2014 14:32:16 +0200 Subject: Apply cx, cy, etc. from template to newly created document window. (bzr r13586) --- src/ui/dialog/template-widget.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ui/dialog/template-widget.cpp b/src/ui/dialog/template-widget.cpp index 9758b35ac..f79d166f2 100644 --- a/src/ui/dialog/template-widget.cpp +++ b/src/ui/dialog/template-widget.cpp @@ -24,6 +24,7 @@ #include "document.h" #include "document-undo.h" #include "file.h" +#include "sp-namedview.h" #include "extension/implementation/implementation.h" #include "inkscape.h" @@ -69,7 +70,10 @@ void TemplateWidget::create() _current_template.tpl_effect->effect(desc); DocumentUndo::clearUndo(sp_desktop_document(desc)); sp_desktop_document(desc)->setModifiedSinceSave(false); - + + // Apply cx,cy etc. from document + sp_namedview_window_from_document( desc ); + if (desktop) desktop->clearWaitingCursor(); } -- cgit v1.2.3