1
0

gs_fntem.ps 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. % Copyright (C) 2000 artofcode LLC. 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_fntem.ps,v 1.8 2004/10/25 15:11:37 igor Exp $
  16. % A procset for Postscript font emulation
  17. % The procedures must not depend on the presence of the
  18. % procset dictionary on the dictionary stack.
  19. languagelevel 2 .setlanguagelevel
  20. %========================= Process xlatmap ====================
  21. mark
  22. %% Replace 1 (xlatmap)
  23. (xlatmap) .runlibfile
  24. .dicttomark dup systemdict exch /.xlatmap_dict exch put
  25. % Convert it into a plain text to simplify the processing in C :
  26. % *(fontkind\0\0\ *(charmap\0decoding\0) ) \0
  27. () exch {
  28. 3 1 roll =string cvs concatstrings (\0\0) concatstrings
  29. exch
  30. { =string cvs concatstrings (\0) concatstrings
  31. } forall
  32. } forall
  33. (\0) concatstrings
  34. systemdict exch /.xlatmap exch put
  35. /FontEmulationProcs 10 dict begin
  36. %-------------------------------Font--------------------------------
  37. /FontCommon % - font_common -
  38. { currentdict /PaintType known not {
  39. /PaintType 0 def
  40. } if
  41. currentdict /Encoding .knownget not {
  42. //StandardEncoding
  43. } if
  44. dup type /nametype eq {
  45. /Encoding findresource
  46. } if
  47. /Encoding exch def
  48. } bind def
  49. /FontOptions 5 dict begin
  50. /make_procs currentdict def
  51. /NameKey /FontName def
  52. /TypeKey /FontType def
  53. 1
  54. { /FontMatrix [0.001 0 0 0.001 0 0] def
  55. /FontBBox [-128 -128 1024 1024] def % zfapi.ps refines it.
  56. /Private 0 dict def
  57. /CharStrings << /.notdef () >> def
  58. //FontCommon exec
  59. } bind def
  60. 42
  61. { /FontMatrix [1 0 0 1 0 0] def
  62. /FontBBox [0 0 1 1] def % zfapi.ps refines it.
  63. /CharStrings <<>> def
  64. /sfnts [<00010000 0000 0000 0000 0000 0000>] def
  65. /GlyphDirectory [] def
  66. //FontCommon exec
  67. } bind def
  68. %fixme : more font types.
  69. currentdict end def
  70. %---------------------------CIDFont---------------------------
  71. /TranslateCSI % <record> TranslateCSI <CSI>
  72. { RESMPDEBUG { (fntem TranslateCSI beg ) = } if
  73. begin
  74. << /Registry (Adobe)
  75. /Ordering CSI aload pop
  76. /Supplement exch
  77. >>
  78. end
  79. RESMPDEBUG { (fntem TranslateCSI end ) = } if
  80. } bind def
  81. /CIDFontCommon
  82. { /CIDSystemInfo currentdict //TranslateCSI exec def
  83. currentdict /CSI undef
  84. /FontBBox [-128 -128 1024 1024] def % zfapi.ps refines it.
  85. /CIDCount 1 def % ChooseDecoding will set a reasonable value.
  86. } bind def
  87. % GFlyph substitution table for narrow, wide, proportional glyphs -
  88. % used with TrueTypes.
  89. currentpacking false setpacking
  90. /SubstNWP <<
  91. % Array format : orig_type, beg_CID, end_CID, subst_beg_CID, subst_type
  92. % type = (n==narrow, w==wide, p==proportional).
  93. /Japan1
  94. { p 1 94 231 n
  95. p 17 26 780 w
  96. p 34 59 790 w
  97. p 66 91 816 w
  98. w 842 842 7918 w % fixme: These substitutions require to shift the glyph origin.
  99. w 844 844 7919 w
  100. w 846 846 7920 w
  101. w 848 848 7921 w
  102. w 850 850 7922 w
  103. w 876 876 7923 w
  104. w 908 908 7924 w
  105. w 910 910 7925 w
  106. w 912 912 7926 w
  107. w 914 914 7927 w
  108. w 925 925 7928 w
  109. w 927 927 7929 w
  110. w 929 929 7930 w
  111. w 931 931 7931 w
  112. w 933 933 7932 w
  113. w 959 959 7933 w
  114. w 991 991 7934 w
  115. w 993 993 7935 w
  116. w 995 995 7936 w
  117. w 1002 1002 7937 w
  118. w 1009 1009 7938 w
  119. w 1010 1010 7939 w
  120. } cvlit
  121. /Japan2 1 index
  122. /CNS1
  123. { p 1 94 13648 n
  124. p 17 26 333 w
  125. p 34 59 365 w
  126. p 66 91 391 w
  127. } cvlit
  128. /GB1
  129. { p 2 94 814 n
  130. p 2 94 262 w
  131. p 1 1 7716 n
  132. } cvlit
  133. /Korea1
  134. { p 1 60 8094 n
  135. p 62 94 8155 n
  136. p 2 59 264 w
  137. p 63 94 325 w
  138. } cvlit
  139. /Identity []
  140. >> def
  141. setpacking
  142. /CIDFontOptions 5 dict begin
  143. /make_procs currentdict def
  144. /NameKey /CIDFontName def
  145. /TypeKey /CIDFontType def
  146. 0
  147. { //CIDFontCommon exec
  148. /FDArray [
  149. 14 dict begin
  150. /FontName CIDFontName =string cvs (%) concatstrings cvn def
  151. /FontType 1 def
  152. /FontMatrix [0.001 0 0 0.001 0 0 ] def
  153. /PaintType 0 def
  154. /Private 0 dict def
  155. currentdict
  156. end
  157. ] def
  158. /GlyphDirectory [] def
  159. /GDBytes 1 def
  160. /FDBytes 0 def
  161. } bind def
  162. 1
  163. { //CIDFontCommon exec
  164. /FontMatrix [1 0 0 1 0 0] def
  165. /BuildGlyph {} def
  166. } bind def
  167. 2
  168. { //CIDFontCommon exec
  169. /FontMatrix [1 0 0 1 0 0] def
  170. /GDBytes 2 def
  171. /CIDMap <0000> def
  172. /sfnts [<00010000 0000 0000 0000 0000 0000>] def
  173. /Encoding [] def
  174. /CharStrings << /.notdef 0 >> def
  175. } bind def
  176. currentdict end def
  177. /complete_instance % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
  178. { begin
  179. dup length dict copy
  180. begin
  181. 1 index NameKey exch def
  182. currentglobal true setglobal
  183. make_procs TypeKey load .knownget {
  184. exec
  185. } { setglobal
  186. /complete_instance cvx /invalidfont signalerror
  187. } ifelse
  188. setglobal
  189. currentdict end
  190. end
  191. } bind def
  192. /GetFilePath % <scratch> <Name> <record> GetFilePath <filepath>
  193. { exch pop % (scratch) <record>
  194. /Path get % (scratch) (path)
  195. exch copy
  196. % What we make here it is not a complete PS resource.
  197. % Unable to provide full conformity :
  198. % the attempt to run this file may fail.
  199. } bind def
  200. /GetSize % <Name> <record> GetSize <size>
  201. { pop pop -1 % Unknown size.
  202. % fixme: probably we could provide an estimation size for some fonts.
  203. } bind def
  204. /RecordVirtualMethodsStub 3 dict begin
  205. /GetFilePath //GetFilePath def
  206. /GetSize //GetSize def
  207. currentdict end def
  208. % ---------------------- Decoding helpers ----------------------------
  209. /encodingnames mark
  210. StandardEncoding /StandardEncoding
  211. ISOLatin1Encoding /ISOLatin1Encoding
  212. SymbolEncoding /SymbolEncoding
  213. DingbatsEncoding /DingbatsEncoding
  214. /resourceforall where
  215. { pop (*) { cvn dup findencoding exch } 1024 string /Encoding resourceforall }
  216. if
  217. .dicttomark def
  218. /ChooseDecoding % <font> ChooseDecoding <font>
  219. { { % A loop for 'exit' context.
  220. dup /Decoding .knownget {
  221. dup type /nametype eq {
  222. 1 index /CIDFontType known { /CIDDecoding } { /Decoding } ifelse
  223. findresource 1 index exch /Decoding exch put
  224. } {
  225. pop
  226. } ifelse
  227. dup /CIDFontType known {
  228. dup dup /Decoding get /CIDCount get /CIDCount exch put
  229. } if
  230. exit
  231. } if
  232. dup /CIDFontType known {
  233. % This is a hooked CID font, no need for Decoding.
  234. exit
  235. } if
  236. % This works when the renderer can't choose character by name,
  237. % and we cannot determine the charset.
  238. % Probably this branch is to be removed after UFST problem is fixed.
  239. dup /Encoding get % <<font>> encoding
  240. dup type /nametype eq {
  241. /Decoding findresource 1 index exch /Decoding exch put
  242. } {
  243. dup //encodingnames
  244. exch .knownget {
  245. exch pop
  246. /Decoding findresource 1 index exch /Decoding exch put
  247. } {
  248. % unknown encoding, convert it to decoding :
  249. dup length dict begin
  250. /.notdef 0 def
  251. 0 1 currentdict length 1 sub
  252. { dup 2 index exch get
  253. dup /.notdef ne {
  254. exch def
  255. } {
  256. pop pop
  257. } ifelse
  258. } for
  259. pop
  260. currentdict end
  261. 1 index exch /Decoding exch put
  262. } ifelse
  263. } ifelse
  264. exit
  265. } loop
  266. dup /CIDFontType known {
  267. dup /SubstNWP .knownget not {
  268. dup /CIDSystemInfo get /Ordering get cvn
  269. } if
  270. dup type /nametype eq {
  271. //SubstNWP exch get % <<font>> [SubstNWP]
  272. } if
  273. 1 index exch /SubstNWP exch put
  274. } if
  275. } bind def
  276. /PrintFontRef % <string|name> <font> PrintFontRef <string|name> <font>
  277. { dup /FontName known { (Font ) } { (CIDFont ) } ifelse print
  278. 1 index =string cvs print
  279. dup /FontName .knownget not {
  280. dup /CIDFontName get
  281. } if % <string|name> <font> <fontname>
  282. dup 3 index ne {
  283. ( \( aliased from ) print
  284. =string cvs print ( \)) print
  285. } {
  286. pop
  287. } ifelse
  288. } bind def
  289. /GetFontType % <font> GetFontType int
  290. { dup /CIDFontType .knownget {
  291. exch pop 9 add
  292. } {
  293. /FontType get
  294. } ifelse
  295. } bind def
  296. /FindInArray % <array> <elem> .array_find <bool>
  297. { false 3 1 roll
  298. exch { % false elem elem_i
  299. 1 index eq { % false elem
  300. pop true exch
  301. } if
  302. } forall
  303. pop
  304. } bind def
  305. /ProvideUnicodeDecoding % <font> ProvideUnicodeDecoding <font>
  306. {
  307. % If the font is maintained by FAPI, or if it is TT-emulated CID font,
  308. % it already has /Decoding. But its value isn't guaranteeed to
  309. % be an Unicode decoding. Since we can't determine whether
  310. % it is an Unicode decoding, we unconditionally load an appropriate Unicode decoding
  311. % and attach it with /GlyphNames2Unicode entry.
  312. %
  313. % Another interesting case is when the font already has /GlyphNames2Unicode.
  314. % The latter to be used instead. Note that /GlyphNames2Unicode
  315. % appears only when type 32 fonts are disable (see .pdf_hook_DSC_Creator),
  316. % but an automatic disabling is not implemented yet.
  317. currentglobal true setglobal exch
  318. dup /FontInfo known not {
  319. dup /FontInfo 1 dict put
  320. } if
  321. { % A loop just for 'exit' context.
  322. dup /FontInfo get /GlyphNames2Unicode known {
  323. exit
  324. } if
  325. dup /CIDFontType known {
  326. dup mark exch % bool <font> [ <font>
  327. dup /CIDSystemInfo get /Ordering get (.Unicode) % bool <font> [ <font> () ()
  328. concatstrings cvn % bool <font> [ <font> /Name
  329. /CIDDecoding { findresource } stopped {
  330. % Can't provide a decoding, giving up without creating /GlyphNames2Unicode.
  331. cleartomark exit
  332. } if % bool <font> [ <font> <D>
  333. exch /FontInfo get exch % bool <font> [ <FI> <D>
  334. /GlyphNames2Unicode exch
  335. .forceput % FontInfo can be read-only.
  336. pop % bool <font>
  337. exit
  338. } if
  339. dup /FontInfo get % bool <font> <FI>
  340. /GlyphNames2Unicode /Unicode /Decoding findresource
  341. .forceput % FontInfo can be read-only.
  342. exit
  343. } loop
  344. exch setglobal
  345. } bind def
  346. currentdict end /ProcSet defineresource pop
  347. .setlanguagelevel