--- pango1.0-1.16.4.orig/modules/indic/indic-lang.c	2007-01-23 10:41:44.000000000 +1100
+++ pango1.0-1.16.4/modules/indic/indic-lang.c	2007-06-25 00:22:26.000000000 +1000
@@ -93,9 +93,16 @@
 {
   const gchar *p, *next = NULL, *next_next;
   gunichar prev_wc, this_wc, next_wc, next_next_wc;
-  gboolean makes_rephaya_syllable = FALSE;
+  gboolean is_conjunct = FALSE;
+  gboolean is_sinhala = FALSE;
   int i;
 
+  if (analysis->language
+      == pango_script_get_sample_language(PANGO_SCRIPT_SINHALA))
+  {
+    is_sinhala = TRUE;
+  }
+
   for (p = text, prev_wc = 0, i = 0;
        p != NULL && p < (text + length);
        p = next, prev_wc = this_wc, i++)
@@ -117,42 +124,50 @@
       else
 	next_next_wc = 0;
 
-      if (prev_wc != 0 && this_wc == 0x0DBB &&
-	  next_wc == 0x0DCA && next_next_wc == 0x200D)
-	{
-	  /* Determine whether or not this forms a Rephaya syllable.
-	   * SINHALA LETTER + U+0DBB U+0DCA U+200D + SINHALA LETTER is
-	   * the kind of Rephaya.
-	   */
-	  makes_rephaya_syllable = TRUE;
-	  attrs[i].is_cursor_position = FALSE;
-	  attrs[i].is_char_break = FALSE;
-	  attrs[i].is_line_break = FALSE;
-	  attrs[i].is_mandatory_break = FALSE;
-	}
-      else if (prev_wc == 0x200D &&
-		(makes_rephaya_syllable || this_wc == 0x0DBB || this_wc == 0x0DBA))
-	{
-	  /* fixes the cursor break in Sinhala.
-	   * SINHALA LETTER + SINHALA VOWEL + ZWJ + 0x0DBB/0x0DBA is
-	   * the kind of Rakaransaya/Yansaya. these characters has to
-	   * be dealt as one character.
-	   */
-	  attrs[i].is_cursor_position = FALSE;
-	  attrs[i].is_char_break = FALSE;
-	  attrs[i].is_line_break = FALSE;
-	  attrs[i].is_mandatory_break = FALSE;
-	  makes_rephaya_syllable = FALSE;
-	}
-      else if (this_wc == 0x200D &&
-		((makes_rephaya_syllable && next_wc != 0) ||
-		 (next_wc == 0x0DBB || next_wc == 0x0DBA)))
-	{
-	  attrs[i].is_cursor_position = FALSE;
-	  attrs[i].is_char_break = FALSE;
-	  attrs[i].is_line_break = FALSE;
-	  attrs[i].is_mandatory_break = FALSE;
-	}
+      /*
+       * TODO: The cursor position should be based on the state table.
+       *       This is the wrong place to be doing this.
+       */
+      if (is_sinhala)
+      {
+	/*
+	 * The cursor should treat as a single glyph:
+	 * SINHALA CONS + 0x0DCA + 0x200D + SINHALA CONS
+	 * SINHALA CONS + 0x200D + 0x0DCA + SINHALA CONS
+	 */
+	if ((this_wc == 0x0DCA && next_wc == 0x200D)
+	    || (this_wc == 0x200D && next_wc == 0x0DCA))
+	  {
+	    attrs[i].is_cursor_position = FALSE;
+	    attrs[i].is_char_break = FALSE;
+	    attrs[i].is_line_break = FALSE;
+	    attrs[i].is_mandatory_break = FALSE;
+	    attrs[i + 1].is_cursor_position = FALSE;
+	    attrs[i + 1].is_char_break = FALSE;
+	    attrs[i + 1].is_line_break = FALSE;
+	    attrs[i + 1].is_mandatory_break = FALSE;
+	    is_conjunct = TRUE;
+	  }
+	else if (is_conjunct
+		 && (prev_wc == 0x200D || prev_wc == 0x0DCA)
+		 && this_wc >= 0x0D9A
+		 && this_wc <= 0x0DC6)
+	  {
+	    attrs[i].is_cursor_position = FALSE;
+	    attrs[i].is_char_break = FALSE;
+	    attrs[i].is_line_break = FALSE;
+	    attrs[i].is_mandatory_break = FALSE;
+	    is_conjunct = FALSE;
+	  }
+	/*
+	 * Consonant clusters do NOT result in implicit conjuncts
+	 * in SINHALA orthography.
+	 */
+	else if (!is_conjunct && prev_wc == 0x0DCA && this_wc != 0x200D)
+	  {
+	    attrs[i].is_cursor_position = TRUE;
+	  }
+      }
       else if (prev_wc != 0 && (this_wc == 0x200D || this_wc == 0x200C))
 	{
 	  if (next_wc != 0)
@@ -180,8 +195,7 @@
 			next_wc == 0x0B4D ||	/* Oriya */
 			next_wc == 0x0A4D ||	/* Punjabi */
 			next_wc == 0x0BCD ||	/* Tamil */
-			next_wc == 0x0C4D ||	/* Telugu */
-			next_wc == 0x0DCA))  /*Sinhala*/
+			next_wc == 0x0C4D))	/* Telugu */
 		{
 		  attrs[i].is_cursor_position = FALSE;
 		  attrs[i].is_char_break = FALSE;
