| 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 |
% Initialization file for Type 32 fonts. |
| 17 |
|
| 18 |
% ------ Type 32 fonts ------ % |
| 19 |
|
| 20 |
% We need LanguageLevel 2 or higher in order to have defineresource. |
| 21 |
languagelevel dup 2 .max .setlanguagelevel |
| 22 |
|
| 23 |
/BitmapFontInit mark |
| 24 |
|
| 25 |
/.makeglyph32 systemdict /.makeglyph32 get |
| 26 |
systemdict /.makeglyph32 .undef |
| 27 |
|
| 28 |
/addglyph { % ([wx wy llx lly urx ury] | |
| 29 |
% [w0x w0y llx lly urx ury w1x w1y vx vy]) |
| 30 |
% <bitmap> <cid> <type32font> addglyph - |
| 31 |
1 index dup 2 index .removeglyphs |
| 32 |
22 string .makeglyph32 |
| 33 |
% Stack: metrics bitmap cid font metstr |
| 34 |
3 index () ne { |
| 35 |
% Use G4 encoding to compress the bitmap. |
| 36 |
% Define a string large enough to hold the metrics, |
| 37 |
% an uncompressed bitmap (worst case = 5x expansion), |
| 38 |
% and the 2 RTC codes (3 bytes). |
| 39 |
dup length 4 index length 5 mul add 10 add |
| 40 |
65535 .min string |
| 41 |
% Stack: metrics bitmap cid font metstr buffer |
| 42 |
dup 0 3 index putinterval |
| 43 |
dup 2 index length 1 index length 1 index sub getinterval |
| 44 |
% Stack: metrics bitmap cid font metstr buffer bitbuf |
| 45 |
mark /Columns 8 index dup 4 get exch 2 get sub |
| 46 |
/Rows 10 index dup 5 get exch 3 get sub |
| 47 |
/K -1 /EndOfBlock //true /BlackIs1 //true |
| 48 |
.dicttomark /CCITTFaxEncode filter |
| 49 |
% Stack: metrics bitmap cid font metstr buffer filter |
| 50 |
dup 6 index writestring closefile |
| 51 |
% Find the end of the data by scanning backwards for the RTC. |
| 52 |
% There are 2 RTCs x 12 bits = 3 bytes to remove. |
| 53 |
{ |
| 54 |
dup dup length 1 sub get 0 ne { exit } if |
| 55 |
0 1 index length 1 sub getinterval |
| 56 |
} loop |
| 57 |
0 1 index length 3 sub getinterval |
| 58 |
exch pop % metstr |
| 59 |
} if |
| 60 |
1 index /CharStrings get 3 index 3 -1 roll put |
| 61 |
pop pop pop pop |
| 62 |
} executeonly obind |
| 63 |
|
| 64 |
/removeall { % <type32font> removeall - |
| 65 |
0 65535 2 index removeglyphs pop |
| 66 |
} executeonly obind |
| 67 |
|
| 68 |
/.removeglyphs systemdict /.removeglyphs get |
| 69 |
systemdict /.removeglyphs .undef |
| 70 |
|
| 71 |
/removeglyphs { % <cid_min> <cid_max> <type32font> .removeglyphs - |
| 72 |
3 copy .removeglyphs |
| 73 |
dup /CharStrings get dup { |
| 74 |
% Stack: cidmin cidmax font CharStrings cid bitmap |
| 75 |
pop dup 5 index ge { dup 4 index le { 2 copy undef } if } if pop |
| 76 |
} forall pop pop pop pop |
| 77 |
} executeonly obind |
| 78 |
|
| 79 |
.dicttomark /ProcSet defineresource pop |
| 80 |
|
| 81 |
/.cidfonttypes where { pop } { /.cidfonttypes 6 dict def } ifelse |
| 82 |
/CIDFontType4 |
| 83 |
{ |
| 84 |
dup /FontType 32 .forceput |
| 85 |
dup /CharStrings 20 dict .forceput |
| 86 |
1 index exch .buildfont32 exch pop |
| 87 |
} .forcebind odef |
| 88 |
.cidfonttypes begin |
| 89 |
|
| 90 |
|
| 91 |
4 /CIDFontType4 load def % CIDFontType 4 = FontType 32 |
| 92 |
|
| 93 |
end % .cidfonttypes |
| 94 |
currentdict /CIDFontType4 .forceundef |
| 95 |
|
| 96 |
% Define the BuildGlyph procedure. |
| 97 |
% Since Type 32 fonts are indexed by CID, there is no BuildChar procedure. |
| 98 |
% The name %Type32BuildGlyph is known to the interpreter. |
| 99 |
(%Type32BuildGlyph) cvn { % <font> <cid> %Type32BuildGlyph - |
| 100 |
1 index /CharStrings get |
| 101 |
% Stack: font cid CharStrings |
| 102 |
dup 2 index .knownget { |
| 103 |
exch pop |
| 104 |
} { |
| 105 |
0 .knownget not { |
| 106 |
exch pop % Stack: cid |
| 107 |
.getshowoperator /invalidfont signalerror |
| 108 |
} if |
| 109 |
} ifelse |
| 110 |
% Stack: font cid cstr |
| 111 |
dup //.getmetrics32 % use // because of .undef below |
| 112 |
dup 14 gt { |
| 113 |
8 index 8 index 13 3 roll setcachedevice2 |
| 114 |
} { |
| 115 |
4 index 4 index 9 3 roll setcachedevice |
| 116 |
} ifelse |
| 117 |
% Stack: font cid cstr w h nmetrics llx lly |
| 118 |
6 -1 roll 4 -1 roll 1 index length 1 index sub getinterval |
| 119 |
% Stack: font cid w h llx lly bitstr |
| 120 |
dup () eq { |
| 121 |
pop pop pop |
| 122 |
} { |
| 123 |
mark /Columns 6 index /Rows 7 index /K -1 /EndOfBlock //false /BlackIs1 //true |
| 124 |
.dicttomark /CCITTFaxDecode filter 4 index 4 index //true |
| 125 |
% Stack: font cid w h llx lly filter w h //true |
| 126 |
[ 1 0 0 1 11 -2 roll exch neg exch neg ] 5 -1 roll imagemask |
| 127 |
} ifelse |
| 128 |
pop pop pop pop |
| 129 |
} .forcebind def |
| 130 |
|
| 131 |
systemdict /.getmetrics32 .undef |
| 132 |
|
| 133 |
buildfontdict 32 /.buildfont32 cvx put |
| 134 |
|
| 135 |
32 dup /FontType defineresource pop |
| 136 |
|
| 137 |
.setlanguagelevel |