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

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