% Copyright (C) 1994 Aladdin Enterprises. All rights reserved. % pdf_font.ps % PDF font operations. /.setlanguagelevel where { pop 2 .setlanguagelevel } if .currentglobal true .setglobal /pdfdict where { pop } { /pdfdict 100 dict def } ifelse GS_PDF_ProcSet begin pdfdict begin % We cache the PostScript font in an additional element of the % font resource dictionary, called PSFont. % ---------------- Encodings ---------------- % % Apply a list of differences to an Encoding. /updateencoding % updateencoding { exch dup length array copy exch dup 0 get exch dup length 1 sub 1 exch getinterval { dup type /nametype ne { exch pop } { 3 copy put pop 1 add } ifelse } forall pop } bdef % Get the Encoding for a font. /getencoding % getencoding { /Encoding knownoget { dup type /nametype eq { exch pop findencoding } { dup /BaseEncoding knownoget { findencoding 3 -1 roll pop exch } if /Differences knownoget { updateencoding } if } ifelse } if } bdef % Insert a modified encoding into a font if needed. /adjustencoding % adjustencoding { exch dup /Encoding known { 1 index /Encoding get exch getencoding dup 2 index /Encoding get ne { % Insert the new Encoding into the font. exch dup length dict copy dup /FID undef dup /Encoding 4 -1 roll put dup /FontName 2 copy get genfontname put dup /FontName get exch definefont } { pop } ifelse } { pop } ifelse } bdef % ---------------- Descriptors ---------------- % % Partial descriptors for the 14 built-in fonts. /standardfontdescriptors mark /Courier mark /Flags 16#23 .dicttomark /Courier-Oblique 1 index /Courier-Bold 1 index /Courier-BoldOblique 1 index /Helvetica mark /Flags 16#20 .dicttomark /Helvetica-Oblique 1 index /Helvetica-Bold 1 index /Helvetica-BoldOblique 1 index /Times-Roman mark /Flags 16#22 .dicttomark /Times-Bold 1 index /Times-Italic mark /Flags 16#62 .dicttomark /Times-BoldItalic 1 index /Symbol mark /Flags 16#4 .dicttomark /ZapfDingbats 1 index .dicttomark readonly def % ---------------- Utilities ---------------- % % Fabricate a font name by adding %'s on the end. /genfontname % genfontname { dup length string cvs { (%) concatstrings dup cvn FontDirectory exch known not { cvn exit } if } loop } bdef % Find a font, and adjust its encoding if necessary. /pdffindfont % pdffindfont { findfont adjustencoding } bdef % ---------------- Type 1 fonts ---------------- % /buildType1 % buildType1 { dup /BaseFont get pdffindfont } bdef % The state dictionary for the embedded Type 1 font reading procedure % has the following keys and values: % data - stream (filter) % buffer, buffer2 - string % left - (non-negative) integer % stream - (stream) dictionary % proc - procedure of the form {dict name} % When the procedure is executing, this dictionary is current. % Read an embedded Type 1 font. /readfontfilter % readfontfilter { % We make this a separate procedure so that we can % redefine it when we're writing PostScript. 0 () /SubFileDecode filter } bdef /readtype1 % readtype1 { % Read the definition, using a procedure-based filter % that turns binary/hex conversion on and off % at the right times. 6 dict begin /left 1 index /Length1 oget def /stream 1 index def true resolvestream /data exch def /buffer 200 string def % arbitrary /buffer2 buffer length 2.1 div cvi 1 sub string def currentdict end /type1read1 cvx 2 array astore cvx dup 0 get /proc 2 index put readfontfilter systemdict begin dup cvx exec closefile end % run /FontDescriptor oget /FontName oget findfont } bdef % Read the next block of data into the buffer. /type1readdata % type1readdata { 0 left 2 index length .min getinterval data exch readstring pop dup length left exch sub /left exch def DEBUG { (Read: ) print dup == flush } if } bdef % Read the next block of the initial text portion. /type1read1 { begin left 0 eq { /proc load 1 /type1read2 cvx put stream /Length2 oget /left exch def currentdict end type1read2 } { buffer type1readdata end } ifelse } bdef % Read the next block of the encrypted portion. /type1trailer (0000000000000000000000000000000000000000000000000000000000000000\n\ 0000000000000000000000000000000000000000000000000000000000000000\n\ 0000000000000000000000000000000000000000000000000000000000000000\n\ 0000000000000000000000000000000000000000000000000000000000000000\n\ 0000000000000000000000000000000000000000000000000000000000000000\n\ 0000000000000000000000000000000000000000000000000000000000000000\n\ 0000000000000000000000000000000000000000000000000000000000000000\n\ 0000000000000000000000000000000000000000000000000000000000000000\n\ cleartomark\n) readonly def /type1read2 { begin left 0 eq { /proc load 1 /type1read3 cvx put stream /Length3 oget dup /left exch def 0 eq { end type1trailer } { currentdict end type1read3 } ifelse } { buffer2 type1readdata buffer /ASCIIHexEncode filter dup 3 -1 roll writestring closefile buffer (>) search pop exch pop exch pop end } ifelse } bdef % Read the next block of the final text portion. % When finished, this procedure returns an empty string. /type1read3 { begin buffer type1readdata end } bdef % ---------------- Type 3 fonts ---------------- % /.notdefEncoding 256 { /.notdef } repeat 256 packedarray def /buildType3 % buildType3 { 8 dict begin /FontType 3 def /FontBBox 1 index /FontBBox get cvx def /FontMatrix 1 index /FontMatrix oget def /CharProcs 1 index /CharProcs oget def /FontName 1 index /Name get genfontname def /Encoding .notdefEncoding 2 index getencoding def /BuildGlyph { exch /CharProcs get exch oget false resolvestream pdfopdict pdfrun } bdef FontName currentdict end definefont exch pop } bdef % ---------------- TrueType fonts ---------------- % /TTfonts mark /Arial /Helvetica /Arial,Italic /Helvetica-Oblique /Arial,Bold /Helvetica-Bold /Arial,BoldItalic /Helvetica-BoldOblique /TimesNewRoman /Times-Roman /TimesNewRoman,Italic /Times-Italic /TimesNewRoman,Bold /Times-Bold /TimesNewRoman,BoldItalic /Times-BoldItalic .dicttomark readonly def /buildTrueType % buildTrueType { dup /BaseFont get dup TTfonts exch .knownget { exch pop } if pdffindfont } bdef % ---------------- Font lookup ---------------- % /fonttypeprocs mark % -proc- /Type1 /buildType1 cvx /MMType1 1 index /Type3 /buildType3 cvx /TrueType /buildTrueType cvx .dicttomark readonly def /resourcefont % resourcefont { dup /PSFont .knownget { /FID .knownget { type /fonttype eq } { false } ifelse } { false } ifelse { /PSFont get } { dup dup /FontDescriptor knownoget { /FontFile knownoget } { false } ifelse { 1 index 3 1 roll readtype1 adjustencoding } { dup /Subtype get fonttypeprocs exch get exec } ifelse 2 copy /PSFont exch put exch pop } ifelse } bdef drawopdict begin /d0 /setcharwidth load def /d1 /setcachedevice load def /Tf { exch Page /Resources oget /Font oget exch oget resourcefont false { %**************** PATCH for #exec **************** /FontName get (xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) cvs { dup dup length 1 sub 1 getinterval (%) ne { exit } if 0 1 index length 1 sub getinterval } loop cvn exch Tf currentfont %**************** END PATCH **************** }{ exch scalefont dup setfont }ifelse /TextFont gput } bdef end end % pdfdict end % GS_PDF_ProcSet .setglobal