Advice sought on ps module

Eddie Corns eddie at holyrood.ed.ac.uk
Fri Jun 21 07:24:36 EDT 2002


hjwidmaier at web.de (Hans-Joachim Widmaier) writes:

>eddie at holyrood.ed.ac.uk (Eddie Corns) wrote in message news:<aesoqg$kc9$1 at scotsman.ed.ac.uk>...

>> I'm not sure that I understand completely what you're trying to do so maybe
>> I'm barking up the wrong gum tree here but ...

>I admit that my writing wasn't very clear ...
> 
>> Surely you want to use postscript itself to do all the work.  PS already has
>> an operator called stringwidth and a complete set of programming constructs so
>> the trick usually is to generate the appropriate PS commands.

>That's how I do it today. Well, I should have given a more concrete
>example. I've written a program that creates good looking timing
>diagrams for documentation purposes. These consist of a drawing part
>and signal names to the left. While the python program knows exactly
>how large the drawing itself is, it has no way of knowing how far the
>signal names extend to the left, making it all but impossible to give
>a valid boundig box for the whole thing -- which is required, as it's
>going to be an EPS file. Sure, I can get at the BBox by piping the
>finished file through one of the ps utils programs, but this is kinda
>cumbersome. And it still doesn't allow me to adjust the right-hand
>drawing width so the combined width is of some fixed size.

OK, that looks like a fairly complex job.  The only other suggestion I can
make is to wonder whether you're getting too hung up on precision.  Does the
BBox really need to be pixel perfect?  I know myself how easy it is, when you
know a perfect solution _should_ be possible, to get fixated on it instead of
just saying, well take the longest string and assume len * em width and see
whether it looks OK (eg would another person notice?).  OK, I'm sure you
wouldn't have gone to the effort of messing about with font metrics for
nothing but don't forget 'good enough' solutions are just that!

>Another example: In my CD cover/inlay generator I have to do insert
>line breaks if the Title+Singer+Time line doesn't fit. I do this in
>PostScript, as I don't know the width in the Python program. This has
>the drawback that the height of the title list changes and my careful
>layout (not to be taken too seriously) is disrupted. And no, I do
>*not* want to write a layout engine in PostScript.

I'm not particularly into PostScript but I have seen a few amazing packages
from time to time, whether you can find something usable though.

>Despite having read most of the PostScript Reference Manual, the AFM
>spec, the DSC specs, etc., ... and having written a bunch of programs
>that output PostScript, I still consider myself a novice (at best!).
>This reverse notation thing with all those stacks gives me the creeps.
>;-)

It's a really elegant model and very suitable in domains where efficiency is
important (like page markup).  I made some effort to learn forth and a little
bit of PS and I thought it was fun but rather too much hard work to do every
day!

>Hope these explanations make the misery I'm in somewhat more clear.

Misery to me is NOT having a challenging programming project :)
Sorry I can't be of any help after all but good luck anyway.

Eddie
P.S.(!!) don't forget comp.lang.postscript

P.P.S. Actually it occurs to me there is another solution, namely creating the
diagram with something else (eg a canvas) and generating (presumably
bitmapped) PS from that.  Though I'm sure you've already rejected that idea as
being unworthy!



More information about the Python-list mailing list