Revert "Imported Upstream version 1.2.7"
[platform/upstream/harfbuzz.git] / src / hb-graphite2.cc
index c32318d..807c330 100644 (file)
@@ -138,9 +138,6 @@ _hb_graphite2_shaper_face_data_destroy (hb_graphite2_shaper_face_data_t *data)
   free (data);
 }
 
-/*
- * Since: 0.9.10
- */
 gr_face *
 hb_graphite2_face_get_gr_face (hb_face_t *face)
 {
@@ -175,9 +172,6 @@ _hb_graphite2_shaper_font_data_destroy (hb_graphite2_shaper_font_data_t *data)
   gr_font_destroy (data);
 }
 
-/*
- * Since: 0.9.10
- */
 gr_font *
 hb_graphite2_font_get_gr_font (hb_font_t *font)
 {
@@ -216,7 +210,6 @@ struct hb_graphite2_cluster_t {
   unsigned int base_glyph;
   unsigned int num_glyphs;
   unsigned int cluster;
-  float advance;
 };
 
 hb_bool_t
@@ -235,11 +228,12 @@ _hb_graphite2_shape (hb_shape_plan_t    *shape_plan,
   int lang_len = lang_end ? lang_end - lang : -1;
   gr_feature_val *feats = gr_face_featureval_for_lang (grface, lang ? hb_tag_from_string (lang, lang_len) : 0);
 
-  for (unsigned int i = 0; i < num_features; i++)
+  while (num_features--)
   {
-    const gr_feature_ref *fref = gr_face_find_fref (grface, features[i].tag);
+    const gr_feature_ref *fref = gr_face_find_fref (grface, features->tag);
     if (fref)
-      gr_fref_set_feature_value (fref, features[i].value, feats);
+      gr_fref_set_feature_value (fref, features->value, feats);
+    features++;
   }
 
   gr_segment *seg = NULL;
@@ -255,8 +249,6 @@ _hb_graphite2_shape (hb_shape_plan_t    *shape_plan,
   for (unsigned int i = 0; i < buffer->len; ++i)
     chars[i] = buffer->info[i].codepoint;
 
-  /* TODO ensure_native_direction. */
-
   hb_tag_t script_tag[2];
   hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script_tag[1]);
 
@@ -275,11 +267,9 @@ _hb_graphite2_shape (hb_shape_plan_t    *shape_plan,
   if (unlikely (!glyph_count)) {
     if (feats) gr_featureval_destroy (feats);
     gr_seg_destroy (seg);
-    buffer->len = 0;
-    return true;
+    return false;
   }
 
-  buffer->ensure (glyph_count);
   scratch = buffer->get_scratch_buffer (&scratch_size);
   while ((DIV_CEIL (sizeof (hb_graphite2_cluster_t) * buffer->len, sizeof (*scratch)) +
          DIV_CEIL (sizeof (hb_codepoint_t) * glyph_count, sizeof (*scratch))) > scratch_size)
@@ -311,12 +301,6 @@ _hb_graphite2_shape (hb_shape_plan_t    *shape_plan,
 
   hb_codepoint_t *pg = gids;
   clusters[0].cluster = buffer->info[0].cluster;
-  float curradv = HB_DIRECTION_IS_BACKWARD(buffer->props.direction) ? gr_slot_origin_X(gr_seg_first_slot(seg)) : 0.;
-  if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
-  {
-    curradv = gr_slot_origin_X(gr_seg_first_slot(seg));
-    clusters[0].advance = gr_seg_advance_X(seg) - curradv;
-  }
   for (is = gr_seg_first_slot (seg), ic = 0; is; is = gr_slot_next_in_segment (is), ic++)
   {
     unsigned int before = gr_slot_before (is);
@@ -327,7 +311,6 @@ _hb_graphite2_shape (hb_shape_plan_t    *shape_plan,
     {
       clusters[ci-1].num_chars += clusters[ci].num_chars;
       clusters[ci-1].num_glyphs += clusters[ci].num_glyphs;
-      clusters[ci-1].advance += clusters[ci].advance;
       ci--;
     }
 
@@ -339,26 +322,16 @@ _hb_graphite2_shape (hb_shape_plan_t    *shape_plan,
       c->num_chars = before - c->base_char;
       c->base_glyph = ic;
       c->num_glyphs = 0;
-      if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
-      {
-        ci++;
-        clusters[ci].advance = curradv - gr_slot_origin_X(is);
-      } else {
-        clusters[ci].advance = gr_slot_origin_X(is) - curradv;
-        ci++;
-      }
-      curradv = gr_slot_origin_X(is);
+      ci++;
     }
     clusters[ci].num_glyphs++;
 
     if (clusters[ci].base_char + clusters[ci].num_chars < after + 1)
        clusters[ci].num_chars = after + 1 - clusters[ci].base_char;
   }
-
-  if (!HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
-    clusters[ci].advance = gr_seg_advance_X(seg) - curradv;
   ci++;
 
+  //buffer->clear_output ();
   for (unsigned int i = 0; i < ci; ++i)
   {
     for (unsigned int j = 0; j < clusters[i].num_glyphs; ++j)
@@ -366,57 +339,35 @@ _hb_graphite2_shape (hb_shape_plan_t    *shape_plan,
       hb_glyph_info_t *info = &buffer->info[clusters[i].base_glyph + j];
       info->codepoint = gids[clusters[i].base_glyph + j];
       info->cluster = clusters[i].cluster;
-      info->var1.i32 = clusters[i].advance;     // all glyphs in the cluster get the same advance
     }
   }
   buffer->len = glyph_count;
+  //buffer->swap_buffers ();
 
-  float yscale = font->y_scale / font->x_scale;
-  /* Positioning. */
-  if (!HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
+  if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
+    curradvx = gr_seg_advance_X(seg);
+
+  hb_glyph_position_t *pPos;
+  for (pPos = hb_buffer_get_glyph_positions (buffer, NULL), is = gr_seg_first_slot (seg);
+       is; pPos++, is = gr_slot_next_in_segment (is))
   {
-    int currclus = -1;
-    const hb_glyph_info_t *info = buffer->info;
-    hb_glyph_position_t *pPos = hb_buffer_get_glyph_positions (buffer, NULL);
-    curradvx = 0;
-    for (is = gr_seg_first_slot (seg); is; pPos++, ++info, is = gr_slot_next_in_segment (is))
-    {
-      pPos->x_offset = gr_slot_origin_X (is) - curradvx;
-      pPos->y_offset = gr_slot_origin_Y (is) * yscale - curradvy;
-      if (info->cluster != currclus) {
-        pPos->x_advance = info->var1.i32;
-        curradvx += pPos->x_advance;
-        currclus = info->cluster;
-      } else
-        pPos->x_advance = 0.;
-
-      pPos->y_advance = gr_slot_advance_Y (is, grface, grfont) * yscale;
-      curradvy += pPos->y_advance;
-    }
+    pPos->x_offset = gr_slot_origin_X (is) - curradvx;
+    pPos->y_offset = gr_slot_origin_Y (is) - curradvy;
+    pPos->x_advance = gr_slot_advance_X (is, grface, grfont);
+    pPos->y_advance = gr_slot_advance_Y (is, grface, grfont);
+    if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
+      curradvx -= pPos->x_advance;
+    pPos->x_offset = gr_slot_origin_X (is) - curradvx;
+    if (!HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
+      curradvx += pPos->x_advance;
+    pPos->y_offset = gr_slot_origin_Y (is) - curradvy;
+    curradvy += pPos->y_advance;
   }
-  else
-  {
-    int currclus = -1;
-    const hb_glyph_info_t *info = buffer->info;
-    hb_glyph_position_t *pPos = hb_buffer_get_glyph_positions (buffer, NULL);
-    curradvx = gr_seg_advance_X(seg);
-    for (is = gr_seg_first_slot (seg); is; pPos++, info++, is = gr_slot_next_in_segment (is))
-    {
-      if (info->cluster != currclus)
-      {
-        pPos->x_advance = info->var1.i32;
-        if (currclus != -1) curradvx -= info[-1].var1.i32;
-        currclus = info->cluster;
-      } else
-      pPos->x_advance = 0.;
-
-      pPos->y_advance = gr_slot_advance_Y (is, grface, grfont) * yscale;
-      curradvy -= pPos->y_advance;
-      pPos->x_offset = gr_slot_origin_X (is) - curradvx + pPos->x_advance;
-      pPos->y_offset = gr_slot_origin_Y (is) * yscale - curradvy;
-    }
+  if (!HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
+    pPos[-1].x_advance += gr_seg_advance_X(seg) - curradvx;
+
+  if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
     hb_buffer_reverse_clusters (buffer);
-  }
 
   if (feats) gr_featureval_destroy (feats);
   gr_seg_destroy (seg);