]> git.ipfire.org Git - thirdparty/cups.git/blob - pstoraster/gs_typ32.ps
Import cups.org releases
[thirdparty/cups.git] / pstoraster / gs_typ32.ps
1 % Copyright (C) 1997 Aladdin Enterprises. All rights reserved.
2 %
3 % This file is part of GNU Ghostscript.
4 %
5 % GNU Ghostscript is distributed in the hope that it will be useful, but
6 % WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
7 % to anyone for the consequences of using it or for whether it serves any
8 % particular purpose or works at all, unless he says so in writing. Refer
9 % to the GNU General Public License for full details.
10 %
11 % Everyone is granted permission to copy, modify and redistribute GNU
12 % Ghostscript, but only under the conditions described in the GNU General
13 % Public License. A copy of this license is supposed to have been given
14 % to you along with GNU Ghostscript so you can know your rights and
15 % responsibilities. It should be in a file named COPYING. Among other
16 % things, the copyright notice and this notice must be preserved on all
17 % copies.
18 %
19 % Aladdin Enterprises supports the work of the GNU Project, but is not
20 % affiliated with the Free Software Foundation or the GNU Project. GNU
21 % Ghostscript, as distributed by Aladdin Enterprises, does not require any
22 % GNU software to build or run it.
23
24 % $Id: gs_typ32.ps 956 2000-03-08 23:15:43Z mike $
25 % Initialization file for Type 32 fonts.
26
27 % ------ Type 32 fonts ------ %
28
29 % We need LanguageLevel 2 or higher in order to have defineresource.
30 languagelevel dup 2 max .setlanguagelevel
31
32 /BitmapFontInit mark
33
34 /.makeglyph32 systemdict /.makeglyph32 get
35 systemdict /.makeglyph32 .undef
36
37 /addglyph { % ([wx wy llx lly urx ury] |
38 % [w0x w0y llx lly urx ury w1x w1y vx vy])
39 % <bitmap> <cid> <type32font> addglyph -
40 1 index dup 2 index .removeglyphs
41 22 string .makeglyph32
42 % Stack: metrics bitmap cid font metstr
43 3 index () ne {
44 % Use G4 encoding to compress the bitmap.
45 % Define a string large enough to hold the metrics,
46 % an uncompressed bitmap (worst case = 5x expansion),
47 % and the 2 RTC codes (3 bytes).
48 dup length 4 index length 5 mul add 10 add string
49 % Stack: metrics bitmap cid font metstr buffer
50 dup 0 3 index putinterval
51 dup 2 index length 1 index length 1 index sub getinterval
52 % Stack: metrics bitmap cid font metstr buffer bitbuf
53 mark /Columns 8 index dup 4 get exch 2 get sub
54 /Rows 10 index dup 5 get exch 3 get sub
55 /K -1 /EndOfBlock true /BlackIs1 true
56 .dicttomark /CCITTFaxEncode filter
57 % Stack: metrics bitmap cid font metstr buffer filter
58 dup 6 index writestring closefile
59 % Find the end of the data by scanning backwards for the RTC.
60 % There are 2 RTCs x 12 bits = 3 bytes to remove.
61 {
62 dup dup length 1 sub get 0 ne { exit } if
63 0 1 index length 1 sub getinterval
64 } loop
65 0 1 index length 3 sub getinterval
66 exch pop % metstr
67 } if
68 1 index /CharStrings get 3 index 3 -1 roll put
69 pop pop pop pop
70 } obind
71
72 /removeall { % <type32font> removeall -
73 0 65535 2 index removeglyphs pop
74 } obind
75
76 /.removeglyphs systemdict /.removeglyphs get
77 systemdict /.removeglyphs .undef
78
79 /removeglyphs { % <cid_min> <cid_max> <type32font> .removeglyphs -
80 3 copy .removeglyphs
81 dup /CharStrings get dup {
82 % Stack: cidmin cidmax font CharStrings cid bitmap
83 pop dup 5 index ge { dup 4 index le { 2 copy undef } if } if pop
84 } forall pop pop pop pop
85 } obind
86
87 .dicttomark /ProcSet defineresource pop
88
89 /.cidfonttypes where { pop } { /.cidfonttypes 6 dict def } ifelse
90 .cidfonttypes begin
91
92 4 % CIDFontType 4 = FontType 32
93 { dup /FontType 32 put
94 dup /CharStrings 20 dict put
95 1 index exch .buildfont32 exch pop
96 } bind def
97
98 end % .cidfonttypes
99
100 % Define the BuildGlyph procedure.
101 % Since Type 32 fonts are indexed by CID, there is no BuildChar procedure.
102 % The name %Type32BuildGlyph is known to the interpreter.
103 (%Type32BuildGlyph) cvn { % <font> <cid> %Type32BuildGlyph -
104 1 index /CharStrings get
105 % Stack: font cid CharStrings
106 dup 2 index .knownget { exch pop } { 0 get } ifelse
107 % Stack: font cid cstr
108 dup .getmetrics32
109 dup 14 gt {
110 11 1 roll setcachedevice2
111 } {
112 7 1 roll setcachedevice
113 } ifelse
114 % Stack: font cid cstr w h nmetrics
115 4 -1 roll exch 1 index length 1 index sub getinterval
116 % Stack: font cid w h bitstr
117 dup () eq {
118 pop
119 } {
120 mark /Columns 4 index /Rows 5 index /K -1 /EndOfBlock false /BlackIs1 true
121 .dicttomark /CCITTFaxDecode filter 2 index 2 index true
122 % Stack: font cid w h filter w h true
123 [ 1 0 0 1 0 7 index ] 5 -1 roll imagemask
124 } ifelse
125 pop pop pop pop
126 } bind def
127
128 systemdict /.getmetrics32 .undef
129
130 buildfontdict 32 /.buildfont32 cvx put
131
132 32 dup /FontType defineresource pop
133
134 .setlanguagelevel