% Copyright (C) 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. % % This file is part of Aladdin Ghostscript. % % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author % or distributor accepts any responsibility for the consequences of using it, % or for whether it serves any particular purpose or works at all, unless he % or she says so in writing. Refer to the Aladdin Ghostscript Free Public % License (the "License") for full details. % % Every copy of Aladdin Ghostscript must include a copy of the License, % normally in a plain ASCII text file named PUBLIC. The License grants you % the right to copy, modify and redistribute Aladdin Ghostscript, but only % under certain conditions described in the License. Among other things, the % License requires that the copyright notice and this notice be preserved on % all copies. % $Id: gs_cff.ps,v 1.1 2000/03/09 08:40:39 lpd Exp $ % Loader for CFF (compressed) fonts. % The following are not implemented yet: % Deleted entries in the Name Index % Embedded PostScript % Multiple Master fonts % CIDFonts % Chameleon fonts % Synthetic fonts % Also, Type 2 charstrings are converted into FontType 2 fonts, % which may or may not be supported. 30 dict begin % ---------------- Standard strings (actually names) ---------------- % /StandardStrings mark % 0 /.notdef /space /exclam /quotedbl /numbersign /dollar /percent /ampersand /quoteright /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash /zero /one /two /three /four /five /six /seven /eight /nine /colon /semicolon /less /equal /greater /question /at /A /B /C /D /E /F /G /H /I /J /K /L /M /N /O /P % 50 /Q /R /S /T /U /V /W /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore /quoteleft /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o /p /q /r /s /t /u /v /w /x /y /z /braceleft /bar /braceright /asciitilde /exclamdown /cent /sterling /fraction % 100 /yen /florin /section /currency /quotesingle /quotedblleft /guillemotleft /guilsinglleft /guilsinglright /fi /fl /endash /dagger /daggerdbl /periodcentered /paragraph /bullet /quotesinglbase /quotedblbase /quotedblright /guillemotright /ellipsis /perthousand /questiondown /grave /acute /circumflex /tilde /macron /breve /dotaccent /dieresis /ring /cedilla /hungarumlaut /ogonek /caron /emdash /AE /ordfeminine /Lslash /Oslash /OE /ordmasculine /ae /dotlessi /lslash /oslash /oe /germandbls % 150 /onesuperior /logicalnot /mu /trademark /Eth /onehalf /plusminus /Thorn /onequarter /divide /brokenbar /degree /thorn /threequarters /twosuperior /registered /minus /eth /multiply /threesuperior /copyright /Aacute /Acircumflex /Adieresis /Agrave /Aring /Atilde /Ccedilla /Eacute /Ecircumflex /Edieresis /Egrave /Iacute /Icircumflex /Idieresis /Igrave /Ntilde /Oacute /Ocircumflex /Odieresis /Ograve /Otilde /Scaron /Uacute /Ucircumflex /Udieresis /Ugrave /Yacute /Ydieresis /Zcaron % 200 /aacute /acircumflex /adieresis /agrave /aring /atilde /ccedilla /eacute /ecircumflex /edieresis /egrave /iacute /icircumflex /idieresis /igrave /ntilde /oacute /ocircumflex /odieresis /ograve /otilde /scaron /uacute /ucircumflex /udieresis /ugrave /yacute /ydieresis /zcaron /exclamsmall /Hungarumlautsmall /dollaroldstyle /dollarsuperior /ampersandsmall /Acutesmall /parenleftsuperior /parenrightsuperior /twodotenleader /onedotenleader /zerooldstyle /oneoldstyle /twooldstyle /threeoldstyle /fouroldstyle /fiveoldstyle /sixoldstyle /sevenoldstyle /eightoldstyle /nineoldstyle /commasuperior % 250 /threequartersemdash /periodsuperior /questionsmall /asuperior /bsuperior /centsuperior /dsuperior /esuperior /isuperior /lsuperior /msuperior /nsuperior /osuperior /rsuperior /ssuperior /tsuperior /ff /ffi /ffl /parenleftinferior /parenrightinferior /Circumflexsmall /hyphensuperior /Gravesmall /Asmall /Bsmall /Csmall /Dsmall /Esmall /Fsmall /Gsmall /Hsmall /Ismall /Jsmall /Ksmall /Lsmall /Msmall /Nsmall /Osmall /Psmall /Qsmall /Rsmall /Ssmall /Tsmall /Usmall /Vsmall /Wsmall /Xsmall /Ysmall /Zsmall % 300 /colonmonetary /onefitted /rupiah /Tildesmall /exclamdownsmall /centoldstyle /Lslashsmall /Scaronsmall /Zcaronsmall /Dieresissmall /Brevesmall /Caronsmall /Dotaccentsmall /Macronsmall /figuredash /hypheninferior /Ogoneksmall /Ringsmall /Cedillasmall /questiondownsmall /oneeighth /threeeighths /fiveeighths /seveneighths /onethird /twothirds /zerosuperior /foursuperior /fivesuperior /sixsuperior /sevensuperior /eightsuperior /ninesuperior /zeroinferior /oneinferior /twoinferior /threeinferior /fourinferior /fiveinferior /sixinferior /seveninferior /eightinferior /nineinferior /centinferior /dollarinferior /periodinferior /commainferior /Agravesmall /Aacutesmall /Acircumflexsmall % 350 /Atildesmall /Adieresissmall /Aringsmall /AEsmall /Ccedillasmall /Egravesmall /Eacutesmall /Ecircumflexsmall /Edieresissmall /Igravesmall /Iacutesmall /Icircumflexsmall /Idieresissmall /Ethsmall /Ntildesmall /Ogravesmall /Oacutesmall /Ocircumflexsmall /Otildesmall /Odieresissmall /OEsmall /Oslashsmall /Ugravesmall /Uacutesmall /Ucircumflexsmall /Udieresissmall /Yacutesmall /Thornsmall /Ydieresissmall (001.000) (001.001) (001.002) (001.003) /Black /Bold /Book /Light /Medium /Regular /Roman /Semibold .packtomark def % ---------------- Standard encodings ---------------- % /StandardEncodings [ % StandardEncoding mark 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 0 111 112 113 114 0 115 116 117 118 119 120 121 122 0 123 0 124 125 126 127 128 129 130 131 0 132 133 0 134 135 136 137 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 138 0 139 0 0 0 0 140 141 142 143 0 0 0 0 0 144 0 0 0 145 0 0 146 147 148 149 0 0 0 0 .packtomark % ExpertEncoding mark 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 229 230 0 231 232 233 234 235 236 237 238 13 14 15 99 239 240 241 242 243 244 245 246 247 248 27 28 249 250 251 252 0 253 254 255 256 257 0 0 0 258 0 0 259 260 261 262 0 0 263 264 265 0 266 109 110 267 268 269 0 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 304 305 306 0 0 307 308 309 310 311 0 312 0 0 313 0 0 314 315 0 0 316 317 318 0 0 0 158 155 163 319 320 321 322 323 324 325 0 0 326 150 164 169 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 .packtomark ] readonly def % ---------------- Standard Charsets ---------------- % % We include an explicit 0 at the beginning of each charset. /StandardCharsets [ % ISOAdobe mark 0 1 1 228 { } for .packtomark % Expert mark 0 1 229 230 231 232 233 234 235 236 237 238 13 14 15 99 239 240 241 242 243 244 245 246 247 248 27 28 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 109 110 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 158 155 163 319 320 321 322 323 324 325 326 150 164 169 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 .packtomark % ExpertSubset mark 0 1 231 232 235 236 237 238 13 14 15 99 239 240 241 242 243 244 245 246 247 248 27 28 249 250 251 253 254 255 256 257 258 259 260 261 262 263 264 265 266 109 110 267 268 269 270 272 300 301 302 305 314 315 158 155 163 320 321 322 323 324 325 326 150 164 169 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 .packtomark ] readonly def % ---------------- Font loading ---------------- % % ------ Utilities ------ % /advance { % advance - f cff eq { /pos pos 3 -1 roll add store } { pop } ifelse } def /next { % - next f read { 1 advance DEBUG { ( ) print dup = } if } if } def /nextstring { % nextstring dup 0 eq { pop () } { string f exch readstring pop dup length advance DEBUG { ( ) print dup == } if } ifelse } def /card8 % - card8 /next load def /card16 { % - card16 card8 8 bitshift card8 add } def /offset { % offset 0 exch { 8 bitshift next add } repeat } def /sid % - sid /card16 load def /Index { % - Index mark card16 dup 0 ne { 1 exch next dup offset pop exch { dup offset dup 4 -1 roll sub 3 1 roll exch } repeat pop } if pop .packtomark [ exch { nextstring } forall ] readonly } def /tokens { % - tokens ... (op# = 12 means EOF) { f read not { 12 exit } if DEBUG { (..) print dup = } if 1 advance dup 12 eq { pop next 32 add exit } if dup 28 lt { exit } if dup 32 lt { 28 sub { { card16 32768 xor 32768 sub } { 4 offset dup 16#7fffffff gt { -1 32 bitshift add } if } { tokenreal } { 31 exit } } exch get exec } { dup 247 lt { 139 sub } { 247 sub { { next 108 add } { next 364 add } { next 620 add } { next 876 add } { next 108 add neg } { next 364 add neg } { next 620 add neg } { next 876 add neg } % 255 is deliberately omitted and will cause a rangecheck } exch get exec } ifelse } ifelse } loop } def /tokenbuf 100 string def /tokenput { % tokenput tokenbuf 2 index 3 -1 roll put 1 add } def /tokenrealarray [ (0123456789.E) { } forall [(E) 0 get /tokenput cvx (-) 0 get] cvx null % will give an error (-) 0 get { exit } ] readonly def /tokenreal { % - tokenreal 0 { next exch 1 index -4 bitshift tokenrealarray exch get exec tokenput % We must leave the byte on the stack temporarily so that % the exit will see a consistent stack state. 1 index 15 and tokenrealarray exch get exec tokenput exch pop } loop tokenbuf 0 3 -1 roll getinterval cvr exch pop } def /Dict { % Dict - /opdict exch store { mark tokens DEBUG { (tokens: ) print ] dup === mark exch aload pop } if opdict exch .knownget { exec } if cleartomark } loop cleartomark } def /idstring { % idstring dup 391 lt { StandardStrings } { 391 sub strings } ifelse exch get } def /idname { % idname idstring dup type /nametype ne { cvn } if } def /subfilefilter { % subfilefilter % SubFileDecode interprets a length of 0 as infinite. dup 0 le { pop pop () 0 } if () /SubFileDecode filter } def % ------ Top dictionary ------ % /offput { % offput - DEBUG { (queued: ) print 1 index =only ( ) print dup === } if currentdict exch aload length 1 add packedarray cvx offsets 3 1 roll put } def /queueput { % queueput - 16#7fffffff offsets { pop .min } forall pos sub nextstring 3 1 roll aload length 2 add packedarray cvx [ queued aload pop counttomark 2 add -1 roll ] /queued exch store } def /xxput { % xxput - 3 1 roll exch put } def /putfi { % putfi - FontInfo xxput } def /xdef { % xdef - exch def } def /topdictops mark 12 { exit } 0 { idstring /version putfi } 1 { idstring /Notice putfi } 32 { idstring /Copyright putfi } 2 { idstring /FullName putfi } 3 { idstring /FamilyName putfi } 4 { idstring /Weight putfi } 33 { 0 ne /isFixedPitch putfi } 34 { /ItalicAngle putfi } 35 { /UnderlinePosition putfi } 36 { /UnderlineThickness putfi } 37 { /PaintType xdef } 38 { /FontType xdef } % actually CharstringType 39 { counttomark array astore /FontMatrix xdef } 13 { /UniqueID xdef } 5 { counttomark array astore /FontBBox xdef } 40 { /StrokeWidth xdef } 14 { counttomark array astore /XUID xdef } 15 { dup StandardCharsets length lt { StandardCharsets exch get /charset xdef } { { queuecharset } offput } ifelse } 16 { dup StandardEncodings length lt { /Encoding xdef } { { queueEncoding } offput } ifelse } 17 { { readCharStrings } offput } 18 { exch /readPrivate cvx 2 packedarray offput } .dicttomark readonly def /readCharStrings { % readCharStrings - /CharStringArray Index put } def % ------ Charsets and encodings ------ % % Note: formats 1 and 2 can overflow the operand stack. % We'll fix this if it ever becomes necessary. /charsetformats [ { [ 0 CharStringArray length 1 sub { sid } repeat ] } { [ 0 CharStringArray length 1 sub { dup 0 eq { pop exit } if sid card8 1 add 2 index .min { exch 1 sub 1 index 1 add } repeat pop } loop ] } { [ 0 CharStringArray length 1 sub { dup 0 eq { pop exit } if sid card16 1 add 2 index .min { exch 1 sub 1 index 1 add } repeat pop } loop ] } ] readonly def /queuecharset { % queuecharset - { readcharset } queueput } def /readcharset { % readcharset - begin 0 () /SubFileDecode filter /f exch store charsetformats next get exec /charset exch def end } def /encodingformats [ { 1 1 next { next exch Encoding 3 1 roll put } for } { 1 next { next next 1 add { % Stack: gid code Encoding 1 index 3 index put exch 1 add exch 1 add } repeat pop } repeat pop } ] readonly def /queueEncoding { % queueEncoding - { readEncoding } queueput } def /readEncoding { % readEncoding - begin 0 () /SubFileDecode filter /f exch store /Encoding [ 256 { /.notdef } repeat ] def next encodingformats 1 index 127 and get exec 128 ge { % Read supplementary encodings. next { Encoding next sid idname put } repeat } if end } def % ------ Private dictionary ------ % /deltarray { % -mark- ... deltarray ... 0 counttomark 1 sub { counttomark -1 roll add dup } repeat pop counttomark array astore } def /privatedictops mark 12 { exit } 6 { deltarray /BlueValues xdef } 7 { deltarray /OtherBlues xdef } 8 { deltarray /FamilyBlues xdef } 9 { deltarray /FamilyOtherBlues xdef } 41 { /BlueScale xdef } 42 { /BlueShift xdef } 43 { /BlueFuzz xdef } 10 { 1 array astore /StdHW xdef } 11 { 1 array astore /StdVW xdef } 44 { deltarray /StemSnapH xdef } 45 { deltarray /StemSnapV xdef } 46 { 0 ne /ForceBold xdef } 47 { /ForceBoldThreshold xdef } 48 { /lenIV xdef } 49 { /LanguageGroup xdef } 50 { /ExpansionFactor xdef } 51 { /initialRandomSeed xdef } 19 { { readSubrs } offput } 20 { /defaultWidthX xdef } 21 { /nominalWidthX xdef } % Multiple Master fonts only 59 { /NDV xdef } 60 { /CDV xdef } 61 { /lenBuildCharArray xdef } .dicttomark readonly def /readPrivate { % readPrivate - exch 1 index f exch subfilefilter /f exch def /Private get begin //privatedictops Dict end /f cff def advance } def % ------ Main program ------ % % We need to pass the file as a parameter for the sake of the PDF % interpreter. /StartData { % StartData - currentfile exch subfilefilter ReadData } def /ReadData { % ReadData - % Initialize. 30 dict begin /cff exch def /pos 0 def /resname exch cvlit def % Read the header. /f cff def /vmajor next def /vminor next def /hdrsize next def /aoffsize next def % Read the Indexes. /names Index def /topdicts Index def /strings Index def /gsubrs Index def % Read the top Dicts. /offsets 50 dict def /queued [] def /opdict null def % reserve a slot /fonts [ topdicts { 0 () /SubFileDecode filter /f exch def 40 dict begin % Preload defaults that differ from PostScript defaults, % or that are required. /FontType 2 def /PaintType 0 def /FontMatrix [0.001 0 0 0.001 0 0] def /charset StandardCharsets 0 get def /Encoding 0 def /FontInfo 10 dict dup /UnderlinePosition -100 put dup /UnderlineThickness 50 put def /Private 20 dict gsubrs length 0 ne { dup /GlobalSubrs gsubrs put } if def //topdictops Dict currentdict end } forall ] def % Read other tables with queued offsets. DEBUG { (offsets: ) print [ offsets { pop } forall ] == } if { /f cff def DEBUG { (pos=) print pos = } if offsets pos 2 copy .knownget not { pop pop exit } if 3 1 roll undef exec } loop offsets length 0 ne { (Error: missing tables at ) print [ offsets { pop } forall ] == (Current position is ) print pos == flush stop } if % Process out-of-order tables. DEBUG { queued length =only ( queued) = flush } if queued { exec } forall % Update Encoding and CharStrings. fonts { begin % Construct the real Encoding. % The value of Encoding is either a number, for predefined % encodings, or an array of mixed GIDs and names. /Encoding mark Encoding DEBUG { (Encoding: ) print dup === flush } if dup type /integertype eq { StandardEncodings exch get { idname } forall } { { dup type /integertype eq { charset exch get idname } if } forall } ifelse .packtomark def % Construct the CharStrings. % Note that they may only correspond to an initial % subset of the charset. /CharStrings charset length CharStringArray length .min dict def DEBUG { charset length =only ( charset ) print CharStringArray length =only ( CharStringArray) = charset == flush } if 0 1 CharStrings maxlength 1 sub { dup CharStringArray exch get exch charset exch get idstring CharStrings xxput } for % Remove unwanted entries. currentdict /charset undef currentdict /CharStringArray undef end } forall % Wrap up. resname mark 0 1 fonts length 1 sub { DEBUG { dup =only ( ) print flush } if dup names exch get DEBUG { dup == flush } if exch fonts exch get dup /FontName 3 index put 1 index exch definefont } for .dicttomark end % temporary dict end % FontSetInit ProcSet /FontSet defineresource pop } bind def % ---------------- Resource category definition ---------------- % currentdict end readonly languagelevel exch 2 .setlanguagelevel /FontSet /Generic /Category findresource dup length dict .copydict /Category defineresource pop /FontSetInit exch /ProcSet defineresource pop .setlanguagelevel