home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-15 | 31.0 KB | 1,011 lines |
- %!PS-Adobe-3.0
- %%BeginFile: zsfont.ps
- %
- % Copyright (c) 1994, 1995 Zenographics, Inc., Irvine, CA. All rights reserved
- %
- % ZScript font emulator
- %
- % This sub-system is designed to allow ZS to make 'placeholder' fonts
- % that substitute for the actual TrueType fonts that we are using. The
- % placeholders are actually Type3 fonts that are dolled up to make them
- % look like Type1's to any PostScript code that may make assumptions about
- % them when manipulating them.
- %
- % First, 'findfont' requests are hooked. The hook uses the special ZS operator
- % 'getplatformfontmetrics' to determine if the font is not loaded, but is
- % available in from the renderer. If not, pass thru to the old findfont
- % handler. If the font is a platform font, create a placeholder font & return
- % to user as a bona fide font.
- %
- % Passthru fonts: This is a Type3 font with extra entries to make it look & act
- % like a Type 1 where necessary. As long as the font is not skewed, clipped or
- % shown at point sizes > 1000, the xfont mechanism in GS will render the
- % glyphs without actually calling the BuildChar/Glyph procedure in the font.
- % When BuildChar/Glyph is actually invoked by the GS font engine, it uses
- % another special ZS operator 'getglyphoutline' to enumerate the font outline
- % and print it to the display. Later, when Level 2 is implemented, we will
- % also keep the enumerated outlines in a cache for speed.
- %
- % The following required dictionary entries are created from the
- % getplatformfontmetrics call:
- % Encoding
- % CharStrings
- % FontName
- % FontBBox
- % FontInfo.
- % .FamilyName
- % .FullName
- % .Weight
- % .ItalicAngle
- % .UnderlinePosition
- % .UnderlineThickness
- % .isFixedPitch
- %
- % The following entries are "dummied out":
- % FontType = 3
- % FontMatrix = [0.001 0 0 0.001]
- % PaintType = 1
- % FontInfo.
- % .version = (001.00)
- % .Notice = ()
- %
- % The following entries contain the code/data needed to emulate a Type1 font:
- % UniqueID = special UID computed by font system
- % BuildChar
- % BuildGlyph
- % Private
- %
- %
- % The following special ZS operators are used exclusively by this font
- % mechanism:
- %
- % <fontname> getplatformfontmetrics [mark <BBoxllx><BBoxlly><BBoxurx>
- % <BBoxury><italicAngle>
- % <underscoreSize><underscorePos>
- % <isFixed>
- % %These are strs: <Weight><familyName><fullName>
- % <UniqueID>
- % %first one is str: <Private><sideBearingsAreTrue>
- % <Encoding#> true]
- % | [false]
- % where the metrics are all in PS 1000 em square font units & conventions.
- % Encoding# = 0 DingBats, 1 Symbol, 2 Std, 3 Win-ANSI
- %
- %
- % <Private><glyph> getglyphmetrics [<xWidth><yWidth><llxBBox><llyBBox>
- % <urxBBox><uryBBox> true]
- % | [false]
- %
- %
- % <Private><glyph> getglyphoutline [mark [<drawingOpAndData>]...
- % <op count> true]
- % | [false]
- %
- % where a <drawingOpAndData> is:
- % moveto: x y 0 (imlicit closepath of previous sub-path)
- % lineto: x y 1
- % curveto: x1 y1 x2 y2 x3 y3 2
- %
- % The first point to draw is on the top of the stack. There is an implicit
- % closepath of the last sub-path after its points are drawn;
- %
- % and <op count> is the count of <drawingOpandData> n-tuples. All units
- % are in PostScript 1000 em square units. Moves are absolute.
- %
- %
- % mark [<UniqueID>...] releaseUIDsexcept --
- %
- % This operator will release all the allocated UID slots, except for the
- % ones enumerated. UIDs are not released when a font is deallocated, so
- % the 'restore' operator must be hooked to call this operator with the list
- % of all fonts in fontdict after the restore.
- %
- %
- % <Private><UniqueID><remap bool> connectUIDtoprivate --
- %
- % This operator associates Private with UniqueID. If remap is true, UniqueID
- % must already be defined; UniqueID will be redefined. In the case where
- % remap is false, Private is mapped to UniqueID only if UniqueID isn't already
- % defined. This operator is needed because of the following situation:
- % if a user takes one of our fake type3 type1's, mofifies it,
- % changes its UID, then does a definefont on it, we must advise the
- % underlying font mechanism that the PrivateStr has another alias (UID).
- % If we don't do this, the xfont mechanism will not work for the new
- % font, since the unknown UID will not enable the xfont mechanism to find
- % the PrivateStr. This is unfortunate since the above scenario is
- % typical when changing a font's /Metrics entry.
- %
- % -- newUID <int>
- %
- % This operator allocates a new UID number from the same pool that the
- % xfont mechanism draws from.
- %
- %
- % [<glyphName><sidebearing> true] | [false] newxglyphsidebearing --
- %
- % If true, set a new sidebearing for the next xfont rendering that comes
- % along. If false, disable waiting sidebearing.
- %
- %
- % -- replacefindfont -- replace findfont operator with platform version
- /replacefindfont
- {
- systemdict begin
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % findfont hook
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- /__oldfindfont /findfont load def % make a copy of old findfont
-
- % 1-time create fake CharStrings entries that we will use in fonts
- % temp procedure to create CharStrings:
- % <CharStringsName><char name array> proc --
- {
- dup length dict begin
- { {} readonly def} %turn char name array into dict
- forall
- currentdict readonly
- end
- def
- }
-
- /__StandardCharStrings
- [
- /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
- /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
- /grave/acute/circumflex/tilde/macron/breve/dotaccent/dieresis/ring/cedilla
- /hungarumlaut/ogonek/caron/dotlessi/quotesingle/space/exclam/quotedbl
- /numbersign/dollar/percent/ampersand/quotesingle/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/bracketleft
- /backslash/bracketright/asciicircum/underscore/grave/braceleft/bar/braceright
- /asciitilde/quotesinglbase/florin/quotedblbase/ellipsis/dagger/daggerdbl
- /ansicircumflex/perthousand/Scaron/guilsinglleft/OE/quoteleft/quoteright
- /quotedblleft/quotedblright/bullet/endash/emdash/ansitilde/trademark/scaron
- /guilsinglright/oe/Ydieresis/ansispace/exclamdown/cent/sterling/currency/yen
- /brokenbar/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot
- /ansihyphen/registered/macron/degree/plusminus/twosuperior/threesuperior
- /acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine
- /guillemotright/onequarter/onehalf/threequarters/questiondown/Agrave
- /Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla/Egrave/Eacute
- /Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis/Eth/Ntilde/Ograve
- /Oacute/Ocircumflex/Otilde/Odieresis/multiply/Oslash/Ugrave/Uacute/Ucircumflex
- /Udieresis/Yacute/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis
- /aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex
- /idieresis/eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide/oslash
- /ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis
- ]
- 2 index exec
-
- /__DingbatCharStrings
- [
- /space/a1/a2/a202/a3/a4/a5/a119/a118/a117/a11/a12/a13/a14/a15/a16/a105/a17
- /a18/a19/a20/a21/a22/a23/a24/a25/a26/a27/a28/a6/a7/a8/a9/a10/a29/a30/a31/a32
- /a33/a34/a35/a36/a37/a38/a39/a40/a41/a42/a43/a44/a45/a46/a47/a48/a49/a50/a51
- /a52/a53/a54/a55/a56/a57/a58/a59/a60/a61/a62/a63/a64/a65/a66/a67/a68/a69/a70
- /a71/a72/a73/a74/a203/a75/a204/a76/a77/a78/a79/a81/a82/a83/a84/a97/a98/a99
- /a100/a101/a102/a103/a104/a106/a107/a108/a112/a111/a110/a109/a120/a121/a122
- /a123/a124/a125/a126/a127/a128/a129/a130/a131/a132/a133/a134/a135/a136/a137
- /a138/a139/a140/a141/a142/a143/a144/a145/a146/a147/a148/a149/a150/a151/a152
- /a153/a154/a155/a156/a157/a158/a159/a160/a161/a163/a164/a196/a165/a192/a166
- /a167/a168/a169/a170/a171/a172/a173/a162/a174/a175/a176/a177/a178/a179/a193
- /a180/a199/a181/a200/a182/a201/a183/a184/a197/a185/a194/a198/a186/a195/a187
- /a188/a189/a190/a191
- ]
- 2 index exec
-
- /__SymbolCharStrings
- [
- /space/exclam/universal/numbersign/existential/percent/ampersand/suchthat
- /parenleft/parenright/asteriskmath/plus/comma/minus/period/slash/zero/one
- /two/three/four/five/six/seven/eight/nine/colon/semicolon/less/equal/greater
- /question/congruent/Alpha/Beta/Chi/Delta/Epsilon/Phi/Gamma/Eta/Iota/theta1
- /Kappa/Lambda/Mu/Nu/Omicron/Pi/Theta/Rho/Sigma/Tau/Upsilon/sigma1/Omega/Xi
- /Psi/Zeta/bracketleft/therefore/bracketright/perpendicular/underscore
- /radicalex/alpha/beta/chi/delta/epsilon/phi/gamma/eta/iota/phi1/kappa/lambda
- /mu/nu/omicron/pi/theta/rho/sigma/tau/upsilon/omega1/omega/xi/psi/zeta
- /braceleft/bar/braceright/similar/Upsilon1/minute/lessequal/fraction/infinity
- /florin/club/diamond/heart/spade/arrowboth/arrowleft/arrowup/arrowright
- /arrowdown/degree/plusminus/second/greaterequal/multiply/proportional
- /partialdiff/bullet/divide/notequal/equivalence/approxequal/ellipsis
- /arrowvertex/arrowhorizex/carriagereturn/aleph/Ifraktur/Rfraktur/weierstrass
- /circlemultiply/circleplus/emptyset/intersection/union/propersuperset
- /reflexsuperset/notsubset/propersubset/reflexsubset/element/notelement/angle
- /gradient/registerserif/copyrightserif/trademarkserif/product/radical/dotmath
- /logicalnot/logicaland/logicalor/arrowdblboth/arrowdblleft/arrowdblup/arrowdblright/arrowdbldown
- /lozenge/angleleft/registersans/copyrightsans/trademarksans/summation
- /parenlefttp/parenleftex/parenleftbt/bracketlefttp/bracketleftex/bracketleftbt
- /bracelefttp/braceleftmid/braceleftbt/braceex/apple/angleright/integral
- /integraltp/integralex/integralbt/parenrighttp/parenrightex/parenrightbt
- /bracketrighttp/bracketrightex/bracketrightbt/bracerighttp/bracerightmid
- /bracerightbt
- ]
- 3 -1 roll exec
-
- % This dict is used as a marker when on the dict stack: If its uniquely-
- % named entry is found by 'where,' we know the marker is on the dictstack
- /__DefiningFontDict 1 dict dup /__DefiningFontMarker__ 0 put def
-
- % These fonts will be substituted for the other font if not found
- /__KnownFontSubstitutes
- mark
- %Substitute_from_name [Substitute_to_name X-scale(opt) Y-scale(opt)]
- /AvantGarde-Book [/Helvetica 0.916 1]
- /AvantGarde-Demi [/Helvetica-Bold 0.916 1]
- /AvantGarde-BookOblique [/Helvetica-Oblique 0.916 1]
- /AvantGarde-DemiOblique [/Helvetica-BoldOblique 0.916 1]
- /Bookman-Light [/Times-Roman 1.2 1]
- /Bookman-Demi [/Times-Bold 1.2 1]
- /Bookman-LightItalic [/Times-Italic 1.1 1]
- /Bookman-DemiItalic [/Times-BoldItalic 1.2 1]
- /Palatino-Roman [/Times-Roman 1.11 1]
- /Palatino-Italic [/Times-Italic 1.11 1]
- /Palatino-Bold [/Times-Bold 1.11 1]
- /Palatino-BoldItalic [/Times-BoldItalic 1.11 1]
- /NewCenturySchlbk-Roman [/Times-Roman 1.175 1]
- /NewCenturySchlbk-Italic [/Times-Italic 1.175 1]
- /NewCenturySchlbk-Bold [/Times-Bold 1.175 1]
- /NewCenturySchlbk-BoldItalic [/Times-BoldItalic 1.175 1]
- /Helvetica-Narrow [/Helvetica 0.82 1]
- /Helvetica-Narrow-Bold [/Helvetica-Bold 0.82 1]
- /Helvetica-Narrow-Oblique [/Helvetica-Oblique 0.82 1]
- /Helvetica-Narrow-BoldOblique [/Helvetica-BoldOblique 0.82 1]
- /ZapfChancery-MediumItalic /Times-Italic
-
- % create dictionary from pairs
- counttomark 2 idiv dup dict
- begin
- {def}
- repeat
- pop
- currentdict
- end
- readonly def
-
- % Manufacture new type3 font dict:
- %key mark <BBoxllx><BBoxlly><BBoxurx><BBoxury><italicAngle>
- % <underscoreSize><underscorePos><isFixed><Weight>
- % <familyName><fullName><UniqueID><Private><SidebearingsTrue>
- % <Encoding#>
- %
- % returns: key dict
- %
- /__buildfontfromplatformmetrics
- {
- 14 dict begin % one bigger for definefont's FID
- /FontType 3 def
- /FontMatrix [0.001 0 0 0.001 0 0]readonly def
- dup 2 ge
- {pop __StandardCharStrings StandardEncoding}
- %else
- {
- 1 eq
- {__SymbolCharStrings SymbolEncoding}
- %else equals 0
- {__DingbatCharStrings DingbatsEncoding}
- ifelse
- }
- ifelse
- /Encoding exch def
- /CharStrings exch def % create this for PSCRIPT.DRV
- pop % ignore SidebearingsTrue
- 4 dict begin
- /PrivateStr exch def
- /RequestedName 14 index def
- currentdict
- end
- /Private exch def
- /UniqueID exch def
- /PaintType 0 def
- /StrokeWidth 0 def
-
- 9 dict begin
- /version (001.000)readonly def
- /Notice ()readonly def
- /FullName exch readonly def
- /FamilyName exch readonly def
- /Weight exch readonly def
- /isFixedPitch exch def
- /UnderlinePosition exch def
- /UnderlineThickness exch def
- /ItalicAngle exch def
-
- currentdict %...dict
- end
- readonly
- /FontInfo exch def
-
- 4 array astore cvx readonly % executable is bogus, but customary
- /FontBBox exch def
-
- cleartomark %key mark [...]
-
- /FontName 1 index def %key
-
- % Font's BuildGlyph proc
- % <fontdict><glyphname> BuildGlyph --
- /BuildGlyph
- {
- exch
- begin
- dup /.notdef eq
- % nop if .notdef
- {pop}
- %else
- % get the glyph from platform, enumerate & render
- { %glyphname
- Private /PrivateStr get %glyphname private
- dup type /nulltype eq
- {
- % This font is a stub for a pre-loaded fake Type 1.
- % Get the real PrivateStr by doing a getplatformfontmetrics,
- % then stick it into the font & force the UniqueID to
- % be associated with the new PrivateStr.
- pop
- currentdict
- Private begin
- currentglobal currentdict gcheck setglobal
- RequestedName getplatformfontmetrics not
- {setglobal end end exch stop}
- if
- 3 -1 roll /PrivateStr exch def
- cleartomark
- currentglobal
- PrivateStr
- exch /UniqueID known
- {
- dup UniqueID true connectUIDtoprivate
- }
- if
- end
- }
- if
- exch %private glyphname
- 2 copy
- getglyphmetrics % *original* sidebearings
- {
- %private glyphname
- % <xWidth><yWidth><llxBBox>
- % <llyBBox><urxBBox><uryBBox>
- currentdict /Metrics .knownget
- {
- 7 index .knownget
- {
- dup type
- dup /integertype eq exch /realtype eq or
- {
- % we've got new xWidth + set yWidth = 0
- 0 %y-width to 0
- }
- %else
- {
- % Array entry means sidebearings 2 adjust
- aload
- length 2 eq
- {
- % new X-width & sidebearing
- 0 % y-width to 0
- }
- %else
- {
- % new X/Y width & X/Y sidebearing
- pop % ignore y-component
- }
- ifelse
- exch
- %private glyphname
- % <xWidth><yWidth><llxBBox>
- % <llyBBox><urxBBox><uryBBox>
- % xwidth ywidth sidebearing
-
- % adjust bbox for new sidebearings
- dup 7 index sub
- dup 9 -1 roll add 8 1 roll
- dup 7 -1 roll add 6 1 roll
-
- % note that sidebearings changed
- 10 1 roll
- 10 index exch true newxglyphsidebearing
- }
- ifelse
- 8 -2 roll pop pop 6 2 roll % new x/y-width
- }
- if
- }
- if
-
- % Expand bbox by a 3 pixels, since filling an outline
- % in Type 3 mode tends to fatten the finished product
- % & shift it over.
- %
- 3 3 idtransform 3 -1 roll add 3 1 roll add exch
-
- % If stroked font, also fatten by width of line.
- %
- currentdict /PaintType .knownget {0 ne}{false}ifelse
- {
- 1.415 currentmiterlimit max
- currentdict /StrokeWidth .knownget {ceiling}{1}ifelse
- mul 2 div
- % llx lly urx ury exp
- 5 1 roll 4 index add
- % exp llx lly urx ury+
- 5 1 roll 3 index add
- % ury+ exp llx lly urx+
- 5 1 roll 2 index sub
- % urx+ ury+ exp llx lly-
- 5 1 roll exch sub
- % lly- urx+ ury+ llx-
- 4 1 roll
- }
- if
- setcachedevice
- false
- }
- %else
- {
- % No glyph available
- dup /fraction ne
- {true}
- %else
- {
- % substitute a slash for fraction bar
- pop
- % .. a "fraction" width is usually 90% of "0" advance
- % .. we further cut the 90% into 3rds
- dup /zero getglyphmetrics not
- {/fraction true} %private glyph
- %else
- {
- pop pop pop pop pop %private width
- 0.3 mul %private .3width0
- exch /slash 2 copy
- getglyphmetrics not
- {3 -1 roll pop true} %private glyph
- %else
- { %.3width0 private /fraction
- % <xW><yW><llx><lly><urx>
- % <ury>
- 9 -1 roll
-
- % new advance width is 30% of zero's wid
- 7 -1 roll
- pop
- 6 1 roll %private /fraction
- %.3wid yW llx lly urx ury
-
- % y-width is 0
- 5 -1 roll pop 0 5 1 roll
-
- % center slash bbox over nu advance box
- % the rest of the slash is under/overhang
- 1 index 4 index % slash's bbox width
- sub
- 6 index sub
- 2 div floor
- neg 4 index sub % additional sidebearing
- dup dup %private /slash .3wid
- % yW llx lly urx ury
- % adjust adjust adjust
- 9 1 roll
- 6 -1 roll
- add
- 5 1 roll
- 3 -1 roll
- add
- exch %private /slash adjust
- % .3wid yW llx' lly
- % urx' ury
-
- % Do any /Metrics modifications needed
- currentdict /Metrics .knownget
- {
- 8 index .knownget
- {
- dup type
- dup /integertype eq exch /realtype eq or
- {
- % we've got new xWidth + set yWidth = 0
- 0 %y-width to 0
- }
- %else
- {
- % Array entry means sidebearings 2 adjust
- aload
- length 2 eq
- {
- % new X-width & sidebearing
- 0 % y-width to 0
- }
- %else
- {
- % new X/Y width & X/Y sidebearing
- pop % ignore y-component s/brng
- }
- ifelse
- %private glyphname adjust
- % <xWidth><yWidth><llxBBox>
- % <llyBBox><urxBBox><uryBBox>
- % xwidth ywidth sidebearing
-
- % adjust bbox for new sidebearings
- dup 7 index sub
- dup 9 -1 roll add 8 1 roll
- dup 7 -1 roll add 6 1 roll
-
- % note that sidebearings changed
- 11 1 roll
- 11 index exch true
- newxglyphsidebearing
- }
- ifelse
- 8 -2 roll pop pop 6 2 roll % new x/y-width
- }
- if
- }
- if
-
- % Expand bbox if stroked font
- currentdict /PaintType .knownget {0 ne}{false}ifelse
- {
- 1.415 currentmiterlimit max
- currentdict /StrokeWidth .knownget {ceiling}{1}ifelse
- mul 2 div
- % llx lly urx ury exp
- 5 1 roll 4 index add
- % exp llx lly urx ury+
- 5 1 roll 3 index add
- % ury+ exp llx lly urx+
- 5 1 roll 2 index sub
- % urx+ ury+ exp llx lly-
- 5 1 roll exch sub
- % lly- urx+ ury+ llx-
- 4 1 roll
- }
- if
- % set cache & offset rendering to land
- % in the right place
- setcachedevice %private /slash adjust
- 0 translate % force -ve sidebearing
-
- false
- }
- ifelse
- }
- ifelse
- }
- ifelse
- }
- ifelse
-
- % Based on bool which preceding code left on stak
- {pop pop} % no glyph available, fail
- %else
- {
- %private glyphname [sideadjust]
- % Paint the glyph by enumerating & filling outline
- %
- % maybe hafta translate in lieu of newxglyphsidebearing
- dup type /nametype ne
- {
- false newxglyphsidebearing
- 0 translate
- }
- if
-
- getglyphoutline
- {
- %mark [<drawingOpAndData>]... <opcnt>
- % enumerate font outline into a path
- %
- % Points are rounded to quarter pixels to
- % improve print quality.
- {
- dup 0 eq
- {
- pop closepath
- transform
- 4 mul floor 4 div .125 add
- exch
- 4 mul floor 4 div .125 add
- exch
- itransform
- moveto
- }
- %else
- {
- dup 1 eq
- {
- pop
- transform
- 4 mul floor 4 div .125 add
- exch
- 4 mul floor 4 div .125 add
- exch
- itransform
- lineto
- }
- %else
- {
- 2 eq
- {
- transform
- 4 mul floor 4 div .125 add
- exch
- 4 mul floor 4 div .125 add
- exch
- itransform
- 6 2 roll
- transform
- 4 mul floor 4 div .125 add
- exch
- 4 mul floor 4 div .125 add
- exch
- itransform
- 6 2 roll
- transform
- 4 mul floor 4 div .125 add
- exch
- 4 mul floor 4 div .125 add
- exch
- itransform
- 6 2 roll
- curveto
- }
- if
- }
- ifelse
- }
- ifelse
- }
- repeat
- closepath
- cleartomark
-
- % fill or stroke path, depending on PaintType
- PaintType 2 eq
- {StrokeWidth setlinewidth stroke}
- %else
- {fill}
- ifelse
- }
- if
- }
- ifelse
- }
- ifelse
- end
- }
- def %bind will make R/O
-
- % Font's BuildChar proc just maps into a BuildGlyph
- % <fontdict><charcode> BuildChar --
- /BuildChar
- {
- 1 index /Encoding get exch get
- BuildGlyph
- }
- def %bind will make R/O
-
- currentdict %key dict
- end
- }
- bind def
-
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % This is the new findfont proc
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- /findfont % replace findfont with new ver
- {
- FontDirectory 1 index known
- {
- __oldfindfont % cascade to old proc if already known
- __fixupstubfont
- }
- %else
- % Must try to substitute req'd font with a platform font
- {
- dup type /stringtype eq {cvn}if % if key is a string, convert to name
- dup getplatformfontmetrics not %key [...] bool
-
- dup
- % try making *known* font substitutions if font not known
- {
- pop
- __KnownFontSubstitutes 1 index .knownget
- {
- % known font substitution... do it
- %key fontname_or_array
- dup type /arraytype eq
- {aload pop}
- %else
- {1 1}
- ifelse %key substname scalex scaley
- 3 -1 roll %key scalex scaley substname
- {findfont} %key scalex scaley font
- stopped
- {
- pop pop pop
- true
- }
- %else
- {
- dup maxlength dict
- begin
- {
- % copy found font into current dict w/mods
- exch
- % our definefont will put in its own UniqueID later
- dup /FID eq 1 index /UniqueID eq or
- {pop pop}
- %else
- { %key scalex scaley value key
- dup /FontName eq
- {exch pop 3 index exch}
- if
- dup /FontMatrix eq
- {
- exch
- 3 index 3 index 6 array scale
- exch 6 array concatmatrix
- readonly
- exch
- }
- if
- exch def
- }
- ifelse
- }
- forall %key scalex scaley
- pop pop
- currentdict %key dict
- end
- false
- }
- ifelse
- }
- %else
- {true}
- ifelse
- }
- if
-
- dup
- % try substituting default font w/property copying if unsuccessful
- {
- pop
- % We go to some trouble to parse the font name and extract
- % properties from it.
- %
- % Look for properties in the font name.
- dup dup length string cvs
- 0 exch
- [
- [(Bold) 1] [(Demi) 1]
- [(Italic) 2] [(Oblique) 2]
- ]
- { %...bitmask namestr subarray
- 2 copy 0 get search
- { pop pop pop 1 get 3 -1 roll or exch }
- %else
- { pop pop }
- ifelse
- }
- forall %...bitmask namestr
- pop %...bitmask
-
- % Substitute alternate font based on accumulated bit mask
- [/Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique]
- exch get
- getplatformfontmetrics not
- }
- if
-
- dup
- % try substituting bottom-line default font if unsuccessful
- {pop /Courier getplatformfontmetrics not}
- if
-
- {__oldfindfont} % no platform font: cascade to old one
- %else
- {
- dup type /dicttype ne
- {
- __buildfontfromplatformmetrics
- % Put a marker on dict stack to prevent 'our' definefont
- % from doing extra work twice. We must call a late-bound
- % 'definefont' to satisfy any potential later hookers.
- __DefiningFontDict begin
- /definefont load exec %font
- end
- }
- %else
- {/definefont load exec} %font
- ifelse
- }
- ifelse
- }
- ifelse
- }
- def %don't bind
-
-
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % subroutine of findfont to reload PrivateStr of stub fonts
- % <font> __fixupstubfont <font>
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- /__fixupstubfont
- {
- % If found font is one of our fake Type 3's & it has the PrivateStr
- % nulled out, load it now.
- false 1 index rcheck %font bool
- {
- 1 index /Private .knownget %font bool [dict] bool
- {
- dup rcheck %font bool dict bool
- {
- /PrivateStr .knownget %font bool [str] bool
- {
- type /nulltype eq %font bool bool
- exch pop %font bool
- }
- if
- }
- %else %font bool dict
- {pop} %font bool
- ifelse
- }
- if
- }
- if %font bool
-
- {
- % This font is a stub for a pre-loaded fake Type 1.
- % Get the real PrivateStr by doing a getplatformfontmetrics,
- % then stick it into the font & force the UniqueID to
- % be associated with the new PrivateStr.
- dup /UniqueID known
- {
- dup begin
- Private begin
- currentglobal currentdict gcheck setglobal
- RequestedName getplatformfontmetrics
- {
- 3 -1 roll /PrivateStr exch def
- cleartomark
- PrivateStr UniqueID true connectUIDtoprivate
- }
- if
- setglobal
- end
- end
- }
- if
- }
- if
- }
- def
-
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % restore hook
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- /__oldrestore /restore load def % make a copy of old restore
-
- % This is the new restore proc
- /restore % replace find fontfont with new ver
- {
- __oldrestore % cascade to old proc first
-
- % push a mark on stack, then UIDs of all fonts still in FontDirectory
- mark
- FontDirectory
- {
- exch pop %...dict
- dup type /dicttype eq %...dict bool
- 1 index rcheck and
- {
- /UniqueID .knownget % push UID of this font if present
- }
- %else
- {pop}
- ifelse
- }
- forall %mark [UID]...
-
- % release all UIDs not in FontDictionary
- releaseUIDsexcept
- }
- odef %odef will make R/O
-
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % definefont hook
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- /__olddefinefont /definefont load def % make a copy of old definefont
-
- % This is the new definefont proc. We must hook this & invoke the
- % connectUIDtoprivate (see comments in main proc header, above) if this
- % font is one of our type3 type1's.
- %
- /definefont % replace find fontfont with new ver
- { %key dict
- /__DefiningFontMarker__ where % don't do our job if called by findfont
- {pop}
- %else
- {
- % is this one of our fake type3 type1's?
- %
- dup type /dicttype eq %key dict bool
- {dup rcheck}
- %else
- {false}
- ifelse
- {
- dup /Private .knownget %key dict [dict] bool
- {
- dup rcheck
- {true}
- %else
- {pop false}
- ifelse
- }
- %else
- {false}
- ifelse
- {
- dup /PrivateStr known %key dict dict bool
- {
- 1 index /UniqueID known %key dict dict bool
- {true}
- %else
- {
- % If there's no UID, try to assign one
- %
- 1 index wcheck
- {1 index /UniqueID newUID put true}
- %else
- {false}
- ifelse
- }
- ifelse
- }
- %else
- {false}
- ifelse
- {
- % This is one of our fake type3 type1's.
- % If there is a UniqueID, we must connect it to PrivateStr.
- %
- /PrivateStr get %key dict str
- 1 index /UniqueID get %key dict str uid
- {false connectUIDtoprivate}%key dict
- stopped % operands haven't been pre-validated
- {pop pop pop}
- if
- }
- %else %key dict dict
- {pop}
- ifelse %key dict
- }
- if
- }
- if %key dict
- }
- ifelse
- __olddefinefont
- }
- odef %odef will make R/O
-
- end
- }
- bind def
-
- % Hook the findfont-related operators
- %
- replacefindfont
-