hiresbbox=0 is the default, unchanged behaviour.
hiresbbox=1 means that the high resolution bounding box (HiResBoundingBox)
is used rather than the normal one (BoundingBox).
Signed-off-by: Michael J Gruber <[EMAIL PROTECTED]>
---
manual/epsfile.tex | 3 ++-
pyx/epsfile.py | 23 +++++++++++++++--------
2 files changed, 17 insertions(+), 9 deletions(-)
Sometimes a 1pt mismatch can make a difference; this match helps with eps
inclusion in such cases. The default behaviour is unchanged. Specifying
hiresbbox=1 for an eps file which has only an ordinary bbox results in
an error, intentionally so: If the user asks for hires she wants hires.
This patch is against svn r3000. I don't have commit rights (but an sf
account michaeljgruber which may serve as the svn author field).
diff --git a/manual/epsfile.tex b/manual/epsfile.tex
index db250b4..486fa7a 100644
--- a/manual/epsfile.tex
+++ b/manual/epsfile.tex
@@ -39,7 +39,8 @@ horizontal alignment: \texttt{l} for left, \texttt{c} for
center
file? Set to $0$ with care.\\
\texttt{bbox=None} & If given, use \texttt{bbox} instance instead of
bounding box of EPS file.\\
-\texttt{kpsearch=0} & Search for file using the kpathsea library.
+\texttt{kpsearch=0} & Search for file using the kpathsea library.\\
+\texttt{hiresbbox=0} & Use the high resolution bounding box rather than the
normal one.
\end{tabularx}
diff --git a/pyx/epsfile.py b/pyx/epsfile.py
index bb203ac..859f086 100644
--- a/pyx/epsfile.py
+++ b/pyx/epsfile.py
@@ -138,7 +138,7 @@ class linefilereader:
self.file.close()
-def _readbbox(filename):
+def _readbbox(filename, hiresbbox=0):
"""returns bounding box of EPS file filename"""
file = linefilereader(filename)
@@ -147,20 +147,26 @@ def _readbbox(filename):
if not file.readline().startswith("%!"):
raise IOError("file doesn't start with a '%!' header comment")
+ if hiresbbox:
+ bboxmatch = "%%HiResBoundingBox:"
+ bboxtype = float
+ else:
+ bboxmatch = "%%BoundingBox:"
+ bboxtype = int
bboxatend = 0
# parse the header (use the first BoundingBox)
while 1:
line = file.readline()
if not line:
break
- if line.startswith("%%BoundingBox:") and not bboxatend:
+ if line.startswith(bboxmatch) and not bboxatend:
values = line.split(":", 1)[1].split()
if values == ["(atend)"]:
bboxatend = 1
else:
if len(values) != 4:
raise IOError("invalid number of bounding box values")
- return bbox.bbox_pt(*map(int, values))
+ return bbox.bbox_pt(*map(bboxtype, values))
elif (line.rstrip() == "%%EndComments" or
(len(line) >= 2 and line[0] != "%" and line[1] not in
string.whitespace)):
# implicit end of comments section
@@ -214,11 +220,11 @@ def _readbbox(filename):
line = True
while line:
line = file.readline(EOFmsg=None)
- if line.startswith("%%BoundingBox:"):
+ if line.startswith(bboxmatch):
values = line.split(":", 1)[1].split()
if len(values) != 4:
raise IOError("invalid number of bounding box values")
- usebbox = bbox.bbox_pt(*map(int, values))
+ usebbox = bbox.bbox_pt(*map(bboxtype, values))
if not usebbox:
raise IOError("missing bounding box information in document trailer")
return usebbox
@@ -232,7 +238,7 @@ class epsfile(canvasitem.canvasitem):
x, y, filename,
width=None, height=None, scale=None, align="bl",
clip=1, translatebbox=1, bbox=None,
- kpsearch=0):
+ kpsearch=0, hiresbbox=0):
"""inserts epsfile
Object for an EPS file named filename at position (x,y). Width, height,
@@ -241,7 +247,8 @@ class epsfile(canvasitem.canvasitem):
translatebbox is not set, the EPS graphics is not translated to the
corresponding origin. If bbox is not None, it overrides the bounding
box in the epsfile itself. If kpsearch is set then filename is searched
- using the kpathsea library.
+ using the kpathsea library. If hiresbbox is set then the high
resolution
+ bbox is used instead of the normal one.
"""
self.x_pt = unit.topt(x)
@@ -250,7 +257,7 @@ class epsfile(canvasitem.canvasitem):
self.filename = pykpathsea.find_file(filename,
pykpathsea.kpse_pict_format)
else:
self.filename = filename
- self.mybbox = bbox or _readbbox(self.filename)
+ self.mybbox = bbox or _readbbox(self.filename, hiresbbox=hiresbbox)
# determine scaling in x and y direction
self.scalex = self.scaley = scale
--
1.6.0.1.285.g1070
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
PyX-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-devel