gs_type1.ps 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. % Copyright (C) 1994, 2000 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This file is part of AFPL Ghostscript.
  4. %
  5. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  6. % distributor accepts any responsibility for the consequences of using it, or
  7. % for whether it serves any particular purpose or works at all, unless he or
  8. % she says so in writing. Refer to the Aladdin Free Public License (the
  9. % "License") for full details.
  10. %
  11. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  12. % in a plain ASCII text file named PUBLIC. The License grants you the right
  13. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14. % conditions described in the License. Among other things, the License
  15. % requires that the copyright notice and this notice be preserved on all
  16. % copies.
  17. % $Id: gs_type1.ps,v 1.5 2001/08/06 16:47:43 igorm Exp $
  18. % Type 1 font support code.
  19. % The standard representation for PostScript compatible fonts is described
  20. % in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc.
  21. % Define an augmented version of .buildfont1 that inserts UnderlinePosition
  22. % and UnderlineThickness entries in FontInfo if they aren't there already,
  23. % and FontBBox isn't degenerate.
  24. % (This works around the incorrect assumption, made by many word processors,
  25. % that these entries are present in the built-in fonts.)
  26. /.buildfont1
  27. {
  28. false 1 index /FontBBox .knownget {
  29. { 0 ne { not exit } if } forall
  30. } if
  31. { dup /FontInfo known not
  32. { .growfontdict dup /FontInfo 2 dict put }
  33. if
  34. dup dup /FontInfo get dup dup
  35. /UnderlinePosition known exch /UnderlineThickness known and
  36. { pop pop % entries already present
  37. }
  38. { dup length 2 add dict .copydict
  39. dup /UnderlinePosition known not
  40. { dup /UnderlinePosition 3 index /FontBBox .knownget
  41. { 1 get 2 div } % 1/2 the font descent
  42. { -100 } ifelse put
  43. }
  44. if
  45. dup /UnderlineThickness known not
  46. { dup /UnderlineThickness 3 index /FontBBox .knownget
  47. { dup 3 get exch 1 get sub 20 div } % 1/20 the font height
  48. { 50 } ifelse put
  49. }
  50. if
  51. 1 index /FontInfo get wcheck not { readonly } if
  52. /FontInfo exch put
  53. }
  54. ifelse
  55. } if
  56. //.buildfont1
  57. } bind def
  58. % If the diskfont feature isn't included, define a dummy .loadfontdict.
  59. /.loadfontdict where
  60. { pop }
  61. { /.loadfontdict 0 dict readonly def }
  62. ifelse
  63. /.loadfontfile % <file> .loadfontfile -
  64. { mark exch
  65. DISKFONTS { .loadfontdict begin } if
  66. % In order to load fonts reliably, we should push systemdict
  67. % here. However, Ed Taft says that Adobe implementations
  68. % push userdict and nothing else!
  69. % We really would just like systemdict on the stack,
  70. % but fonts produced by Fontographer require a writable dictionary.
  71. % However, we can't use any of the other well-known dictionaries
  72. % (such as userdict), since the whole point of pushing systemdict
  73. % is to make sure that nothing important has been redefined.
  74. userdict begin
  75. % We can't just use `run', because we want to check for .PFB files.
  76. currentpacking
  77. { false setpacking .loadfont1 true setpacking }
  78. { .loadfont1 }
  79. ifelse end
  80. { stop } if
  81. DISKFONTS { end } if
  82. cleartomark
  83. } bind def
  84. /.loadfont1 { % <file> .loadfont1 <errorflag>
  85. { % We would like to use `false /PFBDecode filter',
  86. % but this occasionally produces a whitespace character as
  87. % the first of an eexec section, so we can't do it.
  88. % Also, since the real input file never reaches EOF if we are using
  89. % a PFBDecode filter (the filter stops just after reading the last
  90. % character), we must explicitly close the real file in this case.
  91. % Since the file might leave garbage on the operand stack,
  92. % we have to create a procedure to close the file reliably.
  93. dup read not { -1 } if
  94. 2 copy unread 16#80 eq {
  95. dup true /PFBDecode filter cvx
  96. exch .currentresourcefile eq {
  97. dup /.execasresource .systemvar
  98. } {
  99. {exec}
  100. } ifelse
  101. 2 index cvlit
  102. /closefile .systemvar 3 .execn
  103. } {
  104. cvx exec
  105. } ifelse
  106. } stopped
  107. } bind def
  108. % Here are the BuildChar and BuildGlyph implementation for Type 1 fonts.
  109. % The names %Type1BuildChar and %Type1BuildGlyph are known to the interpreter.
  110. % The real work is done in an operator:
  111. % <font> <code|name> <name> <charstring> .type1execchar -
  112. (%Type1BuildChar) cvn { % <font> <code> %Type1BuildChar -
  113. 1 index /Encoding get 1 index get .type1build .type1execchar
  114. } bind def
  115. (%Type1BuildGlyph) cvn { % <font> <name> %Type1BuildGlyph -
  116. dup .type1build .type1execchar
  117. } bind def
  118. % Note: this procedure is used for both Type 1 and Type 2 fonts.
  119. /.type1build { % <font> <code|name> <name> .type1build
  120. % <font> <code|name> <name> <charstring>
  121. 2 index begin
  122. dup CharStrings exch .knownget not {
  123. 2 copy eq { exch pop /.notdef exch } if
  124. QUIET not
  125. { (Substituting .notdef for ) print = flush }
  126. { pop }
  127. ifelse
  128. /.notdef CharStrings /.notdef get
  129. } if
  130. end
  131. } bind def
  132. % CCRun is an undocumented procedure provided for Type 4 and Type 0 fonts.
  133. 1183615869 internaldict begin
  134. % Apparently there are two different argument lists for CCRun.
  135. % Handling the one with the extra Private dictionary requires fabricating
  136. % a Type 1 font on the fly, since we aren't currently prepared to parse the
  137. % dictionary any other way.
  138. /CCRun { % <font> <code|name> <charstring> CCRun -
  139. % <font> <code|name> <charstring> <Private> CCRun -
  140. dup type /dicttype eq {
  141. dup 4 index /Private .knownget { ne } { pop true } ifelse {
  142. % The Private dictionary was supplied, and is different
  143. % from the Private dictionary of the font. Fabricate a
  144. % Type 1 font with this Private dictionary. Most of the
  145. % font entries are arbitrary or not needed.
  146. .currentglobal false .setglobal 10 dict exch .setglobal begin
  147. /Private exch def
  148. /FontType 1 def
  149. /FontMatrix 3 index /FontMatrix get def
  150. /Encoding 3 index /Encoding .knownget not { StandardEncoding } if def
  151. /FontBBox 3 index /FontBBox .knownget not { {0 0 0 0} } if def
  152. /PaintType 0 def
  153. /CharStrings 1 dict dup /.notdef () put def
  154. 3 -1 roll pop () currentdict end .buildfont1 exch pop 3 1 roll
  155. } {
  156. pop
  157. } ifelse
  158. } if
  159. 1 index dup type /integertype eq {
  160. 3 index /Encoding get exch get
  161. } if exch .type1execchar
  162. } bind def
  163. end
  164. % Register the font types for definefont.
  165. buildfontdict 1 /.buildfont1 cvx put
  166. buildfontdict 4 /.buildfont4 cvx put
  167. % Add Type 2 support if applicable.
  168. /.buildfont2 where not { (%END2) .skipeof } if
  169. pop
  170. (%Type2BuildChar) cvn { % <font> <code> %Type2BuildChar -
  171. 1 index /Encoding get 1 index get .type1build .type2execchar
  172. } bind def
  173. (%Type2BuildGlyph) cvn { % <font> <name> %Type2BuildGlyph -
  174. dup .type1build .type2execchar
  175. } bind def
  176. buildfontdict 2 /.buildfont2 cvx put
  177. %END2