home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / postscri / 5532 < prev    next >
Encoding:
Internet Message Format  |  1992-11-15  |  8.5 KB

  1. Path: sparky!uunet!ornl!rsg1.er.usgs.gov!darwin.sura.net!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!julienas!cix!irit!stolte
  2. From: stolte@irit.irit.fr (Nilo STOLTE)
  3. Newsgroups: comp.lang.postscript
  4. Subject: POSTSCRIPT TEXT FORMATTER --> PROG LISTING
  5. Message-ID: <2599@irit.irit.fr>
  6. Date: 15 Nov 92 19:02:06 GMT
  7. Sender: usenet@irit.fr
  8. Organization: IRIT-UPS, Toulouse, France
  9. Lines: 248
  10.  
  11. Run the program and the instructions to use it are given. The text is an exemple
  12. of text to be formatted by the program. To put another text, just delete the
  13. given one and put yours...
  14.  
  15. Nilo.
  16.  
  17.  
  18. %!PS-Adobe-1.0
  19. %%Title: Postscript text formatter
  20. %%Author: Nilo Stolte
  21. %%Page:
  22. /reencsmalldict 12 dict def
  23. /ReEncodeSmall
  24.  { reencsmalldict begin
  25.    /newcodesandnames exch def
  26.    /newfontname exch def
  27.    /basefontname exch def
  28.    /basefontdict basefontname findfont def
  29.    /newfont basefontdict maxlength dict def
  30.    basefontdict
  31.    { exch dup /FID ne
  32.      { dup /Encoding eq
  33.        { exch dup length array copy
  34.          newfont 3 1 roll put
  35.        }
  36.        { exch newfont 3 1 roll put
  37.        }
  38.        ifelse
  39.      }
  40.      { pop pop }
  41.      ifelse
  42.    } forall
  43.    newfont /FontName newfontname put
  44.    newcodesandnames aload pop
  45.    newcodesandnames length 2 idiv
  46.    { newfont /Encoding get 3 1 roll put
  47.    }
  48.    repeat
  49.    newfontname newfont definefont pop
  50.    end
  51.  } def
  52. /scandvec [
  53.  8#300 /Oacute
  54.  8#311 /Atilde
  55.  8#321 /oacute
  56.  8#322 /Otilde
  57.  8#323 /Ccedilla
  58.  8#324 /otilde
  59.  8#325 /ccedilla
  60.  8#330 /Eacute
  61.  8#331 /atilde
  62.  8#332 /eacute
  63.  8#333 /Udieresis
  64.  8#334 /udieresis
  65.  8#340 /Aacute
  66.  8#342 /Acircumflex
  67.  8#344 /Iacute
  68.  8#347 /ecircumflex
  69.  8#360 /aacute
  70.  8#362 /acircumflex
  71.  8#364 /iacute
  72.  8#367 /eacute
  73.  8#374 /uacute
  74.  8#375 /ocircumflex
  75.  8#376 /egrave
  76. ] def
  77. /Times-Roman /Times-Roman-Scand scandvec
  78. ReEncodeSmall
  79. /Times-Roman-Scand findfont
  80. 13 scalefont setfont
  81.  
  82. /normalwidth ( ) stringwidth pop def
  83. /maxbreakwidth 8 def
  84. /maxlinesinpage 50 def
  85.  
  86. /tabwidth 30 def
  87. /wordbreak ( ) def
  88. /BreakIntoLines
  89.   { /proc (nova_linha) cvx cvn def
  90.     /linewidth (tamanho_linha) cvx cvn def
  91.     /textstring exch def
  92.     
  93.     /breakwidth maxbreakwidth def
  94.     /curwidth 0 def
  95.     /lastwordbreak 0 def
  96.     /startchar 0 def
  97.     /restoftext textstring def
  98.     /wordcount 0 def
  99.     
  100.     { restoftext wordbreak search
  101.       { /nextword exch def pop
  102.         /restoftext exch def
  103.         /wordwidth nextword stringwidth pop def
  104.         nextword (\011) eq
  105.         { /curwidth curwidth tabwidth add def
  106.           /wordwidth 0 def
  107.         } if
  108.         curwidth wordwidth add linewidth gt
  109.         breakwidth  maxbreakwidth lt 
  110.         nextword (\001) eq
  111.         nextword (\015) eq
  112.         or or or
  113.         { textstring startchar
  114.           lastwordbreak startchar sub
  115.           getinterval /curline exch def
  116.           nextword (\015) eq
  117.           { curline () ne
  118.             { { curline wordbreak search
  119.                 { /palavra exch def pop
  120.                   /curline exch def
  121.                   palavra () ne palavra (\011) ne and
  122.                   { palavra show
  123.                     normalwidth 0 rmoveto
  124.                   } if
  125.                   palavra (\011) eq
  126.                   { tabwidth 0 rmoveto } if
  127.                 }
  128.                 { pop exit}
  129.                 ifelse
  130.               } loop
  131.             } if
  132.           }
  133.           { { curline wordbreak search
  134.               { /palavra exch def pop
  135.                 /curline exch def
  136.                 palavra () ne palavra (\011) ne and
  137.                 { palavra show
  138.                   breakwidth 0 rmoveto
  139.                 } if
  140.                 palavra (\011) eq
  141.                 { tabwidth 0 rmoveto } if
  142.               }
  143.               { pop exit}
  144.               ifelse
  145.             } loop
  146.           } ifelse 
  147.           yline maxlinesinpage lt
  148.           { textstring dup length lastwordbreak sub lastwordbreak exch 
  149.             getinterval
  150.             /yline 0 def exit
  151.           } if
  152.           nextword (\001) ne nextword (\015) ne and
  153.           { /startchar lastwordbreak def              
  154.             /lastwordbreak lastwordbreak nextword length add 1 add def
  155.           }
  156.           { /lastwordbreak lastwordbreak nextword length add 1 add def
  157.             /startchar lastwordbreak def
  158.             /wordwidth 0 def
  159.             /nextword () def
  160.           } ifelse
  161.           proc
  162.           nextword () eq
  163.           { /wordcount 0 def }
  164.           { /wordcount 1 def } ifelse
  165.           /curwidth wordwidth def
  166.           /breakwidth maxbreakwidth def
  167.         }
  168.         { /curwidth curwidth wordwidth add def
  169.           wordwidth 0 gt
  170.           { /wordcount wordcount 1 add def
  171.             wordcount 2 gt
  172.             { /breakwidth linewidth curwidth sub wordcount 1 sub div def
  173.             }
  174.             { /breakwidth linewidth curwidth sub def
  175.             } ifelse
  176.           } if
  177.           /lastwordbreak lastwordbreak nextword length add 1 add def
  178.         }
  179.         ifelse
  180.       }
  181.       { pop exit
  182.       }
  183.       ifelse
  184.     } loop
  185.     /lastchar textstring length def
  186.     lastchar startchar gt yline 0 ne and
  187.     { textstring startchar lastchar startchar sub getinterval show proc } if
  188.  } def
  189. /yinic 755 def
  190. /yline yinic def
  191. /ydec 13.07 def
  192. /xrightmargin 72 def
  193. /nova_linha {/yline yline ydec sub def
  194.               xrightmargin yline moveto
  195.             } def
  196. /tamanho_linha 470 def
  197. /alinha_dir { dup stringwidth pop tamanho_linha exch sub 0 rmoveto } def
  198.  
  199. xrightmargin yinic moveto
  200.  
  201. (November, 15th 1992.)  alinha_dir show 
  202.  
  203. /yline yline 15 sub def
  204. nova_linha
  205.  
  206. (Hi everybody: \015 \015 \
  207. \011 There is someboby that has asked me for a copy of the PostScript \
  208. formatter I've written. So I send a copy of it. It is really a modification of \
  209. a program in the Cookbook. \(Program 12 / A simple line breaking algorithm\). \
  210. It also contains the program 18 to add accents to foreign languages. \015 \
  211. \011 There are some very important variables to define the format of the \
  212. resulting text. They are \(to change, locate /<variable name>\): \015 \015 \
  213. \011 - yinic, inicial "y" value; \015 \
  214. \011 - tamanho_linha, the size of the line; \015 \
  215. \011 - tabwidth, the size of the tab spacing; \015 \
  216. \011 - xrightmargin, the right margin; \015 \
  217. \011 - ydec, the amount decremented from yline at each new line; \015 \
  218. \011 - yline, variable that has the current line "y" value; \015 \
  219. \011 - maxbreakwidth, maximal admitted space between words; \015 \
  220. \011 - maxlinesinpage, maximal number of lines in a page. \015 \
  221. \015 \011 In adittion there are values that should be set into the commands, \
  222. like the size of the characters. It should be set in the "scalefont" command. \
  223. \015 \011 Although this example is pretty clear, some comments should be done \
  224. to use it correctly. The text to be formatted must be into a string pushed \
  225. onto the stack as a parameter to the BreakIntoLines procedure. Inside this \
  226. string is imperative the use of white space followed by a back slash \
  227. in each line end. If the formatting fails this is most of the times the main \
  228. reason. Inside this string many commands can be used to indicate special \
  229. format characteristics. These commands are octal numbers, which in PostScript \
  230. are represented as a backslash followed by three octal digits. It is \
  231. imperative to separate these commands from the text before and after by one \
  232. space. This is the second main source of errors. These commands should not be \
  233. confused with the special characters also represented as octal numbers, \
  234. that CAN be joined to the words. These commands are: \015 \015 \
  235. \011 - \134001, Breaks the line and justify; \015 \
  236. \011 - \134011, TAB character. Most used as paragraph; \015 \
  237. \011 - \134015, CR character. Breaks the line, but doesn't justify. \015 \
  238. \015 \011 Page breaks are automatic, but there must be at least the same \
  239. number of "%%Page:" comments as the number of pages of the formatted text. \ Observation of the code can give some \
  240. more help. Here it can process 2 pages. Extension to more pages is  \
  241. straightforward. Just copy the lines from "%%Page:" following this text in the \
  242. program until the end as many times the number of extra pages is. \
  243. The names of the special characters to change them, can be found \
  244. in the red book under the title of "Codes and Names" in the appendix A. \
  245. Bug reports please mail to stolte@irit.fr. \
  246. It is not what it could be called an \
  247. ultimate text formatter and have its limitations. I count on you all to \
  248. extend this program to a more complete set of comands to turn it \
  249. more  flexible and usefull. Any changing should be mailed to me. \
  250. \015 \015  Abra\325os, \015 \015 Nilo Stolte. )
  251. BreakIntoLines
  252. showpage
  253.  
  254. %%Page:
  255. /yline yinic def
  256. xrightmargin yinic moveto
  257. BreakIntoLines
  258. showpage
  259.