1 % Copyright (C) 1999 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: addxchar.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
17 % Add the Central European and other Adobe extended Latin characters to a
19 % Requires -dWRITESYSTEMDICT to disable access protection.
21 (type1ops.ps) runlibfile
23 % ---------------- Utilities ---------------- %
25 /addce_dict 50 dict def
28 % Define the added copyright notice.
29 /addednotice (. Portions Copyright (C) 1999 Aladdin Enterprises.) def
31 % Open a font for modification by removing the FID and changing the
32 % FontName. Removing UniqueID and XUID is not necessary, since we
33 % will only be adding characters.
34 /openfont { % <name> <font> openfont <name> <font'>
37 dup /FontName 3 index put
40 % Do the equivalent of false charpath for a glyph.
41 % This should really be an operator!
42 /glyphpath { % <glyph> glyphpath -
43 currentfont /Encoding get 0 3 -1 roll put
47 % Do the equivalent of charpath + pathbbox for a glyph.
48 /glyphbbox { % <glyph> glyphbbox <llx> <lly> <urx> <ury>
49 % We cache this value, because it's expensive to compute.
50 BBoxes 1 index .knownget {
53 gsave newpath 0 0 moveto dup glyphpath [pathbbox] grestore
54 BBoxes 3 -1 roll 2 index put
58 % Get the side bearing and width for a glyph.
59 /glyphsbw { % <glyph> glyphsbw <lsbx> <wx>
60 % We cache this value, because it's expensive to compute.
61 SBW 1 index .knownget {
64 dup glyphcs { dup /hsbw eq { pop exit } if } forall
66 SBW 3 -1 roll 2 index put
70 % Get the CharString for a glyph, as an array.
71 /glyphcs { % <glyph> glyphcs <array>
73 4330 exch dup length string .type1decrypt exch pop
74 dup length lenIV sub lenIV exch getinterval
75 0 () /SubFileDecode filter [ exch charstack_read ]
78 % Find an occurrence of a value in an array.
79 /asearch { % <array> <value> asearch <index> true
80 % <array> <value> asearch false
81 false 0 4 2 roll exch {
82 % Stack: false index value element
83 2 copy eq { pop pop exch not exch dup exit } if
88 % Convert an array back to a CharString.
89 /csdef { % <glyph> <array> csdef -
91 4330 exch dup .type1encrypt exch pop readonly
92 CharStrings 3 1 roll put
95 % Split an accented character name.
96 /splitaccented { % <Baccent> splitaccented <Baccent> <B> <accent>
98 dup 0 1 getinterval cvn
99 exch dup length 1 sub 1 exch getinterval cvn
102 % Begin the definition of a 'seac' character.
103 % Defines accent, base, abox, bbox.
104 % The initial dx lines up the origins of the base and the accent.
105 /beginseac { % <bchar> <achar> beginseac
106 % -mark- <lsbx> <wx> /hsbw <asb> <dx>
107 /accent exch def /base exch def
108 /abox [accent glyphbbox] def
109 /bbox [base glyphbbox] def
110 [ base glyphsbw /hsbw accent glyphsbw pop
114 % Center the accent over the base of a 'seac' character.
115 /centeraccent { % <dx> centeraccent <adx>
116 bbox 2 get bbox 0 get add 2 div
117 abox 2 get abox 0 get add 2 div
121 % Finish the definition of a 'seac' character.
122 /finishseac { % <charname> -mark- ... <adx> <ady> finishseac -
124 charindex base get charindex accent get /seac ] csdef
127 % ---------------- Main program ---------------- %
129 % Define accented characters that can be made with seac,
130 % with the accent centered over the character.
133 /Cacute /Ccaron /Dcaron
134 /Ecaron /Edotaccent /Emacron
139 /Ohungarumlaut /Omacron
143 /Uhungarumlaut /Umacron /Uogonek /Uring
147 /ecaron /edotaccent /emacron
151 /ohungarumlaut /omacron
154 /uhungarumlaut /umacron /uring
158 % Define seac characters where the accent lines up with the right
159 % edge of the character.
161 /Aogonek /Eogonek /Iogonek /aogonek /eogonek /iogonek /uogonek
164 % Define seac characters where the caron becomes an appended quoteright.
166 /dcaron /lcaron /tcaron
169 % Define seac characters using commaaccent.
171 /Gcommaaccent /Kcommaaccent /Lcommaaccent /Ncommaaccent /Rcommaaccent
172 /Scommaaccent /Tcommaaccent
173 /gcommaaccent /kcommaaccent /lcommaaccent /ncommaaccent /rcommaaccent
174 /scommaaccent /tcommaaccent
177 % Define the characters copied from the Symbol font.
179 /Delta /greaterequal /lessequal /lozenge /notequal /partialdiff
183 % Define the procedures for editing the commaaccent character.
184 % Delete all the hints, since it's too hard to adjust them.
186 /rmoveto { exch commatop sub cvi exch }
187 /hstem { pop pop pop }
190 dup 3 eq { 4 { pop } repeat /skip true def } if
192 /pop { skip { pop /skip false def } if }
195 /addce { % <name> <font> addce <font'>
197 /origfont 1 index def
199 dup /CharStrings 2 copy get dup length dict copy put
200 dup /Encoding 2 copy get dup length array copy put
201 dup /FontInfo 2 copy get dup length dict copy put
202 definefont /font exch def
203 currentdict font end begin begin
204 font 1000 scalefont setfont
205 /symbolfont /Symbol findfont def
206 /BBoxes CharStrings length dict def
207 /SBW CharStrings length dict def
209 /italfactor FontInfo /ItalicAngle .knownget {
210 neg dup sin exch cos div
215 % Invert the Encoding (needed for seac).
217 /charindex 256 dict def
219 charindex exch Encoding 1 index get exch put
222 % Add the commaaccent character, by moving the comma downward.
224 /comma glyphbbox /commatop exch def pop pop pop
227 [ exch { caedit 1 index .knownget { exec } if } forall ]
228 /commaaccent exch csdef
230 % Add the accented characters that can be made with seac.
233 splitaccented beginseac
235 % If the accent would collide with the base character,
237 abox 1 get bbox 3 get sub dup 0 le {
238 % ... but not if the accent is in the low position.
241 % Adjust the X position if italic.
242 dup italfactor mul 3 -1 roll add exch
253 splitaccented beginseac
254 bbox 2 get abox 2 get sub add % line up right edges
258 /dcroat /d /hyphen beginseac
259 bbox 2 get abox 2 get sub add % line up right edges
262 /imacron /dotlessi /macron beginseac
266 /Lcaron /L /quoteright beginseac
267 bbox 2 get abox 2 get sub add % line up right edges
271 dup =string cvs 0 1 getinterval cvn /quoteright beginseac
272 % Move the quote to the right of the character.
273 bbox 2 get abox 0 get sub 50 add add
274 % Adjust the character width as well.
275 4 -1 roll abox 2 get abox 0 get sub 50 add add cvi 4 1 roll
280 dup =string cvs 0 1 getinterval cvn /comma beginseac
283 % Lower the accent if the character extends below
285 bbox 1 get 0 .min add
289 % Add the characters from the Symbol font.
290 % We should scale them to match the FontBBox, but we don't.
293 symbolfont /CharStrings get 1 index get
294 CharStrings 3 1 roll put
297 % Add the one remaining character.
299 CharStrings /Dcroat CharStrings /Eth get put
301 % Recompute the FontBBox, since some of the accented characters
302 % may have enlarged it.
304 /llx 1000 def /lly 1000 def /urx 0 def /ury 0 def
307 ury .max /ury exch def urx .max /urx exch def
308 lly .min /lly exch def llx .min /llx exch def
310 /FontBBox llx cvi lly cvi urx ceiling cvi ury ceiling cvi 4 packedarray def
312 % Restore the Encoding and wrap up.
314 [/Copyright /Notice] {
315 FontInfo 1 index .knownget {
316 addednotice concatstrings FontInfo 3 1 roll put
321 FontName font openfont
322 dup /Encoding origfont /Encoding get put
328 currentdict end readonly pop % addce_dict
330 /addce { addce_dict begin addce end } def
332 % ---------------- Integration ---------------- %
334 % We would like to patch the font loader so that it adds the extended
335 % Latin characters automatically. We haven't done this yet.
337 % ---------------- Test program ---------------- %
339 /TEST where { pop TEST } { false } ifelse {
340 /FONT where { pop } { /FONT /Palatino-Italic def } ifelse
341 (unprot.ps) runlibfile
343 (wrfont.ps) runlibfile
345 /eexec_encrypt true def
346 /binary_CharStrings true def
350 /Latin-CE exch addce setfont
351 (t.ce.pfb) (w) file dup writefont closefile
353 (prfont.ps) runlibfile
354 (t.ce.pfb) (r) file .loadfont