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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. % Copyright (C) 1997, 1998, 1999, 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_cff.ps 9351 2009-01-13 22:17:21Z alexcher $
  16. % Loader for CFF (compressed) fonts, including OpenType CFFs.
  17. % The following are not implemented yet:
  18. % Deleted entries in the Name Index
  19. % Embedded PostScript
  20. % Multiple Master fonts
  21. % Chameleon fonts
  22. % Synthetic fonts
  23. % ---------------- Font loading machinery ---------------- %
  24. % Augment the FONTPATH machinery so it recognizes OpenType CFF font sets.
  25. /.scanfontheaders where {
  26. pop /.scanfontheaders [
  27. .scanfontheaders aload pop (OTTO*)
  28. ] def
  29. } if
  30. % Load a font file that might be an OpenType CFF font set.
  31. % <file> .loadfontfile -
  32. /.loadnonottofontfile /.loadfontfile load def
  33. /.loadfontfile {
  34. dup 4 string .peekstring pop (OTTO) eq {
  35. % If this is a font at all, it's an OpenType CFF font set.
  36. .init_otto_font_file
  37. % Use a random FontSet resource name. ****** WRONG ******
  38. realtime rand xor =string cvs exch //false //false
  39. ReadData pop
  40. } {
  41. % Not a TrueType font.
  42. .loadnonottofontfile
  43. } ifelse
  44. } bind def
  45. % <file> .init_otto_font_file <file>
  46. /.init_otto_font_file {
  47. /FontSetInit /ProcSet findresource begin
  48. 2 dict begin
  49. /f exch def /cff null def
  50. card32 pop card16 6 { next pop } repeat dup {
  51. % Stack: numtables tablesleft
  52. dup 0 eq {
  53. pop pop /.loadottofontfile cvx /invalidfont signalerror
  54. } if
  55. f 4 string readstring pop (CFF ) eq { sub exit } if
  56. f 12 string readstring pop pop 1 sub % skip to next table
  57. } loop
  58. % Stack: tablesread
  59. card32 pop card32 card32
  60. % Stack: tablesread start length
  61. exch 3 -1 roll 1 add 16 mul 12 add sub
  62. f exch subfilefilter flushfile % skip to start
  63. f exch subfilefilter end
  64. } bind def
  65. 53 dict begin
  66. % ---------------- Standard strings (actually names) ---------------- %
  67. /StandardStrings mark
  68. % The initial StandardStrings that that denote characters are
  69. % defined as a pseudo-Encoding.
  70. % 0
  71. /CFFStandardStrings .findencoding aload pop
  72. % 379
  73. (001.000)
  74. % 380
  75. (001.001) (001.002) (001.003) /Black /Bold
  76. /Book /Light /Medium /Regular /Roman
  77. /Semibold
  78. .packtomark def
  79. % ---------------- Standard encodings ---------------- %
  80. /StandardEncodings [
  81. % StandardEncoding
  82. mark
  83. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  84. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  85. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  86. 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  87. 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  88. 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  89. 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  90. 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 0
  91. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  92. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93. 0 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
  94. 0 111 112 113 114 0 115 116 117 118 119 120 121 122 0 123
  95. 0 124 125 126 127 128 129 130 131 0 132 133 0 134 135 136
  96. 137 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97. 0 138 0 139 0 0 0 0 140 141 142 143 0 0 0 0
  98. 0 144 0 0 0 145 0 0 146 147 148 149 0 0 0 0
  99. .packtomark
  100. % ExpertEncoding
  101. mark
  102. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  103. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  104. 1 229 230 0 231 232 233 234 235 236 237 238 13 14 15 99
  105. 239 240 241 242 243 244 245 246 247 248 27 28 249 250 251 252
  106. 0 253 254 255 256 257 0 0 0 258 0 0 259 260 261 262
  107. 0 0 263 264 265 0 266 109 110 267 268 269 0 270 271 272
  108. 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
  109. 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 0
  110. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  111. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  112. 0 304 305 306 0 0 307 308 309 310 311 0 312 0 0 313
  113. 0 0 314 315 0 0 316 317 318 0 0 0 158 155 163 319
  114. 320 321 322 323 324 325 0 0 326 150 164 169 327 328 329 330
  115. 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
  116. 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
  117. 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
  118. .packtomark
  119. ] readonly def
  120. % ---------------- Standard Charsets ---------------- %
  121. % We include an explicit 0 at the beginning of each charset.
  122. /StandardCharsets [
  123. % ISOAdobe
  124. mark
  125. 0
  126. 1 1 228 { } for
  127. .packtomark
  128. % Expert
  129. mark
  130. 0
  131. 1 229 230 231 232 233 234 235 236 237 238 13 14 15 99 239
  132. 240 241 242 243 244 245 246 247 248 27 28 249 250 251 252 253
  133. 254 255 256 257 258 259 260 261 262 263 264 265 266 109 110 267
  134. 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
  135. 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
  136. 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
  137. 316 317 318 158 155 163 319 320 321 322 323 324 325 326 150 164
  138. 169 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
  139. 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
  140. 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
  141. 374 375 376 377 378
  142. .packtomark
  143. % ExpertSubset
  144. mark
  145. 0
  146. 1 231 232 235 236 237 238 13 14 15 99 239 240 241 242 243
  147. 244 245 246 247 248 27 28 249 250 251 253 254 255 256 257 258
  148. 259 260 261 262 263 264 265 266 109 110 267 268 269 270 272 300
  149. 301 302 305 314 315 158 155 163 320 321 322 323 324 325 326 150
  150. 164 169 327 328 329 330 331 332 333 334 335 336 337 338 339 340
  151. 341 342 343 344 345 346
  152. .packtomark
  153. ] readonly def
  154. % ---------------- Font loading ---------------- %
  155. % ------ Utilities ------ %
  156. /advance { % <n> advance -
  157. f cff eq { pos add /pos exch store } { pop } ifelse
  158. } bind def
  159. /next { % - next <byte>
  160. f read {
  161. 1 advance
  162. CFFDEBUG { ( ) print dup = } if
  163. } {
  164. 0
  165. CFFDEBUG { ( Out of range access, assuming 0) = } if
  166. /pdfformaterror where {
  167. pop
  168. ( **** Warning: Out of range access to a CFF table, assuming 0.\n)
  169. pdfformaterror
  170. } if
  171. } ifelse
  172. } bind def
  173. /next2 { % - next2 <byte1> <byte2>
  174. f read {
  175. f read {
  176. 2 advance
  177. CFFDEBUG { ( ) print 1 index =only (,) print dup = } if
  178. } {
  179. 1 advance
  180. CFFDEBUG { ( ) print dup = } if
  181. } ifelse
  182. } if
  183. } bind def
  184. /nextstring { % <length> nextstring <string>
  185. dup 0 eq {
  186. pop ()
  187. } {
  188. string f exch readstring pop dup length advance
  189. CFFDEBUG { ( ) print dup == } if
  190. } ifelse
  191. } bind def
  192. /card8 % - card8 <card8>
  193. /next load
  194. def
  195. /card16 { % - card16 <card16>
  196. next2 exch 8 bitshift add
  197. } bind def
  198. /card32 { % - card32 <card32>
  199. card16 16 bitshift card16 add
  200. } bind def
  201. /offsetprocs [
  202. /card8 load
  203. /card16 load
  204. { card8 16 bitshift card16 add } bind
  205. /card32 load
  206. ] readonly def
  207. /offsetproc { % <offsize> offsetproc <proc>
  208. 1 sub //offsetprocs exch get
  209. } bind def
  210. /offset { % <offsize> offset <offset>
  211. offsetproc exec
  212. } bind def
  213. /sid % - <sid> sid
  214. /card16 load
  215. def
  216. /Index { % <name> Index <name> <array>
  217. CFFDEBUG { (% reading Index: ) print dup = } if
  218. mark card16
  219. dup 0 ne {
  220. 1 exch next
  221. dup 0 eq {
  222. pop % skip incorrect index, bug 689854
  223. } {
  224. offsetproc dup exec pop exch {
  225. dup exec dup 4 -1 roll sub 3 1 roll exch
  226. } repeat
  227. } ifelse pop
  228. } if pop .packtomark
  229. CFFDEBUG { (% Index lengths = ) print dup === } if
  230. [ exch { nextstring } forall ] readonly
  231. } bind def
  232. /tokens { % - tokens <num1> ... <op#> (op# = 12 means EOF)
  233. {
  234. f read not { 12 exit } if
  235. CFFDEBUG { (..) print dup = } if
  236. 1 advance
  237. dup 12 eq { pop next 32 add exit } if
  238. dup 28 lt { exit } if
  239. dup 32 lt {
  240. 28 sub {
  241. { card16 32768 xor 32768 sub }
  242. { 4 offset dup 16#7fffffff gt { -1 32 bitshift add } if }
  243. { tokenreal }
  244. { 31 exit }
  245. } exch get exec
  246. } {
  247. dup 247 lt {
  248. 139 sub
  249. } {
  250. 247 sub {
  251. { next 108 add }
  252. { next 364 add }
  253. { next 620 add }
  254. { next 876 add }
  255. { next 108 add neg }
  256. { next 364 add neg }
  257. { next 620 add neg }
  258. { next 876 add neg }
  259. % 255 is deliberately omitted and will cause a rangecheck
  260. } exch get exec
  261. } ifelse
  262. } ifelse
  263. } loop
  264. } bind def
  265. /tokenbuf 100 string def
  266. /tokenput { % <index> <str> tokenput <index+length>
  267. dup length 3 1 roll
  268. tokenbuf 2 index 3 -1 roll putinterval add
  269. } bind def
  270. /tokenrealarray [
  271. (0)(1)(2)(3)(4)(5)(6)(7)(8)(9)(.)(E)
  272. (E-)
  273. () % ignore the invalid value
  274. (-)
  275. { exit } bind
  276. ] readonly def
  277. /tokenreal { % - tokenreal <float>
  278. 0 {
  279. next exch 1 index -4 bitshift tokenrealarray exch get exec tokenput
  280. % We must leave the byte on the stack temporarily so that
  281. % the exit will see a consistent stack state.
  282. 1 index 15 and tokenrealarray exch get exec tokenput exch pop
  283. } loop
  284. tokenbuf 0 3 -1 roll getinterval cvr exch pop
  285. } bind def
  286. /Dict { % <opsdict> Dict -
  287. /opdict exch store {
  288. mark tokens
  289. CFFDEBUG { (tokens: ) print ] dup === mark exch aload pop } if
  290. opdict exch .knownget { exec } if cleartomark
  291. } loop cleartomark
  292. } bind def
  293. /idstring { % <sid> idstring <string|name>
  294. dup 391 lt { //StandardStrings } { 391 sub strings } ifelse exch get
  295. } bind def
  296. /idname { % <sid> idname <name>
  297. idstring dup type /nametype ne { cvn } if
  298. } bind def
  299. /subfilefilter { % <file> <length> subfilefilter <filter>
  300. % SubFileDecode interprets a length of 0 as infinite.
  301. dup 0 le { pop pop () 0 } if () /SubFileDecode filter
  302. } bind def
  303. % ------ Top dictionary ------ %
  304. /offput { % <offset> <proc> offput -
  305. 1 index 0 le
  306. CFFDEBUG { dup { (not ) print } if (queued: ) print 2 index =only ( ) print 1 index === } if
  307. { pop pop
  308. }
  309. { currentdict exch aload length 1 add packedarray cvx
  310. offsets 3 1 roll put
  311. }
  312. ifelse
  313. } bind def
  314. /queueput { % <font> <proc> queueput -
  315. 16#7fffffff offsets { pop .min } forall
  316. pos sub nextstring
  317. 3 1 roll aload length 2 add packedarray cvx
  318. [ queued aload pop counttomark 2 add -1 roll ]
  319. /queued exch store
  320. } bind def
  321. /printvk { % <value> <key> printvk <value> <key>
  322. CFFDEBUG { (\t% ) print dup =only ( = ) print 1 index === } if
  323. } bind def
  324. /xxput { % <value> <key> <dict> xxput -
  325. 3 1 roll exch put
  326. } bind def
  327. /putfi { % <value> <key> putfi -
  328. printvk FontInfo xxput
  329. } bind def
  330. /xdef { % <value> <key> xdef -
  331. exch def
  332. } bind def
  333. /pxdef { % <value> <key> pxdef -
  334. printvk xdef
  335. } bind def
  336. /topdictops mark
  337. 12 { CFFDEBUG { (\t% EOD) = } if exit }
  338. 0 { idstring /version putfi }
  339. 1 { idstring /Notice putfi }
  340. 32 { idstring /Copyright putfi }
  341. 2 { idstring /FullName putfi }
  342. 3 { idstring /FamilyName putfi }
  343. 4 { idstring /Weight putfi }
  344. 33 { 0 ne /isFixedPitch putfi }
  345. 34 { /ItalicAngle putfi }
  346. 35 { /UnderlinePosition putfi }
  347. 36 { /UnderlineThickness putfi }
  348. 37 { /PaintType pxdef }
  349. 38 { /FontType pxdef } % actually CharstringType
  350. 39 { counttomark array astore /FontMatrix pxdef }
  351. 13 { /UniqueID pxdef }
  352. 5 { counttomark array astore /FontBBox pxdef }
  353. 40 { /StrokeWidth pxdef }
  354. 14 { counttomark array astore /XUID pxdef }
  355. 15 {
  356. /charset printvk pop
  357. dup StandardCharsets length lt {
  358. StandardCharsets exch get /charset xdef
  359. } {
  360. { queuecharset } offput
  361. } ifelse
  362. }
  363. 16 {
  364. /Encoding printvk pop
  365. dup StandardEncodings length lt {
  366. /Encoding xdef
  367. } {
  368. { queueEncoding } offput
  369. } ifelse
  370. }
  371. 17 { { readCharStrings } offput }
  372. 18 { exch /readPrivate cvx 2 packedarray offput }
  373. % CIDFont operators
  374. 62 { % ROS, must be first in a CIDFont
  375. currentdict /FontType undef
  376. currentdict /Encoding undef
  377. currentdict /FontMatrix undef
  378. /CIDFontVersion 0 def
  379. /CIDFontRevision 0 def
  380. /CIDFontType 0 def
  381. /CIDCount 8720 def % Default value defined in CFF spec.
  382. 3 dict begin
  383. /Supplement pxdef
  384. idstring dup type /nametype eq { .namestring } if /Ordering pxdef
  385. idstring dup type /nametype eq { .namestring } if /Registry pxdef
  386. /CIDSystemInfo currentdict end def
  387. }
  388. 63 { /CIDFontVersion pxdef }
  389. 64 { /CIDFontRevision pxdef }
  390. 65 { /CIDFontType pxdef }
  391. 66 { /CIDCount pxdef }
  392. 67 { /UIDBase pxdef }
  393. 68 { { readFDArray } offput }
  394. 69 { { readFDSelect } offput }
  395. % This operator only appears in a FDArray element.
  396. % We don't really need it, so ignore an error.
  397. 70 { { idstring } .internalstopped { pop pop } { /FontName pxdef } ifelse }
  398. .dicttomark readonly def
  399. % readcharset and readFDSelect may require the length of CharStringArray,
  400. % but these structures may occur in the file before the CharStrings.
  401. % If that happens, use a hack: assume that all the data up to the next
  402. % queued read should be read.
  403. /charstringcount { % <font> charstringcount <count> true
  404. % <font> charstringcount <length> false
  405. /CharStringArray .knownget {
  406. length true
  407. } {
  408. % Hack: look for the next queued read.
  409. 16#7fffffff offsets { pop .min } forall
  410. pos sub false
  411. } ifelse
  412. } bind def
  413. /readCharStrings { % <font> readCharStrings -
  414. /CharStringArray Index put
  415. } bind def
  416. % ------ Charsets and encodings ------ %
  417. % Note: formats 1 and 2 can overflow the operand stack.
  418. % We'll fix this if it ever becomes necessary.
  419. /charsetcount {
  420. charstringcount { 1 sub } { 2 idiv } ifelse
  421. } bind def
  422. /charsetformats [
  423. { [ 0 3 -1 roll charsetcount { sid } repeat ]
  424. } bind
  425. { [ 0 3 -1 roll charsetcount {
  426. dup 0 eq { pop exit } if
  427. sid card8 1 add 2 index .min { exch 1 sub 1 index 1 add } repeat pop
  428. } loop ]
  429. } bind
  430. { [ 0 3 -1 roll charsetcount {
  431. dup 0 eq { pop exit } if
  432. sid card16 1 add 2 index .min { exch 1 sub 1 index 1 add } repeat pop
  433. } loop ]
  434. } bind
  435. ] readonly def
  436. /queuecharset { % <font> queuecharset -
  437. { readcharset } queueput
  438. } bind def
  439. /readcharset { % <data> <font> readcharset -
  440. begin 0 () /SubFileDecode filter /f exch store
  441. charsetformats next get currentdict exch exec /charset exch def end
  442. } bind def
  443. /encodingformats [
  444. { 1 1 next { next exch Encoding 3 1 roll put } for
  445. } bind
  446. { 1 next {
  447. next next 1 add {
  448. % Stack: gid code
  449. Encoding 1 index 3 index put
  450. exch 1 add exch 1 add
  451. } repeat pop
  452. } repeat pop
  453. } bind
  454. ] readonly def
  455. /queueEncoding { % <font> queueEncoding -
  456. { readEncoding } queueput
  457. } bind def
  458. /readEncoding { % <data> <font> readEncoding -
  459. begin 0 () /SubFileDecode filter /f exch store
  460. /Encoding [ 256 { /.notdef } repeat ] def
  461. next encodingformats 1 index 127 and get exec
  462. 128 ge {
  463. % Read supplementary encodings.
  464. next {
  465. Encoding next sid idname put
  466. } repeat
  467. } if end
  468. } bind def
  469. % ------ FDArray and FDSelect ------ %
  470. /readFDArray { % <font> readFDArray -
  471. /FDarray Index exch pop exch
  472. 2 dict begin /f null def begin
  473. [ exch {
  474. dup length subfilefilter /f exch store
  475. 10 dict begin
  476. /FontType 2 def
  477. /PaintType 0 def
  478. /FontMatrix [0.001 0 0 0.001 0 0] def
  479. /Private 20 dict def
  480. //topdictops Dict currentdict end
  481. } forall ] /FDArray xdef end end
  482. } bind def
  483. /fdselectformats [
  484. % Note: this procedure can overflow the operand stack.
  485. % We'll fix this if it ever becomes necessary.
  486. { [ exch charstringcount pop { card8 } repeat ] } bind % Format 0
  487. { /FDSelect cvx /invalidfont signalerror } bind % Format 1
  488. dup % Format 2
  489. % The following procedure does not use excessive op-stack space.
  490. { pop 65535 array card16 card16 exch % Format 3
  491. { % Stack: array previndex
  492. card8 card16
  493. exch 1 index 4 -1 roll
  494. exch 1 exch 1 sub
  495. { 3 index exch 2 index put } for pop
  496. } repeat
  497. % now resize the array to the final index.
  498. 0 exch getinterval
  499. } bind
  500. ] readonly def
  501. /readFDSelect { % <font> readFDSelect -
  502. begin fdselectformats next get currentdict exch exec /FDSelect exch def end
  503. } bind def
  504. % ------ Private dictionary ------ %
  505. /deltarray { % -mark- <num1> ... deltarray <num1'> ...
  506. 0 counttomark 1 sub { counttomark -1 roll add dup } repeat pop
  507. counttomark array astore
  508. } bind def
  509. /privatedictops mark
  510. 12 { CFFDEBUG { (\t% EOD) = } if exit }
  511. 6 { deltarray /BlueValues pxdef }
  512. 7 { deltarray /OtherBlues pxdef }
  513. 8 { deltarray /FamilyBlues pxdef }
  514. 9 { deltarray /FamilyOtherBlues pxdef }
  515. 41 { /BlueScale pxdef }
  516. 42 { /BlueShift pxdef }
  517. 43 { /BlueFuzz pxdef }
  518. 10 { 1 array astore /StdHW pxdef }
  519. 11 { 1 array astore /StdVW pxdef }
  520. 44 { deltarray /StemSnapH pxdef }
  521. 45 { deltarray /StemSnapV pxdef }
  522. 46 { 0 ne /ForceBold pxdef }
  523. 47 { /ForceBoldThreshold pxdef }
  524. 48 { /lenIV pxdef }
  525. 49 { /LanguageGroup pxdef }
  526. 50 { /ExpansionFactor pxdef }
  527. 51 { /initialRandomSeed pxdef }
  528. 19 { PrivateStart add { readSubrs } offput }
  529. 20 { /defaultWidthX pxdef }
  530. 21 { /nominalWidthX pxdef }
  531. % Multiple Master fonts only
  532. 59 { /NDV pxdef }
  533. 60 { /CDV pxdef }
  534. 61 { /lenBuildCharArray pxdef }
  535. .dicttomark readonly def
  536. /readPrivate { % <font> <size> readPrivate -
  537. 2 dict begin
  538. f 3 1 roll exch % f <size> <font>
  539. StringCache queued_offset known {
  540. /PrivateStart queued_offset def
  541. } {
  542. /PrivateStart pos def
  543. 1 index 0 gt {
  544. f 2 index string readstring pop
  545. } {
  546. ()
  547. } ifelse
  548. StringCache queued_offset 2 index put
  549. 0 () /SubFileDecode filter
  550. /f exch store
  551. } ifelse
  552. dup /FontType .knownget not { 2 } if exch
  553. /Private get begin
  554. % Default lenIV to -1 even for Type 1 CharStrings.
  555. 2 ne { /lenIV -1 def } if
  556. //privatedictops Dict end
  557. exch /f exch store advance
  558. end
  559. } bind def
  560. /readSubrs { % <font> readSubrs -
  561. /Subrs Index put
  562. } bind def
  563. % ------ Main program ------ %
  564. % Clean up after finishing a font.
  565. /cleanupFont { % (currentdict) cleanupFont -
  566. % Remove unwanted entries.
  567. currentdict /charset undef
  568. currentdict /CharStringArray undef
  569. } bind def
  570. % Update the Encoding and CharStrings for a real font.
  571. /finishFont { % (currentdict) finishFont -
  572. % Construct the real Encoding.
  573. % The value of Encoding is either a number, for predefined
  574. % encodings, or an array of mixed GIDs and names.
  575. /Encoding mark Encoding
  576. CFFDEBUG { (Encoding: ) print dup === flush } if
  577. dup type /integertype eq {
  578. StandardEncodings exch get { idname } forall
  579. } {
  580. {
  581. dup type /integertype eq { charset exch get idname } if
  582. } forall
  583. } ifelse .packtomark def
  584. % Construct the CharStrings.
  585. % Note that they may only correspond to an initial
  586. % subset of the charset.
  587. /CharStrings charset length CharStringArray length .min dict def
  588. CFFDEBUG {
  589. charset length =only ( charset ) print
  590. CharStringArray length =only ( CharStringArray) =
  591. charset == flush
  592. } if
  593. 0 1 CharStrings maxlength 1 sub {
  594. dup CharStringArray exch get
  595. exch charset exch get idstring CharStrings xxput
  596. } for
  597. cleanupFont
  598. } bind def
  599. % Replace CharStrings with GlyphDirectory for a CIDFont;
  600. % Move GlobalSubrs to descendent fonts.
  601. /finishCIDFont { % (currentdict) finishCIDFont -
  602. % Construct the GlyphDirectory, similar to CharStrings.
  603. /FDBytes FDArray length 1 gt { 1 } { 0 } ifelse def
  604. /GlyphDirectory charset length CharStringArray length .min dict def
  605. CFFDEBUG {
  606. charset length =only ( charset ) print
  607. CharStringArray length =only ( CharStringArray) =
  608. charset == flush
  609. } if
  610. 0 1 GlyphDirectory maxlength 1 sub {
  611. dup CharStringArray exch get
  612. % If there is more than one FDArray entry, add the font
  613. % index to the beginning of each charstring.
  614. FDBytes 1 eq {
  615. FDSelect 2 index get
  616. 1 string dup 0 4 -1 roll put exch concatstrings
  617. } if
  618. exch charset exch get GlyphDirectory xxput
  619. } for
  620. Private /GlobalSubrs .knownget {
  621. FDArray {
  622. /Private get /GlobalSubrs 2 index put
  623. } forall
  624. pop
  625. Private /GlobalSubrs undef
  626. } if
  627. % Clean up.
  628. currentdict /FDSelect undef
  629. cleanupFont
  630. } bind def
  631. % PDF may load OpenType font containing ordinary CFF data as a CIDFont.
  632. % Convert the ordinary font to a CIDFont.
  633. /makeCIDFont { % (currentdict) finishCIDFont -
  634. /CIDFontType 0 def
  635. /FDBytes 0 def
  636. /GDBytes 0 def
  637. /CIDMapOffset 0 def
  638. /CIDSystemInfo 3 dict begin % bogus
  639. /Registry (Adobe) def
  640. /Ordering (Identity) def
  641. /Supplement 0 def
  642. currentdict end def
  643. /FDArray 4 dict begin
  644. /FontMatrix dup load { 1000 0 0 1000 0 0 } matrix concatmatrix def
  645. /Private dup load def
  646. /FontType dup load def
  647. /PaintType dup load def
  648. currentdict end 1 array astore def
  649. /FontType 9 def
  650. /GlyphDirectory CharStringArray def
  651. /CIDCount GlyphDirectory length def
  652. currentdict /Private undef
  653. currentdict /Encoding undef
  654. currentdict /CharStrings undef
  655. currentdict /UniqueID undef
  656. currentdict /XUID undef
  657. cleanupFont
  658. } bind def
  659. % We need to pass the file as a parameter for the sake of the PDF
  660. % interpreter. Also for the sake of PDF, a flag forces the font
  661. % to be defined as <resname> instead of the name embedded in the data.
  662. % This is needed for subsetted fonts; it is valid if the CFF
  663. % contains only a single font.
  664. % Finally, PDF interpreter may request creation of CIDFont out of an
  665. % ordinary CFF font.
  666. /StartData { % <resname> <nbytes> StartData -
  667. currentfile exch subfilefilter //false //false ReadData pop
  668. } bind def
  669. /ReadData { % <resname> <file> <forceresname> <forcecid> ReadData <fontset>
  670. % Initialize.
  671. 30 dict begin
  672. /forcecidfont exch def
  673. /forceresname exch def
  674. /cff exch def
  675. /pos 0 def
  676. /resname exch cvlit def
  677. /DEBUG CFFDEBUG def % bring the binding closer
  678. /StringCache 1 dict def % Private DICT may be reused.
  679. % Read the header.
  680. /f cff def
  681. /vmajor next def
  682. /vminor next def
  683. /hdrsize next def
  684. /aoffsize next def
  685. hdrsize 4 gt {
  686. hdrsize 4 sub dup advance
  687. f exch () /SubFileDecode filter flushfile
  688. } if
  689. % Read the Indexes.
  690. /names Index def
  691. /topdicts Index def
  692. /strings Index def
  693. /gsubrs Index def
  694. % Read the top Dicts.
  695. /offsets 50 dict def
  696. /queued [] def
  697. /opdict null def % reserve a slot
  698. /fonts [ topdicts {
  699. 0 () /SubFileDecode filter /f exch def
  700. 40 dict begin
  701. % Preload defaults that differ from PostScript defaults,
  702. % or that are required.
  703. /FontType 2 def
  704. /PaintType 0 def
  705. /FontMatrix [0.001 0 0 0.001 0 0] def
  706. /charset StandardCharsets 0 get def
  707. /Encoding 0 def
  708. /FontInfo 10 dict
  709. dup /UnderlinePosition -100 put
  710. dup /UnderlineThickness 50 put
  711. def
  712. /Private 20 dict
  713. gsubrs length 0 ne { dup /GlobalSubrs gsubrs put } if
  714. def
  715. //topdictops Dict
  716. currentdict end
  717. } forall ] def
  718. % Read other tables with queued offsets.
  719. % We process these in order so we can advance if needed.
  720. % The CFF file may not be positionable.
  721. { % outer loop since offsets may be updated when processing
  722. CFFDEBUG { (offsets: ) print [ offsets { pop } forall ] == } if
  723. [ offsets { pop } forall ] { lt } .sort % process in order of appearance
  724. {
  725. CFFDEBUG { (queued offset: ) print dup =print flush (, current pos=) print pos = } if
  726. /queued_offset 1 index def
  727. StringCache 1 index .knownget {
  728. /f exch 0 () /SubFileDecode filter def
  729. } {
  730. /f cff def
  731. dup pos ne { dup pos sub nextstring pop } if % negative advance will cause error
  732. } ifelse
  733. offsets exch 2 copy get 3 1 roll undef
  734. CFFDEBUG { (exec queued: ) print dup == } if
  735. exec
  736. } forall
  737. offsets length 0 eq { exit } if
  738. } loop
  739. % Process out-of-order tables.
  740. CFFDEBUG { queued length =only ( queued) = flush } if
  741. queued { exec } forall
  742. % Update Encoding and CharStrings.
  743. fonts {
  744. begin
  745. currentdict /CIDFontType known {
  746. finishCIDFont
  747. } {
  748. forcecidfont //makeCIDFont //finishFont ifelse
  749. } ifelse
  750. end
  751. } forall
  752. % Wrap up.
  753. resname mark 0 1 fonts length 1 sub {
  754. CFFDEBUG { dup =only ( ) print flush } if
  755. dup names exch get
  756. forceresname { pop resname } if
  757. CFFDEBUG { dup == flush } if
  758. exch fonts exch get
  759. dup /CIDFontType known {
  760. % This is a CIDFont.
  761. dup /CIDFontName 3 index put
  762. 1 index exch /CIDFont defineresource
  763. } {
  764. % This is a font.
  765. dup /FontName 3 index put
  766. 1 index exch definefont
  767. } ifelse
  768. } for .dicttomark
  769. end % temporary dict
  770. end % FontSetInit ProcSet
  771. /FontSet defineresource
  772. } bind def
  773. % ---------------- Resource category definition ---------------- %
  774. currentdict end readonly
  775. languagelevel exch 2 .setlanguagelevel
  776. /FontSet /Generic /Category findresource dup length dict .copydict
  777. /Category defineresource pop
  778. /FontSetInit exch /ProcSet defineresource pop
  779. .setlanguagelevel