diff options
Diffstat (limited to 'Master/tlpkg/tlgs/Resource/Init/gs_ttf.ps')
-rw-r--r-- | Master/tlpkg/tlgs/Resource/Init/gs_ttf.ps | 468 |
1 files changed, 254 insertions, 214 deletions
diff --git a/Master/tlpkg/tlgs/Resource/Init/gs_ttf.ps b/Master/tlpkg/tlgs/Resource/Init/gs_ttf.ps index 05943c5d716..e34967dd78d 100644 --- a/Master/tlpkg/tlgs/Resource/Init/gs_ttf.ps +++ b/Master/tlpkg/tlgs/Resource/Init/gs_ttf.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2018 Artifex Software, Inc. +% Copyright (C) 2001-2019 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -36,128 +36,6 @@ ] def } if -% <file> <key> .findfontvalue <value> true -% <file> <key> .findfontvalue false -% Closes the file in either case. -/.findnonttfontvalue /.findfontvalue load def -/.findfontvalue { - 1 index .is_woff { - dup /FontType eq { - pop closefile 42 //true - } { - dup /FontName eq { pop .findwoffname } { pop closefile //false } ifelse - } ifelse - } - { - 1 index .is_ttf_or_otf { - % If this is a font at all, it's a TrueType font. - dup /FontType eq { - pop closefile 42 //true - } { - dup /FontName eq { pop .findttfontname } { pop closefile //false } ifelse - } ifelse - } { - % Not a TrueType font. - .findnonttfontvalue - } ifelse - } ifelse -} bind def - -% <file> .findttfontname <fname> true -% <file> .findttfontname false -% Closes the file in either case. -/.findttfontname { - //true 0 .loadttfonttables - tabdict /name .knownget { - dup 8 getu32 f exch setfileposition - 12 getu32 - dup 65535 gt { pop 65535 } if % protect against extremely large name - string f exch readstring pop - dup - 6 findname not { - 4 findname % Try FullName - } { - exch pop //true - } - ifelse - } { - //false - } ifelse - f closefile end end -} bind def - -/.findwoffname { - //true 0 .loadwofftables - tabdict /name .knownget { - dup /clen exch 8 getu32 def - dup /olen exch 12 getu32 def - 4 getu32 f exch setfileposition - olen dup 65535 gt { pop 65535 } if % protect against extremely large name - /fs - clen olen ne - {f clen () /SubFileDecode filter /FlateDecode filter} - {f clen () /SubFileDecode filter} - ifelse def - string fs exch readstring pop - fs closefile - dup - 6 findname not { - 4 findname % Try FullName - } { - exch pop //true - } - ifelse - } { - //false - } ifelse - f closefile end end -} bind def - - -% Load a font file that might be a TrueType font. - -/tt_tag_dict << <00010000> 0 (true) 0 (typ1) 0 (ttcf) 0 >> readonly def -/ttf_otf_tag_dict << <00010000> 0 (true) 0 (typ1) 0 (ttcf) 0 (OTTO) 0>> readonly def -% The wOFF tag is immediately followed by the sfnt "flavour" so for simplicity -% combine them -/woff_tag_dict << - (wOFF) 0 - <774F464600010000> 0 % (wOFF)<00010000> .concatstrings - (wOFFtrue) 0 - (wOFFtyp1) 0 ->> readonly def - -% <file> .loadfontfile - -/.loadnonttfontfile /.loadfontfile load def -/.loadfontfile { - dup (12345678) .peekstring { //woff_tag_dict exch known } { //false } ifelse - { - .loadwofffont pop - } - { - dup (1234) .peekstring { //tt_tag_dict exch known } { //false } ifelse { - % If this is a font at all, it's a TrueType font. - .loadttfont pop - } { - % Not a TrueType font. - .loadnonttfontfile - } ifelse - } ifelse -} bind def - -% <file> .is_ttf_or_otf <bool> -/.is_ttf_or_otf { - dup 0 setfileposition (1234) .peekstring { //ttf_otf_tag_dict exch known } { //false } ifelse -} bind def - -/.is_woff { - dup 0 setfileposition (1234) .peekstring { //woff_tag_dict exch known } { //false } ifelse -} bind def - -currentdict /tt_tag_dict .undef -currentdict /ttf_otf_tag_dict .undef -currentdict /woff_tag_dict .undef - % ---------------- Automatic Type 42 generation ---------------- % % Load a TrueType font from a file as a Type 42 PostScript font. @@ -342,7 +220,7 @@ currentdict /woff_tag_dict .undef 16#ffffffff 0 gt { % 64-bit sign extension { /gets32 /gets32a} { mark 1 index load aload pop { 16#80000000 xor 16#80000000 sub } aload pop - .packtomark cvx def + //.packtomark exec cvx def } bind forall } if @@ -911,7 +789,7 @@ end readonly def % .loadttfontdict % Defines f, offsets, tables, tabdict, tabs, tthdrlen. % Skips loca and glyf if <bool> is true. /.loadttfonttables { - .loadttfontdict begin + //.loadttfontdict begin 40 dict begin /SubfontID exch def /load_stripped exch def @@ -954,7 +832,7 @@ end readonly def % .loadttfontdict % tabs = tables we want to keep, sorted by file position. /tabs [ 0 16 tables length 1 sub { tables exch 16 getinterval - TTFDEBUG { dup .printtab } if + TTFDEBUG { dup //.printtab exec } if dup 0 4 getinterval readtables_ 1 index known { % put all 0 length tables at 0 to avoid overlap 1 index 12 getu32 0 eq { 1 index 8 0 putu32 } if @@ -978,7 +856,7 @@ end readonly def % .loadttfontdict 2 index 12 3 -1 roll putu32 } if pop pop } for -} bind def +} bind executeonly def @@ -987,7 +865,7 @@ end readonly def % .loadttfontdict % Defines f, offsets, tables, tabdict, tabs, tthdrlen. % Skips loca and glyf if <bool> is true. /.loadwofftables { - .loadttfontdict begin + //.loadttfontdict begin 40 dict begin /SubfontID exch def /load_stripped exch def @@ -1011,7 +889,7 @@ end readonly def % .loadttfontdict /tabs [ 0 20 tables length 1 sub { tables exch 20 getinterval - TTFDEBUG { dup .printtab } if + TTFDEBUG { dup //.printtab exec } if dup 0 4 getinterval readtables_ 1 index known { % put all 0 length tables at 0 to avoid overlap @@ -1107,7 +985,7 @@ mark % Defines checksum, getloca, head, locatable, numloca, post, sfnts, upem % Note that the 'loca' table may be out of order. /.makesfnts { - .readttdata + //.readttdata exec /head tabdict /head get def /post tabdict /post .knownget { dup 0 get /post_first_part exch def @@ -1124,7 +1002,7 @@ mark locatable type /stringtype eq { /.indexloca {} def } { - /.indexloca /.findseg load def + /.indexloca //.findseg def } ifelse head 50 getu16 0 ne { /getloca { @@ -1148,7 +1026,7 @@ mark dup type /stringtype ne { aload pop } if } forall ] def -} bind def +} .bind executeonly odef /first_post_string % - first_post_string <string> { @@ -1209,7 +1087,7 @@ mark counttomark 0 ne { .dicttomark } { pop pop } ifelse /XUID [orgXUID 42 curxuid] TTFDEBUG { - tabs { .printtab } forall + tabs { //.printtab exec } forall [ sfnts { length } forall ] //== exec count ttkeycount sub array astore dup { //== exec } forall aload pop } if @@ -1322,7 +1200,9 @@ mark } { //.pickcmap_with_no_xlatmap exec } ifelse -} bind def +} .bind executeonly odef +currentdict /.pickcmap_with_xlatmap .undef +currentdict /.pickcmap_with_no_xlatmap .undef % <glyph> .nname <_name> /.nname { @@ -1369,7 +1249,7 @@ mark } for % /glyphencoding <newarray> <glyphencoding length> 1 numloca 1 sub { - 1 index exch dup .nname put + 1 index exch dup //.nname exec put } for def } if @@ -1394,7 +1274,7 @@ mark 3 index 1 index known { % The same name maps to more than one glyph. Change the name. % No special treatment for /.notdef glyph. Bug 689408. - pop .nname 3 index 2 index 2 index put + pop //.nname exec 3 index 2 index 2 index put 2 index exch 3 -1 roll put } { 3 index exch 3 -1 roll put % unique name @@ -1421,7 +1301,7 @@ mark TTFDEBUG { (\n1 setting alias: ) print dup ==only ( to be the same as ) print 2 index //== exec } if - 7 index 2 index 3 -1 roll exch //.growput systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse + 7 index 2 index 3 -1 roll exch .forceput } forall pop pop pop } @@ -1439,7 +1319,7 @@ mark exch pop TTFDEBUG { (\n2 setting alias: ) print 1 index ==only ( to use glyph index: ) print dup //== exec } if - 5 index 3 1 roll //.growput systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse + 5 index 3 1 roll .forceput //false } { @@ -1456,7 +1336,7 @@ mark { % CharStrings(dict) isunicode(boolean) cmap(dict) RAGL(dict) gname(name) codep(integer) gindex(integer) TTFDEBUG { (\3 nsetting alias: ) print 1 index ==only ( to be index: ) print dup //== exec } if - exch pop 5 index 3 1 roll //.growput systemdict /superexec known {//superexec}{1183615869 internaldict /superexec get exec} ifelse + exch pop 5 index 3 1 roll .forceput } { pop pop @@ -1486,56 +1366,7 @@ mark } ifelse ] TTFDEBUG { (Encoding: ) print dup === flush } if -} bind def - -% to be removed 9.09...... -currentdict /postalias undef -% .....to be removed 9.09 - -% <file> .loadttfont <type42font> -/.loadttfont { - TTFDEBUG { (.loadttfont) = } if - //false 0 .loadttfonttables - .makesfnts - .getpost - .pickcmap - mark - % if we're loading to substitute for TTF in a PDF, - % load the font the "PDF way" - /prebuilt_encoding where - {pop .pdfcharkeys} - {.charkeys} ifelse - .ttkeys - /FontType 42 - /PaintType 0 - TTFDEBUG { - (numloca=) print numloca = - } if - .dicttomark - end end dup /FontName get exch definefont -} bind def - -% <file> .loadwofffont <type42font> -/.loadwofffont -{ - TTFDEBUG { (.loadwofffont) = } if - //false 0 .loadwofftables - .makesfnts - .getpost - .pickcmap - mark - .charkeys - .ttkeys - /FontType 42 - /PaintType 0 - TTFDEBUG { - (numloca=) print numloca = - } if - .dicttomark - end end dup /FontName get exch - definefont -} bind def - +} .bind executeonly odef % hides .forceput % ---------------- CIDFontType 2 font loading ---------------- % @@ -1569,11 +1400,11 @@ currentdict /postalias undef def % processCIDToGIDMap may replace. /CIDMap numloca maxstring le { % Use a single string. - numloca 2 mul string 0 .fill_identity_cmap + numloca 2 mul string 0 //.fill_identity_cmap exec } { % We must use 2 strings. - maxstring 2 mul string 0 .fill_identity_cmap - numloca maxstring sub 2 mul string maxstring .fill_identity_cmap + maxstring 2 mul string 0 //.fill_identity_cmap exec + numloca maxstring sub 2 mul string maxstring //.fill_identity_cmap exec 2 array astore } ifelse def @@ -1591,15 +1422,15 @@ currentdict /postalias undef .makesfnts % CIDFontType2 fonts don't have a cmap: they are indexed by CID. mark - .ttkeys + //.ttkeys exec .dicttomark dup % convert keys to dict and copy dict 3 -1 roll % Bring PDF substitute name to top of stack dup /fontname exch def /FontName exch put % replace any definition of /FontName - .definettcidfont -} bind def + //.definettcidfont exec +} .bind executeonly odef % <file> <SubfontID> .load_tt_font_stripped <font_data> % The font_data includes sfnts, NumGlyphs, TT_cmap, file_table_pos, Decoding. @@ -1609,17 +1440,17 @@ currentdict /postalias undef .makesfnts .pickcmap mark - .ttkeys + //.ttkeys exec /NumGlyphs numloca /TT_cmap cmaptab cmapdict /file_table_pos file_table_pos /Decoding Decoding .dicttomark end end -} bind def +} .bind executeonly def /.load_woff_for_cid { - //false exch .loadwofftables + //false exch //.loadwofftables exec .makesfnts % we have to set load_stripped here so % .pickcmap will follow the right logic @@ -1628,14 +1459,14 @@ currentdict /postalias undef .pickcmap /load_stripped //false def mark - .ttkeys + //.ttkeys exec /NumGlyphs numloca /TT_cmap cmaptab cmapdict % /file_table_pos file_table_pos /Decoding Decoding .dicttomark end end -} bind def +} .bind executeonly def % ---------------- PDF TrueType font loading ---------------- % @@ -1836,13 +1667,13 @@ currentdict /postalias undef % Finally, if none of that works, remove the Encoding, and treat it % as non-symbolic. is_symbolic { - <00030000> .findcmap + <00030000> //.findcmap exec { //true } { prebuilt_encoding //null eq { - <00030001> .findcmap + <00030001> //.findcmap exec {//true} - {<00010000> .findcmap} + {<00010000> //.findcmap exec} ifelse } {//false} @@ -1850,7 +1681,7 @@ currentdict /postalias undef } ifelse { - .pdfmapsymbolic + //.pdfmapsymbolic exec /prebuilt_encoding //null def //false } { @@ -1862,7 +1693,7 @@ currentdict /postalias undef } ifelse { - <00030001> .findcmap { + <00030001> //.findcmap exec { prebuilt_encoding //null ne { TTFDEBUG { (Using cmap 3.1 with prebuilt_encoding for non-symbolic.) = } if //true /.render_notdef gput @@ -1888,29 +1719,29 @@ currentdict /postalias undef exch pop % <<pbe>> TTFDEBUG { dup (<<\n) print { exch ( ) print =only (\t) print //== exec } forall (>>\n) print flush } if exch AdobeGlyphList - .pdfmapchars + //.pdfmapchars exec /Encoding prebuilt_encoding } { % Likely this branch is now obsolete. TTFDEBUG { (Using cmap 3.1 for non-symbolic.) = } if 0 dict exch - AdobeGlyphList .pdfmapchars + AdobeGlyphList //.pdfmapchars exec /Encoding /WinAnsiEncoding .findencoding % WinAnsiEncoding is just a stub here. % It will be replaced with one from font resource, % because PDF spec requires it. } ifelse } { - <00010000> .findcmap { + <00010000> //.findcmap exec { TTFDEBUG { (Using cmap 1.0 for non-symbolic.) = } if - 0 dict exch - .romanmacdict .pdfmapchars - /Encoding prebuilt_encoding //null ne { + prebuilt_encoding .invert_encoding exch .romanmacdict //.pdfmapchars exec prebuilt_encoding } { + 0 dict exch /MacRomanEncodingForTrueType .findencoding } ifelse + /Encoding exch } { % Apply the default algorithm for using the 'post'. .charkeys @@ -1922,7 +1753,7 @@ currentdict /postalias undef } ifelse } if TTFDEBUG { (.pdfcharkeys end) = } if -} bind def +} bind executeonly def % <file> <is_symbolic> <Encoding|null> <FontName> .loadpdfttfont <type42font> /.loadpdfttfont { @@ -1968,8 +1799,8 @@ currentdict /postalias undef .getpost .pickcmap mark - .pdfcharkeys - .ttkeys + //.pdfcharkeys exec + //.ttkeys exec /FontType 42 /PaintType 0 /.render_notdef .render_notdef @@ -1980,4 +1811,213 @@ currentdict /postalias undef dup /FontName font_name put % replace any definition of /FontName end end .completefont +} .bind executeonly odef + +%--------- Define main type42font loading routines, after their dependencies ------------ +% <file> .loadttfont <type42font> +/.loadttfont { + TTFDEBUG { (.loadttfont) = } if + //false + % if this came from Fontmap, there may be a dictionary on the dict stack + % with a SubfontID in it. Validate it *is* a Fontmap record by also + % checking for a Path key + /SubfontID where + { + dup /Path known + {/SubfontID get} + {pop 0} ifelse + } + {0} ifelse + .loadttfonttables + .makesfnts + .getpost + .pickcmap + mark + % if we're loading to substitute for TTF in a PDF, + % load the font the "PDF way" + /prebuilt_encoding where + {pop //.pdfcharkeys exec} + {.charkeys} ifelse + //.ttkeys exec + /FontType 42 + /PaintType 0 + TTFDEBUG { + (numloca=) print numloca = + } if + .dicttomark + end end dup /FontName get exch definefont +} .bind executeonly def + +% <file> .loadwofffont <type42font> +/.loadwofffont +{ + TTFDEBUG { (.loadwofffont) = } if + //false 0 //.loadwofftables exec + .makesfnts + .getpost + .pickcmap + mark + .charkeys + //.ttkeys exec + /FontType 42 + /PaintType 0 + TTFDEBUG { + (numloca=) print numloca = + } if + .dicttomark + end end dup /FontName get exch + definefont +} .bind executeonly def + +% ----- Utilities for loading possible TrueType font ------ +% <file> .findttfontname <fname> true +% <file> .findttfontname false +% Closes the file in either case. +/.findttfontname { + //true 0 .loadttfonttables + tabdict /name .knownget { + dup 8 getu32 f exch setfileposition + 12 getu32 + dup 65535 gt { pop 65535 } if % protect against extremely large name + string f exch readstring pop + dup + 6 findname not { + 4 findname % Try FullName + } { + exch pop //true + } + ifelse + } { + //false + } ifelse + f closefile end end } bind def + +/.findwoffname { + //true 0 //.loadwofftables exec + tabdict /name .knownget { + dup /clen exch 8 getu32 def + dup /olen exch 12 getu32 def + 4 getu32 f exch setfileposition + olen dup 65535 gt { pop 65535 } if % protect against extremely large name + /fs + clen olen ne + {f clen () /SubFileDecode filter /FlateDecode filter} + {f clen () /SubFileDecode filter} + ifelse def + string fs exch readstring pop + fs closefile + dup + 6 findname not { + 4 findname % Try FullName + } { + exch pop //true + } + ifelse + } { + //false + } ifelse + f closefile end end +} bind def + +/tt_tag_dict << <00010000> 0 (true) 0 (typ1) 0 (ttcf) 0 >> readonly def +/ttf_otf_tag_dict << <00010000> 0 (true) 0 (typ1) 0 (ttcf) 0 (OTTO) 0>> readonly def +% The wOFF tag is immediately followed by the sfnt "flavour" so for simplicity +% combine them +/woff_tag_dict << + (wOFF) 0 + <774F464600010000> 0 % (wOFF)<00010000> .concatstrings + (wOFFtrue) 0 + (wOFFtyp1) 0 +>> readonly def + +% <file> .is_ttf_or_otf <bool> +/.is_ttf_or_otf { + dup 0 setfileposition (1234) .peekstring { //ttf_otf_tag_dict exch known } { //false } ifelse +} bind def + +/.is_woff { + dup 0 setfileposition (1234) .peekstring { //woff_tag_dict exch known } { //false } ifelse +} bind def + +% <file> <key> .findfontvalue <value> true +% <file> <key> .findfontvalue false +% Closes the file in either case. +/.findnonttfontvalue /.findfontvalue load def +/.findfontvalue { + 1 index //.is_woff exec { + dup /FontType eq { + pop closefile 42 //true + } { + dup /FontName eq { pop //.findwoffname exec} { pop closefile //false } ifelse + } ifelse + } + { + 1 index //.is_ttf_or_otf exec { + % If this is a font at all, it's a TrueType font. + dup /FontType eq { + pop closefile 42 //true + } { + dup /FontName eq { pop //.findttfontname exec} { pop closefile //false } ifelse + } ifelse + } { + % Not a TrueType font. + .findnonttfontvalue + } ifelse + } ifelse +} bind executeonly def + +% Load a font file that might be a TrueType font. +% <file> .loadfontfile - +/.loadnonttfontfile /.loadfontfile load def +/.loadfontfile { + dup (12345678) .peekstring { //woff_tag_dict exch known } { //false } ifelse + { + //.loadwofffont exec pop + } + { + dup (1234) .peekstring { //tt_tag_dict exch known } { //false } ifelse { + % If this is a font at all, it's a TrueType font. + //.loadttfont exec pop + } { + % Not a TrueType font. + .loadnonttfontfile + } ifelse + } ifelse +} bind def + +% Undef the local utility funcs +[ + /.findttfontname + /.findwoffname + /ttf_otf_tag_dict + /tt_tag_dict + /woff_tag_dict + /.is_ttf_or_otf + /.is_woff +] +{currentdict exch .undef} forall +% ----- END .loadfontfile that supports possible TrueType font ------ + +% Undef these, not needed outside this file +[ + /.addglyph + /.definettcidfont + /.fill_identity_cmap + /.findseg + /.loadttfontdict + /.is_hex_digit + /.pop3ex + /.popfex + /.ttkeys + /.printtab + /.readttdata + /.nname + /.loadttfont + /.loadwofffont + /.loadwofftables + /.findcmap + /.pdfmapsymbolic + /.pdfcharkeys + /.pdfmapchars +] {systemdict exch .forceundef} forall |