| 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 cidfmap . |
| 17 |
|
| 18 |
languagelevel 2 .setlanguagelevel |
| 19 |
|
| 20 |
4 dict begin |
| 21 |
/CategoryName /CIDFont def |
| 22 |
|
| 23 |
/MapFileName (cidfmap) def |
| 24 |
|
| 25 |
/IsMyRecord % <raw_record> -> <raw_record> bool |
| 26 |
{ % Only for client's needs. |
| 27 |
dup type /stringtype eq exch |
| 28 |
dup type /nametype eq 3 -1 roll or |
| 29 |
} .internalbind def |
| 30 |
|
| 31 |
/RecordVirtualMethods 3 dict begin |
| 32 |
|
| 33 |
/MakeInstance % <Name> <record> MakeInstance <Name> <Instance> <size> |
| 34 |
{ % We know that currentdict is the category. |
| 35 |
/Substitute get dup type /stringtype eq |
| 36 |
{ |
| 37 |
(r) file dup cvx exec closefile |
| 38 |
dup |
| 39 |
} if |
| 40 |
|
| 41 |
FindResource % /Name <<CIDFont>> |
| 42 |
|
| 43 |
dup length dict copy % /Name <<CIDFont>> |
| 44 |
1 index ResourceStatus pop exch pop % /Name <<CIDFont>> size |
| 45 |
} .internalbind def |
| 46 |
|
| 47 |
/GetFilePath % <scratch> <Name> <record> GetFilePath <filepath> |
| 48 |
{ % We know that currentdict is the category. |
| 49 |
exch pop |
| 50 |
/Substitute get dup type /stringtype eq not |
| 51 |
{ |
| 52 |
exch ResourceFileName |
| 53 |
} if |
| 54 |
} .internalbind def |
| 55 |
|
| 56 |
/GetSize % <Name> <record> GetSize <size> |
| 57 |
{ % We know that currentdict is the category. |
| 58 |
dup /Substitute get dup type /stringtype eq |
| 59 |
{ |
| 60 |
% The simplest solution is to instantiate the resource |
| 61 |
pop //MakeInstance exec |
| 62 |
3 1 roll pop pop |
| 63 |
} |
| 64 |
{ |
| 65 |
exch pop |
| 66 |
ResourceStatus { |
| 67 |
exch pop exch pop |
| 68 |
} { |
| 69 |
/undefinedresource signalerror |
| 70 |
} ifelse |
| 71 |
}ifelse |
| 72 |
} .internalbind def |
| 73 |
|
| 74 |
/GetCSI % <record> GetCSI null |
| 75 |
% <record> GetCSI dict |
| 76 |
{ % We know that currentdict is the category. |
| 77 |
RESMPDEBUG { (cidfm GetCSI beg ) = } if |
| 78 |
dup /Substitute get dup type /stringtype eq |
| 79 |
{ |
| 80 |
pop |
| 81 |
dup /Name get exch //MakeInstance exec |
| 82 |
pop exch pop |
| 83 |
/CIDSystemInfo get |
| 84 |
} |
| 85 |
{ |
| 86 |
exch pop % /Name |
| 87 |
GetCIDSystemInfoFromMap |
| 88 |
} ifelse |
| 89 |
RESMPDEBUG { (cidfm GetCSI end ) print dup = } if |
| 90 |
} .internalbind def |
| 91 |
|
| 92 |
/IsActive % <record> IsActive <bool> |
| 93 |
{ pop //true |
| 94 |
} .internalbind def |
| 95 |
|
| 96 |
currentdict end def |
| 97 |
|
| 98 |
% This is the default definition of our fallback CIDFont |
| 99 |
/DefaultCIDFallBack |
| 100 |
<< |
| 101 |
/Path |
| 102 |
systemdict /CIDFSubstPath .knownget |
| 103 |
{ |
| 104 |
(/) concatstrings |
| 105 |
} |
| 106 |
{ |
| 107 |
(CIDFSUBSTPATH) getenv |
| 108 |
{ |
| 109 |
(/) concatstrings |
| 110 |
} |
| 111 |
{ |
| 112 |
currentsystemparams /GenericResourceDir get (CIDFSubst/) concatstrings |
| 113 |
} ifelse |
| 114 |
} ifelse |
| 115 |
|
| 116 |
systemdict /CIDFSubstFont .knownget not |
| 117 |
{ |
| 118 |
(CIDFSUBSTFONT) getenv not |
| 119 |
{ |
| 120 |
(DroidSansFallback.ttf) |
| 121 |
} if |
| 122 |
} if |
| 123 |
% If CIDFSubstFont looks like a path/file (rather than just file) |
| 124 |
% use it without the CIDFSubstPath string |
| 125 |
dup .file_name_directory_separator rsearch |
| 126 |
{pop pop pop exch pop} |
| 127 |
{pop concatstrings} |
| 128 |
ifelse |
| 129 |
% The CSI data just has to be valid, the substition machinery will |
| 130 |
% generally overwrite it with appropriate values for the missing font. |
| 131 |
/CSI [(Identity) 0] |
| 132 |
/RecordVirtualMethods //RecordVirtualMethods |
| 133 |
/FileType /TrueType |
| 134 |
|
| 135 |
(CIDFSUBSTFONTID) getenv |
| 136 |
{ |
| 137 |
/SubfontID exch cvi |
| 138 |
} if |
| 139 |
>> def |
| 140 |
|
| 141 |
% <dir.../base.extn> .basename <dir> |
| 142 |
/.splitdirname { |
| 143 |
(/) rsearch { //true } { (\\) rsearch } ifelse |
| 144 |
{exch concatstrings exch pop //true}{//false} ifelse |
| 145 |
} .internalbind def |
| 146 |
|
| 147 |
% <file> .addcidfmappath - |
| 148 |
/.addcidfmpermitpath |
| 149 |
{ |
| 150 |
.filename |
| 151 |
{ |
| 152 |
//.splitdirname exec |
| 153 |
{dup def} if |
| 154 |
} if |
| 155 |
} .internalbind def |
| 156 |
|
| 157 |
/VerifyMap % <raw_map> VerifyMap - |
| 158 |
{ |
| 159 |
% This is where we insert the default fallback into the map |
| 160 |
% checking first to see if there is a user specified alternative |
| 161 |
dup /CIDFallBack known not{ |
| 162 |
//DefaultCIDFallBack dup /Path get status |
| 163 |
{ |
| 164 |
pop pop pop pop |
| 165 |
/CIDFallBack exch 2 index 3 1 roll put |
| 166 |
} |
| 167 |
{ |
| 168 |
pop |
| 169 |
}ifelse |
| 170 |
} if |
| 171 |
|
| 172 |
% Remove any mappings for which we cannot find the font file |
| 173 |
dup length dict begin |
| 174 |
dup |
| 175 |
{ |
| 176 |
% if we have a name1->name2 mapping, follow the "trail", |
| 177 |
% so if the name2 mapping is known in the .map dict, retrieve |
| 178 |
% that map value and loop round until we either reach a map |
| 179 |
% which references a TTF (i.e. a dictionary record) or we have |
| 180 |
% a name not known in the .map, in which case we have to resort |
| 181 |
% to the normal Postscript "resourcestatus". |
| 182 |
{ |
| 183 |
dup type /nametype eq |
| 184 |
{ |
| 185 |
dup 3 index exch .knownget |
| 186 |
{ exch pop } |
| 187 |
{ |
| 188 |
/CIDFont resourcestatus |
| 189 |
{ pop pop pop } |
| 190 |
{ 2 index exch .undef } |
| 191 |
ifelse |
| 192 |
exit |
| 193 |
} ifelse |
| 194 |
} |
| 195 |
{ |
| 196 |
dup type /dicttype eq |
| 197 |
{ |
| 198 |
/Path .knownget |
| 199 |
{ |
| 200 |
.libfile |
| 201 |
{ |
| 202 |
dup //.addcidfmpermitpath exec closefile pop} |
| 203 |
{ |
| 204 |
{(r) file} //.internalstopped exec |
| 205 |
{pop pop 2 index exch .undef} |
| 206 |
{dup //.addcidfmpermitpath exec closefile pop} ifelse |
| 207 |
} ifelse |
| 208 |
} |
| 209 |
{2 index exch .undef} |
| 210 |
ifelse |
| 211 |
exit |
| 212 |
} if |
| 213 |
} ifelse |
| 214 |
} loop |
| 215 |
} forall |
| 216 |
currentdict end |
| 217 |
{exch pop /PermitFileReading exch .addcontrolpath} forall |
| 218 |
|
| 219 |
% Checks for vicious substitution cycles. |
| 220 |
dup length dict copy % <<map>> |
| 221 |
dup length dict % <<map>> <<temp>> |
| 222 |
{ % Choose a random record : |
| 223 |
//true 2 index { % <<map>> <<temp>> true /Name /Subs |
| 224 |
3 2 roll pop //false exit % <<map>> <<temp>> /Name /Subs false |
| 225 |
} forall |
| 226 |
{ exit % <<map>> <<temp>> |
| 227 |
} if % <<map>> <<temp>> /Name /Subs |
| 228 |
% Move the substitution chain to <<temp>>, checking for a cycle : |
| 229 |
3 index 2 index undef % <<map>> <<temp>> /Name /Subs |
| 230 |
exch 2 index exch 0 put % <<map>> <<temp>> /Subs |
| 231 |
{ //IsMyRecord exec not { |
| 232 |
% Not a substitution, the chain terminates. |
| 233 |
pop exit % <<map>> <<temp>> |
| 234 |
} if % <<map>> <<temp>> /Subs |
| 235 |
1 index 1 index known { |
| 236 |
(Vicious substitution cycle in map file with the entry ) print =string cvs print ( .) = |
| 237 |
/VerifyMap cvx /undefinedresource signalerror |
| 238 |
} if % <<map>> <<temp>> /Subs |
| 239 |
1 index 1 index 0 put |
| 240 |
dup 3 index exch .knownget not { % <<map>> <<temp>> /Subs |
| 241 |
% No more substitutions, the chain terminates. |
| 242 |
pop exit % <<map>> <<temp>> |
| 243 |
} if % <<map>> <<temp>> /Subs /Subs1 |
| 244 |
exch % <<map>> <<temp>> /Subs1 /Subs |
| 245 |
3 index exch undef % <<map>> <<temp>> /Subs1 |
| 246 |
} loop |
| 247 |
% Not cycled, now purge the <<temp>> : |
| 248 |
{ % Choose a random record : |
| 249 |
//true 1 index { % <<map>> <<temp>> true /Name /Subs |
| 250 |
3 2 roll pop //false exit % <<map>> <<temp>> /Name /Subs false |
| 251 |
} forall |
| 252 |
{ exit % <<map>> <<temp>> |
| 253 |
} if % <<map>> <<temp>> /Name /Subs |
| 254 |
% Remove it : |
| 255 |
pop 1 index exch undef % <<map>> <<temp>> |
| 256 |
} loop |
| 257 |
} loop |
| 258 |
pop pop |
| 259 |
} .internalbind def |
| 260 |
|
| 261 |
currentdict /.splitdirname undef |
| 262 |
currentdict /.addcidfmpermitpath undef |
| 263 |
|
| 264 |
/PreprocessRecord % <map> <Name> <raw_record> PreprocessRecord <map> <Name> <record> <bool> |
| 265 |
{ |
| 266 |
//IsMyRecord exec { |
| 267 |
1 dict begin |
| 268 |
/Substitute exch def |
| 269 |
dup /Name exch def |
| 270 |
/RecordVirtualMethods //RecordVirtualMethods def |
| 271 |
currentdict end |
| 272 |
//true |
| 273 |
} { |
| 274 |
//false |
| 275 |
} ifelse |
| 276 |
} .internalbind def |
| 277 |
|
| 278 |
currentdict end |
| 279 |
|
| 280 |
/MappedCategoryRedefiner /ProcSet findresource /Redefine get exec |
| 281 |
|
| 282 |
.setlanguagelevel |