8ade12
Index: icu/trunk/source/layout/IndicReordering.cpp
8ade12
===================================================================
8ade12
--- icu/trunk/source/layout/IndicReordering.cpp	(revision 25772)
8ade12
+++ icu/trunk/source/layout/IndicReordering.cpp	(revision 26090)
8ade12
@@ -126,4 +126,8 @@
8ade12
     FeatureMask fSMFeatures;
8ade12
 
8ade12
+    LEUnicode   fPreBaseConsonant;
8ade12
+    LEUnicode   fPreBaseVirama;
8ade12
+    le_int32    fPBCIndex;
8ade12
+    FeatureMask fPBCFeatures;
8ade12
 
8ade12
     void saveMatra(LEUnicode matra, le_int32 matraIndex, IndicClassTable::CharClass matraClass)
8ade12
@@ -172,5 +176,6 @@
8ade12
           fMatraFeatures(0), fMPreOutIndex(-1), fMPreFixups(mpreFixups),
8ade12
           fVMabove(0), fVMpost(0), fVMIndex(0), fVMFeatures(0),
8ade12
-          fSMabove(0), fSMbelow(0), fSMIndex(0), fSMFeatures(0)
8ade12
+          fSMabove(0), fSMbelow(0), fSMIndex(0), fSMFeatures(0),
8ade12
+          fPreBaseConsonant(0), fPreBaseVirama(0), fPBCIndex(0), fPBCFeatures(0)
8ade12
     {
8ade12
         // nothing else to do...
8ade12
@@ -191,4 +196,6 @@
8ade12
         fVMabove = fVMpost  = 0;
8ade12
         fSMabove = fSMbelow = 0;
8ade12
+
8ade12
+        fPreBaseConsonant = fPreBaseVirama = 0;
8ade12
     }
8ade12
 
8ade12
@@ -386,4 +393,12 @@
8ade12
     }
8ade12
 
8ade12
+    void notePreBaseConsonant(le_uint32 index,LEUnicode PBConsonant, LEUnicode PBVirama, FeatureMask features)
8ade12
+    {
8ade12
+        fPBCIndex = index;
8ade12
+        fPreBaseConsonant = PBConsonant;
8ade12
+        fPreBaseVirama = PBVirama;
8ade12
+        fPBCFeatures = features;
8ade12
+    }
8ade12
+
8ade12
     void noteBaseConsonant()
8ade12
     {
8ade12
@@ -465,4 +480,20 @@
8ade12
     }
8ade12
     
8ade12
+    void writePreBaseConsonant()
8ade12
+    {
8ade12
+        // The TDIL spec says that consonant + virama + RRA should produce a rakar in Malayalam.  However,
8ade12
+        // it seems that almost none of the fonts for Malayalam are set up to handle this.
8ade12
+        // So, we're going to force the issue here by using the rakar as defined with RA in most fonts.
8ade12
+
8ade12
+        if (fPreBaseConsonant == 0x0d31) { // RRA
8ade12
+            fPreBaseConsonant = 0x0d30; // RA
8ade12
+        }
8ade12
+        
8ade12
+        if (fPreBaseConsonant != 0) {
8ade12
+            writeChar(fPreBaseConsonant, fPBCIndex, fPBCFeatures);
8ade12
+            writeChar(fPreBaseVirama,fPBCIndex-1,fPBCFeatures);
8ade12
+        }
8ade12
+    }
8ade12
+
8ade12
     le_int32 getOutputIndex()
8ade12
     {
8ade12
@@ -723,4 +754,5 @@
8ade12
             }
8ade12
 
8ade12
+            
8ade12
             IndicClassTable::CharClass charClass = CC_RESERVED;
8ade12
             IndicClassTable::CharClass nextClass = CC_RESERVED;
8ade12
@@ -730,7 +762,9 @@
8ade12
             le_bool  seenVattu = FALSE;
8ade12
             le_bool  seenBelowBaseForm = FALSE;
8ade12
+            le_bool  seenPreBaseForm = FALSE;
8ade12
             le_bool  hasNukta = FALSE;
8ade12
             le_bool  hasBelowBaseForm = FALSE;
8ade12
             le_bool  hasPostBaseForm = FALSE;
8ade12
+            le_bool  hasPreBaseForm = FALSE;
8ade12
 
8ade12
             if (postBase < markStart && classTable->isNukta(chars[postBase])) {
8ade12
@@ -746,12 +780,20 @@
8ade12
                 hasBelowBaseForm = IndicClassTable::hasBelowBaseForm(charClass) && !hasNukta;
8ade12
                 hasPostBaseForm  = IndicClassTable::hasPostBaseForm(charClass)  && !hasNukta;
8ade12
+                hasPreBaseForm = IndicClassTable::hasPreBaseForm(charClass) && !hasNukta;
8ade12
 
8ade12
                 if (IndicClassTable::isConsonant(charClass)) {
8ade12
                     if (postBaseLimit == 0 || seenVattu ||
8ade12
                         (baseConsonant > baseLimit && !classTable->isVirama(chars[baseConsonant - 1])) ||
8ade12
-                        !(hasBelowBaseForm || hasPostBaseForm)) {
8ade12
+                        !(hasBelowBaseForm || hasPostBaseForm || hasPreBaseForm)) {
8ade12
                         break;
8ade12
                     }
8ade12
 
8ade12
+                    // Note any pre-base consonants
8ade12
+                    if ( baseConsonant == lastConsonant && lastConsonant > 0 && 
8ade12
+                         hasPreBaseForm && classTable->isVirama(chars[baseConsonant - 1])) {
8ade12
+                        output.notePreBaseConsonant(lastConsonant,chars[lastConsonant],chars[lastConsonant-1],tagArray2);
8ade12
+                        seenPreBaseForm = TRUE;
8ade12
+   
8ade12
+                    }
8ade12
                     // consonants with nuktas are never vattus
8ade12
                     seenVattu = IndicClassTable::isVattu(charClass) && !hasNukta;
8ade12
@@ -786,10 +828,12 @@
8ade12
 
8ade12
             // write any pre-base consonants
8ade12
+            output.writePreBaseConsonant();
8ade12
+
8ade12
             le_bool supressVattu = TRUE;
8ade12
 
8ade12
             for (i = baseLimit; i < baseConsonant; i += 1) {
8ade12
                 LEUnicode ch = chars[i];
8ade12
-                // Don't put 'blwf' on first consonant.
8ade12
-                FeatureMask features = (i == baseLimit? tagArray2 : tagArray1);
8ade12
+                // Don't put 'pstf' or 'blwf' on anything before the base consonant.
8ade12
+                FeatureMask features = tagArray1 & ~( pstfFeatureMask | blwfFeatureMask );
8ade12
 
8ade12
                 charClass = classTable->getCharClass(ch);
8ade12
@@ -842,5 +886,5 @@
8ade12
 
8ade12
             // write below-base consonants
8ade12
-            if (baseConsonant != lastConsonant) {
8ade12
+            if (baseConsonant != lastConsonant && !seenPreBaseForm) {
8ade12
                 for (i = bcSpan + 1; i < postBase; i += 1) {
8ade12
                     output.writeChar(chars[i], i, tagArray1);
8ade12
@@ -872,5 +916,5 @@
8ade12
             // write post-base consonants
8ade12
             // FIXME: does this put the right tags on post-base consonants?
8ade12
-            if (baseConsonant != lastConsonant) {
8ade12
+            if (baseConsonant != lastConsonant && !seenPreBaseForm) {
8ade12
                 if (postBase <= lastConsonant) {
8ade12
                     for (i = postBase; i <= lastConsonant; i += 1) {