src/java.desktop/share/native/libfontmanager/harfbuzz/hb-ot-layout-gsubgpos-private.hh
author prr
Thu, 21 Jun 2018 12:54:30 -0700
changeset 50826 f5b95be8b6e2
parent 50352 25db2c8f3cf8
permissions -rw-r--r--
8205441: Upgrade to harfbuzz 1.8.1 Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     1
/*
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     2
 * Copyright © 2007,2008,2009,2010  Red Hat, Inc.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     3
 * Copyright © 2010,2012  Google, Inc.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     4
 *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     5
 *  This is part of HarfBuzz, a text shaping library.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     6
 *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     7
 * Permission is hereby granted, without written agreement and without
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     8
 * license or royalty fees, to use, copy, modify, and distribute this
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     9
 * software and its documentation for any purpose, provided that the
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    10
 * above copyright notice and the following two paragraphs appear in
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    11
 * all copies of this software.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    12
 *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    13
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    14
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    15
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    16
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    17
 * DAMAGE.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    18
 *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    19
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    20
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    21
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    22
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    23
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    24
 *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    25
 * Red Hat Author(s): Behdad Esfahbod
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    26
 * Google Author(s): Behdad Esfahbod
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    27
 */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    28
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    29
#ifndef HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    30
#define HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    31
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
    32
#include "hb-private.hh"
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
    33
#include "hb-debug.hh"
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    34
#include "hb-buffer-private.hh"
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    35
#include "hb-map-private.hh"
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    36
#include "hb-ot-layout-gdef-table.hh"
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    37
#include "hb-set-private.hh"
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    38
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    39
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    40
namespace OT {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    41
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    42
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    43
struct hb_closure_context_t :
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    44
       hb_dispatch_context_t<hb_closure_context_t, hb_void_t, HB_DEBUG_CLOSURE>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    45
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    46
  inline const char *get_name (void) { return "CLOSURE"; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    47
  typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    48
  template <typename T>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    49
  inline return_t dispatch (const T &obj) { obj.closure (this); return HB_VOID; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    50
  static return_t default_return_value (void) { return HB_VOID; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    51
  bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    52
  return_t recurse (unsigned int lookup_index)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    53
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    54
    if (unlikely (nesting_level_left == 0 || !recurse_func))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    55
      return default_return_value ();
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    56
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    57
    nesting_level_left--;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    58
    recurse_func (this, lookup_index);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    59
    nesting_level_left++;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    60
    return HB_VOID;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    61
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    62
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    63
  bool should_visit_lookup (unsigned int lookup_index)
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    64
  {
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    65
    if (is_lookup_done (lookup_index))
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    66
      return false;
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    67
    done_lookups->set (lookup_index, glyphs->get_population ());
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    68
    return true;
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    69
  }
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    70
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    71
  bool is_lookup_done (unsigned int lookup_index)
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    72
  {
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    73
    // Have we visited this lookup with the current set of glyphs?
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    74
    return done_lookups->get (lookup_index) == glyphs->get_population ();
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    75
  }
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    76
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    77
  hb_face_t *face;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    78
  hb_set_t *glyphs;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    79
  recurse_func_t recurse_func;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    80
  unsigned int nesting_level_left;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    81
  unsigned int debug_depth;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    82
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    83
  hb_closure_context_t (hb_face_t *face_,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    84
                        hb_set_t *glyphs_,
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    85
                        hb_map_t *done_lookups_,
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
    86
                        unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) :
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    87
                          face (face_),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    88
                          glyphs (glyphs_),
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
    89
                          recurse_func (nullptr),
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    90
                          nesting_level_left (nesting_level_left_),
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    91
                          debug_depth (0),
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    92
                          done_lookups (done_lookups_) {}
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    93
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    94
  void set_recurse_func (recurse_func_t func) { recurse_func = func; }
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    95
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    96
  private:
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
    97
  hb_map_t *done_lookups;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    98
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    99
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   100
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   101
struct hb_would_apply_context_t :
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   102
       hb_dispatch_context_t<hb_would_apply_context_t, bool, HB_DEBUG_WOULD_APPLY>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   103
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   104
  inline const char *get_name (void) { return "WOULD_APPLY"; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   105
  template <typename T>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   106
  inline return_t dispatch (const T &obj) { return obj.would_apply (this); }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   107
  static return_t default_return_value (void) { return false; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   108
  bool stop_sublookup_iteration (return_t r) const { return r; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   109
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   110
  hb_face_t *face;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   111
  const hb_codepoint_t *glyphs;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   112
  unsigned int len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   113
  bool zero_context;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   114
  unsigned int debug_depth;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   115
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   116
  hb_would_apply_context_t (hb_face_t *face_,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   117
                            const hb_codepoint_t *glyphs_,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   118
                            unsigned int len_,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   119
                            bool zero_context_) :
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   120
                              face (face_),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   121
                              glyphs (glyphs_),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   122
                              len (len_),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   123
                              zero_context (zero_context_),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   124
                              debug_depth (0) {}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   125
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   126
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   127
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   128
struct hb_collect_glyphs_context_t :
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   129
       hb_dispatch_context_t<hb_collect_glyphs_context_t, hb_void_t, HB_DEBUG_COLLECT_GLYPHS>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   130
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   131
  inline const char *get_name (void) { return "COLLECT_GLYPHS"; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   132
  typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   133
  template <typename T>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   134
  inline return_t dispatch (const T &obj) { obj.collect_glyphs (this); return HB_VOID; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   135
  static return_t default_return_value (void) { return HB_VOID; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   136
  bool stop_sublookup_iteration (return_t r HB_UNUSED) const { return false; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   137
  return_t recurse (unsigned int lookup_index)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   138
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   139
    if (unlikely (nesting_level_left == 0 || !recurse_func))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   140
      return default_return_value ();
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   141
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   142
    /* Note that GPOS sets recurse_func to nullptr already, so it doesn't get
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   143
     * past the previous check.  For GSUB, we only want to collect the output
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   144
     * glyphs in the recursion.  If output is not requested, we can go home now.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   145
     *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   146
     * Note further, that the above is not exactly correct.  A recursed lookup
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   147
     * is allowed to match input that is not matched in the context, but that's
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   148
     * not how most fonts are built.  It's possible to relax that and recurse
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   149
     * with all sets here if it proves to be an issue.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   150
     */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   151
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   152
    if (output == hb_set_get_empty ())
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   153
      return HB_VOID;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   154
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   155
    /* Return if new lookup was recursed to before. */
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   156
    if (recursed_lookups->has (lookup_index))
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   157
      return HB_VOID;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   158
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   159
    hb_set_t *old_before = before;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   160
    hb_set_t *old_input  = input;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   161
    hb_set_t *old_after  = after;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   162
    before = input = after = hb_set_get_empty ();
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   163
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   164
    nesting_level_left--;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   165
    recurse_func (this, lookup_index);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   166
    nesting_level_left++;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   167
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   168
    before = old_before;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   169
    input  = old_input;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   170
    after  = old_after;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   171
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   172
    recursed_lookups->add (lookup_index);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   173
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   174
    return HB_VOID;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   175
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   176
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   177
  hb_face_t *face;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   178
  hb_set_t *before;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   179
  hb_set_t *input;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   180
  hb_set_t *after;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   181
  hb_set_t *output;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   182
  recurse_func_t recurse_func;
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   183
  hb_set_t *recursed_lookups;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   184
  unsigned int nesting_level_left;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   185
  unsigned int debug_depth;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   186
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   187
  hb_collect_glyphs_context_t (hb_face_t *face_,
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   188
                               hb_set_t  *glyphs_before, /* OUT. May be nullptr */
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   189
                               hb_set_t  *glyphs_input,  /* OUT. May be nullptr */
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   190
                               hb_set_t  *glyphs_after,  /* OUT. May be nullptr */
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   191
                               hb_set_t  *glyphs_output, /* OUT. May be nullptr */
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   192
                               unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) :
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   193
                              face (face_),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   194
                              before (glyphs_before ? glyphs_before : hb_set_get_empty ()),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   195
                              input  (glyphs_input  ? glyphs_input  : hb_set_get_empty ()),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   196
                              after  (glyphs_after  ? glyphs_after  : hb_set_get_empty ()),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   197
                              output (glyphs_output ? glyphs_output : hb_set_get_empty ()),
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   198
                              recurse_func (nullptr),
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   199
                              recursed_lookups (nullptr),
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   200
                              nesting_level_left (nesting_level_left_),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   201
                              debug_depth (0)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   202
  {
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   203
    recursed_lookups = hb_set_create ();
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   204
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   205
  ~hb_collect_glyphs_context_t (void)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   206
  {
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   207
    hb_set_destroy (recursed_lookups);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   208
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   209
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   210
  void set_recurse_func (recurse_func_t func) { recurse_func = func; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   211
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   212
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   213
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   214
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   215
/* XXX Can we remove this? */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   216
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   217
template <typename set_t>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   218
struct hb_add_coverage_context_t :
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   219
       hb_dispatch_context_t<hb_add_coverage_context_t<set_t>, const Coverage &, HB_DEBUG_GET_COVERAGE>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   220
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   221
  inline const char *get_name (void) { return "GET_COVERAGE"; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   222
  typedef const Coverage &return_t;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   223
  template <typename T>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   224
  inline return_t dispatch (const T &obj) { return obj.get_coverage (); }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   225
  static return_t default_return_value (void) { return Null(Coverage); }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   226
  bool stop_sublookup_iteration (return_t r) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   227
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   228
    r.add_coverage (set);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   229
    return false;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   230
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   231
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   232
  hb_add_coverage_context_t (set_t *set_) :
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   233
                            set (set_),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   234
                            debug_depth (0) {}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   235
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   236
  set_t *set;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   237
  unsigned int debug_depth;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   238
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   239
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   240
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   241
struct hb_ot_apply_context_t :
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   242
       hb_dispatch_context_t<hb_ot_apply_context_t, bool, HB_DEBUG_APPLY>
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   243
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   244
  struct matcher_t
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   245
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   246
    inline matcher_t (void) :
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   247
             lookup_props (0),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   248
             ignore_zwnj (false),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   249
             ignore_zwj (false),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   250
             mask (-1),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   251
#define arg1(arg) (arg) /* Remove the macro to see why it's needed! */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   252
             syllable arg1(0),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   253
#undef arg1
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   254
             match_func (nullptr),
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   255
             match_data (nullptr) {};
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   256
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   257
    typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const HBUINT16 &value, const void *data);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   258
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   259
    inline void set_ignore_zwnj (bool ignore_zwnj_) { ignore_zwnj = ignore_zwnj_; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   260
    inline void set_ignore_zwj (bool ignore_zwj_) { ignore_zwj = ignore_zwj_; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   261
    inline void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   262
    inline void set_mask (hb_mask_t mask_) { mask = mask_; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   263
    inline void set_syllable (uint8_t syllable_)  { syllable = syllable_; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   264
    inline void set_match_func (match_func_t match_func_,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   265
                                const void *match_data_)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   266
    { match_func = match_func_; match_data = match_data_; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   267
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   268
    enum may_match_t {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   269
      MATCH_NO,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   270
      MATCH_YES,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   271
      MATCH_MAYBE
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   272
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   273
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   274
    inline may_match_t may_match (const hb_glyph_info_t &info,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   275
                                  const HBUINT16          *glyph_data) const
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   276
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   277
      if (!(info.mask & mask) ||
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   278
          (syllable && syllable != info.syllable ()))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   279
        return MATCH_NO;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   280
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   281
      if (match_func)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   282
        return match_func (info.codepoint, *glyph_data, match_data) ? MATCH_YES : MATCH_NO;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   283
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   284
      return MATCH_MAYBE;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   285
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   286
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   287
    enum may_skip_t {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   288
      SKIP_NO,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   289
      SKIP_YES,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   290
      SKIP_MAYBE
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   291
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   292
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   293
    inline may_skip_t
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   294
    may_skip (const hb_ot_apply_context_t *c,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   295
              const hb_glyph_info_t    &info) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   296
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   297
      if (!c->check_glyph_property (&info, lookup_props))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   298
        return SKIP_YES;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   299
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   300
      if (unlikely (_hb_glyph_info_is_default_ignorable_and_not_hidden (&info) &&
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   301
                    (ignore_zwnj || !_hb_glyph_info_is_zwnj (&info)) &&
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   302
                    (ignore_zwj || !_hb_glyph_info_is_zwj (&info))))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   303
        return SKIP_MAYBE;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   304
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   305
      return SKIP_NO;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   306
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   307
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   308
    protected:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   309
    unsigned int lookup_props;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   310
    bool ignore_zwnj;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   311
    bool ignore_zwj;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   312
    hb_mask_t mask;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   313
    uint8_t syllable;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   314
    match_func_t match_func;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   315
    const void *match_data;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   316
  };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   317
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   318
  struct skipping_iterator_t
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   319
  {
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   320
    inline void init (hb_ot_apply_context_t *c_, bool context_match = false)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   321
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   322
      c = c_;
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   323
      match_glyph_data = nullptr;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   324
      matcher.set_match_func (nullptr, nullptr);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   325
      matcher.set_lookup_props (c->lookup_props);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   326
      /* Ignore ZWNJ if we are matching GSUB context, or matching GPOS. */
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   327
      matcher.set_ignore_zwnj (c->table_index == 1 || (context_match && c->auto_zwnj));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   328
      /* Ignore ZWJ if we are matching GSUB context, or matching GPOS, or if asked to. */
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   329
      matcher.set_ignore_zwj  (c->table_index == 1 || (context_match || c->auto_zwj));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   330
      matcher.set_mask (context_match ? -1 : c->lookup_mask);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   331
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   332
    inline void set_lookup_props (unsigned int lookup_props)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   333
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   334
      matcher.set_lookup_props (lookup_props);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   335
    }
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   336
    inline void set_match_func (matcher_t::match_func_t match_func_,
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   337
                                const void *match_data_,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   338
                                const HBUINT16 glyph_data[])
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   339
    {
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   340
      matcher.set_match_func (match_func_, match_data_);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   341
      match_glyph_data = glyph_data;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   342
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   343
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   344
    inline void reset (unsigned int start_index_,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   345
                       unsigned int num_items_)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   346
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   347
      idx = start_index_;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   348
      num_items = num_items_;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   349
      end = c->buffer->len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   350
      matcher.set_syllable (start_index_ == c->buffer->idx ? c->buffer->cur().syllable () : 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   351
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   352
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   353
    inline void reject (void) { num_items++; match_glyph_data--; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   354
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   355
    inline matcher_t::may_skip_t
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   356
    may_skip (const hb_glyph_info_t    &info) const
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   357
    {
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   358
      return matcher.may_skip (c, info);
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   359
    }
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   360
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   361
    inline bool next (void)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   362
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   363
      assert (num_items > 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   364
      while (idx + num_items < end)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   365
      {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   366
        idx++;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   367
        const hb_glyph_info_t &info = c->buffer->info[idx];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   368
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   369
        matcher_t::may_skip_t skip = matcher.may_skip (c, info);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   370
        if (unlikely (skip == matcher_t::SKIP_YES))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   371
          continue;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   372
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   373
        matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   374
        if (match == matcher_t::MATCH_YES ||
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   375
            (match == matcher_t::MATCH_MAYBE &&
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   376
             skip == matcher_t::SKIP_NO))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   377
        {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   378
          num_items--;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   379
          match_glyph_data++;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   380
          return true;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   381
        }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   382
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   383
        if (skip == matcher_t::SKIP_NO)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   384
          return false;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   385
      }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   386
      return false;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   387
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   388
    inline bool prev (void)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   389
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   390
      assert (num_items > 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   391
      while (idx >= num_items)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   392
      {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   393
        idx--;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   394
        const hb_glyph_info_t &info = c->buffer->out_info[idx];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   395
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   396
        matcher_t::may_skip_t skip = matcher.may_skip (c, info);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   397
        if (unlikely (skip == matcher_t::SKIP_YES))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   398
          continue;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   399
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   400
        matcher_t::may_match_t match = matcher.may_match (info, match_glyph_data);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   401
        if (match == matcher_t::MATCH_YES ||
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   402
            (match == matcher_t::MATCH_MAYBE &&
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   403
             skip == matcher_t::SKIP_NO))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   404
        {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   405
          num_items--;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   406
          match_glyph_data++;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   407
          return true;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   408
        }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   409
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   410
        if (skip == matcher_t::SKIP_NO)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   411
          return false;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   412
      }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   413
      return false;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   414
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   415
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   416
    unsigned int idx;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   417
    protected:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   418
    hb_ot_apply_context_t *c;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   419
    matcher_t matcher;
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   420
    const HBUINT16 *match_glyph_data;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   421
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   422
    unsigned int num_items;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   423
    unsigned int end;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   424
  };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   425
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   426
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   427
  inline const char *get_name (void) { return "APPLY"; }
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   428
  typedef return_t (*recurse_func_t) (hb_ot_apply_context_t *c, unsigned int lookup_index);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   429
  template <typename T>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   430
  inline return_t dispatch (const T &obj) { return obj.apply (this); }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   431
  static return_t default_return_value (void) { return false; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   432
  bool stop_sublookup_iteration (return_t r) const { return r; }
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   433
  return_t recurse (unsigned int sub_lookup_index)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   434
  {
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   435
    if (unlikely (nesting_level_left == 0 || !recurse_func || buffer->max_ops-- <= 0))
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   436
      return default_return_value ();
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   437
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   438
    nesting_level_left--;
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   439
    bool ret = recurse_func (this, sub_lookup_index);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   440
    nesting_level_left++;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   441
    return ret;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   442
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   443
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   444
  skipping_iterator_t iter_input, iter_context;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   445
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   446
  hb_font_t *font;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   447
  hb_face_t *face;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   448
  hb_buffer_t *buffer;
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   449
  recurse_func_t recurse_func;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   450
  const GDEF &gdef;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   451
  const VariationStore &var_store;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   452
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   453
  hb_direction_t direction;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   454
  hb_mask_t lookup_mask;
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   455
  unsigned int table_index; /* GSUB/GPOS */
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   456
  unsigned int lookup_index;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   457
  unsigned int lookup_props;
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   458
  unsigned int nesting_level_left;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   459
  unsigned int debug_depth;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   460
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   461
  bool auto_zwnj;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   462
  bool auto_zwj;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   463
  bool has_glyph_classes;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   464
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   465
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   466
  hb_ot_apply_context_t (unsigned int table_index_,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   467
                      hb_font_t *font_,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   468
                      hb_buffer_t *buffer_) :
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   469
                        iter_input (), iter_context (),
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   470
                        font (font_), face (font->face), buffer (buffer_),
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   471
                        recurse_func (nullptr),
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   472
                        gdef (*hb_ot_layout_from_face (face)->gdef),
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   473
                        var_store (gdef.get_var_store ()),
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   474
                        direction (buffer_->props.direction),
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   475
                        lookup_mask (1),
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   476
                        table_index (table_index_),
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   477
                        lookup_index ((unsigned int) -1),
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   478
                        lookup_props (0),
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   479
                        nesting_level_left (HB_MAX_NESTING_LEVEL),
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   480
                        debug_depth (0),
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   481
                        auto_zwnj (true),
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   482
                        auto_zwj (true),
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   483
                        has_glyph_classes (gdef.has_glyph_classes ()) {}
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   484
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   485
  inline void set_lookup_mask (hb_mask_t mask) { lookup_mask = mask; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   486
  inline void set_auto_zwj (bool auto_zwj_) { auto_zwj = auto_zwj_; }
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   487
  inline void set_auto_zwnj (bool auto_zwnj_) { auto_zwnj = auto_zwnj_; }
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   488
  inline void set_recurse_func (recurse_func_t func) { recurse_func = func; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   489
  inline void set_lookup_index (unsigned int lookup_index_) { lookup_index = lookup_index_; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   490
  inline void set_lookup_props (unsigned int lookup_props_)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   491
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   492
    lookup_props = lookup_props_;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   493
    iter_input.init (this, false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   494
    iter_context.init (this, true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   495
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   496
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   497
  inline bool
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   498
  match_properties_mark (hb_codepoint_t  glyph,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   499
                         unsigned int    glyph_props,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   500
                         unsigned int    match_props) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   501
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   502
    /* If using mark filtering sets, the high short of
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   503
     * match_props has the set index.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   504
     */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   505
    if (match_props & LookupFlag::UseMarkFilteringSet)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   506
      return gdef.mark_set_covers (match_props >> 16, glyph);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   507
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   508
    /* The second byte of match_props has the meaning
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   509
     * "ignore marks of attachment type different than
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   510
     * the attachment type specified."
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   511
     */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   512
    if (match_props & LookupFlag::MarkAttachmentType)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   513
      return (match_props & LookupFlag::MarkAttachmentType) == (glyph_props & LookupFlag::MarkAttachmentType);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   514
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   515
    return true;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   516
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   517
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   518
  inline bool
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   519
  check_glyph_property (const hb_glyph_info_t *info,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   520
                        unsigned int  match_props) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   521
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   522
    hb_codepoint_t glyph = info->codepoint;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   523
    unsigned int glyph_props = _hb_glyph_info_get_glyph_props (info);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   524
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   525
    /* Not covered, if, for example, glyph class is ligature and
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   526
     * match_props includes LookupFlags::IgnoreLigatures
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   527
     */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   528
    if (glyph_props & match_props & LookupFlag::IgnoreFlags)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   529
      return false;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   530
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   531
    if (unlikely (glyph_props & HB_OT_LAYOUT_GLYPH_PROPS_MARK))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   532
      return match_properties_mark (glyph, glyph_props, match_props);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   533
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   534
    return true;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   535
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   536
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   537
  inline void _set_glyph_props (hb_codepoint_t glyph_index,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   538
                          unsigned int class_guess = 0,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   539
                          bool ligature = false,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   540
                          bool component = false) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   541
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   542
    unsigned int add_in = _hb_glyph_info_get_glyph_props (&buffer->cur()) &
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   543
                          HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   544
    add_in |= HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   545
    if (ligature)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   546
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   547
      add_in |= HB_OT_LAYOUT_GLYPH_PROPS_LIGATED;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   548
      /* In the only place that the MULTIPLIED bit is used, Uniscribe
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   549
       * seems to only care about the "last" transformation between
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   550
       * Ligature and Multiple substitions.  Ie. if you ligate, expand,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   551
       * and ligate again, it forgives the multiplication and acts as
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   552
       * if only ligation happened.  As such, clear MULTIPLIED bit.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   553
       */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   554
      add_in &= ~HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   555
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   556
    if (component)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   557
      add_in |= HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   558
    if (likely (has_glyph_classes))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   559
      _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | gdef.get_glyph_props (glyph_index));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   560
    else if (class_guess)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   561
      _hb_glyph_info_set_glyph_props (&buffer->cur(), add_in | class_guess);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   562
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   563
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   564
  inline void replace_glyph (hb_codepoint_t glyph_index) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   565
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   566
    _set_glyph_props (glyph_index);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   567
    buffer->replace_glyph (glyph_index);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   568
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   569
  inline void replace_glyph_inplace (hb_codepoint_t glyph_index) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   570
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   571
    _set_glyph_props (glyph_index);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   572
    buffer->cur().codepoint = glyph_index;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   573
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   574
  inline void replace_glyph_with_ligature (hb_codepoint_t glyph_index,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   575
                                           unsigned int class_guess) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   576
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   577
    _set_glyph_props (glyph_index, class_guess, true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   578
    buffer->replace_glyph (glyph_index);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   579
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   580
  inline void output_glyph_for_component (hb_codepoint_t glyph_index,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   581
                                          unsigned int class_guess) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   582
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   583
    _set_glyph_props (glyph_index, class_guess, false, true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   584
    buffer->output_glyph (glyph_index);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   585
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   586
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   587
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   588
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   589
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   590
typedef bool (*intersects_func_t) (hb_set_t *glyphs, const HBUINT16 &value, const void *data);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   591
typedef void (*collect_glyphs_func_t) (hb_set_t *glyphs, const HBUINT16 &value, const void *data);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   592
typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const HBUINT16 &value, const void *data);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   593
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   594
struct ContextClosureFuncs
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   595
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   596
  intersects_func_t intersects;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   597
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   598
struct ContextCollectGlyphsFuncs
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   599
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   600
  collect_glyphs_func_t collect;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   601
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   602
struct ContextApplyFuncs
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   603
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   604
  match_func_t match;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   605
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   606
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   607
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   608
static inline bool intersects_glyph (hb_set_t *glyphs, const HBUINT16 &value, const void *data HB_UNUSED)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   609
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   610
  return glyphs->has (value);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   611
}
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   612
static inline bool intersects_class (hb_set_t *glyphs, const HBUINT16 &value, const void *data)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   613
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   614
  const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   615
  return class_def.intersects_class (glyphs, value);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   616
}
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   617
static inline bool intersects_coverage (hb_set_t *glyphs, const HBUINT16 &value, const void *data)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   618
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   619
  const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   620
  return (data+coverage).intersects (glyphs);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   621
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   622
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   623
static inline bool intersects_array (hb_closure_context_t *c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   624
                                     unsigned int count,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   625
                                     const HBUINT16 values[],
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   626
                                     intersects_func_t intersects_func,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   627
                                     const void *intersects_data)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   628
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   629
  for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   630
    if (likely (!intersects_func (c->glyphs, values[i], intersects_data)))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   631
      return false;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   632
  return true;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   633
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   634
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   635
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   636
static inline void collect_glyph (hb_set_t *glyphs, const HBUINT16 &value, const void *data HB_UNUSED)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   637
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   638
  glyphs->add (value);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   639
}
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   640
static inline void collect_class (hb_set_t *glyphs, const HBUINT16 &value, const void *data)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   641
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   642
  const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   643
  class_def.add_class (glyphs, value);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   644
}
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   645
static inline void collect_coverage (hb_set_t *glyphs, const HBUINT16 &value, const void *data)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   646
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   647
  const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   648
  (data+coverage).add_coverage (glyphs);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   649
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   650
static inline void collect_array (hb_collect_glyphs_context_t *c HB_UNUSED,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   651
                                  hb_set_t *glyphs,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   652
                                  unsigned int count,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   653
                                  const HBUINT16 values[],
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   654
                                  collect_glyphs_func_t collect_func,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   655
                                  const void *collect_data)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   656
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   657
  for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   658
    collect_func (glyphs, values[i], collect_data);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   659
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   660
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   661
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   662
static inline bool match_glyph (hb_codepoint_t glyph_id, const HBUINT16 &value, const void *data HB_UNUSED)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   663
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   664
  return glyph_id == value;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   665
}
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   666
static inline bool match_class (hb_codepoint_t glyph_id, const HBUINT16 &value, const void *data)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   667
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   668
  const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   669
  return class_def.get_class (glyph_id) == value;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   670
}
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   671
static inline bool match_coverage (hb_codepoint_t glyph_id, const HBUINT16 &value, const void *data)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   672
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   673
  const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   674
  return (data+coverage).get_coverage (glyph_id) != NOT_COVERED;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   675
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   676
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   677
static inline bool would_match_input (hb_would_apply_context_t *c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   678
                                      unsigned int count, /* Including the first glyph (not matched) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   679
                                      const HBUINT16 input[], /* Array of input values--start with second glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   680
                                      match_func_t match_func,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   681
                                      const void *match_data)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   682
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   683
  if (count != c->len)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   684
    return false;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   685
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   686
  for (unsigned int i = 1; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   687
    if (likely (!match_func (c->glyphs[i], input[i - 1], match_data)))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   688
      return false;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   689
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   690
  return true;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   691
}
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   692
static inline bool match_input (hb_ot_apply_context_t *c,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   693
                                unsigned int count, /* Including the first glyph (not matched) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   694
                                const HBUINT16 input[], /* Array of input values--start with second glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   695
                                match_func_t match_func,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   696
                                const void *match_data,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   697
                                unsigned int *end_offset,
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   698
                                unsigned int match_positions[HB_MAX_CONTEXT_LENGTH],
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   699
                                bool *p_is_mark_ligature = nullptr,
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   700
                                unsigned int *p_total_component_count = nullptr)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   701
{
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   702
  TRACE_APPLY (nullptr);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   703
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   704
  if (unlikely (count > HB_MAX_CONTEXT_LENGTH)) return_trace (false);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   705
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   706
  hb_buffer_t *buffer = c->buffer;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   707
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   708
  hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   709
  skippy_iter.reset (buffer->idx, count - 1);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   710
  skippy_iter.set_match_func (match_func, match_data, input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   711
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   712
  /*
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   713
   * This is perhaps the trickiest part of OpenType...  Remarks:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   714
   *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   715
   * - If all components of the ligature were marks, we call this a mark ligature.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   716
   *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   717
   * - If there is no GDEF, and the ligature is NOT a mark ligature, we categorize
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   718
   *   it as a ligature glyph.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   719
   *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   720
   * - Ligatures cannot be formed across glyphs attached to different components
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   721
   *   of previous ligatures.  Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   722
   *   LAM,LAM,HEH form a ligature, leaving SHADDA,FATHA next to eachother.
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   723
   *   However, it would be wrong to ligate that SHADDA,FATHA sequence.
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   724
   *   There are a couple of exceptions to this:
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   725
   *
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   726
   *   o If a ligature tries ligating with marks that belong to it itself, go ahead,
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   727
   *     assuming that the font designer knows what they are doing (otherwise it can
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   728
   *     break Indic stuff when a matra wants to ligate with a conjunct,
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   729
   *
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   730
   *   o If two marks want to ligate and they belong to different components of the
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   731
   *     same ligature glyph, and said ligature glyph is to be ignored according to
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   732
   *     mark-filtering rules, then allow.
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   733
   *     https://github.com/harfbuzz/harfbuzz/issues/545
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   734
   */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   735
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   736
  bool is_mark_ligature = _hb_glyph_info_is_mark (&buffer->cur());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   737
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   738
  unsigned int total_component_count = 0;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   739
  total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->cur());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   740
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   741
  unsigned int first_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   742
  unsigned int first_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->cur());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   743
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   744
  enum {
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   745
    LIGBASE_NOT_CHECKED,
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   746
    LIGBASE_MAY_NOT_SKIP,
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   747
    LIGBASE_MAY_SKIP
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   748
  } ligbase = LIGBASE_NOT_CHECKED;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   749
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   750
  match_positions[0] = buffer->idx;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   751
  for (unsigned int i = 1; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   752
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   753
    if (!skippy_iter.next ()) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   754
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   755
    match_positions[i] = skippy_iter.idx;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   756
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   757
    unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx]);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   758
    unsigned int this_lig_comp = _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   759
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   760
    if (first_lig_id && first_lig_comp)
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   761
    {
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   762
      /* If first component was attached to a previous ligature component,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   763
       * all subsequent components should be attached to the same ligature
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   764
       * component, otherwise we shouldn't ligate them... */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   765
      if (first_lig_id != this_lig_id || first_lig_comp != this_lig_comp)
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   766
      {
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   767
        /* ...unless, we are attached to a base ligature and that base
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   768
         * ligature is ignorable. */
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   769
        if (ligbase == LIGBASE_NOT_CHECKED)
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   770
        {
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   771
          bool found = false;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   772
          const hb_glyph_info_t *out = buffer->out_info;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   773
          unsigned int j = buffer->out_len;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   774
          while (j && _hb_glyph_info_get_lig_id (&out[j - 1]) == first_lig_id)
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   775
          {
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   776
            if (_hb_glyph_info_get_lig_comp (&out[j - 1]) == 0)
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   777
            {
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   778
              j--;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   779
              found = true;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   780
              break;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   781
            }
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   782
            j--;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   783
          }
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   784
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   785
          if (found && skippy_iter.may_skip (out[j]) == hb_ot_apply_context_t::matcher_t::SKIP_YES)
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   786
            ligbase = LIGBASE_MAY_SKIP;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   787
          else
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   788
            ligbase = LIGBASE_MAY_NOT_SKIP;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   789
        }
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   790
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   791
        if (ligbase == LIGBASE_MAY_NOT_SKIP)
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   792
          return_trace (false);
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   793
      }
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   794
    }
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   795
    else
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   796
    {
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   797
      /* If first component was NOT attached to a previous ligature component,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   798
       * all subsequent components should also NOT be attached to any ligature
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   799
       * component, unless they are attached to the first component itself! */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   800
      if (this_lig_id && this_lig_comp && (this_lig_id != first_lig_id))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   801
        return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   802
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   803
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   804
    is_mark_ligature = is_mark_ligature && _hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx]);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   805
    total_component_count += _hb_glyph_info_get_lig_num_comps (&buffer->info[skippy_iter.idx]);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   806
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   807
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   808
  *end_offset = skippy_iter.idx - buffer->idx + 1;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   809
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   810
  if (p_is_mark_ligature)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   811
    *p_is_mark_ligature = is_mark_ligature;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   812
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   813
  if (p_total_component_count)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   814
    *p_total_component_count = total_component_count;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   815
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   816
  return_trace (true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   817
}
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   818
static inline bool ligate_input (hb_ot_apply_context_t *c,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   819
                                 unsigned int count, /* Including the first glyph */
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   820
                                 unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], /* Including the first glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   821
                                 unsigned int match_length,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   822
                                 hb_codepoint_t lig_glyph,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   823
                                 bool is_mark_ligature,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   824
                                 unsigned int total_component_count)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   825
{
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   826
  TRACE_APPLY (nullptr);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   827
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   828
  hb_buffer_t *buffer = c->buffer;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   829
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   830
  buffer->merge_clusters (buffer->idx, buffer->idx + match_length);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   831
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   832
  /*
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   833
   * - If it *is* a mark ligature, we don't allocate a new ligature id, and leave
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   834
   *   the ligature to keep its old ligature id.  This will allow it to attach to
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   835
   *   a base ligature in GPOS.  Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   836
   *   and LAM,LAM,HEH for a ligature, they will leave SHADDA and FATHA wit a
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   837
   *   ligature id and component value of 2.  Then if SHADDA,FATHA form a ligature
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   838
   *   later, we don't want them to lose their ligature id/component, otherwise
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   839
   *   GPOS will fail to correctly position the mark ligature on top of the
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   840
   *   LAM,LAM,HEH ligature.  See:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   841
   *     https://bugzilla.gnome.org/show_bug.cgi?id=676343
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   842
   *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   843
   * - If a ligature is formed of components that some of which are also ligatures
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   844
   *   themselves, and those ligature components had marks attached to *their*
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   845
   *   components, we have to attach the marks to the new ligature component
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   846
   *   positions!  Now *that*'s tricky!  And these marks may be following the
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   847
   *   last component of the whole sequence, so we should loop forward looking
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   848
   *   for them and update them.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   849
   *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   850
   *   Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   851
   *   'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   852
   *   id and component == 1.  Now, during 'liga', the LAM and the LAM-HEH ligature
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   853
   *   form a LAM-LAM-HEH ligature.  We need to reassign the SHADDA and FATHA to
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   854
   *   the new ligature with a component value of 2.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   855
   *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   856
   *   This in fact happened to a font...  See:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   857
   *   https://bugzilla.gnome.org/show_bug.cgi?id=437633
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   858
   */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   859
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   860
  unsigned int klass = is_mark_ligature ? 0 : HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   861
  unsigned int lig_id = is_mark_ligature ? 0 : _hb_allocate_lig_id (buffer);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   862
  unsigned int last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   863
  unsigned int last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   864
  unsigned int components_so_far = last_num_components;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   865
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   866
  if (!is_mark_ligature)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   867
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   868
    _hb_glyph_info_set_lig_props_for_ligature (&buffer->cur(), lig_id, total_component_count);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   869
    if (_hb_glyph_info_get_general_category (&buffer->cur()) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   870
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   871
      _hb_glyph_info_set_general_category (&buffer->cur(), HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   872
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   873
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   874
  c->replace_glyph_with_ligature (lig_glyph, klass);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   875
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   876
  for (unsigned int i = 1; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   877
  {
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
   878
    while (buffer->idx < match_positions[i] && buffer->successful)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   879
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   880
      if (!is_mark_ligature) {
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   881
        unsigned int this_comp = _hb_glyph_info_get_lig_comp (&buffer->cur());
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   882
        if (this_comp == 0)
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   883
          this_comp = last_num_components;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   884
        unsigned int new_lig_comp = components_so_far - last_num_components +
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   885
                                    MIN (this_comp, last_num_components);
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   886
          _hb_glyph_info_set_lig_props_for_mark (&buffer->cur(), lig_id, new_lig_comp);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   887
      }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   888
      buffer->next_glyph ();
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   889
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   890
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   891
    last_lig_id = _hb_glyph_info_get_lig_id (&buffer->cur());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   892
    last_num_components = _hb_glyph_info_get_lig_num_comps (&buffer->cur());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   893
    components_so_far += last_num_components;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   894
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   895
    /* Skip the base glyph */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   896
    buffer->idx++;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   897
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   898
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   899
  if (!is_mark_ligature && last_lig_id) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   900
    /* Re-adjust components for any marks following. */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   901
    for (unsigned int i = buffer->idx; i < buffer->len; i++) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   902
      if (last_lig_id == _hb_glyph_info_get_lig_id (&buffer->info[i])) {
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   903
        unsigned int this_comp = _hb_glyph_info_get_lig_comp (&buffer->info[i]);
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   904
        if (!this_comp)
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   905
          break;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   906
        unsigned int new_lig_comp = components_so_far - last_num_components +
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   907
                                    MIN (this_comp, last_num_components);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   908
        _hb_glyph_info_set_lig_props_for_mark (&buffer->info[i], lig_id, new_lig_comp);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   909
      } else
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   910
        break;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   911
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   912
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   913
  return_trace (true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   914
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   915
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   916
static inline bool match_backtrack (hb_ot_apply_context_t *c,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   917
                                    unsigned int count,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   918
                                    const HBUINT16 backtrack[],
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   919
                                    match_func_t match_func,
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   920
                                    const void *match_data,
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   921
                                    unsigned int *match_start)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   922
{
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   923
  TRACE_APPLY (nullptr);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   924
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   925
  hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_context;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   926
  skippy_iter.reset (c->buffer->backtrack_len (), count);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   927
  skippy_iter.set_match_func (match_func, match_data, backtrack);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   928
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   929
  for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   930
    if (!skippy_iter.prev ())
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   931
      return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   932
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   933
  *match_start = skippy_iter.idx;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   934
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   935
  return_trace (true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   936
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   937
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   938
static inline bool match_lookahead (hb_ot_apply_context_t *c,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   939
                                    unsigned int count,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   940
                                    const HBUINT16 lookahead[],
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   941
                                    match_func_t match_func,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   942
                                    const void *match_data,
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   943
                                    unsigned int offset,
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   944
                                    unsigned int *end_index)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   945
{
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   946
  TRACE_APPLY (nullptr);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   947
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   948
  hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_context;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   949
  skippy_iter.reset (c->buffer->idx + offset - 1, count);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   950
  skippy_iter.set_match_func (match_func, match_data, lookahead);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   951
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   952
  for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   953
    if (!skippy_iter.next ())
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   954
      return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   955
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   956
  *end_index = skippy_iter.idx + 1;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   957
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   958
  return_trace (true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   959
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   960
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   961
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   962
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   963
struct LookupRecord
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   964
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   965
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   966
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   967
    TRACE_SANITIZE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   968
    return_trace (c->check_struct (this));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   969
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   970
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   971
  HBUINT16      sequenceIndex;          /* Index into current glyph
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   972
                                         * sequence--first glyph = 0 */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   973
  HBUINT16      lookupListIndex;        /* Lookup to apply to that
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   974
                                         * position--zero--based */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   975
  public:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   976
  DEFINE_SIZE_STATIC (4);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   977
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   978
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   979
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   980
template <typename context_t>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   981
static inline void recurse_lookups (context_t *c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   982
                                    unsigned int lookupCount,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   983
                                    const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   984
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   985
  for (unsigned int i = 0; i < lookupCount; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   986
    c->recurse (lookupRecord[i].lookupListIndex);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   987
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   988
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
   989
static inline bool apply_lookup (hb_ot_apply_context_t *c,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   990
                                 unsigned int count, /* Including the first glyph */
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
   991
                                 unsigned int match_positions[HB_MAX_CONTEXT_LENGTH], /* Including the first glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   992
                                 unsigned int lookupCount,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   993
                                 const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   994
                                 unsigned int match_length)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   995
{
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   996
  TRACE_APPLY (nullptr);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   997
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   998
  hb_buffer_t *buffer = c->buffer;
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
   999
  int end;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1000
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1001
  /* All positions are distance from beginning of *output* buffer.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1002
   * Adjust. */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1003
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1004
    unsigned int bl = buffer->backtrack_len ();
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1005
    end = bl + match_length;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1006
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1007
    int delta = bl - buffer->idx;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1008
    /* Convert positions to new indexing. */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1009
    for (unsigned int j = 0; j < count; j++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1010
      match_positions[j] += delta;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1011
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1012
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1013
  for (unsigned int i = 0; i < lookupCount && buffer->successful; i++)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1014
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1015
    unsigned int idx = lookupRecord[i].sequenceIndex;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1016
    if (idx >= count)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1017
      continue;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1018
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1019
    /* Don't recurse to ourself at same position.
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1020
     * Note that this test is too naive, it doesn't catch longer loops. */
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1021
    if (idx == 0 && lookupRecord[i].lookupListIndex == c->lookup_index)
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1022
      continue;
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1023
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1024
    if (unlikely (!buffer->move_to (match_positions[idx])))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1025
      break;
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1026
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1027
    if (unlikely (buffer->max_ops <= 0))
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1028
      break;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1029
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1030
    unsigned int orig_len = buffer->backtrack_len () + buffer->lookahead_len ();
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1031
    if (!c->recurse (lookupRecord[i].lookupListIndex))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1032
      continue;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1033
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1034
    unsigned int new_len = buffer->backtrack_len () + buffer->lookahead_len ();
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1035
    int delta = new_len - orig_len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1036
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1037
    if (!delta)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1038
        continue;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1039
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1040
    /* Recursed lookup changed buffer len.  Adjust.
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1041
     *
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1042
     * TODO:
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1043
     *
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1044
     * Right now, if buffer length increased by n, we assume n new glyphs
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1045
     * were added right after the current position, and if buffer length
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1046
     * was decreased by n, we assume n match positions after the current
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1047
     * one where removed.  The former (buffer length increased) case is
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1048
     * fine, but the decrease case can be improved in at least two ways,
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1049
     * both of which are significant:
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1050
     *
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1051
     *   - If recursed-to lookup is MultipleSubst and buffer length
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1052
     *     decreased, then it's current match position that was deleted,
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1053
     *     NOT the one after it.
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1054
     *
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1055
     *   - If buffer length was decreased by n, it does not necessarily
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1056
     *     mean that n match positions where removed, as there might
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1057
     *     have been marks and default-ignorables in the sequence.  We
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1058
     *     should instead drop match positions between current-position
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1059
     *     and current-position + n instead.
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1060
     *
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1061
     * It should be possible to construct tests for both of these cases.
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1062
     */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1063
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1064
    end += delta;
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1065
    if (end <= int (match_positions[idx]))
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1066
    {
43232
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  1067
      /* End might end up being smaller than match_positions[idx] if the recursed
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  1068
       * lookup ended up removing many items, more than we have had matched.
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  1069
       * Just never rewind end back and get out of here.
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  1070
       * https://bugs.chromium.org/p/chromium/issues/detail?id=659496 */
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  1071
      end = match_positions[idx];
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1072
      /* There can't be any further changes. */
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1073
      break;
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1074
    }
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1075
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1076
    unsigned int next = idx + 1; /* next now is the position after the recursed lookup. */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1077
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1078
    if (delta > 0)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1079
    {
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1080
      if (unlikely (delta + count > HB_MAX_CONTEXT_LENGTH))
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1081
        break;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1082
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1083
    else
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1084
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1085
      /* NOTE: delta is negative. */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1086
      delta = MAX (delta, (int) next - (int) count);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1087
      next -= delta;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1088
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1089
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1090
    /* Shift! */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1091
    memmove (match_positions + next + delta, match_positions + next,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1092
             (count - next) * sizeof (match_positions[0]));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1093
    next += delta;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1094
    count += delta;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1095
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1096
    /* Fill in new entries. */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1097
    for (unsigned int j = idx + 1; j < next; j++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1098
      match_positions[j] = match_positions[j - 1] + 1;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1099
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1100
    /* And fixup the rest. */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1101
    for (; next < count; next++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1102
      match_positions[next] += delta;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1103
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1104
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1105
  buffer->move_to (end);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1106
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1107
  return_trace (true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1108
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1109
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1110
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1111
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1112
/* Contextual lookups */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1113
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1114
struct ContextClosureLookupContext
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1115
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1116
  ContextClosureFuncs funcs;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1117
  const void *intersects_data;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1118
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1119
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1120
struct ContextCollectGlyphsLookupContext
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1121
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1122
  ContextCollectGlyphsFuncs funcs;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1123
  const void *collect_data;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1124
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1125
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1126
struct ContextApplyLookupContext
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1127
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1128
  ContextApplyFuncs funcs;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1129
  const void *match_data;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1130
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1131
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1132
static inline void context_closure_lookup (hb_closure_context_t *c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1133
                                           unsigned int inputCount, /* Including the first glyph (not matched) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1134
                                           const HBUINT16 input[], /* Array of input values--start with second glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1135
                                           unsigned int lookupCount,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1136
                                           const LookupRecord lookupRecord[],
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1137
                                           ContextClosureLookupContext &lookup_context)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1138
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1139
  if (intersects_array (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1140
                        inputCount ? inputCount - 1 : 0, input,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1141
                        lookup_context.funcs.intersects, lookup_context.intersects_data))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1142
    recurse_lookups (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1143
                     lookupCount, lookupRecord);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1144
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1145
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1146
static inline void context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1147
                                                  unsigned int inputCount, /* Including the first glyph (not matched) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1148
                                                  const HBUINT16 input[], /* Array of input values--start with second glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1149
                                                  unsigned int lookupCount,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1150
                                                  const LookupRecord lookupRecord[],
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1151
                                                  ContextCollectGlyphsLookupContext &lookup_context)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1152
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1153
  collect_array (c, c->input,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1154
                 inputCount ? inputCount - 1 : 0, input,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1155
                 lookup_context.funcs.collect, lookup_context.collect_data);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1156
  recurse_lookups (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1157
                   lookupCount, lookupRecord);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1158
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1159
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1160
static inline bool context_would_apply_lookup (hb_would_apply_context_t *c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1161
                                               unsigned int inputCount, /* Including the first glyph (not matched) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1162
                                               const HBUINT16 input[], /* Array of input values--start with second glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1163
                                               unsigned int lookupCount HB_UNUSED,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1164
                                               const LookupRecord lookupRecord[] HB_UNUSED,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1165
                                               ContextApplyLookupContext &lookup_context)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1166
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1167
  return would_match_input (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1168
                            inputCount, input,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1169
                            lookup_context.funcs.match, lookup_context.match_data);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1170
}
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1171
static inline bool context_apply_lookup (hb_ot_apply_context_t *c,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1172
                                         unsigned int inputCount, /* Including the first glyph (not matched) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1173
                                         const HBUINT16 input[], /* Array of input values--start with second glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1174
                                         unsigned int lookupCount,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1175
                                         const LookupRecord lookupRecord[],
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1176
                                         ContextApplyLookupContext &lookup_context)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1177
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1178
  unsigned int match_length = 0;
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1179
  unsigned int match_positions[HB_MAX_CONTEXT_LENGTH];
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1180
  return match_input (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1181
                      inputCount, input,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1182
                      lookup_context.funcs.match, lookup_context.match_data,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1183
                      &match_length, match_positions)
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1184
      && (c->buffer->unsafe_to_break (c->buffer->idx, c->buffer->idx + match_length),
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1185
          apply_lookup (c,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1186
                       inputCount, match_positions,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1187
                       lookupCount, lookupRecord,
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1188
                       match_length));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1189
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1190
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1191
struct Rule
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1192
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1193
  inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1194
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1195
    TRACE_CLOSURE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1196
    const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1197
    context_closure_lookup (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1198
                            inputCount, inputZ,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1199
                            lookupCount, lookupRecord,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1200
                            lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1201
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1202
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1203
  inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1204
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1205
    TRACE_COLLECT_GLYPHS (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1206
    const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1207
    context_collect_glyphs_lookup (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1208
                                   inputCount, inputZ,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1209
                                   lookupCount, lookupRecord,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1210
                                   lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1211
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1212
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1213
  inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1214
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1215
    TRACE_WOULD_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1216
    const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1217
    return_trace (context_would_apply_lookup (c, inputCount, inputZ, lookupCount, lookupRecord, lookup_context));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1218
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1219
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1220
  inline bool apply (hb_ot_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1221
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1222
    TRACE_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1223
    const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (inputZ, inputZ[0].static_size * (inputCount ? inputCount - 1 : 0));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1224
    return_trace (context_apply_lookup (c, inputCount, inputZ, lookupCount, lookupRecord, lookup_context));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1225
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1226
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1227
  public:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1228
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1229
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1230
    TRACE_SANITIZE (this);
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1231
    return_trace (inputCount.sanitize (c) &&
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1232
                  lookupCount.sanitize (c) &&
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1233
                  c->check_range (inputZ,
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1234
                                  inputZ[0].static_size * inputCount +
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1235
                                  LookupRecord::static_size * lookupCount));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1236
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1237
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1238
  protected:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1239
  HBUINT16      inputCount;             /* Total number of glyphs in input
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1240
                                         * glyph sequence--includes the first
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1241
                                         * glyph */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1242
  HBUINT16      lookupCount;            /* Number of LookupRecords */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1243
  HBUINT16      inputZ[VAR];            /* Array of match inputs--start with
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1244
                                         * second glyph */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1245
/*LookupRecord  lookupRecordX[VAR];*/   /* Array of LookupRecords--in
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1246
                                         * design order */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1247
  public:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1248
  DEFINE_SIZE_ARRAY (4, inputZ);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1249
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1250
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1251
struct RuleSet
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1252
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1253
  inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1254
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1255
    TRACE_CLOSURE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1256
    unsigned int num_rules = rule.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1257
    for (unsigned int i = 0; i < num_rules; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1258
      (this+rule[i]).closure (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1259
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1260
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1261
  inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1262
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1263
    TRACE_COLLECT_GLYPHS (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1264
    unsigned int num_rules = rule.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1265
    for (unsigned int i = 0; i < num_rules; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1266
      (this+rule[i]).collect_glyphs (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1267
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1268
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1269
  inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1270
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1271
    TRACE_WOULD_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1272
    unsigned int num_rules = rule.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1273
    for (unsigned int i = 0; i < num_rules; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1274
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1275
      if ((this+rule[i]).would_apply (c, lookup_context))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1276
        return_trace (true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1277
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1278
    return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1279
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1280
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1281
  inline bool apply (hb_ot_apply_context_t *c, ContextApplyLookupContext &lookup_context) const
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1282
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1283
    TRACE_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1284
    unsigned int num_rules = rule.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1285
    for (unsigned int i = 0; i < num_rules; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1286
    {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1287
      if ((this+rule[i]).apply (c, lookup_context))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1288
        return_trace (true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1289
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1290
    return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1291
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1292
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1293
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1294
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1295
    TRACE_SANITIZE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1296
    return_trace (rule.sanitize (c, this));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1297
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1298
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1299
  protected:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1300
  OffsetArrayOf<Rule>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1301
                rule;                   /* Array of Rule tables
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1302
                                         * ordered by preference */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1303
  public:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1304
  DEFINE_SIZE_ARRAY (2, rule);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1305
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1306
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1307
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1308
struct ContextFormat1
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1309
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1310
  inline void closure (hb_closure_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1311
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1312
    TRACE_CLOSURE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1313
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1314
    const Coverage &cov = (this+coverage);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1315
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1316
    struct ContextClosureLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1317
      {intersects_glyph},
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1318
      nullptr
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1319
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1320
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1321
    unsigned int count = ruleSet.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1322
    for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1323
      if (cov.intersects_coverage (c->glyphs, i)) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1324
        const RuleSet &rule_set = this+ruleSet[i];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1325
        rule_set.closure (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1326
      }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1327
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1328
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1329
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1330
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1331
    TRACE_COLLECT_GLYPHS (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1332
    (this+coverage).add_coverage (c->input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1333
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1334
    struct ContextCollectGlyphsLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1335
      {collect_glyph},
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1336
      nullptr
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1337
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1338
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1339
    unsigned int count = ruleSet.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1340
    for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1341
      (this+ruleSet[i]).collect_glyphs (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1342
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1343
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1344
  inline bool would_apply (hb_would_apply_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1345
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1346
    TRACE_WOULD_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1347
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1348
    const RuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1349
    struct ContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1350
      {match_glyph},
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1351
      nullptr
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1352
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1353
    return_trace (rule_set.would_apply (c, lookup_context));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1354
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1355
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1356
  inline const Coverage &get_coverage (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1357
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1358
    return this+coverage;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1359
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1360
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1361
  inline bool apply (hb_ot_apply_context_t *c) const
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1362
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1363
    TRACE_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1364
    unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1365
    if (likely (index == NOT_COVERED))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1366
      return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1367
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1368
    const RuleSet &rule_set = this+ruleSet[index];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1369
    struct ContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1370
      {match_glyph},
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1371
      nullptr
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1372
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1373
    return_trace (rule_set.apply (c, lookup_context));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1374
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1375
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1376
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1377
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1378
    TRACE_SANITIZE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1379
    return_trace (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1380
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1381
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1382
  protected:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1383
  HBUINT16      format;                 /* Format identifier--format = 1 */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1384
  OffsetTo<Coverage>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1385
                coverage;               /* Offset to Coverage table--from
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1386
                                         * beginning of table */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1387
  OffsetArrayOf<RuleSet>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1388
                ruleSet;                /* Array of RuleSet tables
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1389
                                         * ordered by Coverage Index */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1390
  public:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1391
  DEFINE_SIZE_ARRAY (6, ruleSet);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1392
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1393
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1394
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1395
struct ContextFormat2
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1396
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1397
  inline void closure (hb_closure_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1398
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1399
    TRACE_CLOSURE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1400
    if (!(this+coverage).intersects (c->glyphs))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1401
      return;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1402
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1403
    const ClassDef &class_def = this+classDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1404
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1405
    struct ContextClosureLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1406
      {intersects_class},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1407
      &class_def
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1408
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1409
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1410
    unsigned int count = ruleSet.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1411
    for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1412
      if (class_def.intersects_class (c->glyphs, i)) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1413
        const RuleSet &rule_set = this+ruleSet[i];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1414
        rule_set.closure (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1415
      }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1416
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1417
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1418
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1419
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1420
    TRACE_COLLECT_GLYPHS (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1421
    (this+coverage).add_coverage (c->input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1422
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1423
    const ClassDef &class_def = this+classDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1424
    struct ContextCollectGlyphsLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1425
      {collect_class},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1426
      &class_def
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1427
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1428
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1429
    unsigned int count = ruleSet.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1430
    for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1431
      (this+ruleSet[i]).collect_glyphs (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1432
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1433
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1434
  inline bool would_apply (hb_would_apply_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1435
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1436
    TRACE_WOULD_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1437
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1438
    const ClassDef &class_def = this+classDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1439
    unsigned int index = class_def.get_class (c->glyphs[0]);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1440
    const RuleSet &rule_set = this+ruleSet[index];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1441
    struct ContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1442
      {match_class},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1443
      &class_def
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1444
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1445
    return_trace (rule_set.would_apply (c, lookup_context));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1446
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1447
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1448
  inline const Coverage &get_coverage (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1449
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1450
    return this+coverage;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1451
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1452
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1453
  inline bool apply (hb_ot_apply_context_t *c) const
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1454
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1455
    TRACE_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1456
    unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1457
    if (likely (index == NOT_COVERED)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1458
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1459
    const ClassDef &class_def = this+classDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1460
    index = class_def.get_class (c->buffer->cur().codepoint);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1461
    const RuleSet &rule_set = this+ruleSet[index];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1462
    struct ContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1463
      {match_class},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1464
      &class_def
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1465
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1466
    return_trace (rule_set.apply (c, lookup_context));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1467
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1468
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1469
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1470
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1471
    TRACE_SANITIZE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1472
    return_trace (coverage.sanitize (c, this) && classDef.sanitize (c, this) && ruleSet.sanitize (c, this));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1473
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1474
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1475
  protected:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1476
  HBUINT16      format;                 /* Format identifier--format = 2 */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1477
  OffsetTo<Coverage>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1478
                coverage;               /* Offset to Coverage table--from
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1479
                                         * beginning of table */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1480
  OffsetTo<ClassDef>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1481
                classDef;               /* Offset to glyph ClassDef table--from
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1482
                                         * beginning of table */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1483
  OffsetArrayOf<RuleSet>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1484
                ruleSet;                /* Array of RuleSet tables
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1485
                                         * ordered by class */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1486
  public:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1487
  DEFINE_SIZE_ARRAY (8, ruleSet);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1488
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1489
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1490
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1491
struct ContextFormat3
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1492
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1493
  inline void closure (hb_closure_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1494
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1495
    TRACE_CLOSURE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1496
    if (!(this+coverageZ[0]).intersects (c->glyphs))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1497
      return;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1498
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1499
    const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1500
    struct ContextClosureLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1501
      {intersects_coverage},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1502
      this
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1503
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1504
    context_closure_lookup (c,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1505
                            glyphCount, (const HBUINT16 *) (coverageZ + 1),
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1506
                            lookupCount, lookupRecord,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1507
                            lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1508
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1509
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1510
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1511
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1512
    TRACE_COLLECT_GLYPHS (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1513
    (this+coverageZ[0]).add_coverage (c->input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1514
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1515
    const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1516
    struct ContextCollectGlyphsLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1517
      {collect_coverage},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1518
      this
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1519
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1520
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1521
    context_collect_glyphs_lookup (c,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1522
                                   glyphCount, (const HBUINT16 *) (coverageZ + 1),
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1523
                                   lookupCount, lookupRecord,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1524
                                   lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1525
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1526
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1527
  inline bool would_apply (hb_would_apply_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1528
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1529
    TRACE_WOULD_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1530
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1531
    const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1532
    struct ContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1533
      {match_coverage},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1534
      this
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1535
    };
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1536
    return_trace (context_would_apply_lookup (c, glyphCount, (const HBUINT16 *) (coverageZ + 1), lookupCount, lookupRecord, lookup_context));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1537
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1538
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1539
  inline const Coverage &get_coverage (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1540
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1541
    return this+coverageZ[0];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1542
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1543
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1544
  inline bool apply (hb_ot_apply_context_t *c) const
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1545
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1546
    TRACE_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1547
    unsigned int index = (this+coverageZ[0]).get_coverage (c->buffer->cur().codepoint);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1548
    if (likely (index == NOT_COVERED)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1549
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1550
    const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * glyphCount);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1551
    struct ContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1552
      {match_coverage},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1553
      this
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1554
    };
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1555
    return_trace (context_apply_lookup (c, glyphCount, (const HBUINT16 *) (coverageZ + 1), lookupCount, lookupRecord, lookup_context));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1556
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1557
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1558
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1559
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1560
    TRACE_SANITIZE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1561
    if (!c->check_struct (this)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1562
    unsigned int count = glyphCount;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1563
    if (!count) return_trace (false); /* We want to access coverageZ[0] freely. */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1564
    if (!c->check_array (coverageZ, coverageZ[0].static_size, count)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1565
    for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1566
      if (!coverageZ[i].sanitize (c, this)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1567
    const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ, coverageZ[0].static_size * count);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1568
    return_trace (c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1569
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1570
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1571
  protected:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1572
  HBUINT16      format;                 /* Format identifier--format = 3 */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1573
  HBUINT16      glyphCount;             /* Number of glyphs in the input glyph
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1574
                                         * sequence */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1575
  HBUINT16      lookupCount;            /* Number of LookupRecords */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1576
  OffsetTo<Coverage>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1577
                coverageZ[VAR];         /* Array of offsets to Coverage
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1578
                                         * table in glyph sequence order */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1579
/*LookupRecord  lookupRecordX[VAR];*/   /* Array of LookupRecords--in
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1580
                                         * design order */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1581
  public:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1582
  DEFINE_SIZE_ARRAY (6, coverageZ);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1583
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1584
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1585
struct Context
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1586
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1587
  template <typename context_t>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1588
  inline typename context_t::return_t dispatch (context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1589
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1590
    TRACE_DISPATCH (this, u.format);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1591
    if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1592
    switch (u.format) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1593
    case 1: return_trace (c->dispatch (u.format1));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1594
    case 2: return_trace (c->dispatch (u.format2));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1595
    case 3: return_trace (c->dispatch (u.format3));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1596
    default:return_trace (c->default_return_value ());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1597
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1598
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1599
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1600
  protected:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1601
  union {
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1602
  HBUINT16              format;         /* Format identifier */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1603
  ContextFormat1        format1;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1604
  ContextFormat2        format2;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1605
  ContextFormat3        format3;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1606
  } u;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1607
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1608
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1609
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1610
/* Chaining Contextual lookups */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1611
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1612
struct ChainContextClosureLookupContext
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1613
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1614
  ContextClosureFuncs funcs;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1615
  const void *intersects_data[3];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1616
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1617
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1618
struct ChainContextCollectGlyphsLookupContext
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1619
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1620
  ContextCollectGlyphsFuncs funcs;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1621
  const void *collect_data[3];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1622
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1623
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1624
struct ChainContextApplyLookupContext
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1625
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1626
  ContextApplyFuncs funcs;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1627
  const void *match_data[3];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1628
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1629
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1630
static inline void chain_context_closure_lookup (hb_closure_context_t *c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1631
                                                 unsigned int backtrackCount,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1632
                                                 const HBUINT16 backtrack[],
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1633
                                                 unsigned int inputCount, /* Including the first glyph (not matched) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1634
                                                 const HBUINT16 input[], /* Array of input values--start with second glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1635
                                                 unsigned int lookaheadCount,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1636
                                                 const HBUINT16 lookahead[],
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1637
                                                 unsigned int lookupCount,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1638
                                                 const LookupRecord lookupRecord[],
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1639
                                                 ChainContextClosureLookupContext &lookup_context)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1640
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1641
  if (intersects_array (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1642
                        backtrackCount, backtrack,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1643
                        lookup_context.funcs.intersects, lookup_context.intersects_data[0])
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1644
   && intersects_array (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1645
                        inputCount ? inputCount - 1 : 0, input,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1646
                        lookup_context.funcs.intersects, lookup_context.intersects_data[1])
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1647
   && intersects_array (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1648
                       lookaheadCount, lookahead,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1649
                       lookup_context.funcs.intersects, lookup_context.intersects_data[2]))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1650
    recurse_lookups (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1651
                     lookupCount, lookupRecord);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1652
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1653
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1654
static inline void chain_context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1655
                                                        unsigned int backtrackCount,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1656
                                                        const HBUINT16 backtrack[],
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1657
                                                        unsigned int inputCount, /* Including the first glyph (not matched) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1658
                                                        const HBUINT16 input[], /* Array of input values--start with second glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1659
                                                        unsigned int lookaheadCount,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1660
                                                        const HBUINT16 lookahead[],
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1661
                                                        unsigned int lookupCount,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1662
                                                        const LookupRecord lookupRecord[],
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1663
                                                        ChainContextCollectGlyphsLookupContext &lookup_context)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1664
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1665
  collect_array (c, c->before,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1666
                 backtrackCount, backtrack,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1667
                 lookup_context.funcs.collect, lookup_context.collect_data[0]);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1668
  collect_array (c, c->input,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1669
                 inputCount ? inputCount - 1 : 0, input,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1670
                 lookup_context.funcs.collect, lookup_context.collect_data[1]);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1671
  collect_array (c, c->after,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1672
                 lookaheadCount, lookahead,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1673
                 lookup_context.funcs.collect, lookup_context.collect_data[2]);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1674
  recurse_lookups (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1675
                   lookupCount, lookupRecord);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1676
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1677
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1678
static inline bool chain_context_would_apply_lookup (hb_would_apply_context_t *c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1679
                                                     unsigned int backtrackCount,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1680
                                                     const HBUINT16 backtrack[] HB_UNUSED,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1681
                                                     unsigned int inputCount, /* Including the first glyph (not matched) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1682
                                                     const HBUINT16 input[], /* Array of input values--start with second glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1683
                                                     unsigned int lookaheadCount,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1684
                                                     const HBUINT16 lookahead[] HB_UNUSED,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1685
                                                     unsigned int lookupCount HB_UNUSED,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1686
                                                     const LookupRecord lookupRecord[] HB_UNUSED,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1687
                                                     ChainContextApplyLookupContext &lookup_context)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1688
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1689
  return (c->zero_context ? !backtrackCount && !lookaheadCount : true)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1690
      && would_match_input (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1691
                            inputCount, input,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1692
                            lookup_context.funcs.match, lookup_context.match_data[1]);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1693
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1694
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1695
static inline bool chain_context_apply_lookup (hb_ot_apply_context_t *c,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1696
                                               unsigned int backtrackCount,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1697
                                               const HBUINT16 backtrack[],
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1698
                                               unsigned int inputCount, /* Including the first glyph (not matched) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1699
                                               const HBUINT16 input[], /* Array of input values--start with second glyph */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1700
                                               unsigned int lookaheadCount,
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1701
                                               const HBUINT16 lookahead[],
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1702
                                               unsigned int lookupCount,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1703
                                               const LookupRecord lookupRecord[],
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1704
                                               ChainContextApplyLookupContext &lookup_context)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1705
{
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1706
  unsigned int start_index = 0, match_length = 0, end_index = 0;
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  1707
  unsigned int match_positions[HB_MAX_CONTEXT_LENGTH];
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1708
  return match_input (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1709
                      inputCount, input,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1710
                      lookup_context.funcs.match, lookup_context.match_data[1],
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1711
                      &match_length, match_positions)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1712
      && match_backtrack (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1713
                          backtrackCount, backtrack,
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1714
                          lookup_context.funcs.match, lookup_context.match_data[0],
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1715
                          &start_index)
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1716
      && match_lookahead (c,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1717
                          lookaheadCount, lookahead,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1718
                          lookup_context.funcs.match, lookup_context.match_data[2],
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1719
                          match_length, &end_index)
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1720
      && (c->buffer->unsafe_to_break_from_outbuffer (start_index, end_index),
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1721
          apply_lookup (c,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1722
                       inputCount, match_positions,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1723
                       lookupCount, lookupRecord,
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1724
                       match_length));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1725
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1726
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1727
struct ChainRule
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1728
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1729
  inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1730
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1731
    TRACE_CLOSURE (this);
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1732
    const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16> > (backtrack);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1733
    const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16> > (input);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1734
    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1735
    chain_context_closure_lookup (c,
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1736
                                  backtrack.len, backtrack.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1737
                                  input.len, input.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1738
                                  lookahead.len, lookahead.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1739
                                  lookup.len, lookup.arrayZ,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1740
                                  lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1741
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1742
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1743
  inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1744
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1745
    TRACE_COLLECT_GLYPHS (this);
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1746
    const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16> > (backtrack);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1747
    const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16> > (input);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1748
    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1749
    chain_context_collect_glyphs_lookup (c,
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1750
                                         backtrack.len, backtrack.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1751
                                         input.len, input.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1752
                                         lookahead.len, lookahead.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1753
                                         lookup.len, lookup.arrayZ,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1754
                                         lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1755
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1756
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1757
  inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1758
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1759
    TRACE_WOULD_APPLY (this);
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1760
    const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16> > (backtrack);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1761
    const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16> > (input);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1762
    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1763
    return_trace (chain_context_would_apply_lookup (c,
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1764
                                                    backtrack.len, backtrack.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1765
                                                    input.len, input.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1766
                                                    lookahead.len, lookahead.arrayZ, lookup.len,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1767
                                                    lookup.arrayZ, lookup_context));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1768
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1769
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1770
  inline bool apply (hb_ot_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1771
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1772
    TRACE_APPLY (this);
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1773
    const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16> > (backtrack);
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1774
    const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16> > (input);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1775
    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1776
    return_trace (chain_context_apply_lookup (c,
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1777
                                              backtrack.len, backtrack.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1778
                                              input.len, input.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1779
                                              lookahead.len, lookahead.arrayZ, lookup.len,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  1780
                                              lookup.arrayZ, lookup_context));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1781
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1782
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1783
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1784
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1785
    TRACE_SANITIZE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1786
    if (!backtrack.sanitize (c)) return_trace (false);
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1787
    const HeadlessArrayOf<HBUINT16> &input = StructAfter<HeadlessArrayOf<HBUINT16> > (backtrack);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1788
    if (!input.sanitize (c)) return_trace (false);
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1789
    const ArrayOf<HBUINT16> &lookahead = StructAfter<ArrayOf<HBUINT16> > (input);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1790
    if (!lookahead.sanitize (c)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1791
    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1792
    return_trace (lookup.sanitize (c));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1793
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1794
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1795
  protected:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1796
  ArrayOf<HBUINT16>
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1797
                backtrack;              /* Array of backtracking values
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1798
                                         * (to be matched before the input
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1799
                                         * sequence) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1800
  HeadlessArrayOf<HBUINT16>
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1801
                inputX;                 /* Array of input values (start with
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1802
                                         * second glyph) */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1803
  ArrayOf<HBUINT16>
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1804
                lookaheadX;             /* Array of lookahead values's (to be
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1805
                                         * matched after the input sequence) */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1806
  ArrayOf<LookupRecord>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1807
                lookupX;                /* Array of LookupRecords--in
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1808
                                         * design order) */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1809
  public:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1810
  DEFINE_SIZE_MIN (8);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1811
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1812
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1813
struct ChainRuleSet
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1814
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1815
  inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1816
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1817
    TRACE_CLOSURE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1818
    unsigned int num_rules = rule.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1819
    for (unsigned int i = 0; i < num_rules; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1820
      (this+rule[i]).closure (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1821
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1822
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1823
  inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1824
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1825
    TRACE_COLLECT_GLYPHS (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1826
    unsigned int num_rules = rule.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1827
    for (unsigned int i = 0; i < num_rules; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1828
      (this+rule[i]).collect_glyphs (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1829
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1830
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1831
  inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1832
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1833
    TRACE_WOULD_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1834
    unsigned int num_rules = rule.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1835
    for (unsigned int i = 0; i < num_rules; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1836
      if ((this+rule[i]).would_apply (c, lookup_context))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1837
        return_trace (true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1838
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1839
    return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1840
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1841
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1842
  inline bool apply (hb_ot_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1843
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1844
    TRACE_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1845
    unsigned int num_rules = rule.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1846
    for (unsigned int i = 0; i < num_rules; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1847
      if ((this+rule[i]).apply (c, lookup_context))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1848
        return_trace (true);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1849
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1850
    return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1851
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1852
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1853
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1854
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1855
    TRACE_SANITIZE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1856
    return_trace (rule.sanitize (c, this));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1857
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1858
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1859
  protected:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1860
  OffsetArrayOf<ChainRule>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1861
                rule;                   /* Array of ChainRule tables
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1862
                                         * ordered by preference */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1863
  public:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1864
  DEFINE_SIZE_ARRAY (2, rule);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1865
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1866
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1867
struct ChainContextFormat1
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1868
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1869
  inline void closure (hb_closure_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1870
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1871
    TRACE_CLOSURE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1872
    const Coverage &cov = (this+coverage);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1873
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1874
    struct ChainContextClosureLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1875
      {intersects_glyph},
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1876
      {nullptr, nullptr, nullptr}
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1877
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1878
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1879
    unsigned int count = ruleSet.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1880
    for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1881
      if (cov.intersects_coverage (c->glyphs, i)) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1882
        const ChainRuleSet &rule_set = this+ruleSet[i];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1883
        rule_set.closure (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1884
      }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1885
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1886
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1887
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1888
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1889
    TRACE_COLLECT_GLYPHS (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1890
    (this+coverage).add_coverage (c->input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1891
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1892
    struct ChainContextCollectGlyphsLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1893
      {collect_glyph},
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1894
      {nullptr, nullptr, nullptr}
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1895
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1896
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1897
    unsigned int count = ruleSet.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1898
    for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1899
      (this+ruleSet[i]).collect_glyphs (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1900
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1901
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1902
  inline bool would_apply (hb_would_apply_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1903
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1904
    TRACE_WOULD_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1905
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1906
    const ChainRuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1907
    struct ChainContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1908
      {match_glyph},
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1909
      {nullptr, nullptr, nullptr}
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1910
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1911
    return_trace (rule_set.would_apply (c, lookup_context));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1912
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1913
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1914
  inline const Coverage &get_coverage (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1915
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1916
    return this+coverage;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1917
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1918
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1919
  inline bool apply (hb_ot_apply_context_t *c) const
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1920
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1921
    TRACE_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1922
    unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1923
    if (likely (index == NOT_COVERED)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1924
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1925
    const ChainRuleSet &rule_set = this+ruleSet[index];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1926
    struct ChainContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1927
      {match_glyph},
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  1928
      {nullptr, nullptr, nullptr}
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1929
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1930
    return_trace (rule_set.apply (c, lookup_context));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1931
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1932
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1933
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1934
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1935
    TRACE_SANITIZE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1936
    return_trace (coverage.sanitize (c, this) && ruleSet.sanitize (c, this));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1937
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1938
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1939
  protected:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  1940
  HBUINT16      format;                 /* Format identifier--format = 1 */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1941
  OffsetTo<Coverage>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1942
                coverage;               /* Offset to Coverage table--from
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1943
                                         * beginning of table */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1944
  OffsetArrayOf<ChainRuleSet>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1945
                ruleSet;                /* Array of ChainRuleSet tables
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1946
                                         * ordered by Coverage Index */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1947
  public:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1948
  DEFINE_SIZE_ARRAY (6, ruleSet);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1949
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1950
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1951
struct ChainContextFormat2
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1952
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1953
  inline void closure (hb_closure_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1954
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1955
    TRACE_CLOSURE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1956
    if (!(this+coverage).intersects (c->glyphs))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1957
      return;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1958
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1959
    const ClassDef &backtrack_class_def = this+backtrackClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1960
    const ClassDef &input_class_def = this+inputClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1961
    const ClassDef &lookahead_class_def = this+lookaheadClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1962
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1963
    struct ChainContextClosureLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1964
      {intersects_class},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1965
      {&backtrack_class_def,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1966
       &input_class_def,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1967
       &lookahead_class_def}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1968
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1969
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1970
    unsigned int count = ruleSet.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1971
    for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1972
      if (input_class_def.intersects_class (c->glyphs, i)) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1973
        const ChainRuleSet &rule_set = this+ruleSet[i];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1974
        rule_set.closure (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1975
      }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1976
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1977
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1978
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1979
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1980
    TRACE_COLLECT_GLYPHS (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1981
    (this+coverage).add_coverage (c->input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1982
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1983
    const ClassDef &backtrack_class_def = this+backtrackClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1984
    const ClassDef &input_class_def = this+inputClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1985
    const ClassDef &lookahead_class_def = this+lookaheadClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1986
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1987
    struct ChainContextCollectGlyphsLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1988
      {collect_class},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1989
      {&backtrack_class_def,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1990
       &input_class_def,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1991
       &lookahead_class_def}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1992
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1993
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1994
    unsigned int count = ruleSet.len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1995
    for (unsigned int i = 0; i < count; i++)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1996
      (this+ruleSet[i]).collect_glyphs (c, lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1997
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1998
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  1999
  inline bool would_apply (hb_would_apply_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2000
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2001
    TRACE_WOULD_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2002
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2003
    const ClassDef &backtrack_class_def = this+backtrackClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2004
    const ClassDef &input_class_def = this+inputClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2005
    const ClassDef &lookahead_class_def = this+lookaheadClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2006
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2007
    unsigned int index = input_class_def.get_class (c->glyphs[0]);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2008
    const ChainRuleSet &rule_set = this+ruleSet[index];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2009
    struct ChainContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2010
      {match_class},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2011
      {&backtrack_class_def,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2012
       &input_class_def,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2013
       &lookahead_class_def}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2014
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2015
    return_trace (rule_set.would_apply (c, lookup_context));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2016
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2017
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2018
  inline const Coverage &get_coverage (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2019
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2020
    return this+coverage;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2021
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2022
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2023
  inline bool apply (hb_ot_apply_context_t *c) const
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2024
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2025
    TRACE_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2026
    unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2027
    if (likely (index == NOT_COVERED)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2028
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2029
    const ClassDef &backtrack_class_def = this+backtrackClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2030
    const ClassDef &input_class_def = this+inputClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2031
    const ClassDef &lookahead_class_def = this+lookaheadClassDef;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2032
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2033
    index = input_class_def.get_class (c->buffer->cur().codepoint);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2034
    const ChainRuleSet &rule_set = this+ruleSet[index];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2035
    struct ChainContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2036
      {match_class},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2037
      {&backtrack_class_def,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2038
       &input_class_def,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2039
       &lookahead_class_def}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2040
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2041
    return_trace (rule_set.apply (c, lookup_context));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2042
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2043
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2044
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2045
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2046
    TRACE_SANITIZE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2047
    return_trace (coverage.sanitize (c, this) &&
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2048
                  backtrackClassDef.sanitize (c, this) &&
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2049
                  inputClassDef.sanitize (c, this) &&
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2050
                  lookaheadClassDef.sanitize (c, this) &&
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2051
                  ruleSet.sanitize (c, this));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2052
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2053
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2054
  protected:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2055
  HBUINT16      format;                 /* Format identifier--format = 2 */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2056
  OffsetTo<Coverage>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2057
                coverage;               /* Offset to Coverage table--from
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2058
                                         * beginning of table */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2059
  OffsetTo<ClassDef>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2060
                backtrackClassDef;      /* Offset to glyph ClassDef table
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2061
                                         * containing backtrack sequence
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2062
                                         * data--from beginning of table */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2063
  OffsetTo<ClassDef>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2064
                inputClassDef;          /* Offset to glyph ClassDef
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2065
                                         * table containing input sequence
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2066
                                         * data--from beginning of table */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2067
  OffsetTo<ClassDef>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2068
                lookaheadClassDef;      /* Offset to glyph ClassDef table
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2069
                                         * containing lookahead sequence
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2070
                                         * data--from beginning of table */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2071
  OffsetArrayOf<ChainRuleSet>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2072
                ruleSet;                /* Array of ChainRuleSet tables
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2073
                                         * ordered by class */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2074
  public:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2075
  DEFINE_SIZE_ARRAY (12, ruleSet);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2076
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2077
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2078
struct ChainContextFormat3
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2079
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2080
  inline void closure (hb_closure_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2081
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2082
    TRACE_CLOSURE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2083
    const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2084
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2085
    if (!(this+input[0]).intersects (c->glyphs))
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2086
      return;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2087
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2088
    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2089
    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2090
    struct ChainContextClosureLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2091
      {intersects_coverage},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2092
      {this, this, this}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2093
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2094
    chain_context_closure_lookup (c,
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2095
                                  backtrack.len, (const HBUINT16 *) backtrack.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2096
                                  input.len, (const HBUINT16 *) input.arrayZ + 1,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2097
                                  lookahead.len, (const HBUINT16 *) lookahead.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2098
                                  lookup.len, lookup.arrayZ,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2099
                                  lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2100
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2101
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2102
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2103
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2104
    TRACE_COLLECT_GLYPHS (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2105
    const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2106
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2107
    (this+input[0]).add_coverage (c->input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2108
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2109
    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2110
    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2111
    struct ChainContextCollectGlyphsLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2112
      {collect_coverage},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2113
      {this, this, this}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2114
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2115
    chain_context_collect_glyphs_lookup (c,
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2116
                                         backtrack.len, (const HBUINT16 *) backtrack.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2117
                                         input.len, (const HBUINT16 *) input.arrayZ + 1,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2118
                                         lookahead.len, (const HBUINT16 *) lookahead.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2119
                                         lookup.len, lookup.arrayZ,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2120
                                         lookup_context);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2121
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2122
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2123
  inline bool would_apply (hb_would_apply_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2124
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2125
    TRACE_WOULD_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2126
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2127
    const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2128
    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2129
    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2130
    struct ChainContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2131
      {match_coverage},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2132
      {this, this, this}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2133
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2134
    return_trace (chain_context_would_apply_lookup (c,
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2135
                                                    backtrack.len, (const HBUINT16 *) backtrack.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2136
                                                    input.len, (const HBUINT16 *) input.arrayZ + 1,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2137
                                                    lookahead.len, (const HBUINT16 *) lookahead.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2138
                                                    lookup.len, lookup.arrayZ, lookup_context));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2139
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2140
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2141
  inline const Coverage &get_coverage (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2142
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2143
    const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2144
    return this+input[0];
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2145
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2146
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2147
  inline bool apply (hb_ot_apply_context_t *c) const
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2148
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2149
    TRACE_APPLY (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2150
    const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2151
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2152
    unsigned int index = (this+input[0]).get_coverage (c->buffer->cur().codepoint);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2153
    if (likely (index == NOT_COVERED)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2154
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2155
    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2156
    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2157
    struct ChainContextApplyLookupContext lookup_context = {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2158
      {match_coverage},
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2159
      {this, this, this}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2160
    };
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2161
    return_trace (chain_context_apply_lookup (c,
50826
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2162
                                              backtrack.len, (const HBUINT16 *) backtrack.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2163
                                              input.len, (const HBUINT16 *) input.arrayZ + 1,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2164
                                              lookahead.len, (const HBUINT16 *) lookahead.arrayZ,
f5b95be8b6e2 8205441: Upgrade to harfbuzz 1.8.1
prr
parents: 50352
diff changeset
  2165
                                              lookup.len, lookup.arrayZ, lookup_context));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2166
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2167
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2168
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2169
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2170
    TRACE_SANITIZE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2171
    if (!backtrack.sanitize (c, this)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2172
    const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2173
    if (!input.sanitize (c, this)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2174
    if (!input.len) return_trace (false); /* To be consistent with Context. */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2175
    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2176
    if (!lookahead.sanitize (c, this)) return_trace (false);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2177
    const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2178
    return_trace (lookup.sanitize (c));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2179
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2180
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2181
  protected:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2182
  HBUINT16      format;                 /* Format identifier--format = 3 */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2183
  OffsetArrayOf<Coverage>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2184
                backtrack;              /* Array of coverage tables
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2185
                                         * in backtracking sequence, in  glyph
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2186
                                         * sequence order */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2187
  OffsetArrayOf<Coverage>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2188
                inputX          ;       /* Array of coverage
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2189
                                         * tables in input sequence, in glyph
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2190
                                         * sequence order */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2191
  OffsetArrayOf<Coverage>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2192
                lookaheadX;             /* Array of coverage tables
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2193
                                         * in lookahead sequence, in glyph
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2194
                                         * sequence order */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2195
  ArrayOf<LookupRecord>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2196
                lookupX;                /* Array of LookupRecords--in
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2197
                                         * design order) */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2198
  public:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2199
  DEFINE_SIZE_MIN (10);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2200
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2201
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2202
struct ChainContext
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2203
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2204
  template <typename context_t>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2205
  inline typename context_t::return_t dispatch (context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2206
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2207
    TRACE_DISPATCH (this, u.format);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2208
    if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2209
    switch (u.format) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2210
    case 1: return_trace (c->dispatch (u.format1));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2211
    case 2: return_trace (c->dispatch (u.format2));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2212
    case 3: return_trace (c->dispatch (u.format3));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2213
    default:return_trace (c->default_return_value ());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2214
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2215
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2216
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2217
  protected:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2218
  union {
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2219
  HBUINT16              format; /* Format identifier */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2220
  ChainContextFormat1   format1;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2221
  ChainContextFormat2   format2;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2222
  ChainContextFormat3   format3;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2223
  } u;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2224
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2225
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2226
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2227
template <typename T>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2228
struct ExtensionFormat1
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2229
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2230
  inline unsigned int get_type (void) const { return extensionLookupType; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2231
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2232
  template <typename X>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2233
  inline const X& get_subtable (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2234
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2235
    unsigned int offset = extensionOffset;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2236
    if (unlikely (!offset)) return Null(typename T::LookupSubTable);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2237
    return StructAtOffset<typename T::LookupSubTable> (this, offset);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2238
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2239
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2240
  template <typename context_t>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2241
  inline typename context_t::return_t dispatch (context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2242
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2243
    TRACE_DISPATCH (this, format);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2244
    if (unlikely (!c->may_dispatch (this, this))) return_trace (c->no_dispatch_return_value ());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2245
    return_trace (get_subtable<typename T::LookupSubTable> ().dispatch (c, get_type ()));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2246
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2247
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2248
  /* This is called from may_dispatch() above with hb_sanitize_context_t. */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2249
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2250
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2251
    TRACE_SANITIZE (this);
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2252
    return_trace (c->check_struct (this) &&
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2253
                  extensionOffset != 0 &&
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2254
                  extensionLookupType != T::LookupSubTable::Extension);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2255
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2256
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2257
  protected:
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2258
  HBUINT16      format;                 /* Format identifier. Set to 1. */
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2259
  HBUINT16      extensionLookupType;    /* Lookup type of subtable referenced
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2260
                                         * by ExtensionOffset (i.e. the
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2261
                                         * extension subtable). */
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2262
  HBUINT32      extensionOffset;        /* Offset to the extension subtable,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2263
                                         * of lookup type subtable. */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2264
  public:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2265
  DEFINE_SIZE_STATIC (8);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2266
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2267
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2268
template <typename T>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2269
struct Extension
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2270
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2271
  inline unsigned int get_type (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2272
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2273
    switch (u.format) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2274
    case 1: return u.format1.get_type ();
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2275
    default:return 0;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2276
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2277
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2278
  template <typename X>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2279
  inline const X& get_subtable (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2280
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2281
    switch (u.format) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2282
    case 1: return u.format1.template get_subtable<typename T::LookupSubTable> ();
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2283
    default:return Null(typename T::LookupSubTable);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2284
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2285
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2286
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2287
  template <typename context_t>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2288
  inline typename context_t::return_t dispatch (context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2289
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2290
    TRACE_DISPATCH (this, u.format);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2291
    if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2292
    switch (u.format) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2293
    case 1: return_trace (u.format1.dispatch (c));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2294
    default:return_trace (c->default_return_value ());
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2295
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2296
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2297
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2298
  protected:
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2299
  union {
50352
25db2c8f3cf8 8199530: Upgrade to harfbuzz 1.7.6
prr
parents: 48274
diff changeset
  2300
  HBUINT16              format;         /* Format identifier */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2301
  ExtensionFormat1<T>   format1;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2302
  } u;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2303
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2304
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2305
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2306
/*
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2307
 * GSUB/GPOS Common
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2308
 */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2309
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2310
struct GSUBGPOS
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2311
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2312
  inline unsigned int get_script_count (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2313
  { return (this+scriptList).len; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2314
  inline const Tag& get_script_tag (unsigned int i) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2315
  { return (this+scriptList).get_tag (i); }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2316
  inline unsigned int get_script_tags (unsigned int start_offset,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2317
                                       unsigned int *script_count /* IN/OUT */,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2318
                                       hb_tag_t     *script_tags /* OUT */) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2319
  { return (this+scriptList).get_tags (start_offset, script_count, script_tags); }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2320
  inline const Script& get_script (unsigned int i) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2321
  { return (this+scriptList)[i]; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2322
  inline bool find_script_index (hb_tag_t tag, unsigned int *index) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2323
  { return (this+scriptList).find_index (tag, index); }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2324
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2325
  inline unsigned int get_feature_count (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2326
  { return (this+featureList).len; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2327
  inline hb_tag_t get_feature_tag (unsigned int i) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2328
  { return i == Index::NOT_FOUND_INDEX ? HB_TAG_NONE : (this+featureList).get_tag (i); }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2329
  inline unsigned int get_feature_tags (unsigned int start_offset,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2330
                                        unsigned int *feature_count /* IN/OUT */,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2331
                                        hb_tag_t     *feature_tags /* OUT */) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2332
  { return (this+featureList).get_tags (start_offset, feature_count, feature_tags); }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2333
  inline const Feature& get_feature (unsigned int i) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2334
  { return (this+featureList)[i]; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2335
  inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2336
  { return (this+featureList).find_index (tag, index); }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2337
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2338
  inline unsigned int get_lookup_count (void) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2339
  { return (this+lookupList).len; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2340
  inline const Lookup& get_lookup (unsigned int i) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2341
  { return (this+lookupList)[i]; }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2342
43232
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2343
  inline bool find_variations_index (const int *coords, unsigned int num_coords,
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2344
                                     unsigned int *index) const
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2345
  { return (version.to_int () >= 0x00010001u ? this+featureVars : Null(FeatureVariations))
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2346
           .find_index (coords, num_coords, index); }
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2347
  inline const Feature& get_feature_variation (unsigned int feature_index,
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2348
                                               unsigned int variations_index) const
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2349
  {
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2350
    if (FeatureVariations::NOT_FOUND_INDEX != variations_index &&
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2351
        version.to_int () >= 0x00010001u)
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2352
    {
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2353
      const Feature *feature = (this+featureVars).find_substitute (variations_index,
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2354
                                                                   feature_index);
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2355
      if (feature)
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2356
        return *feature;
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2357
    }
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2358
    return get_feature (feature_index);
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2359
  }
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2360
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2361
  inline bool sanitize (hb_sanitize_context_t *c) const
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2362
  {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2363
    TRACE_SANITIZE (this);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2364
    return_trace (version.sanitize (c) &&
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2365
                  likely (version.major == 1) &&
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2366
                  scriptList.sanitize (c, this) &&
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2367
                  featureList.sanitize (c, this) &&
43232
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2368
                  lookupList.sanitize (c, this) &&
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2369
                  (version.to_int () < 0x00010001u || featureVars.sanitize (c, this)));
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2370
  }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2371
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2372
  protected:
40435
553eb1a50733 8163238: Upgrade to harfbuzz 1.3.0 in JDK 9
prr
parents: 34414
diff changeset
  2373
  FixedVersion<>version;        /* Version of the GSUB/GPOS table--initially set
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2374
                                 * to 0x00010000u */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2375
  OffsetTo<ScriptList>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2376
                scriptList;     /* ScriptList table */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2377
  OffsetTo<FeatureList>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2378
                featureList;    /* FeatureList table */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2379
  OffsetTo<LookupList>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2380
                lookupList;     /* LookupList table */
48274
51772bf1fb0c 8188836: Upgrade to Harfbuzz 1.7.1 in JDK 10
prr
parents: 47216
diff changeset
  2381
  LOffsetTo<FeatureVariations>
43232
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2382
                featureVars;    /* Offset to Feature Variations
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2383
                                   table--from beginning of table
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2384
                                 * (may be NULL).  Introduced
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2385
                                 * in version 0x00010001. */
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2386
  public:
43232
8e39ad39979f 8171456: Upgrade harfbuzz in JDK 9 to v1.4.1
prr
parents: 40435
diff changeset
  2387
  DEFINE_SIZE_MIN (10);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2388
};
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2389
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2390
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2391
} /* namespace OT */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2392
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2393
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
  2394
#endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */