Giter Club home page Giter Club logo

cairosvg's Introduction

CairoSVG is an SVG converter based on Cairo. It can export SVG files to PDF, EPS, PS, and PNG files.

CairoSVG has been created and developed by Kozea (https://kozea.fr). Professional support, maintenance and community management is provided by CourtBouillon (https://www.courtbouillon.org).

Copyrights are retained by their contributors, no copyright assignment is required to contribute to CairoSVG. Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion is licensed under the LGPL license, without any additional terms or conditions. For full authorship information, see the version control history.

cairosvg's People

Contributors

aziesemer avatar bartmassey avatar bufordsharkley avatar erikonbike avatar eumiro avatar fitnr avatar grewn0uille avatar gsbabil avatar gwenzek avatar hugodelahousse avatar jkocherhans avatar jlugao avatar jpadcoder avatar jwcarr avatar le-stagiaire avatar lize avatar malthe avatar mingaldrichgan avatar mscroggs avatar naddiseo avatar paradoxxxzero avatar ralphbean avatar rianmcguire avatar ricardobeat avatar rtpg avatar silvercardioid avatar simonsapin avatar tgaillar avatar wthie avatar yig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cairosvg's Issues

RGB rendering ?

Hey ! Thanks for the nice package. I intend to use cairosvg to render rgb (numpy) arrays from SVGs. For the moment the obvious way seems to render a PNG with cairosvg and somehow pipe this to a PNG to RGB converter, but it seems like a longcut. Is there a simpler way, to get a RGB rendering without the compression (I know the Python library Cairo can do that) ? Thanks !

Doesn't support ANTIALIAS_FAST

Here is the error

CairoSVG-1.0.9/CairoSVG$ python cairosvg.py ../Comic/001_Teen.svg -f png > 1.png
Traceback (most recent call last):
  File "cairosvg.py", line 25, in <module>
    cairosvg.main()
  File "/home/dev/projects/CairoSVG-1.0.9/CairoSVG/cairosvg/__init__.py", line 93, in main
    SURFACES[output_format.upper()].convert(**kwargs)
  File "/home/dev/projects/CairoSVG-1.0.9/CairoSVG/cairosvg/surface/__init__.py", line 87, in convert
    cls(tree, output, dpi).finish()
  File "/home/dev/projects/CairoSVG-1.0.9/CairoSVG/cairosvg/surface/__init__.py", line 141, in __init__
    self.draw_root(tree)
  File "/home/dev/projects/CairoSVG-1.0.9/CairoSVG/cairosvg/surface/__init__.py", line 194, in draw_root
    self.draw(node)
  File "/home/dev/projects/CairoSVG-1.0.9/CairoSVG/cairosvg/surface/__init__.py", line 324, in draw
    "optimizeSpeed": cairo.ANTIALIAS_FAST,
AttributeError: 'module' object has no attribute 'ANTIALIAS_FAST'

here is the file to test
https://www.amazon.com/clouddrive/share/y-J77coa6eM_HdI9iluJeAU_B8MpRRMUJkhuxZSRxow?ref_=cd_share_link_copy

error in features.py line 60

Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'split'
Exception Location: /usr/local/lib/python2.7/dist-packages/cairosvg/features.py in support_languages, line 60

IndexError: pop from empty list

I'm trying to convert an svg to a pdf using cairosvg v0.4.3. The svg converts fine with inkscape or illustrator. Can anyone tell me if I'm doing something wrong, or what's wrong with my svg file?

You can download the chart.svg file I'm using from here:
https://www.box.com/s/o3qo6w1k45889fom7yq8

Here is the command line I'm using:
cairosvg chart.svg -o chart.pdf

I'm getting the following stack trace:
Traceback (most recent call last):
File "./cairosvg", line 25, in
cairosvg.main()
File "/usr/lib/python3/dist-packages/cairosvg/init.py", line 92, in main
SURFACES[output_format.upper()].convert(**kwargs)
File "/usr/lib/python3/dist-packages/cairosvg/surface/init.py", line 78, in convert
cls(tree, output, dpi).finish()
File "/usr/lib/python3/dist-packages/cairosvg/surface/init.py", line 119, in init
self.draw_root(tree)
File "/usr/lib/python3/dist-packages/cairosvg/surface/init.py", line 312, in draw_root
self.draw(node)
File "/usr/lib/python3/dist-packages/cairosvg/surface/init.py", line 277, in draw
self.draw(child, stroke_and_fill)
File "/usr/lib/python3/dist-packages/cairosvg/surface/init.py", line 277, in draw
self.draw(child, stroke_and_fill)
File "/usr/lib/python3/dist-packages/cairosvg/surface/init.py", line 277, in draw
self.draw(child, stroke_and_fill)
File "/usr/lib/python3/dist-packages/cairosvg/surface/init.py", line 236, in draw
TAGS[node.tag](self, node)
File "/usr/lib/python3/dist-packages/cairosvg/surface/path.py", line 302, in path
draw_marker(surface, node, "end")
File "/usr/lib/python3/dist-packages/cairosvg/surface/defs.py", line 167, in draw_marker
angle1 = node.tangents.pop(0)
IndexError: pop from empty list

Nested svg tags cannot be rendered

Cairo v1.0.9 is failing to produce an output with input which includes nested svg tags like the following example:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <svg x="10">
    <rect x="10" y="10" height="100" width="100" style="stroke:#ff0000; fill: #0000ff"/>
  </svg>
  <svg x="200">
    <rect x="10" y="10" height="100" width="100" style="stroke:#009900; fill: #00cc00"/>
  </svg>
</svg>

Expected output:
image

Nesting SVG elements can be useful to group SVG shapes together, and position them as a collection. All shapes nested inside an svg element will be positioned (x, y) relative to the position (x, y) of its enclosing svg element. By moving the x and y coordinates of the enclosing svg element, you move all the nested shapes too.

cairo not found

cairosvg rpi_cam_body01.svg  -o test.pdf
Traceback (most recent call last):
  File "/usr/local/bin/cairosvg", line 24, in <module>
    import cairosvg
  File "/Library/Python/2.7/site-packages/cairosvg/__init__.py", line 27, in <module>
    from . import surface
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 23, in <module>
    import cairo
ImportError: No module named cairo

Don't lowercase ids in CSS

Hello!

Inkscape generates linearGradients like the following:

<linearGradient
   id="linearGradient3857">
  <stop
     style="stop-color:#e56e00;stop-opacity:1;"
     offset="0"
     id="stop3859" />
  <stop
     style="stop-color:#871500;stop-opacity:1;"
     offset="1"
     id="stop3861" />
</linearGradient>
<linearGradient
   inkscape:collect="always"
   xlink:href="#linearGradient3857"
   id="linearGradient3863"
   x1="165"
   y1="157.36218"
   x2="165"
   y2="92.362183"
   gradientUnits="userSpaceOnUse" />

So essentially, the stops are defined in a first linearGradient definition and then a second linearGradient instance is created to give coordinates to those stops. The weird thing is that the Inkscape linearGradients do not render. Here's a minimal example that should reproduce the issue:

<svg width="250" height="150" viewBox="0 0 250 150"
  xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink">

  <defs>
    <linearGradient
       id="linearGradient0011"
       x1="0"
       y1="0"
       x2="0"
       y2="150"
       gradientUnits="userSpaceOnUse">
      <stop
        offset="0%"
        style="stop-color: #000080; stop-opacity:1"/>
      <stop
        offset="100%"
        style="stop-color: #005cdb; stop-opacity:1"/>
    </linearGradient>
  </defs>

  <rect x="20" y="20" width="200" height="100"
    style="fill: url(#linearGradient0011);  stroke: black;"/>
</svg>

If instead I simply replace "linearGradient0011" by anything else in this code, the gradient is actually rendered, so the following is correctly rendered for me:

<svg width="250" height="150" viewBox="0 0 250 150"
  xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink">

  <defs>
    <linearGradient
       id="lolcat"
       x1="0"
       y1="0"
       x2="0"
       y2="150"
       gradientUnits="userSpaceOnUse">
      <stop
       offset="0%"
       style="stop-color: #000080; stop-opacity:1"/>
      <stop
        offset="100%"
        style="stop-color: #005cdb; stop-opacity:1"/>
    </linearGradient>
  </defs>

  <rect x="20" y="20" width="200" height="100"
    style="fill: url(#lolcat);  stroke: black;"/>
</svg>

Simply in the interest of keeping compatibility with Inkscape, it would be nice to fix this issue. I'm trying to track it down myself, but since I'm not familiar at all with the code, anyone may be faster.Let me know if the problem is reproducible at all, I'm working on MacOS Yosemite. CairoSVG is really nice btw!

didn't suport <text> taget

when i using

cairosvg.svg2png(bytestring=svg,write_to=png)

if the svg content containt "" target ,and there are throw Exception , Exception in below .

File "/data/hg/sites/sf_017/survey/docx_utils.py", line 171, in create_svg
cairosvg.svg2png(bytestring=svg_sign+svg,write_to=fout)
File "/data/hg/wenjuan_env/lib/python2.7/site-packages/cairosvg/__init__.py", line 43, in 
surface_type.convert(*args, **kwargs))(_surface_type)
File "/data/hg/wenjuan_env/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 84, in convert
cls(tree, output, dpi).finish()
File "/data/hg/wenjuan_env/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 138, in __init__
self.draw_root(tree)
File "/data/hg/wenjuan_env/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 191, in draw_root
self.draw(node)
File "/data/hg/wenjuan_env/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 344, in draw
self.draw(child)
File "/data/hg/wenjuan_env/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 300, in draw
TAGS[node.tag](self, node)
File "/data/hg/wenjuan_env/lib/python2.7/site-packages/cairosvg/surface/text.py", line 93, in text
text_extents = surface.context.text_extents(node.text)
MemoryError

The -d flag on cairosvg has no effect

I am trying to use cairosvg.py (the executable) to scale an image to be bigger than it's svg dimensions. Looking at the help note -d 500 or --dpi=500 should be enough, however the image generated is the same size as the image generated id the -d flag is not included (and yes I have used dpi numbers other than 500, default is said to be 96)

cairosvg test.svg -f png -o test1.png -d 500

Denied image requests

Just ran into an error where cloudfare denied a request for an image when trying to convert from an svg to a pdf. I'm using 1.0.13. Here's a reduced test case:

<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="300" height="300" version="1.1">
  <image x="0" y="0" width="208" height="156"
         xlink:href="http://www.survivingcollege.com/wp-content/uploads/2013/03/Stanford-Tree-Logo-Mascot-Monday.jpg">
  </image>
</svg>
cairosvg test.svg test.pdf

Traceback (most recent call last):
  File "/usr/local/bin/cairosvg", line 25, in <module>
    cairosvg.main()
  File "/Library/Python/2.7/site-packages/cairosvg/__init__.py", line 93, in main
    SURFACES[output_format.upper()].convert(**kwargs)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 87, in convert
    cls(tree, output, dpi).finish()
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 141, in __init__
    self.draw_root(tree)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 394, in draw_root
    self.draw(node)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 350, in draw
    self.draw(child)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 303, in draw
    TAGS[node.tag](self, node)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/image.py", line 119, in image
    url=url, bytestring=image_bytes, tree_cache=surface.tree_cache)
  File "/Library/Python/2.7/site-packages/cairosvg/parser.py", line 270, in __init__
    tree = ElementTree.fromstring(bytestring)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1300, in XML
    parser.feed(text)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1642, in feed
    self._raiseerror(v)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: undefined entity: line 29, column 65

%PDF-1.5
%????
3 0 obj
<< /Length 4 0 R
   /Filter /FlateDecode
>>
stream
x?+?
???
endstream
endobj
4 0 obj
   12
endobj
2 0 obj
<<
>>
endobj
5 0 obj
<< /Type /Page
   /Parent 1 0 R
   /MediaBox [ 0 0 225 225 ]
   /Contents 3 0 R
   /Group <<
      /Type /Group
      /S /Transparency
      /I true
      /CS /DeviceRGB
   >>
   /Resources 2 0 R
>>
endobj
1 0 obj
<< /Type /Pages
   /Kids [ 5 0 R ]
   /Count 1
>>
endobj
6 0 obj
<< /Creator (cairo 1.12.16 (http://cairographics.org))
   /Producer (cairo 1.12.16 (http://cairographics.org))
>>
endobj
7 0 obj
<< /Type /Catalog
   /Pages 1 0 R
>>
endobj
xref
0 8
0000000000 65535 f 
0000000360 00000 n 
0000000125 00000 n 
0000000015 00000 n 
0000000104 00000 n 
0000000146 00000 n 
0000000425 00000 n 
0000000554 00000 n 
trailer
<< /Size 8
   /Root 7 0 R
   /Info 6 0 R
>>
startxref
606
%%EOF

The same file works fine using wkhtmltopdf

wkhtmltopdf test.svg test.pdf

Any ideas why cloudfare would permit the request from wkhtmltopdf and deny it for cairo?

A Switch to Set Page Scaling to None

PDF 1.6 has an option to specify that the page scaling can be set to None. In some cases this would eliminate the need for users to modify default print settings in order to prevent the printer from shrinking the PDF and adding margins. For example, the switch --noscaling would cause cairosvg to add the required option/property. I have no idea how hard this would be, or even if it's possible. But if you could, this would be extremely useful to me (and anyone designing forms etc which must be printed without scaling).

Importing cairosvg fails on Python 3 in a virtualenv

After I set up a Python 3 virtualenv and install cairosvg, importing it fails with ImportError: cannot import name surface.

The full procedure to reproduce it is:

~ ★ mkdir temp
~ ★ cd temp
temp ★ virtualenv -p /usr/bin/python3.3 p3test
Running virtualenv with interpreter /usr/bin/python3.3
Using base prefix '/usr'
New python executable in p3test/bin/python3.3
Also creating executable in p3test/bin/python
Installing setuptools, pip...done.
temp ★ . p3test/bin/activate
(p3test)temp ★ pip install cairosvg
Downloading/unpacking cairosvg
  Downloading CairoSVG-1.0.4.tar.gz
  Running setup.py (path:/home/jason/temp/p3test/build/cairosvg/setup.py) egg_info for package cairosvg

Installing collected packages: cairosvg
  Running setup.py install for cairosvg
    changing mode of build/scripts-3.3/cairosvg from 664 to 775

    changing mode of /home/jason/temp/p3test/bin/cairosvg to 775
Successfully installed cairosvg
Cleaning up...
(p3test)temp ★ python
Python 3.3.0 (default, Sep 25 2013, 19:28:08) 
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairosvg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jason/temp/p3test/lib/python3.3/site-packages/cairosvg/__init__.py", line 27, in <module>
    from . import surface
ImportError: cannot import name surface
>>> 

Make a PyPI release

There was many changes since the PyPI release (including compat with cairocffi.) It’s time to make a new one. Releases are cheap.

Compatibility with OS X

Hi guys,

I'm contributor of a french open source project and we would like to integrate the support of SVG files. For that, we think to use CairoSVG. Your library works fine with linux but when I would like to use it on OS X, it cannot find import of cairo.

I'm trying to install it with:

sudo port install py27-cairo

But this solution didn't work.

Do you have any ideas about the compatibility with OS X?

Wrong translation caused by viewboxes

Here is an example:

<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" width="150mm" height="150mm" viewBox="26 6 34.2 34" fill-rule="evenodd" fill-opacity="0.3">
  <path id="letter" d="M 54,33 C 62,25 54,12 33,13 C 32,34 46,42 54,33 Z M 43,6 C 19,6 22,40 44,40 C 66,40 66,6 43,6 Z" fill="#5c8182"/>
  <circle id="dot" cx="46" cy="26" r="7" fill="#fd9105"/>
</svg>

pip install fails

I am trying to install in a clean virtualenv. I tried both pip install cairosvg and sudo pip install cairosvg.

I get the following error (copied from the tail of the pip.log)

Exception information:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip-1.4.1-py2.7.egg/pip/basecommand.py", line 134, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.4.1-py2.7.egg/pip/commands/install.py", line 241, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.4.1-py2.7.egg/pip/req.py", line 1298, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.4.1-py2.7.egg/pip/req.py", line 625, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "/usr/local/lib/python2.7/dist-packages/pip-1.4.1-py2.7.egg/pip/util.py", line 670, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip_build_root/cffi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-OivIFM-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip_build_root/cffi

Details on fonts documented?

We're trying to convert SVGs that work in browsers to work with CairoSvg.

I see that woff, otf, svg, ttf are included in the resources directory. Are all of these supported?

Where's the best place for information on how to integrate fonts using CSS style sheets? And are external CSS style sheets supported?

Opacity problem in converted png

Hi folks,

We've been using CairoSVG to convert FusionCharts data to PNG, and it's great! However, we're encountering a bug with one chart type, where some circles that should be opaque are transparent.

The svg string comes directly from the getSVGString() method of our FusionCharts charts. If I save this string as an svg file locally and open it in Illustrator or a browser, it looks fine. Here is the svg data: http://pastebin.com/GG0vqWF4

Here is what the image is supposed to look like: http://pbrd.co/1nE9y11

But in the png returned to the browser, all the circles are empty: http://pbrd.co/1nE9IFL

Here's Python code that handles the conversion:

import cherrypy
import cairocffi as cairo
import cairosvg
...

class SaveImagePage(LoggedInPage):
    @cherrypy.expose
    def index(self, svgString, **params):
        png = cairosvg.svg2png(svgString)

        cherrypy.response.headers['content-type'] = 'image/png'
        cherrypy.response.headers['content-disposition'] = \
            'attachment; filename="BrandIndex Chart.png"'

        return png

Any ideas? I haven't worked with the svg format much, and neither Cairo nor CairoSVG are throwing errors here. I posted this to stackoverflow, and someone there suggested it might be a bug in CairoSVG; let me know if this is likely, or if you think it's a problem on our end. Thanks!!

DPI For PNG Conversions?

The dpi option doesn't seem to have any effect when converting an SVG to a PNG. I dug into the source a bit and saw that PNGSurface's device_units_per_user_units is hardcoded to 1. Right now I'm working around this with a subclass of PNGSurface, but I'm not sure if this is expected behavior or not.

Create Cairo path from SVG file

Hey everybody,

I came across your project, when I was looking for a way to reshape and rescale multiple SVG-files. The paths from that SVG-files should be later used to extraxt parts of PNG-images. (Just using the PNGs as source and the paths from the SVGs)

Now my question:
Is there a way to do that with cairosvg?
Or for example to extract the paths from SVG files, with cairosvg?

Thanks for your help!

Jitos

CSS specificity: !important in style declaration was not applied to SVG elements

Consider following style declaration inside svg element .

<defs id="defs3023">
   <style type="text/css">
    text {
        fill: #ffffff !important;
    }
    </style>
</defs>

The style above will not overwrite the inline style declared in svg elements eg..

<text
       xml:space="preserve"
       style="font-size:48px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       x="891.28571"
       y="184.51617"
       id="text3061"
       sodipodi:linespacing="125%"><tspan
         sodipodi:role="line"
         id="tspan3063"
         x="891.28571"
         y="184.51617"
         style="font-size:32px">Generowany prostokąt</tspan></text>

While in browser, the !important will take the priority. The text inside the svg will be showing in white colour.

Division by zero error when gradient nodes have no set height or width

Hi! We've been using CairoSVG to convert FusionCharts SVG data to PNG files. Today I ran into the following error from surface/defs.py, line 194:

width = 0.0, height = 0.0, x = 0.0, y = 0.0
<type 'exceptions.ZeroDivisionError'>: float division by zero 
      args = ('float division by zero',) 
      message = 'float division by zero'

Full traceback: http://pastebin.com/8P1A5vhA

On inspection, it seems like the issue occurs because the following gradient node we're trying to render has no specified height or width:

<path fill="url('http://localhost:8084/charts#97790-rgba_205_144_92_1_:0-rgba_205_144_92_1_:30-rgba_235_211_190_1_:60-rgba_205_144_92_1_:90-rgba_205_144_92_1_:100')" stroke="#7b5637" d="M7,35L7,27.3L9.75,27.3L9.75,35ZM11.125,35L11.125,24L13.875,24L13.875,35ZM15.25,35L15.25,30.6L18,30.6L18,35Z" stroke-width="0.5" opacity="1" fill-opacity="1" style="opacity: 1; fill-opacity: 1; cursor: pointer;"></path>

I'm not very familiar with SVG generally; is it considered invalid to have a node with no height or width? This code is coming directly from FusionCharts, so if it's a bug on their end, we'll take it up with them.

In the meantime, I was able to hack in a workaround in surface/defs.py by catching zero values for height and width in draw_gradient() and changing them to 1. :P This was just an experiment, and lets us render our chart PNG images successfully, but I assume there's a better solution.

If you know how to fix this or have any advice, would love to hear it! And thanks so much for your work - this project has been hugely useful to us!

Enhance the text management

A lot of features (text on a path, text rotation, etc.) are not correctly handled. Rewriting text.py the module should help to solve most of these problems.

TypeError: object of type 'NoneType' has no len()

Error output:

Traceback (most recent call last):
  File "/usr/local/bin/cairosvg", line 25, in <module>
    cairosvg.main()
  File "/Library/Python/2.7/site-packages/cairosvg/__init__.py", line 92, in main
    SURFACES[output_format.upper()].convert(**kwargs)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 79, in convert
    tree = Tree(**kwargs)
  File "/Library/Python/2.7/site-packages/cairosvg/parser.py", line 236, in __init__
    apply_stylesheets(tree)
  File "/Library/Python/2.7/site-packages/cairosvg/css.py", line 96, in apply_stylesheets
    for rule in find_style_rules(tree):
  File "/Library/Python/2.7/site-packages/cairosvg/css.py", line 58, in find_style_rules
    for stylesheet in find_stylesheets(tree):
  File "/Library/Python/2.7/site-packages/cairosvg/css.py", line 52, in find_stylesheets
    yield tinycss.make_parser().parse_stylesheet(element.text)
  File "/Library/Python/2.7/site-packages/tinycss/css21.py", line 394, in parse_stylesheet
    tokens = tokenize_grouped(css_unicode)
  File "/Library/Python/2.7/site-packages/tinycss/tokenizer.py", line 203, in tokenize_grouped
    return regroup(tokenize_flat(css_source, ignore_comments))
  File "speedups.pyx", line 93, in tinycss.speedups.tokenize_flat (tinycss/speedups.c:1904)
TypeError: object of type 'NoneType' has no len()

SVG file: http://upload.wikimedia.org/wikipedia/commons/3/36/Flag_of_Albania.svg
(I get the same error for other flags from wikipedia as well)

svg2png output for clipped path does not match Inkscape's

When I use svg2png to render the SVG document below, the result looks quite different from what Inkscape or Google Chrome render. Inkscape's output is what I was expecting.

I'm using CairoSVG 1.0.4 in a Python 3 virtualenv on Ubuntu 12.10. Dependency versions are:

cairocffi==0.5.1
cffi==0.8.1
cssutils==1.0
lxml==3.3.1
Pillow==2.3.0

To get the Inkscape output:

inkscape -f testout.svg -e testout_inkscape.png

To get the cairosvg output:

(p3)dungeon ★ python
Python 3.3.0 (default, Sep 25 2013, 19:28:08) 
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cairosvg import svg2png
>>> with open("testout.svg", "rb") as fp:
...   svg2png(fp.read(), write_to="testout_cairosvg.png")
... 
>>>

Since I can't upload SVG to Github, I've pasted it below. I've uploaded it here as well.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   width="1000.0" height="1200.0"
   id="test"
   version="1.1"
   inkscape:version="0.48.4 r"
   sodipodi:docname="test">
 <defs id="defs1">
  <rect
   id="test-square"
   width="500" height="500"
   x="0" y="0"
   style="fill-opacity: 1; fill: #000077"/>
  <clipPath id="clip-path-test-inverted" clipPathUnits="userSpaceOnUse">
   <path
    id="clip-path-test-path-inverted"
    d="M 0.0 0.0
       L 0.0 1200.0
       L 1000.0 1200.0
       L 1000.0 0.0
       Z
       M 300.0 500.0
       C 300.0 500.0 300.0 500.0 300.0 500.0
       C 300.0 500.0 300.0 500.0 300.0 500.0
       C 300.0 500.0 300.0 700.0 300.0 700.0
       C 300.0 700.0 500.0 700.0 500.0 700.0
       C 500.0 700.0 500.0 500.0 500.0 500.0
       C 500.0 500.0 300.0 500.0 300.0 500.0
       M 400.0 0.0
       C 400.0 0.0 400.0 0.0 400.0 0.0
       C 400.0 0.0 600.0 0.0 600.0 0.0
       C 600.0 0.0 600.0 400.0 600.0 400.0
       C 600.0 400.0 800.0 400.0 800.0 400.0
       C 800.0 400.0 800.0 600.0 800.0 600.0
       C 800.0 600.0 1000.0 600.0 1000.0 600.0
       C 1000.0 600.0 1000.0 800.0 1000.0 800.0
       C 1000.0 800.0 800.0 800.0 800.0 800.0
       C 800.0 800.0 800.0 1000.0 800.0 1000.0
       C 800.0 1000.0 600.0 1000.0 600.0 1000.0
       C 600.0 1000.0 600.0 1200.0 600.0 1200.0
       C 600.0 1200.0 400.0 1200.0 400.0 1200.0
       C 400.0 1200.0 400.0 900.0 400.0 900.0
       C 400.0 900.0 100.0 900.0 100.0 900.0
       C 100.0 900.0 100.0 300.0 100.0 300.0
       C 100.0 300.0 400.0 300.0 400.0 300.0
       C 400.0 300.0 400.0 0.0 400.0 0.0
       Z"
    style="fill:#000000;fill-opacity:1;stroke:none"/>
  </clipPath>
 </defs>
 <g clip-path="url(#clip-path-test-inverted)">
  <use x="0"   y="0"    xlink:href="#test-square"/>
  <use x="0"   y="500"  xlink:href="#test-square"/>
  <use x="0"   y="1000" xlink:href="#test-square"/>
  <use x="500" y="0"    xlink:href="#test-square"/>
  <use x="500" y="500"  xlink:href="#test-square"/>
  <use x="500" y="1000" xlink:href="#test-square"/>
 </g>
</svg>

The SVG file was originally made in Inkscape, but simplified by hand. I've attached the PNG output I get from both programs.

Inkscape output:

testout_inkscape

svg2png output:

testout_cairosvg

TypeError: Matrix.__init__() takes at most 6 arguments (8 given)

cairosvg rpi_cam_body01.svg  -o test.pdf
Traceback (most recent call last):
  File "/usr/local/bin/cairosvg", line 25, in <module>
    cairosvg.main()
  File "/Library/Python/2.7/site-packages/cairosvg/__init__.py", line 92, in main
    SURFACES[output_format.upper()].convert(**kwargs)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 84, in convert
    cls(tree, output, dpi).finish()
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 135, in __init__
    self.draw_root(tree)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 362, in draw_root
    self.draw(node)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 324, in draw
    self.draw(child, stroke_and_fill)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 324, in draw
    self.draw(child, stroke_and_fill)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 214, in draw
    transform(self, node.get("transform"))
  File "/Library/Python/2.7/site-packages/cairosvg/surface/helpers.py", line 203, in transform
    matrix = cairo.Matrix(*values).multiply(matrix)
TypeError: Matrix.__init__() takes at most 6 arguments (8 given)

Consider shipping tests with the tarball

You might consider shipping the tests/ directory with the distributed tar ball so that end users can run them on their systems to make sure cairosvg will work.

Linux distributions like to do this as a part of our build process where possible.

Empty output is produced for this SVG

However, browser and batik-rasterizer both produce correct image.
Target SVG:

<svg style="overflow: hidden; position: relative;"
    xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    width="1024" version="1.1" height="536">
    <image transform="matrix(1,0,0,1,0,0)" 
       preserveAspectRatio="none"
       x="365" y="145"
       width="200" height="200"
       xlink:href="flower.svg"></image>
</svg>

flower.svg:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<svg xmlns="http://www.w3.org/2000/svg"
   viewBox="0 0 752.3 737.93"
   version="1.1"
   width="100%"
   height="100%"
   >

  <path
     id="use5347"
     d="M456.62,5.3125c-31.25,0-59.65,12.236-80.65,32.188-20.83-19.05-48.58-30.688-79.03-30.688-40.635,0-76.433,20.7-97.438,52.125-39.235,1.1855-76.966,22.045-98.031,58.531-15.63,27.07-19.246,57.77-12.47,85.94-26.914,8.51-50.866,26.72-66.094,53.09-20.312,35.18-20.262,76.51-3.562,110.41-18.605,34.57-19.415,77.69,1.656,114.18,15.629,27.07,40.406,45.535,68.188,53.75-6.0815,27.567-2.2898,57.407,12.938,83.781,20.319,35.193,56.156,55.867,93.875,58.344,20.646,33.38,57.561,55.625,99.688,55.625,31.258,0,59.651-12.236,80.656-32.188,20.833,19.05,48.577,30.688,79.031,30.688,40.622,0,76.398-20.687,97.406-52.094,39.247-1.1753,76.991-22.035,98.062-58.531,15.629-27.07,19.214-57.802,12.438-85.969,26.914-8.5167,50.866-26.719,66.094-53.094,20.318-35.192,20.307-76.534,3.5938-110.44,18.583-34.569,19.406-77.675-1.6562-114.16-15.629-27.07-40.437-45.535-68.219-53.75,6.0815-27.567,2.2898-57.407-12.938-83.781-20.31-35.17-56.1-55.813-93.81-58.301-20.64-33.396-57.58-55.656-99.72-55.656z"
     stroke="#FFF"
     stroke-dasharray="none"
     stroke-miterlimit="4"
     stroke-width="3.54330709"
     style="fill:#cccccc;fill-opacity:1" />
</svg>

Cairosvg rendered pdf is slow and heavy

Hey Folks,

I realize this might be an upstream issue but I'm curious to see if you can help. I've been
using cairosvg to handle visualization downloads on my site: http://atlas.cid.harvard.edu/explore/tree_map/export/jpn/all/show/2012/ (hit the PDF link on the right toolbar).

So far it's been working great but I've received complaints about the generated pdfs being very slow to load and crashing preview on OSX. I've reproduced the issue in the firefox pdf.js renderer (very slow), the chrome builtin one (workable) and preview.app (hangs). I thought it may have something to do with the number of elements in the PDF since with smaller countries it seems to load much easier (e.g. try Fiji).

At that point I would chalk it up to the renderers being slow but someone I know took the SVG, loaded it up in illustrator and exported as PDF, and that renders almost instantly, and the file size is much smaller too. Is there any insight into what that might be doing that I am not? I know it's not rasterizing it, but it seems it's optimizing it somehow.

I'm really just looking for pointers here, and hoping you're more experienced at this than I am.

Here's a prettified version of one of the svgs for your convenience:
https://gist.github.com/makmanalp/f630625df0bdf40b61b5

Thanks,
~mali

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.