1 % Copyright (C) 1997 Aladdin Enterprises. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
6 % This software is distributed under license and may not be copied,
7 % modified or distributed except as expressly authorized under the terms
8 % of the license contained in the file LICENSE in this distribution.
10 % For more information about licensing, please refer to
11 % http://www.ghostscript.com/licensing/. For information on
12 % commercial licensing, go to http://www.artifex.com/licensing/ or
13 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
16 % $Id: gs_typ32.ps,v 1.6 2002/06/02 12:03:28 mpsuzuki Exp $
17 % Initialization file for Type 32 fonts.
19 % ------ Type 32 fonts ------ %
21 % We need LanguageLevel 2 or higher in order to have defineresource.
22 languagelevel dup 2 .max .setlanguagelevel
26 /.makeglyph32 systemdict /.makeglyph32 get
27 systemdict /.makeglyph32 .undef
29 /addglyph { % ([wx wy llx lly urx ury] |
30 % [w0x w0y llx lly urx ury w1x w1y vx vy])
31 % <bitmap> <cid> <type32font> addglyph -
32 1 index dup 2 index .removeglyphs
33 22 string .makeglyph32
34 % Stack: metrics bitmap cid font metstr
36 % Use G4 encoding to compress the bitmap.
37 % Define a string large enough to hold the metrics,
38 % an uncompressed bitmap (worst case = 5x expansion),
39 % and the 2 RTC codes (3 bytes).
40 dup length 4 index length 5 mul add 10 add 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.
54 dup dup length 1 sub get 0 ne { exit } if
55 0 1 index length 1 sub getinterval
57 0 1 index length 3 sub getinterval
60 1 index /CharStrings get 3 index 3 -1 roll put
64 /removeall { % <type32font> removeall -
65 0 65535 2 index removeglyphs pop
68 /.removeglyphs systemdict /.removeglyphs get
69 systemdict /.removeglyphs .undef
71 /removeglyphs { % <cid_min> <cid_max> <type32font> .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
79 .dicttomark /ProcSet defineresource pop
81 /.cidfonttypes where { pop } { /.cidfonttypes 6 dict def } ifelse
84 4 % CIDFontType 4 = FontType 32
85 { dup /FontType 32 put
86 dup /CharStrings 20 dict put
87 1 index exch .buildfont32 exch pop
92 % Define the BuildGlyph procedure.
93 % Since Type 32 fonts are indexed by CID, there is no BuildChar procedure.
94 % The name %Type32BuildGlyph is known to the interpreter.
95 (%Type32BuildGlyph) cvn { % <font> <cid> %Type32BuildGlyph -
96 1 index /CharStrings get
97 % Stack: font cid CharStrings
99 { exch pop } { 0 get } ifelse
100 % Stack: font cid cstr
101 dup //.getmetrics32 % use // because of .undef below
103 8 index 8 index 13 3 roll setcachedevice2
105 4 index 4 index 9 3 roll setcachedevice
107 % Stack: font cid cstr w h nmetrics llx lly
108 6 -1 roll 4 -1 roll 1 index length 1 index sub getinterval
109 % Stack: font cid w h llx lly bitstr
113 mark /Columns 6 index /Rows 7 index /K -1 /EndOfBlock false /BlackIs1 true
114 .dicttomark /CCITTFaxDecode filter 4 index 4 index true
115 % Stack: font cid w h llx lly filter w h true
116 [ 1 0 0 1 11 -2 roll exch neg exch neg ] 5 -1 roll imagemask
121 systemdict /.getmetrics32 .undef
123 buildfontdict 32 /.buildfont32 cvx put
125 32 dup /FontType defineresource pop