summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Weller <ianweller@gmail.com>2008-09-30 22:02:05 -0500
committerIan Weller <ianweller@gmail.com>2008-09-30 22:02:05 -0500
commitd0ace2f9c69a5d897e748060f2421e9b60d6175c (patch)
treef9559d618604454adc56d2d0b7442c2860c01954
parentac99bb9e07378602854b80f331891ec7976fe2c4 (diff)
downloadfedora-business-cards-d0ace2f9c69a5d897e748060f2421e9b60d6175c.zip
fedora-business-cards-d0ace2f9c69a5d897e748060f2421e9b60d6175c.tar.gz
fedora-business-cards-d0ace2f9c69a5d897e748060f2421e9b60d6175c.tar.xz
Switch from cairo to inkscape
Known bug: letters with accents don't work yet. Trying to fix that.
-rw-r--r--fedora_business_cards/export.py37
1 files changed, 13 insertions, 24 deletions
diff --git a/fedora_business_cards/export.py b/fedora_business_cards/export.py
index 9b68451..597c61a 100644
--- a/fedora_business_cards/export.py
+++ b/fedora_business_cards/export.py
@@ -21,16 +21,7 @@
Functions to export cards from SVGs.
"""
-# Thanks much to Jef Spaleta for this code.
-
-import rsvg
-import cairo
-from StringIO import StringIO
-
-if not cairo.HAS_PDF_SURFACE:
- raise SystemExit('cairo was not compiled with PDF support')
-if not cairo.HAS_PNG_FUNCTIONS:
- raise SystemExit('cairo was not compiled with PNG support')
+import subprocess
def svg_to_pdf_png(xmlstring, filename, format='png', dpi=300):
@@ -41,18 +32,16 @@ def svg_to_pdf_png(xmlstring, filename, format='png', dpi=300):
format = either 'png' or 'pdf'
dpi = DPI to export PNG with (default: 300)
"""
- svg = rsvg.Handle(data=xmlstring)
- if format == "pdf":
- pdffile = file(filename, 'w')
+ stdin = xmlstring.encode('iso-8859-1')
+ command = ['inkscape', '-d', str(dpi), '-e', filename, '/dev/stdin']
+ if format == 'png':
+ sp = subprocess.Popen(' '.join(command), shell=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,)
+ sp.communicate(stdin)
+ elif format == 'pdf':
+ command[3] = '-A'
+ sp = subprocess.Popen(' '.join(command), shell=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,)
+ sp.communicate(stdin)
else:
- pdffile = StringIO()
- width = int(svg.props.width/90.*dpi)
- height = int(svg.props.height/90.*dpi)
- surface = cairo.PDFSurface(pdffile, width, height)
- ctx = cairo.Context(surface)
- ctx.scale(dpi/90., dpi/90.)
- svg.render_cairo(ctx)
- if format == "png":
- surface.write_to_png(filename)
- surface.finish()
- pdffile.close()
+ raise Exception("Invalid file format requested")