os/textandloc/fontservices/textshaperplugin/IcuSource/layout/IndicReordering.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/layout/IndicReordering.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,376 @@
     1.4 +/*
     1.5 + *
     1.6 + * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
     1.7 + *
     1.8 + */
     1.9 +
    1.10 +#ifndef __INDICREORDERING_H
    1.11 +#define __INDICREORDERING_H
    1.12 +
    1.13 +/**
    1.14 + * \file
    1.15 + * \internal
    1.16 + */
    1.17 +
    1.18 +#include "LETypes.h"
    1.19 +#include "OpenTypeTables.h"
    1.20 +
    1.21 +U_NAMESPACE_BEGIN
    1.22 +
    1.23 +// Characters that get refered to by name...
    1.24 +#define C_SIGN_ZWNJ           0x200C
    1.25 +#define C_SIGN_ZWJ            0x200D
    1.26 +
    1.27 +// Character class values
    1.28 +#define CC_RESERVED               		0U
    1.29 +#define CC_VOWEL_MODIFIER         		1U
    1.30 +#define CC_STRESS_MARK            		2U
    1.31 +#define CC_INDEPENDENT_VOWEL      		3U
    1.32 +#define CC_INDEPENDENT_VOWEL_2    		4U
    1.33 +#define CC_CONSONANT              		5U
    1.34 +#define CC_CONSONANT_WITH_NUKTA   		6U
    1.35 +#define CC_NUKTA                  		7U
    1.36 +#define CC_DEPENDENT_VOWEL        		8U
    1.37 +#define CC_SPLIT_VOWEL_PIECE_1    		9U
    1.38 +#define CC_SPLIT_VOWEL_PIECE_2   		10U
    1.39 +#define CC_SPLIT_VOWEL_PIECE_3   		11U
    1.40 +#define CC_VIRAMA                		12U
    1.41 +#define CC_ZERO_WIDTH_MARK       		13U
    1.42 +// Added by Nokia -- special case
    1.43 +#define CC_INDEPENDENT_VOWEL_A			14U
    1.44 +// Added by Nokia -- special case with independent vowel A
    1.45 +#define CC_DEPENDENT_VOWEL_CANDRA_E		15U
    1.46 +// Added by Nokia -- special case for Kannada Ra
    1.47 +#define CC_CONSONANT_KANNADA_BENGALI_RA	16U
    1.48 +// Added by Nokia -- special case for Tamil independent vowel O
    1.49 +#define CC_INDEPENDENT_VOWEL_TAMIL_O	17U
    1.50 +
    1.51 +// Added by Nokia -- special case for Gurmukhi Bearer ARA and independent A 
    1.52 +#define CC_GUR_BEARER_A					18U
    1.53 +// Added by Nokia -- special case for Gurmukhi Bearer IRI 
    1.54 +#define CC_GUR_BEARER_I					19U
    1.55 +// Added by Nokia -- special case for Gurmukhi Bearer URA
    1.56 +#define CC_GUR_BEARER_U					20U
    1.57 +
    1.58 +// Added by Nokia -- special case for Gurmukhi dependent Vowel which can combine with Bearer ARA
    1.59 +#define CC_GUR_DEPENDENT_VOWEL_A		21U
    1.60 +// Added by Nokia -- special case for Gurmukhi dependent Vowel which can combine with Bearer IRI
    1.61 +#define CC_GUR_DEPENDENT_VOWEL_I		22U
    1.62 +// Added by Nokia -- special case for Gurmukhi dependent Vowel which can combine with Bearer URA
    1.63 +#define CC_GUR_DEPENDENT_VOWEL_U		23U
    1.64 +
    1.65 +#define CC_COUNT                 		24U
    1.66 +
    1.67 +// Character class flags
    1.68 +#define CF_CLASS_MASK    0x0000FFFFU
    1.69 +
    1.70 +#define CF_CONSONANT     0x80000000U
    1.71 +
    1.72 +#define CF_REPH          0x40000000U
    1.73 +#define CF_VATTU         0x20000000U
    1.74 +#define CF_BELOW_BASE    0x10000000U
    1.75 +#define CF_POST_BASE     0x08000000U
    1.76 +#define CF_LENGTH_MARK   0x04000000U
    1.77 +// Added by Nokia -- special case for Bengali Ya
    1.78 +#define CF_CONSONANT_BENGALI_YA			0x00800000U
    1.79 +
    1.80 +// Added by Nokia -- 1922 Malayalam Chillu -->
    1.81 +#define CF_CONSONANT_MLYL_CHILLU      0x00400000U
    1.82 +#define CC_DEPENDENT_VOWEL_SIGN_MLYL_E 0xD46U
    1.83 +#define CC_CONSONANT_MLYL_YA 0xD2FU
    1.84 +#define CC_CONSONANT_MLYL_VA 0xD35U
    1.85 +#define CC_CONSONANT_MLYL_RA 0xD30U
    1.86 +#define CC_CONSONANT_MLYL_RRA 0xD31U
    1.87 +#define CC_CONSONANT_MLYL_LLA 0xD33U
    1.88 +#define CC_CONSONANT_MLYL_LLLA 0xD34U
    1.89 +// <-- 1922 mlyl
    1.90 +
    1.91 +#define CF_POS_BEFORE    0x00300000U
    1.92 +#define CF_POS_BELOW     0x00200000U
    1.93 +#define CF_POS_ABOVE     0x00100000U
    1.94 +#define CF_POS_AFTER     0x00000000U
    1.95 +#define CF_POS_MASK      0x00300000U
    1.96 +
    1.97 +#define CF_INDEX_MASK    0x000F0000U
    1.98 +#define CF_INDEX_SHIFT   16
    1.99 +
   1.100 +// Script flag bits
   1.101 +#define SF_MATRAS_AFTER_BASE     0x80000000U
   1.102 +#define SF_REPH_AFTER_BELOW      0x40000000U
   1.103 +#define SF_EYELASH_RA            0x20000000U
   1.104 +#define SF_MPRE_FIXUP            0x10000000U
   1.105 +//Added by Nokia for matra combined with final form of YA in Gurmukhi
   1.106 +//Flags SF_MATRAS_AFTER_BASE and SF_MATRAS_AFTER_POSTBASE cannot coexist.
   1.107 +//with SF_MATRAS_AFTER_BASE setting: Mbelow, Mabove and Mpost are attached to base consonant.
   1.108 +//With SF_MATRAS_AFTER_AFTERBASE setting: Mbelow, Mabove and Mpost are attached to postbase consonant
   1.109 +//without SF_MATRAS_AFTER_BASE or SF_MATRAS_AFTER_AFTERBASE setting: Mbelow, Mabove are attached to
   1.110 +//base (or base+below-base consonant cluster), but Mpost attached to postbase
   1.111 +#define SF_MATRAS_AFTER_POSTBASE		 0x08000000U
   1.112 +
   1.113 +#define SF_POST_BASE_LIMIT_MASK  0x0000FFFFU
   1.114 +#define SF_NO_POST_BASE_LIMIT    0x00007FFFU
   1.115 +
   1.116 +typedef LEUnicode SplitMatra[3];
   1.117 +
   1.118 +class MPreFixups;
   1.119 +class LEGlyphStorage;
   1.120 +
   1.121 +struct IndicClassTable
   1.122 +{
   1.123 +    typedef le_uint32 CharClass;
   1.124 +    typedef le_uint32 ScriptFlags;
   1.125 +
   1.126 +    LEUnicode firstChar;
   1.127 +    LEUnicode lastChar;
   1.128 +    le_int32 worstCaseExpansion;
   1.129 +    ScriptFlags scriptFlags;
   1.130 +    const CharClass *classTable;
   1.131 +    const SplitMatra *splitMatraTable;
   1.132 +
   1.133 +    inline le_int32 getWorstCaseExpansion() const;
   1.134 +
   1.135 +    CharClass getCharClass(LEUnicode ch) const;
   1.136 +
   1.137 +    inline const SplitMatra *getSplitMatra(CharClass charClass) const;
   1.138 +
   1.139 +    inline le_bool isVowelModifier(LEUnicode ch) const;
   1.140 +    inline le_bool isStressMark(LEUnicode ch) const;
   1.141 +    inline le_bool isConsonant(LEUnicode ch) const;
   1.142 +    inline le_bool isReph(LEUnicode ch) const;
   1.143 +    inline le_bool isVirama(LEUnicode ch) const;
   1.144 +    inline le_bool isNukta(LEUnicode ch) const;
   1.145 +    inline le_bool isVattu(LEUnicode ch) const;
   1.146 +    inline le_bool isMatra(LEUnicode ch) const;
   1.147 +    inline le_bool isSplitMatra(LEUnicode ch) const;
   1.148 +    inline le_bool isLengthMark(LEUnicode ch) const;
   1.149 +    inline le_bool hasPostOrBelowBaseForm(LEUnicode ch) const;
   1.150 +    inline le_bool hasPostBaseForm(LEUnicode ch) const;
   1.151 +    inline le_bool hasBelowBaseForm(LEUnicode ch) const;
   1.152 +    // Added by Nokia: For special case Bengali Ya
   1.153 +    inline le_bool isBengaliYa(LEUnicode ch) const;
   1.154 +    // Added by Nokia -- 1922 mlyl -->
   1.155 +    inline le_bool isMlylChillu(LEUnicode ch) const;
   1.156 +    // <-- 1922 mlyl
   1.157 +    
   1.158 +    inline static le_bool isVowelModifier(CharClass charClass);
   1.159 +    inline static le_bool isStressMark(CharClass charClass);
   1.160 +    inline static le_bool isConsonant(CharClass charClass);
   1.161 +    inline static le_bool isReph(CharClass charClass);
   1.162 +    inline static le_bool isVirama(CharClass charClass);
   1.163 +    inline static le_bool isNukta(CharClass charClass);
   1.164 +    inline static le_bool isVattu(CharClass charClass);
   1.165 +    inline static le_bool isMatra(CharClass charClass);
   1.166 +    inline static le_bool isSplitMatra(CharClass charClass);
   1.167 +    inline static le_bool isLengthMark(CharClass charClass);
   1.168 +    inline static le_bool hasPostOrBelowBaseForm(CharClass charClass);
   1.169 +    inline static le_bool hasPostBaseForm(CharClass charClass);
   1.170 +    inline static le_bool hasBelowBaseForm(CharClass charClass);
   1.171 +    // Added by Nokia: For special case Bengali Ya
   1.172 +    inline static le_bool isBengaliYa(CharClass charClass);
   1.173 +    // Added by Nokia -- 1922 mlyl -->
   1.174 +    inline static le_bool isMlylChillu(CharClass charClass);
   1.175 +    // <-- 1922 mlyl
   1.176 +    
   1.177 +    static const IndicClassTable *getScriptClassTable(le_int32 scriptCode);
   1.178 +};
   1.179 +
   1.180 +class IndicReordering /* not : public UObject because all methods are static */ {
   1.181 +public:
   1.182 +    static le_int32 getWorstCaseExpansion(le_int32 scriptCode);
   1.183 +
   1.184 +    static le_int32 reorder(const LEUnicode *theChars, le_int32 charCount, le_int32 scriptCode,
   1.185 +        LEUnicode *outChars, LEGlyphStorage &glyphStorage,
   1.186 +        MPreFixups **outMPreFixups, LEErrorCode& success);
   1.187 +
   1.188 +    static void adjustMPres(MPreFixups *mpreFixups, LEGlyphStorage &glyphStorage,
   1.189 +        LEErrorCode& success);
   1.190 +
   1.191 +    static const LETag *getFeatureOrder();
   1.192 +
   1.193 +private:
   1.194 +    // do not instantiate
   1.195 +    IndicReordering();
   1.196 +
   1.197 +    static le_int32 findSyllable(const IndicClassTable *classTable, const LEUnicode *chars, le_int32 prev, le_int32 charCount);
   1.198 +
   1.199 +};
   1.200 +
   1.201 +inline le_int32 IndicClassTable::getWorstCaseExpansion() const
   1.202 +{
   1.203 +    return worstCaseExpansion;
   1.204 +}
   1.205 +
   1.206 +inline const SplitMatra *IndicClassTable::getSplitMatra(CharClass charClass) const
   1.207 +{
   1.208 +    le_int32 index = (charClass & CF_INDEX_MASK) >> CF_INDEX_SHIFT;
   1.209 +
   1.210 +    return &splitMatraTable[index - 1];
   1.211 +}
   1.212 +
   1.213 +inline le_bool IndicClassTable::isVowelModifier(CharClass charClass)
   1.214 +{
   1.215 +    return (charClass & CF_CLASS_MASK) == CC_VOWEL_MODIFIER;
   1.216 +}
   1.217 +
   1.218 +inline le_bool IndicClassTable::isStressMark(CharClass charClass)
   1.219 +{
   1.220 +    return (charClass & CF_CLASS_MASK) == CC_STRESS_MARK;
   1.221 +}
   1.222 +
   1.223 +inline le_bool IndicClassTable::isConsonant(CharClass charClass)
   1.224 +{
   1.225 +    return (charClass & CF_CONSONANT) != 0;
   1.226 +}
   1.227 +
   1.228 +inline le_bool IndicClassTable::isReph(CharClass charClass)
   1.229 +{
   1.230 +    return (charClass & CF_REPH) != 0;
   1.231 +}
   1.232 +
   1.233 +inline le_bool IndicClassTable::isNukta(CharClass charClass)
   1.234 +{
   1.235 +    return (charClass & CF_CLASS_MASK) == CC_NUKTA;
   1.236 +}
   1.237 +
   1.238 +inline le_bool IndicClassTable::isVirama(CharClass charClass)
   1.239 +{
   1.240 +    return (charClass & CF_CLASS_MASK) == CC_VIRAMA;
   1.241 +}
   1.242 +
   1.243 +inline le_bool IndicClassTable::isVattu(CharClass charClass)
   1.244 +{
   1.245 +    return (charClass & CF_VATTU) != 0;
   1.246 +}
   1.247 +
   1.248 +inline le_bool IndicClassTable::isMatra(CharClass charClass)
   1.249 +{
   1.250 +    charClass &= CF_CLASS_MASK;
   1.251 +	
   1.252 +	// Added special CANDRA E char class check to enable formation of Devanagari CANDRA A
   1.253 +    // Added speical CC_GUR_DEPENDENT_VOWEL_* to support decompositions of the independent
   1.254 +    // vowels into a sequence of a vowel bearer and a depending vowel sign
   1.255 +    return charClass >= CC_DEPENDENT_VOWEL && charClass <= CC_SPLIT_VOWEL_PIECE_3
   1.256 +    	   || charClass == CC_DEPENDENT_VOWEL_CANDRA_E
   1.257 +    	   || charClass == CC_GUR_DEPENDENT_VOWEL_A
   1.258 +    	   || charClass == CC_GUR_DEPENDENT_VOWEL_I
   1.259 +    	   || charClass == CC_GUR_DEPENDENT_VOWEL_U;
   1.260 +}
   1.261 +
   1.262 +inline le_bool IndicClassTable::isSplitMatra(CharClass charClass)
   1.263 +{
   1.264 +    return (charClass & CF_INDEX_MASK) != 0;
   1.265 +}
   1.266 +
   1.267 +inline le_bool IndicClassTable::isLengthMark(CharClass charClass)
   1.268 +{
   1.269 +    return (charClass & CF_LENGTH_MARK) != 0;
   1.270 +}
   1.271 +
   1.272 +inline le_bool IndicClassTable::hasPostOrBelowBaseForm(CharClass charClass)
   1.273 +{
   1.274 +    return (charClass & (CF_POST_BASE | CF_BELOW_BASE)) != 0;
   1.275 +}
   1.276 +
   1.277 +inline le_bool IndicClassTable::hasPostBaseForm(CharClass charClass)
   1.278 +{
   1.279 +    return (charClass & CF_POST_BASE) != 0;
   1.280 +}
   1.281 +
   1.282 +inline le_bool IndicClassTable::hasBelowBaseForm(CharClass charClass)
   1.283 +{
   1.284 +    return (charClass & CF_BELOW_BASE) != 0;
   1.285 +}
   1.286 +
   1.287 +// Added by Nokia -- For determining whether a character is a Bengali Ya
   1.288 +inline le_bool IndicClassTable::isBengaliYa(CharClass charClass)
   1.289 +	{
   1.290 +	    return (charClass & CF_CONSONANT_BENGALI_YA) != 0;
   1.291 +	}
   1.292 +
   1.293 +// Added by Nokia -- 1922 mlyl -->
   1.294 +inline le_bool IndicClassTable::isMlylChillu(CharClass charClass)
   1.295 +{
   1.296 +    return (charClass & CF_CONSONANT_MLYL_CHILLU) != 0;
   1.297 +}
   1.298 +// <-- 1922 mlyl
   1.299 +
   1.300 +inline le_bool IndicClassTable::isVowelModifier(LEUnicode ch) const
   1.301 +{
   1.302 +    return isVowelModifier(getCharClass(ch));
   1.303 +}
   1.304 +
   1.305 +inline le_bool IndicClassTable::isStressMark(LEUnicode ch) const
   1.306 +{
   1.307 +    return isStressMark(getCharClass(ch));
   1.308 +}
   1.309 +
   1.310 +inline le_bool IndicClassTable::isConsonant(LEUnicode ch) const
   1.311 +{
   1.312 +    return isConsonant(getCharClass(ch));
   1.313 +}
   1.314 +
   1.315 +inline le_bool IndicClassTable::isReph(LEUnicode ch) const
   1.316 +{
   1.317 +    return isReph(getCharClass(ch));
   1.318 +}
   1.319 +
   1.320 +inline le_bool IndicClassTable::isVirama(LEUnicode ch) const
   1.321 +{
   1.322 +    return isVirama(getCharClass(ch));
   1.323 +}
   1.324 +
   1.325 +inline le_bool IndicClassTable::isNukta(LEUnicode ch) const
   1.326 +{
   1.327 +    return isNukta(getCharClass(ch));
   1.328 +}
   1.329 +
   1.330 +inline le_bool IndicClassTable::isVattu(LEUnicode ch) const
   1.331 +{
   1.332 +    return isVattu(getCharClass(ch));
   1.333 +}
   1.334 +
   1.335 +inline le_bool IndicClassTable::isMatra(LEUnicode ch) const
   1.336 +{
   1.337 +    return isMatra(getCharClass(ch));
   1.338 +}
   1.339 +
   1.340 +inline le_bool IndicClassTable::isSplitMatra(LEUnicode ch) const
   1.341 +{
   1.342 +    return isSplitMatra(getCharClass(ch));
   1.343 +}
   1.344 +
   1.345 +inline le_bool IndicClassTable::isLengthMark(LEUnicode ch) const
   1.346 +{
   1.347 +    return isLengthMark(getCharClass(ch));
   1.348 +}
   1.349 +
   1.350 +inline le_bool IndicClassTable::hasPostOrBelowBaseForm(LEUnicode ch) const
   1.351 +{
   1.352 +    return hasPostOrBelowBaseForm(getCharClass(ch));
   1.353 +}
   1.354 +
   1.355 +inline le_bool IndicClassTable::hasPostBaseForm(LEUnicode ch) const
   1.356 +{
   1.357 +    return hasPostBaseForm(getCharClass(ch));
   1.358 +}
   1.359 +
   1.360 +inline le_bool IndicClassTable::hasBelowBaseForm(LEUnicode ch) const
   1.361 +{
   1.362 +    return hasBelowBaseForm(getCharClass(ch));
   1.363 +}
   1.364 +
   1.365 +// Added by Nokia -- For determining whether a character is a Bengali Ya
   1.366 +inline le_bool IndicClassTable::isBengaliYa(LEUnicode ch) const
   1.367 +{
   1.368 +    return isBengaliYa(getCharClass(ch));
   1.369 +}
   1.370 +
   1.371 +// Added by Nokia -- 1922 mlyl -->
   1.372 +inline le_bool IndicClassTable::isMlylChillu(LEUnicode ch) const
   1.373 +{
   1.374 +    return isMlylChillu(getCharClass(ch));
   1.375 +}
   1.376 +// <-- 1922 mlyl
   1.377 +
   1.378 +U_NAMESPACE_END
   1.379 +#endif