2
|
1 |
/*
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
3 |
*
|
|
4 |
* This code is free software; you can redistribute it and/or modify it
|
|
5 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
6 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
8 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
9 |
*
|
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
14 |
* accompanied this code).
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License version
|
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
19 |
*
|
5506
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
21 |
* or visit www.oracle.com if you need additional information or have any
|
|
22 |
* questions.
|
2
|
23 |
*
|
|
24 |
*/
|
|
25 |
|
|
26 |
/*
|
16890
|
27 |
* (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
|
2
|
28 |
*
|
|
29 |
*/
|
|
30 |
|
|
31 |
#ifndef __OPENTYPELAYOUTENGINE_H
|
|
32 |
#define __OPENTYPELAYOUTENGINE_H
|
|
33 |
|
|
34 |
#include "LETypes.h"
|
|
35 |
#include "LEGlyphFilter.h"
|
|
36 |
#include "LEFontInstance.h"
|
|
37 |
#include "LayoutEngine.h"
|
16891
|
38 |
#include "LETableReference.h"
|
2
|
39 |
|
|
40 |
#include "GlyphSubstitutionTables.h"
|
|
41 |
#include "GlyphDefinitionTables.h"
|
|
42 |
#include "GlyphPositioningTables.h"
|
|
43 |
|
3935
|
44 |
U_NAMESPACE_BEGIN
|
|
45 |
|
2
|
46 |
/**
|
|
47 |
* OpenTypeLayoutEngine implements complex text layout for OpenType fonts - that is
|
|
48 |
* fonts which have GSUB and GPOS tables associated with them. In order to do this,
|
|
49 |
* the glyph processsing step described for LayoutEngine is further broken into three
|
|
50 |
* steps:
|
|
51 |
*
|
|
52 |
* 1) Character processing - this step analyses the characters and assigns a list of OpenType
|
|
53 |
* feature tags to each one. It may also change, remove or add characters, and change
|
|
54 |
* their order.
|
|
55 |
*
|
|
56 |
* 2) Glyph processing - This step performs character to glyph mapping,and uses the GSUB
|
|
57 |
* table associated with the font to perform glyph substitutions, such as ligature substitution.
|
|
58 |
*
|
|
59 |
* 3) Glyph post processing - in cases where the font doesn't directly contain a GSUB table,
|
|
60 |
* the previous two steps may have generated "fake" glyph indices to use with a "canned" GSUB
|
|
61 |
* table. This step turns those glyph indices into actual font-specific glyph indices, and may
|
|
62 |
* perform any other adjustments requried by the previous steps.
|
|
63 |
*
|
|
64 |
* OpenTypeLayoutEngine will also use the font's GPOS table to apply position adjustments
|
|
65 |
* such as kerning and accent positioning.
|
|
66 |
*
|
|
67 |
* @see LayoutEngine
|
|
68 |
*
|
|
69 |
* @internal
|
|
70 |
*/
|
7486
|
71 |
class U_LAYOUT_API OpenTypeLayoutEngine : public LayoutEngine
|
2
|
72 |
{
|
|
73 |
public:
|
|
74 |
/**
|
|
75 |
* This is the main constructor. It constructs an instance of OpenTypeLayoutEngine for
|
|
76 |
* a particular font, script and language. It takes the GSUB table as a parameter since
|
|
77 |
* LayoutEngine::layoutEngineFactory has to read the GSUB table to know that it has an
|
|
78 |
* OpenType font.
|
|
79 |
*
|
|
80 |
* @param fontInstance - the font
|
|
81 |
* @param scriptCode - the script
|
|
82 |
* @param langaugeCode - the language
|
|
83 |
* @param gsubTable - the GSUB table
|
7486
|
84 |
* @param success - set to an error code if the operation fails
|
2
|
85 |
*
|
|
86 |
* @see LayoutEngine::layoutEngineFactory
|
|
87 |
* @see ScriptAndLangaugeTags.h for script and language codes
|
|
88 |
*
|
|
89 |
* @internal
|
|
90 |
*/
|
|
91 |
OpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
|
16891
|
92 |
le_int32 typoFlags, const LEReferenceTo<GlyphSubstitutionTableHeader> &gsubTable, LEErrorCode &success);
|
2
|
93 |
|
|
94 |
/**
|
|
95 |
* This constructor is used when the font requires a "canned" GSUB table which can't be known
|
|
96 |
* until after this constructor has been invoked.
|
|
97 |
*
|
|
98 |
* @param fontInstance - the font
|
|
99 |
* @param scriptCode - the script
|
3935
|
100 |
* @param langaugeCode - the language
|
7486
|
101 |
* @param success - set to an error code if the operation fails
|
2
|
102 |
*
|
|
103 |
* @internal
|
|
104 |
*/
|
3935
|
105 |
OpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
|
7486
|
106 |
le_int32 typoFlags, LEErrorCode &success);
|
2
|
107 |
|
|
108 |
/**
|
|
109 |
* The destructor, virtual for correct polymorphic invocation.
|
|
110 |
*
|
|
111 |
* @internal
|
|
112 |
*/
|
|
113 |
virtual ~OpenTypeLayoutEngine();
|
|
114 |
|
|
115 |
/**
|
|
116 |
* A convenience method used to convert the script code into
|
|
117 |
* the four byte script tag required by OpenType.
|
7486
|
118 |
* For Indic languages where multiple script tags exist,
|
|
119 |
* the version 1 (old style) tag is returned.
|
2
|
120 |
*
|
|
121 |
* @param scriptCode - the script code
|
|
122 |
*
|
|
123 |
* @return the four byte script tag
|
|
124 |
*
|
|
125 |
* @internal
|
|
126 |
*/
|
|
127 |
static LETag getScriptTag(le_int32 scriptCode);
|
7486
|
128 |
/**
|
|
129 |
* A convenience method used to convert the script code into
|
|
130 |
* the four byte script tag required by OpenType.
|
|
131 |
* For Indic languages where multiple script tags exist,
|
|
132 |
* the version 2 tag is returned.
|
|
133 |
*
|
|
134 |
* @param scriptCode - the script code
|
|
135 |
*
|
|
136 |
* @return the four byte script tag
|
|
137 |
*
|
|
138 |
* @internal
|
|
139 |
*/
|
|
140 |
static LETag getV2ScriptTag(le_int32 scriptCode);
|
2
|
141 |
|
|
142 |
/**
|
|
143 |
* A convenience method used to convert the langauge code into
|
|
144 |
* the four byte langauge tag required by OpenType.
|
|
145 |
*
|
|
146 |
* @param languageCode - the language code
|
|
147 |
*
|
|
148 |
* @return the four byte language tag
|
|
149 |
*
|
|
150 |
* @internal
|
|
151 |
*/
|
|
152 |
static LETag getLangSysTag(le_int32 languageCode);
|
|
153 |
|
3935
|
154 |
/**
|
|
155 |
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
|
156 |
*
|
|
157 |
* @stable ICU 2.8
|
|
158 |
*/
|
|
159 |
virtual UClassID getDynamicClassID() const;
|
|
160 |
|
|
161 |
/**
|
|
162 |
* ICU "poor man's RTTI", returns a UClassID for this class.
|
|
163 |
*
|
|
164 |
* @stable ICU 2.8
|
|
165 |
*/
|
|
166 |
static UClassID getStaticClassID();
|
|
167 |
|
7486
|
168 |
/**
|
|
169 |
* The array of language tags, indexed by language code.
|
|
170 |
*
|
|
171 |
* @internal
|
|
172 |
*/
|
|
173 |
static const LETag languageTags[];
|
|
174 |
|
2
|
175 |
private:
|
|
176 |
|
|
177 |
/**
|
|
178 |
* This method is used by the constructors to convert the script
|
|
179 |
* and language codes to four byte tags and save them.
|
|
180 |
*/
|
|
181 |
void setScriptAndLanguageTags();
|
|
182 |
|
|
183 |
/**
|
|
184 |
* The array of script tags, indexed by script code.
|
|
185 |
*/
|
|
186 |
static const LETag scriptTags[];
|
|
187 |
|
16890
|
188 |
/**
|
|
189 |
* apply the typoflags. Only called by the c'tors.
|
|
190 |
*/
|
|
191 |
void applyTypoFlags();
|
|
192 |
|
2
|
193 |
protected:
|
|
194 |
/**
|
|
195 |
* A set of "default" features. The default characterProcessing method
|
|
196 |
* will apply all of these features to every glyph.
|
|
197 |
*
|
|
198 |
* @internal
|
|
199 |
*/
|
|
200 |
FeatureMask fFeatureMask;
|
|
201 |
|
|
202 |
/**
|
|
203 |
* A set of mappings from feature tags to feature masks. These may
|
|
204 |
* be in the order in which the featues should be applied, but they
|
|
205 |
* don't need to be.
|
|
206 |
*
|
|
207 |
* @internal
|
|
208 |
*/
|
|
209 |
const FeatureMap *fFeatureMap;
|
|
210 |
|
|
211 |
/**
|
|
212 |
* The length of the feature map.
|
|
213 |
*
|
|
214 |
* @internal
|
|
215 |
*/
|
|
216 |
le_int32 fFeatureMapCount;
|
|
217 |
|
|
218 |
/**
|
|
219 |
* <code>TRUE</code> if the features in the
|
|
220 |
* feature map are in the order in which they
|
|
221 |
* must be applied.
|
|
222 |
*
|
|
223 |
* @internal
|
|
224 |
*/
|
|
225 |
le_bool fFeatureOrder;
|
|
226 |
|
|
227 |
/**
|
|
228 |
* The address of the GSUB table.
|
|
229 |
*
|
|
230 |
* @internal
|
|
231 |
*/
|
16891
|
232 |
LEReferenceTo<GlyphSubstitutionTableHeader> fGSUBTable;
|
2
|
233 |
|
|
234 |
/**
|
|
235 |
* The address of the GDEF table.
|
|
236 |
*
|
|
237 |
* @internal
|
|
238 |
*/
|
16891
|
239 |
LEReferenceTo<GlyphDefinitionTableHeader> fGDEFTable;
|
2
|
240 |
|
|
241 |
/**
|
|
242 |
* The address of the GPOS table.
|
|
243 |
*
|
|
244 |
* @internal
|
|
245 |
*/
|
16891
|
246 |
LEReferenceTo<GlyphPositioningTableHeader> fGPOSTable;
|
2
|
247 |
|
|
248 |
/**
|
|
249 |
* An optional filter used to inhibit substitutions
|
|
250 |
* preformed by the GSUB table. This is used for some
|
|
251 |
* "canned" GSUB tables to restrict substitutions to
|
|
252 |
* glyphs that are in the font.
|
|
253 |
*
|
|
254 |
* @internal
|
|
255 |
*/
|
|
256 |
LEGlyphFilter *fSubstitutionFilter;
|
|
257 |
|
|
258 |
/**
|
|
259 |
* The four byte script tag.
|
|
260 |
*
|
|
261 |
* @internal
|
|
262 |
*/
|
|
263 |
LETag fScriptTag;
|
|
264 |
|
|
265 |
/**
|
7486
|
266 |
* The four byte script tag for V2 fonts.
|
|
267 |
*
|
|
268 |
* @internal
|
|
269 |
*/
|
|
270 |
LETag fScriptTagV2;
|
|
271 |
|
|
272 |
/**
|
2
|
273 |
* The four byte language tag
|
|
274 |
*
|
|
275 |
* @internal
|
|
276 |
*/
|
|
277 |
LETag fLangSysTag;
|
|
278 |
|
|
279 |
/**
|
|
280 |
* This method does the OpenType character processing. It assigns the OpenType feature
|
|
281 |
* tags to the characters, and may generate output characters that differ from the input
|
|
282 |
* charcters due to insertions, deletions, or reorderings. In such cases, it will also
|
|
283 |
* generate an output character index array reflecting these changes.
|
|
284 |
*
|
|
285 |
* Subclasses must override this method.
|
|
286 |
*
|
|
287 |
* Input parameters:
|
|
288 |
* @param chars - the input character context
|
|
289 |
* @param offset - the index of the first character to process
|
|
290 |
* @param count - the number of characters to process
|
|
291 |
* @param max - the number of characters in the input context
|
|
292 |
* @param rightToLeft - TRUE if the characters are in a right to left directional run
|
|
293 |
*
|
|
294 |
* Output parameters:
|
|
295 |
* @param outChars - the output character array, if different from the input
|
|
296 |
* @param charIndices - the output character index array
|
|
297 |
* @param featureTags - the output feature tag array
|
|
298 |
* @param success - set to an error code if the operation fails
|
|
299 |
*
|
|
300 |
* @return the output character count (input character count if no change)
|
|
301 |
*
|
|
302 |
* @internal
|
|
303 |
*/
|
3935
|
304 |
virtual le_int32 characterProcessing(const LEUnicode /*chars*/[], le_int32 offset, le_int32 count, le_int32 max, le_bool /*rightToLeft*/,
|
|
305 |
LEUnicode *&/*outChars*/, LEGlyphStorage &glyphStorage, LEErrorCode &success);
|
2
|
306 |
|
|
307 |
/**
|
|
308 |
* This method does character to glyph mapping, and applies the GSUB table. The
|
|
309 |
* default implementation calls mapCharsToGlyphs and then applies the GSUB table,
|
|
310 |
* if there is one.
|
|
311 |
*
|
|
312 |
* Note that in the case of "canned" GSUB tables, the output glyph indices may be
|
|
313 |
* "fake" glyph indices that need to be converted to "real" glyph indices by the
|
|
314 |
* glyphPostProcessing method.
|
|
315 |
*
|
|
316 |
* Input parameters:
|
|
317 |
* @param chars - the input character context
|
|
318 |
* @param offset - the index of the first character to process
|
|
319 |
* @param count - the number of characters to process
|
|
320 |
* @param max - the number of characters in the input context
|
|
321 |
* @param rightToLeft - TRUE if the characters are in a right to left directional run
|
|
322 |
* @param featureTags - the feature tag array
|
|
323 |
*
|
|
324 |
* Output parameters:
|
|
325 |
* @param glyphs - the output glyph index array
|
|
326 |
* @param charIndices - the output character index array
|
|
327 |
* @param success - set to an error code if the operation fails
|
|
328 |
*
|
|
329 |
* @return the number of glyphs in the output glyph index array
|
|
330 |
*
|
|
331 |
* Note: if the character index array was already set by the characterProcessing
|
|
332 |
* method, this method won't change it.
|
|
333 |
*
|
|
334 |
* @internal
|
|
335 |
*/
|
3935
|
336 |
virtual le_int32 glyphProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
|
|
337 |
LEGlyphStorage &glyphStorage, LEErrorCode &success);
|
2
|
338 |
|
7486
|
339 |
virtual le_int32 glyphSubstitution(le_int32 count, le_int32 max, le_bool rightToLeft, LEGlyphStorage &glyphStorage, LEErrorCode &success);
|
|
340 |
|
2
|
341 |
/**
|
|
342 |
* This method does any processing necessary to convert "fake"
|
|
343 |
* glyph indices used by the glyphProcessing method into "real" glyph
|
|
344 |
* indices which can be used to render the text. Note that in some
|
|
345 |
* cases, such as CDAC Indic fonts, several "real" glyphs may be needed
|
|
346 |
* to render one "fake" glyph.
|
|
347 |
*
|
|
348 |
* The default implementation of this method just returns the input glyph
|
|
349 |
* index and character index arrays, assuming that no "fake" glyph indices
|
|
350 |
* were needed to do GSUB processing.
|
|
351 |
*
|
|
352 |
* Input paramters:
|
|
353 |
* @param tempGlyphs - the input "fake" glyph index array
|
|
354 |
* @param tempCharIndices - the input "fake" character index array
|
|
355 |
* @param tempGlyphCount - the number of "fake" glyph indices
|
|
356 |
*
|
|
357 |
* Output parameters:
|
|
358 |
* @param glyphs - the output glyph index array
|
|
359 |
* @param charIndices - the output character index array
|
|
360 |
* @param success - set to an error code if the operation fails
|
|
361 |
*
|
|
362 |
* @return the number of glyph indices in the output glyph index array
|
|
363 |
*
|
|
364 |
* @internal
|
|
365 |
*/
|
3935
|
366 |
virtual le_int32 glyphPostProcessing(LEGlyphStorage &tempGlyphStorage, LEGlyphStorage &glyphStorage, LEErrorCode &success);
|
2
|
367 |
|
|
368 |
/**
|
|
369 |
* This method applies the characterProcessing, glyphProcessing and glyphPostProcessing
|
|
370 |
* methods. Most subclasses will not need to override this method.
|
|
371 |
*
|
|
372 |
* Input parameters:
|
|
373 |
* @param chars - the input character context
|
|
374 |
* @param offset - the index of the first character to process
|
|
375 |
* @param count - the number of characters to process
|
|
376 |
* @param max - the number of characters in the input context
|
|
377 |
* @param rightToLeft - TRUE if the text is in a right to left directional run
|
|
378 |
*
|
|
379 |
* Output parameters:
|
|
380 |
* @param glyphs - the glyph index array
|
|
381 |
* @param charIndices - the character index array
|
|
382 |
* @param success - set to an error code if the operation fails
|
|
383 |
*
|
|
384 |
* @return the number of glyphs in the glyph index array
|
|
385 |
*
|
|
386 |
* @see LayoutEngine::computeGlyphs
|
|
387 |
*
|
|
388 |
* @internal
|
|
389 |
*/
|
3935
|
390 |
virtual le_int32 computeGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft, LEGlyphStorage &glyphStorage, LEErrorCode &success);
|
2
|
391 |
|
|
392 |
/**
|
|
393 |
* This method uses the GPOS table, if there is one, to adjust the glyph positions.
|
|
394 |
*
|
|
395 |
* Input parameters:
|
|
396 |
* @param glyphs - the input glyph array
|
|
397 |
* @param glyphCount - the number of glyphs in the glyph array
|
|
398 |
* @param x - the starting X position
|
|
399 |
* @param y - the starting Y position
|
|
400 |
*
|
|
401 |
* Output parameters:
|
|
402 |
* @param positions - the output X and Y positions (two entries per glyph)
|
|
403 |
* @param success - set to an error code if the operation fails
|
|
404 |
*
|
|
405 |
* @internal
|
|
406 |
*/
|
3935
|
407 |
virtual void adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, LEGlyphStorage &glyphStorage, LEErrorCode &success);
|
2
|
408 |
|
|
409 |
/**
|
|
410 |
* This method frees the feature tag array so that the
|
|
411 |
* OpenTypeLayoutEngine can be reused for different text.
|
|
412 |
* It is also called from our destructor.
|
|
413 |
*
|
|
414 |
* @internal
|
|
415 |
*/
|
|
416 |
virtual void reset();
|
|
417 |
};
|
|
418 |
|
3935
|
419 |
U_NAMESPACE_END
|
2
|
420 |
#endif
|
3935
|
421 |
|