home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / servis / ovladace / drivers / CPPLW9xNTgb.exe / CPP_L / Driver / ZSFONT.PS < prev    next >
Encoding:
Text File  |  1995-11-15  |  31.0 KB  |  1,011 lines

  1. %!PS-Adobe-3.0
  2. %%BeginFile: zsfont.ps
  3. %
  4. %   Copyright (c) 1994, 1995 Zenographics, Inc., Irvine, CA. All rights reserved
  5. %
  6. % ZScript font emulator
  7. %
  8. % This sub-system is designed to allow ZS to make 'placeholder' fonts
  9. % that substitute for the actual TrueType fonts that we are using. The
  10. % placeholders are actually Type3 fonts that are dolled up to make them
  11. % look like Type1's to any PostScript code that may make assumptions about
  12. % them when manipulating them.
  13. %
  14. % First, 'findfont' requests are hooked. The hook uses the special ZS operator
  15. % 'getplatformfontmetrics' to determine if the font is not loaded, but is
  16. % available in from the renderer. If not, pass thru to the old findfont 
  17. % handler. If the font is a platform font, create a placeholder font & return
  18. % to user as a bona fide font.
  19. %
  20. % Passthru fonts: This is a Type3 font with extra entries to make it look & act
  21. % like a Type 1 where necessary. As long as the font is not skewed, clipped or
  22. % shown at point sizes > 1000, the xfont mechanism in GS will render the
  23. % glyphs without actually calling the BuildChar/Glyph procedure in the font.
  24. % When BuildChar/Glyph is actually invoked by the GS font engine, it uses
  25. % another special ZS operator 'getglyphoutline' to enumerate the font outline
  26. % and print it to the display. Later, when Level 2 is implemented, we will
  27. % also keep the enumerated outlines in a cache for speed.
  28. %
  29. % The following required dictionary entries are created from the
  30. % getplatformfontmetrics call:
  31. %   Encoding
  32. %   CharStrings
  33. %   FontName
  34. %   FontBBox
  35. %   FontInfo.
  36. %           .FamilyName
  37. %           .FullName
  38. %           .Weight
  39. %           .ItalicAngle
  40. %           .UnderlinePosition
  41. %           .UnderlineThickness
  42. %           .isFixedPitch
  43. %
  44. % The following entries are "dummied out":
  45. %   FontType       = 3
  46. %   FontMatrix     = [0.001 0 0 0.001]
  47. %   PaintType      = 1
  48. %   FontInfo.
  49. %           .version = (001.00)
  50. %           .Notice  = ()
  51. %
  52. % The following entries contain the code/data needed to emulate a Type1 font:
  53. %   UniqueID       = special UID computed by font system
  54. %   BuildChar
  55. %   BuildGlyph
  56. %   Private
  57. %
  58. %
  59. % The following special ZS operators are used exclusively by this font 
  60. % mechanism:
  61. %
  62. % <fontname> getplatformfontmetrics  [mark <BBoxllx><BBoxlly><BBoxurx>
  63. %                                     <BBoxury><italicAngle>
  64. %                                     <underscoreSize><underscorePos>
  65. %                                     <isFixed>
  66. %                  %These are strs:   <Weight><familyName><fullName>
  67. %                                     <UniqueID>
  68. %                %first one is str:   <Private><sideBearingsAreTrue>
  69. %                                     <Encoding#> true]
  70. %                                  | [false]
  71. %    where the metrics are all in PS 1000 em square font units & conventions.
  72. %    Encoding# = 0 DingBats, 1 Symbol, 2 Std, 3 Win-ANSI
  73. %
  74. %
  75. % <Private><glyph> getglyphmetrics  [<xWidth><yWidth><llxBBox><llyBBox>
  76. %                                    <urxBBox><uryBBox> true]
  77. %                                 | [false]
  78. %
  79. %
  80. % <Private><glyph> getglyphoutline  [mark [<drawingOpAndData>]...
  81. %                                    <op count> true]
  82. %                                 | [false]
  83. %
  84. %   where a <drawingOpAndData> is:
  85. %     moveto: x y 0      (imlicit closepath of previous sub-path)
  86. %     lineto: x y 1
  87. %     curveto: x1 y1 x2 y2 x3 y3 2
  88. %     The first point to draw is on the top of the stack. There is an implicit
  89. %     closepath of the last sub-path after its points are drawn;
  90. %
  91. %   and <op count> is the count of <drawingOpandData> n-tuples. All units
  92. %   are in PostScript 1000 em square units. Moves are absolute.
  93. %
  94. %
  95. % mark [<UniqueID>...]  releaseUIDsexcept  --
  96. %
  97. %   This operator will release all the allocated UID slots, except for the
  98. %   ones enumerated. UIDs are not released when a font is deallocated, so
  99. %   the 'restore' operator must be hooked to call this operator with the list
  100. %   of all fonts in fontdict after the restore.
  101. %
  102. %
  103. % <Private><UniqueID><remap bool>  connectUIDtoprivate  --
  104. %
  105. %   This operator associates Private with UniqueID. If remap is true, UniqueID
  106. %   must already be defined; UniqueID will be redefined. In the case where
  107. %   remap is false, Private is mapped to UniqueID only if UniqueID isn't already
  108. %   defined. This operator is needed because of the following situation:
  109. %   if a user takes one of our fake type3 type1's, mofifies it,
  110. %   changes its UID, then does a definefont on it, we must advise the
  111. %   underlying font mechanism that the PrivateStr has another alias (UID).
  112. %   If we don't do this, the xfont mechanism will not work for the new
  113. %   font, since the unknown UID will not enable the xfont mechanism to find
  114. %   the PrivateStr. This is unfortunate since the above scenario is
  115. %   typical when changing a font's /Metrics entry.
  116. %
  117. % --  newUID  <int>
  118. %
  119. %   This operator allocates a new UID number from the same pool that the
  120. %   xfont mechanism draws from.
  121. %
  122. %
  123. % [<glyphName><sidebearing> true] | [false]  newxglyphsidebearing  --
  124. %
  125. %   If true, set a new sidebearing for the next xfont rendering that comes
  126. %   along. If false, disable waiting sidebearing.
  127. %
  128. %
  129. % --  replacefindfont  --     replace findfont operator with platform version
  130. /replacefindfont
  131.     {
  132.     systemdict begin
  133.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  134.         % findfont hook
  135.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  136.  
  137.         /__oldfindfont /findfont load def        % make a copy of old findfont
  138.  
  139.         % 1-time create fake CharStrings entries that we will use in fonts
  140.             % temp procedure to create CharStrings:
  141.             % <CharStringsName><char name array> proc --
  142.             {
  143.             dup length dict begin
  144.                     { {} readonly def}    %turn char name array into dict
  145.                 forall
  146.                 currentdict readonly
  147.             end
  148.             def
  149.             }
  150.  
  151.         /__StandardCharStrings
  152.         [
  153.         /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
  154.         /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
  155.         /grave/acute/circumflex/tilde/macron/breve/dotaccent/dieresis/ring/cedilla
  156.         /hungarumlaut/ogonek/caron/dotlessi/quotesingle/space/exclam/quotedbl
  157.         /numbersign/dollar/percent/ampersand/quotesingle/parenleft/parenright
  158.         /asterisk/plus/comma/hyphen/period/slash/zero/one/two/three/four/five/six
  159.         /seven/eight/nine/colon/semicolon/less/equal/greater/question/at/bracketleft
  160.         /backslash/bracketright/asciicircum/underscore/grave/braceleft/bar/braceright
  161.         /asciitilde/quotesinglbase/florin/quotedblbase/ellipsis/dagger/daggerdbl
  162.         /ansicircumflex/perthousand/Scaron/guilsinglleft/OE/quoteleft/quoteright
  163.         /quotedblleft/quotedblright/bullet/endash/emdash/ansitilde/trademark/scaron
  164.         /guilsinglright/oe/Ydieresis/ansispace/exclamdown/cent/sterling/currency/yen
  165.         /brokenbar/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot
  166.         /ansihyphen/registered/macron/degree/plusminus/twosuperior/threesuperior
  167.         /acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine
  168.         /guillemotright/onequarter/onehalf/threequarters/questiondown/Agrave
  169.         /Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla/Egrave/Eacute
  170.         /Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis/Eth/Ntilde/Ograve
  171.         /Oacute/Ocircumflex/Otilde/Odieresis/multiply/Oslash/Ugrave/Uacute/Ucircumflex
  172.         /Udieresis/Yacute/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis
  173.         /aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex
  174.         /idieresis/eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide/oslash
  175.         /ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis
  176.         ]
  177.         2 index exec
  178.  
  179.         /__DingbatCharStrings
  180.         [
  181.         /space/a1/a2/a202/a3/a4/a5/a119/a118/a117/a11/a12/a13/a14/a15/a16/a105/a17
  182.         /a18/a19/a20/a21/a22/a23/a24/a25/a26/a27/a28/a6/a7/a8/a9/a10/a29/a30/a31/a32
  183.         /a33/a34/a35/a36/a37/a38/a39/a40/a41/a42/a43/a44/a45/a46/a47/a48/a49/a50/a51
  184.         /a52/a53/a54/a55/a56/a57/a58/a59/a60/a61/a62/a63/a64/a65/a66/a67/a68/a69/a70
  185.         /a71/a72/a73/a74/a203/a75/a204/a76/a77/a78/a79/a81/a82/a83/a84/a97/a98/a99
  186.         /a100/a101/a102/a103/a104/a106/a107/a108/a112/a111/a110/a109/a120/a121/a122
  187.         /a123/a124/a125/a126/a127/a128/a129/a130/a131/a132/a133/a134/a135/a136/a137
  188.         /a138/a139/a140/a141/a142/a143/a144/a145/a146/a147/a148/a149/a150/a151/a152
  189.         /a153/a154/a155/a156/a157/a158/a159/a160/a161/a163/a164/a196/a165/a192/a166
  190.         /a167/a168/a169/a170/a171/a172/a173/a162/a174/a175/a176/a177/a178/a179/a193
  191.         /a180/a199/a181/a200/a182/a201/a183/a184/a197/a185/a194/a198/a186/a195/a187
  192.         /a188/a189/a190/a191
  193.         ]
  194.         2 index exec
  195.  
  196.         /__SymbolCharStrings
  197.         [
  198.         /space/exclam/universal/numbersign/existential/percent/ampersand/suchthat
  199.         /parenleft/parenright/asteriskmath/plus/comma/minus/period/slash/zero/one
  200.         /two/three/four/five/six/seven/eight/nine/colon/semicolon/less/equal/greater
  201.         /question/congruent/Alpha/Beta/Chi/Delta/Epsilon/Phi/Gamma/Eta/Iota/theta1
  202.         /Kappa/Lambda/Mu/Nu/Omicron/Pi/Theta/Rho/Sigma/Tau/Upsilon/sigma1/Omega/Xi
  203.         /Psi/Zeta/bracketleft/therefore/bracketright/perpendicular/underscore
  204.         /radicalex/alpha/beta/chi/delta/epsilon/phi/gamma/eta/iota/phi1/kappa/lambda
  205.         /mu/nu/omicron/pi/theta/rho/sigma/tau/upsilon/omega1/omega/xi/psi/zeta
  206.         /braceleft/bar/braceright/similar/Upsilon1/minute/lessequal/fraction/infinity
  207.         /florin/club/diamond/heart/spade/arrowboth/arrowleft/arrowup/arrowright
  208.         /arrowdown/degree/plusminus/second/greaterequal/multiply/proportional
  209.         /partialdiff/bullet/divide/notequal/equivalence/approxequal/ellipsis
  210.         /arrowvertex/arrowhorizex/carriagereturn/aleph/Ifraktur/Rfraktur/weierstrass
  211.         /circlemultiply/circleplus/emptyset/intersection/union/propersuperset
  212.         /reflexsuperset/notsubset/propersubset/reflexsubset/element/notelement/angle
  213.         /gradient/registerserif/copyrightserif/trademarkserif/product/radical/dotmath
  214.         /logicalnot/logicaland/logicalor/arrowdblboth/arrowdblleft/arrowdblup/arrowdblright/arrowdbldown
  215.         /lozenge/angleleft/registersans/copyrightsans/trademarksans/summation
  216.         /parenlefttp/parenleftex/parenleftbt/bracketlefttp/bracketleftex/bracketleftbt
  217.         /bracelefttp/braceleftmid/braceleftbt/braceex/apple/angleright/integral
  218.         /integraltp/integralex/integralbt/parenrighttp/parenrightex/parenrightbt
  219.         /bracketrighttp/bracketrightex/bracketrightbt/bracerighttp/bracerightmid
  220.         /bracerightbt
  221.         ]
  222.         3 -1 roll exec
  223.  
  224.         % This dict is used as a marker when on the dict stack: If its uniquely-
  225.         % named entry is found by 'where,' we know the marker is on the dictstack
  226.         /__DefiningFontDict 1 dict dup /__DefiningFontMarker__ 0 put def
  227.  
  228.         % These fonts will be substituted for the other font if not found
  229.         /__KnownFontSubstitutes
  230.         mark
  231.         %Substitute_from_name [Substitute_to_name X-scale(opt) Y-scale(opt)]
  232.         /AvantGarde-Book [/Helvetica 0.916 1]
  233.         /AvantGarde-Demi [/Helvetica-Bold 0.916 1]
  234.         /AvantGarde-BookOblique [/Helvetica-Oblique 0.916 1]
  235.         /AvantGarde-DemiOblique [/Helvetica-BoldOblique 0.916 1]
  236.         /Bookman-Light [/Times-Roman 1.2 1]
  237.         /Bookman-Demi [/Times-Bold 1.2 1]
  238.         /Bookman-LightItalic [/Times-Italic 1.1 1]
  239.         /Bookman-DemiItalic [/Times-BoldItalic 1.2 1]
  240.         /Palatino-Roman [/Times-Roman 1.11 1]
  241.         /Palatino-Italic [/Times-Italic 1.11 1]
  242.         /Palatino-Bold [/Times-Bold 1.11 1]
  243.         /Palatino-BoldItalic [/Times-BoldItalic 1.11 1]
  244.         /NewCenturySchlbk-Roman [/Times-Roman 1.175 1]
  245.         /NewCenturySchlbk-Italic [/Times-Italic 1.175 1]
  246.         /NewCenturySchlbk-Bold [/Times-Bold 1.175 1]
  247.         /NewCenturySchlbk-BoldItalic [/Times-BoldItalic 1.175 1]
  248.         /Helvetica-Narrow [/Helvetica 0.82 1]
  249.         /Helvetica-Narrow-Bold [/Helvetica-Bold 0.82 1]
  250.         /Helvetica-Narrow-Oblique [/Helvetica-Oblique 0.82 1]
  251.         /Helvetica-Narrow-BoldOblique [/Helvetica-BoldOblique 0.82 1]
  252.         /ZapfChancery-MediumItalic /Times-Italic
  253.  
  254.         % create dictionary from pairs
  255.         counttomark 2 idiv dup dict    
  256.         begin
  257.                 {def}
  258.             repeat
  259.             pop
  260.             currentdict
  261.         end
  262.         readonly def
  263.  
  264.         % Manufacture new type3 font dict:
  265.         %key mark <BBoxllx><BBoxlly><BBoxurx><BBoxury><italicAngle>
  266.         % <underscoreSize><underscorePos><isFixed><Weight>
  267.         % <familyName><fullName><UniqueID><Private><SidebearingsTrue>
  268.         % <Encoding#>
  269.         %
  270.         % returns: key dict
  271.         %
  272.         /__buildfontfromplatformmetrics
  273.             {
  274.             14 dict begin                        % one bigger for definefont's FID
  275.                 /FontType 3 def
  276.                 /FontMatrix [0.001 0 0 0.001 0 0]readonly def
  277.                 dup 2 ge
  278.                     {pop __StandardCharStrings StandardEncoding}
  279.                 %else
  280.                     {
  281.                     1 eq
  282.                         {__SymbolCharStrings SymbolEncoding}
  283.                     %else equals 0
  284.                         {__DingbatCharStrings DingbatsEncoding}
  285.                     ifelse
  286.                     }
  287.                 ifelse
  288.                 /Encoding exch def
  289.                 /CharStrings exch def            % create this for PSCRIPT.DRV
  290.                 pop                                    % ignore SidebearingsTrue
  291.                 4 dict begin
  292.                     /PrivateStr exch def
  293.                     /RequestedName 14 index def
  294.                     currentdict
  295.                 end
  296.                 /Private exch def
  297.                 /UniqueID exch def
  298.                 /PaintType 0 def
  299.                 /StrokeWidth 0 def
  300.  
  301.                 9 dict begin
  302.                     /version (001.000)readonly def
  303.                     /Notice ()readonly def
  304.                     /FullName exch readonly def
  305.                     /FamilyName exch readonly def
  306.                     /Weight exch readonly def
  307.                     /isFixedPitch exch def
  308.                     /UnderlinePosition exch def
  309.                     /UnderlineThickness exch def
  310.                     /ItalicAngle exch def
  311.  
  312.                     currentdict                        %...dict
  313.                 end
  314.                 readonly
  315.                 /FontInfo exch def
  316.  
  317.                 4 array astore cvx readonly    % executable is bogus, but customary
  318.                 /FontBBox exch def
  319.  
  320.                 cleartomark                            %key mark [...] 
  321.  
  322.                 /FontName 1 index def            %key
  323.  
  324.                 % Font's BuildGlyph proc
  325.                 % <fontdict><glyphname>  BuildGlyph  --
  326.                 /BuildGlyph
  327.                     {
  328.                     exch
  329.                     begin
  330.                         dup /.notdef eq
  331.                             % nop if .notdef
  332.                             {pop}
  333.                         %else
  334.                             % get the glyph from platform, enumerate & render
  335.                             {                            %glyphname
  336.                             Private /PrivateStr get            %glyphname private
  337.                             dup type /nulltype eq
  338.                                 {
  339.                                 % This font is a stub for a pre-loaded fake Type 1.
  340.                                 % Get the real PrivateStr by doing a getplatformfontmetrics,
  341.                                 % then stick it into the font & force the UniqueID to
  342.                                 % be associated with the new PrivateStr.
  343.                                 pop
  344.                                 currentdict
  345.                                 Private begin
  346.                                     currentglobal currentdict gcheck setglobal
  347.                                      RequestedName getplatformfontmetrics not
  348.                                         {setglobal end end exch stop}
  349.                                     if
  350.                                     3 -1 roll /PrivateStr exch def
  351.                                     cleartomark
  352.                                     currentglobal
  353.                                     PrivateStr
  354.                                     exch /UniqueID known
  355.                                         {
  356.                                         dup UniqueID true connectUIDtoprivate
  357.                                         }
  358.                                     if
  359.                                 end
  360.                                 }
  361.                             if
  362.                             exch                                    %private glyphname
  363.                             2 copy
  364.                             getglyphmetrics        % *original* sidebearings
  365.                                 {
  366.                                                         %private glyphname
  367.                                             % <xWidth><yWidth><llxBBox>
  368.                                                         % <llyBBox><urxBBox><uryBBox>
  369.                                 currentdict /Metrics .knownget
  370.                                     {
  371.                                     7 index .knownget
  372.                                         {
  373.                                         dup type
  374.                                         dup /integertype eq exch /realtype eq or
  375.                                             {
  376.                                             % we've got new xWidth + set yWidth = 0
  377.                                             0                %y-width to 0
  378.                                             }
  379.                                         %else
  380.                                             {
  381.                                             % Array entry means sidebearings 2 adjust
  382.                                             aload
  383.                                             length 2 eq
  384.                                                 {
  385.                                                 % new X-width & sidebearing
  386.                                                 0                % y-width to 0
  387.                                                 }
  388.                                             %else
  389.                                                 {
  390.                                                 % new X/Y width & X/Y sidebearing
  391.                                                 pop            % ignore y-component
  392.                                                 }
  393.                                             ifelse
  394.                                             exch
  395.                                                         %private glyphname
  396.                                             % <xWidth><yWidth><llxBBox>
  397.                                                         % <llyBBox><urxBBox><uryBBox>
  398.                                                         % xwidth ywidth sidebearing
  399.  
  400.                                             % adjust bbox for new sidebearings
  401.                                             dup 7 index sub
  402.                                             dup 9 -1 roll add 8 1 roll
  403.                                             dup 7 -1 roll add 6 1 roll
  404.  
  405.                                             % note that sidebearings changed
  406.                                             10 1 roll
  407.                                             10 index exch true newxglyphsidebearing
  408.                                             }
  409.                                         ifelse
  410.                                         8 -2 roll pop pop 6 2 roll    % new x/y-width
  411.                                         }
  412.                                     if
  413.                                     }
  414.                                 if
  415.  
  416.                                 % Expand bbox by a 3 pixels, since filling an outline
  417.                                 % in Type 3 mode tends to fatten the finished product
  418.                                 % & shift it over.
  419.                                 %
  420.                                 3 3 idtransform 3 -1 roll add 3 1 roll add exch
  421.  
  422.                                 % If stroked font, also fatten by width of line.
  423.                                 %
  424.                                 currentdict /PaintType .knownget {0 ne}{false}ifelse
  425.                                     {
  426.                                     1.415 currentmiterlimit max 
  427.                                     currentdict /StrokeWidth .knownget {ceiling}{1}ifelse
  428.                                     mul 2 div
  429.                                         % llx lly urx ury exp
  430.                                     5 1 roll 4 index add
  431.                                         % exp llx lly urx ury+
  432.                                     5 1 roll 3 index add
  433.                                         % ury+ exp llx lly urx+
  434.                                     5 1 roll 2 index sub
  435.                                         % urx+ ury+ exp llx lly-
  436.                                     5 1 roll exch sub
  437.                                         % lly- urx+ ury+ llx-
  438.                                     4 1 roll
  439.                                     }
  440.                                 if
  441.                                 setcachedevice
  442.                                 false
  443.                                 }
  444.                             %else
  445.                                 {
  446.                                 % No glyph available
  447.                                 dup /fraction ne
  448.                                     {true}
  449.                                 %else
  450.                                     {
  451.                                     % substitute a slash for fraction bar
  452.                                     pop
  453.                                     % .. a "fraction" width is usually 90% of "0" advance
  454.                                     % .. we further cut the 90% into 3rds
  455.                                     dup /zero getglyphmetrics not
  456.                                         {/fraction true}        %private glyph
  457.                                     %else
  458.                                         {
  459.                                         pop pop pop pop pop    %private width
  460.                                         0.3 mul                    %private .3width0
  461.                                         exch /slash 2 copy
  462.                                         getglyphmetrics not
  463.                                             {3 -1 roll pop true} %private glyph
  464.                                         %else
  465.                                             {                %.3width0 private /fraction
  466.                                                             % <xW><yW><llx><lly><urx>
  467.                                                             % <ury>
  468.                                             9 -1 roll
  469.  
  470.                                             % new advance width is 30% of zero's wid
  471.                                             7 -1 roll
  472.                                             pop
  473.                                             6 1 roll        %private /fraction
  474.                                                             %.3wid yW llx lly urx ury
  475.  
  476.                                             % y-width is 0
  477.                                             5 -1 roll pop 0 5 1 roll
  478.  
  479.                                             % center slash bbox over nu advance box
  480.                                             % the rest of the slash is under/overhang
  481.                                             1 index 4 index     % slash's bbox width
  482.                                             sub
  483.                                             6 index sub
  484.                                             2 div floor
  485.                                             neg 4 index sub    % additional sidebearing
  486.                                             dup dup            %private /slash .3wid
  487.                                                                 % yW llx lly urx ury
  488.                                                                 % adjust adjust adjust
  489.                                             9 1 roll
  490.                                             6 -1 roll
  491.                                             add
  492.                                             5 1 roll
  493.                                             3 -1 roll
  494.                                             add
  495.                                             exch                %private /slash adjust
  496.                                                                 % .3wid yW llx' lly
  497.                                                                 % urx' ury
  498.  
  499.                                             % Do any /Metrics modifications needed
  500.                                             currentdict /Metrics .knownget
  501.                                                 {
  502.                                                 8 index .knownget
  503.                                                     {
  504.                                                     dup type
  505.                                                     dup /integertype eq exch /realtype eq or
  506.                                                         {
  507.                                                         % we've got new xWidth + set yWidth = 0
  508.                                                         0                %y-width to 0
  509.                                                         }
  510.                                                     %else
  511.                                                         {
  512.                                                         % Array entry means sidebearings 2 adjust
  513.                                                         aload
  514.                                                         length 2 eq
  515.                                                             {
  516.                                                             % new X-width & sidebearing
  517.                                                             0                % y-width to 0
  518.                                                             }
  519.                                                         %else
  520.                                                             {
  521.                                                             % new X/Y width & X/Y sidebearing
  522.                                                             pop            % ignore y-component s/brng
  523.                                                             }
  524.                                                         ifelse
  525.                                                             %private glyphname adjust
  526.                                                 % <xWidth><yWidth><llxBBox>
  527.                                                             % <llyBBox><urxBBox><uryBBox>
  528.                                                             % xwidth ywidth sidebearing
  529.  
  530.                                                         % adjust bbox for new sidebearings
  531.                                                         dup 7 index sub
  532.                                                         dup 9 -1 roll add 8 1 roll
  533.                                                         dup 7 -1 roll add 6 1 roll
  534.  
  535.                                                         % note that sidebearings changed
  536.                                                         11 1 roll
  537.                                                         11 index exch true
  538.                                                          newxglyphsidebearing
  539.                                                         }
  540.                                                     ifelse
  541.                                                     8 -2 roll pop pop 6 2 roll    % new x/y-width
  542.                                                     }
  543.                                                 if
  544.                                                 }
  545.                                             if
  546.  
  547.                                             % Expand bbox if stroked font
  548.                                             currentdict /PaintType .knownget {0 ne}{false}ifelse
  549.                                                 {
  550.                                                 1.415 currentmiterlimit max
  551.                                                 currentdict /StrokeWidth .knownget {ceiling}{1}ifelse
  552.                                                 mul 2 div
  553.                                                     % llx lly urx ury exp
  554.                                                 5 1 roll 4 index add
  555.                                                     % exp llx lly urx ury+
  556.                                                 5 1 roll 3 index add
  557.                                                     % ury+ exp llx lly urx+
  558.                                                 5 1 roll 2 index sub
  559.                                                     % urx+ ury+ exp llx lly-
  560.                                                 5 1 roll exch sub
  561.                                                     % lly- urx+ ury+ llx-
  562.                                                 4 1 roll
  563.                                                 }
  564.                                             if
  565.                                             % set cache & offset rendering to land
  566.                                             % in the right place
  567.                                             setcachedevice    %private /slash adjust
  568.                                             0 translate        % force -ve sidebearing
  569.  
  570.                                             false
  571.                                             }
  572.                                         ifelse
  573.                                         }
  574.                                     ifelse
  575.                                     }
  576.                                 ifelse
  577.                                 }
  578.                             ifelse
  579.  
  580.                             % Based on bool which preceding code left on stak
  581.                                 {pop pop}            % no glyph available, fail
  582.                             %else
  583.                                 {
  584.                                                     %private glyphname [sideadjust]
  585.                                 % Paint the glyph by enumerating & filling outline
  586.                                 %
  587.                                 % maybe hafta translate in lieu of newxglyphsidebearing
  588.                                 dup type /nametype ne
  589.                                     {
  590.                                     false newxglyphsidebearing
  591.                                     0 translate
  592.                                     }
  593.                                 if
  594.  
  595.                                 getglyphoutline
  596.                                     {
  597.                                     %mark [<drawingOpAndData>]... <opcnt>
  598.                                     % enumerate font outline into a path
  599.                                     %
  600.                                     % Points are rounded to quarter pixels to
  601.                                     % improve print quality.
  602.                                         {
  603.                                         dup 0 eq
  604.                                             {
  605.                                             pop closepath
  606.                                             transform
  607.                                             4 mul floor 4 div .125 add
  608.                                             exch
  609.                                             4 mul floor 4 div .125 add
  610.                                             exch
  611.                                             itransform
  612.                                             moveto
  613.                                             }
  614.                                         %else
  615.                                             {
  616.                                             dup 1 eq
  617.                                                 {
  618.                                                          pop
  619.                                                 transform
  620.                                                 4 mul floor 4 div .125 add
  621.                                                 exch
  622.                                                 4 mul floor 4 div .125 add
  623.                                                 exch
  624.                                                 itransform
  625.                                                 lineto
  626.                                                 }
  627.                                             %else
  628.                                                 {
  629.                                                 2 eq
  630.                                                     {
  631.                                                     transform
  632.                                                     4 mul floor 4 div .125 add
  633.                                                     exch
  634.                                                     4 mul floor 4 div .125 add
  635.                                                     exch
  636.                                                     itransform
  637.                                                     6 2 roll
  638.                                                     transform
  639.                                                     4 mul floor 4 div .125 add
  640.                                                     exch
  641.                                                     4 mul floor 4 div .125 add
  642.                                                     exch
  643.                                                     itransform
  644.                                                     6 2 roll
  645.                                                     transform
  646.                                                     4 mul floor 4 div .125 add
  647.                                                     exch
  648.                                                     4 mul floor 4 div .125 add
  649.                                                     exch
  650.                                                     itransform
  651.                                                     6 2 roll
  652.                                                     curveto
  653.                                                     }
  654.                                                 if
  655.                                                 }
  656.                                             ifelse
  657.                                             }
  658.                                         ifelse
  659.                                         }                                    
  660.                                     repeat
  661.                                     closepath
  662.                                     cleartomark
  663.  
  664.                                     % fill or stroke path, depending on PaintType
  665.                                     PaintType 2 eq
  666.                                         {StrokeWidth setlinewidth stroke}
  667.                                     %else
  668.                                         {fill}
  669.                                     ifelse
  670.                                     }
  671.                                 if
  672.                                 }
  673.                             ifelse
  674.                             }
  675.                         ifelse
  676.                     end
  677.                     }
  678.                 def %bind will make R/O
  679.  
  680.                 % Font's BuildChar proc just maps into a BuildGlyph
  681.                 % <fontdict><charcode>  BuildChar  --
  682.                 /BuildChar
  683.                     {
  684.                     1 index /Encoding get exch get
  685.                     BuildGlyph
  686.                     }
  687.                 def %bind will make R/O
  688.  
  689.                 currentdict                        %key dict
  690.             end
  691.             }
  692.         bind def
  693.  
  694.  
  695.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  696.         % This is the new findfont proc
  697.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  698.         /findfont                                        % replace findfont with new ver
  699.             {
  700.             FontDirectory 1 index known
  701.                 {
  702.                 __oldfindfont                            % cascade to old proc if already known
  703.                 __fixupstubfont
  704.                 }
  705.             %else
  706.                 % Must try to substitute req'd font with a platform font
  707.                 {
  708.                 dup type /stringtype eq {cvn}if    % if key is a string, convert to name
  709.                 dup getplatformfontmetrics not    %key [...] bool
  710.  
  711.                 dup
  712.                     % try making *known* font substitutions if font not known
  713.                     {
  714.                     pop
  715.                     __KnownFontSubstitutes 1 index .knownget
  716.                         {
  717.                         % known font substitution... do it
  718.                         %key fontname_or_array
  719.                         dup type /arraytype eq
  720.                             {aload pop}
  721.                         %else
  722.                             {1 1}
  723.                         ifelse                            %key substname scalex scaley
  724.                         3 -1 roll                        %key scalex scaley substname
  725.                             {findfont}                    %key scalex scaley font
  726.                         stopped
  727.                             {
  728.                             pop pop pop
  729.                             true
  730.                             }
  731.                         %else
  732.                             {
  733.                             dup maxlength dict
  734.                             begin
  735.                                     {
  736.                                     % copy found font into current dict w/mods
  737.                                     exch
  738.                                     % our definefont will put in its own UniqueID later
  739.                                     dup /FID eq 1 index /UniqueID eq or
  740.                                         {pop pop}
  741.                                     %else
  742.                                         {                        %key scalex scaley value key
  743.                                         dup /FontName eq
  744.                                             {exch pop 3 index exch}
  745.                                         if
  746.                                         dup /FontMatrix eq
  747.                                             {
  748.                                             exch
  749.                                             3 index 3 index 6 array scale
  750.                                             exch 6 array concatmatrix
  751.                                             readonly
  752.                                             exch
  753.                                             }
  754.                                         if
  755.                                         exch def
  756.                                         }
  757.                                     ifelse
  758.                                     }
  759.                                 forall                        %key scalex scaley
  760.                                 pop pop
  761.                                 currentdict                    %key dict
  762.                             end
  763.                             false
  764.                             }
  765.                         ifelse
  766.                         }
  767.                     %else
  768.                         {true}
  769.                     ifelse
  770.                     }
  771.                 if
  772.  
  773.                 dup
  774.                     % try substituting default font w/property copying if unsuccessful
  775.                     {
  776.                     pop
  777.                     % We go to some trouble to parse the font name and extract
  778.                     % properties from it.
  779.                     %
  780.                     % Look for properties in the font name.
  781.                    dup dup length string cvs
  782.                    0 exch
  783.                     [
  784.                      [(Bold) 1] [(Demi) 1]
  785.                      [(Italic) 2] [(Oblique) 2]
  786.                     ]
  787.                         {                                    %...bitmask namestr subarray
  788.                         2 copy 0 get search
  789.                             { pop pop pop 1 get 3 -1 roll or exch }
  790.                         %else
  791.                             { pop pop }
  792.                         ifelse
  793.                         }
  794.                     forall                                %...bitmask namestr
  795.                     pop                                    %...bitmask
  796.  
  797.                     % Substitute alternate font based on accumulated bit mask
  798.                     [/Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique]
  799.                     exch get
  800.                     getplatformfontmetrics not
  801.                     }
  802.                 if
  803.  
  804.                 dup
  805.                     % try substituting bottom-line default font if unsuccessful
  806.                     {pop /Courier getplatformfontmetrics not}
  807.                 if
  808.  
  809.                     {__oldfindfont}                    % no platform font: cascade to old one
  810.                 %else
  811.                     {
  812.                     dup type /dicttype ne
  813.                         {
  814.                         __buildfontfromplatformmetrics
  815.                         % Put a marker on dict stack to prevent 'our' definefont
  816.                         % from doing extra work twice. We must call a late-bound
  817.                         % 'definefont' to satisfy any potential later hookers.
  818.                         __DefiningFontDict begin
  819.                             /definefont load exec    %font
  820.                         end
  821.                         }
  822.                     %else
  823.                         {/definefont load exec}        %font
  824.                     ifelse
  825.                     }
  826.                 ifelse
  827.                 }
  828.             ifelse
  829.             }
  830.         def %don't bind
  831.  
  832.  
  833.  
  834.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  835.         % subroutine of findfont to reload PrivateStr of stub fonts
  836.         % <font> __fixupstubfont <font>
  837.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  838.         /__fixupstubfont
  839.             {
  840.             % If found font is one of our fake Type 3's & it has the PrivateStr
  841.             % nulled out, load it now.
  842.             false 1 index rcheck                    %font bool
  843.                 {
  844.                 1 index /Private .knownget        %font bool [dict] bool
  845.                     {
  846.                     dup rcheck                        %font bool dict bool
  847.                         {
  848.                         /PrivateStr .knownget    %font bool [str] bool
  849.                             {
  850.                             type /nulltype eq        %font bool bool
  851.                             exch pop                    %font bool
  852.                             }
  853.                         if
  854.                         }
  855.                     %else                                %font bool dict
  856.                         {pop}                            %font bool
  857.                     ifelse
  858.                     }
  859.                 if
  860.                 }
  861.             if                                            %font bool
  862.  
  863.                 {
  864.                 % This font is a stub for a pre-loaded fake Type 1.
  865.                 % Get the real PrivateStr by doing a getplatformfontmetrics,
  866.                 % then stick it into the font & force the UniqueID to
  867.                 % be associated with the new PrivateStr.
  868.                 dup /UniqueID known
  869.                          {
  870.                     dup begin
  871.                         Private begin
  872.                             currentglobal currentdict gcheck setglobal
  873.                             RequestedName getplatformfontmetrics
  874.                                 {
  875.                                 3 -1 roll /PrivateStr exch def
  876.                                 cleartomark
  877.                                 PrivateStr UniqueID true connectUIDtoprivate
  878.                                 }
  879.                             if
  880.                             setglobal
  881.                         end
  882.                     end
  883.                     }
  884.                 if
  885.                 }
  886.             if
  887.             }
  888.         def
  889.  
  890.  
  891.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  892.         % restore hook
  893.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  894.  
  895.         /__oldrestore /restore load def        % make a copy of old restore
  896.  
  897.         % This is the new restore proc
  898.         /restore                                        % replace find fontfont with new ver
  899.             {
  900.             __oldrestore                            % cascade to old proc first
  901.  
  902.             % push a mark on stack, then UIDs of all fonts still in FontDirectory
  903.             mark
  904.             FontDirectory
  905.                 {
  906.                 exch pop                                %...dict
  907.                 dup type /dicttype eq            %...dict bool
  908.                 1 index rcheck and
  909.                     {
  910.                     /UniqueID .knownget            % push UID of this font if present
  911.                     }
  912.                 %else
  913.                     {pop}
  914.                 ifelse
  915.                 }
  916.             forall                                    %mark [UID]...
  917.  
  918.             % release all UIDs not in FontDictionary            
  919.             releaseUIDsexcept
  920.             }
  921.         odef %odef will make R/O
  922.  
  923.  
  924.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  925.         % definefont hook
  926.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  927.  
  928.         /__olddefinefont /definefont load def    % make a copy of old definefont
  929.  
  930.         % This is the new definefont proc. We must hook this & invoke the
  931.         % connectUIDtoprivate (see comments in main proc header, above) if this
  932.         % font is one of our type3 type1's.
  933.         %
  934.         /definefont                                    % replace find fontfont with new ver
  935.             {                                            %key dict
  936.             /__DefiningFontMarker__ where        % don't do our job if called by findfont
  937.                 {pop}
  938.             %else
  939.                 {
  940.                 % is this one of our fake type3 type1's?
  941.                 %
  942.                 dup type /dicttype eq                %key dict bool
  943.                     {dup rcheck}
  944.                 %else
  945.                     {false}
  946.                 ifelse
  947.                     {
  948.                     dup /Private .knownget            %key dict [dict] bool
  949.                         {
  950.                         dup rcheck
  951.                             {true}
  952.                         %else
  953.                             {pop false}
  954.                         ifelse
  955.                         }
  956.                     %else
  957.                         {false}
  958.                     ifelse
  959.                         {
  960.                         dup /PrivateStr known         %key dict dict bool
  961.                             {
  962.                             1 index /UniqueID known        %key dict dict bool
  963.                                 {true}
  964.                             %else
  965.                                 {
  966.                                 % If there's no UID, try to assign one
  967.                                 %
  968.                                 1 index wcheck
  969.                                     {1 index /UniqueID newUID put true}
  970.                                 %else
  971.                                     {false}
  972.                                 ifelse
  973.                                 }
  974.                             ifelse
  975.                             }
  976.                         %else
  977.                             {false}
  978.                         ifelse
  979.                             {
  980.                             % This is one of our fake type3 type1's.
  981.                             % If there is a UniqueID, we must connect it to PrivateStr.
  982.                             %
  983.                             /PrivateStr get            %key dict str
  984.                             1 index /UniqueID get    %key dict str uid
  985.                                 {false connectUIDtoprivate}%key dict
  986.                             stopped                        % operands haven't been pre-validated
  987.                                 {pop pop pop}
  988.                             if
  989.                             }
  990.                         %else                                %key dict dict
  991.                             {pop}
  992.                         ifelse                            %key dict
  993.                         }
  994.                     if
  995.                     }
  996.                 if                                            %key dict
  997.                 }
  998.             ifelse
  999.             __olddefinefont
  1000.             }
  1001.         odef %odef will make R/O
  1002.  
  1003.     end
  1004.     }
  1005. bind def
  1006.  
  1007. % Hook the findfont-related operators
  1008. %
  1009. replacefindfont
  1010.