blob: 8c83cf28ca32cb2d911f079ba05de19ac67ca7bc [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 Esfahbod5f5b24f2009-08-02 20:03:12 -040032#include "hb-ot-layout-gsubgpos-private.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 Esfahbod0f6278d2016-02-11 14:49:10 +070039#define attach_chain() var.i16[0] /* glyph to which this attaches to, relative to current glyphs; negative for going back. */
40#define cursive_chain() var.i16[1] /* glyph to which this connects, may be positive or negative */
Behdad Esfahbod194d4562010-10-27 23:09:10 -040041
42
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040043/* Shared Tables: ValueRecord, Anchor Table, and MarkArray */
44
Behdad Esfahbodc2ddfd22010-05-06 13:06:15 -040045typedef USHORT Value;
Behdad Esfahbodc91facd2009-08-26 18:53:43 -040046
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -040047typedef Value ValueRecord[VAR];
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040048
Behdad Esfahbodfca6a0d2009-05-21 04:49:04 -040049struct ValueFormat : USHORT
50{
Behdad Esfahbodc6035cf2012-04-12 13:23:59 -040051 enum Flags {
Behdad Esfahbod76271002014-07-11 14:54:42 -040052 xPlacement = 0x0001u, /* Includes horizontal adjustment for placement */
53 yPlacement = 0x0002u, /* Includes vertical adjustment for placement */
54 xAdvance = 0x0004u, /* Includes horizontal adjustment for advance */
55 yAdvance = 0x0008u, /* Includes vertical adjustment for advance */
56 xPlaDevice = 0x0010u, /* Includes horizontal Device table for placement */
57 yPlaDevice = 0x0020u, /* Includes vertical Device table for placement */
58 xAdvDevice = 0x0040u, /* Includes horizontal Device table for advance */
59 yAdvDevice = 0x0080u, /* Includes vertical Device table for advance */
60 ignored = 0x0F00u, /* Was used in TrueType Open for MM fonts */
61 reserved = 0xF000u, /* For future use */
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -040062
Behdad Esfahbod76271002014-07-11 14:54:42 -040063 devices = 0x00F0u /* Mask for having any Device table */
Behdad Esfahbodfca6a0d2009-05-21 04:49:04 -040064 };
65
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -040066/* All fields are options. Only those available advance the value pointer. */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040067#if 0
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040068 SHORT xPlacement; /* Horizontal adjustment for
69 * placement--in design units */
70 SHORT yPlacement; /* Vertical adjustment for
71 * placement--in design units */
72 SHORT xAdvance; /* Horizontal adjustment for
73 * advance--in design units (only used
74 * for horizontal writing) */
75 SHORT yAdvance; /* Vertical adjustment for advance--in
76 * design units (only used for vertical
77 * writing) */
78 Offset xPlaDevice; /* Offset to Device table for
79 * horizontal placement--measured from
80 * beginning of PosTable (may be NULL) */
81 Offset yPlaDevice; /* Offset to Device table for vertical
82 * placement--measured from beginning
83 * of PosTable (may be NULL) */
84 Offset xAdvDevice; /* Offset to Device table for
85 * horizontal advance--measured from
86 * beginning of PosTable (may be NULL) */
87 Offset yAdvDevice; /* Offset to Device table for vertical
88 * advance--measured from beginning of
89 * PosTable (may be NULL) */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -040090#endif
91
Behdad Esfahbod7f97d2c2010-10-01 18:58:50 -040092 inline unsigned int get_len (void) const
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -040093 { return _hb_popcount32 ((unsigned int) *this); }
Behdad Esfahbod7f97d2c2010-10-01 18:58:50 -040094 inline unsigned int get_size (void) const
Behdad Esfahbode45d3f82010-05-06 19:33:31 -040095 { return get_len () * Value::static_size; }
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -040096
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -040097 void apply_value (hb_font_t *font,
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -040098 hb_direction_t direction,
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -040099 const void *base,
100 const Value *values,
101 hb_glyph_position_t &glyph_pos) const
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400102 {
103 unsigned int x_ppem, y_ppem;
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400104 unsigned int format = *this;
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400105 hb_bool_t horizontal = HB_DIRECTION_IS_HORIZONTAL (direction);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400106
107 if (!format) return;
108
Behdad Esfahbodb6f902a2011-05-11 00:04:15 -0400109 if (format & xPlacement) glyph_pos.x_offset += font->em_scale_x (get_short (values++));
110 if (format & yPlacement) glyph_pos.y_offset += font->em_scale_y (get_short (values++));
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400111 if (format & xAdvance) {
Konstantin Ritt08322592014-01-22 20:31:30 +0200112 if (likely (horizontal)) glyph_pos.x_advance += font->em_scale_x (get_short (values));
113 values++;
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400114 }
Behdad Esfahbodcc2086d2011-05-19 19:19:50 -0400115 /* y_advance values grow downward but font-space grows upward, hence negation */
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400116 if (format & yAdvance) {
Konstantin Ritt08322592014-01-22 20:31:30 +0200117 if (unlikely (!horizontal)) glyph_pos.y_advance -= font->em_scale_y (get_short (values));
118 values++;
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400119 }
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400120
Behdad Esfahboda8d960b2010-04-29 14:31:56 -0400121 if (!has_device ()) return;
122
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400123 x_ppem = font->x_ppem;
124 y_ppem = font->y_ppem;
Behdad Esfahboda8d960b2010-04-29 14:31:56 -0400125
126 if (!x_ppem && !y_ppem) return;
127
Behdad Esfahbod0090dc02009-07-30 16:28:45 -0400128 /* pixel -> fractional pixel */
129 if (format & xPlaDevice) {
Konstantin Ritt08322592014-01-22 20:31:30 +0200130 if (x_ppem) glyph_pos.x_offset += (base + get_device (values)).get_x_delta (font);
131 values++;
Behdad Esfahbod0090dc02009-07-30 16:28:45 -0400132 }
133 if (format & yPlaDevice) {
Konstantin Ritt08322592014-01-22 20:31:30 +0200134 if (y_ppem) glyph_pos.y_offset += (base + get_device (values)).get_y_delta (font);
135 values++;
Behdad Esfahbod0090dc02009-07-30 16:28:45 -0400136 }
137 if (format & xAdvDevice) {
Konstantin Ritt08322592014-01-22 20:31:30 +0200138 if (horizontal && x_ppem) glyph_pos.x_advance += (base + get_device (values)).get_x_delta (font);
139 values++;
Behdad Esfahbod0090dc02009-07-30 16:28:45 -0400140 }
141 if (format & yAdvDevice) {
Behdad Esfahbodcc2086d2011-05-19 19:19:50 -0400142 /* y_advance values grow downward but font-space grows upward, hence negation */
Konstantin Ritt08322592014-01-22 20:31:30 +0200143 if (!horizontal && y_ppem) glyph_pos.y_advance -= (base + get_device (values)).get_y_delta (font);
144 values++;
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400145 }
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400146 }
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400147
148 private:
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300149 inline bool sanitize_value_devices (hb_sanitize_context_t *c, const void *base, const Value *values) const
150 {
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400151 unsigned int format = *this;
152
153 if (format & xPlacement) values++;
154 if (format & yPlacement) values++;
155 if (format & xAdvance) values++;
156 if (format & yAdvance) values++;
157
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400158 if ((format & xPlaDevice) && !get_device (values++).sanitize (c, base)) return false;
159 if ((format & yPlaDevice) && !get_device (values++).sanitize (c, base)) return false;
160 if ((format & xAdvDevice) && !get_device (values++).sanitize (c, base)) return false;
161 if ((format & yAdvDevice) && !get_device (values++).sanitize (c, base)) return false;
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400162
163 return true;
164 }
165
Behdad Esfahbodc2ddfd22010-05-06 13:06:15 -0400166 static inline OffsetTo<Device>& get_device (Value* value)
167 { return *CastP<OffsetTo<Device> > (value); }
168 static inline const OffsetTo<Device>& get_device (const Value* value)
169 { return *CastP<OffsetTo<Device> > (value); }
170
171 static inline const SHORT& get_short (const Value* value)
172 { return *CastP<SHORT> (value); }
173
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400174 public:
175
Behdad Esfahbod7f97d2c2010-10-01 18:58:50 -0400176 inline bool has_device (void) const {
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400177 unsigned int format = *this;
178 return (format & devices) != 0;
179 }
180
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300181 inline bool sanitize_value (hb_sanitize_context_t *c, const void *base, const Value *values) const
182 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500183 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100184 return_trace (c->check_range (values, get_size ()) && (!has_device () || sanitize_value_devices (c, base, values)));
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400185 }
186
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300187 inline bool sanitize_values (hb_sanitize_context_t *c, const void *base, const Value *values, unsigned int count) const
188 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500189 TRACE_SANITIZE (this);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400190 unsigned int len = get_len ();
191
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100192 if (!c->check_array (values, get_size (), count)) return_trace (false);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400193
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100194 if (!has_device ()) return_trace (true);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400195
196 for (unsigned int i = 0; i < count; i++) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400197 if (!sanitize_value_devices (c, base, values))
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100198 return_trace (false);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400199 values += len;
200 }
201
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100202 return_trace (true);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400203 }
204
Behdad Esfahbod278a91f2010-04-22 13:59:39 -0400205 /* Just sanitize referenced Device tables. Doesn't check the values themselves. */
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300206 inline bool sanitize_values_stride_unsafe (hb_sanitize_context_t *c, const void *base, const Value *values, unsigned int count, unsigned int stride) const
207 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500208 TRACE_SANITIZE (this);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400209
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100210 if (!has_device ()) return_trace (true);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400211
212 for (unsigned int i = 0; i < count; i++) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400213 if (!sanitize_value_devices (c, base, values))
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100214 return_trace (false);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400215 values += stride;
216 }
217
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100218 return_trace (true);
Behdad Esfahbod673a4ef2010-04-21 02:02:57 -0400219 }
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400220};
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400221
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400222
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400223struct AnchorFormat1
224{
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400225 inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id HB_UNUSED,
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400226 hb_position_t *x, hb_position_t *y) const
227 {
Behdad Esfahbodb6f902a2011-05-11 00:04:15 -0400228 *x = font->em_scale_x (xCoordinate);
229 *y = font->em_scale_y (yCoordinate);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400230 }
231
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300232 inline bool sanitize (hb_sanitize_context_t *c) const
233 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500234 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100235 return_trace (c->check_struct (this));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400236 }
237
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400238 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400239 USHORT format; /* Format identifier--format = 1 */
240 SHORT xCoordinate; /* Horizontal value--in design units */
241 SHORT yCoordinate; /* Vertical value--in design units */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400242 public:
243 DEFINE_SIZE_STATIC (6);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400244};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400245
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400246struct AnchorFormat2
247{
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400248 inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id,
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400249 hb_position_t *x, hb_position_t *y) const
250 {
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400251 unsigned int x_ppem = font->x_ppem;
252 unsigned int y_ppem = font->y_ppem;
Behdad Esfahbod6f729b42010-04-29 03:59:06 -0400253 hb_position_t cx, cy;
Konstantin Ritt08322592014-01-22 20:31:30 +0200254 hb_bool_t ret;
Behdad Esfahbod6f729b42010-04-29 03:59:06 -0400255
Konstantin Ritt08322592014-01-22 20:31:30 +0200256 ret = (x_ppem || y_ppem) &&
257 font->get_glyph_contour_point_for_origin (glyph_id, anchorPoint, HB_DIRECTION_LTR, &cx, &cy);
258 *x = ret && x_ppem ? cx : font->em_scale_x (xCoordinate);
259 *y = ret && y_ppem ? cy : font->em_scale_y (yCoordinate);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400260 }
261
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300262 inline bool sanitize (hb_sanitize_context_t *c) const
263 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500264 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100265 return_trace (c->check_struct (this));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400266 }
267
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400268 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400269 USHORT format; /* Format identifier--format = 2 */
270 SHORT xCoordinate; /* Horizontal value--in design units */
271 SHORT yCoordinate; /* Vertical value--in design units */
272 USHORT anchorPoint; /* Index to glyph contour point */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400273 public:
274 DEFINE_SIZE_STATIC (8);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400275};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400276
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400277struct AnchorFormat3
278{
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400279 inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id HB_UNUSED,
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400280 hb_position_t *x, hb_position_t *y) const
281 {
Behdad Esfahbodb6f902a2011-05-11 00:04:15 -0400282 *x = font->em_scale_x (xCoordinate);
283 *y = font->em_scale_y (yCoordinate);
Behdad Esfahbodc18ec2b2009-05-21 04:54:01 -0400284
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400285 if (font->x_ppem)
286 *x += (this+xDeviceTable).get_x_delta (font);
287 if (font->y_ppem)
288 *y += (this+yDeviceTable).get_x_delta (font);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400289 }
290
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300291 inline bool sanitize (hb_sanitize_context_t *c) const
292 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500293 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100294 return_trace (c->check_struct (this) && xDeviceTable.sanitize (c, this) && yDeviceTable.sanitize (c, this));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400295 }
296
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400297 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400298 USHORT format; /* Format identifier--format = 3 */
299 SHORT xCoordinate; /* Horizontal value--in design units */
300 SHORT yCoordinate; /* Vertical value--in design units */
301 OffsetTo<Device>
302 xDeviceTable; /* Offset to Device table for X
303 * coordinate-- from beginning of
304 * Anchor table (may be NULL) */
305 OffsetTo<Device>
306 yDeviceTable; /* Offset to Device table for Y
307 * coordinate-- from beginning of
308 * Anchor table (may be NULL) */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400309 public:
310 DEFINE_SIZE_STATIC (10);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400311};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400312
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400313struct Anchor
314{
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400315 inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id,
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400316 hb_position_t *x, hb_position_t *y) const
317 {
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400318 *x = *y = 0;
319 switch (u.format) {
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400320 case 1: u.format1.get_anchor (font, glyph_id, x, y); return;
321 case 2: u.format2.get_anchor (font, glyph_id, x, y); return;
322 case 3: u.format3.get_anchor (font, glyph_id, x, y); return;
323 default: return;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400324 }
325 }
326
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300327 inline bool sanitize (hb_sanitize_context_t *c) const
328 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500329 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100330 if (!u.format.sanitize (c)) return_trace (false);
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400331 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100332 case 1: return_trace (u.format1.sanitize (c));
333 case 2: return_trace (u.format2.sanitize (c));
334 case 3: return_trace (u.format3.sanitize (c));
335 default:return_trace (true);
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400336 }
337 }
338
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400339 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400340 union {
341 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400342 AnchorFormat1 format1;
343 AnchorFormat2 format2;
344 AnchorFormat3 format3;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400345 } u;
Behdad Esfahboded074222010-05-10 18:08:46 -0400346 public:
Behdad Esfahbod596e4712010-05-10 18:47:48 -0400347 DEFINE_SIZE_UNION (2, format);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400348};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400349
350
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400351struct AnchorMatrix
352{
Behdad Esfahbode95e0312013-01-08 16:15:46 -0600353 inline const Anchor& get_anchor (unsigned int row, unsigned int col, unsigned int cols, bool *found) const {
354 *found = false;
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400355 if (unlikely (row >= rows || col >= cols)) return Null(Anchor);
Behdad Esfahbod093c5202014-12-12 21:07:53 -0800356 *found = !matrixZ[row * cols + col].is_null ();
357 return this+matrixZ[row * cols + col];
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400358 }
359
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300360 inline bool sanitize (hb_sanitize_context_t *c, unsigned int cols) const
361 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500362 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100363 if (!c->check_struct (this)) return_trace (false);
364 if (unlikely (rows > 0 && cols >= ((unsigned int) -1) / rows)) return_trace (false);
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400365 unsigned int count = rows * cols;
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100366 if (!c->check_array (matrixZ, matrixZ[0].static_size, count)) return_trace (false);
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400367 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100368 if (!matrixZ[i].sanitize (c, this)) return_trace (false);
369 return_trace (true);
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400370 }
371
372 USHORT rows; /* Number of rows */
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400373 protected:
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400374 OffsetTo<Anchor>
Behdad Esfahbod093c5202014-12-12 21:07:53 -0800375 matrixZ[VAR]; /* Matrix of offsets to Anchor tables--
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400376 * from beginning of AnchorMatrix table */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400377 public:
Behdad Esfahbod093c5202014-12-12 21:07:53 -0800378 DEFINE_SIZE_ARRAY (2, matrixZ);
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400379};
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -0400380
381
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400382struct MarkRecord
383{
Behdad Esfahbod377bfc52009-05-21 04:58:24 -0400384 friend struct MarkArray;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400385
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300386 inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
387 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500388 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100389 return_trace (c->check_struct (this) && markAnchor.sanitize (c, base));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400390 }
391
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400392 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400393 USHORT klass; /* Class defined for this mark */
394 OffsetTo<Anchor>
395 markAnchor; /* Offset to Anchor table--from
396 * beginning of MarkArray table */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400397 public:
398 DEFINE_SIZE_STATIC (4);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400399};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400400
Behdad Esfahbodbea34c72010-05-10 17:28:16 -0400401struct MarkArray : ArrayOf<MarkRecord> /* Array of MarkRecords--in Coverage order */
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400402{
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400403 inline bool apply (hb_apply_context_t *c,
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400404 unsigned int mark_index, unsigned int glyph_index,
405 const AnchorMatrix &anchors, unsigned int class_count,
406 unsigned int glyph_pos) const
407 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500408 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200409 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbodbea34c72010-05-10 17:28:16 -0400410 const MarkRecord &record = ArrayOf<MarkRecord>::operator[](mark_index);
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400411 unsigned int mark_class = record.klass;
412
413 const Anchor& mark_anchor = this + record.markAnchor;
Behdad Esfahbode95e0312013-01-08 16:15:46 -0600414 bool found;
415 const Anchor& glyph_anchor = anchors.get_anchor (glyph_index, mark_class, class_count, &found);
416 /* If this subtable doesn't have an anchor for this base and this class,
417 * return false such that the subsequent subtables have a chance at it. */
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100418 if (unlikely (!found)) return_trace (false);
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400419
420 hb_position_t mark_x, mark_y, base_x, base_y;
421
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200422 mark_anchor.get_anchor (c->font, buffer->cur().codepoint, &mark_x, &mark_y);
423 glyph_anchor.get_anchor (c->font, buffer->info[glyph_pos].codepoint, &base_x, &base_y);
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400424
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200425 hb_glyph_position_t &o = buffer->cur_pos();
Behdad Esfahbod194d4562010-10-27 23:09:10 -0400426 o.x_offset = base_x - mark_x;
427 o.y_offset = base_y - mark_y;
Behdad Esfahbod0f6278d2016-02-11 14:49:10 +0700428 o.attach_chain() = (int) glyph_pos - (int) buffer->idx;
Behdad Esfahbod550bd142015-11-04 22:58:58 -0800429 buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT;
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400430
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200431 buffer->idx++;
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100432 return_trace (true);
Behdad Esfahbodb41f2102009-08-14 19:33:24 -0400433 }
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400434
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300435 inline bool sanitize (hb_sanitize_context_t *c) const
436 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500437 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100438 return_trace (ArrayOf<MarkRecord>::sanitize (c, this));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400439 }
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400440};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400441
442
443/* Lookups */
444
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400445struct SinglePosFormat1
446{
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500447 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
448 {
449 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod83035932012-12-04 17:08:41 -0500450 (this+coverage).add_coverage (c->input);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500451 }
452
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400453 inline const Coverage &get_coverage (void) const
454 {
455 return this+coverage;
456 }
457
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400458 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400459 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500460 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200461 hb_buffer_t *buffer = c->buffer;
462 unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100463 if (likely (index == NOT_COVERED)) return_trace (false);
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400464
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400465 valueFormat.apply_value (c->font, c->direction, this,
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200466 values, buffer->cur_pos());
Behdad Esfahbodf53d4342009-05-30 22:17:32 -0400467
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200468 buffer->idx++;
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100469 return_trace (true);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400470 }
471
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300472 inline bool sanitize (hb_sanitize_context_t *c) const
473 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500474 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100475 return_trace (c->check_struct (this) &&
476 coverage.sanitize (c, this) &&
477 valueFormat.sanitize_value (c, this, values));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400478 }
479
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400480 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400481 USHORT format; /* Format identifier--format = 1 */
482 OffsetTo<Coverage>
483 coverage; /* Offset to Coverage table--from
484 * beginning of subtable */
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400485 ValueFormat valueFormat; /* Defines the types of data in the
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400486 * ValueRecord */
487 ValueRecord values; /* Defines positioning
488 * value(s)--applied to all glyphs in
489 * the Coverage table */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400490 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400491 DEFINE_SIZE_ARRAY (6, values);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400492};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400493
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400494struct SinglePosFormat2
495{
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500496 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
497 {
498 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod83035932012-12-04 17:08:41 -0500499 (this+coverage).add_coverage (c->input);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500500 }
501
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400502 inline const Coverage &get_coverage (void) const
503 {
504 return this+coverage;
505 }
506
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400507 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400508 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500509 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200510 hb_buffer_t *buffer = c->buffer;
511 unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100512 if (likely (index == NOT_COVERED)) return_trace (false);
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400513
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100514 if (likely (index >= valueCount)) return_trace (false);
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400515
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400516 valueFormat.apply_value (c->font, c->direction, this,
Behdad Esfahbod4b8487d2010-03-16 03:46:17 -0400517 &values[index * valueFormat.get_len ()],
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200518 buffer->cur_pos());
Behdad Esfahbodf53d4342009-05-30 22:17:32 -0400519
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200520 buffer->idx++;
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100521 return_trace (true);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400522 }
523
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300524 inline bool sanitize (hb_sanitize_context_t *c) const
525 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500526 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100527 return_trace (c->check_struct (this) &&
528 coverage.sanitize (c, this) &&
529 valueFormat.sanitize_values (c, this, values, valueCount));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400530 }
531
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400532 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400533 USHORT format; /* Format identifier--format = 2 */
534 OffsetTo<Coverage>
535 coverage; /* Offset to Coverage table--from
536 * beginning of subtable */
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400537 ValueFormat valueFormat; /* Defines the types of data in the
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400538 * ValueRecord */
539 USHORT valueCount; /* Number of ValueRecords */
540 ValueRecord values; /* Array of ValueRecords--positioning
541 * values applied to glyphs */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400542 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400543 DEFINE_SIZE_ARRAY (8, values);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400544};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400545
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400546struct SinglePos
547{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -0500548 template <typename context_t>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -0500549 inline typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400550 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -0800551 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -0400552 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400553 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100554 case 1: return_trace (c->dispatch (u.format1));
555 case 2: return_trace (c->dispatch (u.format2));
556 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400557 }
558 }
559
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400560 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400561 union {
562 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400563 SinglePosFormat1 format1;
564 SinglePosFormat2 format2;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400565 } u;
566};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400567
568
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400569struct PairValueRecord
570{
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400571 friend struct PairSet;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400572
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400573 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400574 GlyphID secondGlyph; /* GlyphID of second glyph in the
575 * pair--first glyph is listed in the
576 * Coverage table */
577 ValueRecord values; /* Positioning data for the first glyph
578 * followed by for second glyph */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400579 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400580 DEFINE_SIZE_ARRAY (2, values);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400581};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400582
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400583struct PairSet
584{
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400585 friend struct PairPosFormat1;
586
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500587 inline void collect_glyphs (hb_collect_glyphs_context_t *c,
588 const ValueFormat *valueFormats) const
589 {
590 TRACE_COLLECT_GLYPHS (this);
591 unsigned int len1 = valueFormats[0].get_len ();
592 unsigned int len2 = valueFormats[1].get_len ();
593 unsigned int record_size = USHORT::static_size * (1 + len1 + len2);
594
Behdad Esfahbod093c5202014-12-12 21:07:53 -0800595 const PairValueRecord *record = CastP<PairValueRecord> (arrayZ);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500596 unsigned int count = len;
597 for (unsigned int i = 0; i < count; i++)
598 {
Behdad Esfahbod83035932012-12-04 17:08:41 -0500599 c->input->add (record->secondGlyph);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500600 record = &StructAtOffset<PairValueRecord> (record, record_size);
601 }
602 }
603
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400604 inline bool apply (hb_apply_context_t *c,
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400605 const ValueFormat *valueFormats,
606 unsigned int pos) const
607 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500608 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200609 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400610 unsigned int len1 = valueFormats[0].get_len ();
611 unsigned int len2 = valueFormats[1].get_len ();
612 unsigned int record_size = USHORT::static_size * (1 + len1 + len2);
613
Behdad Esfahbod67dfa8c2015-01-19 17:00:31 -0800614 const PairValueRecord *record_array = CastP<PairValueRecord> (arrayZ);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500615 unsigned int count = len;
Behdad Esfahbod67dfa8c2015-01-19 17:00:31 -0800616
617 /* Hand-coded bsearch. */
618 if (unlikely (!count))
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100619 return_trace (false);
Behdad Esfahbod67dfa8c2015-01-19 17:00:31 -0800620 hb_codepoint_t x = buffer->info[pos].codepoint;
621 int min = 0, max = (int) count - 1;
622 while (min <= max)
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400623 {
Behdad Esfahbod67dfa8c2015-01-19 17:00:31 -0800624 int mid = (min + max) / 2;
625 const PairValueRecord *record = &StructAtOffset<PairValueRecord> (record_array, record_size * mid);
626 hb_codepoint_t mid_x = record->secondGlyph;
627 if (x < mid_x)
628 max = mid - 1;
629 else if (x > mid_x)
630 min = mid + 1;
631 else
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400632 {
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400633 valueFormats[0].apply_value (c->font, c->direction, this,
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200634 &record->values[0], buffer->cur_pos());
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400635 valueFormats[1].apply_value (c->font, c->direction, this,
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200636 &record->values[len1], buffer->pos[pos]);
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400637 if (len2)
638 pos++;
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200639 buffer->idx = pos;
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100640 return_trace (true);
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400641 }
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400642 }
643
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100644 return_trace (false);
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400645 }
646
647 struct sanitize_closure_t {
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300648 const void *base;
649 const ValueFormat *valueFormats;
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400650 unsigned int len1; /* valueFormats[0].get_len() */
651 unsigned int stride; /* 1 + len1 + len2 */
652 };
653
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300654 inline bool sanitize (hb_sanitize_context_t *c, const sanitize_closure_t *closure) const
655 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500656 TRACE_SANITIZE (this);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400657 if (!(c->check_struct (this)
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100658 && c->check_array (arrayZ, USHORT::static_size * closure->stride, len))) return_trace (false);
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400659
660 unsigned int count = len;
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300661 const PairValueRecord *record = CastP<PairValueRecord> (arrayZ);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100662 return_trace (closure->valueFormats[0].sanitize_values_stride_unsafe (c, closure->base, &record->values[0], count, closure->stride) &&
663 closure->valueFormats[1].sanitize_values_stride_unsafe (c, closure->base, &record->values[closure->len1], count, closure->stride));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400664 }
665
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400666 protected:
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400667 USHORT len; /* Number of PairValueRecords */
Behdad Esfahbod093c5202014-12-12 21:07:53 -0800668 USHORT arrayZ[VAR]; /* Array of PairValueRecords--ordered
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400669 * by GlyphID of the second glyph */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400670 public:
Behdad Esfahbod093c5202014-12-12 21:07:53 -0800671 DEFINE_SIZE_ARRAY (2, arrayZ);
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400672};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400673
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400674struct PairPosFormat1
675{
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500676 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
677 {
678 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod83035932012-12-04 17:08:41 -0500679 (this+coverage).add_coverage (c->input);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500680 unsigned int count = pairSet.len;
681 for (unsigned int i = 0; i < count; i++)
682 (this+pairSet[i]).collect_glyphs (c, &valueFormat1);
683 }
684
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400685 inline const Coverage &get_coverage (void) const
686 {
687 return this+coverage;
688 }
689
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400690 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400691 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500692 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200693 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200694 unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100695 if (likely (index == NOT_COVERED)) return_trace (false);
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400696
Behdad Esfahbod365576d2015-01-29 13:59:42 +0100697 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +0100698 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100699 if (!skippy_iter.next ()) return_trace (false);
Behdad Esfahbodb24ecba2009-05-19 22:16:04 -0400700
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100701 return_trace ((this+pairSet[index]).apply (c, &valueFormat1, skippy_iter.idx));
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400702 }
703
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300704 inline bool sanitize (hb_sanitize_context_t *c) const
705 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500706 TRACE_SANITIZE (this);
Behdad Esfahbodeba8b4f2010-03-29 00:04:12 -0400707
Behdad Esfahbodf9666492015-10-13 00:30:50 -0400708 if (!c->check_struct (this)) return_trace (false);
709
Behdad Esfahbodeba8b4f2010-03-29 00:04:12 -0400710 unsigned int len1 = valueFormat1.get_len ();
711 unsigned int len2 = valueFormat2.get_len ();
Behdad Esfahbod70c9bfd2010-05-11 00:23:50 -0400712 PairSet::sanitize_closure_t closure = {
713 this,
714 &valueFormat1,
715 len1,
716 1 + len1 + len2
717 };
Behdad Esfahbodeba8b4f2010-03-29 00:04:12 -0400718
Behdad Esfahbodf9666492015-10-13 00:30:50 -0400719 return_trace (coverage.sanitize (c, this) && pairSet.sanitize (c, this, &closure));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400720 }
721
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400722 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400723 USHORT format; /* Format identifier--format = 1 */
724 OffsetTo<Coverage>
725 coverage; /* Offset to Coverage table--from
726 * beginning of subtable */
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400727 ValueFormat valueFormat1; /* Defines the types of data in
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400728 * ValueRecord1--for the first glyph
729 * in the pair--may be zero (0) */
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400730 ValueFormat valueFormat2; /* Defines the types of data in
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400731 * ValueRecord2--for the second glyph
732 * in the pair--may be zero (0) */
733 OffsetArrayOf<PairSet>
734 pairSet; /* Array of PairSet tables
735 * ordered by Coverage Index */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400736 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400737 DEFINE_SIZE_ARRAY (10, pairSet);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400738};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400739
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400740struct PairPosFormat2
741{
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500742 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
743 {
744 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbodfc38e602015-12-23 14:50:53 +0100745 (this+coverage).add_coverage (c->input);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500746
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500747 unsigned int count1 = class1Count;
748 const ClassDef &klass1 = this+classDef1;
749 for (unsigned int i = 0; i < count1; i++)
Behdad Esfahbod83035932012-12-04 17:08:41 -0500750 klass1.add_class (c->input, i);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500751
752 unsigned int count2 = class2Count;
753 const ClassDef &klass2 = this+classDef2;
754 for (unsigned int i = 0; i < count2; i++)
Behdad Esfahbod83035932012-12-04 17:08:41 -0500755 klass2.add_class (c->input, i);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500756 }
757
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400758 inline const Coverage &get_coverage (void) const
759 {
760 return this+coverage;
761 }
762
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400763 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400764 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500765 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200766 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200767 unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100768 if (likely (index == NOT_COVERED)) return_trace (false);
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400769
Behdad Esfahbod365576d2015-01-29 13:59:42 +0100770 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +0100771 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100772 if (!skippy_iter.next ()) return_trace (false);
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400773
774 unsigned int len1 = valueFormat1.get_len ();
775 unsigned int len2 = valueFormat2.get_len ();
776 unsigned int record_len = len1 + len2;
777
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200778 unsigned int klass1 = (this+classDef1).get_class (buffer->cur().codepoint);
779 unsigned int klass2 = (this+classDef2).get_class (buffer->info[skippy_iter.idx].codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100780 if (unlikely (klass1 >= class1Count || klass2 >= class2Count)) return_trace (false);
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400781
Behdad Esfahbod4b8487d2010-03-16 03:46:17 -0400782 const Value *v = &values[record_len * (klass1 * class2Count + klass2)];
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400783 valueFormat1.apply_value (c->font, c->direction, this,
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200784 v, buffer->cur_pos());
Behdad Esfahbod3b0bb852011-05-20 15:59:59 -0400785 valueFormat2.apply_value (c->font, c->direction, this,
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200786 v + len1, buffer->pos[skippy_iter.idx]);
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400787
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200788 buffer->idx = skippy_iter.idx;
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400789 if (len2)
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200790 buffer->idx++;
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400791
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100792 return_trace (true);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400793 }
794
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300795 inline bool sanitize (hb_sanitize_context_t *c) const
796 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500797 TRACE_SANITIZE (this);
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400798 if (!(c->check_struct (this)
799 && coverage.sanitize (c, this)
800 && classDef1.sanitize (c, this)
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100801 && classDef2.sanitize (c, this))) return_trace (false);
Behdad Esfahbod815a73e2009-08-14 17:31:16 -0400802
Behdad Esfahbodeba8b4f2010-03-29 00:04:12 -0400803 unsigned int len1 = valueFormat1.get_len ();
804 unsigned int len2 = valueFormat2.get_len ();
805 unsigned int stride = len1 + len2;
Behdad Esfahbod4b8487d2010-03-16 03:46:17 -0400806 unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size ();
Behdad Esfahbodeba8b4f2010-03-29 00:04:12 -0400807 unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count;
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100808 return_trace (c->check_array (values, record_size, count) &&
809 valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) &&
810 valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400811 }
Behdad Esfahbod70632ad2009-05-19 22:30:09 -0400812
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400813 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400814 USHORT format; /* Format identifier--format = 2 */
815 OffsetTo<Coverage>
816 coverage; /* Offset to Coverage table--from
817 * beginning of subtable */
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400818 ValueFormat valueFormat1; /* ValueRecord definition--for the
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400819 * first glyph of the pair--may be zero
820 * (0) */
Behdad Esfahbod056c7ec2009-05-18 19:47:52 -0400821 ValueFormat valueFormat2; /* ValueRecord definition--for the
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400822 * second glyph of the pair--may be
823 * zero (0) */
824 OffsetTo<ClassDef>
825 classDef1; /* Offset to ClassDef table--from
826 * beginning of PairPos subtable--for
827 * the first glyph of the pair */
828 OffsetTo<ClassDef>
829 classDef2; /* Offset to ClassDef table--from
830 * beginning of PairPos subtable--for
831 * the second glyph of the pair */
832 USHORT class1Count; /* Number of classes in ClassDef1
833 * table--includes Class0 */
834 USHORT class2Count; /* Number of classes in ClassDef2
835 * table--includes Class0 */
836 ValueRecord values; /* Matrix of value pairs:
837 * class1-major, class2-minor,
838 * Each entry has value1 and value2 */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400839 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400840 DEFINE_SIZE_ARRAY (16, values);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400841};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400842
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400843struct PairPos
844{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -0500845 template <typename context_t>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -0500846 inline typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400847 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -0800848 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -0400849 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400850 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100851 case 1: return_trace (c->dispatch (u.format1));
852 case 2: return_trace (c->dispatch (u.format2));
853 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400854 }
855 }
856
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400857 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400858 union {
859 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400860 PairPosFormat1 format1;
861 PairPosFormat2 format2;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400862 } u;
863};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400864
865
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400866struct EntryExitRecord
867{
Behdad Esfahbod569da922010-05-10 16:38:32 -0400868 friend struct CursivePosFormat1;
869
Behdad Esfahbodde2118e2015-02-17 17:27:44 +0300870 inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
871 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500872 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100873 return_trace (entryAnchor.sanitize (c, base) && exitAnchor.sanitize (c, base));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -0400874 }
875
Behdad Esfahbodec8d2492012-07-24 15:40:37 -0400876 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400877 OffsetTo<Anchor>
878 entryAnchor; /* Offset to EntryAnchor table--from
879 * beginning of CursivePos
880 * subtable--may be NULL */
881 OffsetTo<Anchor>
882 exitAnchor; /* Offset to ExitAnchor table--from
883 * beginning of CursivePos
884 * subtable--may be NULL */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400885 public:
886 DEFINE_SIZE_STATIC (4);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400887};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -0400888
Behdad Esfahbod65785752015-08-25 20:24:59 +0100889static void
890reverse_cursive_minor_offset (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction, unsigned int new_parent);
891
Behdad Esfahbod4c44d832009-05-19 23:42:30 -0400892struct CursivePosFormat1
893{
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500894 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
895 {
896 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod83035932012-12-04 17:08:41 -0500897 (this+coverage).add_coverage (c->input);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -0500898 }
899
Behdad Esfahbod0b994292012-07-28 17:31:01 -0400900 inline const Coverage &get_coverage (void) const
901 {
902 return this+coverage;
903 }
904
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400905 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbodd18fd8e2009-05-19 23:25:41 -0400906 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -0500907 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200908 hb_buffer_t *buffer = c->buffer;
Behdad Esfahbod0f7e6b22009-05-20 04:16:35 -0400909
910 /* We don't handle mark glyphs here. */
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100911 if (unlikely (_hb_glyph_info_is_mark (&buffer->cur()))) return_trace (false);
Behdad Esfahbod0f7e6b22009-05-20 04:16:35 -0400912
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200913 const EntryExitRecord &this_record = entryExitRecord[(this+coverage).get_coverage (buffer->cur().codepoint)];
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100914 if (!this_record.exitAnchor) return_trace (false);
Behdad Esfahbodd18fd8e2009-05-19 23:25:41 -0400915
Behdad Esfahbod365576d2015-01-29 13:59:42 +0100916 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +0100917 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100918 if (!skippy_iter.next ()) return_trace (false);
Behdad Esfahbodd18fd8e2009-05-19 23:25:41 -0400919
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200920 const EntryExitRecord &next_record = entryExitRecord[(this+coverage).get_coverage (buffer->info[skippy_iter.idx].codepoint)];
Behdad Esfahbodb4715902015-09-29 14:57:02 +0100921 if (!next_record.entryAnchor) return_trace (false);
Behdad Esfahbodaf5d02a2010-10-27 11:54:26 -0400922
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200923 unsigned int i = buffer->idx;
Behdad Esfahbod4ab97312012-01-16 22:05:08 -0500924 unsigned int j = skippy_iter.idx;
Behdad Esfahbodaf5d02a2010-10-27 11:54:26 -0400925
926 hb_position_t entry_x, entry_y, exit_x, exit_y;
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200927 (this+this_record.exitAnchor).get_anchor (c->font, buffer->info[i].codepoint, &exit_x, &exit_y);
928 (this+next_record.entryAnchor).get_anchor (c->font, buffer->info[j].codepoint, &entry_x, &entry_y);
Behdad Esfahbodcc83ae12009-05-27 00:17:37 -0400929
Behdad Esfahbodac8cd512013-10-18 19:33:09 +0200930 hb_glyph_position_t *pos = buffer->pos;
Behdad Esfahbod7403e052011-05-24 21:04:15 -0400931
932 hb_position_t d;
933 /* Main-direction adjustment */
934 switch (c->direction) {
935 case HB_DIRECTION_LTR:
936 pos[i].x_advance = exit_x + pos[i].x_offset;
937
938 d = entry_x + pos[j].x_offset;
939 pos[j].x_advance -= d;
940 pos[j].x_offset -= d;
941 break;
942 case HB_DIRECTION_RTL:
943 d = exit_x + pos[i].x_offset;
944 pos[i].x_advance -= d;
945 pos[i].x_offset -= d;
946
947 pos[j].x_advance = entry_x + pos[j].x_offset;
948 break;
949 case HB_DIRECTION_TTB:
950 pos[i].y_advance = exit_y + pos[i].y_offset;
951
952 d = entry_y + pos[j].y_offset;
953 pos[j].y_advance -= d;
954 pos[j].y_offset -= d;
955 break;
956 case HB_DIRECTION_BTT:
957 d = exit_y + pos[i].y_offset;
958 pos[i].y_advance -= d;
959 pos[i].y_offset -= d;
960
961 pos[j].y_advance = entry_y;
962 break;
963 case HB_DIRECTION_INVALID:
964 default:
965 break;
Behdad Esfahbodd18fd8e2009-05-19 23:25:41 -0400966 }
967
Behdad Esfahbod7403e052011-05-24 21:04:15 -0400968 /* Cross-direction adjustment */
Behdad Esfahbod58f2a732015-08-25 18:55:34 +0100969
970 /* We attach child to parent (think graph theory and rooted trees whereas
971 * the root stays on baseline and each node aligns itself against its
972 * parent.
973 *
974 * Optimize things for the case of RightToLeft, as that's most common in
975 * Arabinc. */
976 unsigned int child = i;
977 unsigned int parent = j;
978 hb_position_t x_offset = entry_x - exit_x;
979 hb_position_t y_offset = entry_y - exit_y;
980 if (!(c->lookup_props & LookupFlag::RightToLeft))
981 {
982 unsigned int k = child;
983 child = parent;
984 parent = k;
985 x_offset = -x_offset;
986 y_offset = -y_offset;
Behdad Esfahbodd18fd8e2009-05-19 23:25:41 -0400987 }
988
Behdad Esfahbod65785752015-08-25 20:24:59 +0100989 /* If child was already connected to someone else, walk through its old
990 * chain and reverse the link direction, such that the whole tree of its
991 * previous connection now attaches to new parent. Watch out for case
992 * where new parent is on the path from old chain...
993 */
994 reverse_cursive_minor_offset (pos, child, c->direction, parent);
995
Behdad Esfahbod0f6278d2016-02-11 14:49:10 +0700996 pos[child].cursive_chain() = (int) parent - (int) child;
Behdad Esfahbod550bd142015-11-04 22:58:58 -0800997 buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_CURSIVE;
Behdad Esfahbod58f2a732015-08-25 18:55:34 +0100998 if (likely (HB_DIRECTION_IS_HORIZONTAL (c->direction)))
999 pos[child].y_offset = y_offset;
1000 else
1001 pos[child].x_offset = x_offset;
1002
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001003 buffer->idx = j;
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001004 return_trace (true);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001005 }
1006
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001007 inline bool sanitize (hb_sanitize_context_t *c) const
1008 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001009 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001010 return_trace (coverage.sanitize (c, this) && entryExitRecord.sanitize (c, this));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -04001011 }
1012
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001013 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001014 USHORT format; /* Format identifier--format = 1 */
1015 OffsetTo<Coverage>
1016 coverage; /* Offset to Coverage table--from
1017 * beginning of subtable */
1018 ArrayOf<EntryExitRecord>
1019 entryExitRecord; /* Array of EntryExit records--in
1020 * Coverage Index order */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001021 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -04001022 DEFINE_SIZE_ARRAY (6, entryExitRecord);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001023};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001024
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001025struct CursivePos
1026{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -05001027 template <typename context_t>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05001028 inline typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001029 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08001030 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -04001031 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001032 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001033 case 1: return_trace (c->dispatch (u.format1));
1034 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001035 }
1036 }
1037
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001038 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001039 union {
1040 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001041 CursivePosFormat1 format1;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001042 } u;
1043};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001044
1045
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -04001046typedef AnchorMatrix BaseArray; /* base-major--
1047 * in order of BaseCoverage Index--,
1048 * mark-minor--
Behdad Esfahbodfb3b5cc2009-05-21 04:47:05 -04001049 * ordered by class--zero-based. */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001050
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001051struct MarkBasePosFormat1
1052{
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001053 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1054 {
1055 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod83035932012-12-04 17:08:41 -05001056 (this+markCoverage).add_coverage (c->input);
1057 (this+baseCoverage).add_coverage (c->input);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001058 }
1059
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001060 inline const Coverage &get_coverage (void) const
1061 {
1062 return this+markCoverage;
1063 }
1064
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -04001065 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001066 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001067 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001068 hb_buffer_t *buffer = c->buffer;
1069 unsigned int mark_index = (this+markCoverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001070 if (likely (mark_index == NOT_COVERED)) return_trace (false);
Behdad Esfahbod357ccde2009-05-21 06:32:01 -04001071
1072 /* now we search backwards for a non-mark glyph */
Behdad Esfahbod365576d2015-01-29 13:59:42 +01001073 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +01001074 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodc074ebc2013-02-13 11:22:42 -05001075 skippy_iter.set_lookup_props (LookupFlag::IgnoreMarks);
Behdad Esfahbod7b84c532012-06-08 22:04:23 -04001076 do {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001077 if (!skippy_iter.prev ()) return_trace (false);
Behdad Esfahbod7b84c532012-06-08 22:04:23 -04001078 /* We only want to attach to the first of a MultipleSubst sequence. Reject others. */
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001079 if (0 == _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx])) break;
Behdad Esfahbod7b84c532012-06-08 22:04:23 -04001080 skippy_iter.reject ();
1081 } while (1);
Behdad Esfahbod0532ed12009-08-12 15:40:04 -04001082
Behdad Esfahbod101303d2013-10-18 00:42:39 +02001083 /* Checking that matched glyph is actually a base glyph by GDEF is too strong; disabled */
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001084 if (!_hb_glyph_info_is_base_glyph (&buffer->info[skippy_iter.idx])) { /*return_trace (false);*/ }
Behdad Esfahbod357ccde2009-05-21 06:32:01 -04001085
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001086 unsigned int base_index = (this+baseCoverage).get_coverage (buffer->info[skippy_iter.idx].codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001087 if (base_index == NOT_COVERED) return_trace (false);
Behdad Esfahbod357ccde2009-05-21 06:32:01 -04001088
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001089 return_trace ((this+markArray).apply (c, mark_index, base_index, this+baseArray, classCount, skippy_iter.idx));
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001090 }
1091
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001092 inline bool sanitize (hb_sanitize_context_t *c) const
1093 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001094 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001095 return_trace (c->check_struct (this) &&
1096 markCoverage.sanitize (c, this) &&
1097 baseCoverage.sanitize (c, this) &&
1098 markArray.sanitize (c, this) &&
1099 baseArray.sanitize (c, this, (unsigned int) classCount));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -04001100 }
1101
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001102 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001103 USHORT format; /* Format identifier--format = 1 */
Behdad Esfahbodfb3b5cc2009-05-21 04:47:05 -04001104 OffsetTo<Coverage>
1105 markCoverage; /* Offset to MarkCoverage table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001106 * beginning of MarkBasePos subtable */
Behdad Esfahbodfb3b5cc2009-05-21 04:47:05 -04001107 OffsetTo<Coverage>
1108 baseCoverage; /* Offset to BaseCoverage table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001109 * beginning of MarkBasePos subtable */
1110 USHORT classCount; /* Number of classes defined for marks */
Behdad Esfahbodfb3b5cc2009-05-21 04:47:05 -04001111 OffsetTo<MarkArray>
1112 markArray; /* Offset to MarkArray table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001113 * beginning of MarkBasePos subtable */
Behdad Esfahbodfb3b5cc2009-05-21 04:47:05 -04001114 OffsetTo<BaseArray>
1115 baseArray; /* Offset to BaseArray table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001116 * beginning of MarkBasePos subtable */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001117 public:
1118 DEFINE_SIZE_STATIC (12);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001119};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001120
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001121struct MarkBasePos
1122{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -05001123 template <typename context_t>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05001124 inline typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001125 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08001126 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -04001127 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001128 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001129 case 1: return_trace (c->dispatch (u.format1));
1130 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001131 }
1132 }
1133
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001134 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001135 union {
1136 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001137 MarkBasePosFormat1 format1;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001138 } u;
1139};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001140
1141
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -04001142typedef AnchorMatrix LigatureAttach; /* component-major--
1143 * in order of writing direction--,
1144 * mark-minor--
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001145 * ordered by class--zero-based. */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001146
Behdad Esfahbod3564ee52009-08-14 18:32:56 -04001147typedef OffsetListOf<LigatureAttach> LigatureArray;
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001148 /* Array of LigatureAttach
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001149 * tables ordered by
1150 * LigatureCoverage Index */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001151
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001152struct MarkLigPosFormat1
1153{
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001154 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1155 {
1156 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod83035932012-12-04 17:08:41 -05001157 (this+markCoverage).add_coverage (c->input);
1158 (this+ligatureCoverage).add_coverage (c->input);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001159 }
1160
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001161 inline const Coverage &get_coverage (void) const
1162 {
1163 return this+markCoverage;
1164 }
1165
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -04001166 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001167 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001168 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001169 hb_buffer_t *buffer = c->buffer;
1170 unsigned int mark_index = (this+markCoverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001171 if (likely (mark_index == NOT_COVERED)) return_trace (false);
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001172
1173 /* now we search backwards for a non-mark glyph */
Behdad Esfahbod365576d2015-01-29 13:59:42 +01001174 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +01001175 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodc074ebc2013-02-13 11:22:42 -05001176 skippy_iter.set_lookup_props (LookupFlag::IgnoreMarks);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001177 if (!skippy_iter.prev ()) return_trace (false);
Behdad Esfahbod0532ed12009-08-12 15:40:04 -04001178
Behdad Esfahbod101303d2013-10-18 00:42:39 +02001179 /* Checking that matched glyph is actually a ligature by GDEF is too strong; disabled */
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001180 if (!_hb_glyph_info_is_ligature (&buffer->info[skippy_iter.idx])) { /*return_trace (false);*/ }
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001181
Behdad Esfahbod4ab97312012-01-16 22:05:08 -05001182 unsigned int j = skippy_iter.idx;
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001183 unsigned int lig_index = (this+ligatureCoverage).get_coverage (buffer->info[j].codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001184 if (lig_index == NOT_COVERED) return_trace (false);
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001185
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001186 const LigatureArray& lig_array = this+ligatureArray;
Behdad Esfahbod3564ee52009-08-14 18:32:56 -04001187 const LigatureAttach& lig_attach = lig_array[lig_index];
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -04001188
1189 /* Find component to attach to */
Behdad Esfahbodb2b18ef2009-08-14 19:37:18 -04001190 unsigned int comp_count = lig_attach.rows;
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001191 if (unlikely (!comp_count)) return_trace (false);
Behdad Esfahbodacea1832012-05-11 02:33:11 +02001192
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001193 /* We must now check whether the ligature ID of the current mark glyph
1194 * is identical to the ligature ID of the found ligature. If yes, we
1195 * can directly use the component index. If not, we attach the mark
1196 * glyph to the last component of the ligature. */
Behdad Esfahbod0aef4252012-07-30 00:55:15 -04001197 unsigned int comp_index;
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001198 unsigned int lig_id = _hb_glyph_info_get_lig_id (&buffer->info[j]);
1199 unsigned int mark_id = _hb_glyph_info_get_lig_id (&buffer->cur());
1200 unsigned int mark_comp = _hb_glyph_info_get_lig_comp (&buffer->cur());
Behdad Esfahbod0aef4252012-07-30 00:55:15 -04001201 if (lig_id && lig_id == mark_id && mark_comp > 0)
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001202 comp_index = MIN (comp_count, _hb_glyph_info_get_lig_comp (&buffer->cur())) - 1;
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001203 else
Behdad Esfahbodb2b18ef2009-08-14 19:37:18 -04001204 comp_index = comp_count - 1;
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001205
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001206 return_trace ((this+markArray).apply (c, mark_index, comp_index, lig_attach, classCount, j));
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001207 }
1208
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001209 inline bool sanitize (hb_sanitize_context_t *c) const
1210 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001211 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001212 return_trace (c->check_struct (this) &&
1213 markCoverage.sanitize (c, this) &&
1214 ligatureCoverage.sanitize (c, this) &&
1215 markArray.sanitize (c, this) &&
1216 ligatureArray.sanitize (c, this, (unsigned int) classCount));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -04001217 }
1218
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001219 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001220 USHORT format; /* Format identifier--format = 1 */
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001221 OffsetTo<Coverage>
1222 markCoverage; /* Offset to Mark Coverage table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001223 * beginning of MarkLigPos subtable */
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001224 OffsetTo<Coverage>
1225 ligatureCoverage; /* Offset to Ligature Coverage
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001226 * table--from beginning of MarkLigPos
1227 * subtable */
1228 USHORT classCount; /* Number of defined mark classes */
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001229 OffsetTo<MarkArray>
1230 markArray; /* Offset to MarkArray table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001231 * beginning of MarkLigPos subtable */
Behdad Esfahbod9b006bc2009-05-22 18:29:45 -04001232 OffsetTo<LigatureArray>
1233 ligatureArray; /* Offset to LigatureArray table--from
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001234 * beginning of MarkLigPos subtable */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001235 public:
1236 DEFINE_SIZE_STATIC (12);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001237};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001238
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001239struct MarkLigPos
1240{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -05001241 template <typename context_t>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05001242 inline typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001243 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08001244 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -04001245 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001246 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001247 case 1: return_trace (c->dispatch (u.format1));
1248 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001249 }
1250 }
1251
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001252 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001253 union {
1254 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001255 MarkLigPosFormat1 format1;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001256 } u;
1257};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001258
1259
Behdad Esfahbodcb71a2f2009-08-14 18:14:03 -04001260typedef AnchorMatrix Mark2Array; /* mark2-major--
1261 * in order of Mark2Coverage Index--,
1262 * mark1-minor--
1263 * ordered by class--zero-based. */
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001264
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001265struct MarkMarkPosFormat1
1266{
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001267 inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
1268 {
1269 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbod83035932012-12-04 17:08:41 -05001270 (this+mark1Coverage).add_coverage (c->input);
1271 (this+mark2Coverage).add_coverage (c->input);
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001272 }
1273
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001274 inline const Coverage &get_coverage (void) const
1275 {
1276 return this+mark1Coverage;
1277 }
1278
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -04001279 inline bool apply (hb_apply_context_t *c) const
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001280 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001281 TRACE_APPLY (this);
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001282 hb_buffer_t *buffer = c->buffer;
1283 unsigned int mark1_index = (this+mark1Coverage).get_coverage (buffer->cur().codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001284 if (likely (mark1_index == NOT_COVERED)) return_trace (false);
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001285
1286 /* now we search backwards for a suitable mark glyph until a non-mark glyph */
Behdad Esfahbod365576d2015-01-29 13:59:42 +01001287 hb_apply_context_t::skipping_iterator_t &skippy_iter = c->iter_input;
Behdad Esfahbodb051be52015-01-29 13:40:39 +01001288 skippy_iter.reset (buffer->idx, 1);
Behdad Esfahbodc074ebc2013-02-13 11:22:42 -05001289 skippy_iter.set_lookup_props (c->lookup_props & ~LookupFlag::IgnoreFlags);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001290 if (!skippy_iter.prev ()) return_trace (false);
Behdad Esfahbod0532ed12009-08-12 15:40:04 -04001291
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001292 if (!_hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx])) { return_trace (false); }
Behdad Esfahbod80ea5bd2009-05-26 17:58:37 -04001293
Behdad Esfahbod4ab97312012-01-16 22:05:08 -05001294 unsigned int j = skippy_iter.idx;
1295
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001296 unsigned int id1 = _hb_glyph_info_get_lig_id (&buffer->cur());
1297 unsigned int id2 = _hb_glyph_info_get_lig_id (&buffer->info[j]);
1298 unsigned int comp1 = _hb_glyph_info_get_lig_comp (&buffer->cur());
1299 unsigned int comp2 = _hb_glyph_info_get_lig_comp (&buffer->info[j]);
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001300
Behdad Esfahbod5d874d52012-07-28 21:05:25 -04001301 if (likely (id1 == id2)) {
1302 if (id1 == 0) /* Marks belonging to the same base. */
1303 goto good;
1304 else if (comp1 == comp2) /* Marks belonging to the same ligature component. */
1305 goto good;
1306 } else {
1307 /* If ligature ids don't match, it may be the case that one of the marks
1308 * itself is a ligature. In which case match. */
1309 if ((id1 > 0 && !comp1) || (id2 > 0 && !comp2))
1310 goto good;
1311 }
1312
1313 /* Didn't match. */
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001314 return_trace (false);
Behdad Esfahbod5d874d52012-07-28 21:05:25 -04001315
1316 good:
Behdad Esfahbodac8cd512013-10-18 19:33:09 +02001317 unsigned int mark2_index = (this+mark2Coverage).get_coverage (buffer->info[j].codepoint);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001318 if (mark2_index == NOT_COVERED) return_trace (false);
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001319
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001320 return_trace ((this+mark1Array).apply (c, mark1_index, mark2_index, this+mark2Array, classCount, j));
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001321 }
1322
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001323 inline bool sanitize (hb_sanitize_context_t *c) const
1324 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001325 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001326 return_trace (c->check_struct (this) &&
1327 mark1Coverage.sanitize (c, this) &&
1328 mark2Coverage.sanitize (c, this) &&
1329 mark1Array.sanitize (c, this) &&
1330 mark2Array.sanitize (c, this, (unsigned int) classCount));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -04001331 }
1332
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001333 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001334 USHORT format; /* Format identifier--format = 1 */
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001335 OffsetTo<Coverage>
1336 mark1Coverage; /* Offset to Combining Mark1 Coverage
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001337 * table--from beginning of MarkMarkPos
1338 * subtable */
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001339 OffsetTo<Coverage>
1340 mark2Coverage; /* Offset to Combining Mark2 Coverage
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001341 * table--from beginning of MarkMarkPos
1342 * subtable */
Behdad Esfahbodfe550f42009-05-21 08:27:07 -04001343 USHORT classCount; /* Number of defined mark classes */
1344 OffsetTo<MarkArray>
1345 mark1Array; /* Offset to Mark1Array table--from
1346 * beginning of MarkMarkPos subtable */
1347 OffsetTo<Mark2Array>
1348 mark2Array; /* Offset to Mark2Array table--from
1349 * beginning of MarkMarkPos subtable */
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001350 public:
1351 DEFINE_SIZE_STATIC (12);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001352};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001353
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001354struct MarkMarkPos
1355{
Behdad Esfahbod2005fa52012-11-22 14:38:10 -05001356 template <typename context_t>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05001357 inline typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001358 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08001359 TRACE_DISPATCH (this, u.format);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -04001360 if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001361 switch (u.format) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001362 case 1: return_trace (c->dispatch (u.format1));
1363 default:return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001364 }
1365 }
1366
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001367 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001368 union {
1369 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001370 MarkMarkPosFormat1 format1;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001371 } u;
1372};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001373
1374
Behdad Esfahbod08f1eed2012-11-23 16:51:43 -05001375struct ContextPos : Context {};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001376
Behdad Esfahbod08f1eed2012-11-23 16:51:43 -05001377struct ChainContextPos : ChainContext {};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001378
Behdad Esfahbod653eeb22012-11-23 16:57:36 -05001379struct ExtensionPos : Extension<ExtensionPos>
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001380{
Behdad Esfahbod7dddd4e2012-11-23 17:04:55 -05001381 typedef struct PosLookupSubTable LookupSubTable;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001382};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001383
1384
Behdad Esfahbodd468f9a2009-05-21 22:31:33 -04001385
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001386/*
1387 * PosLookup
1388 */
1389
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001390
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001391struct PosLookupSubTable
1392{
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001393 friend struct PosLookup;
1394
Behdad Esfahbodc6035cf2012-04-12 13:23:59 -04001395 enum Type {
Behdad Esfahbodff05d252009-05-20 03:53:00 -04001396 Single = 1,
1397 Pair = 2,
1398 Cursive = 3,
1399 MarkBase = 4,
1400 MarkLig = 5,
1401 MarkMark = 6,
1402 Context = 7,
1403 ChainContext = 8,
Behdad Esfahbod8f034d52009-08-18 16:41:59 -04001404 Extension = 9
Behdad Esfahbodff05d252009-05-20 03:53:00 -04001405 };
1406
Behdad Esfahbod2005fa52012-11-22 14:38:10 -05001407 template <typename context_t>
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05001408 inline typename context_t::return_t dispatch (context_t *c, unsigned int lookup_type) const
Behdad Esfahbodfaf0f202012-06-09 03:02:36 -04001409 {
Behdad Esfahbod00f6a8e2014-12-12 20:36:49 -08001410 TRACE_DISPATCH (this, lookup_type);
Behdad Esfahbodf396fbb2015-10-09 12:25:55 -04001411 if (unlikely (!c->may_dispatch (this, &u.sub_format))) return_trace (c->no_dispatch_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001412 switch (lookup_type) {
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001413 case Single: return_trace (u.single.dispatch (c));
1414 case Pair: return_trace (u.pair.dispatch (c));
1415 case Cursive: return_trace (u.cursive.dispatch (c));
1416 case MarkBase: return_trace (u.markBase.dispatch (c));
1417 case MarkLig: return_trace (u.markLig.dispatch (c));
1418 case MarkMark: return_trace (u.markMark.dispatch (c));
1419 case Context: return_trace (u.context.dispatch (c));
1420 case ChainContext: return_trace (u.chainContext.dispatch (c));
1421 case Extension: return_trace (u.extension.dispatch (c));
1422 default: return_trace (c->default_return_value ());
Behdad Esfahbod0b994292012-07-28 17:31:01 -04001423 }
Behdad Esfahbodfaf0f202012-06-09 03:02:36 -04001424 }
1425
Behdad Esfahbodec8d2492012-07-24 15:40:37 -04001426 protected:
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001427 union {
Behdad Esfahbod6759ed92015-02-17 16:05:30 +03001428 USHORT sub_format;
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001429 SinglePos single;
1430 PairPos pair;
1431 CursivePos cursive;
1432 MarkBasePos markBase;
1433 MarkLigPos markLig;
1434 MarkMarkPos markMark;
Behdad Esfahbode72b3602012-07-19 14:35:23 -04001435 ContextPos context;
Behdad Esfahboddacebca2010-05-10 19:45:41 -04001436 ChainContextPos chainContext;
1437 ExtensionPos extension;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001438 } u;
Behdad Esfahboded074222010-05-10 18:08:46 -04001439 public:
Behdad Esfahbod6759ed92015-02-17 16:05:30 +03001440 DEFINE_SIZE_UNION (2, sub_format);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001441};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001442
1443
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001444struct PosLookup : Lookup
1445{
Behdad Esfahbod6d08c7f2012-07-11 18:01:27 -04001446 inline const PosLookupSubTable& get_subtable (unsigned int i) const
Behdad Esfahbod70366f52015-02-18 13:09:54 +03001447 { return Lookup::get_subtable<PosLookupSubTable> (i); }
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001448
Behdad Esfahbode015b8f2013-05-03 17:34:29 -04001449 inline bool is_reverse (void) const
1450 {
1451 return false;
1452 }
1453
Behdad Esfahbodbd047d32015-02-19 10:47:18 +03001454 inline bool apply (hb_apply_context_t *c) const
1455 {
1456 TRACE_APPLY (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001457 return_trace (dispatch (c));
Behdad Esfahbodbd047d32015-02-19 10:47:18 +03001458 }
1459
Behdad Esfahbod780cd932013-05-03 17:33:16 -04001460 inline hb_collect_glyphs_context_t::return_t collect_glyphs (hb_collect_glyphs_context_t *c) const
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001461 {
1462 TRACE_COLLECT_GLYPHS (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001463 return_trace (dispatch (c));
Behdad Esfahbodcdd756b2012-11-24 01:38:41 -05001464 }
1465
Behdad Esfahboda878c582012-08-01 21:18:54 -04001466 template <typename set_t>
1467 inline void add_coverage (set_t *glyphs) const
1468 {
Behdad Esfahbod8e36ccf2015-02-17 19:15:34 +03001469 hb_add_coverage_context_t<set_t> c (glyphs);
1470 dispatch (&c);
Behdad Esfahboda878c582012-08-01 21:18:54 -04001471 }
1472
Behdad Esfahbodec35a722012-11-22 16:05:59 -05001473 static bool apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index);
1474
Behdad Esfahbodee5464d2013-03-09 01:59:30 -05001475 template <typename context_t>
1476 static inline typename context_t::return_t dispatch_recurse_func (context_t *c, unsigned int lookup_index);
1477
1478 template <typename context_t>
1479 inline typename context_t::return_t dispatch (context_t *c) const
Behdad Esfahbod40c58922015-02-18 13:18:46 +03001480 { return Lookup::dispatch<PosLookupSubTable> (c); }
Behdad Esfahbodee5464d2013-03-09 01:59:30 -05001481
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001482 inline bool sanitize (hb_sanitize_context_t *c) const
1483 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001484 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001485 if (unlikely (!Lookup::sanitize (c))) return_trace (false);
1486 return_trace (dispatch (c));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -04001487 }
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001488};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001489
Behdad Esfahbod42b778f2009-08-04 13:30:49 -04001490typedef OffsetListOf<PosLookup> PosLookupList;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001491
1492/*
Behdad Esfahbodae9877d2011-08-17 14:43:45 +02001493 * GPOS -- The Glyph Positioning Table
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001494 */
1495
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001496struct GPOS : GSUBGPOS
1497{
Behdad Esfahbod6c48f202013-09-09 15:43:10 -04001498 static const hb_tag_t tableTag = HB_OT_TAG_GPOS;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001499
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001500 inline const PosLookup& get_lookup (unsigned int i) const
Behdad Esfahbod187454c2010-04-23 16:35:01 -04001501 { return CastR<PosLookup> (GSUBGPOS::get_lookup (i)); }
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001502
Behdad Esfahbod05bd1b62012-07-30 19:30:01 -04001503 static inline void position_start (hb_font_t *font, hb_buffer_t *buffer);
Behdad Esfahbod56800022013-02-12 09:44:57 -05001504 static inline void position_finish (hb_font_t *font, hb_buffer_t *buffer);
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001505
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001506 inline bool sanitize (hb_sanitize_context_t *c) const
1507 {
Behdad Esfahbodbe218c62012-11-23 15:32:14 -05001508 TRACE_SANITIZE (this);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001509 if (unlikely (!GSUBGPOS::sanitize (c))) return_trace (false);
Behdad Esfahbodde2118e2015-02-17 17:27:44 +03001510 const OffsetTo<PosLookupList> &list = CastR<OffsetTo<PosLookupList> > (lookupList);
Behdad Esfahbodb4715902015-09-29 14:57:02 +01001511 return_trace (list.sanitize (c, this));
Behdad Esfahbod42b778f2009-08-04 13:30:49 -04001512 }
Behdad Esfahbodb3651232010-05-10 16:57:29 -04001513 public:
1514 DEFINE_SIZE_STATIC (10);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001515};
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001516
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001517
1518static void
Behdad Esfahbod65785752015-08-25 20:24:59 +01001519reverse_cursive_minor_offset (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction, unsigned int new_parent)
1520{
1521 unsigned int j = pos[i].cursive_chain();
1522 if (likely (!j))
1523 return;
1524
Behdad Esfahbod806ad8d2016-02-11 14:53:11 +07001525 int old_chain = j;
Behdad Esfahbod65785752015-08-25 20:24:59 +01001526 pos[i].cursive_chain() = 0;
1527
Behdad Esfahbod806ad8d2016-02-11 14:53:11 +07001528 j += i;
1529
Behdad Esfahbod65785752015-08-25 20:24:59 +01001530 /* Stop if we see new parent in the chain. */
1531 if (j == new_parent)
1532 return;
1533
1534 reverse_cursive_minor_offset (pos, j, direction, new_parent);
1535
1536 if (HB_DIRECTION_IS_HORIZONTAL (direction))
1537 pos[j].y_offset = -pos[i].y_offset;
1538 else
1539 pos[j].x_offset = -pos[i].x_offset;
1540
Behdad Esfahbod806ad8d2016-02-11 14:53:11 +07001541 pos[j].cursive_chain() = -old_chain;
Behdad Esfahbod65785752015-08-25 20:24:59 +01001542}
1543static void
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001544fix_cursive_minor_offset (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction)
1545{
Behdad Esfahboddf5d5c62012-08-23 09:33:30 -04001546 unsigned int j = pos[i].cursive_chain();
1547 if (likely (!j))
1548 return;
Behdad Esfahbod806ad8d2016-02-11 14:53:11 +07001549 pos[i].cursive_chain() = 0;
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001550
Behdad Esfahboddf5d5c62012-08-23 09:33:30 -04001551 j += i;
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001552
Behdad Esfahboddf5d5c62012-08-23 09:33:30 -04001553 fix_cursive_minor_offset (pos, j, direction);
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001554
Behdad Esfahboddf5d5c62012-08-23 09:33:30 -04001555 if (HB_DIRECTION_IS_HORIZONTAL (direction))
1556 pos[i].y_offset += pos[j].y_offset;
1557 else
1558 pos[i].x_offset += pos[j].x_offset;
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001559}
1560
1561static void
Behdad Esfahbod56800022013-02-12 09:44:57 -05001562fix_mark_attachment (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction)
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001563{
Behdad Esfahbod0f6278d2016-02-11 14:49:10 +07001564 unsigned int j = pos[i].attach_chain();
1565 if (likely (!j))
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001566 return;
1567
Behdad Esfahbod0f6278d2016-02-11 14:49:10 +07001568 j += i;
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001569
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001570 pos[i].x_offset += pos[j].x_offset;
1571 pos[i].y_offset += pos[j].y_offset;
1572
1573 if (HB_DIRECTION_IS_FORWARD (direction))
Behdad Esfahbod21deab22011-05-30 11:08:40 -04001574 for (unsigned int k = j; k < i; k++) {
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001575 pos[i].x_offset -= pos[k].x_advance;
1576 pos[i].y_offset -= pos[k].y_advance;
1577 }
1578 else
Behdad Esfahbod21deab22011-05-30 11:08:40 -04001579 for (unsigned int k = j + 1; k < i + 1; k++) {
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001580 pos[i].x_offset += pos[k].x_advance;
1581 pos[i].y_offset += pos[k].y_advance;
1582 }
1583}
1584
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001585void
Behdad Esfahbod05bd1b62012-07-30 19:30:01 -04001586GPOS::position_start (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer)
Behdad Esfahboda9ad3d32011-07-28 15:42:18 -04001587{
1588 buffer->clear_positions ();
Behdad Esfahbodb65c0602011-07-28 16:48:43 -04001589
1590 unsigned int count = buffer->len;
1591 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbod0f6278d2016-02-11 14:49:10 +07001592 buffer->pos[i].attach_chain() = buffer->pos[i].cursive_chain() = 0;
Behdad Esfahboda9ad3d32011-07-28 15:42:18 -04001593}
1594
1595void
Behdad Esfahbod56800022013-02-12 09:44:57 -05001596GPOS::position_finish (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer)
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001597{
Behdad Esfahbod8f3eebf2014-08-02 17:18:46 -04001598 _hb_buffer_assert_gsubgpos_vars (buffer);
1599
Ryan Lortie70566be2011-04-15 18:32:36 -04001600 unsigned int len;
1601 hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, &len);
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001602 hb_direction_t direction = buffer->props.direction;
1603
Behdad Esfahbod7403e052011-05-24 21:04:15 -04001604 /* Handle cursive connections */
Behdad Esfahbod550bd142015-11-04 22:58:58 -08001605 if (buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_CURSIVE)
1606 for (unsigned int i = 0; i < len; i++)
1607 fix_cursive_minor_offset (pos, i, direction);
Behdad Esfahbodff31b3c2015-11-04 22:42:41 -08001608
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001609 /* Handle attachments */
Behdad Esfahbod550bd142015-11-04 22:58:58 -08001610 if (buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT)
1611 for (unsigned int i = 0; i < len; i++)
1612 fix_mark_attachment (pos, i, direction);
Behdad Esfahbod1e7c1fc2010-10-27 22:48:31 -04001613}
1614
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001615
1616/* Out-of-class implementation for methods recursing */
1617
Behdad Esfahbodc6fb8432012-11-23 18:04:08 -05001618template <typename context_t>
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -07001619/*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 -05001620{
1621 const GPOS &gpos = *(hb_ot_layout_from_face (c->face)->gpos);
1622 const PosLookup &l = gpos.get_lookup (lookup_index);
Behdad Esfahbod9c5a9ee2013-03-09 01:55:04 -05001623 return l.dispatch (c);
Behdad Esfahbodc6fb8432012-11-23 18:04:08 -05001624}
1625
Behdad Esfahbod6faff8e2014-04-28 14:29:39 -07001626/*static*/ inline bool PosLookup::apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index)
Behdad Esfahbod4c44d832009-05-19 23:42:30 -04001627{
Behdad Esfahbodea278d32012-07-27 02:12:28 -04001628 const GPOS &gpos = *(hb_ot_layout_from_face (c->face)->gpos);
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001629 const PosLookup &l = gpos.get_lookup (lookup_index);
Behdad Esfahbod4c4e8f02012-11-24 01:13:20 -05001630 unsigned int saved_lookup_props = c->lookup_props;
Behdad Esfahbod2c8b3b22015-08-18 14:36:43 +01001631 unsigned int saved_lookup_index = c->lookup_index;
1632 c->set_lookup_index (lookup_index);
1633 c->set_lookup_props (l.get_props ());
Behdad Esfahbod1a232212015-02-19 10:40:23 +03001634 bool ret = l.dispatch (c);
Behdad Esfahbod2c8b3b22015-08-18 14:36:43 +01001635 c->set_lookup_index (saved_lookup_index);
Behdad Esfahbod77889932015-01-28 23:01:12 -08001636 c->set_lookup_props (saved_lookup_props);
Behdad Esfahbod4c4e8f02012-11-24 01:13:20 -05001637 return ret;
Behdad Esfahbod5e5eb052009-05-18 17:09:33 -04001638}
1639
1640
Behdad Esfahbod0f6278d2016-02-11 14:49:10 +07001641#undef attach_chain
Behdad Esfahbod194d4562010-10-27 23:09:10 -04001642#undef cursive_chain
1643
1644
Behdad Esfahbod7d52e662012-11-16 18:49:54 -08001645} /* namespace OT */
Behdad Esfahbod7c8e8442012-08-28 17:57:49 -04001646
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -04001647
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +02001648#endif /* HB_OT_LAYOUT_GPOS_TABLE_HH */