Debian Codegraph @

Resource/Init/gs_cidtt.ps

raw
1 % Copyright (C) 2001-2023 Artifex Software, Inc.
2 % All Rights Reserved.
3 %
4 % This software is provided AS-IS with no warranty, either express or
5 % implied.
6 %
7 % This software is distributed under license and may not be copied,
8 % modified or distributed except as expressly authorized under the terms
9 % of the license contained in the file LICENSE in this distribution.
10 %
11 % Refer to licensing information at http://www.artifex.com or contact
12 % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
13 % CA 94129, USA, for further information.
14 %
15
16 % Redefine CIDFont category with an emulation with True Type fonts.
17
18 languagelevel 2 .setlanguagelevel
19
20 15 dict begin % a temporary dictionary for local binding.
21
22 %------------------Copy the FontEmulationProcs here : -------------------
23
24 /FontEmulationProcs /ProcSet findresource {
25 def
26 } forall
27
28 currentdict /super.complete_instance currentdict /complete_instance get put
29
30 %-------Auxiliary procedures for building CIDFontType 2 from TT file -----------
31
32 /GenerateCIDMap % <font> GenerateCIDMap <font>
33 { begin
34 % Obtain the maximal CID :
35 % This implementation doesn't check whether glyphs really present.
36 Decoding /CIDCount get /CIDCount exch def
37 % Prepare the CIDMap structure :
38 /CIDMap [
39 CIDCount 22000 le {
40 CIDCount 2 mul string
41 } {
42 44000 string
43 CIDCount 44000 gt {
44 % need three strings
45 44000 string % 22000 2 mul string
46 CIDCount 44000 sub 2 mul string
47 } {
48 CIDCount 22000 sub 2 mul string
49 } ifelse
50 } ifelse
51 ] def
52 % Now fill it :
53 Decoding TT_cmap SubstNWP GDBytes CIDMap .fillCIDMap
54 currentdict end
55 } .internalbind def
56
57 /GenerateIdentityCIDMap % <font> GenerateCIDMap <font>
58 { begin
59 /CIDMap [ 44000 string 44000 string 44000 string] def
60 CIDMap .fillIdentityCIDMap
61 currentdict end
62 } .internalbind def
63
64 /load_sfnts % <FontDict> load_sfnts <FontDict>
65 { % Read the True Type file from the path /Path, and buld /sfnts,
66 % skipping glyf and loca.
67 dup /Path get % <font> (path)
68 QUIET not {
69 (Loading a TT font from ) print dup print
70 ( to emulate a CID font ) print 1 index /CIDFontName get =only ( ... ) print
71 } if
72 (r) file dup % <font> file file
73 3 1 roll % file <font> file
74 1 index /SubfontID .knownget not { 0 } if % file <font> file SubfontID
75 2 index /FileType .knownget
76 {/WOFF eq}
77 {//false} ifelse
78 % It's not (currently) viable to load WOFF fonts "stripped", so we don't try
79 {.load_woff_for_cid exch copy exch pop}
80 {
81 .load_tt_font_stripped exch
82 copy % file <font>
83 QUIET not {
84 (Done.) =
85 } if
86 dup 3 1 roll % <font> file <font>
87 exch /File exch put % <font>
88 } ifelse
89 dup dup /CIDSystemInfo get /Ordering get (.) % <font> () ()
90 2 index /Decoding get =string cvs % <font> () () ()
91 concatstrings concatstrings cvn /Decoding exch put % <font>
92 dup dup /CIDSystemInfo get /Ordering get (-WMode) % <font> <font> () ()
93 concatstrings cvn /SubstCID
94 2 copy resourcestatus {
95 pop pop
96 findresource /subst_CID_on_WMode exch put % <font>
97 } {
98 pop pop pop
99 } ifelse
100 dup /Decoding get /Identity.Unicode eq {
101 //ChooseDecoding exec % <font>
102 //GenerateIdentityCIDMap exec % <font>
103 } {
104 //ChooseDecoding exec % <font>
105 //GenerateCIDMap exec % <font>
106 } ifelse
107 } .internalbind def
108
109 %-----------TrueType-specific methods for category redefinition : -----------
110
111 /RefinePath % <FontDict> RefinePath <FontDict>
112 { dup begin
113 Path .libfile {
114 dup .filename {
115 currentdict exch /Path exch put
116 } if
117 closefile
118 } {
119 (r) { file } //.internalstopped exec
120 {
121 (Can't find the font file ) print =
122 /findfont cvx /undefinedfilename signalerror
123 }
124 {
125 dup .filename {
126 currentdict exch /Path exch put
127 } if
128 closefile
129 } ifelse
130 } ifelse
131 end
132 } .internalbind def
133
134 /complete_instance % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
135 { 1 index /CIDFontType 2 put % Other types are not emulated yet.
136 //super.complete_instance exec
137 //RefinePath exec
138 //load_sfnts exec
139 } .internalbind def
140
141 /ValidFileTypes
142 <<
143 /TrueType 0
144 /WOFF 0
145 >> def
146
147 /IsMyRecord % <raw_record> -> <raw_record> bool
148 {
149 dup type /dicttype eq { dup /FileType .knownget { //ValidFileTypes exch known } { //false } ifelse } { //false } ifelse
150 } .internalbind def
151
152 currentdict /ValidFileTypes undef
153
154 /IsActive % <record> IsActive <bool>
155 { pop //true
156 } .internalbind def
157
158 /CIDFontRecordVirtualMethods //RecordVirtualMethodsStub dup length 3 add dict copy begin
159 /GetCSI //TranslateCSI def
160 /IsActive //IsActive def
161 /MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size>
162 { currentglobal 3 1 roll //true setglobal
163 //CIDFontOptions //complete_instance exec
164 2 copy //GetSize exec
165 4 3 roll setglobal
166 } .internalbind def
167 currentdict end def
168
169 % Redefine the /CIDFont category :
170 4 dict begin
171 /CategoryName /CIDFont def
172 /IsMapFileOptional //true def
173 /VerifyMap { pop } .internalbind def
174 /PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool>
175 { //IsMyRecord exec dup {
176 pop dup /RecordVirtualMethods //CIDFontRecordVirtualMethods put
177 //true
178 } if
179 } .internalbind def
180 currentdict end
181
182 /MappedCategoryRedefiner /ProcSet findresource /Redefine get exec
183
184 end % the temporary dictionary for local binding.
185
186 .setlanguagelevel