<OT> postscript question: Justify text

Alan Jackson ajackson
Mon May 17 11:31:24 PDT 2004


What are you actually trying to do? I know a bit about text formatting and
PostScript, but I'm not clear on what your real goal is.

On Sat, 18 May 2002 18:57:57 -0700  "Kevin O'Gorman" wrote:
> There's nothing very simple about using Postscript directly; it's not
> actually designed for that, it seems.
> 
> You can indeed stretch the line with ashow, but be aware that this method
> only looks acceptable for VERY small amounts of added space.  As the
> added amount gets bigger, you lose visual track of where the real spaces are.
> You're much better off with widthshow, but you'd have to count the
> space characters yourself.
> 
> If you're going to stick with ashow, you can use the stringwidth operator
> to count characters, and divide the extra space among them.  You might
> have to use the length-1; I've never tried it.  If you want to count
> space characters, you probably want the forall operator.
> 
> To count, try this:
> 
> /countspace {32 eq {1 add} if} bind def
> /countspaces {0 exch {countspace} for} bind def
> 
> (a b c) countspaces
>  
> This should leave the integer 2 on the stack.  But then I haven't tested
> it, so YMMV.
> 
> ++ kevin
> 
> 
> 
> On Sat, May 18, 2002 at 08:49:36PM -0400, Joel Hammer wrote:
> > I want to justify simple text files, such as are output by vi.  It is
> > hard to believe it is so hard to do.
> > 
> > When you say keep adding spaces until the line if filled, do you mean
> > actually adding spaces to the string itself.  Wouldn't that get you
> > words on the same line which were unevenly spaced?
> > 
> > If there were some way for the stringwidth command to return the lenght
> > of a string that "x y ashow" or widthshow would put out in the current metric, then
> > you could just write a loop to keep increasing x until the line were
> > filled, however; I was unable to figure out how to get the width of a string
> > put out by ashow, without actually ashowing it. 
> > 
> > Or, if there were a quick and easy way to increase the width of
> > the glyph for "space" in the current metric, the same trick might be used.
> > That is what I am going to be fooling with, I guess, fonts.
> > 
> > Seems like it should be simple, to an amateur.
> > 
> > 
> > Joel
> > 
> > On Sat, May 18, 2002 at 03:53:44PM -0700, Kevin O'Gorman wrote:
> > > That is a laborious process in Postscript proper.  The primitives are there
> > > to support it, but the real work is usually done by the application program
> > > that emits the postscript file.  This makes sense, because the application
> > > knows how it wants it done, and there are a remarkable number of different
> > > ways to do it, when you take kerning and such into account.
> > > 
> > > The relevant primitves are (besides knowing the font metrics for the font
> > > you're using) are the 'width' and 'moveto' operators.  You find out how
> > > wide a given string will be when printed, then add space until the size is
> > > just right, then emit the line.  Usually an application will precompute all
> > > this, then just emit the 'moveto' and 'show' operators.  All the operators
> > > I put in 'primes' have several variants.
> > > 
> > > My advice: don't try to do it in Postscript unless you're really ready
> > > for a steep learning curve.  You'd be a bit better off modifying enscript,
> > > especially if you're outputting a constant-width font like Courier.
> > > 
> > > ++ kevin
> > > 
> > > 
> > > On Sat, May 18, 2002 at 05:44:38PM -0400, Joel Hammer wrote:
> > > > Does anyone know how to produce justified text in a postscript document?
> > > > It sounds simple, but there is no reference to this option in enscript, and
> > > > the two postscript manuals I downloaded from the internet don't have the
> > > > word "justify" in them.
> > > > Any insight appreciated,
> > > > Joel
> > > > 
> > > > _______________________________________________
> > > > Linux-users mailing list - http://linux-sxs.org/mailman/listinfo/linux-users
> > > > Subscribe/Unsubscribe info, Archives,and Digests are located at the above URL.
> > > 
> > > -- 
> > > Kevin O'Gorman  (805) 650-6274  mailto:kevin at kosmanor.com
> > > Permanent e-mail forwarder:  mailto:Kevin.O'Gorman.64 at Alum.Dartmouth.org
> > > At school: mailto:kogorman at cs.ucsb.edu
> > > Web: http://www.cs.ucsb.edu/~kogorman/index.html
> > > Web: http://kosmanor.com/~kevin/index.html
> > > 
> > > "Life is short; eat dessert first!"
> > > _______________________________________________
> > > Linux-users mailing list - http://linux-sxs.org/mailman/listinfo/linux-users
> > > Subscribe/Unsubscribe info, Archives,and Digests are located at the above URL.
> > _______________________________________________
> > Linux-users mailing list - http://linux-sxs.org/mailman/listinfo/linux-users
> > Subscribe/Unsubscribe info, Archives,and Digests are located at the above URL.
> 
> -- 
> Kevin O'Gorman  (805) 650-6274  mailto:kevin at kosmanor.com
> Permanent e-mail forwarder:  mailto:Kevin.O'Gorman.64 at Alum.Dartmouth.org
> At school: mailto:kogorman at cs.ucsb.edu
> Web: http://www.cs.ucsb.edu/~kogorman/index.html
> Web: http://kosmanor.com/~kevin/index.html
> 
> "Life is short; eat dessert first!"
> _______________________________________________
> Linux-users mailing list - http://linux-sxs.org/mailman/listinfo/linux-users
> Subscribe/Unsubscribe info, Archives,and Digests are located at the above URL.
> 

-- 
-----------------------------------------------------------------------
| Alan K. Jackson            | To see a World in a Grain of Sand      |
| alan at ajackson.org          | And a Heaven in a Wild Flower,         |
| www.ajackson.org           | Hold Infinity in the palm of your hand |
| Houston, Texas             | And Eternity in an hour. - Blake       |
-----------------------------------------------------------------------




More information about the Linux-users mailing list