src/java.desktop/share/native/libfontmanager/harfbuzz/hb-ot-shape-complex-khmer.cc
author prr
Thu, 21 Jun 2018 12:54:30 -0700
changeset 50826 f5b95be8b6e2
parent 50352 25db2c8f3cf8
child 51000 7c8841474f57
permissions -rw-r--r--
8205441: Upgrade to harfbuzz 1.8.1 Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
     1
/*
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
     2
 * Copyright © 2011,2012  Google, Inc.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
     3
 *
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
     4
 *  This is part of HarfBuzz, a text shaping library.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
     5
 *
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
     6
 * Permission is hereby granted, without written agreement and without
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
     7
 * license or royalty fees, to use, copy, modify, and distribute this
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
     8
 * software and its documentation for any purpose, provided that the
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
     9
 * above copyright notice and the following two paragraphs appear in
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    10
 * all copies of this software.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    11
 *
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    12
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    13
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    14
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    15
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    16
 * DAMAGE.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    17
 *
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    18
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    19
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    20
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    21
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    22
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    23
 *
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    24
 * Google Author(s): Behdad Esfahbod
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    25
 */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    26
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    27
#include "hb-ot-shape-complex-khmer-private.hh"
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    28
#include "hb-ot-layout-private.hh"
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    29
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    30
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    31
/*
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    32
 * Khmer shaper.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    33
 */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    34
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    35
struct feature_list_t {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    36
  hb_tag_t tag;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    37
  hb_ot_map_feature_flags_t flags;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    38
};
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    39
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    40
static const feature_list_t
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    41
khmer_features[] =
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    42
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    43
  /*
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    44
   * Basic features.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    45
   * These features are applied in order, one at a time, after initial_reordering.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    46
   */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    47
  {HB_TAG('p','r','e','f'), F_NONE},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    48
  {HB_TAG('b','l','w','f'), F_NONE},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    49
  {HB_TAG('a','b','v','f'), F_NONE},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    50
  {HB_TAG('p','s','t','f'), F_NONE},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    51
  {HB_TAG('c','f','a','r'), F_NONE},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    52
  /*
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    53
   * Other features.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    54
   * These features are applied all at once, after final_reordering.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    55
   * Default Bengali font in Windows for example has intermixed
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    56
   * lookups for init,pres,abvs,blws features.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    57
   */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    58
  {HB_TAG('p','r','e','s'), F_GLOBAL},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    59
  {HB_TAG('a','b','v','s'), F_GLOBAL},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    60
  {HB_TAG('b','l','w','s'), F_GLOBAL},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    61
  {HB_TAG('p','s','t','s'), F_GLOBAL},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    62
  /* Positioning features, though we don't care about the types. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    63
  {HB_TAG('d','i','s','t'), F_GLOBAL},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    64
  {HB_TAG('a','b','v','m'), F_GLOBAL},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    65
  {HB_TAG('b','l','w','m'), F_GLOBAL},
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    66
};
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    67
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    68
/*
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    69
 * Must be in the same order as the khmer_features array.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    70
 */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    71
enum {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    72
  PREF,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    73
  BLWF,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    74
  ABVF,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    75
  PSTF,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    76
  CFAR,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    77
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    78
  _PRES,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    79
  _ABVS,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    80
  _BLWS,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    81
  _PSTS,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    82
  _DIST,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    83
  _ABVM,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    84
  _BLWM,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    85
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    86
  KHMER_NUM_FEATURES,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    87
  KHMER_BASIC_FEATURES = _PRES /* Don't forget to update this! */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    88
};
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    89
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    90
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    91
setup_syllables (const hb_ot_shape_plan_t *plan,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    92
                 hb_font_t *font,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    93
                 hb_buffer_t *buffer);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    94
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    95
initial_reordering (const hb_ot_shape_plan_t *plan,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    96
                    hb_font_t *font,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    97
                    hb_buffer_t *buffer);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    98
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
    99
final_reordering (const hb_ot_shape_plan_t *plan,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   100
                  hb_font_t *font,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   101
                  hb_buffer_t *buffer);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   102
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   103
clear_syllables (const hb_ot_shape_plan_t *plan,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   104
                 hb_font_t *font,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   105
                 hb_buffer_t *buffer);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   106
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   107
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   108
collect_features_khmer (hb_ot_shape_planner_t *plan)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   109
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   110
  hb_ot_map_builder_t *map = &plan->map;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   111
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   112
  /* Do this before any lookups have been applied. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   113
  map->add_gsub_pause (setup_syllables);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   114
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   115
  map->add_global_bool_feature (HB_TAG('l','o','c','l'));
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   116
  /* The Indic specs do not require ccmp, but we apply it here since if
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   117
   * there is a use of it, it's typically at the beginning. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   118
  map->add_global_bool_feature (HB_TAG('c','c','m','p'));
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   119
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   120
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   121
  unsigned int i = 0;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   122
  map->add_gsub_pause (initial_reordering);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   123
  for (; i < KHMER_BASIC_FEATURES; i++) {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   124
    map->add_feature (khmer_features[i].tag, 1, khmer_features[i].flags | F_MANUAL_ZWJ | F_MANUAL_ZWNJ);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   125
    map->add_gsub_pause (nullptr);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   126
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   127
  map->add_gsub_pause (final_reordering);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   128
  for (; i < KHMER_NUM_FEATURES; i++) {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   129
    map->add_feature (khmer_features[i].tag, 1, khmer_features[i].flags | F_MANUAL_ZWJ | F_MANUAL_ZWNJ);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   130
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   131
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   132
  map->add_global_bool_feature (HB_TAG('c','a','l','t'));
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   133
  map->add_global_bool_feature (HB_TAG('c','l','i','g'));
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   134
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   135
  map->add_gsub_pause (clear_syllables);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   136
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   137
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   138
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   139
override_features_khmer (hb_ot_shape_planner_t *plan)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   140
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   141
  /* Uniscribe does not apply 'kern' in Khmer. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   142
  if (hb_options ().uniscribe_bug_compatible)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   143
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   144
    plan->map.add_feature (HB_TAG('k','e','r','n'), 0, F_GLOBAL);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   145
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   146
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   147
  plan->map.add_feature (HB_TAG('l','i','g','a'), 0, F_GLOBAL);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   148
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   149
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   150
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   151
struct would_substitute_feature_t
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   152
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   153
  inline void init (const hb_ot_map_t *map, hb_tag_t feature_tag, bool zero_context_)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   154
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   155
    zero_context = zero_context_;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   156
    map->get_stage_lookups (0/*GSUB*/,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   157
                            map->get_feature_stage (0/*GSUB*/, feature_tag),
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   158
                            &lookups, &count);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   159
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   160
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   161
  inline bool would_substitute (const hb_codepoint_t *glyphs,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   162
                                unsigned int          glyphs_count,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   163
                                hb_face_t            *face) const
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   164
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   165
    for (unsigned int i = 0; i < count; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   166
      if (hb_ot_layout_lookup_would_substitute_fast (face, lookups[i].index, glyphs, glyphs_count, zero_context))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   167
        return true;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   168
    return false;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   169
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   170
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   171
  private:
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   172
  const hb_ot_map_t::lookup_map_t *lookups;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   173
  unsigned int count;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   174
  bool zero_context;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   175
};
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   176
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   177
struct khmer_shape_plan_t
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   178
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   179
  ASSERT_POD ();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   180
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   181
  inline bool get_virama_glyph (hb_font_t *font, hb_codepoint_t *pglyph) const
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   182
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   183
    hb_codepoint_t glyph = virama_glyph;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   184
    if (unlikely (virama_glyph == (hb_codepoint_t) -1))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   185
    {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   186
      if (!font->get_nominal_glyph (0x17D2u, &glyph))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   187
        glyph = 0;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   188
      /* Technically speaking, the spec says we should apply 'locl' to virama too.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   189
       * Maybe one day... */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   190
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   191
      /* Our get_nominal_glyph() function needs a font, so we can't get the virama glyph
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   192
       * during shape planning...  Instead, overwrite it here.  It's safe.  Don't worry! */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   193
      virama_glyph = glyph;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   194
    }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   195
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   196
    *pglyph = glyph;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   197
    return glyph != 0;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   198
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   199
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   200
  mutable hb_codepoint_t virama_glyph;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   201
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   202
  would_substitute_feature_t pref;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   203
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   204
  hb_mask_t mask_array[KHMER_NUM_FEATURES];
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   205
};
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   206
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   207
static void *
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   208
data_create_khmer (const hb_ot_shape_plan_t *plan)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   209
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   210
  khmer_shape_plan_t *khmer_plan = (khmer_shape_plan_t *) calloc (1, sizeof (khmer_shape_plan_t));
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   211
  if (unlikely (!khmer_plan))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   212
    return nullptr;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   213
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   214
  khmer_plan->virama_glyph = (hb_codepoint_t) -1;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   215
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   216
  khmer_plan->pref.init (&plan->map, HB_TAG('p','r','e','f'), true);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   217
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   218
  for (unsigned int i = 0; i < ARRAY_LENGTH (khmer_plan->mask_array); i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   219
    khmer_plan->mask_array[i] = (khmer_features[i].flags & F_GLOBAL) ?
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   220
                                 0 : plan->map.get_1_mask (khmer_features[i].tag);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   221
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   222
  return khmer_plan;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   223
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   224
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   225
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   226
data_destroy_khmer (void *data)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   227
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   228
  free (data);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   229
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   230
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   231
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   232
enum syllable_type_t {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   233
  consonant_syllable,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   234
  broken_cluster,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   235
  non_khmer_cluster,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   236
};
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   237
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   238
#include "hb-ot-shape-complex-khmer-machine.hh"
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   239
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   240
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   241
setup_masks_khmer (const hb_ot_shape_plan_t *plan HB_UNUSED,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   242
                   hb_buffer_t              *buffer,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   243
                   hb_font_t                *font HB_UNUSED)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   244
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   245
  HB_BUFFER_ALLOCATE_VAR (buffer, khmer_category);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   246
  HB_BUFFER_ALLOCATE_VAR (buffer, khmer_position);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   247
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   248
  /* We cannot setup masks here.  We save information about characters
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   249
   * and setup masks later on in a pause-callback. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   250
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   251
  unsigned int count = buffer->len;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   252
  hb_glyph_info_t *info = buffer->info;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   253
  for (unsigned int i = 0; i < count; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   254
    set_khmer_properties (info[i]);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   255
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   256
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   257
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   258
setup_syllables (const hb_ot_shape_plan_t *plan HB_UNUSED,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   259
                 hb_font_t *font HB_UNUSED,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   260
                 hb_buffer_t *buffer)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   261
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   262
  find_syllables (buffer);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   263
  foreach_syllable (buffer, start, end)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   264
    buffer->unsafe_to_break (start, end);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   265
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   266
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   267
static int
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   268
compare_khmer_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   269
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   270
  int a = pa->khmer_position();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   271
  int b = pb->khmer_position();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   272
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   273
  return a < b ? -1 : a == b ? 0 : +1;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   274
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   275
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   276
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   277
/* Rules from:
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
   278
 * https://docs.microsoft.com/en-us/typography/script-development/devanagari */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   279
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   280
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   281
initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   282
                                       hb_face_t *face,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   283
                                       hb_buffer_t *buffer,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   284
                                       unsigned int start, unsigned int end)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   285
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   286
  const khmer_shape_plan_t *khmer_plan = (const khmer_shape_plan_t *) plan->data;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   287
  hb_glyph_info_t *info = buffer->info;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   288
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   289
  /* 1. Khmer shaping assumes that a syllable will begin with a Cons, IndV, or Number. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   290
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   291
  /* The first consonant is always the base. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   292
  unsigned int base = start;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   293
  info[base].khmer_position() = POS_BASE_C;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   294
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   295
  /* Mark all subsequent consonants as below. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   296
  for (unsigned int i = base + 1; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   297
    if (is_consonant_or_vowel (info[i]))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   298
      info[i].khmer_position() = POS_BELOW_C;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   299
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   300
  /* Mark final consonants.  A final consonant is one appearing after a matra,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   301
   * like in Khmer. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   302
  for (unsigned int i = base + 1; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   303
    if (info[i].khmer_category() == OT_M) {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   304
      for (unsigned int j = i + 1; j < end; j++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   305
        if (is_consonant_or_vowel (info[j])) {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   306
          info[j].khmer_position() = POS_FINAL_C;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   307
          break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   308
        }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   309
      break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   310
    }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   311
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   312
  /* Attach misc marks to previous char to move with them. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   313
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   314
    khmer_position_t last_pos = POS_START;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   315
    for (unsigned int i = start; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   316
    {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   317
      if ((FLAG_UNSAFE (info[i].khmer_category()) & (JOINER_FLAGS | FLAG (OT_N) | FLAG (OT_RS) | MEDIAL_FLAGS | FLAG (OT_Coeng))))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   318
      {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   319
        info[i].khmer_position() = last_pos;
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
   320
        if (unlikely (info[i].khmer_category() == OT_Coeng &&
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   321
                      info[i].khmer_position() == POS_PRE_M))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   322
        {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   323
          /*
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   324
           * Uniscribe doesn't move the Halant with Left Matra.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   325
           * TEST: U+092B,U+093F,U+094DE
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   326
           * We follow.  This is important for the Sinhala
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   327
           * U+0DDA split matra since it decomposes to U+0DD9,U+0DCA
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   328
           * where U+0DD9 is a left matra and U+0DCA is the virama.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   329
           * We don't want to move the virama with the left matra.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   330
           * TEST: U+0D9A,U+0DDA
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   331
           */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   332
          for (unsigned int j = i; j > start; j--)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   333
            if (info[j - 1].khmer_position() != POS_PRE_M) {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   334
              info[i].khmer_position() = info[j - 1].khmer_position();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   335
              break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   336
            }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   337
        }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   338
      } else if (info[i].khmer_position() != POS_SMVD) {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   339
        last_pos = (khmer_position_t) info[i].khmer_position();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   340
      }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   341
    }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   342
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   343
  /* For post-base consonants let them own anything before them
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   344
   * since the last consonant or matra. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   345
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   346
    unsigned int last = base;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   347
    for (unsigned int i = base + 1; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   348
      if (is_consonant_or_vowel (info[i]))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   349
      {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   350
        for (unsigned int j = last + 1; j < i; j++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   351
          if (info[j].khmer_position() < POS_SMVD)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   352
            info[j].khmer_position() = info[i].khmer_position();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   353
        last = i;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   354
      } else if (info[i].khmer_category() == OT_M)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   355
        last = i;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   356
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   357
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   358
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   359
    /* Use syllable() for sort accounting temporarily. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   360
    unsigned int syllable = info[start].syllable();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   361
    for (unsigned int i = start; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   362
      info[i].syllable() = i - start;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   363
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   364
    /* Sit tight, rock 'n roll! */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   365
    hb_stable_sort (info + start, end - start, compare_khmer_order);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   366
    /* Find base again */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   367
    base = end;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   368
    for (unsigned int i = start; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   369
      if (info[i].khmer_position() == POS_BASE_C)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   370
      {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   371
        base = i;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   372
        break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   373
      }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   374
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   375
    /* Note!  syllable() is a one-byte field. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   376
    for (unsigned int i = base; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   377
      if (info[i].syllable() != 255)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   378
      {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   379
        unsigned int max = i;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   380
        unsigned int j = start + info[i].syllable();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   381
        while (j != i)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   382
        {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   383
          max = MAX (max, j);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   384
          unsigned int next = start + info[j].syllable();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   385
          info[j].syllable() = 255; /* So we don't process j later again. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   386
          j = next;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   387
        }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   388
        if (i != max)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   389
          buffer->merge_clusters (i, max + 1);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   390
      }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   391
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   392
    /* Put syllable back in. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   393
    for (unsigned int i = start; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   394
      info[i].syllable() = syllable;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   395
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   396
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   397
  /* Setup masks now */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   398
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   399
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   400
    hb_mask_t mask;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   401
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   402
    /* Post-base */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   403
    mask = khmer_plan->mask_array[BLWF] | khmer_plan->mask_array[ABVF] | khmer_plan->mask_array[PSTF];
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   404
    for (unsigned int i = base + 1; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   405
      info[i].mask  |= mask;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   406
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   407
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   408
  unsigned int pref_len = 2;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   409
  if (khmer_plan->mask_array[PREF] && base + pref_len < end)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   410
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   411
    /* Find a Halant,Ra sequence and mark it for pre-base-reordering processing. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   412
    for (unsigned int i = base + 1; i + pref_len - 1 < end; i++) {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   413
      hb_codepoint_t glyphs[2];
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   414
      for (unsigned int j = 0; j < pref_len; j++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   415
        glyphs[j] = info[i + j].codepoint;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   416
      if (khmer_plan->pref.would_substitute (glyphs, pref_len, face))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   417
      {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   418
        for (unsigned int j = 0; j < pref_len; j++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   419
          info[i++].mask |= khmer_plan->mask_array[PREF];
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   420
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   421
        /* Mark the subsequent stuff with 'cfar'.  Used in Khmer.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   422
         * Read the feature spec.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   423
         * This allows distinguishing the following cases with MS Khmer fonts:
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   424
         * U+1784,U+17D2,U+179A,U+17D2,U+1782
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   425
         * U+1784,U+17D2,U+1782,U+17D2,U+179A
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   426
         */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   427
        if (khmer_plan->mask_array[CFAR])
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   428
          for (; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   429
            info[i].mask |= khmer_plan->mask_array[CFAR];
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   430
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   431
        break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   432
      }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   433
    }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   434
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   435
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   436
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   437
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   438
initial_reordering_syllable (const hb_ot_shape_plan_t *plan,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   439
                             hb_face_t *face,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   440
                             hb_buffer_t *buffer,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   441
                             unsigned int start, unsigned int end)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   442
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   443
  syllable_type_t syllable_type = (syllable_type_t) (buffer->info[start].syllable() & 0x0F);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   444
  switch (syllable_type)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   445
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   446
    case broken_cluster: /* We already inserted dotted-circles, so just call the consonant_syllable. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   447
    case consonant_syllable:
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   448
     initial_reordering_consonant_syllable (plan, face, buffer, start, end);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   449
     break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   450
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   451
    case non_khmer_cluster:
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   452
      break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   453
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   454
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   455
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   456
static inline void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   457
insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   458
                       hb_font_t *font,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   459
                       hb_buffer_t *buffer)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   460
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   461
  /* Note: This loop is extra overhead, but should not be measurable. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   462
  bool has_broken_syllables = false;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   463
  unsigned int count = buffer->len;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   464
  hb_glyph_info_t *info = buffer->info;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   465
  for (unsigned int i = 0; i < count; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   466
    if ((info[i].syllable() & 0x0F) == broken_cluster)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   467
    {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   468
      has_broken_syllables = true;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   469
      break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   470
    }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   471
  if (likely (!has_broken_syllables))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   472
    return;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   473
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   474
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   475
  hb_codepoint_t dottedcircle_glyph;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   476
  if (!font->get_nominal_glyph (0x25CCu, &dottedcircle_glyph))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   477
    return;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   478
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   479
  hb_glyph_info_t dottedcircle = {0};
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   480
  dottedcircle.codepoint = 0x25CCu;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   481
  set_khmer_properties (dottedcircle);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   482
  dottedcircle.codepoint = dottedcircle_glyph;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   483
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   484
  buffer->clear_output ();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   485
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   486
  buffer->idx = 0;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   487
  unsigned int last_syllable = 0;
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
   488
  while (buffer->idx < buffer->len && buffer->successful)
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   489
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   490
    unsigned int syllable = buffer->cur().syllable();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   491
    syllable_type_t syllable_type = (syllable_type_t) (syllable & 0x0F);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   492
    if (unlikely (last_syllable != syllable && syllable_type == broken_cluster))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   493
    {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   494
      last_syllable = syllable;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   495
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   496
      hb_glyph_info_t ginfo = dottedcircle;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   497
      ginfo.cluster = buffer->cur().cluster;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   498
      ginfo.mask = buffer->cur().mask;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   499
      ginfo.syllable() = buffer->cur().syllable();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   500
      /* TODO Set glyph_props? */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   501
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   502
      /* Insert dottedcircle after possible Repha. */
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
   503
      while (buffer->idx < buffer->len && buffer->successful &&
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   504
             last_syllable == buffer->cur().syllable() &&
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   505
             buffer->cur().khmer_category() == OT_Repha)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   506
        buffer->next_glyph ();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   507
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   508
      buffer->output_info (ginfo);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   509
    }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   510
    else
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   511
      buffer->next_glyph ();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   512
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   513
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   514
  buffer->swap_buffers ();
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   515
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   516
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   517
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   518
initial_reordering (const hb_ot_shape_plan_t *plan,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   519
                    hb_font_t *font,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   520
                    hb_buffer_t *buffer)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   521
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   522
  insert_dotted_circles (plan, font, buffer);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   523
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   524
  foreach_syllable (buffer, start, end)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   525
    initial_reordering_syllable (plan, font->face, buffer, start, end);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   526
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   527
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   528
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   529
final_reordering_syllable (const hb_ot_shape_plan_t *plan,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   530
                           hb_buffer_t *buffer,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   531
                           unsigned int start, unsigned int end)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   532
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   533
  const khmer_shape_plan_t *khmer_plan = (const khmer_shape_plan_t *) plan->data;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   534
  hb_glyph_info_t *info = buffer->info;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   535
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   536
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   537
  /* This function relies heavily on halant glyphs.  Lots of ligation
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   538
   * and possibly multiple substitutions happened prior to this
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   539
   * phase, and that might have messed up our properties.  Recover
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   540
   * from a particular case of that where we're fairly sure that a
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
   541
   * class of OT_Coeng is desired but has been lost. */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   542
  if (khmer_plan->virama_glyph)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   543
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   544
    unsigned int virama_glyph = khmer_plan->virama_glyph;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   545
    for (unsigned int i = start; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   546
      if (info[i].codepoint == virama_glyph &&
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   547
          _hb_glyph_info_ligated (&info[i]) &&
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   548
          _hb_glyph_info_multiplied (&info[i]))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   549
      {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   550
        /* This will make sure that this glyph passes is_coeng() test. */
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
   551
        info[i].khmer_category() = OT_Coeng;
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   552
        _hb_glyph_info_clear_ligated_and_multiplied (&info[i]);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   553
      }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   554
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   555
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   556
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   557
  /* 4. Final reordering:
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   558
   *
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   559
   * After the localized forms and basic shaping forms GSUB features have been
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   560
   * applied (see below), the shaping engine performs some final glyph
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   561
   * reordering before applying all the remaining font features to the entire
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   562
   * syllable.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   563
   */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   564
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   565
  bool try_pref = !!khmer_plan->mask_array[PREF];
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   566
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   567
  /* Find base again */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   568
  unsigned int base;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   569
  for (base = start; base < end; base++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   570
    if (info[base].khmer_position() >= POS_BASE_C)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   571
    {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   572
      if (try_pref && base + 1 < end)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   573
      {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   574
        for (unsigned int i = base + 1; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   575
          if ((info[i].mask & khmer_plan->mask_array[PREF]) != 0)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   576
          {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   577
            if (!(_hb_glyph_info_substituted (&info[i]) &&
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   578
                  _hb_glyph_info_ligated_and_didnt_multiply (&info[i])))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   579
            {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   580
              /* Ok, this was a 'pref' candidate but didn't form any.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   581
               * Base is around here... */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   582
              base = i;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   583
              while (base < end && is_coeng (info[base]))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   584
                base++;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   585
              info[base].khmer_position() = POS_BASE_C;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   586
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   587
              try_pref = false;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   588
            }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   589
            break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   590
          }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   591
      }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   592
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   593
      if (start < base && info[base].khmer_position() > POS_BASE_C)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   594
        base--;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   595
      break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   596
    }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   597
  if (base == end && start < base &&
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   598
      is_one_of (info[base - 1], FLAG (OT_ZWJ)))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   599
    base--;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   600
  if (base < end)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   601
    while (start < base &&
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   602
           is_one_of (info[base], (FLAG (OT_N) | FLAG (OT_Coeng))))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   603
      base--;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   604
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   605
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   606
  /*   o Reorder matras:
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   607
   *
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   608
   *     If a pre-base matra character had been reordered before applying basic
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   609
   *     features, the glyph can be moved closer to the main consonant based on
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   610
   *     whether half-forms had been formed. Actual position for the matra is
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   611
   *     defined as “after last standalone halant glyph, after initial matra
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   612
   *     position and before the main consonant”. If ZWJ or ZWNJ follow this
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   613
   *     halant, position is moved after it.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   614
   */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   615
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   616
  if (start + 1 < end && start < base) /* Otherwise there can't be any pre-base matra characters. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   617
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   618
    /* If we lost track of base, alas, position before last thingy. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   619
    unsigned int new_pos = base == end ? base - 2 : base - 1;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   620
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   621
    while (new_pos > start &&
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   622
           !(is_one_of (info[new_pos], (FLAG (OT_M) | FLAG (OT_Coeng)))))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   623
      new_pos--;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   624
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   625
    /* If we found no Halant we are done.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   626
     * Otherwise only proceed if the Halant does
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   627
     * not belong to the Matra itself! */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   628
    if (is_coeng (info[new_pos]) &&
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   629
        info[new_pos].khmer_position() != POS_PRE_M)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   630
    {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   631
      /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   632
      if (new_pos + 1 < end && is_joiner (info[new_pos + 1]))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   633
        new_pos++;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   634
    }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   635
    else
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   636
      new_pos = start; /* No move. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   637
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   638
    if (start < new_pos && info[new_pos].khmer_position () != POS_PRE_M)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   639
    {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   640
      /* Now go see if there's actually any matras... */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   641
      for (unsigned int i = new_pos; i > start; i--)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   642
        if (info[i - 1].khmer_position () == POS_PRE_M)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   643
        {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   644
          unsigned int old_pos = i - 1;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   645
          if (old_pos < base && base <= new_pos) /* Shouldn't actually happen. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   646
            base--;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   647
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   648
          hb_glyph_info_t tmp = info[old_pos];
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   649
          memmove (&info[old_pos], &info[old_pos + 1], (new_pos - old_pos) * sizeof (info[0]));
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   650
          info[new_pos] = tmp;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   651
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   652
          /* Note: this merge_clusters() is intentionally *after* the reordering.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   653
           * Indic matra reordering is special and tricky... */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   654
          buffer->merge_clusters (new_pos, MIN (end, base + 1));
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   655
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   656
          new_pos--;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   657
        }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   658
    } else {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   659
      for (unsigned int i = start; i < base; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   660
        if (info[i].khmer_position () == POS_PRE_M) {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   661
          buffer->merge_clusters (i, MIN (end, base + 1));
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   662
          break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   663
        }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   664
    }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   665
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   666
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   667
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   668
  /*   o Reorder pre-base-reordering consonants:
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   669
   *
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   670
   *     If a pre-base-reordering consonant is found, reorder it according to
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   671
   *     the following rules:
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   672
   */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   673
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   674
  if (try_pref && base + 1 < end) /* Otherwise there can't be any pre-base-reordering Ra. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   675
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   676
    for (unsigned int i = base + 1; i < end; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   677
      if ((info[i].mask & khmer_plan->mask_array[PREF]) != 0)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   678
      {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   679
        /*       1. Only reorder a glyph produced by substitution during application
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   680
         *          of the <pref> feature. (Note that a font may shape a Ra consonant with
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   681
         *          the feature generally but block it in certain contexts.)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   682
         */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   683
        /* Note: We just check that something got substituted.  We don't check that
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   684
         * the <pref> feature actually did it...
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   685
         *
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   686
         * Reorder pref only if it ligated. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   687
        if (_hb_glyph_info_ligated_and_didnt_multiply (&info[i]))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   688
        {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   689
          /*
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   690
           *       2. Try to find a target position the same way as for pre-base matra.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   691
           *          If it is found, reorder pre-base consonant glyph.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   692
           *
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   693
           *       3. If position is not found, reorder immediately before main
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   694
           *          consonant.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   695
           */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   696
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   697
          unsigned int new_pos = base;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   698
          while (new_pos > start &&
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   699
                 !(is_one_of (info[new_pos - 1], FLAG(OT_M) | FLAG (OT_Coeng))))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   700
            new_pos--;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   701
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   702
          /* In Khmer coeng model, a H,Ra can go *after* matras.  If it goes after a
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   703
           * split matra, it should be reordered to *before* the left part of such matra. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   704
          if (new_pos > start && info[new_pos - 1].khmer_category() == OT_M)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   705
          {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   706
            unsigned int old_pos = i;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   707
            for (unsigned int j = base + 1; j < old_pos; j++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   708
              if (info[j].khmer_category() == OT_M)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   709
              {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   710
                new_pos--;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   711
                break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   712
              }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   713
          }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   714
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   715
          if (new_pos > start && is_coeng (info[new_pos - 1]))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   716
          {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   717
            /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   718
            if (new_pos < end && is_joiner (info[new_pos]))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   719
              new_pos++;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   720
          }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   721
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   722
          {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   723
            unsigned int old_pos = i;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   724
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   725
            buffer->merge_clusters (new_pos, old_pos + 1);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   726
            hb_glyph_info_t tmp = info[old_pos];
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   727
            memmove (&info[new_pos + 1], &info[new_pos], (old_pos - new_pos) * sizeof (info[0]));
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   728
            info[new_pos] = tmp;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   729
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   730
            if (new_pos <= base && base < old_pos)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   731
              base++;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   732
          }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   733
        }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   734
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   735
        break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   736
      }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   737
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   738
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   739
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   740
  /*
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   741
   * Finish off the clusters and go home!
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   742
   */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   743
  if (hb_options ().uniscribe_bug_compatible)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   744
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   745
    /* Uniscribe merges the entire syllable into a single cluster... Except for Tamil & Sinhala.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   746
     * This means, half forms are submerged into the main consonant's cluster.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   747
     * This is unnecessary, and makes cursor positioning harder, but that's what
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   748
     * Uniscribe does. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   749
    buffer->merge_clusters (start, end);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   750
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   751
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   752
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   753
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   754
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   755
final_reordering (const hb_ot_shape_plan_t *plan,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   756
                  hb_font_t *font HB_UNUSED,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   757
                  hb_buffer_t *buffer)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   758
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   759
  unsigned int count = buffer->len;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   760
  if (unlikely (!count)) return;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   761
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   762
  foreach_syllable (buffer, start, end)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   763
    final_reordering_syllable (plan, buffer, start, end);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   764
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   765
  HB_BUFFER_DEALLOCATE_VAR (buffer, khmer_category);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   766
  HB_BUFFER_DEALLOCATE_VAR (buffer, khmer_position);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   767
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   768
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   769
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   770
static void
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   771
clear_syllables (const hb_ot_shape_plan_t *plan HB_UNUSED,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   772
                 hb_font_t *font HB_UNUSED,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   773
                 hb_buffer_t *buffer)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   774
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   775
  hb_glyph_info_t *info = buffer->info;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   776
  unsigned int count = buffer->len;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   777
  for (unsigned int i = 0; i < count; i++)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   778
    info[i].syllable() = 0;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   779
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   780
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   781
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   782
static bool
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   783
decompose_khmer (const hb_ot_shape_normalize_context_t *c,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   784
                 hb_codepoint_t  ab,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   785
                 hb_codepoint_t *a,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   786
                 hb_codepoint_t *b)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   787
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   788
  switch (ab)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   789
  {
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   790
    /*
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   791
     * Decompose split matras that don't have Unicode decompositions.
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   792
     */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   793
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   794
    /* Khmer */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   795
    case 0x17BEu  : *a = 0x17C1u; *b= 0x17BEu; return true;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   796
    case 0x17BFu  : *a = 0x17C1u; *b= 0x17BFu; return true;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   797
    case 0x17C0u  : *a = 0x17C1u; *b= 0x17C0u; return true;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   798
    case 0x17C4u  : *a = 0x17C1u; *b= 0x17C4u; return true;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   799
    case 0x17C5u  : *a = 0x17C1u; *b= 0x17C5u; return true;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   800
  }
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   801
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   802
  return (bool) c->unicode->decompose (ab, a, b);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   803
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   804
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   805
static bool
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   806
compose_khmer (const hb_ot_shape_normalize_context_t *c,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   807
               hb_codepoint_t  a,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   808
               hb_codepoint_t  b,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   809
               hb_codepoint_t *ab)
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   810
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   811
  /* Avoid recomposing split matras. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   812
  if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (c->unicode->general_category (a)))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   813
    return false;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   814
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   815
  return (bool) c->unicode->compose (a, b, ab);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   816
}
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   817
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   818
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   819
const hb_ot_complex_shaper_t _hb_ot_complex_shaper_khmer =
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   820
{
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   821
  collect_features_khmer,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   822
  override_features_khmer,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   823
  data_create_khmer,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   824
  data_destroy_khmer,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   825
  nullptr, /* preprocess_text */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   826
  nullptr, /* postprocess_glyphs */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   827
  HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   828
  decompose_khmer,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   829
  compose_khmer,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   830
  setup_masks_khmer,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   831
  nullptr, /* disable_otl */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   832
  nullptr, /* reorder_marks */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   833
  HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE,
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   834
  false, /* fallback_position */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents:
diff changeset
   835
};