You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
4.8 KiB

1 month ago
  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. % Modified by L. Peter Deutsch 9/14/93:
  12. % uses Ghostscript's =only procedure to replace 'buf cvs print'.
  13. % Modified by L. Peter Deutsch 9/6/95:
  14. % uses Ghostscript's .shellarguments facility to accept the font name
  15. % on the command line.
  16. % Altered my master@iaas.msu.ru to work with fonts of more than 256 glyphs
  17. % and avoid FSType output. Also print a comment with UniqueID of the font.
  18. /onechar 1 string def
  19. % c toupper - c
  20. /toupper {
  21. dup dup 8#141 ge exch 8#172 le and {
  22. 8#40 sub
  23. } if
  24. } bind def
  25. % print unencoded character metric data lines for glyphs in `v' array
  26. % and reset `v' -
  27. /printv {
  28. % define a new font with v as its encoding vector
  29. currentfont maxlength dict /f exch def
  30. currentfont {
  31. exch dup dup /FID ne exch /Encoding ne and {
  32. exch f 3 1 roll put
  33. } {
  34. pop pop
  35. } ifelse
  36. } forall
  37. f /Encoding v put
  38. f /FontName /temp put
  39. % make this new font the current font
  40. /temp f definefont setfont
  41. % print a entry for each character not in old vector
  42. /e currentfont /Encoding get def
  43. 0 1 255 {
  44. dup e exch get
  45. dup dup /.notdef ne exch s exch known not and {
  46. exch -1 printmetric
  47. } {
  48. pop pop
  49. } ifelse
  50. } for
  51. 0 1 255 {
  52. v exch /.notdef put
  53. } for
  54. } bind def
  55. % printcharmetrics -
  56. /printcharmetrics {
  57. (StartCharMetrics ) print
  58. currentfont /CharStrings get dup length exch /.notdef known { 1 sub } if =
  59. currentfont 1000 scalefont setfont 0 0 moveto
  60. /e currentfont /Encoding get def
  61. 0 1 255 {
  62. dup e exch get
  63. dup /.notdef ne {
  64. exch dup printmetric
  65. } {
  66. pop pop
  67. } ifelse
  68. } for
  69. % s contains an entry for each name in the original encoding vector
  70. /s 256 dict def
  71. e {
  72. s exch true put
  73. } forall
  74. % v is the new encoding vector
  75. /v 256 array def
  76. 0 1 255 {
  77. v exch /.notdef put
  78. } for
  79. % fill up v with names in CharStrings
  80. /i 0 def
  81. currentfont /CharStrings get {
  82. pop
  83. i 255 le {
  84. v i 3 -1 roll put
  85. /i i 1 add def
  86. } {
  87. printv
  88. v 0 3 -1 roll put
  89. /i 1 def
  90. } ifelse
  91. } forall
  92. printv
  93. (EndCharMetrics) =
  94. } bind def
  95. % name actual_code normal_code printmetric -
  96. /printmetric {
  97. /saved save def
  98. (C ) print =only
  99. ( ; WX ) print
  100. onechar 0 3 -1 roll put
  101. onechar stringwidth pop round cvi =only
  102. ( ; N ) print =only
  103. ( ; B ) print
  104. onechar false charpath flattenpath mark pathbbox counttomark {
  105. counttomark -1 roll
  106. round cvi =only
  107. ( ) print
  108. } repeat pop
  109. (;) =
  110. saved restore
  111. } bind def
  112. % fontname printafm -
  113. /printafm {
  114. findfont gsave setfont
  115. (StartFontMetrics 2.0) =
  116. % Print the UniqueID
  117. currentfont /UniqueID known {
  118. (Comment UniqueID ) print
  119. currentfont /UniqueID get =only
  120. (\n) print
  121. } if
  122. (FontName ) print currentfont /FontName get =
  123. % Print the FontInfo
  124. currentfont /FontInfo get {
  125. exch
  126. dup /FSType ne {
  127. =string cvs dup dup 0 get 0 exch toupper put print
  128. ( ) print =
  129. } {
  130. pop pop
  131. } ifelse
  132. } forall
  133. % Print the FontBBox
  134. (FontBBox) print
  135. currentfont /FontBBox get {
  136. ( ) print round cvi =only
  137. } forall
  138. (\n) print
  139. printcharmetrics
  140. (EndFontMetrics) =
  141. grestore
  142. } bind def
  143. % Check for command line arguments.
  144. [ .shellarguments
  145. { ] dup length 1 eq
  146. { 0 get printafm }
  147. { (Usage: printafm fontname\n) print flush }
  148. ifelse
  149. }
  150. { pop }
  151. ifelse