Debian Codegraph @

podofo/3rdparty/adobe/afdko/include/cffwrite.h

raw
1
2 /* Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/). All Rights Reserved.
3 This software is licensed as OpenSource, under the Apache License, Version 2.0.
4 This license is available at: http://opensource.org/licenses/Apache-2.0. */
5
6 #ifndef CFFWRITE_H
7 #define CFFWRITE_H
8
9 #include "ctlshare.h"
10
11 #define CFW_VERSION CTL_MAKE_VERSION(1, 0, 56)
12
13 #include "absfont.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /* Compact Font Format (CFF) Generation Library
20 ============================================
21 This library allows the generation of CFF FontSets. Regular and synthetic
22 name-based (Type 1) and registry-based (CID-keyed) fonts are supported as
23 members of single- or multiple-font FontSets.
24
25 This library is initialized with a single call to cfwNew() which allocates a
26 opaque context (cfwCtx) which is passed to subsequent functions and is
27 destroyed by a single call to cfwFree(). Thus, multiple contexts may be
28 concurrently allocated permitting operation in a multi-threaded environment.
29
30 Once a context has been allocated a client may call other functions in the
31 interface in order to construct the desired FontSet.
32
33 Memory management and data I/O are implemented via a number of
34 client-supplied callback functions passed to cfwNew() via the cfwCallbacks
35 data structure.
36
37 Library I/O is performed on two abstract data streams:
38
39 o cff FontSet data output
40 o temporary data input and output
41
42 These streams are managed by a single set of client callback functions
43 enabling the client to choose from a wide variety of implementation schemes
44 ranging from disk files to memory buffers.
45
46 The temporary stream is used to keep the run-time memory usage within
47 reasonable limits when handling large fonts. */
48
49 typedef struct cfwCtx_ *cfwCtx;
50 cfwCtx cfwNew(ctlMemoryCallbacks *mem_cb, ctlStreamCallbacks *stm_cb,
51 CTL_CHECK_ARGS_DCL);
52
53 #define CFW_CHECK_ARGS CTL_CHECK_ARGS_CALL(CFW_VERSION)
54
55 /* cfwNew() initializes the library and returns an opaque context that
56 subsequently passed to all the other library functions. It must be the first
57 function in the library to be called by the client. The client passes sets
58 memory and stream callback functions (described in ctlshare.h) to the
59 library via the mem_cb and stm_cb parameters.
60
61 The CFW_CHECK_ARGS macro is passed as the last parameter to cfwNew() in
62 order to perform a client/library compatibility check. */
63
64 int cfwBegSet(cfwCtx h, long flags);
65
66 /* cfwBegSet() is called to begin a new FontSet specification. The flags
67 parameter specifies FontSet creation options below: */
68
69 enum {
70 CFW_SUBRIZE = 1 << 0, /* Subroutinize member fonts' charstrings */
71 CFW_EMBED_OPT = 1 << 1, /* Perform embedding optimization */
72 CFW_ROM_OPT = 1 << 2, /* Perform ROM-resident FontSet optimization */
73 CFW_NO_DEP_OPS = 1 << 3, /* Remove/convert deprecated ops */
74 CFW_NO_FAMILY_OPT = 1 << 4, /* Don't apply family value optimizations */
75 CFW_WARN_DUP_HINTSUBS = 1 << 5, /* Report duplicate hintsubs warnings */
76 CFW_PRESERVE_GLYPH_ORDER = 1 << 6, /* Preserve glyph addition order */
77 CFW_CHECK_IF_GLYPHS_DIFFER = 1 << 7, /* When adding a charstring, check if */
78 /* it is already present and same or different. */
79 CFW_ENABLE_CMP_TEST = 1 << 8, /* Enable testing by disabling optimizations */
80 CFW_FORCE_STD_ENCODING = 1 << 10,
81 /* When bit 10 is set, TopDict encoding vector is set to StandardEncoding,
82 no matter what is in the font. This is useful for working with font
83 sources that will be used for OpenType/CFF fonts */
84 CFW_NO_OPTIMIZATION = 1 << 12, /* Suppress charstring optimizations, e.g.: */
85 /* x 0 rmoveto => x hmoveto */
86 CFW_WRITE_CFF2 = 1 << 13
87 };
88
89 /* If the CFW_PRESERVE_GLYPH_ORDER bit is not set, glyphs are accumulated and
90 then sorted during cfwEndFont(), into an order that reduces the internal CFF
91 charset and encoding data structure sizes.
92
93 Conversely, if the CFW_PRESERVE_GLYPH_ORDER bit is set, the order in which
94 glyphs are added to the font via the glyph callbacks is preserved. However,
95 in either of these cases the .notdef glyph is special and is always assigned
96 a glyph index of 0.
97
98 The CFW_CHECK_IF_GLYPHS_DIFFER allows clients to merge two or more fonts
99 together. Note that the client is responsible for ensuring that the fonts
100 are sufficiently compatible that the merged glyphs play well together.
101
102 If the CFW_ENABLE_CMP_TEST bit is set, several necessary optimization are
103 disabled so as to enable rendering tests to succeed. This must never be
104 used by production code.
105
106 If the CFW_SUBRIZE bit is set, repeated patterns in charstrings are extracted
107 as subroutines in order to minimize the total font size. Since this process
108 is both memory and CPU intensive, this option should be used cautiously. */
109
110 typedef struct cfwMapCallback_ cfwMapCallback;
111 struct cfwMapCallback_ {
112 void *ctx;
113 void (*glyphmap)(cfwMapCallback *cb,
114 unsigned short gid, abfGlyphInfo *info);
115 };
116
117 int cfwBegFont(cfwCtx h, cfwMapCallback *map, unsigned long maxNumSubrs);
118
119 /* cfwBegFont() is called to begin a new member font definition.
120
121 The "map" parameter specifies an optional glyph mapping callback that
122 provides information to the client about how the glyphs have been allocated
123 in the CFF CharStrings INDEX. This facility may be disabled by setting the
124 "map" parameter to NULL.
125
126 If "map" is non-NULL and the CFW_PRESERVE_GLYPH_ORDER bit is set the
127 glyphmap() callback function is called during the glyphEnd() callback thus
128 enabling clients to get information about the glyph just added (like its
129 glyph index).
130
131 If "map" is non-NULL and the CFW_PRESERVE_GLYPH_ORDER bit is NOT set the
132 glyphmap() callback function is called during cfwEndFont() after the glyphs
133 have been sorted into order. Each glyph is called back, in order, beginning
134 with the first at GID 0.
135
136 The glyphmap() "gid" parameter specifies the glyph's index and the
137 "info" parameter identifies the glyph. */
138
139 extern const abfGlyphCallbacks cfwGlyphCallbacks;
140
141 /* cfwGlyphCallbacks is a glyph callback set template that will add the data
142 passed to these callbacks to the current font. Clients should make a copy of
143 this data structure and set the "direct_ctx" field to the context returned
144 by cfwNew().
145
146 The client must keep the glyph information, passed via the "info" parameter
147 to the glyphBeg() callback, stable until after cfwEndFont() returns. */
148
149 int cfwCompareFDArrays(cfwCtx h, abfTopDict *srcTop);
150
151 /* cfwCompareFDArrays() compares the FDArray of the source font with the the
152 FDArray of the destination font. If a source font dict has a FontName
153 different than that in the font dict in the destination font, then it is
154 skipped. If there is a font dict in the destination font which has the same
155 name, then the two font dicts are compared. If any source font dict is not
156 compatible with a destination font dict of the same FontName, the function
157 returns 1 else it returns 0. */
158
159 int cfwMergeFDArray(cfwCtx h, abfTopDict *top, int *newFDIndex);
160
161 /* cfwMergeFDArray() merges all the fdArray font dicts of the passed-in source
162 font top dict into the destination font. It also fills in the array pointed
163 to by newFDIndex such that newFDIndex[source font dict index] == destination
164 font dict index. The newFDIndex array must be allocated by the client, and
165 must be large enough to hold an array of length top->FDArray.cnt. If the
166 destination font has a font dict with the same name as a source font dict,
167 then source font dict is assumed to be compatible to the destination font
168 dict, and is not merged into the destination font; otherwise, the source
169 font dict as added to the destination font as a new font dict.
170
171 if the cffwrite module error code is set before or during the merging
172 process, then cfwMergeFDArray() will set the destination font iFD to
173 ABF_UNSET_INT for all remaining font dicts, and will return the error code.
174
175 It is assumed that source and destination font dicts with the same name are
176 compatible; the function cfwCompareFDArrays can be used to verify this.
177
178 The client must then set the abfGlyphInfo->iFD field to the destination font
179 FDArray index, as returned by cfwMergeDict, after reading from the source
180 font, and before calling the destination font glyphBeg function.
181
182 Note! Once cfwMergeTopDict() has been called, the cffwrite module will NOT
183 merge in the original source font top dicts when fontEnd is called. If
184 cfwMergeTopDict() is called for any font dict of any source font, then it
185 must be called for every font dict of every source font, and the
186 abfGlyphInfo->iFD value of each source glyph must be set to the destination
187 font iFD value for the font dict before the glyph callbacks are used.
188
189 Note! cfwMergeTopDict() should not be called for fonts which do not meet the
190 test: font is not CID and both font have only one dict in the FDArray This
191 is because the cfwMergeTopDict() function assumes that fontDicts with
192 different names must be treated as different font dicts. For non_CID fonts
193 with one font dict, this is not the case; subset fonts will have fontDicts
194 with different prefixes, but which should be considered equivalent. If
195 cfwMergeTopDict() is used with two subset fonts, the destination font will
196 incorrectly get two font dicts. */
197
198 int cfwGetErrCode(cfwCtx h);
199
200 /* cfwGetErrCode() returns any error flags currently set in the cfwCtx. It can
201 be called at any time, and does not change the state of the cfwCtx */
202
203 int cfwEndFont(cfwCtx h, abfTopDict *top);
204
205 /* cfwEndFont() completes the definition of the font that commenced with
206 cfwBegFont(). The "top" parameter specifies global font information via the
207 data structures described in absfont.h.
208
209 A client can abandon a font part way through its definition by calling
210 cfwEndFont() with a "top" parameter value of NULL.
211
212 When cfwEndFont() returns the client no longer needs to keep the glyph
213 information, passed via the "info" parameter to the glyphBeg() callback,
214 stable. */
215
216 int cfwEndSet(cfwCtx h);
217
218 /* cfwEndSet() completes the definition of the FontSet that was initiated with
219 cfwBegSet(); */
220
221 void cfwFree(cfwCtx h);
222
223 /* cfwFree() destroys the library context and all the resources allocated to
224 it. It must be the last function called by a client of the library. */
225
226 enum {
227 #undef CTL_DCL_ERR
228 #define CTL_DCL_ERR(name, string) name,
229 #include "cfwerr.h"
230 cfwErrCount
231 };
232
233 /* Library functions return either zero (cfwSuccess) to indicate success or a
234 positive non-zero error code that is defined in the above enumeration that
235 is built from cfwerr.h. */
236
237 char *cfwErrStr(int err_code);
238
239 /* cfwErrStr() maps the "err_code" parameter to a null-terminated error
240 string. */
241
242 void cfwGetVersion(ctlVersionCallbacks *cb);
243
244 /* cfwGetVersion() returns the library version number and name via the client
245 callbacks passed with the "cb" parameter (see ctlshare.h). */
246
247 #ifdef __cplusplus
248 }
249 #endif
250
251 #endif /* CFFWRITE_H */