Revert "Imported Upstream version 1.2.7"
[platform/upstream/harfbuzz.git] / src / hb-ot-shape-complex-myanmar.cc
index 545765d..d016380 100644 (file)
@@ -154,7 +154,7 @@ is_one_of (const hb_glyph_info_t &info, unsigned int flags)
 {
   /* If it ligated, all bets are off. */
   if (_hb_glyph_info_ligated (&info)) return false;
-  return !!(FLAG_SAFE (info.myanmar_category()) & flags);
+  return !!(FLAG (info.myanmar_category()) & flags);
 }
 
 static inline bool
@@ -199,10 +199,6 @@ set_myanmar_properties (hb_glyph_info_t &info)
       cat = (indic_category_t) OT_A;
       break;
 
-    case 0x1039u:
-      cat = (indic_category_t) OT_H;
-      break;
-
     case 0x103Au:
       cat = (indic_category_t) OT_As;
       break;
@@ -308,7 +304,9 @@ compare_myanmar_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb)
  * http://www.microsoft.com/typography/OpenTypeDev/myanmar/intro.htm */
 
 static void
-initial_reordering_consonant_syllable (hb_buffer_t *buffer,
+initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan,
+                                      hb_face_t *face,
+                                      hb_buffer_t *buffer,
                                       unsigned int start, unsigned int end)
 {
   hb_glyph_info_t *info = buffer->info;
@@ -395,10 +393,42 @@ initial_reordering_consonant_syllable (hb_buffer_t *buffer,
     }
   }
 
+  buffer->merge_clusters (start, end);
   /* Sit tight, rock 'n roll! */
-  buffer->sort (start, end, compare_myanmar_order);
+  hb_bubble_sort (info + start, end - start, compare_myanmar_order);
+}
+
+static void
+initial_reordering_broken_cluster (const hb_ot_shape_plan_t *plan,
+                                  hb_face_t *face,
+                                  hb_buffer_t *buffer,
+                                  unsigned int start, unsigned int end)
+{
+  /* We already inserted dotted-circles, so just call the consonant_syllable. */
+  initial_reordering_consonant_syllable (plan, face, buffer, start, end);
+}
+
+static void
+initial_reordering_punctuation_cluster (const hb_ot_shape_plan_t *plan HB_UNUSED,
+                                       hb_face_t *face HB_UNUSED,
+                                       hb_buffer_t *buffer HB_UNUSED,
+                                       unsigned int start HB_UNUSED, unsigned int end HB_UNUSED)
+{
+  /* Nothing to do right now.  If we ever switch to using the output
+   * buffer in the reordering process, we'd need to next_glyph() here. */
+}
+
+static void
+initial_reordering_non_myanmar_cluster (const hb_ot_shape_plan_t *plan HB_UNUSED,
+                                       hb_face_t *face HB_UNUSED,
+                                       hb_buffer_t *buffer HB_UNUSED,
+                                       unsigned int start HB_UNUSED, unsigned int end HB_UNUSED)
+{
+  /* Nothing to do right now.  If we ever switch to using the output
+   * buffer in the reordering process, we'd need to next_glyph() here. */
 }
 
+
 static void
 initial_reordering_syllable (const hb_ot_shape_plan_t *plan,
                             hb_face_t *face,
@@ -407,15 +437,10 @@ initial_reordering_syllable (const hb_ot_shape_plan_t *plan,
 {
   syllable_type_t syllable_type = (syllable_type_t) (buffer->info[start].syllable() & 0x0F);
   switch (syllable_type) {
-
-    case broken_cluster: /* We already inserted dotted-circles, so just call the consonant_syllable. */
-    case consonant_syllable:
-      initial_reordering_consonant_syllable  (buffer, start, end);
-      break;
-
-    case punctuation_cluster:
-    case non_myanmar_cluster:
-      break;
+  case consonant_syllable:     initial_reordering_consonant_syllable  (plan, face, buffer, start, end); return;
+  case punctuation_cluster:    initial_reordering_punctuation_cluster (plan, face, buffer, start, end); return;
+  case broken_cluster:         initial_reordering_broken_cluster      (plan, face, buffer, start, end); return;
+  case non_myanmar_cluster:    initial_reordering_non_myanmar_cluster (plan, face, buffer, start, end); return;
   }
 }
 
@@ -439,7 +464,7 @@ insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED,
 
 
   hb_codepoint_t dottedcircle_glyph;
-  if (!font->get_nominal_glyph (0x25CCu, &dottedcircle_glyph))
+  if (!font->get_glyph (0x25CCu, 0, &dottedcircle_glyph))
     return;
 
   hb_glyph_info_t dottedcircle = {0};
@@ -451,7 +476,7 @@ insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED,
 
   buffer->idx = 0;
   unsigned int last_syllable = 0;
-  while (buffer->idx < buffer->len && !buffer->in_error)
+  while (buffer->idx < buffer->len)
   {
     unsigned int syllable = buffer->cur().syllable();
     syllable_type_t syllable_type = (syllable_type_t) (syllable & 0x0F);
@@ -459,12 +484,12 @@ insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED,
     {
       last_syllable = syllable;
 
-      hb_glyph_info_t ginfo = dottedcircle;
-      ginfo.cluster = buffer->cur().cluster;
-      ginfo.mask = buffer->cur().mask;
-      ginfo.syllable() = buffer->cur().syllable();
+      hb_glyph_info_t info = dottedcircle;
+      info.cluster = buffer->cur().cluster;
+      info.mask = buffer->cur().mask;
+      info.syllable() = buffer->cur().syllable();
 
-      buffer->output_info (ginfo);
+      buffer->output_info (info);
     }
     else
       buffer->next_glyph ();
@@ -480,8 +505,18 @@ initial_reordering (const hb_ot_shape_plan_t *plan,
 {
   insert_dotted_circles (plan, font, buffer);
 
-  foreach_syllable (buffer, start, end)
-    initial_reordering_syllable (plan, font->face, buffer, start, end);
+  hb_glyph_info_t *info = buffer->info;
+  unsigned int count = buffer->len;
+  if (unlikely (!count)) return;
+  unsigned int last = 0;
+  unsigned int last_syllable = info[0].syllable();
+  for (unsigned int i = 1; i < count; i++)
+    if (last_syllable != info[i].syllable()) {
+      initial_reordering_syllable (plan, font->face, buffer, last, i);
+      last = i;
+      last_syllable = info[last].syllable();
+    }
+  initial_reordering_syllable (plan, font->face, buffer, last, count);
 }
 
 static void
@@ -511,7 +546,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar_old =
   NULL, /* data_create */
   NULL, /* data_destroy */
   NULL, /* preprocess_text */
-  NULL, /* postprocess_glyphs */
   HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT,
   NULL, /* decompose */
   NULL, /* compose */
@@ -528,7 +562,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar =
   NULL, /* data_create */
   NULL, /* data_destroy */
   NULL, /* preprocess_text */
-  NULL, /* postprocess_glyphs */
   HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT,
   NULL, /* decompose */
   NULL, /* compose */