printafm.ps 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. /onechar 1 string def
  17. % c toupper - c
  18. /toupper {
  19. dup dup 8#141 ge exch 8#172 le and {
  20. 8#40 sub
  21. } if
  22. } bind def
  23. % printcharmetrics -
  24. /printcharmetrics {
  25. (StartCharMetrics ) print
  26. currentfont /CharStrings get dup length exch /.notdef known { 1 sub } if =
  27. currentfont 1000 scalefont setfont 0 0 moveto
  28. /e currentfont /Encoding get def
  29. 0 1 255 {
  30. dup e exch get
  31. dup /.notdef ne {
  32. exch dup printmetric
  33. } {
  34. pop pop
  35. } ifelse
  36. } for
  37. % s contains an entry for each name in the original encoding vector
  38. /s 256 dict def
  39. e {
  40. s exch true put
  41. } forall
  42. % v is the new encoding vector
  43. /v 256 array def
  44. 0 1 255 {
  45. v exch /.notdef put
  46. } for
  47. % fill up v with names in CharStrings
  48. /i 0 def
  49. currentfont /CharStrings get {
  50. pop
  51. i 255 le {
  52. v i 3 -1 roll put
  53. /i i 1 add def
  54. } {
  55. pop
  56. } ifelse
  57. } forall
  58. % define a new font with v as its encoding vector
  59. currentfont maxlength dict /f exch def
  60. currentfont {
  61. exch dup dup /FID ne exch /Encoding ne and {
  62. exch f 3 1 roll put
  63. } {
  64. pop pop
  65. } ifelse
  66. } forall
  67. f /Encoding v put
  68. f /FontName /temp put
  69. % make this new font the current font
  70. /temp f definefont setfont
  71. % print a entry for each character not in old vector
  72. /e currentfont /Encoding get def
  73. 0 1 255 {
  74. dup e exch get
  75. dup dup /.notdef ne exch s exch known not and {
  76. exch -1 printmetric
  77. } {
  78. pop pop
  79. } ifelse
  80. } for
  81. (EndCharMetrics) =
  82. } bind def
  83. % name actual_code normal_code printmetric -
  84. /printmetric {
  85. /saved save def
  86. (C ) print =only
  87. ( ; WX ) print
  88. onechar 0 3 -1 roll put
  89. onechar stringwidth pop round cvi =only
  90. ( ; N ) print =only
  91. ( ; B ) print
  92. onechar false charpath flattenpath mark pathbbox counttomark {
  93. counttomark -1 roll
  94. round cvi =only
  95. ( ) print
  96. } repeat pop
  97. (;) =
  98. saved restore
  99. } bind def
  100. % fontname printafm -
  101. /printafm {
  102. findfont gsave setfont
  103. (StartFontMetrics 2.0) =
  104. (FontName ) print currentfont /FontName get =
  105. % Print the FontInfo
  106. currentfont /FontInfo get {
  107. exch
  108. =string cvs dup dup 0 get 0 exch toupper put print
  109. ( ) print =
  110. } forall
  111. % Print the FontBBox
  112. (FontBBox) print
  113. currentfont /FontBBox get {
  114. ( ) print round cvi =only
  115. } forall
  116. (\n) print
  117. printcharmetrics
  118. (EndFontMetrics) =
  119. grestore
  120. } bind def
  121. % Check for command line arguments.
  122. [ shellarguments
  123. { ] dup length 1 eq
  124. { 0 get printafm }
  125. { (Usage: printafm fontname\n) print flush }
  126. ifelse
  127. }
  128. { pop }
  129. ifelse