X-Received: by 2002:ac8:67cf:: with SMTP id r15mr1928045qtp.258.1589416493334; Wed, 13 May 2020 17:34:53 -0700 (PDT) X-Received: by 2002:a37:6152:: with SMTP id v79mr2324777qkb.384.1589416493094; Wed, 13 May 2020 17:34:53 -0700 (PDT) Path: csiph.com!xmission!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.postscript Date: Wed, 13 May 2020 17:34:52 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=24.107.176.41; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz NNTP-Posting-Host: 24.107.176.41 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Challenge: clean up this old script From: luser droog Injection-Date: Thu, 14 May 2020 00:34:53 +0000 Content-Type: text/plain; charset="UTF-8" Lines: 110 Xref: csiph.com comp.lang.postscript:3515 On Tuesday, May 12, 2020 at 4:34:26 PM UTC-5, luser droog wrote: > I found this post on stackoverflow where someone was trying to use some > old postscript code from the internet and it wasn't quite doing what he > wanted due to portability issues in the code. > > I'm busy with finals week in school so I can't put in the time to work > on it. But if anyone is looking for a (light) PS programming effort, > I the results will be entertaining for the group. > > SO question: > https://stackoverflow.com/q/59950318/733077/why-does-this-postscript-ps-file-create-way-more-top-margin-than-specified > > > %! > % > % From: Jonathan Monsarrat (jgm@cs.brown.edu) > % Subject: PostScript -> ASCII *and* ASCII -> PostScript programs > % Newsgroups: comp.lang.postscript > % Date: 1992-10-01 04:45:38 PST > % > % "If anyone is interested, here is an interesting program written by > % Professor John Hughes here at Brown University that formats ASCII > % in PostScript without a machine generator of any kind." > % > %%% > %%% Plan: > %%% Start with an empty string. > %%% For each character in the input stream, > %%% check to see if it's a carriage return. > %%% if so, show the current string and reset it to empty > %%% if not, add it to the current string. > I got both my finals turned in, so I looked closer at this code. It's actually pretty decent overall. I did not make a lot of changes. Changed some names, factored out the ++ operation, simplify calculation of the leading (nee lineheight). And most importantly replace the explicit /pageheight 11 inch def with your choice between taking the maximum Y value from the page device or the clipping path. The bizarre "dup 500 gt" I left alone. I can't see that it hurts anything, but I can't imagine a situation where it would accomplish anything either. Modified version: /Courier 10 selectfont /leading gsave currentfont dup /FontMatrix get matrix currentmatrix matrix invertmatrix concat concat /FontBBox get aload pop % llx lly urx ury dtransform 3 2 roll dtransform % urx' ury' llx' lly' exch pop sub exch pop % ury-lly grestore def /buf 500 string def /empty 500 string def /ptr 0 def /inch {72 mul} def /pageheight currentpagedevice /PageSize get 1 get def %/pageheight newpath clippath pathbbox 4 1 roll pop pop pop def /topmargin 1 inch def /botmargin 1 inch def /leftmargin 1 inch def /linesperpage pageheight topmargin sub botmargin sub leading div cvi def /linenumber 1 def % the line we're about to write on /++ {dup load 1 add store} def /newline { linenumber linesperpage gt {/linenumber 1 def showpage} if leftmargin pageheight topmargin sub linenumber leading mul sub moveto /linenumber ++ } def /cleanup { buf show showpage } def /startstring { buf 0 empty putinterval /ptr 0 def } def /showstring { newline buf show startstring } def /addtostring { dup 500 gt {pop}{ buf exch ptr exch put /ptr ++ } ifelse } def { currentfile read {}{cleanup exit} ifelse dup 10 eq {pop showstring} {dup 0 eq {exit} {addtostring} ifelse } ifelse } loop Show me the money!