Commits

Dinu Gherman committed e3aaa27

Initial checkin of version 0.6.3.

Comments (0)

Files changed (27)

+		   GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+  This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+  0. Additional Definitions.
+
+  As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+  "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+  An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+  A "Combined Work" is a work produced by combining or linking an
+Application with the Library.  The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+  The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+  The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+  1. Exception to Section 3 of the GNU GPL.
+
+  You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+  2. Conveying Modified Versions.
+
+  If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+   a) under this License, provided that you make a good faith effort to
+   ensure that, in the event an Application does not supply the
+   function or data, the facility still operates, and performs
+   whatever part of its purpose remains meaningful, or
+
+   b) under the GNU GPL, with none of the additional permissions of
+   this License applicable to that copy.
+
+  3. Object Code Incorporating Material from Library Header Files.
+
+  The object code form of an Application may incorporate material from
+a header file that is part of the Library.  You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+   a) Give prominent notice with each copy of the object code that the
+   Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the object code with a copy of the GNU GPL and this license
+   document.
+
+  4. Combined Works.
+
+  You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+   a) Give prominent notice with each copy of the Combined Work that
+   the Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the Combined Work with a copy of the GNU GPL and this license
+   document.
+
+   c) For a Combined Work that displays copyright notices during
+   execution, include the copyright notice for the Library among
+   these notices, as well as a reference directing the user to the
+   copies of the GNU GPL and this license document.
+
+   d) Do one of the following:
+
+       0) Convey the Minimal Corresponding Source under the terms of this
+       License, and the Corresponding Application Code in a form
+       suitable for, and under terms that permit, the user to
+       recombine or relink the Application with a modified version of
+       the Linked Version to produce a modified Combined Work, in the
+       manner specified by section 6 of the GNU GPL for conveying
+       Corresponding Source.
+
+       1) Use a suitable shared library mechanism for linking with the
+       Library.  A suitable mechanism is one that (a) uses at run time
+       a copy of the Library already present on the user's computer
+       system, and (b) will operate properly with a modified version
+       of the Library that is interface-compatible with the Linked
+       Version.
+
+   e) Provide Installation Information, but only if you would otherwise
+   be required to provide such information under section 6 of the
+   GNU GPL, and only to the extent that such information is
+   necessary to install and execute a modified version of the
+   Combined Work produced by recombining or relinking the
+   Application with a modified version of the Linked Version. (If
+   you use option 4d0, the Installation Information must accompany
+   the Minimal Corresponding Source and Corresponding Application
+   Code. If you use option 4d1, you must provide the Installation
+   Information in the manner specified by section 6 of the GNU GPL
+   for conveying Corresponding Source.)
+
+  5. Combined Libraries.
+
+  You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+   a) Accompany the combined library with a copy of the same work based
+   on the Library, uncombined with any other library facilities,
+   conveyed under the terms of this License.
+
+   b) Give prominent notice with the combined library that part of it
+   is a work based on the Library, and explaining where to find the
+   accompanying uncombined form of the same work.
+
+  6. Revised Versions of the GNU Lesser General Public License.
+
+  The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+  Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+  If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+include ez_setup.py
+include metainfo.py
+include setup.py
+include MANIFEST.in
+include LICENSE.txt
+include README.txt, README.html
+include src/test/*.py
+include src/test/*.txt
+include src/test/samples/wikipedia/README.txt
+include src/test/samples/misc/*.svg
+Metadata-Version: 1.0
+Name: svglib
+Version: 0.6.3
+Summary: An experimental library for reading and converting SVG.
+Home-page: http://www.dinu-gherman.net/
+Author: Dinu Gherman
+Author-email: gherman@darwin.in-berlin.de
+License: LGPL 3
+Download-URL: http://www.dinu-gherman.net/tmp/svglib-0.6.3.tar.gz
+Description: `Svglib` is an experimental library for reading `SVG
+        <http://www.w3.org/Graphics/SVG/>`_ files and converting them (to a
+        reasonable degree) to other formats using the Open Source `ReportLab
+        Toolkit <http://www.reportlab.org>`_. As a package it reads existing
+        SVG files and returns them converted to ReportLab Drawing objects that
+        can be used in a variety of ReportLab-related contexts, e.g. as Platypus
+        Flowable objects or in RML2PDF. As a command-line tool it converts SVG
+        files into PDF ones.
+        
+        Tests include a vast amount of tests from the `W3C SVG test suite
+        <http://www.w3.org/Graphics/SVG/WG/wiki/Test_Suite_Overview>`_.
+        It also accesses around `200 flags from Wikipedia.org
+        <http://en.wikipedia.org/wiki/Gallery_of_sovereign_state_flags>`_
+        for test purposes (some of them hinting at more work to be done).
+        
+        This release changes the license from GPL 3 to LGPL 3, introduces
+        tiny bug fix reported by Harald Armin Massa and adapts to changed
+        URLs for Wikipedia SVG flags used for test purposes.
+        
+        
+        Features
+        ++++++++
+        
+        - convert SVG files into ReportLab Graphics Drawing objects
+        - handle plain or compressed SVG files (.svg and .svgz)
+        - allow patterns for output files on command-line
+        - install a Python package named ``svglib``
+        - install a Python command-line script named ``svg2pdf``
+        - provide a Unittest test suite
+        - test on some standard W3C SVG tests available online
+        - test on some Wikipedia sample SVG symbols available online
+        - test on some Wikipedia sample SVG flags available online
+        
+        
+        Examples
+        ++++++++
+        
+        You can use `svglib` as a Python package e.g. like in the following
+        interactive Python session::
+        
+        >>> from svglib.svglib import svg2rlg
+        >>> from reportlab.graphics import renderPDF
+        >>>
+        >>> drawing = svg2rlg("file.svg")
+        >>> renderPDF.drawToFile(drawing, "file.pdf")
+        
+        In addition a script named ``svg2pdf`` can be used more easily from
+        the system command-line like this (you can see more examples when
+        typing ``svg2pdf -h``)::
+        
+        $ svg2pdf file1.svg file2.svgz
+        $ svg2pdf -o "%(basename)s.pdf" /path/file[12].svgz?
+        
+Keywords: svg,reportlab,PDF
+Platform: Posix
+Platform: Windows
+Classifier: Development Status :: 4 - Beta
+Classifier: Environment :: Console
+Classifier: Intended Audience :: End Users/Desktop
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: GNU General Public License (GPL)
+Classifier: Operating System :: MacOS :: MacOS X
+Classifier: Operating System :: POSIX
+Classifier: Operating System :: Microsoft :: Windows
+Classifier: Natural Language :: English
+Classifier: Programming Language :: Python
+Classifier: Topic :: Documentation
+Classifier: Topic :: Utilities
+Classifier: Topic :: Printing
+Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
+Classifier: Topic :: Text Processing :: Markup :: XML
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
+<title>Svglib</title>
+<meta name="author" content="Dinu Gherman &lt;gherman&#64;darwin.in-berlin.de&gt;" />
+<meta name="date" content="2010-03-01" />
+<meta name="copyright" content="GNU Lesser General Public Licence v3 (LGPLv3)" />
+<style type="text/css">
+
+/*
+:Author: David Goodger (goodger@python.org)
+:Id: $Id: html4css1.css 5196 2007-06-03 20:25:28Z wiemann $
+:Copyright: This stylesheet has been placed in the public domain.
+
+Default cascading style sheet for the HTML output of Docutils.
+
+See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
+customize this style sheet.
+*/
+
+/* used to remove borders from tables and images */
+.borderless, table.borderless td, table.borderless th {
+  border: 0 }
+
+table.borderless td, table.borderless th {
+  /* Override padding for "table.docutils td" with "! important".
+     The right padding separates the table cells. */
+  padding: 0 0.5em 0 0 ! important }
+
+.first {
+  /* Override more specific margin styles with "! important". */
+  margin-top: 0 ! important }
+
+.last, .with-subtitle {
+  margin-bottom: 0 ! important }
+
+.hidden {
+  display: none }
+
+a.toc-backref {
+  text-decoration: none ;
+  color: black }
+
+blockquote.epigraph {
+  margin: 2em 5em ; }
+
+dl.docutils dd {
+  margin-bottom: 0.5em }
+
+/* Uncomment (and remove this text!) to get bold-faced definition list terms
+dl.docutils dt {
+  font-weight: bold }
+*/
+
+div.abstract {
+  margin: 2em 5em }
+
+div.abstract p.topic-title {
+  font-weight: bold ;
+  text-align: center }
+
+div.admonition, div.attention, div.caution, div.danger, div.error,
+div.hint, div.important, div.note, div.tip, div.warning {
+  margin: 2em ;
+  border: medium outset ;
+  padding: 1em }
+
+div.admonition p.admonition-title, div.hint p.admonition-title,
+div.important p.admonition-title, div.note p.admonition-title,
+div.tip p.admonition-title {
+  font-weight: bold ;
+  font-family: sans-serif }
+
+div.attention p.admonition-title, div.caution p.admonition-title,
+div.danger p.admonition-title, div.error p.admonition-title,
+div.warning p.admonition-title {
+  color: red ;
+  font-weight: bold ;
+  font-family: sans-serif }
+
+/* Uncomment (and remove this text!) to get reduced vertical space in
+   compound paragraphs.
+div.compound .compound-first, div.compound .compound-middle {
+  margin-bottom: 0.5em }
+
+div.compound .compound-last, div.compound .compound-middle {
+  margin-top: 0.5em }
+*/
+
+div.dedication {
+  margin: 2em 5em ;
+  text-align: center ;
+  font-style: italic }
+
+div.dedication p.topic-title {
+  font-weight: bold ;
+  font-style: normal }
+
+div.figure {
+  margin-left: 2em ;
+  margin-right: 2em }
+
+div.footer, div.header {
+  clear: both;
+  font-size: smaller }
+
+div.line-block {
+  display: block ;
+  margin-top: 1em ;
+  margin-bottom: 1em }
+
+div.line-block div.line-block {
+  margin-top: 0 ;
+  margin-bottom: 0 ;
+  margin-left: 1.5em }
+
+div.sidebar {
+  margin: 0 0 0.5em 1em ;
+  border: medium outset ;
+  padding: 1em ;
+  background-color: #ffffee ;
+  width: 40% ;
+  float: right ;
+  clear: right }
+
+div.sidebar p.rubric {
+  font-family: sans-serif ;
+  font-size: medium }
+
+div.system-messages {
+  margin: 5em }
+
+div.system-messages h1 {
+  color: red }
+
+div.system-message {
+  border: medium outset ;
+  padding: 1em }
+
+div.system-message p.system-message-title {
+  color: red ;
+  font-weight: bold }
+
+div.topic {
+  margin: 2em }
+
+h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
+h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
+  margin-top: 0.4em }
+
+h1.title {
+  text-align: center }
+
+h2.subtitle {
+  text-align: center }
+
+hr.docutils {
+  width: 75% }
+
+img.align-left {
+  clear: left }
+
+img.align-right {
+  clear: right }
+
+ol.simple, ul.simple {
+  margin-bottom: 1em }
+
+ol.arabic {
+  list-style: decimal }
+
+ol.loweralpha {
+  list-style: lower-alpha }
+
+ol.upperalpha {
+  list-style: upper-alpha }
+
+ol.lowerroman {
+  list-style: lower-roman }
+
+ol.upperroman {
+  list-style: upper-roman }
+
+p.attribution {
+  text-align: right ;
+  margin-left: 50% }
+
+p.caption {
+  font-style: italic }
+
+p.credits {
+  font-style: italic ;
+  font-size: smaller }
+
+p.label {
+  white-space: nowrap }
+
+p.rubric {
+  font-weight: bold ;
+  font-size: larger ;
+  color: maroon ;
+  text-align: center }
+
+p.sidebar-title {
+  font-family: sans-serif ;
+  font-weight: bold ;
+  font-size: larger }
+
+p.sidebar-subtitle {
+  font-family: sans-serif ;
+  font-weight: bold }
+
+p.topic-title {
+  font-weight: bold }
+
+pre.address {
+  margin-bottom: 0 ;
+  margin-top: 0 ;
+  font-family: serif ;
+  font-size: 100% }
+
+pre.literal-block, pre.doctest-block {
+  margin-left: 2em ;
+  margin-right: 2em }
+
+span.classifier {
+  font-family: sans-serif ;
+  font-style: oblique }
+
+span.classifier-delimiter {
+  font-family: sans-serif ;
+  font-weight: bold }
+
+span.interpreted {
+  font-family: sans-serif }
+
+span.option {
+  white-space: nowrap }
+
+span.pre {
+  white-space: pre }
+
+span.problematic {
+  color: red }
+
+span.section-subtitle {
+  /* font-size relative to parent (h1..h6 element) */
+  font-size: 80% }
+
+table.citation {
+  border-left: solid 1px gray;
+  margin-left: 1px }
+
+table.docinfo {
+  margin: 2em 4em }
+
+table.docutils {
+  margin-top: 0.5em ;
+  margin-bottom: 0.5em }
+
+table.footnote {
+  border-left: solid 1px black;
+  margin-left: 1px }
+
+table.docutils td, table.docutils th,
+table.docinfo td, table.docinfo th {
+  padding-left: 0.5em ;
+  padding-right: 0.5em ;
+  vertical-align: top }
+
+table.docutils th.field-name, table.docinfo th.docinfo-name {
+  font-weight: bold ;
+  text-align: left ;
+  white-space: nowrap ;
+  padding-left: 0 }
+
+h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
+h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
+  font-size: 100% }
+
+ul.auto-toc {
+  list-style-type: none }
+
+</style>
+</head>
+<body>
+<div class="document" id="svglib">
+<h1 class="title">Svglib</h1>
+<h2 class="subtitle" id="an-experimental-library-for-reading-and-converting-svg">An experimental library for reading and converting SVG</h2>
+<table class="docinfo" frame="void" rules="none">
+<col class="docinfo-name" />
+<col class="docinfo-content" />
+<tbody valign="top">
+<tr><th class="docinfo-name">Author:</th>
+<td>Dinu Gherman &lt;<a class="reference external" href="mailto:gherman&#64;darwin.in-berlin.de">gherman&#64;darwin.in-berlin.de</a>&gt;</td></tr>
+<tr class="field"><th class="docinfo-name">Homepage:</th><td class="field-body"><a class="reference external" href="http://www.dinu-gherman.net/">http://www.dinu-gherman.net/</a></td>
+</tr>
+<tr><th class="docinfo-name">Version:</th>
+<td>Version 0.6.3</td></tr>
+<tr><th class="docinfo-name">Date:</th>
+<td>2010-03-01</td></tr>
+<tr><th class="docinfo-name">Copyright:</th>
+<td>GNU Lesser General Public Licence v3 (LGPLv3)</td></tr>
+</tbody>
+</table>
+<!-- -*- mode: rst -*- -->
+<div class="section" id="about">
+<h1>About</h1>
+<p><cite>Svglib</cite> is an experimental library for reading <a class="reference external" href="http://www.w3.org/Graphics/SVG/">SVG</a> files and converting them (to a
+reasonable degree) to other formats using the Open Source <a class="reference external" href="http://www.reportlab.org">ReportLab
+Toolkit</a>. As a package it reads existing
+SVG files and returns them converted to ReportLab Drawing objects that
+can be used in a variety of ReportLab-related contexts, e.g. as Platypus
+Flowable objects or in RML2PDF. As a command-line tool it converts SVG
+files into PDF ones.</p>
+<p>Tests include a vast amount of tests from the <a class="reference external" href="http://www.w3.org/Graphics/SVG/WG/wiki/Test_Suite_Overview">W3C SVG test suite</a>.
+It also accesses around <a class="reference external" href="http://en.wikipedia.org/wiki/Gallery_of_sovereign_state_flags">200 flags from Wikipedia.org</a>
+for test purposes (some of them hinting at more work to be done).</p>
+<p>This release changes the license from GPL 3 to LGPL 3, introduces
+tiny bug fix reported by Harald Armin Massa and adapts to changed
+URLs for Wikipedia SVG flags used for test purposes.</p>
+</div>
+<div class="section" id="features">
+<h1>Features</h1>
+<ul class="simple">
+<li>convert SVG files into ReportLab Graphics Drawing objects</li>
+<li>handle plain or compressed SVG files (.svg and .svgz)</li>
+<li>allow patterns for output files on command-line</li>
+<li>install a Python package named <tt class="docutils literal"><span class="pre">svglib</span></tt></li>
+<li>install a Python command-line script named <tt class="docutils literal"><span class="pre">svg2pdf</span></tt></li>
+<li>provide a Unittest test suite</li>
+<li>test on some standard W3C SVG tests available online</li>
+<li>test on some Wikipedia sample SVG symbols available online</li>
+<li>test on some Wikipedia sample SVG flags available online</li>
+</ul>
+</div>
+<div class="section" id="examples">
+<h1>Examples</h1>
+<p>You can use <cite>svglib</cite> as a Python package e.g. like in the following
+interactive Python session:</p>
+<pre class="literal-block">
+&gt;&gt;&gt; from svglib.svglib import svg2rlg
+&gt;&gt;&gt; from reportlab.graphics import renderPDF
+&gt;&gt;&gt;
+&gt;&gt;&gt; drawing = svg2rlg(&quot;file.svg&quot;)
+&gt;&gt;&gt; renderPDF.drawToFile(drawing, &quot;file.pdf&quot;)
+</pre>
+<p>In addition a script named <tt class="docutils literal"><span class="pre">svg2pdf</span></tt> can be used more easily from
+the system command-line like this (you can see more examples when
+typing <tt class="docutils literal"><span class="pre">svg2pdf</span> <span class="pre">-h</span></tt>):</p>
+<pre class="literal-block">
+$ svg2pdf file1.svg file2.svgz
+$ svg2pdf -o &quot;%(basename)s.pdf&quot; /path/file[12].svgz?
+</pre>
+</div>
+<div class="section" id="installation">
+<h1>Installation</h1>
+<p>There are two ways to install <cite>svglib</cite>, depending on whether you have
+the <cite>easy_install</cite> command available on your system or not.</p>
+<div class="section" id="using-easy-install">
+<h2>1. Using <cite>easy_install</cite></h2>
+<p>With the <cite>easy_install</cite> command on your system and a working internet
+connection you can install <cite>svglib</cite> with only one command in a terminal:</p>
+<pre class="literal-block">
+$ easy_install svglib
+</pre>
+<p>If the <cite>easy_install</cite> command is not available to you and you want to
+install it before installing <cite>svglib</cite>, you might want to go to the
+<a class="reference external" href="http://peak.telecommunity.com/DevCenter/EasyInstall">Easy Install homepage</a>
+and follow the <a class="reference external" href="http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install">instructions there</a>.</p>
+</div>
+<div class="section" id="manual-installation">
+<h2>2. Manual installation</h2>
+<p>Alternatively, you can install the <cite>svglib</cite> tarball after downloading
+the file <tt class="docutils literal"><span class="pre">svglib-0.6.3.tar.gz</span></tt> and decompressing it with the following
+command:</p>
+<pre class="literal-block">
+$ tar xfz svglib-0.6.3.tar.gz
+</pre>
+<p>Then change into the newly created directory <tt class="docutils literal"><span class="pre">svglib</span></tt> and install
+<cite>svglib</cite> by running the following command:</p>
+<pre class="literal-block">
+$ python setup.py install
+</pre>
+<p>This will install a Python module file named <tt class="docutils literal"><span class="pre">svglib.py</span></tt> in the
+<tt class="docutils literal"><span class="pre">site-packages</span></tt> subfolder of your Python interpreter and a script
+tool named <tt class="docutils literal"><span class="pre">svglib</span></tt> in your <tt class="docutils literal"><span class="pre">bin</span></tt> directory, usually in
+<tt class="docutils literal"><span class="pre">/usr/local/bin</span></tt>.</p>
+</div>
+</div>
+<div class="section" id="dependencies">
+<h1>Dependencies</h1>
+<p><cite>Svglib</cite> depends on the <cite>reportlab</cite> package, which, as of now, you
+have to install manually, before you can use <cite>svglib</cite>. Unfortunately,
+up to its latest release, <cite>reportlab</cite> 2.2, this package cannot be
+installed automatically using <cite>easy_install</cite>.</p>
+</div>
+<div class="section" id="testing">
+<h1>Testing</h1>
+<p>The <cite>svglib</cite> tarball distribution contains a Unittest test suite
+in the file <tt class="docutils literal"><span class="pre">test_svglib.py</span></tt> which can be run like shown in the
+following lines on the system command-line:</p>
+<pre class="literal-block">
+$ tar xfz svglib-0.6.3.tar.gz
+$ cd svglib/src/test
+$ python test_svglib.py
+......
+[...]
+working on [0] wikipedia/Ankh.svg
+working on [1] wikipedia/Biohazard.svg
+working on [2] wikipedia/Dharma_wheel.svg
+working on [3] wikipedia/Eye_of_Horus_bw.svg
+[...]
+----------------------------------------------------------------------
+Ran 12 tests in 87.536s
+
+OK
+</pre>
+</div>
+<div class="section" id="bug-reports">
+<h1>Bug reports</h1>
+<p>Please report bugs and patches to Dinu Gherman
+&lt;<a class="reference external" href="mailto:gherman&#64;darwin.in-berlin.de">gherman&#64;darwin.in-berlin.de</a>&gt;. Don't forget to include information
+about the operating system, ReportLab and Python versions being used.</p>
+</div>
+</div>
+</body>
+</html>
+.. -*- mode: rst -*-
+
+========
+Svglib
+========
+
+---------------------------------------------------------------------------
+An experimental library for reading and converting SVG
+---------------------------------------------------------------------------
+
+:Author:     Dinu Gherman <gherman@darwin.in-berlin.de>
+:Homepage:   http://www.dinu-gherman.net/
+:Version:    Version 0.6.3
+:Date:       2010-03-01
+:Copyright:  GNU Lesser General Public Licence v3 (LGPLv3)
+
+
+About
+-----
+
+`Svglib` is an experimental library for reading `SVG 
+<http://www.w3.org/Graphics/SVG/>`_ files and converting them (to a 
+reasonable degree) to other formats using the Open Source `ReportLab 
+Toolkit <http://www.reportlab.org>`_. As a package it reads existing 
+SVG files and returns them converted to ReportLab Drawing objects that 
+can be used in a variety of ReportLab-related contexts, e.g. as Platypus 
+Flowable objects or in RML2PDF. As a command-line tool it converts SVG 
+files into PDF ones. 
+
+Tests include a vast amount of tests from the `W3C SVG test suite 
+<http://www.w3.org/Graphics/SVG/WG/wiki/Test_Suite_Overview>`_.
+It also accesses around `200 flags from Wikipedia.org 
+<http://en.wikipedia.org/wiki/Gallery_of_sovereign_state_flags>`_ 
+for test purposes (some of them hinting at more work to be done).
+
+This release changes the license from GPL 3 to LGPL 3, introduces
+tiny bug fix reported by Harald Armin Massa and adapts to changed 
+URLs for Wikipedia SVG flags used for test purposes.
+ 
+
+Features
+--------
+
+- convert SVG files into ReportLab Graphics Drawing objects
+- handle plain or compressed SVG files (.svg and .svgz)
+- allow patterns for output files on command-line
+- install a Python package named ``svglib``
+- install a Python command-line script named ``svg2pdf``
+- provide a Unittest test suite
+- test on some standard W3C SVG tests available online
+- test on some Wikipedia sample SVG symbols available online
+- test on some Wikipedia sample SVG flags available online
+
+
+Examples
+--------
+
+You can use `svglib` as a Python package e.g. like in the following
+interactive Python session::
+
+    >>> from svglib.svglib import svg2rlg
+    >>> from reportlab.graphics import renderPDF
+    >>>
+    >>> drawing = svg2rlg("file.svg")
+    >>> renderPDF.drawToFile(drawing, "file.pdf")
+
+In addition a script named ``svg2pdf`` can be used more easily from 
+the system command-line like this (you can see more examples when 
+typing ``svg2pdf -h``)::
+
+    $ svg2pdf file1.svg file2.svgz
+    $ svg2pdf -o "%(basename)s.pdf" /path/file[12].svgz?
+  
+
+Installation
+------------
+
+There are two ways to install `svglib`, depending on whether you have
+the `easy_install` command available on your system or not.
+
+1. Using `easy_install`
+++++++++++++++++++++++++
+
+With the `easy_install` command on your system and a working internet 
+connection you can install `svglib` with only one command in a terminal::
+
+  $ easy_install svglib
+
+If the `easy_install` command is not available to you and you want to
+install it before installing `svglib`, you might want to go to the 
+`Easy Install homepage <http://peak.telecommunity.com/DevCenter/EasyInstall>`_ 
+and follow the `instructions there <http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install>`_.
+
+2. Manual installation
++++++++++++++++++++++++
+
+Alternatively, you can install the `svglib` tarball after downloading 
+the file ``svglib-0.6.3.tar.gz`` and decompressing it with the following 
+command::
+
+  $ tar xfz svglib-0.6.3.tar.gz
+
+Then change into the newly created directory ``svglib`` and install 
+`svglib` by running the following command::
+
+  $ python setup.py install
+  
+This will install a Python module file named ``svglib.py`` in the 
+``site-packages`` subfolder of your Python interpreter and a script 
+tool named ``svglib`` in your ``bin`` directory, usually in 
+``/usr/local/bin``.
+
+
+Dependencies
+------------
+
+`Svglib` depends on the `reportlab` package, which, as of now, you
+have to install manually, before you can use `svglib`. Unfortunately,
+up to its latest release, `reportlab` 2.2, this package cannot be
+installed automatically using `easy_install`.
+
+
+Testing
+-------
+
+The `svglib` tarball distribution contains a Unittest test suite 
+in the file ``test_svglib.py`` which can be run like shown in the 
+following lines on the system command-line::
+ 
+  $ tar xfz svglib-0.6.3.tar.gz
+  $ cd svglib/src/test
+  $ python test_svglib.py
+  ......
+  [...]
+  working on [0] wikipedia/Ankh.svg
+  working on [1] wikipedia/Biohazard.svg
+  working on [2] wikipedia/Dharma_wheel.svg
+  working on [3] wikipedia/Eye_of_Horus_bw.svg
+  [...]
+  ----------------------------------------------------------------------
+  Ran 12 tests in 87.536s
+
+  OK
+
+
+Bug reports
+-----------
+
+Please report bugs and patches to Dinu Gherman 
+<gherman@darwin.in-berlin.de>. Don't forget to include information 
+about the operating system, ReportLab and Python versions being used.
+#!python
+"""Bootstrap setuptools installation
+
+If you want to use setuptools in your package's setup.py, just include this
+file in the same directory with it, and add this to the top of your setup.py::
+
+    from ez_setup import use_setuptools
+    use_setuptools()
+
+If you want to require a specific version of setuptools, set a download
+mirror, or use an alternate download directory, you can do so by supplying
+the appropriate options to ``use_setuptools()``.
+
+This file can also be run as a script to install or upgrade setuptools.
+"""
+import sys
+DEFAULT_VERSION = "0.6c9"
+DEFAULT_URL     = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3]
+
+md5_data = {
+    'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca',
+    'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb',
+    'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b',
+    'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a',
+    'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618',
+    'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac',
+    'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5',
+    'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4',
+    'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c',
+    'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b',
+    'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27',
+    'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277',
+    'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa',
+    'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e',
+    'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e',
+    'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f',
+    'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2',
+    'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc',
+    'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167',
+    'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64',
+    'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d',
+    'setuptools-0.6c6-py2.3.egg': '35686b78116a668847237b69d549ec20',
+    'setuptools-0.6c6-py2.4.egg': '3c56af57be3225019260a644430065ab',
+    'setuptools-0.6c6-py2.5.egg': 'b2f8a7520709a5b34f80946de5f02f53',
+    'setuptools-0.6c7-py2.3.egg': '209fdf9adc3a615e5115b725658e13e2',
+    'setuptools-0.6c7-py2.4.egg': '5a8f954807d46a0fb67cf1f26c55a82e',
+    'setuptools-0.6c7-py2.5.egg': '45d2ad28f9750e7434111fde831e8372',
+    'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902',
+    'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de',
+    'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b',
+}
+
+import sys, os
+try: from hashlib import md5
+except ImportError: from md5 import md5
+
+def _validate_md5(egg_name, data):
+    if egg_name in md5_data:
+        digest = md5(data).hexdigest()
+        if digest != md5_data[egg_name]:
+            print >>sys.stderr, (
+                "md5 validation of %s failed!  (Possible download problem?)"
+                % egg_name
+            )
+            sys.exit(2)
+    return data
+
+def use_setuptools(
+    version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
+    download_delay=15
+):
+    """Automatically find/download setuptools and make it available on sys.path
+
+    `version` should be a valid setuptools version number that is available
+    as an egg for download under the `download_base` URL (which should end with
+    a '/').  `to_dir` is the directory where setuptools will be downloaded, if
+    it is not already available.  If `download_delay` is specified, it should
+    be the number of seconds that will be paused before initiating a download,
+    should one be required.  If an older version of setuptools is installed,
+    this routine will print a message to ``sys.stderr`` and raise SystemExit in
+    an attempt to abort the calling script.
+    """
+    was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules
+    def do_download():
+        egg = download_setuptools(version, download_base, to_dir, download_delay)
+        sys.path.insert(0, egg)
+        import setuptools; setuptools.bootstrap_install_from = egg
+    try:
+        import pkg_resources
+    except ImportError:
+        return do_download()       
+    try:
+        pkg_resources.require("setuptools>="+version); return
+    except pkg_resources.VersionConflict, e:
+        if was_imported:
+            print >>sys.stderr, (
+            "The required version of setuptools (>=%s) is not available, and\n"
+            "can't be installed while this script is running. Please install\n"
+            " a more recent version first, using 'easy_install -U setuptools'."
+            "\n\n(Currently using %r)"
+            ) % (version, e.args[0])
+            sys.exit(2)
+        else:
+            del pkg_resources, sys.modules['pkg_resources']    # reload ok
+            return do_download()
+    except pkg_resources.DistributionNotFound:
+        return do_download()
+
+def download_setuptools(
+    version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
+    delay = 15
+):
+    """Download setuptools from a specified location and return its filename
+
+    `version` should be a valid setuptools version number that is available
+    as an egg for download under the `download_base` URL (which should end
+    with a '/'). `to_dir` is the directory where the egg will be downloaded.
+    `delay` is the number of seconds to pause before an actual download attempt.
+    """
+    import urllib2, shutil
+    egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3])
+    url = download_base + egg_name
+    saveto = os.path.join(to_dir, egg_name)
+    src = dst = None
+    if not os.path.exists(saveto):  # Avoid repeated downloads
+        try:
+            from distutils import log
+            if delay:
+                log.warn("""
+---------------------------------------------------------------------------
+This script requires setuptools version %s to run (even to display
+help).  I will attempt to download it for you (from
+%s), but
+you may need to enable firewall access for this script first.
+I will start the download in %d seconds.
+
+(Note: if this machine does not have network access, please obtain the file
+
+   %s
+
+and place it in this directory before rerunning this script.)
+---------------------------------------------------------------------------""",
+                    version, download_base, delay, url
+                ); from time import sleep; sleep(delay)
+            log.warn("Downloading %s", url)
+            src = urllib2.urlopen(url)
+            # Read/write all in one block, so we don't create a corrupt file
+            # if the download is interrupted.
+            data = _validate_md5(egg_name, src.read())
+            dst = open(saveto,"wb"); dst.write(data)
+        finally:
+            if src: src.close()
+            if dst: dst.close()
+    return os.path.realpath(saveto)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+def main(argv, version=DEFAULT_VERSION):
+    """Install or upgrade setuptools and EasyInstall"""
+    try:
+        import setuptools
+    except ImportError:
+        egg = None
+        try:
+            egg = download_setuptools(version, delay=0)
+            sys.path.insert(0,egg)
+            from setuptools.command.easy_install import main
+            return main(list(argv)+[egg])   # we're done here
+        finally:
+            if egg and os.path.exists(egg):
+                os.unlink(egg)
+    else:
+        if setuptools.__version__ == '0.0.1':
+            print >>sys.stderr, (
+            "You have an obsolete version of setuptools installed.  Please\n"
+            "remove it from your system entirely before rerunning this script."
+            )
+            sys.exit(2)
+
+    req = "setuptools>="+version
+    import pkg_resources
+    try:
+        pkg_resources.require(req)
+    except pkg_resources.VersionConflict:
+        try:
+            from setuptools.command.easy_install import main
+        except ImportError:
+            from easy_install import main
+        main(list(argv)+[download_setuptools(delay=0)])
+        sys.exit(0) # try to force an exit
+    else:
+        if argv:
+            from setuptools.command.easy_install import main
+            main(argv)
+        else:
+            print "Setuptools version",version,"or greater has been installed."
+            print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
+
+def update_md5(filenames):
+    """Update our built-in md5 registry"""
+
+    import re
+
+    for name in filenames:
+        base = os.path.basename(name)
+        f = open(name,'rb')
+        md5_data[base] = md5(f.read()).hexdigest()
+        f.close()
+
+    data = ["    %r: %r,\n" % it for it in md5_data.items()]
+    data.sort()
+    repl = "".join(data)
+
+    import inspect
+    srcfile = inspect.getsourcefile(sys.modules[__name__])
+    f = open(srcfile, 'rb'); src = f.read(); f.close()
+
+    match = re.search("\nmd5_data = {\n([^}]+)}", src)
+    if not match:
+        print >>sys.stderr, "Internal error!"
+        sys.exit(2)
+
+    src = src[:match.start(1)] + repl + src[match.end(1):]
+    f = open(srcfile,'w')
+    f.write(src)
+    f.close()
+
+
+if __name__=='__main__':
+    if len(sys.argv)>2 and sys.argv[1]=='--md5update':
+        update_md5(sys.argv[2:])
+    else:
+        main(sys.argv[1:])
+
+
+
+
+
+
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+"Project meta information"
+
+
+__version__ = "0.6.3"
+__license__ = "LGPL 3"
+__author__ = "Dinu Gherman"
+__date__ = "2010-03-01"
+
+
+name = "svglib"
+version = __version__
+date = __date__
+description = "An experimental library for reading and converting SVG."
+long_description = """\
+`Svglib` is an experimental library for reading `SVG 
+<http://www.w3.org/Graphics/SVG/>`_ files and converting them (to a 
+reasonable degree) to other formats using the Open Source `ReportLab 
+Toolkit <http://www.reportlab.org>`_. As a package it reads existing 
+SVG files and returns them converted to ReportLab Drawing objects that 
+can be used in a variety of ReportLab-related contexts, e.g. as Platypus 
+Flowable objects or in RML2PDF. As a command-line tool it converts SVG 
+files into PDF ones. 
+
+Tests include a vast amount of tests from the `W3C SVG test suite 
+<http://www.w3.org/Graphics/SVG/WG/wiki/Test_Suite_Overview>`_.
+It also accesses around `200 flags from Wikipedia.org 
+<http://en.wikipedia.org/wiki/Gallery_of_sovereign_state_flags>`_ 
+for test purposes (some of them hinting at more work to be done).
+
+This release changes the license from GPL 3 to LGPL 3, introduces
+tiny bug fix reported by Harald Armin Massa and adapts to changed 
+URLs for Wikipedia SVG flags used for test purposes.
+
+
+Features
+++++++++
+
+- convert SVG files into ReportLab Graphics Drawing objects
+- handle plain or compressed SVG files (.svg and .svgz)
+- allow patterns for output files on command-line
+- install a Python package named ``svglib``
+- install a Python command-line script named ``svg2pdf``
+- provide a Unittest test suite
+- test on some standard W3C SVG tests available online
+- test on some Wikipedia sample SVG symbols available online
+- test on some Wikipedia sample SVG flags available online
+
+
+Examples
+++++++++
+
+You can use `svglib` as a Python package e.g. like in the following
+interactive Python session::
+
+    >>> from svglib.svglib import svg2rlg
+    >>> from reportlab.graphics import renderPDF
+    >>>
+    >>> drawing = svg2rlg("file.svg")
+    >>> renderPDF.drawToFile(drawing, "file.pdf")
+
+In addition a script named ``svg2pdf`` can be used more easily from 
+the system command-line like this (you can see more examples when 
+typing ``svg2pdf -h``)::
+
+    $ svg2pdf file1.svg file2.svgz
+    $ svg2pdf -o "%(basename)s.pdf" /path/file[12].svgz?
+"""
+author = 'Dinu Gherman'
+author_email = '@'.join(['gherman', 'darwin.in-berlin.de'])
+maintainer = author
+maintainer_email = author_email
+license_short = 'GNU GPL'
+license = __license__
+platforms = ["Posix", "Windows"]
+keywords = ["svg", "reportlab", "PDF"]
+_baseURL = "http://www.dinu-gherman.net/"
+url = _baseURL
+download_url = _baseURL + "tmp/%s-%s.tar.gz" % (name, __version__)
+package_dir = {"svglib": "src/svglib"}
+packages = ["svglib"]
+py_modules = []
+scripts = ["src/scripts/svg2pdf"]
+classifiers = [
+    # see http://pypi.python.org/pypi?%3Aaction=list_classifiers
+    "Development Status :: 4 - Beta",
+    "Environment :: Console",
+    "Intended Audience :: End Users/Desktop",
+    "Intended Audience :: Developers",
+    "License :: OSI Approved :: GNU General Public License (GPL)",
+    "Operating System :: MacOS :: MacOS X",
+    "Operating System :: POSIX",
+    "Operating System :: Microsoft :: Windows",
+    "Natural Language :: English",
+    "Programming Language :: Python",
+    "Topic :: Documentation",
+    "Topic :: Utilities",
+    "Topic :: Printing",
+    "Topic :: Multimedia :: Graphics :: Graphics Conversion",
+    "Topic :: Software Development :: Libraries :: Python Modules",
+    "Topic :: Text Processing :: Markup :: XML",
+]
+
+# for setuptools, only:
+# install_requires = ["reportlab>2.0"],
+[egg_info]
+tag_build = 
+tag_date = 0
+tag_svn_revision = 0
+
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+import sys
+sys.path.insert(0, "src")
+
+import ez_setup
+ez_setup.use_setuptools()
+from setuptools import setup
+
+
+import metainfo
+
+# get module not starting with '_'
+# this also excludes '__builtins__', '__doc__', '__file__', '__name__'
+items = dict([(k, metainfo.__getattribute__(k)) 
+    for k in metainfo.__dict__ if k[0] != '_'])
+
+# pass them to distutils
+setup(**items)

src/scripts/svg2pdf

+#!/usr/bin/env python
+# _*_ coding: UTF-8 _*_
+
+"""A simple converter from SVG to PDF.
+
+For further information please look into the file README.txt!
+"""
+
+import re
+import sys
+import getopt
+import os.path
+
+from reportlab.graphics import renderPDF
+
+from svglib import svglib
+
+
+__version__ = "0.6.3"
+__license__ = "LGPL 3"
+__author__ = "Dinu Gherman"
+__date__ = "2010-03-01"
+
+
+def svg2pdf(path, outputPat=None):
+    "Convert an SVG file to a PDF one."
+ 
+    # generate a drawing from the SVG file
+    try:
+        drawing = svglib.svg2rlg(path)
+    except:
+        print "Rendering failed."
+        raise
+
+    # derive output filename from output pattern
+    if not outputPat:
+        outputPat = "%(dirname)s/%(base)s.pdf"
+    dirname = os.path.dirname(path) or "."
+    basename = os.path.basename(path)
+    base = os.path.basename(os.path.splitext(path)[0])
+    ext = os.path.splitext(path)[1]
+    
+    aDict = {
+        "dirname":dirname, "basename":basename, 
+        "base":base, "ext":ext
+    }
+    outPath = outputPat % aDict
+
+    # save as PDF file
+    if drawing:
+        renderPDF.drawToFile(drawing, outPath, showBoundary=0)
+
+
+# command-line usage stuff
+
+def _showVersion():
+    "Print version message and terminate."
+
+    prog = os.path.basename(sys.argv[0])
+    print "%s %s" % (prog, __version__)
+    sys.exit()
+
+
+def _showUsage():
+    "Print usage message and terminate."
+
+    prog = os.path.basename(sys.argv[0])
+    copyrightYear = __date__[:__date__.find("-")]
+    args = (prog, __version__, __author__, copyrightYear, __license__)
+    print "%s v. %s, Copyleft by %s, %s (%s)" % args 
+    print "An experimental SVG to PDF converter (via ReportLab Graphics)"
+    print "USAGE: %s [options] file1.svg(z) [file2.svg(z)...]" % prog
+    print """\
+OPTIONS:
+  -h --help          Print this usage message and exits.
+  -v --version       Print version number and exits.
+  -o --output FILE   Set output path (incl. some patterns).
+
+EXAMPLES:
+  %(prog)s file1.svg file2.svgz # produce file1.pdf and file2.pdf
+  %(prog)s path/file.svg        # produce path/file.pdf
+  %(prog)s -o out.pdf file.svg  # produce out.pdf
+  %(prog)s -o "%%(basename)s.pdf" path/file*.svg  
+                               # creates all output in local dir.
+
+COPYLEFT:
+  see http://www.gnu.org/copyleft/gpl.html
+""" % {"prog": prog}
+
+    sys.exit()
+
+
+def _main():
+    "Main for command-line usage."
+
+    try:
+        longOpts = "help version output=".split()
+        opts, args = getopt.getopt(sys.argv[1:], "hvo:", longOpts)
+    except getopt.GetoptError:
+        print "ERROR"
+        _showUsage()
+    
+    stopOptions = "-v --version -h --help"
+    stopOptions = [key for (key, val) in opts if key in stopOptions]
+    if len(args) == 0 and len(stopOptions) == 0:
+        _showUsage()
+
+    outputPat = None
+    for key, val in opts:
+        if key in ("-h", "--help"):
+            _showUsage()
+        elif key in ("-v", "--version"):
+            _showVersion()
+        elif key in ("-o", "--output"):
+            outputPat = val
+
+    # determine paths of input files
+    paths = [a for a in args if os.path.exists(a)]
+
+    for path in paths:    
+        svg2pdf(path, outputPat)
+
+
+if __name__ == '__main__':    
+    _main()

src/svglib/__init__.py

Empty file added.

src/svglib/svglib.py

+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+"""An experimental library for reading and converting SVG.
+
+This is an experimental converter from SVG to RLG (ReportLab Graphics)
+drawings. It converts mainly basic shapes, paths and simple text. 
+The current intended usage is either as module within other projects:
+
+    from svglib.svglib import svg2rlg
+    drawing = svg2rlg("foo.svg")
+  
+or from the command-line where right now it is usable as an SVG to PDF
+converting tool named sv2pdf (which should also handle SVG files com-
+pressed with gzip and extension .svgz).
+"""
+
+import sys
+import os
+import glob
+import types
+import re
+import operator
+import gzip
+import xml.dom.minidom 
+
+from reportlab.pdfbase.pdfmetrics import stringWidth
+from reportlab.graphics.shapes import *
+from reportlab.graphics import renderPDF
+from reportlab.lib import colors
+from reportlab.lib.units import cm, inch, mm, pica, toLength
+
+
+__version__ = "0.6.3"
+__license__ = "LGPL 3"
+__author__ = "Dinu Gherman"
+__date__ = "2010-03-01"
+
+
+pt = 1
+LOGMESSAGES = 0
+
+
+### helpers ###
+
+def convertToFloats(aList):
+    "Convert number strings in list to floats (leave rest untouched)."
+
+    for i in xrange(len(aList)):
+        try:
+            aList[i] = float(aList[i])
+        except ValueError:
+            try:
+                aList[i] = aList[i].encode("ASCII")
+            except:
+                pass
+
+    return aList
+
+
+def convertQuadraticToCubicPath(Q0, Q1, Q2):
+    "Convert a quadratic Bezier curve through Q0, Q1, Q2 to a cubic one."
+
+    C0 = Q0
+    C1 = (Q0[0]+2./3*(Q1[0]-Q0[0]), Q0[1]+2./3*(Q1[1]-Q0[1]))
+    C2 = (C1[0]+1./3*(Q2[0]-Q0[0]), C1[1]+1./3*(Q2[1]-Q0[1]))
+    C3 = Q2
+
+    return C0, C1, C2, C3
+
+
+def fixSvgPath(aList):
+    """Normalise certain "abnormalities" in SVG paths.
+
+    Basically, this reduces adjacent number values for h and v
+    operators to the sum of these numbers and those for H and V
+    operators to the last number only.
+
+    Returns a slightly more compact list if such reductions
+    were applied or a copy of the same list, otherwise.
+    """
+
+    # this could also modify the path to contain an op code
+    # for each coord. tuple of a tuple sequence... 
+
+    hPos, vPos, HPos, VPos, numPos = [], [], [], [], []
+    for i in xrange(len(aList)):
+        hPos.append(aList[i]=='h')
+        vPos.append(aList[i]=='v')
+        HPos.append(aList[i]=='H')
+        VPos.append(aList[i]=='V')
+        numPos.append(type(aList[i])==type(1.0))
+
+    fixedList = []
+
+    i = 0
+    while i < len(aList):
+        if hPos[i] + vPos[i] + HPos[i] + VPos[i] == 0:
+            fixedList.append(aList[i])
+        elif hPos[i] == 1 or vPos[i] == 1:
+            fixedList.append(aList[i])
+            sum = 0
+            j = i+1
+            while j < len(aList) and numPos[j] == 1:
+                sum = sum + aList[j]
+                j = j+1
+            fixedList.append(sum)
+            i = j-1
+        elif HPos[i] == 1 or VPos[i] == 1:
+            fixedList.append(aList[i])
+            last = 0
+            j = i+1
+            while j < len(aList) and numPos[j] == 1:
+                last = aList[j]
+                j = j+1
+            fixedList.append(last)
+            i = j-1
+        i = i+1
+
+    return fixedList
+
+
+def normaliseSvgPath(attr):
+    """Normalise SVG path.
+
+    This basically introduces operator codes for multi-argument
+    parameters. Also, it fixes sequences of consecutive M or m
+    operators to MLLL... and mlll... operators. It adds an empty
+    list as argument for Z and z only in order to make the resul-
+    ting list easier to iterate over.
+
+    E.g. "M 10 20, M 20 20, L 30 40, 40 40, Z" 
+      -> ['M', [10, 20], 'L', [20, 20], 'L', [30, 40], 'L', [40, 40], 'Z', []]
+    """
+
+    # operator codes mapped to the minimum number of expected arguments 
+    ops = {'A':7, 'a':7,
+      'Q':4, 'q':4, 'T':2, 't':2, 'S':4, 's':4, 
+      'M':2, 'L':2, 'm':2, 'l':2, 'H':1, 'V':1,  
+      'h':1, 'v':1, 'C':6, 'c':6, 'Z':0, 'z':0}
+
+    # do some preprocessing
+    opKeys = ops.keys()
+    a = attr
+    a = a.replace(',', ' ')
+    a = string.replace(a, 'e-', 'ee')
+    a = string.replace(a, '-', ' -')
+    a = string.replace(a, 'ee', 'e-')
+    for op in opKeys:
+        a = a.replace(op, " %s " % op)
+    a = a.strip()
+    a = a.split()
+    a = convertToFloats(a)
+    a = fixSvgPath(a)
+
+    # insert op codes for each argument of an op with multiple arguments
+    res = []
+    i = 0
+    while i < len(a):
+        el = a[i]
+        if el in opKeys:
+            if el in ('z', 'Z'):
+                res.append(el)
+                res.append([])
+            else:
+                while i < len(a)-1:
+                    if a[i+1] not in opKeys:
+                        res.append(el)
+                        res.append(a[i+1:i+1+ops[el]])
+                        i = i + ops[el]
+                    else:
+                        break
+        i = i + 1
+
+    # fix sequences of M to one M plus a sequence of L operators,
+    # same for m and l.
+    for i in xrange(0, len(res), 2):
+        op, nums = res[i:i+2]
+        if i >= 2:
+            if op == 'M' == res[i-2]:
+                res[i] = 'L'
+            elif op == 'm' == res[i-2]:
+                res[i] = 'l'
+
+    return res
+
+
+### attribute converters (from SVG to RLG)
+
+class AttributeConverter:
+    "An abstract class to locate and convert attributes in a DOM instance."
+
+    def parseMultiAttributes(self, line):
+        """Try parsing compound attribute string.
+
+        Return a dictionary with single attributes in 'line'.
+        """
+    
+        try:
+            line = line.encode("ASCII")
+        except:
+            pass
+
+        attrs = line.split(';')
+        attrs = [a.strip() for a in attrs]
+        attrs = filter(lambda a:len(a)>0, attrs)
+
+        newAttrs = {}
+        for a in attrs:
+            k, v = a.split(':')
+            k, v = [s.strip() for s in (k, v)]
+            newAttrs[k] = v
+
+        return newAttrs
+
+
+    def findAttr(self, svgNode, name):
+        """Search an attribute with some name in some node or above.
+
+        First the node is searched, then its style attribute, then
+        the search continues in the node's parent node. If no such
+        attribute is found, '' is returned. 
+        """
+
+        # This needs also to lookup values like "url(#SomeName)"...    
+
+        try:
+            attrValue = svgNode.getAttribute(name)
+        except:
+            return ''
+
+        if attrValue and attrValue != "inherit":
+            return attrValue
+        elif svgNode.getAttribute("style"):
+            dict = self.parseMultiAttributes(svgNode.getAttribute("style"))
+            if dict.has_key(name):
+                return dict[name]
+        else:
+            if svgNode.parentNode:
+                return self.findAttr(svgNode.parentNode, name)
+
+        return ''
+
+
+    def getAllAttributes(self, svgNode):
+        "Return a dictionary of all attributes of svgNode or those inherited by it."
+
+        dict = {}
+
+        if svgNode.parentNode and svgNode.parentNode == 'g':
+            dict.update(self.getAllAttributes(svgNode.parentNode))
+
+        if svgNode.nodeType == svgNode.ELEMENT_NODE:
+            style = svgNode.getAttribute("style")
+            if style:
+                d = self.parseMultiAttributes(style)
+                dict.update(d)
+
+        attrs = svgNode.attributes
+        for i in xrange(attrs.length):
+            a = attrs.item(i)
+            if a.name != "style":
+                dict[a.name.encode("ASCII")] = a.value
+
+        return dict
+
+
+    def id(self, svgAttr):
+        "Return attribute as is."
+
+        return svgAttr
+
+
+    def convertTransform(self, svgAttr):
+        """Parse transform attribute string.
+
+        E.g. "scale(2) translate(10,20)" 
+             -> [("scale", 2), ("translate", (10,20))]
+        """
+
+        line = svgAttr
+
+        try:
+            line = line.encode("ASCII")
+        except:
+            pass
+
+        line = line.strip()
+        ops = line[:]
+        brackets = []
+        indices = []
+        for i in range(len(line)):
+           if line[i] in "()": brackets.append(i)
+        for i in range(0, len(brackets), 2):
+            bi, bj = brackets[i], brackets[i+1]
+            subline = line[bi+1:bj]
+            subline = subline.strip()
+            subline = subline.replace(',', ' ')
+            subline = re.sub("[ ]+", ',', subline)
+            indices.append(eval(subline))
+            ops = ops[:bi] + ' '*(bj-bi+1) + ops[bj+1:]
+        ops = ops.split()
+
+        assert len(ops) == len(indices)
+        result = []
+        for i in range(len(ops)):
+            result.append((ops[i], indices[i]))
+
+        return result
+
+
+class Svg2RlgAttributeConverter(AttributeConverter):
+    "A concrete SVG to RLG attribute converter."
+
+    def convertLength(self, svgAttr, percentOf=100):
+        "Convert length to points."
+
+        text = svgAttr
+        if not text:
+            return 0.0
+
+        if text[-1] == '%':
+            if LOGMESSAGES:
+                print "Fiddling length unit: %"
+            return float(text[:-1]) / 100 * percentOf
+        elif text[-2:] == "pc":
+            return float(text[:-2]) * pica
+
+        newSize = text[:]
+        for u in "em ex px".split():
+            if newSize.find(u) >= 0:
+                if LOGMESSAGES:
+                    print "Ignoring unit: %s" % u
+                newSize = newSize.replace(u, '')
+
+        newSize = newSize.strip()
+        length = toLength(newSize)
+
+        return length
+
+
+    def convertLengthList(self, svgAttr):
+        "Convert a list of lengths."
+
+        t = svgAttr.replace(',', ' ')
+        t = t.strip()
+        t = re.sub("[ ]+", ' ', t)
+        a = t.split(' ')
+        a = map(self.convertLength, a)
+
+        return a
+
+
+    def convertColor(self, svgAttr):
+        "Convert string to a RL color object."
+
+        # fix it: most likely all "web colors" are allowed
+        predefined = "aqua black blue fuchsia gray green lime maroon navy "
+        predefined = predefined + "olive orange purple red silver teal white yellow "
+        predefined = predefined + "lawngreen indianred aquamarine lightgreen brown"
+
+        # This needs also to lookup values like "url(#SomeName)"...    
+
+        text = svgAttr
+        if not text or text == "none":
+            return None
+
+        try:
+            text = text.encode("ASCII")
+        except:
+            pass
+
+        if text in predefined.split():
+            return getattr(colors, text)
+        elif text == "currentColor":
+            return "currentColor"
+        elif len(text) == 7 and text[0] == '#':
+            return colors.HexColor(text)
+        elif len(text) == 4 and text[0] == '#':
+            return colors.HexColor('#' + 2*text[1] + 2*text[2] + 2*text[3])
+        elif text[:3] == "rgb" and text.find('%') < 0:
+            t = text[:][3:]
+            t = t.replace('%', '')
+            tup = eval(t)
+            tup = map(lambda h:h[2:], map(hex, tup))
+            tup = map(lambda h:(2-len(h))*'0'+h, tup)
+            col = "#%s%s%s" % tuple(tup)
+            return colors.HexColor(col)
+        elif text[:3] == 'rgb' and text.find('%') >= 0:
+            t = text[:][3:]
+            t = t.replace('%', '')
+            tup = eval(t)
+            tup = map(lambda c:c/100.0, tup)
+            col = apply(colors.Color, tup)
+            return col
+
+        if LOGMESSAGES:
+            print "Can't handle color:", text
+
+        return None
+
+
+    def convertLineJoin(self, svgAttr):
+        return {"miter":0, "round":1, "bevel":2}[svgAttr]
+
+
+    def convertLineCap(self, svgAttr):
+        return {"butt":0, "round":1, "square":2}[svgAttr]
+
+
+    def convertDashArray(self, svgAttr):
+        strokeDashArray = self.convertLengthList(svgAttr)
+        return strokeDashArray
+
+
+    def convertDashOffset(self, svgAttr):
+        strokeDashOffset = self.convertLength(svgAttr)
+        return strokeDashOffset
+
+
+    def convertFontFamily(self, svgAttr):
+        # very hackish
+        fontMapping = {"sans-serif":"Helvetica", 
+                       "serif":"Times-Roman", 
+                       "monospace":"Courier"}
+        fontName = svgAttr
+        if not fontName:
+            return ''
+        try:
+            fontName = fontMapping[fontName]
+        except KeyError:
+            pass
+        if fontName not in ("Helvetica", "Times-Roman", "Courier"):
+            fontName = "Helvetica"
+
+        return fontName
+
+
+class NodeTracker:
+    """An object wrapper keeping track of arguments to certain method calls.
+
+    Instances wrap an object and store all arguments to one special
+    method, getAttribute(name), in a list of unique elements, usedAttrs.
+    """
+
+    def __init__(self, anObject):
+        self.object = anObject
+        self.usedAttrs = []
+
+    def getAttribute(self, name):
+        # add argument to the history, if not already present
+        if name not in self.usedAttrs:
+            self.usedAttrs.append(name)
+        # forward call to wrapped object
+        return self.object.getAttribute(name)
+
+    # also getAttributeNS(uri, name)?
+
+    def __getattr__(self, name):
+        # forward attribute access to wrapped object 
+        return getattr(self.object, name)
+
+
+### the main meat ###
+
+class SvgRenderer:
+    """Renderer that renders an SVG file on a ReportLab Drawing instance.
+
+    This is the base class for walking over an SVG DOM document and
+    transforming it into a ReportLab Drawing instance.
+    """
+
+    def __init__(self, path=None):
+        self.attrConverter = Svg2RlgAttributeConverter()
+        self.shapeConverter = Svg2RlgShapeConverter()
+        self.shapeConverter.svgSourceFile = path
+        self.handledShapes = self.shapeConverter.getHandledShapes()
+        self.drawing = None
+        self.mainGroup = Group()
+        self.definitions = {}
+        self.doesProcessDefinitions = 0
+        self.verbose = 0
+        self.level = 0
+        self.path = path
+        self.logFile = None
+        #if self.path:
+        #    logPath = os.path.splitext(self.path)[0] + ".log"
+        #    self.logFile = open(logPath, 'w')
+
+
+    def render(self, node, parent=None):
+        if parent == None:
+            parent = self.mainGroup
+        name = node.nodeName
+        if self.verbose:
+            format = "%s%s"
+            args = ('  '*self.level, name)
+            #if not self.logFile:
+            #    print format % args
+            #else:
+            #    self.logFile.write((format+"\n") % args)
+
+        if name == "svg":
+            self.level = self.level + 1
+            n = NodeTracker(node)
+            drawing = self.renderSvg(n)
+            children = n.childNodes
+            for child in children:
+                if child.nodeType != 1:
+                    continue
+                self.render(child, self.mainGroup)
+            self.level = self.level - 1
+            self.printUnusedAttributes(node, n)
+        elif name == "defs":
+            self.doesProcessDefinitions = 1
+            n = NodeTracker(node)
+            self.level = self.level + 1
+            parent.add(self.renderG(n))
+            self.level = self.level - 1
+            self.doesProcessDefinitions = 0
+            self.printUnusedAttributes(node, n)
+        elif name == 'a':
+            self.level = self.level + 1
+            n = NodeTracker(node)
+            item = self.renderA(n)
+            parent.add(item)
+            self.level = self.level - 1
+            self.printUnusedAttributes(node, n)
+        elif name == 'g':
+            self.level = self.level + 1
+            n = NodeTracker(node)
+            display = n.getAttribute("display")
+            if display != "none":
+                item = self.renderG(n)
+                parent.add(item)
+            if self.doesProcessDefinitions:
+                id = n.getAttribute("id")
+                self.definitions[id] = item
+            self.level = self.level - 1
+            self.printUnusedAttributes(node, n)
+        elif name == "symbol":
+            self.level = self.level + 1
+            n = NodeTracker(node)
+            item = self.renderSymbol(n)
+            # parent.add(item)
+            id = n.getAttribute("id")
+            if id:
+                self.definitions[id] = item
+            self.level = self.level - 1
+            self.printUnusedAttributes(node, n)
+        elif name in self.handledShapes:
+            methodName = "convert"+name[0].upper()+name[1:]
+            n = NodeTracker(node)
+            shape = getattr(self.shapeConverter, methodName)(n)
+            if shape:
+                self.shapeConverter.applyStyleOnShape(shape, n)
+                transform = n.getAttribute("transform")
+                display = n.getAttribute("display")
+                if transform and display != "none": 
+                    gr = Group()
+                    self.shapeConverter.applyTransformOnGroup(transform, gr)
+                    gr.add(shape)
+                    parent.add(gr)
+                elif display != "none":
+                    parent.add(shape)
+                self.printUnusedAttributes(node, n)
+        else:
+            if LOGMESSAGES:
+                print "Ignoring node: %s" % name
+
+
+    def printUnusedAttributes(self, node, n):
+        allAttrs = self.attrConverter.getAllAttributes(node).keys()
+        unusedAttrs = []
+
+        for a in allAttrs:
+            if a not in n.usedAttrs:
+                unusedAttrs.append(a)
+
+        if self.verbose and unusedAttrs:
+            format = "%s-Unused: %s"
+            args = ("  "*(self.level+1), unusedAttrs.join(", "))
+            #if not self.logFile:
+            #    print format % args
+            #else:
+            #    self.logFile.write((format+"\n") % args)
+
+        if LOGMESSAGES and unusedAttrs:
+            #print "Used attrs:", n.nodeName, n.usedAttrs
+            #print "All attrs:", n.nodeName, allAttrs
+            print "Unused attrs:", n.nodeName, unusedAttrs
+
+
+    def renderTitle_(self, node):
+        # Main SVG title attr. could be used in the PDF document info field.
+        pass
+
+
+    def renderDesc_(self, node):
+        # Main SVG desc. attr. could be used in the PDF document info field.
+        pass
+
+
+    def renderSvg(self, node):
+        getAttr = node.getAttribute
+        width, height = map(getAttr, ("width", "height"))
+        width, height = map(self.attrConverter.convertLength, (width, height))
+        viewBox = getAttr("viewBox")
+        if viewBox:
+            viewBox = self.attrConverter.convertLengthList(viewBox)
+            width, height = viewBox[2:4]
+        self.drawing = Drawing(width, height)
+        return self.drawing
+
+
+    def renderG(self, node, display=1):
+        getAttr = node.getAttribute
+        id, style, transform = map(getAttr, ("id", "style", "transform"))
+        #sw = map(getAttr, ("stroke-width",))
+        self.attrs = self.attrConverter.parseMultiAttributes(style)
+        gr = Group()
+        children = node.childNodes
+        for child in children:
+            if child.nodeType != 1:
+                continue
+            item = self.render(child, parent=gr)
+            if item and display: 
+                gr.add(item)
+
+        if transform:
+            self.shapeConverter.applyTransformOnGroup(transform, gr)
+
+        return gr
+
+
+    def renderSymbol(self, node):
+        return self.renderG(node, display=0)
+
+
+    def renderA(self, node):
+        # currently nothing but a group...
+        # there is no linking info stored in shapes, maybe a group should?
+        return self.renderG(node)
+
+
+    def renderUse(self, node):
+        xlink_href = node.getAttributeNS("http://www.w3.org/1999/xlink", "href")
+        grp = Group()
+        try:
+            item = self.definitions[xlink_href[1:]]
+            grp.add(item)
+            transform = node.getAttribute("transform")
+            if transform:
+                self.shapeConverter.applyTransformOnGroup(transform, grp)
+        except KeyError:
+            if self.verbose and LOGMESSAGES:
+                print "Ignoring unavailable object width ID '%s'." % xlink_href
+
+        return grp
+
+
+    def finish(self):
+        height = self.drawing.height
+        self.mainGroup.scale(1, -1)
+        self.mainGroup.translate(0, -height)
+        self.drawing.add(self.mainGroup)
+        return self.drawing
+
+
+class SvgShapeConverter:
+    """An abstract SVG shape converter.
+
+    Implement subclasses with methods named 'renderX(node)', where
+    'X' should be the capitalised name of an SVG node element for 
+    shapes, like 'Rect', 'Circle', 'Line', etc.
+
+    Each of these methods should return a shape object appropriate
+    for the target format.
+    """
+
+    def __init__(self):
+        self.attrConverter = AttributeConverter()
+        self.svgSourceFile = ''
+
+
+    def getHandledShapes(self):
+        "Determine a list of handled shape elements."
+
+        items = dir(self)
+        items = self.__class__.__dict__.keys()
+        keys = []
+        for i in items:
+            keys.append(getattr(self, i))
+        keys = filter(lambda k:type(k) == types.MethodType, keys)
+        keys = map(lambda k:k.__name__, keys)
+        keys = filter(lambda k:k[:7] == "convert", keys)
+        keys = filter(lambda k:k != "convert", keys)
+        keys = map(lambda k:k[7:], keys)
+        shapeNames = [k.lower() for k in keys]
+
+        return shapeNames
+
+
+class Svg2RlgShapeConverter(SvgShapeConverter):
+    "Converterer from SVG shapes to RLG (ReportLab Graphics) shapes."
+
+    def __init__(self):
+        self.attrConverter = Svg2RlgAttributeConverter()
+        self.svgSourceFile = ''
+
+
+    def convertLine(self, node):
+        getAttr = node.getAttribute
+        x1, y1, x2, y2 = map(getAttr, ("x1", "y1", "x2", "y2"))
+        x1, y1, x2, y2 = map(self.attrConverter.convertLength, (x1, y1, x2, y2))
+        shape = Line(x1, y1, x2, y2)
+
+        return shape
+
+
+    def convertRect(self, node):
+        getAttr = node.getAttribute
+        x, y, width, height = map(getAttr, ('x', 'y', "width", "height"))
+        x, y, width, height = map(self.attrConverter.convertLength, (x, y, width, height))
+        rx, ry = map(getAttr, ("rx", "ry"))
+        rx, ry = map(self.attrConverter.convertLength, (rx, ry))
+        shape = Rect(x, y, width, height, rx=rx, ry=ry)
+
+        return shape
+
+
+    def convertCircle(self, node):
+        # not rendered if r == 0, error if r < 0.
+        getAttr = node.getAttribute
+        cx, cy, r = map(getAttr, ("cx", "cy", 'r'))
+        cx, cy, r = map(self.attrConverter.convertLength, (cx, cy, r))
+        shape = Circle(cx, cy, r)
+
+        return shape
+
+
+    def convertEllipse(self, node):
+        getAttr = node.getAttribute
+        cx, cy, rx, ry = map(getAttr, ("cx", "cy", "rx", "ry"))
+        cx, cy, rx, ry = map(self.attrConverter.convertLength, (cx, cy, rx, ry))
+        width, height = rx, ry
+        shape = Ellipse(cx, cy, width, height)
+
+        return shape
+
+
+    def convertPolyline(self, node):
+        getAttr = node.getAttribute
+        points = getAttr("points")
+        points = points.replace(',', ' ')
+        points = points.split()
+        points = map(self.attrConverter.convertLength, points)
+
+        # Need to use two shapes, because standard RLG polylines
+        # do not support filling...
+        gr = Group()
+        shape = Polygon(points)
+        self.applyStyleOnShape(shape, node)
+        shape.strokeColor = None
+        gr.add(shape)
+        shape = PolyLine(points)
+        self.applyStyleOnShape(shape, node)
+        gr.add(shape)
+
+        return gr
+
+
+    def convertPolygon(self, node):
+        getAttr = node.getAttribute
+        points = getAttr("points")
+        points = points.replace(',', ' ')
+        points = points.split()
+        points = map(self.attrConverter.convertLength, points)
+        shape = Polygon(points)
+
+        return shape
+
+
+    def convertText0(self, node):
+        getAttr = node.getAttribute
+        x, y = map(getAttr, ('x', 'y'))
+        if not x: x = '0'
+        if not y: y = '0'
+        text = ''
+        if node.firstChild.nodeValue:
+            try:
+                text = node.firstChild.nodeValue.encode("ASCII")
+            except:
+                text = "Unicode"
+        x, y = map(self.attrConv.convertLength, (x, y))
+        shape = String(x, y, text)
+        self.applyStyleOnShape(shape, node)
+        gr = Group()
+        gr.add(shape)
+        gr.scale(1, -1)
+        gr.translate(0, -2*y)
+
+        return gr
+
+
+    def convertText(self, node):