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.

418 lines
11 KiB

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