<OT> postscript question: Justify text

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


Two comments :

In vim, you can use 
gqG
on your file to reformat it into nice paragraphs eliminating the sed.

There is a rather nice perl module, Text::Autoformat, which will
do a lot of stuff, one of which is full justification, done 
intelligently. It's not that hard to do full justification, it is
tricky to do it intelligently. Just look at what happens occasionally
in your newspaper when their algorithm fails!

The example from the man page :

Input :
        R3>     Now is the Winter of our discontent made
        R3> glorious Summer by this son of York. And all
        R3> the clouds that lour'd upon our house In the
        R3>              deep bosom of the ocean buried.


Output :
        R3> Now is the Winter  of  our  discontent  made
        R3> glorious Summer by this son of York. And all
        R3> the clouds that lour'd  upon  our  house  In
        R3> the deep bosom of the ocean buried.

For generating Postscript, I think I would look at running StarOffice
or some other word processor in batch mode to handle it.

On Sat, 18 May 2002 23:09:32 -0400  Joel Hammer wrote:
> Here is what I am doing.
> 
> I create a text file with vi. Its structure is a bunch of lines, ending
> with nl's. The paragraphs are demarcated by empty lines. This is the
> same format as this letter you are reading.
> 
> To get a better looking postscript document, I feed the text file through
> a sed script which strips out all the nl's except for those which are on
> empty lines (paragraph makers).  This makes each paragraph one long line,
> which enscript will wrap for you, thus making a very nice postscript
> document, even if the original text document had irregular or short
> lines in some paragraphs. The idea is to make it hard to have a badly
> formatted document.
> 
> I have gotten just about everything to look like what I want using vi,
> sed and enscript, except for justification of the lines of text. The
> ragged right margins look bad, especially when you have two or more
> columns on a page.
> 
> I am new to postscript, and, although justifying text seems simple,
> I haven't found an easy way to do it.
> 
> Any help appreciated,
> 
> Joel
> 
> On Sat, May 18, 2002 at 09:35:21PM -0500, Alan Jackson wrote:
> > 
> > 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       |
> > -----------------------------------------------------------------------
> > 
> > _______________________________________________
> > 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.
> 




More information about the Linux-users mailing list