summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Weller <ianweller@gmail.com>2008-09-27 21:20:34 -0500
committerIan Weller <ianweller@gmail.com>2008-09-27 21:20:34 -0500
commit64b925b4c193d618e7b7a5b6b4de6bcb56dd56af (patch)
treeb5124e277531a5fff6b151ba3870b58c80c304d1
parent1d73b069fb2dde02b302961cf9ed32d3d36b3bd7 (diff)
downloadfedora-business-cards-64b925b4c193d618e7b7a5b6b4de6bcb56dd56af.zip
fedora-business-cards-64b925b4c193d618e7b7a5b6b4de6bcb56dd56af.tar.gz
fedora-business-cards-64b925b4c193d618e7b7a5b6b4de6bcb56dd56af.tar.xz
Apply spoleeba's patch to remove Inkscape
-rw-r--r--Makefile7
-rw-r--r--generate.py30
2 files changed, 30 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 1df564b..3ec15fa 100644
--- a/Makefile
+++ b/Makefile
@@ -6,12 +6,9 @@ CONVERT = /usr/bin/convert
all: out.png back.png
-out.svg:
+out.svg out.png out.pdf:
$(GENERATE) $(GENERATE_OPTIONS)
-out.png: out.svg
- $(INKSCAPE) $(INKSCAPE_OPTIONS) --export-area-canvas --export-png=$@ $<
-
back.png: back.svg
$(INKSCAPE) $(INKSCAPE_OPTIONS) --export-area-canvas --export-png=$@ $<
@@ -22,4 +19,4 @@ bleed16.png: out.png bleed16-under.png
$(CONVERT) bleed16-under.png out.png -geometry +19+19 -composite bleed16.png
clean:
- rm -f out.svg out.png bleed16-under.png bleed16.png back.png
+ rm -f out.svg out.png out.pdf bleed16-under.png bleed16.png back.png
diff --git a/generate.py b/generate.py
index 154bc63..a87498d 100644
--- a/generate.py
+++ b/generate.py
@@ -32,6 +32,15 @@ import re
import subprocess
from getpass import getpass
from xml.dom import minidom
+import rsvg
+import cairo
+import sys
+
+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')
+
VALID_INFO = ['email', 'phone', 'irc', 'url', 'gpgid', 'gpgfingerprint',
'blank']
@@ -65,6 +74,19 @@ class BusinessCardError(ValueError):
return "No GPG key ID for %s, use override" % self.args[0]
+def svg_to_pdf_png(basename=None,xmlstring=None):
+ # thanks, spoleeba
+ svg = rsvg.Handle(data=xmlstring)
+ pdfname=basename+'.pdf'
+ pngname=basename+'.png'
+ pdffile = file(pdfname, 'w')
+ surface = cairo.PDFSurface(pdffile, svg.props.width, svg.props.height)
+ ctx = cairo.Context(surface)
+ svg.render_cairo(ctx)
+ surface.write_to_png(pngname)
+ surface.finish()
+ pdffile.close()
+
def get_gpg_fingerprint(keyid):
"""
Gets the GPG fingerprint from the key ID.
@@ -111,7 +133,11 @@ def gen_front(name, title, lines, outfile):
for i in range(6):
node = find_node(dom, 'tspan', 'id', 'line%d' % (i+1))
node.appendChild(dom.createTextNode(lines[i]))
- out = file(outfile, "w")
+ hmm=dom.toxml()
+ print dir(hmm)
+ svg_to_pdf_png(basename=outfile,xmlstring=dom.toxml())
+ svgfile=outfile+'.svg'
+ out = file(svgfile, "w")
out.write(dom.toxml())
out.close()
@@ -186,7 +212,7 @@ def main():
for i in info:
lines.append(overrides[i] or infodict[i])
gen_front(overrides['name'] or infodict['name'], overrides['title'] or
- infodict['title'], lines, 'out.svg')
+ infodict['title'], lines, 'out')
if __name__ == "__main__":
main()