0N/A/*
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A *
0N/A */
0N/A
0N/A/*
0N/A *
3171N/A * (C) Copyright IBM Corp. 1998-2009 - All Rights Reserved
0N/A *
0N/A */
0N/A
0N/A#include "LETypes.h"
0N/A#include "OpenTypeTables.h"
0N/A#include "OpenTypeUtilities.h"
0N/A#include "IndicReordering.h"
0N/A#include "LEGlyphStorage.h"
0N/A#include "MPreFixups.h"
0N/A
1693N/AU_NAMESPACE_BEGIN
1693N/A
3171N/A#define loclFeatureTag LE_LOCL_FEATURE_TAG
0N/A#define initFeatureTag LE_INIT_FEATURE_TAG
0N/A#define nuktFeatureTag LE_NUKT_FEATURE_TAG
0N/A#define akhnFeatureTag LE_AKHN_FEATURE_TAG
0N/A#define rphfFeatureTag LE_RPHF_FEATURE_TAG
3171N/A#define rkrfFeatureTag LE_RKRF_FEATURE_TAG
0N/A#define blwfFeatureTag LE_BLWF_FEATURE_TAG
0N/A#define halfFeatureTag LE_HALF_FEATURE_TAG
0N/A#define pstfFeatureTag LE_PSTF_FEATURE_TAG
0N/A#define vatuFeatureTag LE_VATU_FEATURE_TAG
0N/A#define presFeatureTag LE_PRES_FEATURE_TAG
0N/A#define blwsFeatureTag LE_BLWS_FEATURE_TAG
0N/A#define abvsFeatureTag LE_ABVS_FEATURE_TAG
0N/A#define pstsFeatureTag LE_PSTS_FEATURE_TAG
0N/A#define halnFeatureTag LE_HALN_FEATURE_TAG
3171N/A#define cjctFeatureTag LE_CJCT_FEATURE_TAG
0N/A#define blwmFeatureTag LE_BLWM_FEATURE_TAG
0N/A#define abvmFeatureTag LE_ABVM_FEATURE_TAG
0N/A#define distFeatureTag LE_DIST_FEATURE_TAG
3171N/A#define caltFeatureTag LE_CALT_FEATURE_TAG
3171N/A#define kernFeatureTag LE_KERN_FEATURE_TAG
0N/A
3171N/A#define loclFeatureMask 0x80000000UL
3171N/A#define rphfFeatureMask 0x40000000UL
3171N/A#define blwfFeatureMask 0x20000000UL
3171N/A#define halfFeatureMask 0x10000000UL
3171N/A#define pstfFeatureMask 0x08000000UL
3171N/A#define nuktFeatureMask 0x04000000UL
3171N/A#define akhnFeatureMask 0x02000000UL
3171N/A#define vatuFeatureMask 0x01000000UL
3171N/A#define presFeatureMask 0x00800000UL
3171N/A#define blwsFeatureMask 0x00400000UL
3171N/A#define abvsFeatureMask 0x00200000UL
3171N/A#define pstsFeatureMask 0x00100000UL
3171N/A#define halnFeatureMask 0x00080000UL
3171N/A#define blwmFeatureMask 0x00040000UL
3171N/A#define abvmFeatureMask 0x00020000UL
3171N/A#define distFeatureMask 0x00010000UL
3171N/A#define initFeatureMask 0x00008000UL
3171N/A#define cjctFeatureMask 0x00004000UL
3171N/A#define rkrfFeatureMask 0x00002000UL
3171N/A#define caltFeatureMask 0x00001000UL
3171N/A#define kernFeatureMask 0x00000800UL
0N/A
3171N/A// Syllable structure bits
3171N/A#define baseConsonantMask 0x00000400UL
3171N/A#define consonantMask 0x00000200UL
3171N/A#define halfConsonantMask 0x00000100UL
3171N/A#define rephConsonantMask 0x00000080UL
3171N/A#define matraMask 0x00000040UL
3171N/A#define vowelModifierMask 0x00000020UL
3171N/A#define markPositionMask 0x00000018UL
3171N/A
3171N/A#define postBasePosition 0x00000000UL
3171N/A#define preBasePosition 0x00000008UL
3171N/A#define aboveBasePosition 0x00000010UL
3171N/A#define belowBasePosition 0x00000018UL
3171N/A
3171N/A#define repositionedGlyphMask 0x00000002UL
3171N/A
3171N/A#define basicShapingFormsMask ( loclFeatureMask | nuktFeatureMask | akhnFeatureMask | rkrfFeatureMask | blwfFeatureMask | halfFeatureMask | vatuFeatureMask | cjctFeatureMask )
3171N/A#define positioningFormsMask ( kernFeatureMask | distFeatureMask | abvmFeatureMask | blwmFeatureMask )
3171N/A#define presentationFormsMask ( presFeatureMask | abvsFeatureMask | blwsFeatureMask | pstsFeatureMask | halnFeatureMask | caltFeatureMask )
3171N/A
3171N/A
3171N/A#define C_MALAYALAM_VOWEL_SIGN_U 0x0D41
3171N/A#define C_DOTTED_CIRCLE 0x25CC
3171N/A#define NO_GLYPH 0xFFFF
3171N/A
3171N/A// Some level of debate as to the proper value for MAX_CONSONANTS_PER_SYLLABLE. Ticket 5588 states that 4
3171N/A// is the magic number according to ISCII, but 5 seems to be the more consistent with XP.
3171N/A#define MAX_CONSONANTS_PER_SYLLABLE 5
3171N/A
3171N/A#define INDIC_BLOCK_SIZE 0x7F
3171N/A
3171N/Aclass IndicReorderingOutput : public UMemory {
0N/Aprivate:
3171N/A le_int32 fSyllableCount;
0N/A le_int32 fOutIndex;
0N/A LEUnicode *fOutChars;
0N/A
0N/A LEGlyphStorage &fGlyphStorage;
0N/A
0N/A LEUnicode fMpre;
0N/A le_int32 fMpreIndex;
0N/A
0N/A LEUnicode fMbelow;
0N/A le_int32 fMbelowIndex;
0N/A
0N/A LEUnicode fMabove;
0N/A le_int32 fMaboveIndex;
0N/A
0N/A LEUnicode fMpost;
0N/A le_int32 fMpostIndex;
0N/A
0N/A LEUnicode fLengthMark;
0N/A le_int32 fLengthMarkIndex;
0N/A
3171N/A LEUnicode fAlLakuna;
3171N/A le_int32 fAlLakunaIndex;
0N/A
0N/A FeatureMask fMatraFeatures;
0N/A
0N/A le_int32 fMPreOutIndex;
0N/A MPreFixups *fMPreFixups;
0N/A
0N/A LEUnicode fVMabove;
0N/A LEUnicode fVMpost;
0N/A le_int32 fVMIndex;
0N/A FeatureMask fVMFeatures;
0N/A
0N/A LEUnicode fSMabove;
0N/A LEUnicode fSMbelow;
0N/A le_int32 fSMIndex;
0N/A FeatureMask fSMFeatures;
0N/A
3171N/A LEUnicode fPreBaseConsonant;
3171N/A LEUnicode fPreBaseVirama;
3171N/A le_int32 fPBCIndex;
3171N/A FeatureMask fPBCFeatures;
3171N/A
0N/A void saveMatra(LEUnicode matra, le_int32 matraIndex, IndicClassTable::CharClass matraClass)
0N/A {
0N/A // FIXME: check if already set, or if not a matra...
0N/A if (IndicClassTable::isLengthMark(matraClass)) {
0N/A fLengthMark = matra;
0N/A fLengthMarkIndex = matraIndex;
3171N/A } else if (IndicClassTable::isAlLakuna(matraClass)) {
3171N/A fAlLakuna = matra;
3171N/A fAlLakunaIndex = matraIndex;
0N/A } else {
0N/A switch (matraClass & CF_POS_MASK) {
0N/A case CF_POS_BEFORE:
0N/A fMpre = matra;
0N/A fMpreIndex = matraIndex;
0N/A break;
0N/A
0N/A case CF_POS_BELOW:
0N/A fMbelow = matra;
0N/A fMbelowIndex = matraIndex;
0N/A break;
0N/A
0N/A case CF_POS_ABOVE:
0N/A fMabove = matra;
0N/A fMaboveIndex = matraIndex;
0N/A break;
0N/A
0N/A case CF_POS_AFTER:
0N/A fMpost = matra;
0N/A fMpostIndex = matraIndex;
0N/A break;
0N/A
0N/A default:
0N/A // can't get here...
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/Apublic:
3171N/A IndicReorderingOutput(LEUnicode *outChars, LEGlyphStorage &glyphStorage, MPreFixups *mpreFixups)
3171N/A : fSyllableCount(0), fOutIndex(0), fOutChars(outChars), fGlyphStorage(glyphStorage),
0N/A fMpre(0), fMpreIndex(0), fMbelow(0), fMbelowIndex(0), fMabove(0), fMaboveIndex(0),
3171N/A fMpost(0), fMpostIndex(0), fLengthMark(0), fLengthMarkIndex(0), fAlLakuna(0), fAlLakunaIndex(0),
0N/A fMatraFeatures(0), fMPreOutIndex(-1), fMPreFixups(mpreFixups),
0N/A fVMabove(0), fVMpost(0), fVMIndex(0), fVMFeatures(0),
3171N/A fSMabove(0), fSMbelow(0), fSMIndex(0), fSMFeatures(0),
3171N/A fPreBaseConsonant(0), fPreBaseVirama(0), fPBCIndex(0), fPBCFeatures(0)
0N/A {
0N/A // nothing else to do...
0N/A }
0N/A
3171N/A ~IndicReorderingOutput()
0N/A {
0N/A // nothing to do here...
0N/A }
0N/A
0N/A void reset()
0N/A {
3171N/A fSyllableCount += 1;
3171N/A
3171N/A fMpre = fMbelow = fMabove = fMpost = fLengthMark = fAlLakuna = 0;
0N/A fMPreOutIndex = -1;
0N/A
0N/A fVMabove = fVMpost = 0;
0N/A fSMabove = fSMbelow = 0;
3171N/A
3171N/A fPreBaseConsonant = fPreBaseVirama = 0;
0N/A }
0N/A
0N/A void writeChar(LEUnicode ch, le_uint32 charIndex, FeatureMask charFeatures)
0N/A {
0N/A LEErrorCode success = LE_NO_ERROR;
0N/A
0N/A fOutChars[fOutIndex] = ch;
0N/A
0N/A fGlyphStorage.setCharIndex(fOutIndex, charIndex, success);
3171N/A fGlyphStorage.setAuxData(fOutIndex, charFeatures | (fSyllableCount & LE_GLYPH_GROUP_MASK), success);
0N/A
0N/A fOutIndex += 1;
0N/A }
0N/A
3171N/A void setFeatures ( le_uint32 charIndex, FeatureMask charFeatures)
3171N/A {
3171N/A LEErrorCode success = LE_NO_ERROR;
3171N/A
3171N/A fGlyphStorage.setAuxData( charIndex, charFeatures, success );
3171N/A
3171N/A }
3171N/A
3171N/A FeatureMask getFeatures ( le_uint32 charIndex )
3171N/A {
3171N/A LEErrorCode success = LE_NO_ERROR;
3171N/A return fGlyphStorage.getAuxData(charIndex,success);
3171N/A }
3171N/A
3171N/A void decomposeReorderMatras ( const IndicClassTable *classTable, le_int32 beginSyllable, le_int32 nextSyllable, le_int32 inv_count ) {
3171N/A le_int32 i;
3171N/A LEErrorCode success = LE_NO_ERROR;
3171N/A
3171N/A for ( i = beginSyllable ; i < nextSyllable ; i++ ) {
3171N/A if ( classTable->isMatra(fOutChars[i+inv_count])) {
3171N/A IndicClassTable::CharClass matraClass = classTable->getCharClass(fOutChars[i+inv_count]);
3171N/A if ( classTable->isSplitMatra(matraClass)) {
3171N/A le_int32 saveIndex = fGlyphStorage.getCharIndex(i+inv_count,success);
3171N/A le_uint32 saveAuxData = fGlyphStorage.getAuxData(i+inv_count,success);
3171N/A const SplitMatra *splitMatra = classTable->getSplitMatra(matraClass);
3171N/A int j;
5891N/A for (j = 0 ; j < SM_MAX_PIECES && *(splitMatra)[j] != 0 ; j++) {
3171N/A LEUnicode piece = (*splitMatra)[j];
3171N/A if ( j == 0 ) {
3171N/A fOutChars[i+inv_count] = piece;
3171N/A matraClass = classTable->getCharClass(piece);
3171N/A } else {
3171N/A insertCharacter(piece,i+1+inv_count,saveIndex,saveAuxData);
3171N/A nextSyllable++;
3171N/A }
3171N/A }
3171N/A }
3171N/A
3171N/A if ((matraClass & CF_POS_MASK) == CF_POS_BEFORE) {
3171N/A moveCharacter(i+inv_count,beginSyllable+inv_count);
3171N/A }
3171N/A }
3171N/A }
3171N/A }
3171N/A
3171N/A void moveCharacter( le_int32 fromPosition, le_int32 toPosition ) {
3171N/A le_int32 i,saveIndex;
3171N/A le_uint32 saveAuxData;
3171N/A LEUnicode saveChar = fOutChars[fromPosition];
3171N/A LEErrorCode success = LE_NO_ERROR;
3171N/A LEErrorCode success2 = LE_NO_ERROR;
3171N/A saveIndex = fGlyphStorage.getCharIndex(fromPosition,success);
3171N/A saveAuxData = fGlyphStorage.getAuxData(fromPosition,success);
3171N/A
3171N/A if ( fromPosition > toPosition ) {
3171N/A for ( i = fromPosition ; i > toPosition ; i-- ) {
3171N/A fOutChars[i] = fOutChars[i-1];
3171N/A fGlyphStorage.setCharIndex(i,fGlyphStorage.getCharIndex(i-1,success2),success);
3171N/A fGlyphStorage.setAuxData(i,fGlyphStorage.getAuxData(i-1,success2), success);
3171N/A
3171N/A }
3171N/A } else {
3171N/A for ( i = fromPosition ; i < toPosition ; i++ ) {
3171N/A fOutChars[i] = fOutChars[i+1];
3171N/A fGlyphStorage.setCharIndex(i,fGlyphStorage.getCharIndex(i+1,success2),success);
3171N/A fGlyphStorage.setAuxData(i,fGlyphStorage.getAuxData(i+1,success2), success);
3171N/A }
3171N/A
3171N/A }
3171N/A fOutChars[toPosition] = saveChar;
3171N/A fGlyphStorage.setCharIndex(toPosition,saveIndex,success);
3171N/A fGlyphStorage.setAuxData(toPosition,saveAuxData,success);
3171N/A
3171N/A }
3171N/A void insertCharacter( LEUnicode ch, le_int32 toPosition, le_int32 charIndex, le_uint32 auxData ) {
3171N/A LEErrorCode success = LE_NO_ERROR;
3171N/A le_int32 i;
3171N/A fOutIndex += 1;
3171N/A
3171N/A for ( i = fOutIndex ; i > toPosition ; i--) {
3171N/A fOutChars[i] = fOutChars[i-1];
3171N/A fGlyphStorage.setCharIndex(i,fGlyphStorage.getCharIndex(i-1,success),success);
3171N/A fGlyphStorage.setAuxData(i,fGlyphStorage.getAuxData(i-1,success), success);
3171N/A }
3171N/A
3171N/A fOutChars[toPosition] = ch;
3171N/A fGlyphStorage.setCharIndex(toPosition,charIndex,success);
3171N/A fGlyphStorage.setAuxData(toPosition,auxData,success);
3171N/A
3171N/A }
3171N/A void removeCharacter( le_int32 fromPosition ) {
3171N/A LEErrorCode success = LE_NO_ERROR;
3171N/A le_int32 i;
3171N/A fOutIndex -= 1;
3171N/A
3171N/A for ( i = fromPosition ; i < fOutIndex ; i--) {
3171N/A fOutChars[i] = fOutChars[i+1];
3171N/A fGlyphStorage.setCharIndex(i,fGlyphStorage.getCharIndex(i+1,success),success);
3171N/A fGlyphStorage.setAuxData(i,fGlyphStorage.getAuxData(i+1,success), success);
3171N/A }
3171N/A }
3171N/A
1693N/A le_bool noteMatra(const IndicClassTable *classTable, LEUnicode matra, le_uint32 matraIndex, FeatureMask matraFeatures, le_bool wordStart)
0N/A {
0N/A IndicClassTable::CharClass matraClass = classTable->getCharClass(matra);
0N/A
0N/A fMatraFeatures = matraFeatures;
0N/A
0N/A if (wordStart) {
0N/A fMatraFeatures |= initFeatureMask;
0N/A }
0N/A
0N/A if (IndicClassTable::isMatra(matraClass)) {
0N/A if (IndicClassTable::isSplitMatra(matraClass)) {
0N/A const SplitMatra *splitMatra = classTable->getSplitMatra(matraClass);
0N/A int i;
0N/A
5891N/A for (i = 0; i < SM_MAX_PIECES && (*splitMatra)[i] != 0; i += 1) {
0N/A LEUnicode piece = (*splitMatra)[i];
0N/A IndicClassTable::CharClass pieceClass = classTable->getCharClass(piece);
0N/A
0N/A saveMatra(piece, matraIndex, pieceClass);
0N/A }
0N/A } else {
0N/A saveMatra(matra, matraIndex, matraClass);
0N/A }
0N/A
0N/A return TRUE;
0N/A }
0N/A
0N/A return FALSE;
0N/A }
0N/A
1693N/A void noteVowelModifier(const IndicClassTable *classTable, LEUnicode vowelModifier, le_uint32 vowelModifierIndex, FeatureMask vowelModifierFeatures)
0N/A {
0N/A IndicClassTable::CharClass vmClass = classTable->getCharClass(vowelModifier);
0N/A
0N/A fVMIndex = vowelModifierIndex;
1693N/A fVMFeatures = vowelModifierFeatures;
0N/A
0N/A if (IndicClassTable::isVowelModifier(vmClass)) {
0N/A switch (vmClass & CF_POS_MASK) {
0N/A case CF_POS_ABOVE:
0N/A fVMabove = vowelModifier;
0N/A break;
0N/A
0N/A case CF_POS_AFTER:
0N/A fVMpost = vowelModifier;
0N/A break;
0N/A
0N/A default:
0N/A // FIXME: this is an error...
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
1693N/A void noteStressMark(const IndicClassTable *classTable, LEUnicode stressMark, le_uint32 stressMarkIndex, FeatureMask stressMarkFeatures)
0N/A {
0N/A IndicClassTable::CharClass smClass = classTable->getCharClass(stressMark);
0N/A
0N/A fSMIndex = stressMarkIndex;
1693N/A fSMFeatures = stressMarkFeatures;
0N/A
0N/A if (IndicClassTable::isStressMark(smClass)) {
0N/A switch (smClass & CF_POS_MASK) {
0N/A case CF_POS_ABOVE:
0N/A fSMabove = stressMark;
0N/A break;
0N/A
0N/A case CF_POS_BELOW:
0N/A fSMbelow = stressMark;
0N/A break;
0N/A
0N/A default:
0N/A // FIXME: this is an error...
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
3171N/A void notePreBaseConsonant(le_uint32 index,LEUnicode PBConsonant, LEUnicode PBVirama, FeatureMask features)
3171N/A {
3171N/A fPBCIndex = index;
3171N/A fPreBaseConsonant = PBConsonant;
3171N/A fPreBaseVirama = PBVirama;
3171N/A fPBCFeatures = features;
3171N/A }
3171N/A
0N/A void noteBaseConsonant()
0N/A {
0N/A if (fMPreFixups != NULL && fMPreOutIndex >= 0) {
0N/A fMPreFixups->add(fOutIndex, fMPreOutIndex);
0N/A }
0N/A }
0N/A
3171N/A // Handles Al-Lakuna in Sinhala split vowels.
3171N/A void writeAlLakuna()
0N/A {
3171N/A if (fAlLakuna != 0) {
3171N/A writeChar(fAlLakuna, fAlLakunaIndex, fMatraFeatures);
0N/A }
0N/A }
0N/A
0N/A void writeMpre()
0N/A {
0N/A if (fMpre != 0) {
0N/A fMPreOutIndex = fOutIndex;
0N/A writeChar(fMpre, fMpreIndex, fMatraFeatures);
0N/A }
0N/A }
0N/A
0N/A void writeMbelow()
0N/A {
0N/A if (fMbelow != 0) {
0N/A writeChar(fMbelow, fMbelowIndex, fMatraFeatures);
0N/A }
0N/A }
0N/A
0N/A void writeMabove()
0N/A {
0N/A if (fMabove != 0) {
0N/A writeChar(fMabove, fMaboveIndex, fMatraFeatures);
0N/A }
0N/A }
0N/A
0N/A void writeMpost()
0N/A {
0N/A if (fMpost != 0) {
0N/A writeChar(fMpost, fMpostIndex, fMatraFeatures);
0N/A }
0N/A }
0N/A
0N/A void writeLengthMark()
0N/A {
0N/A if (fLengthMark != 0) {
0N/A writeChar(fLengthMark, fLengthMarkIndex, fMatraFeatures);
0N/A }
0N/A }
0N/A
0N/A void writeVMabove()
0N/A {
0N/A if (fVMabove != 0) {
0N/A writeChar(fVMabove, fVMIndex, fVMFeatures);
0N/A }
0N/A }
0N/A
0N/A void writeVMpost()
0N/A {
0N/A if (fVMpost != 0) {
0N/A writeChar(fVMpost, fVMIndex, fVMFeatures);
0N/A }
0N/A }
0N/A
0N/A void writeSMabove()
0N/A {
0N/A if (fSMabove != 0) {
0N/A writeChar(fSMabove, fSMIndex, fSMFeatures);
0N/A }
0N/A }
0N/A
0N/A void writeSMbelow()
0N/A {
0N/A if (fSMbelow != 0) {
0N/A writeChar(fSMbelow, fSMIndex, fSMFeatures);
0N/A }
0N/A }
0N/A
3171N/A void writePreBaseConsonant()
3171N/A {
3171N/A // The TDIL spec says that consonant + virama + RRA should produce a rakar in Malayalam. However,
3171N/A // it seems that almost none of the fonts for Malayalam are set up to handle this.
3171N/A // So, we're going to force the issue here by using the rakar as defined with RA in most fonts.
3171N/A
3171N/A if (fPreBaseConsonant == 0x0d31) { // RRA
3171N/A fPreBaseConsonant = 0x0d30; // RA
3171N/A }
3171N/A
3171N/A if (fPreBaseConsonant != 0) {
3171N/A writeChar(fPreBaseConsonant, fPBCIndex, fPBCFeatures);
3171N/A writeChar(fPreBaseVirama,fPBCIndex-1,fPBCFeatures);
3171N/A }
3171N/A }
3171N/A
0N/A le_int32 getOutputIndex()
0N/A {
0N/A return fOutIndex;
0N/A }
0N/A};
0N/A
3171N/A
0N/A
0N/A// TODO: Find better names for these!
3171N/A#define tagArray4 (loclFeatureMask | nuktFeatureMask | akhnFeatureMask | vatuFeatureMask | presFeatureMask | blwsFeatureMask | abvsFeatureMask | pstsFeatureMask | halnFeatureMask | blwmFeatureMask | abvmFeatureMask | distFeatureMask)
0N/A#define tagArray3 (pstfFeatureMask | tagArray4)
0N/A#define tagArray2 (halfFeatureMask | tagArray3)
0N/A#define tagArray1 (blwfFeatureMask | tagArray2)
0N/A#define tagArray0 (rphfFeatureMask | tagArray1)
0N/A
3171N/Astatic const FeatureMap featureMap[] = {
3171N/A {loclFeatureTag, loclFeatureMask},
0N/A {initFeatureTag, initFeatureMask},
0N/A {nuktFeatureTag, nuktFeatureMask},
0N/A {akhnFeatureTag, akhnFeatureMask},
0N/A {rphfFeatureTag, rphfFeatureMask},
0N/A {blwfFeatureTag, blwfFeatureMask},
0N/A {halfFeatureTag, halfFeatureMask},
0N/A {pstfFeatureTag, pstfFeatureMask},
0N/A {vatuFeatureTag, vatuFeatureMask},
0N/A {presFeatureTag, presFeatureMask},
0N/A {blwsFeatureTag, blwsFeatureMask},
0N/A {abvsFeatureTag, abvsFeatureMask},
0N/A {pstsFeatureTag, pstsFeatureMask},
0N/A {halnFeatureTag, halnFeatureMask},
0N/A {blwmFeatureTag, blwmFeatureMask},
0N/A {abvmFeatureTag, abvmFeatureMask},
0N/A {distFeatureTag, distFeatureMask}
0N/A};
0N/A
0N/Astatic const le_int32 featureCount = LE_ARRAY_SIZE(featureMap);
0N/A
3171N/Astatic const FeatureMap v2FeatureMap[] = {
3171N/A {loclFeatureTag, loclFeatureMask},
3171N/A {nuktFeatureTag, nuktFeatureMask},
3171N/A {akhnFeatureTag, akhnFeatureMask},
3171N/A {rphfFeatureTag, rphfFeatureMask},
3171N/A {rkrfFeatureTag, rkrfFeatureMask},
3171N/A {blwfFeatureTag, blwfFeatureMask},
3171N/A {halfFeatureTag, halfFeatureMask},
3171N/A {vatuFeatureTag, vatuFeatureMask},
3171N/A {cjctFeatureTag, cjctFeatureMask},
3171N/A {presFeatureTag, presFeatureMask},
3171N/A {abvsFeatureTag, abvsFeatureMask},
3171N/A {blwsFeatureTag, blwsFeatureMask},
3171N/A {pstsFeatureTag, pstsFeatureMask},
3171N/A {halnFeatureTag, halnFeatureMask},
3171N/A {caltFeatureTag, caltFeatureMask},
3171N/A {kernFeatureTag, kernFeatureMask},
3171N/A {distFeatureTag, distFeatureMask},
3171N/A {abvmFeatureTag, abvmFeatureMask},
3171N/A {blwmFeatureTag, blwmFeatureMask}
3171N/A};
3171N/A
3171N/Astatic const le_int32 v2FeatureMapCount = LE_ARRAY_SIZE(v2FeatureMap);
3171N/A
0N/Astatic const le_int8 stateTable[][CC_COUNT] =
0N/A{
3171N/A// xx vm sm iv i2 i3 ct cn nu dv s1 s2 s3 vr zw al
3171N/A { 1, 6, 1, 5, 8, 11, 3, 2, 1, 5, 9, 5, 5, 1, 1, 1}, // 0 - ground state
3171N/A {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 1 - exit state
3171N/A {-1, 6, 1, -1, -1, -1, -1, -1, -1, 5, 9, 5, 5, 4, 12, -1}, // 2 - consonant with nukta
3171N/A {-1, 6, 1, -1, -1, -1, -1, -1, 2, 5, 9, 5, 5, 4, 12, 13}, // 3 - consonant
3171N/A {-1, -1, -1, -1, -1, -1, 3, 2, -1, -1, -1, -1, -1, -1, 7, -1}, // 4 - consonant virama
3171N/A {-1, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 5 - dependent vowels
3171N/A {-1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 6 - vowel mark
3171N/A {-1, -1, -1, -1, -1, -1, 3, 2, -1, -1, -1, -1, -1, -1, -1, -1}, // 7 - consonant virama ZWJ, consonant ZWJ virama
3171N/A {-1, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, -1, -1}, // 8 - independent vowels that can take a virama
3171N/A {-1, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 5, -1, -1, -1}, // 9 - first part of split vowel
3171N/A {-1, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 5, -1, -1, -1}, // 10 - second part of split vowel
3171N/A {-1, 6, 1, -1, -1, -1, -1, -1, -1, 5, 9, 5, 5, 4, -1, -1}, // 11 - independent vowels that can take an iv
3171N/A {-1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 7, -1, 7}, // 12 - consonant ZWJ (TODO: Take everything else that can be after a consonant?)
3171N/A {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 7, -1} // 13 - consonant al-lakuna ZWJ consonant
0N/A};
0N/A
0N/A
0N/Aconst FeatureMap *IndicReordering::getFeatureMap(le_int32 &count)
0N/A{
0N/A count = featureCount;
0N/A
0N/A return featureMap;
0N/A}
0N/A
3171N/Aconst FeatureMap *IndicReordering::getv2FeatureMap(le_int32 &count)
3171N/A{
3171N/A count = v2FeatureMapCount;
3171N/A
3171N/A return v2FeatureMap;
3171N/A}
3171N/A
1693N/Ale_int32 IndicReordering::findSyllable(const IndicClassTable *classTable, const LEUnicode *chars, le_int32 prev, le_int32 charCount)
0N/A{
0N/A le_int32 cursor = prev;
0N/A le_int8 state = 0;
3171N/A le_int8 consonant_count = 0;
0N/A
0N/A while (cursor < charCount) {
0N/A IndicClassTable::CharClass charClass = classTable->getCharClass(chars[cursor]);
0N/A
3171N/A if ( IndicClassTable::isConsonant(charClass) ) {
3171N/A consonant_count++;
3171N/A if ( consonant_count > MAX_CONSONANTS_PER_SYLLABLE ) {
3171N/A break;
3171N/A }
3171N/A }
3171N/A
0N/A state = stateTable[state][charClass & CF_CLASS_MASK];
0N/A
0N/A if (state < 0) {
0N/A break;
0N/A }
0N/A
0N/A cursor += 1;
0N/A }
0N/A
0N/A return cursor;
0N/A}
0N/A
0N/Ale_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le_int32 scriptCode,
0N/A LEUnicode *outChars, LEGlyphStorage &glyphStorage,
3171N/A MPreFixups **outMPreFixups, LEErrorCode& success)
0N/A{
3171N/A if (LE_FAILURE(success)) {
3171N/A return 0;
3171N/A }
3171N/A
0N/A MPreFixups *mpreFixups = NULL;
0N/A const IndicClassTable *classTable = IndicClassTable::getScriptClassTable(scriptCode);
0N/A
5980N/A if(classTable==NULL) {
5980N/A success = LE_MEMORY_ALLOCATION_ERROR;
5980N/A return 0;
5980N/A }
5980N/A
0N/A if (classTable->scriptFlags & SF_MPRE_FIXUP) {
0N/A mpreFixups = new MPreFixups(charCount);
3171N/A if (mpreFixups == NULL) {
3171N/A success = LE_MEMORY_ALLOCATION_ERROR;
3171N/A return 0;
3171N/A }
0N/A }
0N/A
3171N/A IndicReorderingOutput output(outChars, glyphStorage, mpreFixups);
0N/A le_int32 i, prev = 0;
0N/A le_bool lastInWord = FALSE;
0N/A
0N/A while (prev < charCount) {
0N/A le_int32 syllable = findSyllable(classTable, chars, prev, charCount);
0N/A le_int32 matra, markStart = syllable;
0N/A
0N/A output.reset();
0N/A
0N/A if (classTable->isStressMark(chars[markStart - 1])) {
0N/A markStart -= 1;
0N/A output.noteStressMark(classTable, chars[markStart], markStart, tagArray1);
0N/A }
0N/A
3171N/A if (markStart != prev && classTable->isVowelModifier(chars[markStart - 1])) {
0N/A markStart -= 1;
0N/A output.noteVowelModifier(classTable, chars[markStart], markStart, tagArray1);
0N/A }
0N/A
0N/A matra = markStart - 1;
0N/A
0N/A while (output.noteMatra(classTable, chars[matra], matra, tagArray1, !lastInWord) && matra != prev) {
0N/A matra -= 1;
0N/A }
0N/A
0N/A lastInWord = TRUE;
0N/A
0N/A switch (classTable->getCharClass(chars[prev]) & CF_CLASS_MASK) {
0N/A case CC_RESERVED:
0N/A lastInWord = FALSE;
0N/A /* fall through */
0N/A
0N/A case CC_INDEPENDENT_VOWEL:
0N/A case CC_ZERO_WIDTH_MARK:
0N/A for (i = prev; i < syllable; i += 1) {
0N/A output.writeChar(chars[i], i, tagArray1);
0N/A }
0N/A
0N/A break;
0N/A
3171N/A case CC_AL_LAKUNA:
0N/A case CC_NUKTA:
3171N/A output.writeChar(C_DOTTED_CIRCLE, prev, tagArray1);
3171N/A output.writeChar(chars[prev], prev, tagArray1);
3171N/A break;
3171N/A
0N/A case CC_VIRAMA:
3171N/A // A lone virama is illegal unless it follows a
3171N/A // MALAYALAM_VOWEL_SIGN_U. Such a usage is called
3171N/A // "samvruthokaram".
3171N/A if (chars[prev - 1] != C_MALAYALAM_VOWEL_SIGN_U) {
0N/A output.writeChar(C_DOTTED_CIRCLE, prev, tagArray1);
3171N/A }
3171N/A
0N/A output.writeChar(chars[prev], prev, tagArray1);
0N/A break;
0N/A
0N/A case CC_DEPENDENT_VOWEL:
0N/A case CC_SPLIT_VOWEL_PIECE_1:
0N/A case CC_SPLIT_VOWEL_PIECE_2:
0N/A case CC_SPLIT_VOWEL_PIECE_3:
0N/A case CC_VOWEL_MODIFIER:
0N/A case CC_STRESS_MARK:
0N/A output.writeMpre();
0N/A
0N/A output.writeChar(C_DOTTED_CIRCLE, prev, tagArray1);
0N/A
0N/A output.writeMbelow();
0N/A output.writeSMbelow();
0N/A output.writeMabove();
0N/A
0N/A if ((classTable->scriptFlags & SF_MATRAS_AFTER_BASE) != 0) {
0N/A output.writeMpost();
0N/A }
0N/A
0N/A if ((classTable->scriptFlags & SF_REPH_AFTER_BELOW) != 0) {
0N/A output.writeVMabove();
0N/A output.writeSMabove(); // FIXME: there are no SM's in these scripts...
0N/A }
0N/A
0N/A if ((classTable->scriptFlags & SF_MATRAS_AFTER_BASE) == 0) {
0N/A output.writeMpost();
0N/A }
0N/A
0N/A output.writeLengthMark();
3171N/A output.writeAlLakuna();
0N/A
0N/A if ((classTable->scriptFlags & SF_REPH_AFTER_BELOW) == 0) {
0N/A output.writeVMabove();
0N/A output.writeSMabove();
0N/A }
0N/A
0N/A output.writeVMpost();
0N/A break;
0N/A
0N/A case CC_INDEPENDENT_VOWEL_2:
0N/A case CC_INDEPENDENT_VOWEL_3:
0N/A case CC_CONSONANT:
0N/A case CC_CONSONANT_WITH_NUKTA:
0N/A {
0N/A le_uint32 length = markStart - prev;
0N/A le_int32 lastConsonant = markStart - 1;
0N/A le_int32 baseLimit = prev;
0N/A
0N/A // Check for REPH at front of syllable
3171N/A if (length > 2 && classTable->isReph(chars[prev]) && classTable->isVirama(chars[prev + 1]) && chars[prev + 2] != C_SIGN_ZWNJ) {
0N/A baseLimit += 2;
0N/A
0N/A // Check for eyelash RA, if the script supports it
0N/A if ((classTable->scriptFlags & SF_EYELASH_RA) != 0 &&
0N/A chars[baseLimit] == C_SIGN_ZWJ) {
0N/A if (length > 3) {
0N/A baseLimit += 1;
0N/A } else {
0N/A baseLimit -= 2;
0N/A }
0N/A }
0N/A }
0N/A
0N/A while (lastConsonant > baseLimit && !classTable->isConsonant(chars[lastConsonant])) {
0N/A lastConsonant -= 1;
0N/A }
0N/A
3171N/A
3171N/A IndicClassTable::CharClass charClass = CC_RESERVED;
3171N/A IndicClassTable::CharClass nextClass = CC_RESERVED;
0N/A le_int32 baseConsonant = lastConsonant;
0N/A le_int32 postBase = lastConsonant + 1;
0N/A le_int32 postBaseLimit = classTable->scriptFlags & SF_POST_BASE_LIMIT_MASK;
0N/A le_bool seenVattu = FALSE;
0N/A le_bool seenBelowBaseForm = FALSE;
3171N/A le_bool seenPreBaseForm = FALSE;
3171N/A le_bool hasNukta = FALSE;
3171N/A le_bool hasBelowBaseForm = FALSE;
3171N/A le_bool hasPostBaseForm = FALSE;
3171N/A le_bool hasPreBaseForm = FALSE;
0N/A
0N/A if (postBase < markStart && classTable->isNukta(chars[postBase])) {
3171N/A charClass = CC_NUKTA;
0N/A postBase += 1;
0N/A }
0N/A
0N/A while (baseConsonant > baseLimit) {
3171N/A nextClass = charClass;
3171N/A hasNukta = IndicClassTable::isNukta(nextClass);
3171N/A charClass = classTable->getCharClass(chars[baseConsonant]);
3171N/A
3171N/A hasBelowBaseForm = IndicClassTable::hasBelowBaseForm(charClass) && !hasNukta;
3171N/A hasPostBaseForm = IndicClassTable::hasPostBaseForm(charClass) && !hasNukta;
3171N/A hasPreBaseForm = IndicClassTable::hasPreBaseForm(charClass) && !hasNukta;
0N/A
0N/A if (IndicClassTable::isConsonant(charClass)) {
0N/A if (postBaseLimit == 0 || seenVattu ||
0N/A (baseConsonant > baseLimit && !classTable->isVirama(chars[baseConsonant - 1])) ||
3171N/A !(hasBelowBaseForm || hasPostBaseForm || hasPreBaseForm)) {
0N/A break;
0N/A }
0N/A
3171N/A // Note any pre-base consonants
3171N/A if ( baseConsonant == lastConsonant && lastConsonant > 0 &&
3171N/A hasPreBaseForm && classTable->isVirama(chars[baseConsonant - 1])) {
3171N/A output.notePreBaseConsonant(lastConsonant,chars[lastConsonant],chars[lastConsonant-1],tagArray2);
3171N/A seenPreBaseForm = TRUE;
0N/A
3171N/A }
3171N/A // consonants with nuktas are never vattus
3171N/A seenVattu = IndicClassTable::isVattu(charClass) && !hasNukta;
3171N/A
3171N/A // consonants with nuktas never have below- or post-base forms
3171N/A if (hasPostBaseForm) {
0N/A if (seenBelowBaseForm) {
0N/A break;
0N/A }
0N/A
0N/A postBase = baseConsonant;
3171N/A } else if (hasBelowBaseForm) {
0N/A seenBelowBaseForm = TRUE;
0N/A }
0N/A
0N/A postBaseLimit -= 1;
0N/A }
0N/A
0N/A baseConsonant -= 1;
0N/A }
0N/A
0N/A // Write Mpre
0N/A output.writeMpre();
0N/A
0N/A // Write eyelash RA
0N/A // NOTE: baseLimit == prev + 3 iff eyelash RA present...
0N/A if (baseLimit == prev + 3) {
0N/A output.writeChar(chars[prev], prev, tagArray2);
0N/A output.writeChar(chars[prev + 1], prev + 1, tagArray2);
0N/A output.writeChar(chars[prev + 2], prev + 2, tagArray2);
0N/A }
0N/A
0N/A // write any pre-base consonants
3171N/A output.writePreBaseConsonant();
3171N/A
0N/A le_bool supressVattu = TRUE;
0N/A
0N/A for (i = baseLimit; i < baseConsonant; i += 1) {
0N/A LEUnicode ch = chars[i];
3171N/A // Don't put 'pstf' or 'blwf' on anything before the base consonant.
3171N/A FeatureMask features = tagArray1 & ~( pstfFeatureMask | blwfFeatureMask );
3171N/A
3171N/A charClass = classTable->getCharClass(ch);
3171N/A nextClass = classTable->getCharClass(chars[i + 1]);
3171N/A hasNukta = IndicClassTable::isNukta(nextClass);
0N/A
0N/A if (IndicClassTable::isConsonant(charClass)) {
3171N/A if (IndicClassTable::isVattu(charClass) && !hasNukta && supressVattu) {
0N/A features = tagArray4;
0N/A }
0N/A
3171N/A supressVattu = IndicClassTable::isVattu(charClass) && !hasNukta;
0N/A } else if (IndicClassTable::isVirama(charClass) && chars[i + 1] == C_SIGN_ZWNJ)
0N/A {
0N/A features = tagArray4;
0N/A }
0N/A
0N/A output.writeChar(ch, i, features);
0N/A }
0N/A
0N/A le_int32 bcSpan = baseConsonant + 1;
0N/A
0N/A if (bcSpan < markStart && classTable->isNukta(chars[bcSpan])) {
0N/A bcSpan += 1;
0N/A }
0N/A
3171N/A if (baseConsonant == lastConsonant && bcSpan < markStart &&
3171N/A (classTable->isVirama(chars[bcSpan]) || classTable->isAlLakuna(chars[bcSpan]))) {
0N/A bcSpan += 1;
0N/A
0N/A if (bcSpan < markStart && chars[bcSpan] == C_SIGN_ZWNJ) {
0N/A bcSpan += 1;
0N/A }
0N/A }
0N/A
0N/A // note the base consonant for post-GSUB fixups
0N/A output.noteBaseConsonant();
0N/A
0N/A // write base consonant
0N/A for (i = baseConsonant; i < bcSpan; i += 1) {
0N/A output.writeChar(chars[i], i, tagArray4);
0N/A }
0N/A
0N/A if ((classTable->scriptFlags & SF_MATRAS_AFTER_BASE) != 0) {
0N/A output.writeMbelow();
0N/A output.writeSMbelow(); // FIXME: there are no SMs in these scripts...
0N/A output.writeMabove();
0N/A output.writeMpost();
0N/A }
0N/A
0N/A // write below-base consonants
3171N/A if (baseConsonant != lastConsonant && !seenPreBaseForm) {
0N/A for (i = bcSpan + 1; i < postBase; i += 1) {
0N/A output.writeChar(chars[i], i, tagArray1);
0N/A }
0N/A
0N/A if (postBase > lastConsonant) {
0N/A // write halant that was after base consonant
0N/A output.writeChar(chars[bcSpan], bcSpan, tagArray1);
0N/A }
0N/A }
0N/A
0N/A // write Mbelow, SMbelow, Mabove
0N/A if ((classTable->scriptFlags & SF_MATRAS_AFTER_BASE) == 0) {
0N/A output.writeMbelow();
0N/A output.writeSMbelow();
0N/A output.writeMabove();
0N/A }
0N/A
0N/A if ((classTable->scriptFlags & SF_REPH_AFTER_BELOW) != 0) {
0N/A if (baseLimit == prev + 2) {
0N/A output.writeChar(chars[prev], prev, tagArray0);
0N/A output.writeChar(chars[prev + 1], prev + 1, tagArray0);
0N/A }
0N/A
0N/A output.writeVMabove();
0N/A output.writeSMabove(); // FIXME: there are no SM's in these scripts...
0N/A }
0N/A
0N/A // write post-base consonants
0N/A // FIXME: does this put the right tags on post-base consonants?
3171N/A if (baseConsonant != lastConsonant && !seenPreBaseForm) {
0N/A if (postBase <= lastConsonant) {
0N/A for (i = postBase; i <= lastConsonant; i += 1) {
0N/A output.writeChar(chars[i], i, tagArray3);
0N/A }
0N/A
0N/A // write halant that was after base consonant
0N/A output.writeChar(chars[bcSpan], bcSpan, tagArray1);
0N/A }
0N/A
0N/A // write the training halant, if there is one
0N/A if (lastConsonant < matra && classTable->isVirama(chars[matra])) {
0N/A output.writeChar(chars[matra], matra, tagArray4);
0N/A }
0N/A }
0N/A
0N/A // write Mpost
0N/A if ((classTable->scriptFlags & SF_MATRAS_AFTER_BASE) == 0) {
0N/A output.writeMpost();
0N/A }
0N/A
0N/A output.writeLengthMark();
3171N/A output.writeAlLakuna();
0N/A
0N/A // write reph
0N/A if ((classTable->scriptFlags & SF_REPH_AFTER_BELOW) == 0) {
0N/A if (baseLimit == prev + 2) {
0N/A output.writeChar(chars[prev], prev, tagArray0);
0N/A output.writeChar(chars[prev + 1], prev + 1, tagArray0);
0N/A }
0N/A
0N/A output.writeVMabove();
0N/A output.writeSMabove();
0N/A }
0N/A
0N/A output.writeVMpost();
0N/A
0N/A break;
0N/A }
0N/A
0N/A default:
0N/A break;
0N/A }
0N/A
0N/A prev = syllable;
0N/A }
0N/A
0N/A *outMPreFixups = mpreFixups;
0N/A
0N/A return output.getOutputIndex();
0N/A}
0N/A
3171N/Avoid IndicReordering::adjustMPres(MPreFixups *mpreFixups, LEGlyphStorage &glyphStorage, LEErrorCode& success)
0N/A{
0N/A if (mpreFixups != NULL) {
3171N/A mpreFixups->apply(glyphStorage, success);
0N/A
0N/A delete mpreFixups;
0N/A }
0N/A}
1693N/A
3171N/Avoid IndicReordering::applyPresentationForms(LEGlyphStorage &glyphStorage, le_int32 count)
3171N/A{
3171N/A LEErrorCode success = LE_NO_ERROR;
3171N/A
3171N/A// This sets us up for 2nd pass of glyph substitution as well as setting the feature masks for the
3171N/A// GPOS table lookups
3171N/A
3171N/A for ( le_int32 i = 0 ; i < count ; i++ ) {
3171N/A glyphStorage.setAuxData(i, ( presentationFormsMask | positioningFormsMask ), success);
3171N/A }
3171N/A
3171N/A}
3171N/Avoid IndicReordering::finalReordering(LEGlyphStorage &glyphStorage, le_int32 count)
3171N/A{
3171N/A LEErrorCode success = LE_NO_ERROR;
3171N/A
3171N/A // Reposition REPH as appropriate
3171N/A
3171N/A for ( le_int32 i = 0 ; i < count ; i++ ) {
3171N/A
3171N/A le_int32 tmpAuxData = glyphStorage.getAuxData(i,success);
3171N/A LEGlyphID tmpGlyph = glyphStorage.getGlyphID(i,success);
3171N/A
3171N/A if ( ( tmpGlyph != NO_GLYPH ) && (tmpAuxData & rephConsonantMask) && !(tmpAuxData & repositionedGlyphMask)) {
3171N/A
3171N/A le_bool targetPositionFound = false;
3171N/A le_int32 targetPosition = i+1;
3171N/A le_int32 baseConsonantData;
3171N/A
3171N/A while (!targetPositionFound) {
3171N/A tmpGlyph = glyphStorage.getGlyphID(targetPosition,success);
3171N/A tmpAuxData = glyphStorage.getAuxData(targetPosition,success);
3171N/A
3171N/A if ( tmpAuxData & baseConsonantMask ) {
3171N/A baseConsonantData = tmpAuxData;
3171N/A targetPositionFound = true;
3171N/A } else {
3171N/A targetPosition++;
3171N/A }
3171N/A }
3171N/A
3171N/A // Make sure we are not putting the reph into an empty hole
3171N/A
3171N/A le_bool targetPositionHasGlyph = false;
3171N/A while (!targetPositionHasGlyph) {
3171N/A tmpGlyph = glyphStorage.getGlyphID(targetPosition,success);
3171N/A if ( tmpGlyph != NO_GLYPH ) {
3171N/A targetPositionHasGlyph = true;
3171N/A } else {
3171N/A targetPosition--;
3171N/A }
3171N/A }
3171N/A
3171N/A // Make sure that REPH is positioned after any above base or post base matras
3171N/A //
3171N/A le_bool checkMatraDone = false;
3171N/A le_int32 checkMatraPosition = targetPosition+1;
3171N/A while ( !checkMatraDone ) {
3171N/A tmpAuxData = glyphStorage.getAuxData(checkMatraPosition,success);
3171N/A if ( checkMatraPosition >= count || ( (tmpAuxData ^ baseConsonantData) & LE_GLYPH_GROUP_MASK)) {
3171N/A checkMatraDone = true;
3171N/A continue;
3171N/A }
3171N/A if ( (tmpAuxData & matraMask) &&
3171N/A (((tmpAuxData & markPositionMask) == aboveBasePosition) ||
3171N/A ((tmpAuxData & markPositionMask) == postBasePosition))) {
3171N/A targetPosition = checkMatraPosition;
3171N/A }
3171N/A checkMatraPosition++;
3171N/A }
3171N/A
3171N/A glyphStorage.moveGlyph(i,targetPosition,repositionedGlyphMask);
3171N/A }
3171N/A }
3171N/A}
3171N/A
3171N/A
3171N/Ale_int32 IndicReordering::v2process(const LEUnicode *chars, le_int32 charCount, le_int32 scriptCode,
3171N/A LEUnicode *outChars, LEGlyphStorage &glyphStorage)
3171N/A{
3171N/A const IndicClassTable *classTable = IndicClassTable::getScriptClassTable(scriptCode);
3171N/A
3171N/A DynamicProperties dynProps[INDIC_BLOCK_SIZE];
3171N/A IndicReordering::getDynamicProperties(dynProps,classTable);
3171N/A
3171N/A IndicReorderingOutput output(outChars, glyphStorage, NULL);
3171N/A le_int32 i, firstConsonant, baseConsonant, secondConsonant, inv_count = 0, beginSyllable = 0;
3171N/A //le_bool lastInWord = FALSE;
3171N/A
3171N/A while (beginSyllable < charCount) {
3171N/A le_int32 nextSyllable = findSyllable(classTable, chars, beginSyllable, charCount);
3171N/A
3171N/A output.reset();
3171N/A
3171N/A // Find the First Consonant
3171N/A for ( firstConsonant = beginSyllable ; firstConsonant < nextSyllable ; firstConsonant++ ) {
3171N/A if ( classTable->isConsonant(chars[firstConsonant]) ) {
3171N/A break;
3171N/A }
3171N/A }
3171N/A
3171N/A // Find the base consonant
3171N/A
3171N/A baseConsonant = nextSyllable - 1;
3171N/A secondConsonant = firstConsonant;
3171N/A
3171N/A // TODO: Use Dynamic Properties for hasBelowBaseForm and hasPostBaseForm()
3171N/A
3171N/A while ( baseConsonant > firstConsonant ) {
3171N/A if ( classTable->isConsonant(chars[baseConsonant]) &&
3171N/A !classTable->hasBelowBaseForm(chars[baseConsonant]) &&
3171N/A !classTable->hasPostBaseForm(chars[baseConsonant]) ) {
3171N/A break;
3171N/A }
3171N/A else {
3171N/A if ( classTable->isConsonant(chars[baseConsonant]) ) {
3171N/A secondConsonant = baseConsonant;
3171N/A }
3171N/A baseConsonant--;
3171N/A }
3171N/A }
3171N/A
3171N/A // If the syllable starts with Ra + Halant ( in a script that has Reph ) and has more than one
3171N/A // consonant, Ra is excluced from candidates for base consonants
3171N/A
3171N/A if ( classTable->isReph(chars[beginSyllable]) &&
3171N/A beginSyllable+1 < nextSyllable && classTable->isVirama(chars[beginSyllable+1]) &&
3171N/A secondConsonant != firstConsonant) {
3171N/A baseConsonant = secondConsonant;
3171N/A }
3171N/A
3171N/A // Populate the output
3171N/A for ( i = beginSyllable ; i < nextSyllable ; i++ ) {
3171N/A
3171N/A // Handle invalid combinartions
3171N/A
3171N/A if ( classTable->isVirama(chars[beginSyllable]) ||
3171N/A classTable->isMatra(chars[beginSyllable]) ||
3171N/A classTable->isVowelModifier(chars[beginSyllable]) ||
3171N/A classTable->isNukta(chars[beginSyllable]) ) {
3171N/A output.writeChar(C_DOTTED_CIRCLE,beginSyllable,basicShapingFormsMask);
3171N/A inv_count++;
3171N/A }
3171N/A output.writeChar(chars[i],i, basicShapingFormsMask);
3171N/A
3171N/A }
3171N/A
3171N/A // Adjust features and set syllable structure bits
3171N/A
3171N/A for ( i = beginSyllable ; i < nextSyllable ; i++ ) {
3171N/A
3171N/A FeatureMask outMask = output.getFeatures(i+inv_count);
3171N/A FeatureMask saveMask = outMask;
3171N/A
3171N/A // Since reph can only validly occur at the beginning of a syllable
3171N/A // We only apply it to the first 2 characters in the syllable, to keep it from
3171N/A // conflicting with other features ( i.e. rkrf )
3171N/A
3171N/A // TODO : Use the dynamic property for determining isREPH
3171N/A if ( i == beginSyllable && i < baseConsonant && classTable->isReph(chars[i]) &&
3171N/A i+1 < nextSyllable && classTable->isVirama(chars[i+1])) {
3171N/A outMask |= rphfFeatureMask;
3171N/A outMask |= rephConsonantMask;
3171N/A output.setFeatures(i+1+inv_count,outMask);
3171N/A
3171N/A }
3171N/A
3171N/A if ( i == baseConsonant ) {
3171N/A outMask |= baseConsonantMask;
3171N/A }
3171N/A
3171N/A if ( classTable->isMatra(chars[i])) {
3171N/A outMask |= matraMask;
3171N/A if ( classTable->hasAboveBaseForm(chars[i])) {
3171N/A outMask |= aboveBasePosition;
3171N/A } else if ( classTable->hasBelowBaseForm(chars[i])) {
3171N/A outMask |= belowBasePosition;
3171N/A }
3171N/A }
3171N/A
3171N/A // Don't apply half form to virama that stands alone at the end of a syllable
3171N/A // to prevent half forms from forming when syllable ends with virama
3171N/A
3171N/A if ( classTable->isVirama(chars[i]) && (i+1 == nextSyllable) ) {
3171N/A outMask ^= halfFeatureMask;
3171N/A if ( classTable->isConsonant(chars[i-1]) ) {
3171N/A FeatureMask tmp = output.getFeatures(i-1+inv_count);
3171N/A tmp ^= halfFeatureMask;
3171N/A output.setFeatures(i-1+inv_count,tmp);
3171N/A }
3171N/A }
3171N/A
3171N/A if ( outMask != saveMask ) {
3171N/A output.setFeatures(i+inv_count,outMask);
3171N/A }
3171N/A }
3171N/A
3171N/A output.decomposeReorderMatras(classTable,beginSyllable,nextSyllable,inv_count);
3171N/A
3171N/A beginSyllable = nextSyllable;
3171N/A }
3171N/A
3171N/A
3171N/A return output.getOutputIndex();
3171N/A}
3171N/A
3171N/A
3171N/Avoid IndicReordering::getDynamicProperties( DynamicProperties *, const IndicClassTable *classTable ) {
3171N/A
3171N/A
3171N/A LEUnicode currentChar;
3171N/A LEUnicode workChars[2];
3171N/A LEGlyphStorage workGlyphs;
3171N/A
3171N/A IndicReorderingOutput workOutput(workChars, workGlyphs, NULL);
3171N/A
3171N/A //le_int32 offset = 0;
3171N/A
5891N/A#if 0
5891N/A// TODO: Should this section of code have actually been doing something?
3171N/A // First find the relevant virama for the script we are dealing with
5891N/A LEUnicode virama;
3171N/A for ( currentChar = classTable->firstChar ; currentChar <= classTable->lastChar ; currentChar++ ) {
3171N/A if ( classTable->isVirama(currentChar)) {
3171N/A virama = currentChar;
3171N/A break;
3171N/A }
3171N/A }
5891N/A#endif
3171N/A
3171N/A for ( currentChar = classTable->firstChar ; currentChar <= classTable->lastChar ; currentChar++ ) {
3171N/A if ( classTable->isConsonant(currentChar)) {
3171N/A workOutput.reset();
3171N/A }
3171N/A }
3171N/A
3171N/A
3171N/A}
3171N/A
1693N/AU_NAMESPACE_END