Blame src/hb-ot-shape-complex-use.cc

Packit 874993
/*
Packit 874993
 * Copyright © 2015  Mozilla Foundation.
Packit 874993
 * Copyright © 2015  Google, Inc.
Packit 874993
 *
Packit 874993
 *  This is part of HarfBuzz, a text shaping library.
Packit 874993
 *
Packit 874993
 * Permission is hereby granted, without written agreement and without
Packit 874993
 * license or royalty fees, to use, copy, modify, and distribute this
Packit 874993
 * software and its documentation for any purpose, provided that the
Packit 874993
 * above copyright notice and the following two paragraphs appear in
Packit 874993
 * all copies of this software.
Packit 874993
 *
Packit 874993
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
Packit 874993
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
Packit 874993
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
Packit 874993
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
Packit 874993
 * DAMAGE.
Packit 874993
 *
Packit 874993
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
Packit 874993
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
Packit 874993
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
Packit 874993
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
Packit 874993
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
Packit 874993
 *
Packit 874993
 * Mozilla Author(s): Jonathan Kew
Packit 874993
 * Google Author(s): Behdad Esfahbod
Packit 874993
 */
Packit 874993
Packit 874993
#include "hb-ot-shape-complex-use-private.hh"
Packit 874993
#include "hb-ot-shape-complex-arabic-private.hh"
Packit 874993
Packit 874993
/* buffer var allocations */
Packit 874993
#define use_category() complex_var_u8_0()
Packit 874993
Packit 874993
Packit 874993
/*
Packit 874993
 * Universal Shaping Engine.
Packit 874993
 * https://www.microsoft.com/typography/OpenTypeDev/USE/intro.htm
Packit 874993
 */
Packit 874993
Packit 874993
static const hb_tag_t
Packit 874993
basic_features[] =
Packit 874993
{
Packit 874993
  /*
Packit 874993
   * Basic features.
Packit 874993
   * These features are applied all at once, before reordering.
Packit 874993
   */
Packit 874993
  HB_TAG('r','k','r','f'),
Packit 874993
  HB_TAG('a','b','v','f'),
Packit 874993
  HB_TAG('b','l','w','f'),
Packit 874993
  HB_TAG('h','a','l','f'),
Packit 874993
  HB_TAG('p','s','t','f'),
Packit 874993
  HB_TAG('v','a','t','u'),
Packit 874993
  HB_TAG('c','j','c','t'),
Packit 874993
};
Packit 874993
static const hb_tag_t
Packit 874993
arabic_features[] =
Packit 874993
{
Packit 874993
  HB_TAG('i','s','o','l'),
Packit 874993
  HB_TAG('i','n','i','t'),
Packit 874993
  HB_TAG('m','e','d','i'),
Packit 874993
  HB_TAG('f','i','n','a'),
Packit 874993
  /* The spec doesn't specify these but we apply anyway, since our Arabic shaper
Packit 874993
   * does.  These are only used in Syriac spec. */
Packit 874993
  HB_TAG('m','e','d','2'),
Packit 874993
  HB_TAG('f','i','n','2'),
Packit 874993
  HB_TAG('f','i','n','3'),
Packit 874993
};
Packit 874993
/* Same order as arabic_features.  Don't need Syriac stuff.*/
Packit 874993
enum joining_form_t {
Packit 874993
  ISOL,
Packit 874993
  INIT,
Packit 874993
  MEDI,
Packit 874993
  FINA,
Packit 874993
  _NONE
Packit 874993
};
Packit 874993
static const hb_tag_t
Packit 874993
other_features[] =
Packit 874993
{
Packit 874993
  /*
Packit 874993
   * Other features.
Packit 874993
   * These features are applied all at once, after reordering.
Packit 874993
   */
Packit 874993
  HB_TAG('a','b','v','s'),
Packit 874993
  HB_TAG('b','l','w','s'),
Packit 874993
  HB_TAG('h','a','l','n'),
Packit 874993
  HB_TAG('p','r','e','s'),
Packit 874993
  HB_TAG('p','s','t','s'),
Packit 874993
  /* Positioning features, though we don't care about the types. */
Packit 874993
  HB_TAG('d','i','s','t'),
Packit 874993
  HB_TAG('a','b','v','m'),
Packit 874993
  HB_TAG('b','l','w','m'),
Packit 874993
};
Packit 874993
Packit 874993
static void
Packit 874993
setup_syllables (const hb_ot_shape_plan_t *plan,
Packit 874993
		 hb_font_t *font,
Packit 874993
		 hb_buffer_t *buffer);
Packit 874993
static void
Packit 874993
clear_substitution_flags (const hb_ot_shape_plan_t *plan,
Packit 874993
			  hb_font_t *font,
Packit 874993
			  hb_buffer_t *buffer);
Packit 874993
static void
Packit 874993
record_rphf (const hb_ot_shape_plan_t *plan,
Packit 874993
	     hb_font_t *font,
Packit 874993
	     hb_buffer_t *buffer);
Packit 874993
static void
Packit 874993
record_pref (const hb_ot_shape_plan_t *plan,
Packit 874993
	     hb_font_t *font,
Packit 874993
	     hb_buffer_t *buffer);
Packit 874993
static void
Packit 874993
reorder (const hb_ot_shape_plan_t *plan,
Packit 874993
	 hb_font_t *font,
Packit 874993
	 hb_buffer_t *buffer);
Packit 874993
Packit 874993
static void
Packit 874993
collect_features_use (hb_ot_shape_planner_t *plan)
Packit 874993
{
Packit 874993
  hb_ot_map_builder_t *map = &plan->map;
Packit 874993
Packit 874993
  /* Do this before any lookups have been applied. */
Packit 874993
  map->add_gsub_pause (setup_syllables);
Packit 874993
Packit 874993
  /* "Default glyph pre-processing group" */
Packit 874993
  map->add_global_bool_feature (HB_TAG('l','o','c','l'));
Packit 874993
  map->add_global_bool_feature (HB_TAG('c','c','m','p'));
Packit 874993
  map->add_global_bool_feature (HB_TAG('n','u','k','t'));
Packit 874993
  map->add_global_bool_feature (HB_TAG('a','k','h','n'));
Packit 874993
Packit 874993
  /* "Reordering group" */
Packit 874993
  map->add_gsub_pause (clear_substitution_flags);
Packit 874993
  map->add_feature (HB_TAG('r','p','h','f'), 1, F_MANUAL_ZWJ);
Packit 874993
  map->add_gsub_pause (record_rphf);
Packit 874993
  map->add_gsub_pause (clear_substitution_flags);
Packit 874993
  map->add_feature (HB_TAG('p','r','e','f'), 1, F_GLOBAL | F_MANUAL_ZWJ);
Packit 874993
  map->add_gsub_pause (record_pref);
Packit 874993
Packit 874993
  /* "Orthographic unit shaping group" */
Packit 874993
  for (unsigned int i = 0; i < ARRAY_LENGTH (basic_features); i++)
Packit 874993
    map->add_feature (basic_features[i], 1, F_GLOBAL | F_MANUAL_ZWJ);
Packit 874993
Packit 874993
  map->add_gsub_pause (reorder);
Packit 874993
Packit 874993
  /* "Topographical features" */
Packit 874993
  for (unsigned int i = 0; i < ARRAY_LENGTH (arabic_features); i++)
Packit 874993
    map->add_feature (arabic_features[i], 1, F_NONE);
Packit 874993
  map->add_gsub_pause (NULL);
Packit 874993
Packit 874993
  /* "Standard typographic presentation" and "Positional feature application" */
Packit 874993
  for (unsigned int i = 0; i < ARRAY_LENGTH (other_features); i++)
Packit 874993
    map->add_feature (other_features[i], 1, F_GLOBAL | F_MANUAL_ZWJ);
Packit 874993
}
Packit 874993
Packit 874993
struct use_shape_plan_t
Packit 874993
{
Packit 874993
  ASSERT_POD ();
Packit 874993
Packit 874993
  hb_mask_t rphf_mask;
Packit 874993
Packit 874993
  arabic_shape_plan_t *arabic_plan;
Packit 874993
};
Packit 874993
Packit 874993
static bool
Packit 874993
has_arabic_joining (hb_script_t script)
Packit 874993
{
Packit 874993
  /* List of scripts that have data in arabic-table. */
Packit 874993
  switch ((int) script)
Packit 874993
  {
Packit 874993
    /* Unicode-1.1 additions */
Packit 874993
    case HB_SCRIPT_ARABIC:
Packit 874993
Packit 874993
    /* Unicode-3.0 additions */
Packit 874993
    case HB_SCRIPT_MONGOLIAN:
Packit 874993
    case HB_SCRIPT_SYRIAC:
Packit 874993
Packit 874993
    /* Unicode-5.0 additions */
Packit 874993
    case HB_SCRIPT_NKO:
Packit 874993
    case HB_SCRIPT_PHAGS_PA:
Packit 874993
Packit 874993
    /* Unicode-6.0 additions */
Packit 874993
    case HB_SCRIPT_MANDAIC:
Packit 874993
Packit 874993
    /* Unicode-7.0 additions */
Packit 874993
    case HB_SCRIPT_MANICHAEAN:
Packit 874993
    case HB_SCRIPT_PSALTER_PAHLAVI:
Packit 874993
Packit 874993
    /* Unicode-9.0 additions */
Packit 874993
    case HB_SCRIPT_ADLAM:
Packit 874993
Packit 874993
      return true;
Packit 874993
Packit 874993
    default:
Packit 874993
      return false;
Packit 874993
  }
Packit 874993
}
Packit 874993
Packit 874993
static void *
Packit 874993
data_create_use (const hb_ot_shape_plan_t *plan)
Packit 874993
{
Packit 874993
  use_shape_plan_t *use_plan = (use_shape_plan_t *) calloc (1, sizeof (use_shape_plan_t));
Packit 874993
  if (unlikely (!use_plan))
Packit 874993
    return NULL;
Packit 874993
Packit 874993
  use_plan->rphf_mask = plan->map.get_1_mask (HB_TAG('r','p','h','f'));
Packit 874993
Packit 874993
  if (has_arabic_joining (plan->props.script))
Packit 874993
  {
Packit 874993
    use_plan->arabic_plan = (arabic_shape_plan_t *) data_create_arabic (plan);
Packit 874993
    if (unlikely (!use_plan->arabic_plan))
Packit 874993
    {
Packit 874993
      free (use_plan);
Packit 874993
      return NULL;
Packit 874993
    }
Packit 874993
  }
Packit 874993
Packit 874993
  return use_plan;
Packit 874993
}
Packit 874993
Packit 874993
static void
Packit 874993
data_destroy_use (void *data)
Packit 874993
{
Packit 874993
  use_shape_plan_t *use_plan = (use_shape_plan_t *) data;
Packit 874993
Packit 874993
  if (use_plan->arabic_plan)
Packit 874993
    data_destroy_arabic (use_plan->arabic_plan);
Packit 874993
Packit 874993
  free (data);
Packit 874993
}
Packit 874993
Packit 874993
enum syllable_type_t {
Packit 874993
  independent_cluster,
Packit 874993
  virama_terminated_cluster,
Packit 874993
  standard_cluster,
Packit 874993
  number_joiner_terminated_cluster,
Packit 874993
  numeral_cluster,
Packit 874993
  symbol_cluster,
Packit 874993
  broken_cluster,
Packit 874993
  non_cluster,
Packit 874993
};
Packit 874993
Packit 874993
#include "hb-ot-shape-complex-use-machine.hh"
Packit 874993
Packit 874993
Packit 874993
static void
Packit 874993
setup_masks_use (const hb_ot_shape_plan_t *plan,
Packit 874993
		 hb_buffer_t              *buffer,
Packit 874993
		 hb_font_t                *font HB_UNUSED)
Packit 874993
{
Packit 874993
  const use_shape_plan_t *use_plan = (const use_shape_plan_t *) plan->data;
Packit 874993
Packit 874993
  /* Do this before allocating use_category(). */
Packit 874993
  if (use_plan->arabic_plan)
Packit 874993
  {
Packit 874993
    setup_masks_arabic_plan (use_plan->arabic_plan, buffer, plan->props.script);
Packit 874993
  }
Packit 874993
Packit 874993
  HB_BUFFER_ALLOCATE_VAR (buffer, use_category);
Packit 874993
Packit 874993
  /* We cannot setup masks here.  We save information about characters
Packit 874993
   * and setup masks later on in a pause-callback. */
Packit 874993
Packit 874993
  unsigned int count = buffer->len;
Packit 874993
  hb_glyph_info_t *info = buffer->info;
Packit 874993
  for (unsigned int i = 0; i < count; i++)
Packit 874993
    info[i].use_category() = hb_use_get_categories (info[i].codepoint);
Packit 874993
}
Packit 874993
Packit 874993
static void
Packit 874993
setup_rphf_mask (const hb_ot_shape_plan_t *plan,
Packit 874993
		 hb_buffer_t *buffer)
Packit 874993
{
Packit 874993
  const use_shape_plan_t *use_plan = (const use_shape_plan_t *) plan->data;
Packit 874993
Packit 874993
  hb_mask_t mask = use_plan->rphf_mask;
Packit 874993
  if (!mask) return;
Packit 874993
Packit 874993
  hb_glyph_info_t *info = buffer->info;
Packit 874993
Packit 874993
  foreach_syllable (buffer, start, end)
Packit 874993
  {
Packit 874993
    unsigned int limit = info[start].use_category() == USE_R ? 1 : MIN (3u, end - start);
Packit 874993
    for (unsigned int i = start; i < start + limit; i++)
Packit 874993
      info[i].mask |= mask;
Packit 874993
  }
Packit 874993
}
Packit 874993
Packit 874993
static void
Packit 874993
setup_topographical_masks (const hb_ot_shape_plan_t *plan,
Packit 874993
			   hb_buffer_t *buffer)
Packit 874993
{
Packit 874993
  const use_shape_plan_t *use_plan = (const use_shape_plan_t *) plan->data;
Packit 874993
  if (use_plan->arabic_plan)
Packit 874993
    return;
Packit 874993
Packit 874993
  ASSERT_STATIC (INIT < 4 && ISOL < 4 && MEDI < 4 && FINA < 4);
Packit 874993
  hb_mask_t masks[4], all_masks = 0;
Packit 874993
  for (unsigned int i = 0; i < 4; i++)
Packit 874993
  {
Packit 874993
    masks[i] = plan->map.get_1_mask (arabic_features[i]);
Packit 874993
    if (masks[i] == plan->map.get_global_mask ())
Packit 874993
      masks[i] = 0;
Packit 874993
    all_masks |= masks[i];
Packit 874993
  }
Packit 874993
  if (!all_masks)
Packit 874993
    return;
Packit 874993
  hb_mask_t other_masks = ~all_masks;
Packit 874993
Packit 874993
  unsigned int last_start = 0;
Packit 874993
  joining_form_t last_form = _NONE;
Packit 874993
  hb_glyph_info_t *info = buffer->info;
Packit 874993
  foreach_syllable (buffer, start, end)
Packit 874993
  {
Packit 874993
    syllable_type_t syllable_type = (syllable_type_t) (info[start].syllable() & 0x0F);
Packit 874993
    switch (syllable_type)
Packit 874993
    {
Packit 874993
      case independent_cluster:
Packit 874993
      case symbol_cluster:
Packit 874993
      case non_cluster:
Packit 874993
	/* These don't join.  Nothing to do. */
Packit 874993
	last_form = _NONE;
Packit 874993
	break;
Packit 874993
Packit 874993
      case virama_terminated_cluster:
Packit 874993
      case standard_cluster:
Packit 874993
      case number_joiner_terminated_cluster:
Packit 874993
      case numeral_cluster:
Packit 874993
      case broken_cluster:
Packit 874993
Packit 874993
	bool join = last_form == FINA || last_form == ISOL;
Packit 874993
Packit 874993
	if (join)
Packit 874993
	{
Packit 874993
	  /* Fixup previous syllable's form. */
Packit 874993
	  last_form = last_form == FINA ? MEDI : INIT;
Packit 874993
	  for (unsigned int i = last_start; i < start; i++)
Packit 874993
	    info[i].mask = (info[i].mask & other_masks) | masks[last_form];
Packit 874993
	}
Packit 874993
Packit 874993
	/* Form for this syllable. */
Packit 874993
	last_form = join ? FINA : ISOL;
Packit 874993
	for (unsigned int i = start; i < end; i++)
Packit 874993
	  info[i].mask = (info[i].mask & other_masks) | masks[last_form];
Packit 874993
Packit 874993
	break;
Packit 874993
    }
Packit 874993
Packit 874993
    last_start = start;
Packit 874993
  }
Packit 874993
}
Packit 874993
Packit 874993
static void
Packit 874993
setup_syllables (const hb_ot_shape_plan_t *plan,
Packit 874993
		 hb_font_t *font HB_UNUSED,
Packit 874993
		 hb_buffer_t *buffer)
Packit 874993
{
Packit 874993
  find_syllables (buffer);
Packit 874993
  setup_rphf_mask (plan, buffer);
Packit 874993
  setup_topographical_masks (plan, buffer);
Packit 874993
}
Packit 874993
Packit 874993
static void
Packit 874993
clear_substitution_flags (const hb_ot_shape_plan_t *plan,
Packit 874993
			  hb_font_t *font HB_UNUSED,
Packit 874993
			  hb_buffer_t *buffer)
Packit 874993
{
Packit 874993
  hb_glyph_info_t *info = buffer->info;
Packit 874993
  unsigned int count = buffer->len;
Packit 874993
  for (unsigned int i = 0; i < count; i++)
Packit 874993
    _hb_glyph_info_clear_substituted (&info[i]);
Packit 874993
}
Packit 874993
Packit 874993
static void
Packit 874993
record_rphf (const hb_ot_shape_plan_t *plan,
Packit 874993
	     hb_font_t *font,
Packit 874993
	     hb_buffer_t *buffer)
Packit 874993
{
Packit 874993
  const use_shape_plan_t *use_plan = (const use_shape_plan_t *) plan->data;
Packit 874993
Packit 874993
  hb_mask_t mask = use_plan->rphf_mask;
Packit 874993
  if (!mask) return;
Packit 874993
  hb_glyph_info_t *info = buffer->info;
Packit 874993
Packit 874993
  foreach_syllable (buffer, start, end)
Packit 874993
  {
Packit 874993
    /* Mark a substituted repha as USE_R. */
Packit 874993
    for (unsigned int i = start; i < end && (info[i].mask & mask); i++)
Packit 874993
      if (_hb_glyph_info_substituted (&info[i]))
Packit 874993
      {
Packit 874993
	info[i].use_category() = USE_R;
Packit 874993
	break;
Packit 874993
      }
Packit 874993
  }
Packit 874993
}
Packit 874993
Packit 874993
static void
Packit 874993
record_pref (const hb_ot_shape_plan_t *plan,
Packit 874993
	     hb_font_t *font,
Packit 874993
	     hb_buffer_t *buffer)
Packit 874993
{
Packit 874993
  hb_glyph_info_t *info = buffer->info;
Packit 874993
Packit 874993
  foreach_syllable (buffer, start, end)
Packit 874993
  {
Packit 874993
    /* Mark a substituted pref as VPre, as they behave the same way. */
Packit 874993
    for (unsigned int i = start; i < end; i++)
Packit 874993
      if (_hb_glyph_info_substituted (&info[i]))
Packit 874993
      {
Packit 874993
	info[i].use_category() = USE_VPre;
Packit 874993
	break;
Packit 874993
      }
Packit 874993
  }
Packit 874993
}
Packit 874993
Packit 874993
static inline bool
Packit 874993
is_halant (const hb_glyph_info_t &info)
Packit 874993
{
Packit 874993
  return info.use_category() == USE_H && !_hb_glyph_info_ligated (&info;;
Packit 874993
}
Packit 874993
Packit 874993
static void
Packit 874993
reorder_syllable (hb_buffer_t *buffer, unsigned int start, unsigned int end)
Packit 874993
{
Packit 874993
  syllable_type_t syllable_type = (syllable_type_t) (buffer->info[start].syllable() & 0x0F);
Packit 874993
  /* Only a few syllable types need reordering. */
Packit 874993
  if (unlikely (!(FLAG_SAFE (syllable_type) &
Packit 874993
		  (FLAG (virama_terminated_cluster) |
Packit 874993
		   FLAG (standard_cluster) |
Packit 874993
		   FLAG (broken_cluster) |
Packit 874993
		   0))))
Packit 874993
    return;
Packit 874993
Packit 874993
  hb_glyph_info_t *info = buffer->info;
Packit 874993
Packit 874993
#define BASE_FLAGS (FLAG (USE_B) | FLAG (USE_GB))
Packit 874993
Packit 874993
  /* Move things forward. */
Packit 874993
  if (info[start].use_category() == USE_R && end - start > 1)
Packit 874993
  {
Packit 874993
    /* Got a repha.  Reorder it to after first base, before first halant. */
Packit 874993
    for (unsigned int i = start + 1; i < end; i++)
Packit 874993
      if ((FLAG_UNSAFE (info[i].use_category()) & (BASE_FLAGS)) || is_halant (info[i]))
Packit 874993
      {
Packit 874993
	/* If we hit a halant, move before it; otherwise it's a base: move to it's
Packit 874993
	 * place, and shift things in between backward. */
Packit 874993
Packit 874993
	if (is_halant (info[i]))
Packit 874993
	  i--;
Packit 874993
Packit 874993
	buffer->merge_clusters (start, i + 1);
Packit 874993
	hb_glyph_info_t t = info[start];
Packit 874993
	memmove (&info[start], &info[start + 1], (i - start) * sizeof (info[0]));
Packit 874993
	info[i] = t;
Packit 874993
Packit 874993
	break;
Packit 874993
      }
Packit 874993
  }
Packit 874993
Packit 874993
  /* Move things back. */
Packit 874993
  unsigned int j = end;
Packit 874993
  for (unsigned int i = start; i < end; i++)
Packit 874993
  {
Packit 874993
    uint32_t flag = FLAG_UNSAFE (info[i].use_category());
Packit 874993
    if ((flag & (BASE_FLAGS)) || is_halant (info[i]))
Packit 874993
    {
Packit 874993
      /* If we hit a halant, move after it; otherwise it's a base: move to it's
Packit 874993
       * place, and shift things in between backward. */
Packit 874993
      if (is_halant (info[i]))
Packit 874993
	j = i + 1;
Packit 874993
      else
Packit 874993
	j = i;
Packit 874993
    }
Packit 874993
    else if (((flag) & (FLAG (USE_VPre) | FLAG (USE_VMPre))) &&
Packit 874993
	     /* Only move the first component of a MultipleSubst. */
Packit 874993
	     0 == _hb_glyph_info_get_lig_comp (&info[i]) &&
Packit 874993
	     j < i)
Packit 874993
    {
Packit 874993
      buffer->merge_clusters (j, i + 1);
Packit 874993
      hb_glyph_info_t t = info[i];
Packit 874993
      memmove (&info[j + 1], &info[j], (i - j) * sizeof (info[0]));
Packit 874993
      info[j] = t;
Packit 874993
    }
Packit 874993
  }
Packit 874993
}
Packit 874993
Packit 874993
static inline void
Packit 874993
insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED,
Packit 874993
		       hb_font_t *font,
Packit 874993
		       hb_buffer_t *buffer)
Packit 874993
{
Packit 874993
  /* Note: This loop is extra overhead, but should not be measurable. */
Packit 874993
  bool has_broken_syllables = false;
Packit 874993
  unsigned int count = buffer->len;
Packit 874993
  hb_glyph_info_t *info = buffer->info;
Packit 874993
  for (unsigned int i = 0; i < count; i++)
Packit 874993
    if ((info[i].syllable() & 0x0F) == broken_cluster)
Packit 874993
    {
Packit 874993
      has_broken_syllables = true;
Packit 874993
      break;
Packit 874993
    }
Packit 874993
  if (likely (!has_broken_syllables))
Packit 874993
    return;
Packit 874993
Packit 874993
  hb_glyph_info_t dottedcircle = {0};
Packit 874993
  if (!font->get_nominal_glyph (0x25CCu, &dottedcircle.codepoint))
Packit 874993
    return;
Packit 874993
  dottedcircle.use_category() = hb_use_get_categories (0x25CC);
Packit 874993
Packit 874993
  buffer->clear_output ();
Packit 874993
Packit 874993
  buffer->idx = 0;
Packit 874993
  unsigned int last_syllable = 0;
Packit 874993
  while (buffer->idx < buffer->len && !buffer->in_error)
Packit 874993
  {
Packit 874993
    unsigned int syllable = buffer->cur().syllable();
Packit 874993
    syllable_type_t syllable_type = (syllable_type_t) (syllable & 0x0F);
Packit 874993
    if (unlikely (last_syllable != syllable && syllable_type == broken_cluster))
Packit 874993
    {
Packit 874993
      last_syllable = syllable;
Packit 874993
Packit 874993
      hb_glyph_info_t ginfo = dottedcircle;
Packit 874993
      ginfo.cluster = buffer->cur().cluster;
Packit 874993
      ginfo.mask = buffer->cur().mask;
Packit 874993
      ginfo.syllable() = buffer->cur().syllable();
Packit 874993
      /* TODO Set glyph_props? */
Packit 874993
Packit 874993
      /* Insert dottedcircle after possible Repha. */
Packit 874993
      while (buffer->idx < buffer->len && !buffer->in_error &&
Packit 874993
	     last_syllable == buffer->cur().syllable() &&
Packit 874993
	     buffer->cur().use_category() == USE_R)
Packit 874993
        buffer->next_glyph ();
Packit 874993
Packit 874993
      buffer->output_info (ginfo);
Packit 874993
    }
Packit 874993
    else
Packit 874993
      buffer->next_glyph ();
Packit 874993
  }
Packit 874993
Packit 874993
  buffer->swap_buffers ();
Packit 874993
}
Packit 874993
Packit 874993
static void
Packit 874993
reorder (const hb_ot_shape_plan_t *plan,
Packit 874993
	 hb_font_t *font,
Packit 874993
	 hb_buffer_t *buffer)
Packit 874993
{
Packit 874993
  insert_dotted_circles (plan, font, buffer);
Packit 874993
Packit 874993
  hb_glyph_info_t *info = buffer->info;
Packit 874993
Packit 874993
  foreach_syllable (buffer, start, end)
Packit 874993
    reorder_syllable (buffer, start, end);
Packit 874993
Packit 874993
  /* Zero syllables now... */
Packit 874993
  unsigned int count = buffer->len;
Packit 874993
  for (unsigned int i = 0; i < count; i++)
Packit 874993
    info[i].syllable() = 0;
Packit 874993
Packit 874993
  HB_BUFFER_DEALLOCATE_VAR (buffer, use_category);
Packit 874993
}
Packit 874993
Packit 874993
static bool
Packit 874993
decompose_use (const hb_ot_shape_normalize_context_t *c,
Packit 874993
                hb_codepoint_t  ab,
Packit 874993
                hb_codepoint_t *a,
Packit 874993
                hb_codepoint_t *b)
Packit 874993
{
Packit 874993
  switch (ab)
Packit 874993
  {
Packit 874993
    /* Chakma:
Packit 874993
     * Special case where the Unicode decomp gives matras in the wrong order
Packit 874993
     * for cluster validation.
Packit 874993
     */
Packit 874993
    case 0x1112Eu : *a = 0x11127u; *b= 0x11131u; return true;
Packit 874993
    case 0x1112Fu : *a = 0x11127u; *b= 0x11132u; return true;
Packit 874993
  }
Packit 874993
Packit 874993
  return (bool) c->unicode->decompose (ab, a, b);
Packit 874993
}
Packit 874993
Packit 874993
static bool
Packit 874993
compose_use (const hb_ot_shape_normalize_context_t *c,
Packit 874993
	     hb_codepoint_t  a,
Packit 874993
	     hb_codepoint_t  b,
Packit 874993
	     hb_codepoint_t *ab)
Packit 874993
{
Packit 874993
  /* Avoid recomposing split matras. */
Packit 874993
  if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (c->unicode->general_category (a)))
Packit 874993
    return false;
Packit 874993
Packit 874993
  return (bool)c->unicode->compose (a, b, ab);
Packit 874993
}
Packit 874993
Packit 874993
Packit 874993
const hb_ot_complex_shaper_t _hb_ot_complex_shaper_use =
Packit 874993
{
Packit 874993
  "use",
Packit 874993
  collect_features_use,
Packit 874993
  NULL, /* override_features */
Packit 874993
  data_create_use,
Packit 874993
  data_destroy_use,
Packit 874993
  NULL, /* preprocess_text */
Packit 874993
  NULL, /* postprocess_glyphs */
Packit 874993
  HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT,
Packit 874993
  decompose_use,
Packit 874993
  compose_use,
Packit 874993
  setup_masks_use,
Packit 874993
  NULL, /* disable_otl */
Packit 874993
  HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY,
Packit 874993
  false, /* fallback_position */
Packit 874993
};