星火微课系统客户端
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.

gs_fntem.ps 11KB

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