Hi,
On Wed, Oct 21, 2009 at 12:04:19PM -0400, Alan G Isaac wrote:
> On 10/19/2009 10:03 AM, André Wobst wrote:
> > the issue should be still manageable, as we only need to take into
> > account the path element ends.
> >
> > Still, I don't see somebody just implementing it in the near future.
>
> Understood.
> Perhaps making it easy to get a bounding box from GhostScript
> (if installed) would be worth while? I'm going to guess that
> most PyX users install GhostScript. (?)
then just use my example - maybe changed like this:
def GetBB(c, filename="-", resolution=100,
gscommand="grep -v -E '^%%(HiRes)?BoundingBox' | gs", gsoptions="",
textalphabits=4, graphicsalphabits=4,
ciecolor=False, xshift = 10, yshift = 10, **kwargs):
gscommand += " -dEPSFit -dNOPAUSE -dQUIET -dBATCH -r%i -q -sDEVICE=bbox
-sOutputFile=%s" % (resolution, filename)
if gsoptions:
gscommand += " %s" % gsoptions
if textalphabits is not None:
gscommand += " -dTextAlphaBits=%i" % textalphabits
if graphicsalphabits is not None:
gscommand += " -dGraphicsAlphaBits=%i" % graphicsalphabits
if ciecolor:
gscommand += " -dUseCIEColor"
gscommand += " -"
pipe_in, pipe_out, pipe_err = os.popen3(gscommand)
c1 = canvas.canvas()
c1.insert(c,[trafo.translate(xshift,yshift)])
c1.writeEPSfile(pipe_in, **kwargs)
pipe_in.close()
for line in pipe_err.readlines():
m=re.match(r"^%%HiResBoundingBox: ([-0-9\.]*) ([-0-9\.]*) ([0-9\.]*)
([0-9\.]*)$",line)
if m != None:
b = map(lambda x: unit.length(float(x),unit="pt"), m.groups())
return bbox.bbox(b[0]-xshift,b[1]-yshift,b[2]-10,b[3]-10)
raise IOError("Can't determine BoundingBox")
This includes a simple translation in order to obtain positive bounding
boxes (may be you have to pass larger values for xshift and yshift).
In the example:
c = pyx.canvas.canvas(attrs=[pyx.style.linewidth(1),pyx.style.linejoin(0)])
triangle = path(moveto(0,0), rlineto(6,0))
x,y = pyx.trafo.rotate(120).apply(6,0)
triangle.extend([rlineto(x,y),closepath()])
c.stroke(triangle)
bbox = GetBB(c)
c.writeEPSfile("bbox",bbox=bbox)
I obtain a perfect bounding box;-)
Axel
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user