X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..ef6cf650f4a75c3f97de06b51fa104f2069b9ea2:/icuSources/layout/IndicReordering.cpp diff --git a/icuSources/layout/IndicReordering.cpp b/icuSources/layout/IndicReordering.cpp index b2c11a2f..1ebc94a6 100644 --- a/icuSources/layout/IndicReordering.cpp +++ b/icuSources/layout/IndicReordering.cpp @@ -1,6 +1,6 @@ /* - * - * (C) Copyright IBM Corp. 1998-2008 - All Rights Reserved +/ * + * (C) Copyright IBM Corp. 1998-2015 - All Rights Reserved * */ @@ -18,6 +18,7 @@ U_NAMESPACE_BEGIN #define nuktFeatureTag LE_NUKT_FEATURE_TAG #define akhnFeatureTag LE_AKHN_FEATURE_TAG #define rphfFeatureTag LE_RPHF_FEATURE_TAG +#define rkrfFeatureTag LE_RKRF_FEATURE_TAG #define blwfFeatureTag LE_BLWF_FEATURE_TAG #define halfFeatureTag LE_HALF_FEATURE_TAG #define pstfFeatureTag LE_PSTF_FEATURE_TAG @@ -27,10 +28,12 @@ U_NAMESPACE_BEGIN #define abvsFeatureTag LE_ABVS_FEATURE_TAG #define pstsFeatureTag LE_PSTS_FEATURE_TAG #define halnFeatureTag LE_HALN_FEATURE_TAG - +#define cjctFeatureTag LE_CJCT_FEATURE_TAG #define blwmFeatureTag LE_BLWM_FEATURE_TAG #define abvmFeatureTag LE_ABVM_FEATURE_TAG #define distFeatureTag LE_DIST_FEATURE_TAG +#define caltFeatureTag LE_CALT_FEATURE_TAG +#define kernFeatureTag LE_KERN_FEATURE_TAG #define loclFeatureMask 0x80000000UL #define rphfFeatureMask 0x40000000UL @@ -43,12 +46,47 @@ U_NAMESPACE_BEGIN #define presFeatureMask 0x00800000UL #define blwsFeatureMask 0x00400000UL #define abvsFeatureMask 0x00200000UL -#define pstsFeatureMask 0x00100000UL +#define pstsFeatureMask 0x00100000UL #define halnFeatureMask 0x00080000UL #define blwmFeatureMask 0x00040000UL #define abvmFeatureMask 0x00020000UL #define distFeatureMask 0x00010000UL #define initFeatureMask 0x00008000UL +#define cjctFeatureMask 0x00004000UL +#define rkrfFeatureMask 0x00002000UL +#define caltFeatureMask 0x00001000UL +#define kernFeatureMask 0x00000800UL + +// Syllable structure bits +#define baseConsonantMask 0x00000400UL +#define consonantMask 0x00000200UL +#define halfConsonantMask 0x00000100UL +#define rephConsonantMask 0x00000080UL +#define matraMask 0x00000040UL +#define vowelModifierMask 0x00000020UL +#define markPositionMask 0x00000018UL + +#define postBasePosition 0x00000000UL +#define preBasePosition 0x00000008UL +#define aboveBasePosition 0x00000010UL +#define belowBasePosition 0x00000018UL + +#define repositionedGlyphMask 0x00000002UL + +#define basicShapingFormsMask ( loclFeatureMask | nuktFeatureMask | akhnFeatureMask | rkrfFeatureMask | blwfFeatureMask | halfFeatureMask | vatuFeatureMask | cjctFeatureMask ) +#define positioningFormsMask ( kernFeatureMask | distFeatureMask | abvmFeatureMask | blwmFeatureMask ) +#define presentationFormsMask ( presFeatureMask | abvsFeatureMask | blwsFeatureMask | pstsFeatureMask | halnFeatureMask | caltFeatureMask ) + + +#define C_MALAYALAM_VOWEL_SIGN_U 0x0D41 +#define C_DOTTED_CIRCLE 0x25CC +#define NO_GLYPH 0xFFFF + +// Some level of debate as to the proper value for MAX_CONSONANTS_PER_SYLLABLE. Ticket 5588 states that 4 +// is the magic number according to ISCII, but 5 seems to be the more consistent with XP. +#define MAX_CONSONANTS_PER_SYLLABLE 5 + +#define INDIC_BLOCK_SIZE 0x7F class IndicReorderingOutput : public UMemory { private: @@ -91,6 +129,11 @@ private: le_int32 fSMIndex; FeatureMask fSMFeatures; + LEUnicode fPreBaseConsonant; + LEUnicode fPreBaseVirama; + le_int32 fPBCIndex; + FeatureMask fPBCFeatures; + void saveMatra(LEUnicode matra, le_int32 matraIndex, IndicClassTable::CharClass matraClass) { // FIXME: check if already set, or if not a matra... @@ -136,7 +179,8 @@ public: fMpost(0), fMpostIndex(0), fLengthMark(0), fLengthMarkIndex(0), fAlLakuna(0), fAlLakunaIndex(0), fMatraFeatures(0), fMPreOutIndex(-1), fMPreFixups(mpreFixups), fVMabove(0), fVMpost(0), fVMIndex(0), fVMFeatures(0), - fSMabove(0), fSMbelow(0), fSMIndex(0), fSMFeatures(0) + fSMabove(0), fSMbelow(0), fSMIndex(0), fSMFeatures(0), + fPreBaseConsonant(0), fPreBaseVirama(0), fPBCIndex(0), fPBCFeatures(0) { // nothing else to do... } @@ -155,6 +199,8 @@ public: fVMabove = fVMpost = 0; fSMabove = fSMbelow = 0; + + fPreBaseConsonant = fPreBaseVirama = 0; } void writeChar(LEUnicode ch, le_uint32 charIndex, FeatureMask charFeatures) @@ -169,6 +215,108 @@ public: fOutIndex += 1; } + void setFeatures ( le_uint32 charIndex, FeatureMask charFeatures) + { + LEErrorCode success = LE_NO_ERROR; + + fGlyphStorage.setAuxData( charIndex, charFeatures, success ); + + } + + FeatureMask getFeatures ( le_uint32 charIndex ) + { + LEErrorCode success = LE_NO_ERROR; + return fGlyphStorage.getAuxData(charIndex,success); + } + + void decomposeReorderMatras ( const IndicClassTable *classTable, le_int32 beginSyllable, le_int32 nextSyllable, le_int32 inv_count ) { + le_int32 i; + LEErrorCode success = LE_NO_ERROR; + + for ( i = beginSyllable ; i < nextSyllable ; i++ ) { + if ( classTable->isMatra(fOutChars[i+inv_count])) { + IndicClassTable::CharClass matraClass = classTable->getCharClass(fOutChars[i+inv_count]); + if ( classTable->isSplitMatra(matraClass)) { + le_int32 saveIndex = fGlyphStorage.getCharIndex(i+inv_count,success); + le_uint32 saveAuxData = fGlyphStorage.getAuxData(i+inv_count,success); + const SplitMatra *splitMatra = classTable->getSplitMatra(matraClass); + int j; + for (j = 0 ; j < SM_MAX_PIECES && *(splitMatra)[j] != 0 ; j++) { + LEUnicode piece = (*splitMatra)[j]; + if ( j == 0 ) { + fOutChars[i+inv_count] = piece; + matraClass = classTable->getCharClass(piece); + } else { + insertCharacter(piece,i+1+inv_count,saveIndex,saveAuxData); + nextSyllable++; + } + } + } + + if ((matraClass & CF_POS_MASK) == CF_POS_BEFORE) { + moveCharacter(i+inv_count,beginSyllable+inv_count); + } + } + } + } + + void moveCharacter( le_int32 fromPosition, le_int32 toPosition ) { + le_int32 i,saveIndex; + le_uint32 saveAuxData; + LEUnicode saveChar = fOutChars[fromPosition]; + LEErrorCode success = LE_NO_ERROR; + LEErrorCode success2 = LE_NO_ERROR; + saveIndex = fGlyphStorage.getCharIndex(fromPosition,success); + saveAuxData = fGlyphStorage.getAuxData(fromPosition,success); + + if ( fromPosition > toPosition ) { + for ( i = fromPosition ; i > toPosition ; i-- ) { + fOutChars[i] = fOutChars[i-1]; + fGlyphStorage.setCharIndex(i,fGlyphStorage.getCharIndex(i-1,success2),success); + fGlyphStorage.setAuxData(i,fGlyphStorage.getAuxData(i-1,success2), success); + + } + } else { + for ( i = fromPosition ; i < toPosition ; i++ ) { + fOutChars[i] = fOutChars[i+1]; + fGlyphStorage.setCharIndex(i,fGlyphStorage.getCharIndex(i+1,success2),success); + fGlyphStorage.setAuxData(i,fGlyphStorage.getAuxData(i+1,success2), success); + } + + } + fOutChars[toPosition] = saveChar; + fGlyphStorage.setCharIndex(toPosition,saveIndex,success); + fGlyphStorage.setAuxData(toPosition,saveAuxData,success); + + } + void insertCharacter( LEUnicode ch, le_int32 toPosition, le_int32 charIndex, le_uint32 auxData ) { + LEErrorCode success = LE_NO_ERROR; + le_int32 i; + fOutIndex += 1; + + for ( i = fOutIndex ; i > toPosition ; i--) { + fOutChars[i] = fOutChars[i-1]; + fGlyphStorage.setCharIndex(i,fGlyphStorage.getCharIndex(i-1,success),success); + fGlyphStorage.setAuxData(i,fGlyphStorage.getAuxData(i-1,success), success); + } + + fOutChars[toPosition] = ch; + fGlyphStorage.setCharIndex(toPosition,charIndex,success); + fGlyphStorage.setAuxData(toPosition,auxData,success); + + } + void removeCharacter( le_int32 fromPosition ) { + LEErrorCode success = LE_NO_ERROR; + le_int32 i; + fOutIndex -= 1; + + for ( i = fromPosition ; i < fOutIndex ; i--) { + fOutChars[i] = fOutChars[i+1]; + fGlyphStorage.setCharIndex(i,fGlyphStorage.getCharIndex(i+1,success),success); + fGlyphStorage.setAuxData(i,fGlyphStorage.getAuxData(i+1,success), success); + } + } + le_bool noteMatra(const IndicClassTable *classTable, LEUnicode matra, le_uint32 matraIndex, FeatureMask matraFeatures, le_bool wordStart) { IndicClassTable::CharClass matraClass = classTable->getCharClass(matra); @@ -184,7 +332,7 @@ public: const SplitMatra *splitMatra = classTable->getSplitMatra(matraClass); int i; - for (i = 0; i < 3 && (*splitMatra)[i] != 0; i += 1) { + for (i = 0; i < SM_MAX_PIECES && (*splitMatra)[i] != 0; i += 1) { LEUnicode piece = (*splitMatra)[i]; IndicClassTable::CharClass pieceClass = classTable->getCharClass(piece); @@ -248,6 +396,14 @@ public: } } + void notePreBaseConsonant(le_uint32 index,LEUnicode PBConsonant, LEUnicode PBVirama, FeatureMask features) + { + fPBCIndex = index; + fPreBaseConsonant = PBConsonant; + fPreBaseVirama = PBVirama; + fPBCFeatures = features; + } + void noteBaseConsonant() { if (fMPreFixups != NULL && fMPreOutIndex >= 0) { @@ -327,17 +483,29 @@ public: } } + void writePreBaseConsonant() + { + // The TDIL spec says that consonant + virama + RRA should produce a rakar in Malayalam. However, + // it seems that almost none of the fonts for Malayalam are set up to handle this. + // So, we're going to force the issue here by using the rakar as defined with RA in most fonts. + + if (fPreBaseConsonant == 0x0d31) { // RRA + fPreBaseConsonant = 0x0d30; // RA + } + + if (fPreBaseConsonant != 0) { + writeChar(fPreBaseConsonant, fPBCIndex, fPBCFeatures); + writeChar(fPreBaseVirama,fPBCIndex-1,fPBCFeatures); + } + } + le_int32 getOutputIndex() { return fOutIndex; } }; -enum -{ - C_MALAYALAM_VOWEL_SIGN_U = 0x0D41, - C_DOTTED_CIRCLE = 0x25CC -}; + // TODO: Find better names for these! #define tagArray4 (loclFeatureMask | nuktFeatureMask | akhnFeatureMask | vatuFeatureMask | presFeatureMask | blwsFeatureMask | abvsFeatureMask | pstsFeatureMask | halnFeatureMask | blwmFeatureMask | abvmFeatureMask | distFeatureMask) @@ -346,8 +514,7 @@ enum #define tagArray1 (blwfFeatureMask | tagArray2) #define tagArray0 (rphfFeatureMask | tagArray1) -static const FeatureMap featureMap[] = -{ +static const FeatureMap featureMap[] = { {loclFeatureTag, loclFeatureMask}, {initFeatureTag, initFeatureMask}, {nuktFeatureTag, nuktFeatureMask}, @@ -369,6 +536,30 @@ static const FeatureMap featureMap[] = static const le_int32 featureCount = LE_ARRAY_SIZE(featureMap); +static const FeatureMap v2FeatureMap[] = { + {loclFeatureTag, loclFeatureMask}, + {nuktFeatureTag, nuktFeatureMask}, + {akhnFeatureTag, akhnFeatureMask}, + {rphfFeatureTag, rphfFeatureMask}, + {rkrfFeatureTag, rkrfFeatureMask}, + {blwfFeatureTag, blwfFeatureMask}, + {halfFeatureTag, halfFeatureMask}, + {vatuFeatureTag, vatuFeatureMask}, + {cjctFeatureTag, cjctFeatureMask}, + {presFeatureTag, presFeatureMask}, + {abvsFeatureTag, abvsFeatureMask}, + {blwsFeatureTag, blwsFeatureMask}, + {pstsFeatureTag, pstsFeatureMask}, + {halnFeatureTag, halnFeatureMask}, + {caltFeatureTag, caltFeatureMask}, + {kernFeatureTag, kernFeatureMask}, + {distFeatureTag, distFeatureMask}, + {abvmFeatureTag, abvmFeatureMask}, + {blwmFeatureTag, blwmFeatureMask} +}; + +static const le_int32 v2FeatureMapCount = LE_ARRAY_SIZE(v2FeatureMap); + static const le_int8 stateTable[][CC_COUNT] = { // xx vm sm iv i2 i3 ct cn nu dv s1 s2 s3 vr zw al @@ -396,13 +587,28 @@ const FeatureMap *IndicReordering::getFeatureMap(le_int32 &count) return featureMap; } +const FeatureMap *IndicReordering::getv2FeatureMap(le_int32 &count) +{ + count = v2FeatureMapCount; + + return v2FeatureMap; +} + le_int32 IndicReordering::findSyllable(const IndicClassTable *classTable, const LEUnicode *chars, le_int32 prev, le_int32 charCount) { le_int32 cursor = prev; le_int8 state = 0; + le_int8 consonant_count = 0; while (cursor < charCount) { IndicClassTable::CharClass charClass = classTable->getCharClass(chars[cursor]); + + if ( IndicClassTable::isConsonant(charClass) ) { + consonant_count++; + if ( consonant_count > MAX_CONSONANTS_PER_SYLLABLE ) { + break; + } + } state = stateTable[state][charClass & CF_CLASS_MASK]; @@ -418,13 +624,26 @@ le_int32 IndicReordering::findSyllable(const IndicClassTable *classTable, const le_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le_int32 scriptCode, LEUnicode *outChars, LEGlyphStorage &glyphStorage, - MPreFixups **outMPreFixups) + MPreFixups **outMPreFixups, LEErrorCode& success) { + if (LE_FAILURE(success)) { + return 0; + } + MPreFixups *mpreFixups = NULL; const IndicClassTable *classTable = IndicClassTable::getScriptClassTable(scriptCode); + if (classTable==NULL) { + success = LE_INTERNAL_ERROR; + return 0; + } + if (classTable->scriptFlags & SF_MPRE_FIXUP) { mpreFixups = new MPreFixups(charCount); + if (mpreFixups == NULL) { + success = LE_MEMORY_ALLOCATION_ERROR; + return 0; + } } IndicReorderingOutput output(outChars, glyphStorage, mpreFixups); @@ -533,7 +752,7 @@ le_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le le_int32 baseLimit = prev; // Check for REPH at front of syllable - if (length > 2 && classTable->isReph(chars[prev]) && classTable->isVirama(chars[prev + 1])) { + if (length > 2 && classTable->isReph(chars[prev]) && classTable->isVirama(chars[prev + 1]) && chars[prev + 2] != C_SIGN_ZWNJ) { baseLimit += 2; // Check for eyelash RA, if the script supports it @@ -551,6 +770,7 @@ le_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le lastConsonant -= 1; } + IndicClassTable::CharClass charClass = CC_RESERVED; IndicClassTable::CharClass nextClass = CC_RESERVED; le_int32 baseConsonant = lastConsonant; @@ -558,9 +778,11 @@ le_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le le_int32 postBaseLimit = classTable->scriptFlags & SF_POST_BASE_LIMIT_MASK; le_bool seenVattu = FALSE; le_bool seenBelowBaseForm = FALSE; + le_bool seenPreBaseForm = FALSE; le_bool hasNukta = FALSE; le_bool hasBelowBaseForm = FALSE; le_bool hasPostBaseForm = FALSE; + le_bool hasPreBaseForm = FALSE; if (postBase < markStart && classTable->isNukta(chars[postBase])) { charClass = CC_NUKTA; @@ -574,14 +796,22 @@ le_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le hasBelowBaseForm = IndicClassTable::hasBelowBaseForm(charClass) && !hasNukta; hasPostBaseForm = IndicClassTable::hasPostBaseForm(charClass) && !hasNukta; + hasPreBaseForm = IndicClassTable::hasPreBaseForm(charClass) && !hasNukta; if (IndicClassTable::isConsonant(charClass)) { if (postBaseLimit == 0 || seenVattu || (baseConsonant > baseLimit && !classTable->isVirama(chars[baseConsonant - 1])) || - !(hasBelowBaseForm || hasPostBaseForm)) { + !(hasBelowBaseForm || hasPostBaseForm || hasPreBaseForm)) { break; } + // Note any pre-base consonants + if ( baseConsonant == lastConsonant && lastConsonant > 0 && + hasPreBaseForm && classTable->isVirama(chars[baseConsonant - 1])) { + output.notePreBaseConsonant(lastConsonant,chars[lastConsonant],chars[lastConsonant-1],tagArray2); + seenPreBaseForm = TRUE; + + } // consonants with nuktas are never vattus seenVattu = IndicClassTable::isVattu(charClass) && !hasNukta; @@ -614,12 +844,14 @@ le_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le } // write any pre-base consonants + output.writePreBaseConsonant(); + le_bool supressVattu = TRUE; for (i = baseLimit; i < baseConsonant; i += 1) { LEUnicode ch = chars[i]; - // Don't put 'blwf' on first consonant. - FeatureMask features = (i == baseLimit? tagArray2 : tagArray1); + // Don't put 'pstf' or 'blwf' on anything before the base consonant. + FeatureMask features = tagArray1 & ~( pstfFeatureMask | blwfFeatureMask ); charClass = classTable->getCharClass(ch); nextClass = classTable->getCharClass(chars[i + 1]); @@ -670,7 +902,7 @@ le_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le } // write below-base consonants - if (baseConsonant != lastConsonant) { + if (baseConsonant != lastConsonant && !seenPreBaseForm) { for (i = bcSpan + 1; i < postBase; i += 1) { output.writeChar(chars[i], i, tagArray1); } @@ -700,7 +932,7 @@ le_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le // write post-base consonants // FIXME: does this put the right tags on post-base consonants? - if (baseConsonant != lastConsonant) { + if (baseConsonant != lastConsonant && !seenPreBaseForm) { if (postBase <= lastConsonant) { for (i = postBase; i <= lastConsonant; i += 1) { output.writeChar(chars[i], i, tagArray3); @@ -752,13 +984,255 @@ le_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le return output.getOutputIndex(); } -void IndicReordering::adjustMPres(MPreFixups *mpreFixups, LEGlyphStorage &glyphStorage) +void IndicReordering::adjustMPres(MPreFixups *mpreFixups, LEGlyphStorage &glyphStorage, LEErrorCode& success) { if (mpreFixups != NULL) { - mpreFixups->apply(glyphStorage); + mpreFixups->apply(glyphStorage, success); delete mpreFixups; } } +void IndicReordering::applyPresentationForms(LEGlyphStorage &glyphStorage, le_int32 count) +{ + LEErrorCode success = LE_NO_ERROR; + +// This sets us up for 2nd pass of glyph substitution as well as setting the feature masks for the +// GPOS table lookups + + for ( le_int32 i = 0 ; i < count ; i++ ) { + glyphStorage.setAuxData(i, ( presentationFormsMask | positioningFormsMask ), success); + } + +} +void IndicReordering::finalReordering(LEGlyphStorage &glyphStorage, le_int32 count) +{ + LEErrorCode success = LE_NO_ERROR; + + // Reposition REPH as appropriate + + for ( le_int32 i = 0 ; i < count ; i++ ) { + + le_int32 tmpAuxData = glyphStorage.getAuxData(i,success); + LEGlyphID tmpGlyph = glyphStorage.getGlyphID(i,success); + + if ( ( tmpGlyph != NO_GLYPH ) && (tmpAuxData & rephConsonantMask) && !(tmpAuxData & repositionedGlyphMask)) { + + le_bool targetPositionFound = false; + le_int32 targetPosition = i+1; + le_int32 baseConsonantData; + + while (!targetPositionFound) { + tmpGlyph = glyphStorage.getGlyphID(targetPosition,success); + tmpAuxData = glyphStorage.getAuxData(targetPosition,success); + + if ( tmpAuxData & baseConsonantMask ) { + baseConsonantData = tmpAuxData; + targetPositionFound = true; + } else { + targetPosition++; + } + } + + // Make sure we are not putting the reph into an empty hole + + le_bool targetPositionHasGlyph = false; + while (!targetPositionHasGlyph) { + tmpGlyph = glyphStorage.getGlyphID(targetPosition,success); + if ( tmpGlyph != NO_GLYPH ) { + targetPositionHasGlyph = true; + } else { + targetPosition--; + } + } + + // Make sure that REPH is positioned after any above base or post base matras + // + le_bool checkMatraDone = false; + le_int32 checkMatraPosition = targetPosition+1; + while ( !checkMatraDone ) { + tmpAuxData = glyphStorage.getAuxData(checkMatraPosition,success); + if ( checkMatraPosition >= count || ( (tmpAuxData ^ baseConsonantData) & LE_GLYPH_GROUP_MASK)) { + checkMatraDone = true; + continue; + } + if ( (tmpAuxData & matraMask) && + (((tmpAuxData & markPositionMask) == aboveBasePosition) || + ((tmpAuxData & markPositionMask) == postBasePosition))) { + targetPosition = checkMatraPosition; + } + checkMatraPosition++; + } + + glyphStorage.moveGlyph(i,targetPosition,repositionedGlyphMask); + } + } +} + + +le_int32 IndicReordering::v2process(const LEUnicode *chars, le_int32 charCount, le_int32 scriptCode, + LEUnicode *outChars, LEGlyphStorage &glyphStorage) +{ + const IndicClassTable *classTable = IndicClassTable::getScriptClassTable(scriptCode); + if (classTable == NULL) { + return 0; + } + + DynamicProperties dynProps[INDIC_BLOCK_SIZE]; + IndicReordering::getDynamicProperties(dynProps,classTable); + + IndicReorderingOutput output(outChars, glyphStorage, NULL); + le_int32 i, firstConsonant, baseConsonant, secondConsonant, inv_count = 0, beginSyllable = 0; + //le_bool lastInWord = FALSE; + + while (beginSyllable < charCount) { + le_int32 nextSyllable = findSyllable(classTable, chars, beginSyllable, charCount); + + output.reset(); + + // Find the First Consonant + for ( firstConsonant = beginSyllable ; firstConsonant < nextSyllable ; firstConsonant++ ) { + if ( classTable->isConsonant(chars[firstConsonant]) ) { + break; + } + } + + // Find the base consonant + + baseConsonant = nextSyllable - 1; + secondConsonant = firstConsonant; + + // TODO: Use Dynamic Properties for hasBelowBaseForm and hasPostBaseForm() + + while ( baseConsonant > firstConsonant ) { + if ( classTable->isConsonant(chars[baseConsonant]) && + !classTable->hasBelowBaseForm(chars[baseConsonant]) && + !classTable->hasPostBaseForm(chars[baseConsonant]) ) { + break; + } + else { + if ( classTable->isConsonant(chars[baseConsonant]) ) { + secondConsonant = baseConsonant; + } + baseConsonant--; + } + } + + // If the syllable starts with Ra + Halant ( in a script that has Reph ) and has more than one + // consonant, Ra is excluced from candidates for base consonants + + if ( classTable->isReph(chars[beginSyllable]) && + beginSyllable+1 < nextSyllable && classTable->isVirama(chars[beginSyllable+1]) && + secondConsonant != firstConsonant) { + baseConsonant = secondConsonant; + } + + // Populate the output + for ( i = beginSyllable ; i < nextSyllable ; i++ ) { + + // Handle invalid combinartions + + if ( classTable->isVirama(chars[beginSyllable]) || + classTable->isMatra(chars[beginSyllable]) || + classTable->isVowelModifier(chars[beginSyllable]) || + classTable->isNukta(chars[beginSyllable]) ) { + output.writeChar(C_DOTTED_CIRCLE,beginSyllable,basicShapingFormsMask); + inv_count++; + } + output.writeChar(chars[i],i, basicShapingFormsMask); + + } + + // Adjust features and set syllable structure bits + + for ( i = beginSyllable ; i < nextSyllable ; i++ ) { + + FeatureMask outMask = output.getFeatures(i+inv_count); + FeatureMask saveMask = outMask; + + // Since reph can only validly occur at the beginning of a syllable + // We only apply it to the first 2 characters in the syllable, to keep it from + // conflicting with other features ( i.e. rkrf ) + + // TODO : Use the dynamic property for determining isREPH + if ( i == beginSyllable && i < baseConsonant && classTable->isReph(chars[i]) && + i+1 < nextSyllable && classTable->isVirama(chars[i+1])) { + outMask |= rphfFeatureMask; + outMask |= rephConsonantMask; + output.setFeatures(i+1+inv_count,outMask); + + } + + if ( i == baseConsonant ) { + outMask |= baseConsonantMask; + } + + if ( classTable->isMatra(chars[i])) { + outMask |= matraMask; + if ( classTable->hasAboveBaseForm(chars[i])) { + outMask |= aboveBasePosition; + } else if ( classTable->hasBelowBaseForm(chars[i])) { + outMask |= belowBasePosition; + } + } + + // Don't apply half form to virama that stands alone at the end of a syllable + // to prevent half forms from forming when syllable ends with virama + + if ( classTable->isVirama(chars[i]) && (i+1 == nextSyllable) ) { + outMask ^= halfFeatureMask; + if ( classTable->isConsonant(chars[i-1]) ) { + FeatureMask tmp = output.getFeatures(i-1+inv_count); + tmp ^= halfFeatureMask; + output.setFeatures(i-1+inv_count,tmp); + } + } + + if ( outMask != saveMask ) { + output.setFeatures(i+inv_count,outMask); + } + } + + output.decomposeReorderMatras(classTable,beginSyllable,nextSyllable,inv_count); + + beginSyllable = nextSyllable; + } + + + return output.getOutputIndex(); +} + + +void IndicReordering::getDynamicProperties( DynamicProperties *, const IndicClassTable *classTable ) { + + + LEUnicode currentChar; + LEUnicode workChars[2]; + LEGlyphStorage workGlyphs; + + IndicReorderingOutput workOutput(workChars, workGlyphs, NULL); + + //le_int32 offset = 0; + +#if 0 +// TODO: Should this section of code have actually been doing something? + // First find the relevant virama for the script we are dealing with + LEUnicode virama; + for ( currentChar = classTable->firstChar ; currentChar <= classTable->lastChar ; currentChar++ ) { + if ( classTable->isVirama(currentChar)) { + virama = currentChar; + break; + } + } +#endif + + for ( currentChar = classTable->firstChar ; currentChar <= classTable->lastChar ; currentChar++ ) { + if ( classTable->isConsonant(currentChar)) { + workOutput.reset(); + } + } + + +} + U_NAMESPACE_END