home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / unix / volume07 / getmetr.ics < prev    next >
Encoding:
Text File  |  1988-09-11  |  8.5 KB  |  304 lines

  1. Subject:  v07i007:  PostScript program to generate .afm files
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: liam@cs.qmc.ac.uk (William Roberts)
  6. Mod.sources: Volume 7, Issue 7
  7. Archive-name: getmetrics
  8.  
  9. [  This has seen distribution elsewhere on the net; my fault for the
  10.    delay which led to that.  --r$  ]
  11.  
  12. This message contains a PostScript program which generates
  13. .afm files from the font descriptions in the LaserWriter +.
  14. These files can then be used with the TranScript software to produce
  15. new font files to allow these fonts to be used with Ditroff.  I suspect
  16. that using them with troff will be about as much fun as pulling your
  17. own teeth out, but you are welcome to try.
  18.  
  19. William Roberts         ARPA: liam@cs.qmc.ac.uk  (gw: cs.ucl.edu)
  20. Queen Mary College      UUCP: liam@qmc-cs.UUCP
  21. LONDON, UK              Tel:  01-980 4811 ext 3900
  22.  
  23. #         This is a shar archive.
  24. #         Remove everything above and including the cut line.
  25. #         Then run the rest of the file through sh.
  26. #--------cut--------cut--------cut--------cut--------cut--------
  27. #! /bin/sh
  28. #  shar:  Shell Archiver
  29. #         Run the following with /bin/sh to create:
  30. #             README
  31. #             getmetric
  32. #             afm.awk
  33. #             getafms
  34. # This archive created: Fri Jul 18 11:05:38 BST 1986
  35. echo shar: extracting "README" '('1626 chars')'
  36. if test -f README
  37. then
  38.     echo shar: will not overwrite existing file "README"
  39. else
  40. cat << \SHAR_EOF > README
  41. W.T. Roberts    18/7/86
  42.  
  43. This shar file contains three components needed to generate the
  44. Adobe Font Metric (.afm) files for the internal fonts in the
  45. LaserWriter or LaserWriter+.  These files can then be used to
  46. make Ditroff device descriptions that can be used by
  47. psroff/psdit to access these fonts from Ditroff.
  48.  
  49. getmetric       PostScript code that prints afm files to
  50.                 the LaserWriter's stdout stream. Edit it to
  51.                 select which fonts you want afm files for.
  52.  
  53. afm.awk         Awk script to extract the afm files from the
  54.                 TranScript logfiles (does SYSV have these?)
  55.  
  56. getafms         Shell script that uses sed to get rid of
  57.                 carriage returns in stdin and then puts it
  58.                 through afm.awk
  59.  
  60.  
  61. On our 4.2 system, the logfile used by the print spooler to record
  62. printer errors on our laserwriter is called "/usr/adm/laser-log"
  63. and the following command gets the afm files:
  64.  
  65.    lpr -Plaser getmetric; tail -f /usr/adm/laser-log | getafms
  66.  
  67. The second command reads the end of the logfile and keeps
  68. trying upon reaching the end-of-file; this has the effect that
  69. you watch the file as it grows. The output on the LaserWriter
  70. stdout stream gets put into this file, so getafms can extract
  71. the .afm files. Each such file is created with the standard name
  72. in the current directory.
  73.  
  74. If someone uses it on a SYSV system (or lookalike), could they
  75. post the appropriately modified instructions for use.
  76.  
  77. William Roberts         ARPA: liam@cs.qmc.ac.uk  (gw: cs.ucl.edu)
  78. Queen Mary College      UUCP: liam@qmc-cs.UUCP
  79. LONDON, UK              Tel:  01-980 4811 ext 3900
  80. SHAR_EOF
  81. if test 1626 -ne `wc -c < README`
  82. then
  83.     echo shar: error transmitting "README" '('should be 1626 chars')'
  84. else
  85.     echo README
  86. fi
  87. fi
  88. echo shar: extracting "getmetric" '('4195 chars')'
  89. if test -f getmetric
  90. then
  91.     echo shar: will not overwrite existing file "getmetric"
  92. else
  93. cat << \SHAR_EOF > getmetric
  94. %!
  95. % Get the Font Metric Information from an internal font
  96. %
  97. % Written by W.T. Roberts, Queen Mary College, LONDON UK
  98. % (liam@cs.qmc.ac.uk, liam@qmc-cs.UUCP)
  99.  
  100. statusdict begin 0 setjobtimeout end
  101.  
  102. /xdef {exch def} def
  103. /sp {( ) print} def
  104. /nl {(\n) print flush} def
  105. /= {dup type (stringtype) ne {buffer cvs} if print} def
  106. /toupper {
  107.    dup dup (a) 0 get ge exch (z) 0 get le and
  108.    {(a) 0 get sub (A) 0 get add} if  % convert to lowercase
  109. } def
  110.  
  111. /buffer 250 string def
  112. /getmetric {
  113.   /VMsave save def
  114.   dup findfont /fontdict xdef       % grab the font
  115.   dup (AFM FILE ) print = (.afm) print nl
  116.   (StartFontMetrics 1.0) print nl
  117.   (FontName ) print = nl        % record PostScript name
  118.   getFontInfo
  119.   getFontBBox
  120.   recorddefaults                % get the default encoding
  121.   miscHeights
  122.   (StartCharMetrics) print nl
  123.   getEncoding
  124.   (EndCharMetrics) print nl
  125.   (EndFontMetrics) print nl
  126.   VMsave restore
  127. } def
  128.  
  129. /getFontInfo {
  130.   (Comment Generated from PostScript version ) print version = nl
  131.   (Comment by getmetric.ps (Written by W.T. Roberts, qmc-cs.UUCP))
  132.   print nl
  133.   fontdict /FontInfo get
  134.   {exch buffer cvs dup
  135.    dup 0 get toupper 0 exch put         % convert first letter to UC
  136.    print sp = nl} forall
  137. } def
  138.  
  139. /getFontBBox {
  140.   /fmat fontdict /FontMatrix get def
  141.   fontdict /FontBBox get aload pop          % llx lly trx try
  142.   fmat transform 4 2 roll fmat transform    % TRX TRY LLX LLY
  143.   4 {1000 mul round cvi 4 1 roll} repeat    % convert to 1000 point
  144.   (FontBBox) print
  145.   2 {exch sp = sp =} repeat
  146.   nl
  147. } def
  148.  
  149. /maketempfont { % encoding vector
  150.   fontdict length dict /testdict xdef
  151.   fontdict
  152.    { 1 index /FID ne {testdict 3 1 roll put}{pop pop} ifelse
  153.    } forall     % copy contents of fontdict
  154.   testdict begin
  155.     /Encoding encoding def
  156.   end     % install the encoding vector
  157.   /TestName testdict definefont 1000 scalefont setfont
  158. } def
  159.  
  160. /recorddefaults {
  161.   fontdict /CharStrings get
  162.   length 1 sub array /names xdef  % make array to hold the names
  163.   /#name 0 def
  164.   /defaultEncoding 256 dict def
  165.   fontdict begin
  166.    defaultEncoding begin
  167.     0 1 Encoding length 1 sub
  168.     {dup Encoding exch get dup
  169.      /.notdef ne
  170.        {dup recordname exch def}
  171.        {pop pop}
  172.     ifelse % record number
  173.     } for
  174.    end
  175.   end
  176. } def
  177.  
  178. /recordname {
  179.   userdict begin
  180.     names exch #name exch put
  181.     /#name #name 1 add def
  182.   end
  183. } def
  184.  
  185. /getEncoding {
  186.   fontdict /CharStrings get
  187.   {pop dup dup
  188.    /.notdef eq exch                     % ignore .notdef
  189.    defaultEncoding exch known or        % and defaultEncoding names
  190.     {pop} {recordname} ifelse
  191.   } forall
  192.   /namecount names length def /first 0 def
  193.   % while (true)
  194.   {namecount 256 le
  195.     {names first namecount getinterval}
  196.     {names first 256 getinterval}
  197.    ifelse
  198.    /encoding xdef maketempfont
  199.    0 1 encoding length 1 sub {getcharmetric} for
  200.    /namecount namecount 256 sub def
  201.    /first first 256 add def
  202.    namecount 0 le {exit} if
  203.   } loop
  204. } def
  205.  
  206. /miscHeights {
  207.   /encoding fontdict /Encoding get def maketempfont     % make real font
  208.   defaultEncoding begin
  209.     p d x H     % get character codes
  210.   end
  211.   nbbox (CapHeight ) print dup = nl 4p
  212.   nbbox (XHeight ) print dup = nl 4p
  213.   nbbox (Ascender ) print dup = nl 4p
  214.   nbbox (Descender ) print 2 index = nl 4p
  215. } def
  216.  
  217. /4p {pop pop pop pop} def
  218. /nbbox {char exch 0 exch put charbbox} def
  219. /charbbox {
  220.   newpath 0 0 moveto char true charpath flattenpath pathbbox
  221.   4 {4 1 roll round cvi} repeat
  222. } def
  223.  
  224. /char ( ) def
  225. /getcharmetric {
  226.   /n xdef       % grab the character code
  227.   char 0 n put  % make a string from it
  228.   /label encoding n get def % record its text name
  229.   (C ) print
  230.   defaultEncoding label known
  231.     {defaultEncoding label get}{-1} ifelse
  232.   = ( ; ) print
  233.   char stringwidth round cvi /ywidth xdef round cvi /xwidth xdef
  234.   ywidth 0 eq
  235.     {(WX ) print xwidth = }
  236.     {(W ) print xwidth = sp ywidth =}
  237.   ifelse
  238.   ( ; N ) print label =
  239.   ( ; B) print
  240.   charbbox 4 2 roll 2 {exch sp = sp =} repeat
  241.   label /f eq { ( ; L i fi ; L l fl) print} if
  242.   ( ;) print nl
  243. } def
  244. %
  245.  
  246. 0 0 moveto
  247. 100 100 lineto stroke   % convince the machine it isn't idle!
  248.  
  249. % FontDirectory {pop getmetric} forall    % get EVERY font metric file
  250. /Times-Roman getmetric
  251.  
  252. (END OF FONT METRICS) print nl
  253. SHAR_EOF
  254. if test 4195 -ne `wc -c < getmetric`
  255. then
  256.     echo shar: error transmitting "getmetric" '('should be 4195 chars')'
  257. else
  258.     echo getmetric
  259. fi
  260. fi
  261. echo shar: extracting "afm.awk" '('237 chars')'
  262. if test -f afm.awk
  263. then
  264.     echo shar: will not overwrite existing file "afm.awk"
  265. else
  266. cat << \SHAR_EOF > afm.awk
  267. BEGIN   { STARTED = "FALSE"}
  268.  
  269. $1=="AFM" &&  $2=="FILE" \
  270.         { AFM=$3; STARTED = "TRUE"; next;}
  271.  
  272. $1=="StartFontMetrics", $1=="EndFontMetrics" \
  273.         { print $0 >AFM }
  274.  
  275. /END OF FONT METRICS/ && STARTED == "TRUE" \
  276.         { exit }
  277. SHAR_EOF
  278. if test 237 -ne `wc -c < afm.awk`
  279. then
  280.     echo shar: error transmitting "afm.awk" '('should be 237 chars')'
  281. else
  282.     echo afm.awk
  283. fi
  284. fi
  285. echo shar: extracting "getafms" '('35 chars')'
  286. if test -f getafms
  287. then
  288.     echo shar: will not overwrite existing file "getafms"
  289. else
  290. cat << \SHAR_EOF > getafms
  291. sed -e 's///' $* | awk -f afm.awk
  292. SHAR_EOF
  293. if test 35 -ne `wc -c < getafms`
  294. then
  295.     echo shar: error transmitting "getafms" '('should be 35 chars')'
  296. else
  297.     echo getafms
  298. fi
  299. fi
  300. #         End of shar archive
  301. exit 0
  302.  
  303.  
  304.