summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsu_v <suv-sf@users.sourceforge.net>2014-10-10 14:32:35 +0000
committer~suv <suv-sf@users.sourceforge.net>2014-10-10 14:32:35 +0000
commitcc1b3bd8508b4b4e53683ca7c0e339cc124c542c (patch)
treeaddb8720f096b078a47289f20658e5e977c0b6db
parentpackaging scripts: fix syntax (diff)
parentApply cx, cy, etc. from template to newly created document window. (diff)
downloadinkscape-cc1b3bd8508b4b4e53683ca7c0e339cc124c542c.tar.gz
inkscape-cc1b3bd8508b4b4e53683ca7c0e339cc124c542c.zip
update to trunk (r13586)
(bzr r13506.1.111)
-rw-r--r--share/extensions/empty_page.py77
-rw-r--r--share/extensions/setup_typography_canvas.inx10
-rwxr-xr-xshare/extensions/setup_typography_canvas.py7
-rw-r--r--src/extension/implementation/script.cpp144
-rw-r--r--src/ui/dialog/template-widget.cpp6
-rw-r--r--src/viewbox.cpp21
6 files changed, 157 insertions, 108 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()
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 @@
<id>org.inkscape.typography.setuptypographycanvas</id>
<dependency type="executable" location="extensions">inkex.py</dependency>
<dependency type="executable" location="extensions">setup_typography_canvas.py</dependency>
- <param name="emsize" type="int" _gui-text="Em-size:" min="10" max="2000">1000</param>
- <param name="ascender" type="int" _gui-text="Ascender:" min="0" max="2000">750</param>
- <param name="caps" type="int" _gui-text="Caps Height:" min="0" max="2000">700</param>
- <param name="xheight" type="int" _gui-text="X-Height:" min="0" max="2000">500</param>
- <param name="descender" type="int" _gui-text="Descender:" min="0" max="1000">250</param>
+ <param name="emsize" type="int" _gui-text="Em-size:" min="10" max="2048">1000</param>
+ <param name="ascender" type="int" _gui-text="Ascender:" min="0" max="2048">750</param>
+ <param name="caps" type="int" _gui-text="Caps Height:" min="0" max="2048">700</param>
+ <param name="xheight" type="int" _gui-text="X-Height:" min="0" max="2048">500</param>
+ <param name="descender" type="int" _gui-text="Descender:" min="0" max="1024">250</param>
<effect>
<object-type>all</object-type>
<effects-menu>
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()
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 <bryce@osdl.org>
* Ted Gould <ted@gould.cx>
* Jon A. Cruz <jon@joncruz.org>
* 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 <config.h>
-#endif
-
-#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
-#include <glibmm/threads.h>
-#endif
-
+#include <glibmm.h>
#include <gtkmm/messagedialog.h>
#include <gtkmm/main.h>
#include <gtkmm/scrolledwindow.h>
@@ -32,44 +22,38 @@
#include <unistd.h>
#include <errno.h>
-#include <glib.h>
#include <glib/gstdio.h>
-#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 <windows.h>
#include <sys/stat.h>
#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<Inkscape::XML::Node *> 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<gchar const *> attribs;
+ std::vector<gchar const *> attribs;
- // Make a list of all attributes of the old root node.
- for (List<AttributeRecord const> 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<gchar const *>::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<AttributeRecord const> iter = oldroot->attributeList(); iter; ++iter) {
+ attribs.push_back(g_quark_to_string(iter->key));
+ }
- // Set the new attributes.
- for (List<AttributeRecord const> 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<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); ++it) {
+ oldroot->setAttribute(*it, NULL);
+ }
+
+ // Set the new attributes.
+ for (List<AttributeRecord const> 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<AttributeRecord const> 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<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); ++it) {
+ oldroot_namedview->setAttribute(*it, NULL);
+ }
+
+ // Set the new attributes.
+ for (List<AttributeRecord const> 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<std::string> &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 :
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();
}
diff --git a/src/viewbox.cpp b/src/viewbox.cpp
index f59909abc..662b05686 100644
--- a/src/viewbox.cpp
+++ b/src/viewbox.cpp
@@ -164,16 +164,17 @@ 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();
+ /* These are floats since SVGLength is a float: See bug 1374614 */
+ 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 +218,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;