Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #3514

Challenge: clean up this old script

Newsgroups comp.lang.postscript
Date 2020-05-12 14:34 -0700
Message-ID <cb697609-7ed7-463c-b7ab-87e15cb147b1@googlegroups.com> (permalink)
Subject Challenge: clean up this old script
From luser droog <luser.droog@gmail.com>

Show all headers | View raw


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.

/Courier findfont 10 scalefont setfont  %% Choose a fixed width font
/lineheight 
currentfont /FontBBox get dup      %% bbox bbox
0 2 getinterval    %% bbox {xm ym}
exch     %% {xm ym} bbox
2 2 getinterval    %% {xm ym} {xM yM}
aload pop    %% {xm ym} xM yM
3 2 roll     %% xM yM {xm ym}
aload pop
currentfont /FontMatrix get  %% xM yM xm ym MAT
transform    %% xM yM xm' ym'
4 2 roll
currentfont /FontMatrix get  %% xm' ym' xM yM MAT
transform    %% xm' ym' xM' yM'
exch pop     %% xm' ym' yM'
sub     %% xm' ym'-yM'
exch pop    %% dy
neg def 

lineheight pstack pop

/str 500 string def   %% Room to store a long string...
/empty 500 string def   %% An empty string to work with
/stringindex 0 def   %% How far we've filled the string
/inch {72 mul } def   %% A useful tool...
/pageheight 11 inch def
/topmargin 1 inch def
/botmargin 1 inch def
/leftmargin 1 inch def
/linesperpage pageheight topmargin sub botmargin sub lineheight div cvi def
/linenumber 1 def   %% the line we're about to write on

/newline {   %% move to a new line; flush page if necessary
   linenumber linesperpage gt {/linenumber 1 def showpage } if
   leftmargin pageheight topmargin sub linenumber lineheight mul sub moveto
   /linenumber linenumber 1 add def
} def

/cleanup {  %% print out the last bit of whatever you had there...
   str show showpage
} def

/startstring {  %% empty the string and reset its counter.
   str 0 empty putinterval
   /stringindex 0 def
} def

/showstring {  %% print the string on a new line and flush it
   newline
   str show 
   startstring
} def

pstack 

/addtostring {  %% put another character in the string, if there's room
   dup 500 gt {pop}{str exch stringindex exch put
   /stringindex stringindex 1 add def} ifelse
} def

%
% Main program: get characters and deal with them
%
{
   currentfile read {}{cleanup exit} ifelse
   dup 10 eq                   %% if it's a carriage return...
      {pop showstring}         %% write out this line of text and start over
      {dup 0 eq         %% if it's an end-of-file mark...
       {exit}                %% stop!
       {addtostring}           %% otherwise, add the character to current string
       ifelse}
      ifelse                   %% Sample data follows.
} loop

Back to comp.lang.postscript | Previous | NextNext in thread | Find similar


Thread

Challenge: clean up this old script luser droog <luser.droog@gmail.com> - 2020-05-12 14:34 -0700
  Re: Challenge: clean up this old script luser droog <luser.droog@gmail.com> - 2020-05-13 17:34 -0700
    Re: Challenge: clean up this old script ken <ken@spamcop.net> - 2020-05-14 07:53 +0100
      Re: Challenge: clean up this old script luser droog <luser.droog@gmail.com> - 2020-05-14 07:35 -0700
    Re: Challenge: clean up this old script luser droog <luser.droog@gmail.com> - 2020-05-15 09:34 -0700

csiph-web