printafm.ps 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. %!
  2. % written by James Clark <jjc@jclark.uucp>
  3. % print an afm file on the standard output
  4. % usage is `fontname printafm' eg `/Times-Roman printafm'
  5. % From the `dvitops' distribution, which included this notice:
  6. % dvitops is not copyrighted; you can do with it exactly as you please.
  7. % I would, however, ask that if you make improvements or modifications,
  8. % you ask me before distributing them to others.
  9. % Altered by d.love@dl.ac.uk to produce input for Rokicki's afm2tfm,
  10. % which groks the format of the Adobe AFMs.
  11. % $Id: printafm.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
  12. % Modified by L. Peter Deutsch 9/14/93:
  13. % uses Ghostscript's =only procedure to replace 'buf cvs print'.
  14. % Modified by L. Peter Deutsch 9/6/95:
  15. % uses Ghostscript's shellarguments facility to accept the font name
  16. % on the command line.
  17. /onechar 1 string def
  18. % c toupper - c
  19. /toupper {
  20. dup dup 8#141 ge exch 8#172 le and {
  21. 8#40 sub
  22. } if
  23. } bind def
  24. % printcharmetrics -
  25. /printcharmetrics {
  26. (StartCharMetrics ) print
  27. currentfont /CharStrings get dup length exch /.notdef known { 1 sub } if =
  28. currentfont 1000 scalefont setfont 0 0 moveto
  29. /e currentfont /Encoding get def
  30. 0 1 255 {
  31. dup e exch get
  32. dup /.notdef ne {
  33. exch dup printmetric
  34. } {
  35. pop pop
  36. } ifelse
  37. } for
  38. % s contains an entry for each name in the original encoding vector
  39. /s 256 dict def
  40. e {
  41. s exch true put
  42. } forall
  43. % v is the new encoding vector
  44. /v 256 array def
  45. 0 1 255 {
  46. v exch /.notdef put
  47. } for
  48. % fill up v with names in CharStrings
  49. /i 0 def
  50. currentfont /CharStrings get {
  51. pop
  52. i 255 le {
  53. v i 3 -1 roll put
  54. /i i 1 add def
  55. } {
  56. pop
  57. } ifelse
  58. } forall
  59. % define a new font with v as its encoding vector
  60. currentfont maxlength dict /f exch def
  61. currentfont {
  62. exch dup dup /FID ne exch /Encoding ne and {
  63. exch f 3 1 roll put
  64. } {
  65. pop pop
  66. } ifelse
  67. } forall
  68. f /Encoding v put
  69. f /FontName /temp put
  70. % make this new font the current font
  71. /temp f definefont setfont
  72. % print a entry for each character not in old vector
  73. /e currentfont /Encoding get def
  74. 0 1 255 {
  75. dup e exch get
  76. dup dup /.notdef ne exch s exch known not and {
  77. exch -1 printmetric
  78. } {
  79. pop pop
  80. } ifelse
  81. } for
  82. (EndCharMetrics) =
  83. } bind def
  84. % name actual_code normal_code printmetric -
  85. /printmetric {
  86. /saved save def
  87. (C ) print =only
  88. ( ; WX ) print
  89. onechar 0 3 -1 roll put
  90. onechar stringwidth pop round cvi =only
  91. ( ; N ) print =only
  92. ( ; B ) print
  93. onechar false charpath flattenpath mark pathbbox counttomark {
  94. counttomark -1 roll
  95. round cvi =only
  96. ( ) print
  97. } repeat pop
  98. (;) =
  99. saved restore
  100. } bind def
  101. % fontname printafm -
  102. /printafm {
  103. findfont gsave setfont
  104. (StartFontMetrics 2.0) =
  105. (FontName ) print currentfont /FontName get =
  106. % Print the FontInfo
  107. currentfont /FontInfo get {
  108. exch
  109. =string cvs dup dup 0 get 0 exch toupper put print
  110. ( ) print =
  111. } forall
  112. % Print the FontBBox
  113. (FontBBox) print
  114. currentfont /FontBBox get {
  115. ( ) print round cvi =only
  116. } forall
  117. (\n) print
  118. printcharmetrics
  119. (EndFontMetrics) =
  120. grestore
  121. } bind def
  122. % Check for command line arguments.
  123. [ shellarguments
  124. { ] dup length 1 eq
  125. { 0 get printafm }
  126. { (Usage: printafm fontname\n) print flush }
  127. ifelse
  128. }
  129. { pop }
  130. ifelse