From d6f114694237c686e105ed4fd41a1ee195d5b921 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Wobst?= Date: Thu, 12 May 2011 22:49:46 +0000 Subject: [PATCH] import EPS in PDF using a transparent bitmap (this is ugly but it works and it is better than nothing, requires PIL) git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@3056 069f4177-920e-0410-937b-c2a4a81bcd90 --- CHANGES | 2 ++ pyx/epsfile.py | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 341189c9..913d6d66 100644 --- a/CHANGES +++ b/CHANGES @@ -148,6 +148,8 @@ TODO: - remove incorrect zero length line in PDF output for each first moveto path element (thanks to Michael J Gruber) - raise correct normpath exception (thanks to Axel Freyn) + - epsfile module: + - an ugly way to import EPS in PDF using a bitmap (requires PIL) 0.10 (2007/10/03): diff --git a/pyx/epsfile.py b/pyx/epsfile.py index bb203ac2..72a94065 100644 --- a/pyx/epsfile.py +++ b/pyx/epsfile.py @@ -20,7 +20,7 @@ # along with PyX; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -import string +import os, string, tempfile, warnings import canvasitem, bbox, pykpathsea, unit, trafo, pswriter # PostScript-procedure definitions (cf. 5002.EPSF_Spec_v3.0.pdf) @@ -335,4 +335,20 @@ class epsfile(canvasitem.canvasitem): file.write("EndEPSF\n") def processPDF(self, file, writer, context, registry, bbox): - raise RuntimeError("Including EPS files in PDF files not supported") + warnings.warn("EPS file is included as a bitmap created using pipeGS") + from pyx import bitmap, canvas + import Image + c = canvas.canvas() + c.insert(self) + fd, fname = tempfile.mkstemp() + f = os.fdopen(fd, "wb") + f.close() + c.pipeGS(fname, device="pngalpha", resolution=600) + i = Image.open(fname) + os.unlink(fname) + b = bitmap.bitmap_pt(self.bbox().llx_pt, self.bbox().lly_pt, i) + # we slightly shift the bitmap to re-center it, as the bitmap might contain some additional border + # unfortunately we need to construct another bitmap instance for that ... + b = bitmap.bitmap_pt(self.bbox().llx_pt + 0.5*(self.bbox().width_pt()-b.bbox().width_pt()), + self.bbox().lly_pt + 0.5*(self.bbox().height_pt()-b.bbox().height_pt()), i) + b.processPDF(file, writer, context, registry, bbox) -- 2.11.4.GIT