% Copyright (C) 2001-2021 Artifex Software, Inc.
% All Rights Reserved.
%
% This software is provided AS-IS with no warranty, either express or
% implied.
%
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
%
% Refer to licensing information at http://www.artifex.com or contact
% Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato,
% CA 94945, U.S.A., +1(415)492-9861, for further information.
%
% Type 1 font support code.
% The standard representation for PostScript compatible fonts is described
% in the book "Adobe Type 1 Font Format", published by Adobe Systems Inc.
/t1_glyph_equivalence mark % Exported for pf2afm.ps
/Odblacute /Ohungarumlaut
/Udblacute /Uhungarumlaut
/odblacute /ohungarumlaut
/udblacute /uhungarumlaut
.dicttomark def
% Define an augmented version of .buildfont1 that inserts UnderlinePosition
% and UnderlineThickness entries in FontInfo if they aren't there already,
% and FontBBox isn't degenerate.
% (This works around the incorrect assumption, made by many word processors,
% that these entries are present in the built-in fonts.)
% Also add alternative names to some glyphs.
/.buildfont1
{
.currentglobal 3 1 roll
dup .gcheck .setglobal
dup .fontbbox {
pop pop pop pop
dup /FontInfo known not
{ //.growfontdict exec dup /FontInfo 2 dict put }
if
dup dup /FontInfo get dup dup
/UnderlinePosition known exch /UnderlineThickness known and
{ pop pop % entries already present
}
{ dup length 2 add dict .copydict
dup /UnderlinePosition known not
{ dup /UnderlinePosition 3 index /FontBBox get
1 get 2 div put % 1/2 the font descent
}
if
dup /UnderlineThickness known not
{ dup /UnderlineThickness 3 index /FontBBox get
dup 3 get exch 1 get sub 20 div put % 1/20 the font height
}
if
1 index /FontInfo get wcheck not { readonly } if
/FontInfo exch put
}
ifelse
} if
% We want to skip this process if we've already done it, and
% not do it for embedded fonts.
dup /.AGLprocessed~GS known not 1 index /PathLoad known and
{
dup /CharStrings get
% Provide all known aliases for each glyph if
% substitution is allowed (pf2afm.ps has code
% to disables it by modifying t1_glyph_equivalence).
t1_glyph_equivalence length 0 ne
{
% 16 byte scratch string
% 16 bytes is arbitrary, but should be large enough to hold any "uniXXXX" style name
//ReverseAdobeGlyphList //AdobeGlyphList 3 -1 roll
% scratch(string) RAGL(dict) AGL(dict) CharStrings(dict)
dup
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) gname cstring
exch dup % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname gname
4 index exch .knownget
{ //true}
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname
dup length 16 gt
{ //false }
{
% if we couldn't derive the code point from the AGL, we might derive it
% from a formatted "uniXXXX" name.
dup <00000000000000000000000000000000> cvs dup flush (uni) anchorsearch
{
% as luck would have it, we can just replace the "uni" with "16#"
% to get something we can convert to a number
pop pop dup 0 (16#) putinterval {cvi} //.internalstopped exec
{ pop //false}
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname cpoint
dup 5 index exch known
{ //true }
{ pop //false }
ifelse
} ifelse
}
{ pop pop //false}
ifelse
} ifelse
} ifelse
{
% scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname cpoint
% loop through the array of names for this codepoint
% if the CharStrings dict doesn't contain an entry for the name
% create one.
5 index exch .knownget
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname aglnames(array)
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname aglname
dup 4 index exch known not
{ % scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname aglname
CFFDEBUG { (\nsetting alias: ) print dup ==only
( to be the same as glyph: ) print 1 index //== exec } if
3 index exch 3 index .forceput
% scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname
}executeonly
{pop} ifelse
} executeonly forall
pop pop
} executeonly
{
pop pop pop
} ifelse
} executeonly
{
% scratch(string) RAGL(dict) AGL(dict) CharStrings(dict) cstring gname
pop pop
} ifelse
} executeonly forall
3 1 roll pop pop
} executeonly if
pop
dup /.AGLprocessed~GS //true .forceput
} executeonly if
%% We need to excute the C .buildfont1 in a stopped context so that, if there
%% are errors we can put the stack back sanely and exit. Otherwise callers won't
%% be able to execute this redefinied .buildfont1 in a stopped context and still
%% usefully continue (because the stack will be altered, which it shold not be).
%%
%% Uncovered working on bug #696306 and fixed as part of that bug.
%%
{//.buildfont1} stopped
4 3 roll .setglobal
{//.buildfont1 $error /errorname get signalerror} if
} .bind executeonly def % hide .forceput
% container for CloseSource flag (default //true to prevent buildup of file handles)
/closesourcedict mark
/CloseSource //true
.dicttomark readonly def
/.loadfont1 { % %Type1BuildChar -
1 index /Encoding get 1 index get //.type1build exec .type1execchar
} bind executeonly def
(%Type1BuildGlyph) cvn { % %Type2BuildChar -
1 index /Encoding get 1 index get //.type1build exec .type2execchar
} bind executeonly def
(%Type2BuildGlyph) cvn { %