/undefined in /iso1dict when using Distiller

François Robert <[email protected]> Mon, 12 Feb 2007 23:06:07 +0100
Newsgroups gmane.comp.printing.a2ps.bugs
Message-ID <[email protected]>
This is a summary of a Usenet posting :
http://groups.google.com/group/comp.lang.postscript/browse_thread/ 
thread/d597ea0cb4822418/d28cf90e181a8d7b#d28cf90e181a8d7b

Version : a2ps 4.13
Symptom : Adobe Distiller (or the Mac OS X Preview tool) errors out  
with %%[ Error: undefined; OffendingCommand: iso1dict ]%%

Reason : The reencode procedure leaves an extra FontInfo dictionary  
on the operand stack if this dictionnary lacks a /UnderlineThickness  
key. This in turn causes an off-by-one-operand situation to propagate  
to the 'def' operator that ends up not assigning the dictionary to  
the expected /iso1dict name but to some other name, thus effectively  
leaving 'iso1dict' undefined.

Proposed patch :
The 'reencode' procedure in base.ps could be rewritten as follow :

% reencode the font
% <encoding-vector> <fontdict> -> <newfontdict>
/reencode
{
   dup length 5 add dict begin
     { % <vector> <key> <val>
       1 index /FID ne
       { def }{ pop pop } ifelse
     } forall
     /Encoding exch def % -

     % Use the font's bounding box to determine the ascent, descent,
     % and overall height; don't forget that these values have to be
     % transformed using the font's matrix.
     % We use `load' because sometimes BBox is executable, sometimes  
not.
     % Since we need 4 numbers an not an array avoid BBox from being  
executed
     /FontBBox load aload pop
     FontMatrix transform /Ascent exch def pop
     FontMatrix transform /Descent exch def pop
     /FontHeight Ascent Descent sub def

     % Get the underline position and thickness if they're defined.
     % Use 1 if they are not defined.
     currentdict /FontInfo 2 copy known
     { get
       /UnderlinePosition 2 copy  % <FontInfo> /UP <FontInfo> /UP
       2 copy known
       { get }{ pop pop 1} ifelse
       0 exch FontMatrix transform exch pop
       def           % <FontInfo>

       /UnderlineThickness 2 copy  % <FontInfo> /UT <FontInfo> /UT
       2 copy known
       { get }{ pop pop 1} ifelse
       0 exch FontMatrix transform exch pop
       def           % <FontInfo>
       pop           % -
     }{ pop pop
     } ifelse

     currentdict
     end