2 |
- |
1 |
/* Copyright (C) 2000, 2001 Aladdin Enterprises. All rights reserved.
|
|
|
2 |
|
|
|
3 |
This software is provided AS-IS with no warranty, either express or
|
|
|
4 |
implied.
|
|
|
5 |
|
|
|
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.
|
|
|
9 |
|
|
|
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.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
/* $Id: gdevpsf.h,v 1.27 2004/08/19 19:33:09 stefan Exp $ */
|
|
|
18 |
/* PostScript/PDF font writing interface */
|
|
|
19 |
|
|
|
20 |
#ifndef gdevpsf_INCLUDED
|
|
|
21 |
# define gdevpsf_INCLUDED
|
|
|
22 |
|
|
|
23 |
#include "gsccode.h"
|
|
|
24 |
#include "gsgdata.h"
|
|
|
25 |
|
|
|
26 |
/* ---------------- Embedded font writing ---------------- */
|
|
|
27 |
|
|
|
28 |
#ifndef gs_font_DEFINED
|
|
|
29 |
# define gs_font_DEFINED
|
|
|
30 |
typedef struct gs_font_s gs_font;
|
|
|
31 |
#endif
|
|
|
32 |
#ifndef gs_font_base_DEFINED
|
|
|
33 |
# define gs_font_base_DEFINED
|
|
|
34 |
typedef struct gs_font_base_s gs_font_base;
|
|
|
35 |
#endif
|
|
|
36 |
#ifndef stream_DEFINED
|
|
|
37 |
# define stream_DEFINED
|
|
|
38 |
typedef struct stream_s stream;
|
|
|
39 |
#endif
|
|
|
40 |
|
|
|
41 |
/*
|
|
|
42 |
* Define the structure used for enumerating the glyphs in a font or a
|
|
|
43 |
* font subset. This type is opaque to clients: we declare it here only
|
|
|
44 |
* so that clients can allocate it on the stack.
|
|
|
45 |
*/
|
|
|
46 |
typedef struct psf_glyph_enum_s psf_glyph_enum_t;
|
|
|
47 |
struct psf_glyph_enum_s {
|
|
|
48 |
gs_font *font;
|
|
|
49 |
struct su_ {
|
|
|
50 |
union sus_ {
|
|
|
51 |
const gs_glyph *list; /* if subset given by a list */
|
|
|
52 |
const byte *bits; /* if CID or TT subset given by a bitmap */
|
|
|
53 |
} selected;
|
|
|
54 |
uint size;
|
|
|
55 |
} subset;
|
|
|
56 |
gs_glyph_space_t glyph_space;
|
|
|
57 |
ulong index;
|
|
|
58 |
int (*enumerate_next)(psf_glyph_enum_t *, gs_glyph *);
|
|
|
59 |
};
|
|
|
60 |
|
|
|
61 |
/*
|
|
|
62 |
* Begin enumerating the glyphs in a font or a font subset. If subset_size
|
|
|
63 |
* > 0 but subset_glyphs == 0, enumerate all glyphs in [0 .. subset_size-1]
|
|
|
64 |
* (as integer glyphs, i.e., offset by gs_min_cid_glyph).
|
|
|
65 |
*/
|
|
|
66 |
void psf_enumerate_list_begin(psf_glyph_enum_t *ppge, gs_font *font,
|
|
|
67 |
const gs_glyph *subset_list,
|
|
|
68 |
uint subset_size,
|
|
|
69 |
gs_glyph_space_t glyph_space);
|
|
|
70 |
/* Backward compatibility */
|
|
|
71 |
#define psf_enumerate_glyphs_begin psf_enumerate_list_begin
|
|
|
72 |
|
|
|
73 |
/* Begin enumerating CID or TT glyphs in a subset given by a bit vector. */
|
|
|
74 |
/* Note that subset_size is given in bits, not in bytes. */
|
|
|
75 |
void psf_enumerate_bits_begin(psf_glyph_enum_t *ppge, gs_font *font,
|
|
|
76 |
const byte *subset_bits, uint subset_size,
|
|
|
77 |
gs_glyph_space_t glyph_space);
|
|
|
78 |
/* Backward compatibility */
|
|
|
79 |
#define psf_enumerate_cids_begin(ppge, font, bits, size)\
|
|
|
80 |
psf_enumerate_bits_begin(ppge, font, bits, size, GLYPH_SPACE_NAME)
|
|
|
81 |
|
|
|
82 |
/*
|
|
|
83 |
* Reset a glyph enumeration.
|
|
|
84 |
*/
|
|
|
85 |
void psf_enumerate_glyphs_reset(psf_glyph_enum_t *ppge);
|
|
|
86 |
|
|
|
87 |
/*
|
|
|
88 |
* Enumerate the next glyph in a font or a font subset.
|
|
|
89 |
* Return 0 if more glyphs, 1 if done, <0 if error.
|
|
|
90 |
*/
|
|
|
91 |
int psf_enumerate_glyphs_next(psf_glyph_enum_t *ppge, gs_glyph *pglyph);
|
|
|
92 |
|
|
|
93 |
/*
|
|
|
94 |
* Add composite glyph pieces to a list of glyphs. Does not sort or
|
|
|
95 |
* remove duplicates. max_pieces is the maximum number of pieces that a
|
|
|
96 |
* single glyph can have: if this value is not known, the caller should
|
|
|
97 |
* use max_count.
|
|
|
98 |
*/
|
|
|
99 |
int psf_add_subset_pieces(gs_glyph *glyphs, uint *pcount, uint max_count,
|
|
|
100 |
uint max_pieces, gs_font *font);
|
|
|
101 |
|
|
|
102 |
/*
|
|
|
103 |
* Sort a list of glyphs and remove duplicates. Return the number of glyphs
|
|
|
104 |
* in the result.
|
|
|
105 |
*/
|
|
|
106 |
int psf_sort_glyphs(gs_glyph *glyphs, int count);
|
|
|
107 |
|
|
|
108 |
/*
|
|
|
109 |
* Return the index of a given glyph in a sorted list of glyphs, or -1
|
|
|
110 |
* if the glyph is not present.
|
|
|
111 |
*/
|
|
|
112 |
int psf_sorted_glyphs_index_of(const gs_glyph *glyphs, int count,
|
|
|
113 |
gs_glyph glyph);
|
|
|
114 |
/*
|
|
|
115 |
* Determine whether a sorted list of glyphs includes a given glyph.
|
|
|
116 |
*/
|
|
|
117 |
bool psf_sorted_glyphs_include(const gs_glyph *glyphs, int count,
|
|
|
118 |
gs_glyph glyph);
|
|
|
119 |
|
|
|
120 |
/*
|
|
|
121 |
* Define the internal structure that holds glyph information for an
|
|
|
122 |
* outline-based font to be written. Currently this only applies to
|
|
|
123 |
* Type 1, Type 2, and CIDFontType 0 fonts, but someday it might also
|
|
|
124 |
* be usable with TrueType (Type 42) and CIDFontType 2 fonts.
|
|
|
125 |
*/
|
|
|
126 |
#define MAX_CFF_MISC_STRINGS 40
|
|
|
127 |
#define MAX_CFF_STD_STRINGS 500 /* 391 entries used */
|
|
|
128 |
typedef struct psf_outline_glyphs_s {
|
|
|
129 |
gs_glyph notdef;
|
|
|
130 |
/* gs_glyph subset_data[256 * 3 + 1]; *3 for seac, +1 for .notdef */
|
|
|
131 |
gs_glyph *subset_data;
|
|
|
132 |
gs_glyph *subset_glyphs; /* 0 or subset_data */
|
|
|
133 |
uint subset_size;
|
|
|
134 |
} psf_outline_glyphs_t;
|
|
|
135 |
|
|
|
136 |
#ifndef gs_font_type1_DEFINED
|
|
|
137 |
# define gs_font_type1_DEFINED
|
|
|
138 |
typedef struct gs_font_type1_s gs_font_type1;
|
|
|
139 |
#endif
|
|
|
140 |
|
|
|
141 |
/* Define the type for the glyph data callback procedure. */
|
|
|
142 |
typedef int (*glyph_data_proc_t)(gs_font_base *, gs_glyph,
|
|
|
143 |
gs_glyph_data_t *, gs_font_type1 **);
|
|
|
144 |
|
|
|
145 |
/* Check that all selected glyphs can be written. */
|
|
|
146 |
int psf_check_outline_glyphs(gs_font_base *pfont,
|
|
|
147 |
psf_glyph_enum_t *ppge,
|
|
|
148 |
glyph_data_proc_t glyph_data);
|
|
|
149 |
|
|
|
150 |
/*
|
|
|
151 |
* Gather glyph information for a Type 1, Type 2, or CIDFontType 0 font.
|
|
|
152 |
* Note that the glyph_data procedure returns both the outline string and
|
|
|
153 |
* a gs_font_type1 (Type 1 or Type 2) font: for Type 1 or Type 2 fonts,
|
|
|
154 |
* this is the original font, but for CIDFontType 0 fonts, it is the
|
|
|
155 |
* FDArray element. If subset_glyphs != 0, this procedure removes
|
|
|
156 |
* undefined glyphs from the list it builds.
|
|
|
157 |
*/
|
|
|
158 |
int psf_get_outline_glyphs(psf_outline_glyphs_t *pglyphs,
|
|
|
159 |
gs_font_base *pfont, gs_glyph *subset_glyphs,
|
|
|
160 |
uint subset_size, glyph_data_proc_t glyph_data);
|
|
|
161 |
|
|
|
162 |
/* ------ Exported by gdevpsf1.c ------ */
|
|
|
163 |
|
|
|
164 |
/* Gather glyph information for a Type 1 or Type 2 font. */
|
|
|
165 |
int psf_type1_glyph_data(gs_font_base *, gs_glyph, gs_glyph_data_t *,
|
|
|
166 |
gs_font_type1 **);
|
|
|
167 |
int psf_get_type1_glyphs(psf_outline_glyphs_t *pglyphs,
|
|
|
168 |
gs_font_type1 *pfont,
|
|
|
169 |
gs_glyph *subset_glyphs, uint subset_size);
|
|
|
170 |
|
|
|
171 |
/*
|
|
|
172 |
* Write a Type 1 font definition. This procedure does not allocate
|
|
|
173 |
* or free any data.
|
|
|
174 |
*/
|
|
|
175 |
#define WRITE_TYPE1_EEXEC 1
|
|
|
176 |
#define WRITE_TYPE1_ASCIIHEX 2 /* use ASCII hex rather than binary */
|
|
|
177 |
#define WRITE_TYPE1_EEXEC_PAD 4 /* add 512 0s */
|
|
|
178 |
#define WRITE_TYPE1_EEXEC_MARK 8 /* assume 512 0s will be added */
|
|
|
179 |
#define WRITE_TYPE1_POSTSCRIPT 16 /* don't observe ATM restrictions */
|
|
|
180 |
#define WRITE_TYPE1_WITH_LENIV 32 /* don't allow lenIV = -1 */
|
|
|
181 |
int psf_write_type1_font(stream *s, gs_font_type1 *pfont, int options,
|
|
|
182 |
gs_glyph *subset_glyphs, uint subset_size,
|
|
|
183 |
const gs_const_string *alt_font_name,
|
|
|
184 |
int lengths[3]);
|
|
|
185 |
|
|
|
186 |
/* ------ Exported by gdevpsf2.c ------ */
|
|
|
187 |
|
|
|
188 |
/*
|
|
|
189 |
* Write a Type 1 or Type 2 font definition as CFF.
|
|
|
190 |
* This procedure does not allocate or free any data.
|
|
|
191 |
*/
|
|
|
192 |
#define WRITE_TYPE2_NO_LENIV 1 /* always use lenIV = -1 */
|
|
|
193 |
#define WRITE_TYPE2_CHARSTRINGS 2 /* convert T1 charstrings to T2 */
|
|
|
194 |
#define WRITE_TYPE2_AR3 4 /* work around bugs in Acrobat Reader 3 */
|
|
|
195 |
#define WRITE_TYPE2_NO_GSUBRS 8 /* omit GlobalSubrs */
|
|
|
196 |
int psf_write_type2_font(stream *s, gs_font_type1 *pfont, int options,
|
|
|
197 |
gs_glyph *subset_glyphs, uint subset_size,
|
|
|
198 |
const gs_const_string *alt_font_name,
|
|
|
199 |
gs_int_rect *FontBBox);
|
|
|
200 |
|
|
|
201 |
#ifndef gs_font_cid0_DEFINED
|
|
|
202 |
# define gs_font_cid0_DEFINED
|
|
|
203 |
typedef struct gs_font_cid0_s gs_font_cid0;
|
|
|
204 |
#endif
|
|
|
205 |
|
|
|
206 |
/*
|
|
|
207 |
* Write a CIDFontType 0 font definition as CFF. The options are
|
|
|
208 |
* the same as for psf_write_type2_font. subset_cids is a bit vector of
|
|
|
209 |
* subset_size bits (not bytes).
|
|
|
210 |
* This procedure does not allocate or free any data.
|
|
|
211 |
*/
|
|
|
212 |
int psf_write_cid0_font(stream *s, gs_font_cid0 *pfont, int options,
|
|
|
213 |
const byte *subset_cids, uint subset_size,
|
|
|
214 |
const gs_const_string *alt_font_name);
|
|
|
215 |
|
|
|
216 |
/* ------ Exported by gdevpsfm.c ------ */
|
|
|
217 |
|
|
|
218 |
/*
|
|
|
219 |
* Write a CMap in its customary (source) form.
|
|
|
220 |
* This procedure does not allocate or free any data.
|
|
|
221 |
*/
|
|
|
222 |
#ifndef gs_cmap_DEFINED
|
|
|
223 |
# define gs_cmap_DEFINED
|
|
|
224 |
typedef struct gs_cmap_s gs_cmap_t;
|
|
|
225 |
#endif
|
|
|
226 |
typedef int (*psf_put_name_chars_proc_t)(stream *, const byte *, uint);
|
|
|
227 |
int psf_write_cmap(const gs_memory_t *mem, stream *s, const gs_cmap_t *pcmap,
|
|
|
228 |
psf_put_name_chars_proc_t put_name_chars,
|
|
|
229 |
const gs_const_string *alt_cmap_name, int font_index_only);
|
|
|
230 |
/* ------ Exported by gdevpsft.c ------ */
|
|
|
231 |
|
|
|
232 |
/*
|
|
|
233 |
* Write a TrueType (Type 42) font definition.
|
|
|
234 |
* This procedure does not allocate or free any data.
|
|
|
235 |
*/
|
|
|
236 |
#ifndef gs_font_type42_DEFINED
|
|
|
237 |
# define gs_font_type42_DEFINED
|
|
|
238 |
typedef struct gs_font_type42_s gs_font_type42;
|
|
|
239 |
#endif
|
|
|
240 |
#define WRITE_TRUETYPE_CMAP 1 /* generate cmap from the Encoding */
|
|
|
241 |
#define WRITE_TRUETYPE_NAME 2 /* generate name if missing */
|
|
|
242 |
#define WRITE_TRUETYPE_POST 4 /* generate post if missing */
|
|
|
243 |
#define WRITE_TRUETYPE_NO_TRIMMED_TABLE 8 /* not OK to use cmap format 6 */
|
|
|
244 |
#define WRITE_TRUETYPE_HVMTX 16 /* generate [hv]mtx from glyph_info */
|
|
|
245 |
int psf_write_truetype_font(stream *s, gs_font_type42 *pfont, int options,
|
|
|
246 |
gs_glyph *subset_glyphs, uint subset_size,
|
|
|
247 |
const gs_const_string *alt_font_name);
|
|
|
248 |
|
|
|
249 |
/*
|
|
|
250 |
* Write a "stripped" TrueType font definition. All tables are written
|
|
|
251 |
* verbatim, except for deleting the bogus Adobe marker "tables" gdir, glyx,
|
|
|
252 |
* and locx, and also deleting glyf and loca.
|
|
|
253 |
* This procedure does not allocate or free any data.
|
|
|
254 |
*
|
|
|
255 |
* The purpose of "stripped" fonts is simply to store all of the non-glyph
|
|
|
256 |
* information from a TrueType-family font in a structure that can be easily
|
|
|
257 |
* stored, accessed, and eventually combined with the glyph information.
|
|
|
258 |
* The only intended client for this function is the font copying code in
|
|
|
259 |
* gxfcopy.c, q.v. In particular, "stripped" fonts are not fully valid
|
|
|
260 |
* fonts because they lack glyph 0 (the .notdef glyph).
|
|
|
261 |
*/
|
|
|
262 |
int psf_write_truetype_stripped(stream *s, gs_font_type42 *pfont);
|
|
|
263 |
|
|
|
264 |
#ifndef gs_font_cid2_DEFINED
|
|
|
265 |
# define gs_font_cid2_DEFINED
|
|
|
266 |
typedef struct gs_font_cid2_s gs_font_cid2;
|
|
|
267 |
#endif
|
|
|
268 |
|
|
|
269 |
/*
|
|
|
270 |
* Write a CIDFontType 2 font definition. This differs from
|
|
|
271 |
* psf_write_truetype_font in that the subset, if any, is specified
|
|
|
272 |
* as a bit vector (as for psf_write_cid0_font) rather than a list of glyphs.
|
|
|
273 |
* Also, none of the options currently have any effect. The only tables
|
|
|
274 |
* written are:
|
|
|
275 |
* - The "required" tables: head, hhea, loca, maxp, cvt_, prep, glyf,
|
|
|
276 |
* hmtx, fpgm.
|
|
|
277 |
* - If present in the font: post, gasp, kern, vhea, vmtx.
|
|
|
278 |
* Note that in particular, the cmap, name, and OS/2 tables are omitted.
|
|
|
279 |
* NOTE: it is the client's responsibility to ensure that if the subset
|
|
|
280 |
* contains any composite glyphs, the components of the composites are
|
|
|
281 |
* included explicitly in the subset.
|
|
|
282 |
* This procedure does not allocate or free any data.
|
|
|
283 |
*/
|
|
|
284 |
int psf_write_cid2_font(stream *s, gs_font_cid2 *pfont, int options,
|
|
|
285 |
const byte *subset_glyphs, uint subset_size,
|
|
|
286 |
const gs_const_string *alt_font_name);
|
|
|
287 |
|
|
|
288 |
/*
|
|
|
289 |
* Write a "stripped" CIDFontType 2 font definition. This is the same
|
|
|
290 |
* as an ordinary CIDFontType 2 definition, minus glyf and loca.
|
|
|
291 |
*/
|
|
|
292 |
int psf_write_cid2_stripped(stream *s, gs_font_cid2 *pfont);
|
|
|
293 |
|
|
|
294 |
/* ------ Exported by gdevpsfx.c ------ */
|
|
|
295 |
|
|
|
296 |
/*
|
|
|
297 |
* Convert a Type 1 CharString to (unencrypted) Type 2.
|
|
|
298 |
* This procedure does not allocate or free any data.
|
|
|
299 |
* NOTE: this procedure expands all Subrs in-line.
|
|
|
300 |
*/
|
|
|
301 |
int psf_convert_type1_to_type2(stream *s, const gs_glyph_data_t *pgd,
|
|
|
302 |
gs_font_type1 *pfont);
|
|
|
303 |
|
|
|
304 |
#endif /* gdevpsf_INCLUDED */
|