Home | History | Annotate | Download | only in layout
      1 
      2 /*
      3  *
      4  * (C) Copyright IBM Corp. 1998-2008 - All Rights Reserved
      5  *
      6  */
      7 
      8 #ifndef __ARABICLAYOUTENGINE_H
      9 #define __ARABICLAYOUTENGINE_H
     10 
     11 #include "LETypes.h"
     12 #include "LEFontInstance.h"
     13 #include "LEGlyphFilter.h"
     14 #include "LayoutEngine.h"
     15 #include "OpenTypeLayoutEngine.h"
     16 
     17 #include "GlyphSubstitutionTables.h"
     18 #include "GlyphDefinitionTables.h"
     19 #include "GlyphPositioningTables.h"
     20 
     21 U_NAMESPACE_BEGIN
     22 
     23 /**
     24  * This class implements OpenType layout for Arabic fonts. It overrides
     25  * the characerProcessing method to assign the correct OpenType feature
     26  * tags for the Arabic contextual forms. It also overrides the adjustGlyphPositions
     27  * method to guarantee that all vowel and accent glyphs have zero advance width.
     28  *
     29  * @internal
     30  */
     31 class ArabicOpenTypeLayoutEngine : public OpenTypeLayoutEngine
     32 {
     33 public:
     34     /**
     35      * This is the main constructor. It constructs an instance of ArabicOpenTypeLayoutEngine for
     36      * a particular font, script and language. It takes the GSUB table as a parameter since
     37      * LayoutEngine::layoutEngineFactory has to read the GSUB table to know that it has an
     38      * Indic OpenType font.
     39      *
     40      * @param fontInstance - the font
     41      * @param scriptCode - the script
     42      * @param langaugeCode - the language
     43      * @param gsubTable - the GSUB table
     44      * @param success - set to an error code if the operation fails
     45      *
     46      * @see LayoutEngine::layoutEngineFactory
     47      * @see OpenTypeLayoutEngine
     48      * @see ScriptAndLanguageTags.h for script and language codes
     49      *
     50      * @internal
     51      */
     52     ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
     53                             le_int32 typoFlags, const GlyphSubstitutionTableHeader *gsubTable, LEErrorCode &success);
     54 
     55     /**
     56      * This constructor is used when the font requires a "canned" GSUB table which can't be known
     57      * until after this constructor has been invoked.
     58      *
     59      * @param fontInstance - the font
     60      * @param scriptCode - the script
     61      * @param langaugeCode - the language
     62      * @param success - set to an error code if the operation fails
     63      *
     64      * @see OpenTypeLayoutEngine
     65      * @see ScriptAndLanguageTags.h for script and language codes
     66      *
     67      * @internal
     68      */
     69     ArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
     70 			       le_int32 typoFlags, LEErrorCode &success);
     71 
     72     /**
     73      * The destructor, virtual for correct polymorphic invocation.
     74      *
     75      * @internal
     76      */
     77     virtual ~ArabicOpenTypeLayoutEngine();
     78 
     79     /**
     80      * ICU "poor man's RTTI", returns a UClassID for the actual class.
     81      *
     82      * @stable ICU 2.8
     83      */
     84     virtual UClassID getDynamicClassID() const;
     85 
     86     /**
     87      * ICU "poor man's RTTI", returns a UClassID for this class.
     88      *
     89      * @stable ICU 2.8
     90      */
     91     static UClassID getStaticClassID();
     92 
     93 protected:
     94 
     95     /**
     96      * This method does Arabic OpenType character processing. It assigns the OpenType feature
     97      * tags to the characters to generate the correct contextual forms and ligatures.
     98      *
     99      * Input parameters:
    100      * @param chars - the input character context
    101      * @param offset - the index of the first character to process
    102      * @param count - the number of characters to process
    103      * @param max - the number of characters in the input context
    104      * @param rightToLeft - <code>TRUE</code> if the characters are in a right to left directional run
    105      *
    106      * Output parameters:
    107      * @param outChars - the output character arrayt
    108      * @param charIndices - the output character index array
    109      * @param featureTags - the output feature tag array
    110      * @param success - set to an error code if the operation fails
    111      *
    112      * @return the output character count
    113      *
    114      * @internal
    115      */
    116     virtual le_int32 characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
    117             LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success);
    118 
    119     /**
    120      * This method applies the GPOS table if it is present, otherwise it ensures that all vowel
    121      * and accent glyphs have a zero advance width by calling the adjustMarkGlyphs method.
    122      * If the font contains a GDEF table, that is used to identify voewls and accents. Otherwise
    123      * the character codes are used.
    124      *
    125      * @param chars - the input character context
    126      * @param offset - the offset of the first character to process
    127      * @param count - the number of characters to process
    128      * @param reverse - <code>TRUE</code> if the glyphs in the glyph array have been reordered
    129      * @param glyphs - the input glyph array
    130      * @param glyphCount - the number of glyphs
    131      * @param positions - the position array, will be updated as needed
    132      * @param success - output parameter set to an error code if the operation fails
    133      *
    134      * @internal
    135      */
    136     virtual void adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, LEGlyphStorage &glyphStorage, LEErrorCode &success);
    137 
    138     // static void adjustMarkGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool rightToLeft, LEGlyphStorage &glyphStorage, LEErrorCode &success);
    139 
    140 };
    141 
    142 /**
    143  * The class implements OpenType layout for Arabic fonts which don't
    144  * contain a GSUB table, using a canned GSUB table based on Unicode
    145  * Arabic Presentation Forms. It overrides the mapCharsToGlyphs method
    146  * to use the Presentation Forms as logical glyph indices. It overrides the
    147  * glyphPostProcessing method to convert the Presentation Forms to actual
    148  * glyph indices.
    149  *
    150  * @see ArabicOpenTypeLayoutEngine
    151  *
    152  * @internal
    153  */
    154 class UnicodeArabicOpenTypeLayoutEngine : public ArabicOpenTypeLayoutEngine
    155 {
    156 public:
    157     /**
    158      * This constructs an instance of UnicodeArabicOpenTypeLayoutEngine for a specific font,
    159      * script and language.
    160      *
    161      * @param fontInstance - the font
    162      * @param scriptCode - the script
    163      * @param languageCode - the language
    164      * @param success - set to an error code if the operation fails
    165      *
    166      * @see LEFontInstance
    167      * @see ScriptAndLanguageTags.h for script and language codes
    168      *
    169      * @internal
    170      */
    171     UnicodeArabicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
    172 		le_int32 typoFlags, LEErrorCode &success);
    173 
    174     /**
    175      * The destructor, virtual for correct polymorphic invocation.
    176      *
    177      * @internal
    178      */
    179     virtual ~UnicodeArabicOpenTypeLayoutEngine();
    180 
    181 protected:
    182 
    183     /**
    184      * This method converts the Arabic Presentation Forms in the temp glyph array
    185      * into actual glyph indices using ArabicOpenTypeLayoutEngine::mapCharsToGlyps.
    186      *
    187      * Input paramters:
    188      * @param tempGlyphs - the input presentation forms
    189      * @param tempCharIndices - the input character index array
    190      * @param tempGlyphCount - the number of Presentation Froms
    191      *
    192      * Output parameters:
    193      * @param glyphs - the output glyph index array
    194      * @param charIndices - the output character index array
    195      * @param success - set to an error code if the operation fails
    196      *
    197      * @return the number of glyph indices in the output glyph index array
    198      *
    199      * @internal
    200      */
    201     virtual le_int32 glyphPostProcessing(LEGlyphStorage &tempGlyphStorage, LEGlyphStorage &glyphStorage, LEErrorCode &success);
    202 
    203     /**
    204      * This method copies the input characters into the output glyph index array,
    205      * for use by the canned GSUB table. It also generates the character index array.
    206      *
    207      * Input parameters:
    208      * @param chars - the input character context
    209      * @param offset - the offset of the first character to be mapped
    210      * @param count - the number of characters to be mapped
    211      * @param reverse - if <code>TRUE</code>, the output will be in reverse order
    212      * @param mirror - if <code>TRUE</code>, do character mirroring
    213      * @param glyphStorage - the glyph storage object. Glyph and char index arrays will be updated.
    214      *
    215      * @param success - set to an error code if the operation fails
    216      *
    217      * @internal
    218      */
    219     virtual void mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, le_bool mirror,
    220         LEGlyphStorage &glyphStorage, LEErrorCode &success);
    221 
    222     /**
    223      * This method ensures that all vowel and accent glyphs have a zero advance width by calling
    224      * the adjustMarkGlyphs method. The character codes are used to identify the vowel and mark
    225      * glyphs.
    226      *
    227      * @param chars - the input character context
    228      * @param offset - the offset of the first character to process
    229      * @param count - the number of characters to process
    230      * @param reverse - <code>TRUE</code> if the glyphs in the glyph array have been reordered
    231      * @param glyphStorage - the glyph storage object. The glyph positions will be updated as needed.
    232      * @param success - output parameter set to an error code if the operation fails
    233      *
    234      * @internal
    235      */
    236     virtual void adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, LEGlyphStorage &glyphStorage, LEErrorCode &success);
    237 };
    238 
    239 U_NAMESPACE_END
    240 #endif
    241 
    242