blob: e17a2824168f5b7fd717038458c8fb967495d6ad [file] [log] [blame]
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 2007,2008,2009,2010 Red Hat, Inc.
Behdad Esfahbod2e0c44f2013-04-24 16:42:05 -04003 * Copyright © 2010,2012,2013 Google, Inc.
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04004 *
Behdad Esfahbodc755cb32010-04-22 00:11:43 -04005 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04006 *
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
12 *
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 *
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 *
25 * Red Hat Author(s): Behdad Esfahbod
Behdad Esfahbod98370e82010-10-27 17:39:01 -040026 * Google Author(s): Behdad Esfahbod
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040027 */
28
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +020029#ifndef HB_OT_LAYOUT_GPOS_TABLE_HH
30#define HB_OT_LAYOUT_GPOS_TABLE_HH
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040031
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070032#include "hb-ot-layout-gsubgpos.hh"
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040033
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040034
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -040035namespace OT {
36
Behdad Esfahbod94a23aa2010-05-05 01:13:09 -040037
Behdad Esfahbodb65c0602011-07-28 16:48:43 -040038/* buffer **position** var allocations */
Behdad Esfahbod686567b2016-02-11 15:25:28 +070039#define attach_chain() var.i16[0] /* glyph to which this attaches to, relative to current glyphs; negative for going back, positive for forward. */
40#define attach_type() var.u8[2] /* attachment type */
41/* Note! if attach_chain() is zero, the value of attach_type() is irrelevant. */
42
43enum attach_type_t {
44 ATTACH_TYPE_NONE = 0X00,
45
46 /* Each attachment should be either a mark or a cursive; can't be both. */
47 ATTACH_TYPE_MARK = 0X01,
48 ATTACH_TYPE_CURSIVE = 0X02,
49};
Behdad Esfahbod194d4562010-10-27 23:09:10 -040050
51
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040052/* Shared Tables: ValueRecord, Anchor Table, and MarkArray */
53
Behdad Esfahbod6b191782018-01-10 03:07:30 +010054typedef HBUINT16 Value;
Behdad Esfahbodc91facd2009-08-26 18:53:43 -040055
Behdad Esfahbod1d66cdc2018-11-10 19:54:08 -050056typedef UnsizedArrayOf<Value> ValueRecord;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040057
Behdad Esfahbod6b191782018-01-10 03:07:30 +010058struct ValueFormat : HBUINT16
Behdad Esfahbodfca6a0d2009-05-21 04:49:04 -040059{
Behdad Esfahbodc6035cf2012-04-12 13:23:59 -040060 enum Flags {
Behdad Esfahbod76271002014-07-11 14:54:42 -040061 xPlacement = 0x0001u, /* Includes horizontal adjustment for placement */
62 yPlacement = 0x0002u, /* Includes vertical adjustment for placement */
63 xAdvance = 0x0004u, /* Includes horizontal adjustment for advance */
64 yAdvance = 0x0008u, /* Includes vertical adjustment for advance */
65 xPlaDevice = 0x0010u, /* Includes horizontal Device table for placement */
66 yPlaDevice = 0x0020u, /* Includes vertical Device table for placement */
67 xAdvDevice = 0x0040u, /* Includes horizontal Device table for advance */
68 yAdvDevice = 0x0080u, /* Includes vertical Device table for advance */
69 ignored = 0x0F00u, /* Was used in TrueType Open for MM fonts */
70 reserved = 0xF000u, /* For future use */
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -040071
Behdad Esfahbod76271002014-07-11 14:54:42 -040072 devices = 0x00F0u /* Mask for having any Device table */
Behdad Esfahbodfca6a0d2009-05-21 04:49:04 -040073 };
74
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -040075/* All fields are options. Only those available advance the value pointer. */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040076#if 0
Behdad Esfahbod6b191782018-01-10 03:07:30 +010077 HBINT16 xPlacement; /* Horizontal adjustment for
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040078 * placement--in design units */
Behdad Esfahbod6b191782018-01-10 03:07:30 +010079 HBINT16 yPlacement; /* Vertical adjustment for
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040080 * placement--in design units */
Behdad Esfahbod6b191782018-01-10 03:07:30 +010081 HBINT16 xAdvance; /* Horizontal adjustment for
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040082 * advance--in design units (only used
83 * for horizontal writing) */
Behdad Esfahbod6b191782018-01-10 03:07:30 +010084 HBINT16 yAdvance; /* Vertical adjustment for advance--in
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040085 * design units (only used for vertical
86 * writing) */
Behdad Esfahbodf39b5602019-01-17 17:49:55 -050087 OffsetTo<Device> xPlaDevice; /* Offset to Device table for
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040088 * horizontal placement--measured from
89 * beginning of PosTable (may be NULL) */
Behdad Esfahbodf39b5602019-01-17 17:49:55 -050090 OffsetTo<Device> yPlaDevice; /* Offset to Device table for vertical
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040091 * placement--measured from beginning
92 * of PosTable (may be NULL) */
Behdad Esfahbodf39b5602019-01-17 17:49:55 -050093 OffsetTo<Device> xAdvDevice; /* Offset to Device table for
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040094 * horizontal advance--measured from
95 * beginning of PosTable (may be NULL) */
Behdad Esfahbodf39b5602019-01-17 17:49:55 -050096 OffsetTo<Device> yAdvDevice; /* Offset to Device table for vertical
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040097 * advance--measured from beginning of
98 * PosTable (may be NULL) */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040099#endif
100
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330101 unsigned int get_len () const { return hb_popcount ((unsigned int) *this); }
102 unsigned int get_size () const { return get_len () * Value::static_size; }
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400103
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500104 bool apply_value (hb_ot_apply_context_t *c,
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400105 const void *base,
106 const Value *values,
107 hb_glyph_position_t &glyph_pos) const
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400108 {
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500109 bool ret = false;
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400110 unsigned int format = *this;
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500111 if (!format) return ret;
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400112
Behdad Esfahbod151d93d2016-09-09 17:03:11 -0700113 hb_font_t *font = c->font;
Behdad Esfahbod385f78b2018-11-07 17:19:21 -0500114 bool horizontal = HB_DIRECTION_IS_HORIZONTAL (c->direction);
Behdad Esfahbod151d93d2016-09-09 17:03:11 -0700115
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500116 if (format & xPlacement) glyph_pos.x_offset += font->em_scale_x (get_short (values++, &ret));
117 if (format & yPlacement) glyph_pos.y_offset += font->em_scale_y (get_short (values++, &ret));
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400118 if (format & xAdvance) {
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500119 if (likely (horizontal)) glyph_pos.x_advance += font->em_scale_x (get_short (values, &ret));
Konstantin Ritt08322592014-01-22 20:31:30 +0200120 values++;
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400121 }
Behdad Esfahbodcc2086d2011-05-19 19:19:50 -0400122 /* y_advance values grow downward but font-space grows upward, hence negation */
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400123 if (format & yAdvance) {
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500124 if (unlikely (!horizontal)) glyph_pos.y_advance -= font->em_scale_y (get_short (values, &ret));
Konstantin Ritt08322592014-01-22 20:31:30 +0200125 values++;
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400126 }
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400127
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500128 if (!has_device ()) return ret;
Behdad Esfahboda8d960b2010-04-29 14:31:56 -0400129
Behdad Esfahbodca286702016-03-01 19:29:36 +0900130 bool use_x_device = font->x_ppem || font->num_coords;
131 bool use_y_device = font->y_ppem || font->num_coords;
Behdad Esfahboda8d960b2010-04-29 14:31:56 -0400132
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500133 if (!use_x_device && !use_y_device) return ret;
Behdad Esfahboda8d960b2010-04-29 14:31:56 -0400134
Behdad Esfahbodcf3de4d2016-09-10 00:22:24 -0700135 const VariationStore &store = c->var_store;
Behdad Esfahbod151d93d2016-09-09 17:03:11 -0700136
Behdad Esfahbod0090dc02009-07-30 16:28:45 -0400137 /* pixel -> fractional pixel */
138 if (format & xPlaDevice) {
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500139 if (use_x_device) glyph_pos.x_offset += (base + get_device (values, &ret)).get_x_delta (font, store);
Konstantin Ritt08322592014-01-22 20:31:30 +0200140 values++;
Behdad Esfahbod0090dc02009-07-30 16:28:45 -0400141 }
142 if (format & yPlaDevice) {
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500143 if (use_y_device) glyph_pos.y_offset += (base + get_device (values, &ret)).get_y_delta (font, store);
Konstantin Ritt08322592014-01-22 20:31:30 +0200144 values++;
Behdad Esfahbod0090dc02009-07-30 16:28:45 -0400145 }
146 if (format & xAdvDevice) {
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500147 if (horizontal && use_x_device) glyph_pos.x_advance += (base + get_device (values, &ret)).get_x_delta (font, store);
Konstantin Ritt08322592014-01-22 20:31:30 +0200148 values++;
Behdad Esfahbod0090dc02009-07-30 16:28:45 -0400149 }
150 if (format & yAdvDevice) {
Behdad Esfahbodcc2086d2011-05-19 19:19:50 -0400151 /* y_advance values grow downward but font-space grows upward, hence negation */
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500152 if (!horizontal && use_y_device) glyph_pos.y_advance -= (base + get_device (values, &ret)).get_y_delta (font, store);
Konstantin Ritt08322592014-01-22 20:31:30 +0200153 values++;
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400154 }
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500155 return ret;
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400156 }
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400157
158 private:
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330159 bool sanitize_value_devices (hb_sanitize_context_t *c, const void *base, const Value *values) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300160 {
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400161 unsigned int format = *this;
162
163 if (format & xPlacement) values++;
164 if (format & yPlacement) values++;
165 if (format & xAdvance) values++;
166 if (format & yAdvance) values++;
167
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400168 if ((format & xPlaDevice) && !get_device (values++).sanitize (c, base)) return false;
169 if ((format & yPlaDevice) && !get_device (values++).sanitize (c, base)) return false;
170 if ((format & xAdvDevice) && !get_device (values++).sanitize (c, base)) return false;
171 if ((format & yAdvDevice) && !get_device (values++).sanitize (c, base)) return false;
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400172
173 return true;
174 }
175
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330176 static OffsetTo<Device>& get_device (Value* value)
Behdad Esfahbodc2ddfd22010-05-06 13:06:15 -0400177 { return *CastP<OffsetTo<Device> > (value); }
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330178 static const OffsetTo<Device>& get_device (const Value* value, bool *worked=nullptr)
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500179 {
Behdad Esfahbodb9a51f52018-12-21 15:05:00 -0500180 if (worked) *worked |= bool (*value);
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500181 return *CastP<OffsetTo<Device> > (value);
182 }
Behdad Esfahbodc2ddfd22010-05-06 13:06:15 -0400183
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330184 static const HBINT16& get_short (const Value* value, bool *worked=nullptr)
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500185 {
Behdad Esfahbodb9a51f52018-12-21 15:05:00 -0500186 if (worked) *worked |= bool (*value);
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500187 return *CastP<HBINT16> (value);
188 }
Behdad Esfahbodc2ddfd22010-05-06 13:06:15 -0400189
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400190 public:
191
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330192 bool has_device () const
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330193 {
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400194 unsigned int format = *this;
195 return (format & devices) != 0;
196 }
197
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330198 bool sanitize_value (hb_sanitize_context_t *c, const void *base, const Value *values) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300199 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500200 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100201 return_trace (c->check_range (values, get_size ()) && (!has_device () || sanitize_value_devices (c, base, values)));
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400202 }
203
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330204 bool sanitize_values (hb_sanitize_context_t *c, const void *base, const Value *values, unsigned int count) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300205 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500206 TRACE_SANITIZE (this);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400207 unsigned int len = get_len ();
208
Behdad Esfahbode0144052018-11-12 14:23:31 -0500209 if (!c->check_range (values, count, get_size ())) return_trace (false);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400210
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100211 if (!has_device ()) return_trace (true);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400212
213 for (unsigned int i = 0; i < count; i++) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400214 if (!sanitize_value_devices (c, base, values))
Ebrahim Byagowi11aa0462018-11-15 23:10:56 +0330215 return_trace (false);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400216 values += len;
217 }
218
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100219 return_trace (true);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400220 }
221
Behdad Esfahbod278a91f2010-04-22 13:59:39 -0400222 /* Just sanitize referenced Device tables. Doesn't check the values themselves. */
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330223 bool sanitize_values_stride_unsafe (hb_sanitize_context_t *c, const void *base, const Value *values, unsigned int count, unsigned int stride) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300224 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500225 TRACE_SANITIZE (this);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400226
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100227 if (!has_device ()) return_trace (true);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400228
229 for (unsigned int i = 0; i < count; i++) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400230 if (!sanitize_value_devices (c, base, values))
Ebrahim Byagowi11aa0462018-11-15 23:10:56 +0330231 return_trace (false);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400232 values += stride;
233 }
234
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100235 return_trace (true);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400236 }
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400237};
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400238
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400239
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400240struct AnchorFormat1
241{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330242 void get_anchor (hb_ot_apply_context_t *c, hb_codepoint_t glyph_id HB_UNUSED,
243 float *x, float *y) const
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400244 {
Behdad Esfahbod49cb8782016-09-09 16:27:03 -0700245 hb_font_t *font = c->font;
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +0100246 *x = font->em_fscale_x (xCoordinate);
247 *y = font->em_fscale_y (yCoordinate);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400248 }
249
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330250 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300251 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500252 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100253 return_trace (c->check_struct (this));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400254 }
255
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400256 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100257 HBUINT16 format; /* Format identifier--format = 1 */
Behdad Esfahbode347fb92018-02-26 01:08:00 -0800258 FWORD xCoordinate; /* Horizontal value--in design units */
259 FWORD yCoordinate; /* Vertical value--in design units */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400260 public:
261 DEFINE_SIZE_STATIC (6);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400262};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400263
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400264struct AnchorFormat2
265{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330266 void get_anchor (hb_ot_apply_context_t *c, hb_codepoint_t glyph_id,
267 float *x, float *y) const
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400268 {
Behdad Esfahbod49cb8782016-09-09 16:27:03 -0700269 hb_font_t *font = c->font;
270 unsigned int x_ppem = font->x_ppem;
271 unsigned int y_ppem = font->y_ppem;
Ebrahim Byagowieaf64942018-04-23 18:39:40 +0430272 hb_position_t cx = 0, cy = 0;
Behdad Esfahbod385f78b2018-11-07 17:19:21 -0500273 bool ret;
Behdad Esfahbod6f729b42010-04-29 03:59:06 -0400274
Behdad Esfahbod49cb8782016-09-09 16:27:03 -0700275 ret = (x_ppem || y_ppem) &&
Behdad Esfahbod385f78b2018-11-07 17:19:21 -0500276 font->get_glyph_contour_point_for_origin (glyph_id, anchorPoint, HB_DIRECTION_LTR, &cx, &cy);
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +0100277 *x = ret && x_ppem ? cx : font->em_fscale_x (xCoordinate);
278 *y = ret && y_ppem ? cy : font->em_fscale_y (yCoordinate);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400279 }
280
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330281 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300282 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500283 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100284 return_trace (c->check_struct (this));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400285 }
286
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400287 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100288 HBUINT16 format; /* Format identifier--format = 2 */
Behdad Esfahbode347fb92018-02-26 01:08:00 -0800289 FWORD xCoordinate; /* Horizontal value--in design units */
290 FWORD yCoordinate; /* Vertical value--in design units */
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100291 HBUINT16 anchorPoint; /* Index to glyph contour point */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400292 public:
293 DEFINE_SIZE_STATIC (8);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400294};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400295
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400296struct AnchorFormat3
297{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330298 void get_anchor (hb_ot_apply_context_t *c, hb_codepoint_t glyph_id HB_UNUSED,
299 float *x, float *y) const
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400300 {
Behdad Esfahbod49cb8782016-09-09 16:27:03 -0700301 hb_font_t *font = c->font;
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +0100302 *x = font->em_fscale_x (xCoordinate);
303 *y = font->em_fscale_y (yCoordinate);
Behdad Esfahbodc18ec2b2009-05-21 04:54:01 -0400304
Behdad Esfahbod49cb8782016-09-09 16:27:03 -0700305 if (font->x_ppem || font->num_coords)
Behdad Esfahbod151d93d2016-09-09 17:03:11 -0700306 *x += (this+xDeviceTable).get_x_delta (font, c->var_store);
Behdad Esfahbod49cb8782016-09-09 16:27:03 -0700307 if (font->y_ppem || font->num_coords)
Behdad Esfahbod1124d2e2016-09-09 22:48:27 -0700308 *y += (this+yDeviceTable).get_y_delta (font, c->var_store);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400309 }
310
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330311 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300312 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500313 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100314 return_trace (c->check_struct (this) && xDeviceTable.sanitize (c, this) && yDeviceTable.sanitize (c, this));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400315 }
316
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400317 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100318 HBUINT16 format; /* Format identifier--format = 3 */
Behdad Esfahbode347fb92018-02-26 01:08:00 -0800319 FWORD xCoordinate; /* Horizontal value--in design units */
320 FWORD yCoordinate; /* Vertical value--in design units */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400321 OffsetTo<Device>
322 xDeviceTable; /* Offset to Device table for X
323 * coordinate-- from beginning of
324 * Anchor table (may be NULL) */
325 OffsetTo<Device>
326 yDeviceTable; /* Offset to Device table for Y
327 * coordinate-- from beginning of
328 * Anchor table (may be NULL) */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400329 public:
330 DEFINE_SIZE_STATIC (10);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400331};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400332
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400333struct Anchor
334{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330335 void get_anchor (hb_ot_apply_context_t *c, hb_codepoint_t glyph_id,
336 float *x, float *y) const
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400337 {
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400338 *x = *y = 0;
339 switch (u.format) {
Behdad Esfahbod49cb8782016-09-09 16:27:03 -0700340 case 1: u.format1.get_anchor (c, glyph_id, x, y); return;
341 case 2: u.format2.get_anchor (c, glyph_id, x, y); return;
342 case 3: u.format3.get_anchor (c, glyph_id, x, y); return;
Behdad Esfahbod7cdd6ab2018-01-10 04:33:08 +0100343 default: return;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400344 }
345 }
346
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330347 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300348 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500349 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100350 if (!u.format.sanitize (c)) return_trace (false);
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400351 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100352 case 1: return_trace (u.format1.sanitize (c));
353 case 2: return_trace (u.format2.sanitize (c));
354 case 3: return_trace (u.format3.sanitize (c));
355 default:return_trace (true);
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400356 }
357 }
358
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400359 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400360 union {
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100361 HBUINT16 format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400362 AnchorFormat1 format1;
363 AnchorFormat2 format2;
364 AnchorFormat3 format3;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400365 } u;
Behdad Esfahboded074222010-05-10 18:08:46 -0400366 public:
Behdad Esfahbod596e4712010-05-10 18:47:48 -0400367 DEFINE_SIZE_UNION (2, format);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400368};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400369
370
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400371struct AnchorMatrix
372{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330373 const Anchor& get_anchor (unsigned int row, unsigned int col,
374 unsigned int cols, bool *found) const
375 {
Behdad Esfahbode95e0312013-01-08 16:15:46 -0600376 *found = false;
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400377 if (unlikely (row >= rows || col >= cols)) return Null(Anchor);
Behdad Esfahbod093c5202014-12-12 21:07:53 -0800378 *found = !matrixZ[row * cols + col].is_null ();
379 return this+matrixZ[row * cols + col];
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400380 }
381
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330382 bool sanitize (hb_sanitize_context_t *c, unsigned int cols) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300383 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500384 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100385 if (!c->check_struct (this)) return_trace (false);
Behdad Esfahbodbddeb2b2018-07-10 14:12:37 +0200386 if (unlikely (hb_unsigned_mul_overflows (rows, cols))) return_trace (false);
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400387 unsigned int count = rows * cols;
Behdad Esfahboddff2c452018-09-10 23:29:26 +0200388 if (!c->check_array (matrixZ.arrayZ, count)) return_trace (false);
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400389 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100390 if (!matrixZ[i].sanitize (c, this)) return_trace (false);
391 return_trace (true);
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400392 }
393
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100394 HBUINT16 rows; /* Number of rows */
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400395 protected:
Behdad Esfahboddff2c452018-09-10 23:29:26 +0200396 UnsizedArrayOf<OffsetTo<Anchor> >
397 matrixZ; /* Matrix of offsets to Anchor tables--
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400398 * from beginning of AnchorMatrix table */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400399 public:
Behdad Esfahbod093c5202014-12-12 21:07:53 -0800400 DEFINE_SIZE_ARRAY (2, matrixZ);
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400401};
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400402
403
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400404struct MarkRecord
405{
Behdad Esfahbod377bfc52009-05-21 04:58:24 -0400406 friend struct MarkArray;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400407
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330408 bool sanitize (hb_sanitize_context_t *c, const void *base) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300409 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500410 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100411 return_trace (c->check_struct (this) && markAnchor.sanitize (c, base));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400412 }
413
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400414 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100415 HBUINT16 klass; /* Class defined for this mark */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400416 OffsetTo<Anchor>
417 markAnchor; /* Offset to Anchor table--from
418 * beginning of MarkArray table */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400419 public:
420 DEFINE_SIZE_STATIC (4);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400421};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400422
Behdad Esfahbodbea34c72010-05-10 17:28:16 -0400423struct MarkArray : ArrayOf<MarkRecord> /* Array of MarkRecords--in Coverage order */
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400424{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330425 bool apply (hb_ot_apply_context_t *c,
426 unsigned int mark_index, unsigned int glyph_index,
427 const AnchorMatrix &anchors, unsigned int class_count,
428 unsigned int glyph_pos) const
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400429 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500430 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200431 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbodbea34c72010-05-10 17:28:16 -0400432 const MarkRecord &record = ArrayOf<MarkRecord>::operator[](mark_index);
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400433 unsigned int mark_class = record.klass;
434
435 const Anchor& mark_anchor = this + record.markAnchor;
Behdad Esfahbode95e0312013-01-08 16:15:46 -0600436 bool found;
437 const Anchor& glyph_anchor = anchors.get_anchor (glyph_index, mark_class, class_count, &found);
438 /* If this subtable doesn't have an anchor for this base and this class,
439 * return false such that the subsequent subtables have a chance at it. */
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100440 if (unlikely (!found)) return_trace (false);
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400441
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +0100442 float mark_x, mark_y, base_x, base_y;
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400443
Behdad Esfahbodb65aa1c2017-08-10 20:32:02 -0700444 buffer->unsafe_to_break (glyph_pos, buffer->idx);
Behdad Esfahbod49cb8782016-09-09 16:27:03 -0700445 mark_anchor.get_anchor (c, buffer->cur().codepoint, &mark_x, &mark_y);
446 glyph_anchor.get_anchor (c, buffer->info[glyph_pos].codepoint, &base_x, &base_y);
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400447
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200448 hb_glyph_position_t &o = buffer->cur_pos();
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +0100449 o.x_offset = round (base_x - mark_x);
450 o.y_offset = round (base_y - mark_y);
Behdad Esfahbod686567b2016-02-11 15:25:28 +0700451 o.attach_type() = ATTACH_TYPE_MARK;
Behdad Esfahbod0f6278d2016-02-11 14:49:10 +0700452 o.attach_chain() = (int) glyph_pos - (int) buffer->idx;
Behdad Esfahbod550bd142015-11-04 22:58:58 -0800453 buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT;
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400454
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200455 buffer->idx++;
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100456 return_trace (true);
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400457 }
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400458
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330459 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300460 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500461 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100462 return_trace (ArrayOf<MarkRecord>::sanitize (c, this));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400463 }
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400464};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400465
466
467/* Lookups */
468
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400469struct SinglePosFormat1
470{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330471 bool intersects (const hb_set_t *glyphs) const
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700472 { return (this+coverage).intersects (glyphs); }
473
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330474 void collect_glyphs (hb_collect_glyphs_context_t *c) const
Behdad Esfahbod89bcfb22019-01-18 14:59:18 -0500475 { if (unlikely (!(this+coverage).add_coverage (c->input))) return; }
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500476
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330477 const Coverage &get_coverage () const { return this+coverage; }
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400478
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330479 bool apply (hb_ot_apply_context_t *c) const
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400480 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500481 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200482 hb_buffer_t *buffer = c->buffer;
483 unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100484 if (likely (index == NOT_COVERED)) return_trace (false);
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400485
Behdad Esfahbod151d93d2016-09-09 17:03:11 -0700486 valueFormat.apply_value (c, this, values, buffer->cur_pos());
Behdad Esfahbodf53d4342009-05-30 22:17:32 -0400487
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200488 buffer->idx++;
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100489 return_trace (true);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400490 }
491
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330492 bool subset (hb_subset_context_t *c) const
Behdad Esfahbod339d3602018-09-03 17:33:34 -0700493 {
494 TRACE_SUBSET (this);
495 // TODO(subset)
496 return_trace (false);
497 }
498
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330499 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300500 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500501 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100502 return_trace (c->check_struct (this) &&
503 coverage.sanitize (c, this) &&
504 valueFormat.sanitize_value (c, this, values));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400505 }
506
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400507 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100508 HBUINT16 format; /* Format identifier--format = 1 */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400509 OffsetTo<Coverage>
510 coverage; /* Offset to Coverage table--from
511 * beginning of subtable */
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400512 ValueFormat valueFormat; /* Defines the types of data in the
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400513 * ValueRecord */
514 ValueRecord values; /* Defines positioning
515 * value(s)--applied to all glyphs in
516 * the Coverage table */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400517 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400518 DEFINE_SIZE_ARRAY (6, values);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400519};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400520
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400521struct SinglePosFormat2
522{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330523 bool intersects (const hb_set_t *glyphs) const
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700524 { return (this+coverage).intersects (glyphs); }
525
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330526 void collect_glyphs (hb_collect_glyphs_context_t *c) const
Behdad Esfahbod89bcfb22019-01-18 14:59:18 -0500527 { if (unlikely (!(this+coverage).add_coverage (c->input))) return; }
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500528
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330529 const Coverage &get_coverage () const { return this+coverage; }
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400530
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330531 bool apply (hb_ot_apply_context_t *c) const
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400532 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500533 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200534 hb_buffer_t *buffer = c->buffer;
535 unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100536 if (likely (index == NOT_COVERED)) return_trace (false);
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400537
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100538 if (likely (index >= valueCount)) return_trace (false);
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400539
Behdad Esfahbod151d93d2016-09-09 17:03:11 -0700540 valueFormat.apply_value (c, this,
Behdad Esfahbod4b8487d2010-03-16 03:46:17 -0400541 &values[index * valueFormat.get_len ()],
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200542 buffer->cur_pos());
Behdad Esfahbodf53d4342009-05-30 22:17:32 -0400543
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200544 buffer->idx++;
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100545 return_trace (true);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400546 }
547
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330548 bool subset (hb_subset_context_t *c) const
Behdad Esfahbod339d3602018-09-03 17:33:34 -0700549 {
550 TRACE_SUBSET (this);
551 // TODO(subset)
552 return_trace (false);
553 }
554
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330555 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300556 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500557 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100558 return_trace (c->check_struct (this) &&
559 coverage.sanitize (c, this) &&
560 valueFormat.sanitize_values (c, this, values, valueCount));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400561 }
562
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400563 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100564 HBUINT16 format; /* Format identifier--format = 2 */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400565 OffsetTo<Coverage>
566 coverage; /* Offset to Coverage table--from
567 * beginning of subtable */
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400568 ValueFormat valueFormat; /* Defines the types of data in the
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400569 * ValueRecord */
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100570 HBUINT16 valueCount; /* Number of ValueRecords */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400571 ValueRecord values; /* Array of ValueRecords--positioning
572 * values applied to glyphs */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400573 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400574 DEFINE_SIZE_ARRAY (8, values);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400575};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400576
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400577struct SinglePos
578{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -0500579 template <typename context_t>
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330580 typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400581 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -0800582 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -0400583 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400584 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100585 case 1: return_trace (c->dispatch (u.format1));
586 case 2: return_trace (c->dispatch (u.format2));
587 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400588 }
589 }
590
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400591 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400592 union {
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100593 HBUINT16 format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400594 SinglePosFormat1 format1;
595 SinglePosFormat2 format2;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400596 } u;
597};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400598
599
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400600struct PairValueRecord
601{
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400602 friend struct PairSet;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400603
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400604 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400605 GlyphID secondGlyph; /* GlyphID of second glyph in the
606 * pair--first glyph is listed in the
607 * Coverage table */
608 ValueRecord values; /* Positioning data for the first glyph
609 * followed by for second glyph */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400610 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400611 DEFINE_SIZE_ARRAY (2, values);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400612};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400613
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400614struct PairSet
615{
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400616 friend struct PairPosFormat1;
617
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330618 bool intersects (const hb_set_t *glyphs,
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700619 const ValueFormat *valueFormats) const
620 {
Behdad Esfahbodfb059082018-11-30 20:45:40 -0500621 unsigned int len1 = valueFormats[0].get_len ();
622 unsigned int len2 = valueFormats[1].get_len ();
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700623 unsigned int record_size = HBUINT16::static_size * (1 + len1 + len2);
624
Behdad Esfahboddff2c452018-09-10 23:29:26 +0200625 const PairValueRecord *record = &firstPairValueRecord;
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700626 unsigned int count = len;
627 for (unsigned int i = 0; i < count; i++)
628 {
629 if (glyphs->has (record->secondGlyph))
Ebrahim Byagowi11aa0462018-11-15 23:10:56 +0330630 return true;
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700631 record = &StructAtOffset<const PairValueRecord> (record, record_size);
632 }
633 return false;
634 }
635
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330636 void collect_glyphs (hb_collect_glyphs_context_t *c,
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500637 const ValueFormat *valueFormats) const
638 {
Behdad Esfahbodfb059082018-11-30 20:45:40 -0500639 unsigned int len1 = valueFormats[0].get_len ();
640 unsigned int len2 = valueFormats[1].get_len ();
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100641 unsigned int record_size = HBUINT16::static_size * (1 + len1 + len2);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500642
Behdad Esfahboddff2c452018-09-10 23:29:26 +0200643 const PairValueRecord *record = &firstPairValueRecord;
Behdad Esfahbod81f27df2017-12-16 06:12:06 -0800644 c->input->add_array (&record->secondGlyph, len, record_size);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500645 }
646
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330647 bool apply (hb_ot_apply_context_t *c,
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400648 const ValueFormat *valueFormats,
649 unsigned int pos) const
650 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500651 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200652 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbodfb059082018-11-30 20:45:40 -0500653 unsigned int len1 = valueFormats[0].get_len ();
654 unsigned int len2 = valueFormats[1].get_len ();
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100655 unsigned int record_size = HBUINT16::static_size * (1 + len1 + len2);
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400656
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500657 unsigned int count = len;
Behdad Esfahbod67dfa8c2015-01-19 17:00:31 -0800658
659 /* Hand-coded bsearch. */
660 if (unlikely (!count))
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100661 return_trace (false);
Behdad Esfahbod67dfa8c2015-01-19 17:00:31 -0800662 hb_codepoint_t x = buffer->info[pos].codepoint;
663 int min = 0, max = (int) count - 1;
664 while (min <= max)
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400665 {
Behdad Esfahbod21ede862018-10-25 13:19:34 -0700666 int mid = ((unsigned int) min + (unsigned int) max) / 2;
Behdad Esfahboddff2c452018-09-10 23:29:26 +0200667 const PairValueRecord *record = &StructAtOffset<PairValueRecord> (&firstPairValueRecord, record_size * mid);
Behdad Esfahbod67dfa8c2015-01-19 17:00:31 -0800668 hb_codepoint_t mid_x = record->secondGlyph;
669 if (x < mid_x)
Ebrahim Byagowi11aa0462018-11-15 23:10:56 +0330670 max = mid - 1;
Behdad Esfahbod67dfa8c2015-01-19 17:00:31 -0800671 else if (x > mid_x)
Ebrahim Byagowi11aa0462018-11-15 23:10:56 +0330672 min = mid + 1;
Behdad Esfahbod67dfa8c2015-01-19 17:00:31 -0800673 else
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400674 {
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500675 /* Note the intentional use of "|" instead of short-circuit "||". */
Behdad Esfahbodfb059082018-11-30 20:45:40 -0500676 if (valueFormats[0].apply_value (c, this, &record->values[0], buffer->cur_pos()) |
677 valueFormats[1].apply_value (c, this, &record->values[len1], buffer->pos[pos]))
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500678 buffer->unsafe_to_break (buffer->idx, pos + 1);
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400679 if (len2)
680 pos++;
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200681 buffer->idx = pos;
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100682 return_trace (true);
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400683 }
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400684 }
685
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100686 return_trace (false);
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400687 }
688
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700689 struct sanitize_closure_t
690 {
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300691 const void *base;
692 const ValueFormat *valueFormats;
Behdad Esfahbodfb059082018-11-30 20:45:40 -0500693 unsigned int len1; /* valueFormats[0].get_len() */
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400694 unsigned int stride; /* 1 + len1 + len2 */
695 };
696
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330697 bool sanitize (hb_sanitize_context_t *c, const sanitize_closure_t *closure) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300698 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500699 TRACE_SANITIZE (this);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400700 if (!(c->check_struct (this)
Behdad Esfahbode0144052018-11-12 14:23:31 -0500701 && c->check_range (&firstPairValueRecord,
702 len,
703 HBUINT16::static_size,
704 closure->stride))) return_trace (false);
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400705
706 unsigned int count = len;
Behdad Esfahboddff2c452018-09-10 23:29:26 +0200707 const PairValueRecord *record = &firstPairValueRecord;
Behdad Esfahbodfb059082018-11-30 20:45:40 -0500708 return_trace (closure->valueFormats[0].sanitize_values_stride_unsafe (c, closure->base, &record->values[0], count, closure->stride) &&
709 closure->valueFormats[1].sanitize_values_stride_unsafe (c, closure->base, &record->values[closure->len1], count, closure->stride));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400710 }
711
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400712 protected:
Behdad Esfahboddff2c452018-09-10 23:29:26 +0200713 HBUINT16 len; /* Number of PairValueRecords */
714 PairValueRecord firstPairValueRecord;
715 /* Array of PairValueRecords--ordered
716 * by GlyphID of the second glyph */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400717 public:
Behdad Esfahboddff2c452018-09-10 23:29:26 +0200718 DEFINE_SIZE_MIN (2);
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400719};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400720
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400721struct PairPosFormat1
722{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330723 bool intersects (const hb_set_t *glyphs) const
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700724 {
725 unsigned int count = pairSet.len;
Behdad Esfahbodca5e5a42018-10-29 22:30:21 -0700726 for (Coverage::Iter iter (this+coverage); iter.more (); iter.next ())
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700727 {
728 if (unlikely (iter.get_coverage () >= count))
Ebrahim Byagowi11aa0462018-11-15 23:10:56 +0330729 break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700730 if (glyphs->has (iter.get_glyph ()) &&
731 (this+pairSet[iter.get_coverage ()]).intersects (glyphs, valueFormat))
Ebrahim Byagowi11aa0462018-11-15 23:10:56 +0330732 return true;
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700733 }
734 return false;
735 }
736
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330737 void collect_glyphs (hb_collect_glyphs_context_t *c) const
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500738 {
Behdad Esfahbod81f27df2017-12-16 06:12:06 -0800739 if (unlikely (!(this+coverage).add_coverage (c->input))) return;
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500740 unsigned int count = pairSet.len;
741 for (unsigned int i = 0; i < count; i++)
Volker H. Simonisad273882016-12-14 18:56:17 +0100742 (this+pairSet[i]).collect_glyphs (c, valueFormat);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500743 }
744
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330745 const Coverage &get_coverage () const { return this+coverage; }
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400746
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330747 bool apply (hb_ot_apply_context_t *c) const
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400748 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500749 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200750 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200751 unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100752 if (likely (index == NOT_COVERED)) return_trace (false);
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400753
Behdad Esfahbodfd034492018-01-17 16:46:51 -0800754 hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +0100755 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100756 if (!skippy_iter.next ()) return_trace (false);
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400757
Volker H. Simonisad273882016-12-14 18:56:17 +0100758 return_trace ((this+pairSet[index]).apply (c, valueFormat, skippy_iter.idx));
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400759 }
760
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330761 bool subset (hb_subset_context_t *c) const
Behdad Esfahbod339d3602018-09-03 17:33:34 -0700762 {
763 TRACE_SUBSET (this);
764 // TODO(subset)
765 return_trace (false);
766 }
767
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330768 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300769 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500770 TRACE_SANITIZE (this);
Behdad Esfahbodeba8b4f2010-03-29 00:04:12 -0400771
Behdad Esfahbodf9666492015-10-13 00:30:50 -0400772 if (!c->check_struct (this)) return_trace (false);
773
Behdad Esfahbodfb059082018-11-30 20:45:40 -0500774 unsigned int len1 = valueFormat[0].get_len ();
775 unsigned int len2 = valueFormat[1].get_len ();
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700776 PairSet::sanitize_closure_t closure =
777 {
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400778 this,
Volker H. Simonisad273882016-12-14 18:56:17 +0100779 valueFormat,
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400780 len1,
781 1 + len1 + len2
782 };
Behdad Esfahbodeba8b4f2010-03-29 00:04:12 -0400783
Behdad Esfahbodf9666492015-10-13 00:30:50 -0400784 return_trace (coverage.sanitize (c, this) && pairSet.sanitize (c, this, &closure));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400785 }
786
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400787 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100788 HBUINT16 format; /* Format identifier--format = 1 */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400789 OffsetTo<Coverage>
790 coverage; /* Offset to Coverage table--from
791 * beginning of subtable */
Behdad Esfahbodfb059082018-11-30 20:45:40 -0500792 ValueFormat valueFormat[2]; /* [0] Defines the types of data in
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400793 * ValueRecord1--for the first glyph
794 * in the pair--may be zero (0) */
Behdad Esfahbodfb059082018-11-30 20:45:40 -0500795 /* [1] Defines the types of data in
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400796 * ValueRecord2--for the second glyph
797 * in the pair--may be zero (0) */
798 OffsetArrayOf<PairSet>
799 pairSet; /* Array of PairSet tables
800 * ordered by Coverage Index */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400801 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400802 DEFINE_SIZE_ARRAY (10, pairSet);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400803};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400804
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400805struct PairPosFormat2
806{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330807 bool intersects (const hb_set_t *glyphs) const
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700808 {
809 return (this+coverage).intersects (glyphs) &&
810 (this+classDef2).intersects (glyphs);
811 }
812
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330813 void collect_glyphs (hb_collect_glyphs_context_t *c) const
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500814 {
Behdad Esfahbod81f27df2017-12-16 06:12:06 -0800815 if (unlikely (!(this+coverage).add_coverage (c->input))) return;
Behdad Esfahbod71e6adf2017-12-16 11:07:37 -0500816 if (unlikely (!(this+classDef2).add_coverage (c->input))) return;
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500817 }
818
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330819 const Coverage &get_coverage () const { return this+coverage; }
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400820
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330821 bool apply (hb_ot_apply_context_t *c) const
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400822 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500823 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200824 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200825 unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100826 if (likely (index == NOT_COVERED)) return_trace (false);
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400827
Behdad Esfahbodfd034492018-01-17 16:46:51 -0800828 hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +0100829 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100830 if (!skippy_iter.next ()) return_trace (false);
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400831
832 unsigned int len1 = valueFormat1.get_len ();
833 unsigned int len2 = valueFormat2.get_len ();
834 unsigned int record_len = len1 + len2;
835
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200836 unsigned int klass1 = (this+classDef1).get_class (buffer->cur().codepoint);
837 unsigned int klass2 = (this+classDef2).get_class (buffer->info[skippy_iter.idx].codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100838 if (unlikely (klass1 >= class1Count || klass2 >= class2Count)) return_trace (false);
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400839
Behdad Esfahbod4b8487d2010-03-16 03:46:17 -0400840 const Value *v = &values[record_len * (klass1 * class2Count + klass2)];
Behdad Esfahbod6ee6cd92018-11-07 15:40:55 -0500841 /* Note the intentional use of "|" instead of short-circuit "||". */
842 if (valueFormat1.apply_value (c, this, v, buffer->cur_pos()) |
843 valueFormat2.apply_value (c, this, v + len1, buffer->pos[skippy_iter.idx]))
844 buffer->unsafe_to_break (buffer->idx, skippy_iter.idx + 1);
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400845
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200846 buffer->idx = skippy_iter.idx;
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400847 if (len2)
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200848 buffer->idx++;
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400849
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100850 return_trace (true);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400851 }
852
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330853 bool subset (hb_subset_context_t *c) const
Behdad Esfahbod339d3602018-09-03 17:33:34 -0700854 {
855 TRACE_SUBSET (this);
856 // TODO(subset)
857 return_trace (false);
858 }
859
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330860 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300861 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500862 TRACE_SANITIZE (this);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400863 if (!(c->check_struct (this)
864 && coverage.sanitize (c, this)
865 && classDef1.sanitize (c, this)
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100866 && classDef2.sanitize (c, this))) return_trace (false);
Behdad Esfahbod815a73e2009-08-14 17:31:16 -0400867
Behdad Esfahbodeba8b4f2010-03-29 00:04:12 -0400868 unsigned int len1 = valueFormat1.get_len ();
869 unsigned int len2 = valueFormat2.get_len ();
870 unsigned int stride = len1 + len2;
Behdad Esfahbod4b8487d2010-03-16 03:46:17 -0400871 unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size ();
Behdad Esfahbodeba8b4f2010-03-29 00:04:12 -0400872 unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count;
Behdad Esfahbode0144052018-11-12 14:23:31 -0500873 return_trace (c->check_range ((const void *) values,
874 count,
875 record_size) &&
Behdad Esfahbodfb059082018-11-30 20:45:40 -0500876 valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) &&
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100877 valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400878 }
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400879
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400880 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100881 HBUINT16 format; /* Format identifier--format = 2 */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400882 OffsetTo<Coverage>
883 coverage; /* Offset to Coverage table--from
884 * beginning of subtable */
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400885 ValueFormat valueFormat1; /* ValueRecord definition--for the
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400886 * first glyph of the pair--may be zero
887 * (0) */
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400888 ValueFormat valueFormat2; /* ValueRecord definition--for the
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400889 * second glyph of the pair--may be
890 * zero (0) */
891 OffsetTo<ClassDef>
892 classDef1; /* Offset to ClassDef table--from
893 * beginning of PairPos subtable--for
894 * the first glyph of the pair */
895 OffsetTo<ClassDef>
896 classDef2; /* Offset to ClassDef table--from
897 * beginning of PairPos subtable--for
898 * the second glyph of the pair */
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100899 HBUINT16 class1Count; /* Number of classes in ClassDef1
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400900 * table--includes Class0 */
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100901 HBUINT16 class2Count; /* Number of classes in ClassDef2
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400902 * table--includes Class0 */
903 ValueRecord values; /* Matrix of value pairs:
904 * class1-major, class2-minor,
905 * Each entry has value1 and value2 */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400906 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400907 DEFINE_SIZE_ARRAY (16, values);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400908};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400909
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400910struct PairPos
911{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -0500912 template <typename context_t>
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330913 typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400914 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -0800915 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -0400916 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400917 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100918 case 1: return_trace (c->dispatch (u.format1));
919 case 2: return_trace (c->dispatch (u.format2));
920 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400921 }
922 }
923
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400924 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400925 union {
Behdad Esfahbod6b191782018-01-10 03:07:30 +0100926 HBUINT16 format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400927 PairPosFormat1 format1;
928 PairPosFormat2 format2;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400929 } u;
930};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400931
932
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400933struct EntryExitRecord
934{
Behdad Esfahbod569da922010-05-10 16:38:32 -0400935 friend struct CursivePosFormat1;
936
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330937 bool sanitize (hb_sanitize_context_t *c, const void *base) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300938 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500939 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100940 return_trace (entryAnchor.sanitize (c, base) && exitAnchor.sanitize (c, base));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400941 }
942
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400943 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400944 OffsetTo<Anchor>
945 entryAnchor; /* Offset to EntryAnchor table--from
946 * beginning of CursivePos
947 * subtable--may be NULL */
948 OffsetTo<Anchor>
949 exitAnchor; /* Offset to ExitAnchor table--from
950 * beginning of CursivePos
951 * subtable--may be NULL */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400952 public:
953 DEFINE_SIZE_STATIC (4);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400954};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400955
Behdad Esfahbod65785752015-08-25 20:24:59 +0100956static void
957reverse_cursive_minor_offset (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction, unsigned int new_parent);
958
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400959struct CursivePosFormat1
960{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330961 bool intersects (const hb_set_t *glyphs) const
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -0700962 { return (this+coverage).intersects (glyphs); }
963
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330964 void collect_glyphs (hb_collect_glyphs_context_t *c) const
Behdad Esfahbod89bcfb22019-01-18 14:59:18 -0500965 { if (unlikely (!(this+coverage).add_coverage (c->input))) return; }
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500966
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330967 const Coverage &get_coverage () const { return this+coverage; }
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400968
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330969 bool apply (hb_ot_apply_context_t *c) const
Behdad Esfahbodd18fd8e2009-05-19 23:25:41 -0400970 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500971 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200972 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbod0f7e6b22009-05-20 04:16:35 -0400973
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200974 const EntryExitRecord &this_record = entryExitRecord[(this+coverage).get_coverage (buffer->cur().codepoint)];
Behdad Esfahbodbf8469b2018-10-11 20:45:00 -0400975 if (!this_record.entryAnchor) return_trace (false);
Behdad Esfahbodd18fd8e2009-05-19 23:25:41 -0400976
Behdad Esfahbodfd034492018-01-17 16:46:51 -0800977 hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +0100978 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodbf8469b2018-10-11 20:45:00 -0400979 if (!skippy_iter.prev ()) return_trace (false);
Behdad Esfahbodd18fd8e2009-05-19 23:25:41 -0400980
Behdad Esfahbodbf8469b2018-10-11 20:45:00 -0400981 const EntryExitRecord &prev_record = entryExitRecord[(this+coverage).get_coverage (buffer->info[skippy_iter.idx].codepoint)];
982 if (!prev_record.exitAnchor) return_trace (false);
Behdad Esfahbodaf5d02a2010-10-27 11:54:26 -0400983
Behdad Esfahbodbf8469b2018-10-11 20:45:00 -0400984 unsigned int i = skippy_iter.idx;
985 unsigned int j = buffer->idx;
Behdad Esfahbodaf5d02a2010-10-27 11:54:26 -0400986
Behdad Esfahbod882ebda2017-08-10 20:23:17 -0700987 buffer->unsafe_to_break (i, j);
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +0100988 float entry_x, entry_y, exit_x, exit_y;
Behdad Esfahbodbf8469b2018-10-11 20:45:00 -0400989 (this+prev_record.exitAnchor).get_anchor (c, buffer->info[i].codepoint, &exit_x, &exit_y);
990 (this+this_record.entryAnchor).get_anchor (c, buffer->info[j].codepoint, &entry_x, &entry_y);
Behdad Esfahbodcc83ae12009-05-27 00:17:37 -0400991
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200992 hb_glyph_position_t *pos = buffer->pos;
Behdad Esfahbod7403e052011-05-24 21:04:15 -0400993
994 hb_position_t d;
995 /* Main-direction adjustment */
996 switch (c->direction) {
997 case HB_DIRECTION_LTR:
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +0100998 pos[i].x_advance = round (exit_x) + pos[i].x_offset;
Behdad Esfahbod7403e052011-05-24 21:04:15 -0400999
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +01001000 d = round (entry_x) + pos[j].x_offset;
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001001 pos[j].x_advance -= d;
1002 pos[j].x_offset -= d;
1003 break;
1004 case HB_DIRECTION_RTL:
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +01001005 d = round (exit_x) + pos[i].x_offset;
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001006 pos[i].x_advance -= d;
1007 pos[i].x_offset -= d;
1008
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +01001009 pos[j].x_advance = round (entry_x) + pos[j].x_offset;
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001010 break;
1011 case HB_DIRECTION_TTB:
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +01001012 pos[i].y_advance = round (exit_y) + pos[i].y_offset;
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001013
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +01001014 d = round (entry_y) + pos[j].y_offset;
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001015 pos[j].y_advance -= d;
1016 pos[j].y_offset -= d;
1017 break;
1018 case HB_DIRECTION_BTT:
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +01001019 d = round (exit_y) + pos[i].y_offset;
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001020 pos[i].y_advance -= d;
1021 pos[i].y_offset -= d;
1022
Behdad Esfahbod188ee6e2018-01-10 05:13:47 +01001023 pos[j].y_advance = round (entry_y);
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001024 break;
1025 case HB_DIRECTION_INVALID:
1026 default:
1027 break;
Behdad Esfahbodd18fd8e2009-05-19 23:25:41 -04001028 }
1029
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001030 /* Cross-direction adjustment */
Behdad Esfahbod58f2a732015-08-25 18:55:34 +01001031
1032 /* We attach child to parent (think graph theory and rooted trees whereas
1033 * the root stays on baseline and each node aligns itself against its
1034 * parent.
1035 *
1036 * Optimize things for the case of RightToLeft, as that's most common in
Behdad Esfahbodbf8469b2018-10-11 20:45:00 -04001037 * Arabic. */
Behdad Esfahbod58f2a732015-08-25 18:55:34 +01001038 unsigned int child = i;
1039 unsigned int parent = j;
1040 hb_position_t x_offset = entry_x - exit_x;
1041 hb_position_t y_offset = entry_y - exit_y;
1042 if (!(c->lookup_props & LookupFlag::RightToLeft))
1043 {
1044 unsigned int k = child;
1045 child = parent;
1046 parent = k;
1047 x_offset = -x_offset;
1048 y_offset = -y_offset;
Behdad Esfahbodd18fd8e2009-05-19 23:25:41 -04001049 }
1050
Behdad Esfahbod65785752015-08-25 20:24:59 +01001051 /* If child was already connected to someone else, walk through its old
1052 * chain and reverse the link direction, such that the whole tree of its
1053 * previous connection now attaches to new parent. Watch out for case
1054 * where new parent is on the path from old chain...
1055 */
1056 reverse_cursive_minor_offset (pos, child, c->direction, parent);
1057
Behdad Esfahbod686567b2016-02-11 15:25:28 +07001058 pos[child].attach_type() = ATTACH_TYPE_CURSIVE;
1059 pos[child].attach_chain() = (int) parent - (int) child;
Behdad Esfahbodcbc3a762016-02-11 16:48:13 +07001060 buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT;
Behdad Esfahbod58f2a732015-08-25 18:55:34 +01001061 if (likely (HB_DIRECTION_IS_HORIZONTAL (c->direction)))
1062 pos[child].y_offset = y_offset;
1063 else
1064 pos[child].x_offset = x_offset;
1065
Behdad Esfahbodbf8469b2018-10-11 20:45:00 -04001066 buffer->idx++;
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001067 return_trace (true);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001068 }
1069
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301070 bool subset (hb_subset_context_t *c) const
Behdad Esfahbod339d3602018-09-03 17:33:34 -07001071 {
1072 TRACE_SUBSET (this);
1073 // TODO(subset)
1074 return_trace (false);
1075 }
1076
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301077 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001078 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001079 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001080 return_trace (coverage.sanitize (c, this) && entryExitRecord.sanitize (c, this));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -04001081 }
1082
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001083 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +01001084 HBUINT16 format; /* Format identifier--format = 1 */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001085 OffsetTo<Coverage>
1086 coverage; /* Offset to Coverage table--from
1087 * beginning of subtable */
1088 ArrayOf<EntryExitRecord>
1089 entryExitRecord; /* Array of EntryExit records--in
1090 * Coverage Index order */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001091 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -04001092 DEFINE_SIZE_ARRAY (6, entryExitRecord);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001093};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001094
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001095struct CursivePos
1096{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -05001097 template <typename context_t>
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301098 typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001099 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08001100 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -04001101 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001102 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001103 case 1: return_trace (c->dispatch (u.format1));
1104 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001105 }
1106 }
1107
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001108 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001109 union {
Behdad Esfahbod6b191782018-01-10 03:07:30 +01001110 HBUINT16 format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001111 CursivePosFormat1 format1;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001112 } u;
1113};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001114
1115
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -04001116typedef AnchorMatrix BaseArray; /* base-major--
1117 * in order of BaseCoverage Index--,
1118 * mark-minor--
Behdad Esfahbodfb3b5cc2009-05-21 04:47:05 -04001119 * ordered by class--zero-based. */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001120
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001121struct MarkBasePosFormat1
1122{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301123 bool intersects (const hb_set_t *glyphs) const
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -07001124 { return (this+markCoverage).intersects (glyphs) &&
1125 (this+baseCoverage).intersects (glyphs); }
1126
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301127 void collect_glyphs (hb_collect_glyphs_context_t *c) const
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001128 {
Behdad Esfahbod81f27df2017-12-16 06:12:06 -08001129 if (unlikely (!(this+markCoverage).add_coverage (c->input))) return;
1130 if (unlikely (!(this+baseCoverage).add_coverage (c->input))) return;
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001131 }
1132
Ebrahim Byagowie4120082018-12-17 21:31:01 +03301133 const Coverage &get_coverage () const { return this+markCoverage; }
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001134
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301135 bool apply (hb_ot_apply_context_t *c) const
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001136 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001137 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001138 hb_buffer_t *buffer = c->buffer;
1139 unsigned int mark_index = (this+markCoverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001140 if (likely (mark_index == NOT_COVERED)) return_trace (false);
Behdad Esfahbod357ccde2009-05-21 06:32:01 -04001141
Behdad Esfahbod6ab92022016-02-11 16:57:52 +07001142 /* Now we search backwards for a non-mark glyph */
Behdad Esfahbodfd034492018-01-17 16:46:51 -08001143 hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +01001144 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodc074ebc2013-02-13 11:22:42 -05001145 skippy_iter.set_lookup_props (LookupFlag::IgnoreMarks);
Behdad Esfahbod7b84c532012-06-08 22:04:23 -04001146 do {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001147 if (!skippy_iter.prev ()) return_trace (false);
Behdad Esfahbod9b5af3e2018-02-10 21:50:26 -06001148 /* We only want to attach to the first of a MultipleSubst sequence.
1149 * https://github.com/harfbuzz/harfbuzz/issues/740
Behdad Esfahbodd3c09802018-06-30 15:59:25 +04301150 * Reject others...
1151 * ...but stop if we find a mark in the MultipleSubst sequence:
1152 * https://github.com/harfbuzz/harfbuzz/issues/1020 */
Behdad Esfahbod5d98de12017-10-03 13:46:25 +02001153 if (!_hb_glyph_info_multiplied (&buffer->info[skippy_iter.idx]) ||
Behdad Esfahbod9b5af3e2018-02-10 21:50:26 -06001154 0 == _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]) ||
1155 (skippy_iter.idx == 0 ||
Behdad Esfahbodd3c09802018-06-30 15:59:25 +04301156 _hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx - 1]) ||
Behdad Esfahbod9b5af3e2018-02-10 21:50:26 -06001157 _hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx]) !=
Behdad Esfahbod1c50a882018-02-18 15:57:09 -08001158 _hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx - 1]) ||
1159 _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]) !=
1160 _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx - 1]) + 1
1161 ))
Behdad Esfahbod5d98de12017-10-03 13:46:25 +02001162 break;
Behdad Esfahbod7b84c532012-06-08 22:04:23 -04001163 skippy_iter.reject ();
Bruce Mitchener8d1e4792018-10-18 22:18:42 +07001164 } while (true);
Behdad Esfahbod0532ed12009-08-12 15:40:04 -04001165
Behdad Esfahbod101303d2013-10-18 00:42:39 +02001166 /* Checking that matched glyph is actually a base glyph by GDEF is too strong; disabled */
Behdad Esfahbod6ab92022016-02-11 16:57:52 +07001167 //if (!_hb_glyph_info_is_base_glyph (&buffer->info[skippy_iter.idx])) { return_trace (false); }
Behdad Esfahbod357ccde2009-05-21 06:32:01 -04001168
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001169 unsigned int base_index = (this+baseCoverage).get_coverage (buffer->info[skippy_iter.idx].codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001170 if (base_index == NOT_COVERED) return_trace (false);
Behdad Esfahbod357ccde2009-05-21 06:32:01 -04001171
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001172 return_trace ((this+markArray).apply (c, mark_index, base_index, this+baseArray, classCount, skippy_iter.idx));
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001173 }
1174
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301175 bool subset (hb_subset_context_t *c) const
Behdad Esfahbod339d3602018-09-03 17:33:34 -07001176 {
1177 TRACE_SUBSET (this);
1178 // TODO(subset)
1179 return_trace (false);
1180 }
1181
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301182 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001183 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001184 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001185 return_trace (c->check_struct (this) &&
1186 markCoverage.sanitize (c, this) &&
1187 baseCoverage.sanitize (c, this) &&
1188 markArray.sanitize (c, this) &&
1189 baseArray.sanitize (c, this, (unsigned int) classCount));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -04001190 }
1191
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001192 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +01001193 HBUINT16 format; /* Format identifier--format = 1 */
Behdad Esfahbodfb3b5cc2009-05-21 04:47:05 -04001194 OffsetTo<Coverage>
1195 markCoverage; /* Offset to MarkCoverage table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001196 * beginning of MarkBasePos subtable */
Behdad Esfahbodfb3b5cc2009-05-21 04:47:05 -04001197 OffsetTo<Coverage>
1198 baseCoverage; /* Offset to BaseCoverage table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001199 * beginning of MarkBasePos subtable */
Behdad Esfahbod6b191782018-01-10 03:07:30 +01001200 HBUINT16 classCount; /* Number of classes defined for marks */
Behdad Esfahbodfb3b5cc2009-05-21 04:47:05 -04001201 OffsetTo<MarkArray>
1202 markArray; /* Offset to MarkArray table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001203 * beginning of MarkBasePos subtable */
Behdad Esfahbodfb3b5cc2009-05-21 04:47:05 -04001204 OffsetTo<BaseArray>
1205 baseArray; /* Offset to BaseArray table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001206 * beginning of MarkBasePos subtable */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001207 public:
1208 DEFINE_SIZE_STATIC (12);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001209};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001210
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001211struct MarkBasePos
1212{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -05001213 template <typename context_t>
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301214 typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001215 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08001216 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -04001217 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001218 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001219 case 1: return_trace (c->dispatch (u.format1));
1220 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001221 }
1222 }
1223
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001224 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001225 union {
Behdad Esfahbod6b191782018-01-10 03:07:30 +01001226 HBUINT16 format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001227 MarkBasePosFormat1 format1;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001228 } u;
1229};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001230
1231
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -04001232typedef AnchorMatrix LigatureAttach; /* component-major--
1233 * in order of writing direction--,
1234 * mark-minor--
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001235 * ordered by class--zero-based. */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001236
Behdad Esfahbod3564ee52009-08-14 18:32:56 -04001237typedef OffsetListOf<LigatureAttach> LigatureArray;
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001238 /* Array of LigatureAttach
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001239 * tables ordered by
1240 * LigatureCoverage Index */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001241
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001242struct MarkLigPosFormat1
1243{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301244 bool intersects (const hb_set_t *glyphs) const
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -07001245 { return (this+markCoverage).intersects (glyphs) &&
1246 (this+ligatureCoverage).intersects (glyphs); }
1247
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301248 void collect_glyphs (hb_collect_glyphs_context_t *c) const
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001249 {
Behdad Esfahbod81f27df2017-12-16 06:12:06 -08001250 if (unlikely (!(this+markCoverage).add_coverage (c->input))) return;
1251 if (unlikely (!(this+ligatureCoverage).add_coverage (c->input))) return;
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001252 }
1253
Ebrahim Byagowie4120082018-12-17 21:31:01 +03301254 const Coverage &get_coverage () const { return this+markCoverage; }
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001255
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301256 bool apply (hb_ot_apply_context_t *c) const
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001257 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001258 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001259 hb_buffer_t *buffer = c->buffer;
1260 unsigned int mark_index = (this+markCoverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001261 if (likely (mark_index == NOT_COVERED)) return_trace (false);
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001262
Behdad Esfahbod6ab92022016-02-11 16:57:52 +07001263 /* Now we search backwards for a non-mark glyph */
Behdad Esfahbodfd034492018-01-17 16:46:51 -08001264 hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +01001265 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodc074ebc2013-02-13 11:22:42 -05001266 skippy_iter.set_lookup_props (LookupFlag::IgnoreMarks);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001267 if (!skippy_iter.prev ()) return_trace (false);
Behdad Esfahbod0532ed12009-08-12 15:40:04 -04001268
Behdad Esfahbod101303d2013-10-18 00:42:39 +02001269 /* Checking that matched glyph is actually a ligature by GDEF is too strong; disabled */
Behdad Esfahbod6ab92022016-02-11 16:57:52 +07001270 //if (!_hb_glyph_info_is_ligature (&buffer->info[skippy_iter.idx])) { return_trace (false); }
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001271
Behdad Esfahbod4ab97312012-01-16 22:05:08 -05001272 unsigned int j = skippy_iter.idx;
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001273 unsigned int lig_index = (this+ligatureCoverage).get_coverage (buffer->info[j].codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001274 if (lig_index == NOT_COVERED) return_trace (false);
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001275
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001276 const LigatureArray& lig_array = this+ligatureArray;
Behdad Esfahbod3564ee52009-08-14 18:32:56 -04001277 const LigatureAttach& lig_attach = lig_array[lig_index];
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -04001278
1279 /* Find component to attach to */
Behdad Esfahbodb2b18ef2009-08-14 19:37:18 -04001280 unsigned int comp_count = lig_attach.rows;
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001281 if (unlikely (!comp_count)) return_trace (false);
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001282
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001283 /* We must now check whether the ligature ID of the current mark glyph
1284 * is identical to the ligature ID of the found ligature. If yes, we
1285 * can directly use the component index. If not, we attach the mark
1286 * glyph to the last component of the ligature. */
Behdad Esfahbod0aef4252012-07-30 00:55:15 -04001287 unsigned int comp_index;
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001288 unsigned int lig_id = _hb_glyph_info_get_lig_id (&buffer->info[j]);
1289 unsigned int mark_id = _hb_glyph_info_get_lig_id (&buffer->cur());
1290 unsigned int mark_comp = _hb_glyph_info_get_lig_comp (&buffer->cur());
Behdad Esfahbod0aef4252012-07-30 00:55:15 -04001291 if (lig_id && lig_id == mark_id && mark_comp > 0)
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001292 comp_index = MIN (comp_count, _hb_glyph_info_get_lig_comp (&buffer->cur())) - 1;
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001293 else
Behdad Esfahbodb2b18ef2009-08-14 19:37:18 -04001294 comp_index = comp_count - 1;
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001295
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001296 return_trace ((this+markArray).apply (c, mark_index, comp_index, lig_attach, classCount, j));
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001297 }
1298
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301299 bool subset (hb_subset_context_t *c) const
Behdad Esfahbod339d3602018-09-03 17:33:34 -07001300 {
1301 TRACE_SUBSET (this);
1302 // TODO(subset)
1303 return_trace (false);
1304 }
1305
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301306 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001307 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001308 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001309 return_trace (c->check_struct (this) &&
1310 markCoverage.sanitize (c, this) &&
1311 ligatureCoverage.sanitize (c, this) &&
1312 markArray.sanitize (c, this) &&
1313 ligatureArray.sanitize (c, this, (unsigned int) classCount));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -04001314 }
1315
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001316 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +01001317 HBUINT16 format; /* Format identifier--format = 1 */
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001318 OffsetTo<Coverage>
1319 markCoverage; /* Offset to Mark Coverage table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001320 * beginning of MarkLigPos subtable */
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001321 OffsetTo<Coverage>
1322 ligatureCoverage; /* Offset to Ligature Coverage
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001323 * table--from beginning of MarkLigPos
1324 * subtable */
Behdad Esfahbod6b191782018-01-10 03:07:30 +01001325 HBUINT16 classCount; /* Number of defined mark classes */
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001326 OffsetTo<MarkArray>
1327 markArray; /* Offset to MarkArray table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001328 * beginning of MarkLigPos subtable */
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001329 OffsetTo<LigatureArray>
1330 ligatureArray; /* Offset to LigatureArray table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001331 * beginning of MarkLigPos subtable */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001332 public:
1333 DEFINE_SIZE_STATIC (12);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001334};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001335
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001336struct MarkLigPos
1337{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -05001338 template <typename context_t>
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301339 typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001340 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08001341 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -04001342 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001343 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001344 case 1: return_trace (c->dispatch (u.format1));
1345 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001346 }
1347 }
1348
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001349 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001350 union {
Behdad Esfahbod6b191782018-01-10 03:07:30 +01001351 HBUINT16 format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001352 MarkLigPosFormat1 format1;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001353 } u;
1354};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001355
1356
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -04001357typedef AnchorMatrix Mark2Array; /* mark2-major--
1358 * in order of Mark2Coverage Index--,
1359 * mark1-minor--
1360 * ordered by class--zero-based. */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001361
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001362struct MarkMarkPosFormat1
1363{
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301364 bool intersects (const hb_set_t *glyphs) const
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -07001365 { return (this+mark1Coverage).intersects (glyphs) &&
1366 (this+mark2Coverage).intersects (glyphs); }
1367
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301368 void collect_glyphs (hb_collect_glyphs_context_t *c) const
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001369 {
Behdad Esfahbod81f27df2017-12-16 06:12:06 -08001370 if (unlikely (!(this+mark1Coverage).add_coverage (c->input))) return;
1371 if (unlikely (!(this+mark2Coverage).add_coverage (c->input))) return;
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001372 }
1373
Ebrahim Byagowie4120082018-12-17 21:31:01 +03301374 const Coverage &get_coverage () const { return this+mark1Coverage; }
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001375
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301376 bool apply (hb_ot_apply_context_t *c) const
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001377 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001378 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001379 hb_buffer_t *buffer = c->buffer;
1380 unsigned int mark1_index = (this+mark1Coverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001381 if (likely (mark1_index == NOT_COVERED)) return_trace (false);
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001382
1383 /* now we search backwards for a suitable mark glyph until a non-mark glyph */
Behdad Esfahbodfd034492018-01-17 16:46:51 -08001384 hb_ot_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +01001385 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodc074ebc2013-02-13 11:22:42 -05001386 skippy_iter.set_lookup_props (c->lookup_props & ~LookupFlag::IgnoreFlags);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001387 if (!skippy_iter.prev ()) return_trace (false);
Behdad Esfahbod0532ed12009-08-12 15:40:04 -04001388
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001389 if (!_hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx])) { return_trace (false); }
Behdad Esfahbod80ea5bd2009-05-26 17:58:37 -04001390
Behdad Esfahbod4ab97312012-01-16 22:05:08 -05001391 unsigned int j = skippy_iter.idx;
1392
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001393 unsigned int id1 = _hb_glyph_info_get_lig_id (&buffer->cur());
1394 unsigned int id2 = _hb_glyph_info_get_lig_id (&buffer->info[j]);
1395 unsigned int comp1 = _hb_glyph_info_get_lig_comp (&buffer->cur());
1396 unsigned int comp2 = _hb_glyph_info_get_lig_comp (&buffer->info[j]);
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001397
Behdad Esfahbod5d874d52012-07-28 21:05:25 -04001398 if (likely (id1 == id2)) {
1399 if (id1 == 0) /* Marks belonging to the same base. */
1400 goto good;
1401 else if (comp1 == comp2) /* Marks belonging to the same ligature component. */
Ebrahim Byagowi11aa0462018-11-15 23:10:56 +03301402 goto good;
Behdad Esfahbod5d874d52012-07-28 21:05:25 -04001403 } else {
1404 /* If ligature ids don't match, it may be the case that one of the marks
1405 * itself is a ligature. In which case match. */
1406 if ((id1 > 0 && !comp1) || (id2 > 0 && !comp2))
1407 goto good;
1408 }
1409
1410 /* Didn't match. */
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001411 return_trace (false);
Behdad Esfahbod5d874d52012-07-28 21:05:25 -04001412
1413 good:
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001414 unsigned int mark2_index = (this+mark2Coverage).get_coverage (buffer->info[j].codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001415 if (mark2_index == NOT_COVERED) return_trace (false);
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001416
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001417 return_trace ((this+mark1Array).apply (c, mark1_index, mark2_index, this+mark2Array, classCount, j));
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001418 }
1419
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301420 bool subset (hb_subset_context_t *c) const
Behdad Esfahbod339d3602018-09-03 17:33:34 -07001421 {
1422 TRACE_SUBSET (this);
1423 // TODO(subset)
1424 return_trace (false);
1425 }
1426
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301427 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001428 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001429 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001430 return_trace (c->check_struct (this) &&
1431 mark1Coverage.sanitize (c, this) &&
1432 mark2Coverage.sanitize (c, this) &&
1433 mark1Array.sanitize (c, this) &&
1434 mark2Array.sanitize (c, this, (unsigned int) classCount));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -04001435 }
1436
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001437 protected:
Behdad Esfahbod6b191782018-01-10 03:07:30 +01001438 HBUINT16 format; /* Format identifier--format = 1 */
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001439 OffsetTo<Coverage>
1440 mark1Coverage; /* Offset to Combining Mark1 Coverage
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001441 * table--from beginning of MarkMarkPos
1442 * subtable */
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001443 OffsetTo<Coverage>
1444 mark2Coverage; /* Offset to Combining Mark2 Coverage
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001445 * table--from beginning of MarkMarkPos
1446 * subtable */
Behdad Esfahbod6b191782018-01-10 03:07:30 +01001447 HBUINT16 classCount; /* Number of defined mark classes */
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001448 OffsetTo<MarkArray>
1449 mark1Array; /* Offset to Mark1Array table--from
1450 * beginning of MarkMarkPos subtable */
1451 OffsetTo<Mark2Array>
1452 mark2Array; /* Offset to Mark2Array table--from
1453 * beginning of MarkMarkPos subtable */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001454 public:
1455 DEFINE_SIZE_STATIC (12);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001456};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001457
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001458struct MarkMarkPos
1459{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -05001460 template <typename context_t>
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301461 typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001462 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08001463 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -04001464 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001465 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001466 case 1: return_trace (c->dispatch (u.format1));
1467 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001468 }
1469 }
1470
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001471 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001472 union {
Behdad Esfahbod6b191782018-01-10 03:07:30 +01001473 HBUINT16 format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001474 MarkMarkPosFormat1 format1;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001475 } u;
1476};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001477
1478
Behdad Esfahbod08f1eed2012-11-23 16:51:43 -05001479struct ContextPos : Context {};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001480
Behdad Esfahbod08f1eed2012-11-23 16:51:43 -05001481struct ChainContextPos : ChainContext {};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001482
Behdad Esfahbod653eeb22012-11-23 16:57:36 -05001483struct ExtensionPos : Extension<ExtensionPos>
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001484{
Behdad Esfahbod9c3747c2018-09-03 16:53:03 -07001485 typedef struct PosLookupSubTable SubTable;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001486};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001487
1488
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04001489
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001490/*
1491 * PosLookup
1492 */
1493
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001494
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001495struct PosLookupSubTable
1496{
Behdad Esfahbod7b2ef552018-09-03 17:16:09 -07001497 friend struct Lookup;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001498 friend struct PosLookup;
1499
Behdad Esfahbodc6035cf2012-04-12 13:23:59 -04001500 enum Type {
Behdad Esfahbodff05d252009-05-20 03:53:00 -04001501 Single = 1,
1502 Pair = 2,
1503 Cursive = 3,
1504 MarkBase = 4,
1505 MarkLig = 5,
1506 MarkMark = 6,
1507 Context = 7,
1508 ChainContext = 8,
Behdad Esfahbod8f034d52009-08-18 16:41:59 -04001509 Extension = 9
Behdad Esfahbodff05d252009-05-20 03:53:00 -04001510 };
1511
Behdad Esfahbod2005fa52012-11-22 14:38:10 -05001512 template <typename context_t>
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301513 typename context_t::return_t dispatch (context_t *c, unsigned int lookup_type) const
Behdad Esfahbodfaf0f202012-06-09 03:02:36 -04001514 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08001515 TRACE_DISPATCH (this, lookup_type);
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001516 switch (lookup_type) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001517 case Single: return_trace (u.single.dispatch (c));
1518 case Pair: return_trace (u.pair.dispatch (c));
1519 case Cursive: return_trace (u.cursive.dispatch (c));
1520 case MarkBase: return_trace (u.markBase.dispatch (c));
1521 case MarkLig: return_trace (u.markLig.dispatch (c));
1522 case MarkMark: return_trace (u.markMark.dispatch (c));
1523 case Context: return_trace (u.context.dispatch (c));
1524 case ChainContext: return_trace (u.chainContext.dispatch (c));
1525 case Extension: return_trace (u.extension.dispatch (c));
1526 default: return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001527 }
Behdad Esfahbodfaf0f202012-06-09 03:02:36 -04001528 }
1529
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001530 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001531 union {
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001532 SinglePos single;
1533 PairPos pair;
1534 CursivePos cursive;
1535 MarkBasePos markBase;
1536 MarkLigPos markLig;
1537 MarkMarkPos markMark;
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001538 ContextPos context;
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001539 ChainContextPos chainContext;
1540 ExtensionPos extension;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001541 } u;
Behdad Esfahboded074222010-05-10 18:08:46 -04001542 public:
Behdad Esfahbod2cc993e2018-12-12 10:07:38 -05001543 DEFINE_SIZE_MIN (0);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001544};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001545
1546
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001547struct PosLookup : Lookup
1548{
Behdad Esfahbod9c3747c2018-09-03 16:53:03 -07001549 typedef struct PosLookupSubTable SubTable;
1550
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301551 const SubTable& get_subtable (unsigned int i) const
Behdad Esfahbod9c3747c2018-09-03 16:53:03 -07001552 { return Lookup::get_subtable<SubTable> (i); }
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001553
Ebrahim Byagowie4120082018-12-17 21:31:01 +03301554 bool is_reverse () const
Behdad Esfahbode015b8f2013-05-03 17:34:29 -04001555 {
1556 return false;
1557 }
1558
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301559 bool apply (hb_ot_apply_context_t *c) const
Behdad Esfahbodbd047d32015-02-19 10:47:18 +03001560 {
1561 TRACE_APPLY (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001562 return_trace (dispatch (c));
Behdad Esfahbodbd047d32015-02-19 10:47:18 +03001563 }
1564
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301565 bool intersects (const hb_set_t *glyphs) const
Behdad Esfahbod7c9cfa22018-09-02 19:47:50 -07001566 {
1567 hb_intersects_context_t c (glyphs);
1568 return dispatch (&c);
1569 }
1570
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301571 hb_collect_glyphs_context_t::return_t collect_glyphs (hb_collect_glyphs_context_t *c) const
Behdad Esfahbod89bcfb22019-01-18 14:59:18 -05001572 { return dispatch (c); }
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001573
Behdad Esfahboda878c582012-08-01 21:18:54 -04001574 template <typename set_t>
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301575 void add_coverage (set_t *glyphs) const
Behdad Esfahboda878c582012-08-01 21:18:54 -04001576 {
Behdad Esfahbod8e36ccf2015-02-17 19:15:34 +03001577 hb_add_coverage_context_t<set_t> c (glyphs);
1578 dispatch (&c);
Behdad Esfahboda878c582012-08-01 21:18:54 -04001579 }
1580
Behdad Esfahbodfd034492018-01-17 16:46:51 -08001581 static bool apply_recurse_func (hb_ot_apply_context_t *c, unsigned int lookup_index);
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001582
Behdad Esfahbodee5464d2013-03-09 01:59:30 -05001583 template <typename context_t>
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301584 static typename context_t::return_t dispatch_recurse_func (context_t *c, unsigned int lookup_index);
Behdad Esfahbodee5464d2013-03-09 01:59:30 -05001585
1586 template <typename context_t>
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301587 typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod9c3747c2018-09-03 16:53:03 -07001588 { return Lookup::dispatch<SubTable> (c); }
Behdad Esfahbodee5464d2013-03-09 01:59:30 -05001589
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301590 bool subset (hb_subset_context_t *c) const
Behdad Esfahbod339d3602018-09-03 17:33:34 -07001591 { return Lookup::subset<SubTable> (c); }
1592
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301593 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbod7b2ef552018-09-03 17:16:09 -07001594 { return Lookup::sanitize<SubTable> (c); }
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001595};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001596
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001597/*
Ebrahim Byagowia02c3ee2018-04-12 13:38:19 +04301598 * GPOS -- Glyph Positioning
1599 * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001600 */
1601
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001602struct GPOS : GSUBGPOS
1603{
Behdad Esfahbodef006542019-01-22 12:08:57 +01001604 static constexpr hb_tag_t tableTag = HB_OT_TAG_GPOS;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001605
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301606 const PosLookup& get_lookup (unsigned int i) const
Behdad Esfahbod187454c2010-04-23 16:35:01 -04001607 { return CastR<PosLookup> (GSUBGPOS::get_lookup (i)); }
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001608
Behdad Esfahbod05bd1b62012-07-30 19:30:01 -04001609 static inline void position_start (hb_font_t *font, hb_buffer_t *buffer);
Behdad Esfahbod7d8d58a2016-02-11 16:34:28 +07001610 static inline void position_finish_advances (hb_font_t *font, hb_buffer_t *buffer);
1611 static inline void position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer);
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001612
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301613 bool subset (hb_subset_context_t *c) const
Behdad Esfahbod339d3602018-09-03 17:33:34 -07001614 { return GSUBGPOS::subset<PosLookup> (c); }
1615
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +03301616 bool sanitize (hb_sanitize_context_t *c) const
Behdad Esfahbod339d3602018-09-03 17:33:34 -07001617 { return GSUBGPOS::sanitize<PosLookup> (c); }
Behdad Esfahbod963413f2018-08-26 00:47:55 -07001618
Behdad Esfahbod574d8882018-11-25 16:51:22 -05001619 HB_INTERNAL bool is_blacklisted (hb_blob_t *blob,
1620 hb_face_t *face) const;
1621
Behdad Esfahbod963413f2018-08-26 00:47:55 -07001622 typedef GSUBGPOS::accelerator_t<GPOS> accelerator_t;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001623};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001624
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001625
1626static void
Behdad Esfahbod65785752015-08-25 20:24:59 +01001627reverse_cursive_minor_offset (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction, unsigned int new_parent)
1628{
Behdad Esfahbod686567b2016-02-11 15:25:28 +07001629 int chain = pos[i].attach_chain(), type = pos[i].attach_type();
1630 if (likely (!chain || 0 == (type & ATTACH_TYPE_CURSIVE)))
Behdad Esfahbod65785752015-08-25 20:24:59 +01001631 return;
1632
Behdad Esfahbod686567b2016-02-11 15:25:28 +07001633 pos[i].attach_chain() = 0;
Behdad Esfahbod65785752015-08-25 20:24:59 +01001634
Behdad Esfahbod686567b2016-02-11 15:25:28 +07001635 unsigned int j = (int) i + chain;
Behdad Esfahbod806ad8d2016-02-11 14:53:11 +07001636
Behdad Esfahbod65785752015-08-25 20:24:59 +01001637 /* Stop if we see new parent in the chain. */
1638 if (j == new_parent)
1639 return;
1640
1641 reverse_cursive_minor_offset (pos, j, direction, new_parent);
1642
1643 if (HB_DIRECTION_IS_HORIZONTAL (direction))
1644 pos[j].y_offset = -pos[i].y_offset;
1645 else
1646 pos[j].x_offset = -pos[i].x_offset;
1647
Behdad Esfahbod686567b2016-02-11 15:25:28 +07001648 pos[j].attach_chain() = -chain;
1649 pos[j].attach_type() = type;
Behdad Esfahbod65785752015-08-25 20:24:59 +01001650}
1651static void
Behdad Esfahbod36f38ea2018-10-16 16:24:03 -07001652propagate_attachment_offsets (hb_glyph_position_t *pos,
1653 unsigned int len,
1654 unsigned int i,
1655 hb_direction_t direction)
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001656{
Behdad Esfahbodcbc3a762016-02-11 16:48:13 +07001657 /* Adjusts offsets of attached glyphs (both cursive and mark) to accumulate
1658 * offset of glyph they are attached to. */
Behdad Esfahbod686567b2016-02-11 15:25:28 +07001659 int chain = pos[i].attach_chain(), type = pos[i].attach_type();
Behdad Esfahbodcbc3a762016-02-11 16:48:13 +07001660 if (likely (!chain))
Behdad Esfahboddf5d5c62012-08-23 09:33:30 -04001661 return;
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001662
Behdad Esfahbod686567b2016-02-11 15:25:28 +07001663 pos[i].attach_chain() = 0;
1664
Behdad Esfahbod36f38ea2018-10-16 16:24:03 -07001665 unsigned int j = (int) i + chain;
1666
1667 if (unlikely (j >= len))
1668 return;
1669
1670 propagate_attachment_offsets (pos, len, j, direction);
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001671
Behdad Esfahbodcbc3a762016-02-11 16:48:13 +07001672 assert (!!(type & ATTACH_TYPE_MARK) ^ !!(type & ATTACH_TYPE_CURSIVE));
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001673
Behdad Esfahbodcbc3a762016-02-11 16:48:13 +07001674 if (type & ATTACH_TYPE_CURSIVE)
1675 {
1676 if (HB_DIRECTION_IS_HORIZONTAL (direction))
1677 pos[i].y_offset += pos[j].y_offset;
1678 else
1679 pos[i].x_offset += pos[j].x_offset;
1680 }
1681 else /*if (type & ATTACH_TYPE_MARK)*/
1682 {
Behdad Esfahboddf5d5c62012-08-23 09:33:30 -04001683 pos[i].x_offset += pos[j].x_offset;
Behdad Esfahbodcbc3a762016-02-11 16:48:13 +07001684 pos[i].y_offset += pos[j].y_offset;
Behdad Esfahbodebd74312016-02-24 15:53:40 +09001685
1686 assert (j < i);
1687 if (HB_DIRECTION_IS_FORWARD (direction))
1688 for (unsigned int k = j; k < i; k++) {
1689 pos[i].x_offset -= pos[k].x_advance;
1690 pos[i].y_offset -= pos[k].y_advance;
1691 }
1692 else
1693 for (unsigned int k = j + 1; k < i + 1; k++) {
1694 pos[i].x_offset += pos[k].x_advance;
1695 pos[i].y_offset += pos[k].y_advance;
1696 }
Behdad Esfahbodcbc3a762016-02-11 16:48:13 +07001697 }
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001698}
1699
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001700void
Behdad Esfahbod05bd1b62012-07-30 19:30:01 -04001701GPOS::position_start (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer)
Behdad Esfahboda9ad3d32011-07-28 15:42:18 -04001702{
Behdad Esfahbodb65c0602011-07-28 16:48:43 -04001703 unsigned int count = buffer->len;
1704 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbod686567b2016-02-11 15:25:28 +07001705 buffer->pos[i].attach_chain() = buffer->pos[i].attach_type() = 0;
Behdad Esfahboda9ad3d32011-07-28 15:42:18 -04001706}
1707
1708void
Behdad Esfahbod39bd07a2018-10-26 21:01:11 -07001709GPOS::position_finish_advances (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer HB_UNUSED)
Behdad Esfahbod7d8d58a2016-02-11 16:34:28 +07001710{
1711 //_hb_buffer_assert_gsubgpos_vars (buffer);
1712}
1713
1714void
1715GPOS::position_finish_offsets (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer)
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001716{
Behdad Esfahbod8f3eebf2014-08-02 17:18:46 -04001717 _hb_buffer_assert_gsubgpos_vars (buffer);
1718
Ryan Lortie70566be2011-04-15 18:32:36 -04001719 unsigned int len;
1720 hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, &len);
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001721 hb_direction_t direction = buffer->props.direction;
1722
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001723 /* Handle attachments */
Behdad Esfahbod550bd142015-11-04 22:58:58 -08001724 if (buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT)
1725 for (unsigned int i = 0; i < len; i++)
Behdad Esfahbod36f38ea2018-10-16 16:24:03 -07001726 propagate_attachment_offsets (pos, len, i, direction);
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001727}
1728
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001729
Behdad Esfahbod33b006c2018-11-05 23:19:04 -05001730struct GPOS_accelerator_t : GPOS::accelerator_t {};
1731
1732
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001733/* Out-of-class implementation for methods recursing */
1734
Behdad Esfahbodc6fb8432012-11-23 18:04:08 -05001735template <typename context_t>
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -07001736/*static*/ inline typename context_t::return_t PosLookup::dispatch_recurse_func (context_t *c, unsigned int lookup_index)
Behdad Esfahbodc6fb8432012-11-23 18:04:08 -05001737{
Behdad Esfahbod33b006c2018-11-05 23:19:04 -05001738 const PosLookup &l = c->face->table.GPOS.get_relaxed ()->table->get_lookup (lookup_index);
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05001739 return l.dispatch (c);
Behdad Esfahbodc6fb8432012-11-23 18:04:08 -05001740}
1741
Behdad Esfahbodfd034492018-01-17 16:46:51 -08001742/*static*/ inline bool PosLookup::apply_recurse_func (hb_ot_apply_context_t *c, unsigned int lookup_index)
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001743{
Behdad Esfahbod33b006c2018-11-05 23:19:04 -05001744 const PosLookup &l = c->face->table.GPOS.get_relaxed ()->table->get_lookup (lookup_index);
Behdad Esfahbod4c4e8f02012-11-24 01:13:20 -05001745 unsigned int saved_lookup_props = c->lookup_props;
Behdad Esfahbod2c8b3b22015-08-18 14:36:43 +01001746 unsigned int saved_lookup_index = c->lookup_index;
1747 c->set_lookup_index (lookup_index);
1748 c->set_lookup_props (l.get_props ());
Behdad Esfahbod1a232212015-02-19 10:40:23 +03001749 bool ret = l.dispatch (c);
Behdad Esfahbod2c8b3b22015-08-18 14:36:43 +01001750 c->set_lookup_index (saved_lookup_index);
Behdad Esfahbod77889932015-01-28 23:01:12 -08001751 c->set_lookup_props (saved_lookup_props);
Behdad Esfahbod4c4e8f02012-11-24 01:13:20 -05001752 return ret;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001753}
1754
1755
Behdad Esfahbod7d52e662012-11-16 18:49:54 -08001756} /* namespace OT */
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -04001757
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -04001758
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +02001759#endif /* HB_OT_LAYOUT_GPOS_TABLE_HH */