annotate src/share/native/sun/font/layout/OpenTypeLayoutEngine.h @ 5725:6784c9903db7

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