gs_type1.ps 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. % Copyright (C) 1994, 2000 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This software is provided AS-IS with no warranty, either express or
  4. % implied.
  5. %
  6. % This software is distributed under license and may not be copied,
  7. % modified or distributed except as expressly authorized under the terms
  8. % of the license contained in the file LICENSE in this distribution.
  9. %
  10. % For more information about licensing, please refer to
  11. % http://www.ghostscript.com/licensing/. For information on
  12. % commercial licensing, go to http://www.artifex.com/licensing/ or
  13. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  14. % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  15. % $Id: gs_type1.ps,v 1.16 2004/12/15 23:21:33 igor Exp $
  16. % Type 1 font support code.
  17. % The standard representation for PostScript compatible fonts is described
  18. % in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc.
  19. % Define an augmented version of .buildfont1 that inserts UnderlinePosition
  20. % and UnderlineThickness entries in FontInfo if they aren't there already,
  21. % and FontBBox isn't degenerate.
  22. % (This works around the incorrect assumption, made by many word processors,
  23. % that these entries are present in the built-in fonts.)
  24. /.buildfont1
  25. {
  26. dup .fontbbox {
  27. pop pop pop pop
  28. dup /FontInfo known not
  29. { .growfontdict dup /FontInfo 2 dict put }
  30. if
  31. dup dup /FontInfo get dup dup
  32. /UnderlinePosition known exch /UnderlineThickness known and
  33. { pop pop % entries already present
  34. }
  35. { dup length 2 add dict .copydict
  36. dup /UnderlinePosition known not
  37. { dup /UnderlinePosition 3 index /FontBBox get
  38. 1 get 2 div put % 1/2 the font descent
  39. }
  40. if
  41. dup /UnderlineThickness known not
  42. { dup /UnderlineThickness 3 index /FontBBox get
  43. dup 3 get exch 1 get sub 20 div put % 1/20 the font height
  44. }
  45. if
  46. 1 index /FontInfo get wcheck not { readonly } if
  47. /FontInfo exch put
  48. }
  49. ifelse
  50. } if
  51. //.buildfont1
  52. } bind def
  53. % If the diskfont feature isn't included, define a dummy .loadfontdict.
  54. /.loadfontdict where
  55. { pop }
  56. { /.loadfontdict 0 dict readonly def }
  57. ifelse
  58. /.loadfontfile % <file> .loadfontfile -
  59. { mark exch
  60. DISKFONTS { .loadfontdict begin } if
  61. % In order to load fonts reliably, we should push systemdict
  62. % here. However, Ed Taft says that Adobe implementations
  63. % push userdict and nothing else!
  64. % We really would just like systemdict on the stack,
  65. % but fonts produced by Fontographer require a writable dictionary.
  66. % However, we can't use any of the other well-known dictionaries
  67. % (such as userdict), since the whole point of pushing systemdict
  68. % is to make sure that nothing important has been redefined.
  69. userdict begin
  70. % We can't just use `run', because we want to check for .PFB files.
  71. currentpacking
  72. { false setpacking .loadfont1 true setpacking }
  73. { .loadfont1 }
  74. ifelse end
  75. { stop } if
  76. DISKFONTS { end } if
  77. cleartomark
  78. } bind def
  79. % container for CloseSource flag (default true to prevent buildup of file handles)
  80. /closesourcedict mark
  81. /CloseSource true
  82. .dicttomark readonly def
  83. /.loadfont1 { % <file> .loadfont1 <errorflag>
  84. { % We would like to use `false /PFBDecode filter',
  85. % but this occasionally produces a whitespace character as
  86. % the first of an eexec section, so we can't do it.
  87. % Also, since the real input file never reaches EOF if we are using
  88. % a PFBDecode filter (the filter stops just after reading the last
  89. % character), we must explicitly close the real file in this case.
  90. % Since the file might leave garbage on the operand stack,
  91. % we have to create a procedure to close the file reliably.
  92. dup read not { -1 } if
  93. 2 copy unread 16#80 eq {
  94. dup //closesourcedict //true /PFBDecode filter cvx
  95. exch .currentresourcefile eq {
  96. dup /.execasresource .systemvar
  97. } {
  98. {exec}
  99. } ifelse
  100. 2 index cvlit
  101. /closefile .systemvar 3 .execn
  102. } {
  103. cvx exec
  104. } ifelse
  105. } stopped
  106. } bind def
  107. % undefine a dict that is only used internally, and is immediately bound
  108. currentdict /closesourcedict .undef
  109. % Here are the BuildChar and BuildGlyph implementation for Type 1 fonts.
  110. % The names %Type1BuildChar and %Type1BuildGlyph are known to the interpreter.
  111. % The real work is done in an operator:
  112. % <font> <code|name> <name> <charstring> .type1execchar -
  113. (%Type1BuildChar) cvn { % <font> <code> %Type1BuildChar -
  114. 1 index /Encoding get 1 index get .type1build .type1execchar
  115. } bind def
  116. (%Type1BuildGlyph) cvn { % <font> <name> %Type1BuildGlyph -
  117. dup .type1build .type1execchar
  118. } bind def
  119. % Note: this procedure is used for both Type 1 and Type 2 fonts.
  120. /.type1build { % <font> <code|name> <name> .type1build
  121. % <font> <code|name> <name> <charstring>
  122. 2 index begin
  123. dup CharStrings exch .knownget not {
  124. 2 copy eq { exch pop /.notdef exch } if
  125. QUIET not
  126. { (Substituting .notdef for ) print
  127. =string cvs print ( in the font ) print
  128. 1 index /FontName get = flush
  129. }
  130. { pop }
  131. ifelse
  132. /.notdef CharStrings /.notdef get
  133. } if
  134. end
  135. } bind def
  136. 1183615869 internaldict begin
  137. % CCRun is an undocumented procedure provided for Type 4 and Type 0 fonts.
  138. % Apparently there are two different argument lists for CCRun.
  139. % Handling the one with the extra Private dictionary requires fabricating
  140. % a Type 1 font on the fly, since we aren't currently prepared to parse the
  141. % dictionary any other way.
  142. /CCRun { % <font> <code|name> <charstring> CCRun -
  143. % <font> <code|name> <charstring> <Private> CCRun -
  144. dup type /dicttype eq {
  145. dup 4 index /Private .knownget { ne } { pop true } ifelse {
  146. % The Private dictionary was supplied, and is different
  147. % from the Private dictionary of the font. Fabricate a
  148. % Type 1 font with this Private dictionary. Most of the
  149. % font entries are arbitrary or not needed.
  150. .currentglobal false .setglobal 10 dict exch .setglobal begin
  151. /Private exch def
  152. /FontType 1 def
  153. /FontMatrix 3 index /FontMatrix get def
  154. /Encoding 3 index /Encoding .knownget not { StandardEncoding } if def
  155. /FontBBox 3 index /FontBBox .knownget not { {0 0 0 0} } if def
  156. /PaintType 0 def
  157. /CharStrings 1 dict dup /.notdef () put def
  158. 3 -1 roll pop () currentdict end .buildfont1 exch pop 3 1 roll
  159. } {
  160. pop
  161. } ifelse
  162. } if
  163. 1 index dup type /integertype eq {
  164. 3 index /Encoding get exch get
  165. } if exch .type1execchar
  166. } bind def
  167. % setweightvector is an undocumented procedure that force writes
  168. % weight vector to the font. Do extra checks for safety.
  169. /setweightvector { % <font> <vector> setweightvector -
  170. dup type dup /arraytype ne exch /packedarraytype ne and
  171. 2 index type /dicttype ne or {
  172. /setweightvector cvx /typecheck signalerror
  173. } if
  174. 1 index /FontType known not {
  175. /setweightvector cvx /invalidfont signalerror
  176. } if
  177. dup gcheck 2 index gcheck not and {
  178. /setweightvector cvx /invalidaccess signalerror
  179. } if
  180. 2 copy /WeightVector exch .forceput
  181. .setweightvector
  182. } .bind executeonly def
  183. end
  184. % Register the font types for definefont.
  185. buildfontdict 1 /.buildfont1 cvx put
  186. buildfontdict 4 /.buildfont4 cvx put
  187. % Add Type 2 support if applicable.
  188. /.buildfont2 where not { (%END2) .skipeof } if
  189. pop
  190. (%Type2BuildChar) cvn { % <font> <code> %Type2BuildChar -
  191. 1 index /Encoding get 1 index get .type1build .type2execchar
  192. } bind def
  193. (%Type2BuildGlyph) cvn { % <font> <name> %Type2BuildGlyph -
  194. dup .type1build .type2execchar
  195. } bind def
  196. buildfontdict 2 /.buildfont2 cvx put
  197. %END2