Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 2007,2008,2009,2010 Red Hat, Inc. |
Behdad Esfahbod | 2e0c44f | 2013-04-24 16:42:05 -0400 | [diff] [blame] | 3 | * Copyright © 2010,2012,2013 Google, Inc. |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 4 | * |
Behdad Esfahbod | c755cb3 | 2010-04-22 00:11:43 -0400 | [diff] [blame] | 5 | * This is part of HarfBuzz, a text shaping library. |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 6 | * |
| 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 Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 26 | * Google Author(s): Behdad Esfahbod |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 27 | */ |
| 28 | |
Behdad Esfahbod | 7a750ac | 2011-08-17 14:19:59 +0200 | [diff] [blame] | 29 | #ifndef HB_OT_LAYOUT_GPOS_TABLE_HH |
| 30 | #define HB_OT_LAYOUT_GPOS_TABLE_HH |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 31 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 32 | #include "hb-ot-layout-gsubgpos-private.hh" |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 33 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 34 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 35 | namespace OT { |
| 36 | |
Behdad Esfahbod | 94a23aa | 2010-05-05 01:13:09 -0400 | [diff] [blame] | 37 | |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 38 | /* buffer **position** var allocations */ |
Behdad Esfahbod | 194d456 | 2010-10-27 23:09:10 -0400 | [diff] [blame] | 39 | #define attach_lookback() var.u16[0] /* number of glyphs to go back to attach this glyph to its base */ |
| 40 | #define cursive_chain() var.i16[1] /* character to which this connects, may be positive or negative */ |
| 41 | |
| 42 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 43 | /* Shared Tables: ValueRecord, Anchor Table, and MarkArray */ |
| 44 | |
Behdad Esfahbod | c2ddfd2 | 2010-05-06 13:06:15 -0400 | [diff] [blame] | 45 | typedef USHORT Value; |
Behdad Esfahbod | c91facd | 2009-08-26 18:53:43 -0400 | [diff] [blame] | 46 | |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 47 | typedef Value ValueRecord[VAR]; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 48 | |
Behdad Esfahbod | fca6a0d | 2009-05-21 04:49:04 -0400 | [diff] [blame] | 49 | struct ValueFormat : USHORT |
| 50 | { |
Behdad Esfahbod | c6035cf | 2012-04-12 13:23:59 -0400 | [diff] [blame] | 51 | enum Flags { |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame^] | 52 | 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 Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 62 | |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame^] | 63 | devices = 0x00F0u /* Mask for having any Device table */ |
Behdad Esfahbod | fca6a0d | 2009-05-21 04:49:04 -0400 | [diff] [blame] | 64 | }; |
| 65 | |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 66 | /* All fields are options. Only those available advance the value pointer. */ |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 67 | #if 0 |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 68 | 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 Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 90 | #endif |
| 91 | |
Behdad Esfahbod | 7f97d2c | 2010-10-01 18:58:50 -0400 | [diff] [blame] | 92 | inline unsigned int get_len (void) const |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 93 | { return _hb_popcount32 ((unsigned int) *this); } |
Behdad Esfahbod | 7f97d2c | 2010-10-01 18:58:50 -0400 | [diff] [blame] | 94 | inline unsigned int get_size (void) const |
Behdad Esfahbod | e45d3f8 | 2010-05-06 19:33:31 -0400 | [diff] [blame] | 95 | { return get_len () * Value::static_size; } |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 96 | |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 97 | void apply_value (hb_font_t *font, |
Behdad Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 98 | hb_direction_t direction, |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 99 | const void *base, |
| 100 | const Value *values, |
| 101 | hb_glyph_position_t &glyph_pos) const |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 102 | { |
| 103 | unsigned int x_ppem, y_ppem; |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 104 | unsigned int format = *this; |
Behdad Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 105 | hb_bool_t horizontal = HB_DIRECTION_IS_HORIZONTAL (direction); |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 106 | |
| 107 | if (!format) return; |
| 108 | |
Behdad Esfahbod | b6f902a | 2011-05-11 00:04:15 -0400 | [diff] [blame] | 109 | 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 Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 111 | if (format & xAdvance) { |
Konstantin Ritt | 0832259 | 2014-01-22 20:31:30 +0200 | [diff] [blame] | 112 | if (likely (horizontal)) glyph_pos.x_advance += font->em_scale_x (get_short (values)); |
| 113 | values++; |
Behdad Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 114 | } |
Behdad Esfahbod | cc2086d | 2011-05-19 19:19:50 -0400 | [diff] [blame] | 115 | /* y_advance values grow downward but font-space grows upward, hence negation */ |
Behdad Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 116 | if (format & yAdvance) { |
Konstantin Ritt | 0832259 | 2014-01-22 20:31:30 +0200 | [diff] [blame] | 117 | if (unlikely (!horizontal)) glyph_pos.y_advance -= font->em_scale_y (get_short (values)); |
| 118 | values++; |
Behdad Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 119 | } |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 120 | |
Behdad Esfahbod | a8d960b | 2010-04-29 14:31:56 -0400 | [diff] [blame] | 121 | if (!has_device ()) return; |
| 122 | |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 123 | x_ppem = font->x_ppem; |
| 124 | y_ppem = font->y_ppem; |
Behdad Esfahbod | a8d960b | 2010-04-29 14:31:56 -0400 | [diff] [blame] | 125 | |
| 126 | if (!x_ppem && !y_ppem) return; |
| 127 | |
Behdad Esfahbod | 0090dc0 | 2009-07-30 16:28:45 -0400 | [diff] [blame] | 128 | /* pixel -> fractional pixel */ |
| 129 | if (format & xPlaDevice) { |
Konstantin Ritt | 0832259 | 2014-01-22 20:31:30 +0200 | [diff] [blame] | 130 | if (x_ppem) glyph_pos.x_offset += (base + get_device (values)).get_x_delta (font); |
| 131 | values++; |
Behdad Esfahbod | 0090dc0 | 2009-07-30 16:28:45 -0400 | [diff] [blame] | 132 | } |
| 133 | if (format & yPlaDevice) { |
Konstantin Ritt | 0832259 | 2014-01-22 20:31:30 +0200 | [diff] [blame] | 134 | if (y_ppem) glyph_pos.y_offset += (base + get_device (values)).get_y_delta (font); |
| 135 | values++; |
Behdad Esfahbod | 0090dc0 | 2009-07-30 16:28:45 -0400 | [diff] [blame] | 136 | } |
| 137 | if (format & xAdvDevice) { |
Konstantin Ritt | 0832259 | 2014-01-22 20:31:30 +0200 | [diff] [blame] | 138 | if (horizontal && x_ppem) glyph_pos.x_advance += (base + get_device (values)).get_x_delta (font); |
| 139 | values++; |
Behdad Esfahbod | 0090dc0 | 2009-07-30 16:28:45 -0400 | [diff] [blame] | 140 | } |
| 141 | if (format & yAdvDevice) { |
Behdad Esfahbod | cc2086d | 2011-05-19 19:19:50 -0400 | [diff] [blame] | 142 | /* y_advance values grow downward but font-space grows upward, hence negation */ |
Konstantin Ritt | 0832259 | 2014-01-22 20:31:30 +0200 | [diff] [blame] | 143 | if (!horizontal && y_ppem) glyph_pos.y_advance -= (base + get_device (values)).get_y_delta (font); |
| 144 | values++; |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 145 | } |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 146 | } |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 147 | |
| 148 | private: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 149 | inline bool sanitize_value_devices (hb_sanitize_context_t *c, void *base, Value *values) { |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 150 | unsigned int format = *this; |
| 151 | |
| 152 | if (format & xPlacement) values++; |
| 153 | if (format & yPlacement) values++; |
| 154 | if (format & xAdvance) values++; |
| 155 | if (format & yAdvance) values++; |
| 156 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 157 | if ((format & xPlaDevice) && !get_device (values++).sanitize (c, base)) return false; |
| 158 | if ((format & yPlaDevice) && !get_device (values++).sanitize (c, base)) return false; |
| 159 | if ((format & xAdvDevice) && !get_device (values++).sanitize (c, base)) return false; |
| 160 | if ((format & yAdvDevice) && !get_device (values++).sanitize (c, base)) return false; |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 161 | |
| 162 | return true; |
| 163 | } |
| 164 | |
Behdad Esfahbod | c2ddfd2 | 2010-05-06 13:06:15 -0400 | [diff] [blame] | 165 | static inline OffsetTo<Device>& get_device (Value* value) |
| 166 | { return *CastP<OffsetTo<Device> > (value); } |
| 167 | static inline const OffsetTo<Device>& get_device (const Value* value) |
| 168 | { return *CastP<OffsetTo<Device> > (value); } |
| 169 | |
| 170 | static inline const SHORT& get_short (const Value* value) |
| 171 | { return *CastP<SHORT> (value); } |
| 172 | |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 173 | public: |
| 174 | |
Behdad Esfahbod | 7f97d2c | 2010-10-01 18:58:50 -0400 | [diff] [blame] | 175 | inline bool has_device (void) const { |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 176 | unsigned int format = *this; |
| 177 | return (format & devices) != 0; |
| 178 | } |
| 179 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 180 | inline bool sanitize_value (hb_sanitize_context_t *c, void *base, Value *values) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 181 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 182 | return TRACE_RETURN (c->check_range (values, get_size ()) && (!has_device () || sanitize_value_devices (c, base, values))); |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 183 | } |
| 184 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 185 | inline bool sanitize_values (hb_sanitize_context_t *c, void *base, Value *values, unsigned int count) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 186 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 187 | unsigned int len = get_len (); |
| 188 | |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 189 | if (!c->check_array (values, get_size (), count)) return TRACE_RETURN (false); |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 190 | |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 191 | if (!has_device ()) return TRACE_RETURN (true); |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 192 | |
| 193 | for (unsigned int i = 0; i < count; i++) { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 194 | if (!sanitize_value_devices (c, base, values)) |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 195 | return TRACE_RETURN (false); |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 196 | values += len; |
| 197 | } |
| 198 | |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 199 | return TRACE_RETURN (true); |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Behdad Esfahbod | 278a91f | 2010-04-22 13:59:39 -0400 | [diff] [blame] | 202 | /* Just sanitize referenced Device tables. Doesn't check the values themselves. */ |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 203 | inline bool sanitize_values_stride_unsafe (hb_sanitize_context_t *c, void *base, Value *values, unsigned int count, unsigned int stride) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 204 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 205 | |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 206 | if (!has_device ()) return TRACE_RETURN (true); |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 207 | |
| 208 | for (unsigned int i = 0; i < count; i++) { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 209 | if (!sanitize_value_devices (c, base, values)) |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 210 | return TRACE_RETURN (false); |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 211 | values += stride; |
| 212 | } |
| 213 | |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 214 | return TRACE_RETURN (true); |
Behdad Esfahbod | 673a4ef | 2010-04-21 02:02:57 -0400 | [diff] [blame] | 215 | } |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 216 | }; |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 217 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 218 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 219 | struct AnchorFormat1 |
| 220 | { |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 221 | inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id HB_UNUSED, |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 222 | hb_position_t *x, hb_position_t *y) const |
| 223 | { |
Behdad Esfahbod | b6f902a | 2011-05-11 00:04:15 -0400 | [diff] [blame] | 224 | *x = font->em_scale_x (xCoordinate); |
| 225 | *y = font->em_scale_y (yCoordinate); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 226 | } |
| 227 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 228 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 229 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 230 | return TRACE_RETURN (c->check_struct (this)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 231 | } |
| 232 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 233 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 234 | USHORT format; /* Format identifier--format = 1 */ |
| 235 | SHORT xCoordinate; /* Horizontal value--in design units */ |
| 236 | SHORT yCoordinate; /* Vertical value--in design units */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 237 | public: |
| 238 | DEFINE_SIZE_STATIC (6); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 239 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 240 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 241 | struct AnchorFormat2 |
| 242 | { |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 243 | inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id, |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 244 | hb_position_t *x, hb_position_t *y) const |
| 245 | { |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 246 | unsigned int x_ppem = font->x_ppem; |
| 247 | unsigned int y_ppem = font->y_ppem; |
Behdad Esfahbod | 6f729b4 | 2010-04-29 03:59:06 -0400 | [diff] [blame] | 248 | hb_position_t cx, cy; |
Konstantin Ritt | 0832259 | 2014-01-22 20:31:30 +0200 | [diff] [blame] | 249 | hb_bool_t ret; |
Behdad Esfahbod | 6f729b4 | 2010-04-29 03:59:06 -0400 | [diff] [blame] | 250 | |
Konstantin Ritt | 0832259 | 2014-01-22 20:31:30 +0200 | [diff] [blame] | 251 | ret = (x_ppem || y_ppem) && |
| 252 | font->get_glyph_contour_point_for_origin (glyph_id, anchorPoint, HB_DIRECTION_LTR, &cx, &cy); |
| 253 | *x = ret && x_ppem ? cx : font->em_scale_x (xCoordinate); |
| 254 | *y = ret && y_ppem ? cy : font->em_scale_y (yCoordinate); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 255 | } |
| 256 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 257 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 258 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 259 | return TRACE_RETURN (c->check_struct (this)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 260 | } |
| 261 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 262 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 263 | USHORT format; /* Format identifier--format = 2 */ |
| 264 | SHORT xCoordinate; /* Horizontal value--in design units */ |
| 265 | SHORT yCoordinate; /* Vertical value--in design units */ |
| 266 | USHORT anchorPoint; /* Index to glyph contour point */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 267 | public: |
| 268 | DEFINE_SIZE_STATIC (8); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 269 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 270 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 271 | struct AnchorFormat3 |
| 272 | { |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 273 | inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id HB_UNUSED, |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 274 | hb_position_t *x, hb_position_t *y) const |
| 275 | { |
Behdad Esfahbod | b6f902a | 2011-05-11 00:04:15 -0400 | [diff] [blame] | 276 | *x = font->em_scale_x (xCoordinate); |
| 277 | *y = font->em_scale_y (yCoordinate); |
Behdad Esfahbod | c18ec2b | 2009-05-21 04:54:01 -0400 | [diff] [blame] | 278 | |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 279 | if (font->x_ppem) |
| 280 | *x += (this+xDeviceTable).get_x_delta (font); |
| 281 | if (font->y_ppem) |
| 282 | *y += (this+yDeviceTable).get_x_delta (font); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 283 | } |
| 284 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 285 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 286 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 287 | return TRACE_RETURN (c->check_struct (this) && xDeviceTable.sanitize (c, this) && yDeviceTable.sanitize (c, this)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 288 | } |
| 289 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 290 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 291 | USHORT format; /* Format identifier--format = 3 */ |
| 292 | SHORT xCoordinate; /* Horizontal value--in design units */ |
| 293 | SHORT yCoordinate; /* Vertical value--in design units */ |
| 294 | OffsetTo<Device> |
| 295 | xDeviceTable; /* Offset to Device table for X |
| 296 | * coordinate-- from beginning of |
| 297 | * Anchor table (may be NULL) */ |
| 298 | OffsetTo<Device> |
| 299 | yDeviceTable; /* Offset to Device table for Y |
| 300 | * coordinate-- from beginning of |
| 301 | * Anchor table (may be NULL) */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 302 | public: |
| 303 | DEFINE_SIZE_STATIC (10); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 304 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 305 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 306 | struct Anchor |
| 307 | { |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 308 | inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id, |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 309 | hb_position_t *x, hb_position_t *y) const |
| 310 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 311 | *x = *y = 0; |
| 312 | switch (u.format) { |
Behdad Esfahbod | 60fbb36 | 2011-05-19 18:46:15 -0400 | [diff] [blame] | 313 | case 1: u.format1.get_anchor (font, glyph_id, x, y); return; |
| 314 | case 2: u.format2.get_anchor (font, glyph_id, x, y); return; |
| 315 | case 3: u.format3.get_anchor (font, glyph_id, x, y); return; |
| 316 | default: return; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 320 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 321 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 322 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 323 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 324 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 325 | case 2: return TRACE_RETURN (u.format2.sanitize (c)); |
| 326 | case 3: return TRACE_RETURN (u.format3.sanitize (c)); |
| 327 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 331 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 332 | union { |
| 333 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 334 | AnchorFormat1 format1; |
| 335 | AnchorFormat2 format2; |
| 336 | AnchorFormat3 format3; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 337 | } u; |
Behdad Esfahbod | ed07422 | 2010-05-10 18:08:46 -0400 | [diff] [blame] | 338 | public: |
Behdad Esfahbod | 596e471 | 2010-05-10 18:47:48 -0400 | [diff] [blame] | 339 | DEFINE_SIZE_UNION (2, format); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 340 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 341 | |
| 342 | |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 343 | struct AnchorMatrix |
| 344 | { |
Behdad Esfahbod | e95e031 | 2013-01-08 16:15:46 -0600 | [diff] [blame] | 345 | inline const Anchor& get_anchor (unsigned int row, unsigned int col, unsigned int cols, bool *found) const { |
| 346 | *found = false; |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 347 | if (unlikely (row >= rows || col >= cols)) return Null(Anchor); |
Behdad Esfahbod | e95e031 | 2013-01-08 16:15:46 -0600 | [diff] [blame] | 348 | *found = !matrix[row * cols + col].is_null (); |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 349 | return this+matrix[row * cols + col]; |
| 350 | } |
| 351 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 352 | inline bool sanitize (hb_sanitize_context_t *c, unsigned int cols) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 353 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 354 | if (!c->check_struct (this)) return TRACE_RETURN (false); |
| 355 | if (unlikely (rows > 0 && cols >= ((unsigned int) -1) / rows)) return TRACE_RETURN (false); |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 356 | unsigned int count = rows * cols; |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 357 | if (!c->check_array (matrix, matrix[0].static_size, count)) return TRACE_RETURN (false); |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 358 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 359 | if (!matrix[i].sanitize (c, this)) return TRACE_RETURN (false); |
| 360 | return TRACE_RETURN (true); |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | USHORT rows; /* Number of rows */ |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 364 | protected: |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 365 | OffsetTo<Anchor> |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 366 | matrix[VAR]; /* Matrix of offsets to Anchor tables-- |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 367 | * from beginning of AnchorMatrix table */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 368 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 369 | DEFINE_SIZE_ARRAY (2, matrix); |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 370 | }; |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 371 | |
| 372 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 373 | struct MarkRecord |
| 374 | { |
Behdad Esfahbod | 377bfc5 | 2009-05-21 04:58:24 -0400 | [diff] [blame] | 375 | friend struct MarkArray; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 376 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 377 | inline bool sanitize (hb_sanitize_context_t *c, void *base) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 378 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 379 | return TRACE_RETURN (c->check_struct (this) && markAnchor.sanitize (c, base)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 380 | } |
| 381 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 382 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 383 | USHORT klass; /* Class defined for this mark */ |
| 384 | OffsetTo<Anchor> |
| 385 | markAnchor; /* Offset to Anchor table--from |
| 386 | * beginning of MarkArray table */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 387 | public: |
| 388 | DEFINE_SIZE_STATIC (4); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 389 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 390 | |
Behdad Esfahbod | bea34c7 | 2010-05-10 17:28:16 -0400 | [diff] [blame] | 391 | struct MarkArray : ArrayOf<MarkRecord> /* Array of MarkRecords--in Coverage order */ |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 392 | { |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 393 | inline bool apply (hb_apply_context_t *c, |
Behdad Esfahbod | b41f210 | 2009-08-14 19:33:24 -0400 | [diff] [blame] | 394 | unsigned int mark_index, unsigned int glyph_index, |
| 395 | const AnchorMatrix &anchors, unsigned int class_count, |
| 396 | unsigned int glyph_pos) const |
| 397 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 398 | TRACE_APPLY (this); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 399 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | bea34c7 | 2010-05-10 17:28:16 -0400 | [diff] [blame] | 400 | const MarkRecord &record = ArrayOf<MarkRecord>::operator[](mark_index); |
Behdad Esfahbod | b41f210 | 2009-08-14 19:33:24 -0400 | [diff] [blame] | 401 | unsigned int mark_class = record.klass; |
| 402 | |
| 403 | const Anchor& mark_anchor = this + record.markAnchor; |
Behdad Esfahbod | e95e031 | 2013-01-08 16:15:46 -0600 | [diff] [blame] | 404 | bool found; |
| 405 | const Anchor& glyph_anchor = anchors.get_anchor (glyph_index, mark_class, class_count, &found); |
| 406 | /* If this subtable doesn't have an anchor for this base and this class, |
| 407 | * return false such that the subsequent subtables have a chance at it. */ |
| 408 | if (unlikely (!found)) return TRACE_RETURN (false); |
Behdad Esfahbod | b41f210 | 2009-08-14 19:33:24 -0400 | [diff] [blame] | 409 | |
| 410 | hb_position_t mark_x, mark_y, base_x, base_y; |
| 411 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 412 | mark_anchor.get_anchor (c->font, buffer->cur().codepoint, &mark_x, &mark_y); |
| 413 | glyph_anchor.get_anchor (c->font, buffer->info[glyph_pos].codepoint, &base_x, &base_y); |
Behdad Esfahbod | b41f210 | 2009-08-14 19:33:24 -0400 | [diff] [blame] | 414 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 415 | hb_glyph_position_t &o = buffer->cur_pos(); |
Behdad Esfahbod | 194d456 | 2010-10-27 23:09:10 -0400 | [diff] [blame] | 416 | o.x_offset = base_x - mark_x; |
| 417 | o.y_offset = base_y - mark_y; |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 418 | o.attach_lookback() = buffer->idx - glyph_pos; |
Behdad Esfahbod | b41f210 | 2009-08-14 19:33:24 -0400 | [diff] [blame] | 419 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 420 | buffer->idx++; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 421 | return TRACE_RETURN (true); |
Behdad Esfahbod | b41f210 | 2009-08-14 19:33:24 -0400 | [diff] [blame] | 422 | } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 423 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 424 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 425 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 426 | return TRACE_RETURN (ArrayOf<MarkRecord>::sanitize (c, this)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 427 | } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 428 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 429 | |
| 430 | |
| 431 | /* Lookups */ |
| 432 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 433 | struct SinglePosFormat1 |
| 434 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 435 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 436 | { |
| 437 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 438 | (this+coverage).add_coverage (c->input); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 439 | } |
| 440 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 441 | inline const Coverage &get_coverage (void) const |
| 442 | { |
| 443 | return this+coverage; |
| 444 | } |
| 445 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 446 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 447 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 448 | TRACE_APPLY (this); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 449 | hb_buffer_t *buffer = c->buffer; |
| 450 | unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 451 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 452 | |
Behdad Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 453 | valueFormat.apply_value (c->font, c->direction, this, |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 454 | values, buffer->cur_pos()); |
Behdad Esfahbod | f53d434 | 2009-05-30 22:17:32 -0400 | [diff] [blame] | 455 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 456 | buffer->idx++; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 457 | return TRACE_RETURN (true); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 458 | } |
| 459 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 460 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 461 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 462 | return TRACE_RETURN (c->check_struct (this) && coverage.sanitize (c, this) && valueFormat.sanitize_value (c, this, values)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 463 | } |
| 464 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 465 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 466 | USHORT format; /* Format identifier--format = 1 */ |
| 467 | OffsetTo<Coverage> |
| 468 | coverage; /* Offset to Coverage table--from |
| 469 | * beginning of subtable */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 470 | ValueFormat valueFormat; /* Defines the types of data in the |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 471 | * ValueRecord */ |
| 472 | ValueRecord values; /* Defines positioning |
| 473 | * value(s)--applied to all glyphs in |
| 474 | * the Coverage table */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 475 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 476 | DEFINE_SIZE_ARRAY (6, values); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 477 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 478 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 479 | struct SinglePosFormat2 |
| 480 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 481 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 482 | { |
| 483 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 484 | (this+coverage).add_coverage (c->input); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 485 | } |
| 486 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 487 | inline const Coverage &get_coverage (void) const |
| 488 | { |
| 489 | return this+coverage; |
| 490 | } |
| 491 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 492 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 493 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 494 | TRACE_APPLY (this); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 495 | hb_buffer_t *buffer = c->buffer; |
| 496 | unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 497 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 498 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 499 | if (likely (index >= valueCount)) return TRACE_RETURN (false); |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 500 | |
Behdad Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 501 | valueFormat.apply_value (c->font, c->direction, this, |
Behdad Esfahbod | 4b8487d | 2010-03-16 03:46:17 -0400 | [diff] [blame] | 502 | &values[index * valueFormat.get_len ()], |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 503 | buffer->cur_pos()); |
Behdad Esfahbod | f53d434 | 2009-05-30 22:17:32 -0400 | [diff] [blame] | 504 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 505 | buffer->idx++; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 506 | return TRACE_RETURN (true); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 507 | } |
| 508 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 509 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 510 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 511 | return TRACE_RETURN (c->check_struct (this) && coverage.sanitize (c, this) && valueFormat.sanitize_values (c, this, values, valueCount)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 514 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 515 | USHORT format; /* Format identifier--format = 2 */ |
| 516 | OffsetTo<Coverage> |
| 517 | coverage; /* Offset to Coverage table--from |
| 518 | * beginning of subtable */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 519 | ValueFormat valueFormat; /* Defines the types of data in the |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 520 | * ValueRecord */ |
| 521 | USHORT valueCount; /* Number of ValueRecords */ |
| 522 | ValueRecord values; /* Array of ValueRecords--positioning |
| 523 | * values applied to glyphs */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 524 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 525 | DEFINE_SIZE_ARRAY (8, values); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 526 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 527 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 528 | struct SinglePos |
| 529 | { |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 530 | template <typename context_t> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 531 | inline typename context_t::return_t dispatch (context_t *c) const |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 532 | { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 533 | TRACE_DISPATCH (this); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 534 | switch (u.format) { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 535 | case 1: return TRACE_RETURN (c->dispatch (u.format1)); |
| 536 | case 2: return TRACE_RETURN (c->dispatch (u.format2)); |
Behdad Esfahbod | f48ec0e | 2012-11-23 17:23:41 -0500 | [diff] [blame] | 537 | default:return TRACE_RETURN (c->default_return_value ()); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 541 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 542 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 543 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 544 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 545 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 546 | case 2: return TRACE_RETURN (u.format2.sanitize (c)); |
| 547 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 551 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 552 | union { |
| 553 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 554 | SinglePosFormat1 format1; |
| 555 | SinglePosFormat2 format2; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 556 | } u; |
| 557 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 558 | |
| 559 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 560 | struct PairValueRecord |
| 561 | { |
Behdad Esfahbod | 70c9bfd | 2010-05-11 00:23:50 -0400 | [diff] [blame] | 562 | friend struct PairSet; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 563 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 564 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 565 | GlyphID secondGlyph; /* GlyphID of second glyph in the |
| 566 | * pair--first glyph is listed in the |
| 567 | * Coverage table */ |
| 568 | ValueRecord values; /* Positioning data for the first glyph |
| 569 | * followed by for second glyph */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 570 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 571 | DEFINE_SIZE_ARRAY (2, values); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 572 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 573 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 574 | struct PairSet |
| 575 | { |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 576 | friend struct PairPosFormat1; |
| 577 | |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 578 | inline void collect_glyphs (hb_collect_glyphs_context_t *c, |
| 579 | const ValueFormat *valueFormats) const |
| 580 | { |
| 581 | TRACE_COLLECT_GLYPHS (this); |
| 582 | unsigned int len1 = valueFormats[0].get_len (); |
| 583 | unsigned int len2 = valueFormats[1].get_len (); |
| 584 | unsigned int record_size = USHORT::static_size * (1 + len1 + len2); |
| 585 | |
| 586 | const PairValueRecord *record = CastP<PairValueRecord> (array); |
| 587 | unsigned int count = len; |
| 588 | for (unsigned int i = 0; i < count; i++) |
| 589 | { |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 590 | c->input->add (record->secondGlyph); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 591 | record = &StructAtOffset<PairValueRecord> (record, record_size); |
| 592 | } |
| 593 | } |
| 594 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 595 | inline bool apply (hb_apply_context_t *c, |
Behdad Esfahbod | 70c9bfd | 2010-05-11 00:23:50 -0400 | [diff] [blame] | 596 | const ValueFormat *valueFormats, |
| 597 | unsigned int pos) const |
| 598 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 599 | TRACE_APPLY (this); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 600 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 70c9bfd | 2010-05-11 00:23:50 -0400 | [diff] [blame] | 601 | unsigned int len1 = valueFormats[0].get_len (); |
| 602 | unsigned int len2 = valueFormats[1].get_len (); |
| 603 | unsigned int record_size = USHORT::static_size * (1 + len1 + len2); |
| 604 | |
Behdad Esfahbod | 70c9bfd | 2010-05-11 00:23:50 -0400 | [diff] [blame] | 605 | const PairValueRecord *record = CastP<PairValueRecord> (array); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 606 | unsigned int count = len; |
Behdad Esfahbod | 70c9bfd | 2010-05-11 00:23:50 -0400 | [diff] [blame] | 607 | for (unsigned int i = 0; i < count; i++) |
| 608 | { |
Behdad Esfahbod | 607feb7 | 2013-02-14 07:43:13 -0500 | [diff] [blame] | 609 | /* TODO bsearch */ |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 610 | if (buffer->info[pos].codepoint == record->secondGlyph) |
Behdad Esfahbod | 70c9bfd | 2010-05-11 00:23:50 -0400 | [diff] [blame] | 611 | { |
Behdad Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 612 | valueFormats[0].apply_value (c->font, c->direction, this, |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 613 | &record->values[0], buffer->cur_pos()); |
Behdad Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 614 | valueFormats[1].apply_value (c->font, c->direction, this, |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 615 | &record->values[len1], buffer->pos[pos]); |
Behdad Esfahbod | 70c9bfd | 2010-05-11 00:23:50 -0400 | [diff] [blame] | 616 | if (len2) |
| 617 | pos++; |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 618 | buffer->idx = pos; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 619 | return TRACE_RETURN (true); |
Behdad Esfahbod | 70c9bfd | 2010-05-11 00:23:50 -0400 | [diff] [blame] | 620 | } |
| 621 | record = &StructAtOffset<PairValueRecord> (record, record_size); |
| 622 | } |
| 623 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 624 | return TRACE_RETURN (false); |
Behdad Esfahbod | 70c9bfd | 2010-05-11 00:23:50 -0400 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | struct sanitize_closure_t { |
| 628 | void *base; |
| 629 | ValueFormat *valueFormats; |
| 630 | unsigned int len1; /* valueFormats[0].get_len() */ |
| 631 | unsigned int stride; /* 1 + len1 + len2 */ |
| 632 | }; |
| 633 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 634 | inline bool sanitize (hb_sanitize_context_t *c, const sanitize_closure_t *closure) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 635 | TRACE_SANITIZE (this); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 636 | if (!(c->check_struct (this) |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 637 | && c->check_array (array, USHORT::static_size * closure->stride, len))) return TRACE_RETURN (false); |
Behdad Esfahbod | 70c9bfd | 2010-05-11 00:23:50 -0400 | [diff] [blame] | 638 | |
| 639 | unsigned int count = len; |
| 640 | PairValueRecord *record = CastP<PairValueRecord> (array); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 641 | return TRACE_RETURN (closure->valueFormats[0].sanitize_values_stride_unsafe (c, closure->base, &record->values[0], count, closure->stride) |
| 642 | && closure->valueFormats[1].sanitize_values_stride_unsafe (c, closure->base, &record->values[closure->len1], count, closure->stride)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 643 | } |
| 644 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 645 | protected: |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 646 | USHORT len; /* Number of PairValueRecords */ |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 647 | USHORT array[VAR]; /* Array of PairValueRecords--ordered |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 648 | * by GlyphID of the second glyph */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 649 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 650 | DEFINE_SIZE_ARRAY (2, array); |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 651 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 652 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 653 | struct PairPosFormat1 |
| 654 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 655 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 656 | { |
| 657 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 658 | (this+coverage).add_coverage (c->input); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 659 | unsigned int count = pairSet.len; |
| 660 | for (unsigned int i = 0; i < count; i++) |
| 661 | (this+pairSet[i]).collect_glyphs (c, &valueFormat1); |
| 662 | } |
| 663 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 664 | inline const Coverage &get_coverage (void) const |
| 665 | { |
| 666 | return this+coverage; |
| 667 | } |
| 668 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 669 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 670 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 671 | TRACE_APPLY (this); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 672 | hb_buffer_t *buffer = c->buffer; |
| 673 | hb_apply_context_t::skipping_forward_iterator_t skippy_iter (c, buffer->idx, 1); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 674 | if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 675 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 676 | unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 677 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 678 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 679 | if (!skippy_iter.next ()) return TRACE_RETURN (false); |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 680 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 681 | return TRACE_RETURN ((this+pairSet[index]).apply (c, &valueFormat1, skippy_iter.idx)); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 682 | } |
| 683 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 684 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 685 | TRACE_SANITIZE (this); |
Behdad Esfahbod | eba8b4f | 2010-03-29 00:04:12 -0400 | [diff] [blame] | 686 | |
| 687 | unsigned int len1 = valueFormat1.get_len (); |
| 688 | unsigned int len2 = valueFormat2.get_len (); |
Behdad Esfahbod | 70c9bfd | 2010-05-11 00:23:50 -0400 | [diff] [blame] | 689 | PairSet::sanitize_closure_t closure = { |
| 690 | this, |
| 691 | &valueFormat1, |
| 692 | len1, |
| 693 | 1 + len1 + len2 |
| 694 | }; |
Behdad Esfahbod | eba8b4f | 2010-03-29 00:04:12 -0400 | [diff] [blame] | 695 | |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 696 | return TRACE_RETURN (c->check_struct (this) && coverage.sanitize (c, this) && pairSet.sanitize (c, this, &closure)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 697 | } |
| 698 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 699 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 700 | USHORT format; /* Format identifier--format = 1 */ |
| 701 | OffsetTo<Coverage> |
| 702 | coverage; /* Offset to Coverage table--from |
| 703 | * beginning of subtable */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 704 | ValueFormat valueFormat1; /* Defines the types of data in |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 705 | * ValueRecord1--for the first glyph |
| 706 | * in the pair--may be zero (0) */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 707 | ValueFormat valueFormat2; /* Defines the types of data in |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 708 | * ValueRecord2--for the second glyph |
| 709 | * in the pair--may be zero (0) */ |
| 710 | OffsetArrayOf<PairSet> |
| 711 | pairSet; /* Array of PairSet tables |
| 712 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 713 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 714 | DEFINE_SIZE_ARRAY (10, pairSet); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 715 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 716 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 717 | struct PairPosFormat2 |
| 718 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 719 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 720 | { |
| 721 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 722 | /* (this+coverage).add_coverage (c->input); // Don't need this. */ |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 723 | |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 724 | unsigned int count1 = class1Count; |
| 725 | const ClassDef &klass1 = this+classDef1; |
| 726 | for (unsigned int i = 0; i < count1; i++) |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 727 | klass1.add_class (c->input, i); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 728 | |
| 729 | unsigned int count2 = class2Count; |
| 730 | const ClassDef &klass2 = this+classDef2; |
| 731 | for (unsigned int i = 0; i < count2; i++) |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 732 | klass2.add_class (c->input, i); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 733 | } |
| 734 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 735 | inline const Coverage &get_coverage (void) const |
| 736 | { |
| 737 | return this+coverage; |
| 738 | } |
| 739 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 740 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 741 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 742 | TRACE_APPLY (this); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 743 | hb_buffer_t *buffer = c->buffer; |
| 744 | hb_apply_context_t::skipping_forward_iterator_t skippy_iter (c, buffer->idx, 1); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 745 | if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 746 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 747 | unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 748 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 749 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 750 | if (!skippy_iter.next ()) return TRACE_RETURN (false); |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 751 | |
| 752 | unsigned int len1 = valueFormat1.get_len (); |
| 753 | unsigned int len2 = valueFormat2.get_len (); |
| 754 | unsigned int record_len = len1 + len2; |
| 755 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 756 | unsigned int klass1 = (this+classDef1).get_class (buffer->cur().codepoint); |
| 757 | unsigned int klass2 = (this+classDef2).get_class (buffer->info[skippy_iter.idx].codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 758 | if (unlikely (klass1 >= class1Count || klass2 >= class2Count)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 759 | |
Behdad Esfahbod | 4b8487d | 2010-03-16 03:46:17 -0400 | [diff] [blame] | 760 | const Value *v = &values[record_len * (klass1 * class2Count + klass2)]; |
Behdad Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 761 | valueFormat1.apply_value (c->font, c->direction, this, |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 762 | v, buffer->cur_pos()); |
Behdad Esfahbod | 3b0bb85 | 2011-05-20 15:59:59 -0400 | [diff] [blame] | 763 | valueFormat2.apply_value (c->font, c->direction, this, |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 764 | v + len1, buffer->pos[skippy_iter.idx]); |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 765 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 766 | buffer->idx = skippy_iter.idx; |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 767 | if (len2) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 768 | buffer->idx++; |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 769 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 770 | return TRACE_RETURN (true); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 771 | } |
| 772 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 773 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 774 | TRACE_SANITIZE (this); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 775 | if (!(c->check_struct (this) |
| 776 | && coverage.sanitize (c, this) |
| 777 | && classDef1.sanitize (c, this) |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 778 | && classDef2.sanitize (c, this))) return TRACE_RETURN (false); |
Behdad Esfahbod | 815a73e | 2009-08-14 17:31:16 -0400 | [diff] [blame] | 779 | |
Behdad Esfahbod | eba8b4f | 2010-03-29 00:04:12 -0400 | [diff] [blame] | 780 | unsigned int len1 = valueFormat1.get_len (); |
| 781 | unsigned int len2 = valueFormat2.get_len (); |
| 782 | unsigned int stride = len1 + len2; |
Behdad Esfahbod | 4b8487d | 2010-03-16 03:46:17 -0400 | [diff] [blame] | 783 | unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size (); |
Behdad Esfahbod | eba8b4f | 2010-03-29 00:04:12 -0400 | [diff] [blame] | 784 | unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count; |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 785 | return TRACE_RETURN (c->check_array (values, record_size, count) && |
| 786 | valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) && |
| 787 | valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 788 | } |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 789 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 790 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 791 | USHORT format; /* Format identifier--format = 2 */ |
| 792 | OffsetTo<Coverage> |
| 793 | coverage; /* Offset to Coverage table--from |
| 794 | * beginning of subtable */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 795 | ValueFormat valueFormat1; /* ValueRecord definition--for the |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 796 | * first glyph of the pair--may be zero |
| 797 | * (0) */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 798 | ValueFormat valueFormat2; /* ValueRecord definition--for the |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 799 | * second glyph of the pair--may be |
| 800 | * zero (0) */ |
| 801 | OffsetTo<ClassDef> |
| 802 | classDef1; /* Offset to ClassDef table--from |
| 803 | * beginning of PairPos subtable--for |
| 804 | * the first glyph of the pair */ |
| 805 | OffsetTo<ClassDef> |
| 806 | classDef2; /* Offset to ClassDef table--from |
| 807 | * beginning of PairPos subtable--for |
| 808 | * the second glyph of the pair */ |
| 809 | USHORT class1Count; /* Number of classes in ClassDef1 |
| 810 | * table--includes Class0 */ |
| 811 | USHORT class2Count; /* Number of classes in ClassDef2 |
| 812 | * table--includes Class0 */ |
| 813 | ValueRecord values; /* Matrix of value pairs: |
| 814 | * class1-major, class2-minor, |
| 815 | * Each entry has value1 and value2 */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 816 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 817 | DEFINE_SIZE_ARRAY (16, values); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 818 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 819 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 820 | struct PairPos |
| 821 | { |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 822 | template <typename context_t> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 823 | inline typename context_t::return_t dispatch (context_t *c) const |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 824 | { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 825 | TRACE_DISPATCH (this); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 826 | switch (u.format) { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 827 | case 1: return TRACE_RETURN (c->dispatch (u.format1)); |
| 828 | case 2: return TRACE_RETURN (c->dispatch (u.format2)); |
Behdad Esfahbod | f48ec0e | 2012-11-23 17:23:41 -0500 | [diff] [blame] | 829 | default:return TRACE_RETURN (c->default_return_value ()); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 833 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 834 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 835 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 836 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 837 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 838 | case 2: return TRACE_RETURN (u.format2.sanitize (c)); |
| 839 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 843 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 844 | union { |
| 845 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 846 | PairPosFormat1 format1; |
| 847 | PairPosFormat2 format2; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 848 | } u; |
| 849 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 850 | |
| 851 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 852 | struct EntryExitRecord |
| 853 | { |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 854 | friend struct CursivePosFormat1; |
| 855 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 856 | inline bool sanitize (hb_sanitize_context_t *c, void *base) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 857 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 858 | return TRACE_RETURN (entryAnchor.sanitize (c, base) && exitAnchor.sanitize (c, base)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 859 | } |
| 860 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 861 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 862 | OffsetTo<Anchor> |
| 863 | entryAnchor; /* Offset to EntryAnchor table--from |
| 864 | * beginning of CursivePos |
| 865 | * subtable--may be NULL */ |
| 866 | OffsetTo<Anchor> |
| 867 | exitAnchor; /* Offset to ExitAnchor table--from |
| 868 | * beginning of CursivePos |
| 869 | * subtable--may be NULL */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 870 | public: |
| 871 | DEFINE_SIZE_STATIC (4); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 872 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 873 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 874 | struct CursivePosFormat1 |
| 875 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 876 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 877 | { |
| 878 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 879 | (this+coverage).add_coverage (c->input); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 880 | } |
| 881 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 882 | inline const Coverage &get_coverage (void) const |
| 883 | { |
| 884 | return this+coverage; |
| 885 | } |
| 886 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 887 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 888 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 889 | TRACE_APPLY (this); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 890 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 0f7e6b2 | 2009-05-20 04:16:35 -0400 | [diff] [blame] | 891 | |
| 892 | /* We don't handle mark glyphs here. */ |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 893 | if (unlikely (_hb_glyph_info_is_mark (&buffer->cur()))) return TRACE_RETURN (false); |
Behdad Esfahbod | 0f7e6b2 | 2009-05-20 04:16:35 -0400 | [diff] [blame] | 894 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 895 | hb_apply_context_t::skipping_forward_iterator_t skippy_iter (c, buffer->idx, 1); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 896 | if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); |
Behdad Esfahbod | 0f7e6b2 | 2009-05-20 04:16:35 -0400 | [diff] [blame] | 897 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 898 | const EntryExitRecord &this_record = entryExitRecord[(this+coverage).get_coverage (buffer->cur().codepoint)]; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 899 | if (!this_record.exitAnchor) return TRACE_RETURN (false); |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 900 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 901 | if (!skippy_iter.next ()) return TRACE_RETURN (false); |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 902 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 903 | const EntryExitRecord &next_record = entryExitRecord[(this+coverage).get_coverage (buffer->info[skippy_iter.idx].codepoint)]; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 904 | if (!next_record.entryAnchor) return TRACE_RETURN (false); |
Behdad Esfahbod | af5d02a | 2010-10-27 11:54:26 -0400 | [diff] [blame] | 905 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 906 | unsigned int i = buffer->idx; |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 907 | unsigned int j = skippy_iter.idx; |
Behdad Esfahbod | af5d02a | 2010-10-27 11:54:26 -0400 | [diff] [blame] | 908 | |
| 909 | hb_position_t entry_x, entry_y, exit_x, exit_y; |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 910 | (this+this_record.exitAnchor).get_anchor (c->font, buffer->info[i].codepoint, &exit_x, &exit_y); |
| 911 | (this+next_record.entryAnchor).get_anchor (c->font, buffer->info[j].codepoint, &entry_x, &entry_y); |
Behdad Esfahbod | cc83ae1 | 2009-05-27 00:17:37 -0400 | [diff] [blame] | 912 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 913 | hb_glyph_position_t *pos = buffer->pos; |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 914 | |
| 915 | hb_position_t d; |
| 916 | /* Main-direction adjustment */ |
| 917 | switch (c->direction) { |
| 918 | case HB_DIRECTION_LTR: |
| 919 | pos[i].x_advance = exit_x + pos[i].x_offset; |
| 920 | |
| 921 | d = entry_x + pos[j].x_offset; |
| 922 | pos[j].x_advance -= d; |
| 923 | pos[j].x_offset -= d; |
| 924 | break; |
| 925 | case HB_DIRECTION_RTL: |
| 926 | d = exit_x + pos[i].x_offset; |
| 927 | pos[i].x_advance -= d; |
| 928 | pos[i].x_offset -= d; |
| 929 | |
| 930 | pos[j].x_advance = entry_x + pos[j].x_offset; |
| 931 | break; |
| 932 | case HB_DIRECTION_TTB: |
| 933 | pos[i].y_advance = exit_y + pos[i].y_offset; |
| 934 | |
| 935 | d = entry_y + pos[j].y_offset; |
| 936 | pos[j].y_advance -= d; |
| 937 | pos[j].y_offset -= d; |
| 938 | break; |
| 939 | case HB_DIRECTION_BTT: |
| 940 | d = exit_y + pos[i].y_offset; |
| 941 | pos[i].y_advance -= d; |
| 942 | pos[i].y_offset -= d; |
| 943 | |
| 944 | pos[j].y_advance = entry_y; |
| 945 | break; |
| 946 | case HB_DIRECTION_INVALID: |
| 947 | default: |
| 948 | break; |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 949 | } |
| 950 | |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 951 | /* Cross-direction adjustment */ |
| 952 | if (c->lookup_props & LookupFlag::RightToLeft) { |
| 953 | pos[i].cursive_chain() = j - i; |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 954 | if (likely (HB_DIRECTION_IS_HORIZONTAL (c->direction))) |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 955 | pos[i].y_offset = entry_y - exit_y; |
Behdad Esfahbod | 13528d0 | 2010-10-27 14:09:27 -0400 | [diff] [blame] | 956 | else |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 957 | pos[i].x_offset = entry_x - exit_x; |
| 958 | } else { |
| 959 | pos[j].cursive_chain() = i - j; |
Behdad Esfahbod | 744970a | 2011-05-16 18:15:37 -0400 | [diff] [blame] | 960 | if (likely (HB_DIRECTION_IS_HORIZONTAL (c->direction))) |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 961 | pos[j].y_offset = exit_y - entry_y; |
Behdad Esfahbod | 13528d0 | 2010-10-27 14:09:27 -0400 | [diff] [blame] | 962 | else |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 963 | pos[j].x_offset = exit_x - entry_x; |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 964 | } |
| 965 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 966 | buffer->idx = j; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 967 | return TRACE_RETURN (true); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 968 | } |
| 969 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 970 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 971 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 972 | return TRACE_RETURN (coverage.sanitize (c, this) && entryExitRecord.sanitize (c, this)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 973 | } |
| 974 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 975 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 976 | USHORT format; /* Format identifier--format = 1 */ |
| 977 | OffsetTo<Coverage> |
| 978 | coverage; /* Offset to Coverage table--from |
| 979 | * beginning of subtable */ |
| 980 | ArrayOf<EntryExitRecord> |
| 981 | entryExitRecord; /* Array of EntryExit records--in |
| 982 | * Coverage Index order */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 983 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 984 | DEFINE_SIZE_ARRAY (6, entryExitRecord); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 985 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 986 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 987 | struct CursivePos |
| 988 | { |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 989 | template <typename context_t> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 990 | inline typename context_t::return_t dispatch (context_t *c) const |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 991 | { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 992 | TRACE_DISPATCH (this); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 993 | switch (u.format) { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 994 | case 1: return TRACE_RETURN (c->dispatch (u.format1)); |
Behdad Esfahbod | f48ec0e | 2012-11-23 17:23:41 -0500 | [diff] [blame] | 995 | default:return TRACE_RETURN (c->default_return_value ()); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 996 | } |
| 997 | } |
| 998 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 999 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1000 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1001 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1002 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1003 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 1004 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1008 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1009 | union { |
| 1010 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1011 | CursivePosFormat1 format1; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1012 | } u; |
| 1013 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1014 | |
| 1015 | |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 1016 | typedef AnchorMatrix BaseArray; /* base-major-- |
| 1017 | * in order of BaseCoverage Index--, |
| 1018 | * mark-minor-- |
Behdad Esfahbod | fb3b5cc | 2009-05-21 04:47:05 -0400 | [diff] [blame] | 1019 | * ordered by class--zero-based. */ |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1020 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1021 | struct MarkBasePosFormat1 |
| 1022 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 1023 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 1024 | { |
| 1025 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 1026 | (this+markCoverage).add_coverage (c->input); |
| 1027 | (this+baseCoverage).add_coverage (c->input); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 1028 | } |
| 1029 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1030 | inline const Coverage &get_coverage (void) const |
| 1031 | { |
| 1032 | return this+markCoverage; |
| 1033 | } |
| 1034 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1035 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1036 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1037 | TRACE_APPLY (this); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1038 | hb_buffer_t *buffer = c->buffer; |
| 1039 | unsigned int mark_index = (this+markCoverage).get_coverage (buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1040 | if (likely (mark_index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 1041 | |
| 1042 | /* now we search backwards for a non-mark glyph */ |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1043 | hb_apply_context_t::skipping_backward_iterator_t skippy_iter (c, buffer->idx, 1); |
Behdad Esfahbod | c074ebc | 2013-02-13 11:22:42 -0500 | [diff] [blame] | 1044 | skippy_iter.set_lookup_props (LookupFlag::IgnoreMarks); |
Behdad Esfahbod | 7b84c53 | 2012-06-08 22:04:23 -0400 | [diff] [blame] | 1045 | do { |
Behdad Esfahbod | c074ebc | 2013-02-13 11:22:42 -0500 | [diff] [blame] | 1046 | if (!skippy_iter.prev ()) return TRACE_RETURN (false); |
Behdad Esfahbod | 7b84c53 | 2012-06-08 22:04:23 -0400 | [diff] [blame] | 1047 | /* We only want to attach to the first of a MultipleSubst sequence. Reject others. */ |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1048 | if (0 == _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx])) break; |
Behdad Esfahbod | 7b84c53 | 2012-06-08 22:04:23 -0400 | [diff] [blame] | 1049 | skippy_iter.reject (); |
| 1050 | } while (1); |
Behdad Esfahbod | 0532ed1 | 2009-08-12 15:40:04 -0400 | [diff] [blame] | 1051 | |
Behdad Esfahbod | 101303d | 2013-10-18 00:42:39 +0200 | [diff] [blame] | 1052 | /* Checking that matched glyph is actually a base glyph by GDEF is too strong; disabled */ |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1053 | if (!_hb_glyph_info_is_base_glyph (&buffer->info[skippy_iter.idx])) { /*return TRACE_RETURN (false);*/ } |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 1054 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1055 | unsigned int base_index = (this+baseCoverage).get_coverage (buffer->info[skippy_iter.idx].codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1056 | if (base_index == NOT_COVERED) return TRACE_RETURN (false); |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 1057 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1058 | return TRACE_RETURN ((this+markArray).apply (c, mark_index, base_index, this+baseArray, classCount, skippy_iter.idx)); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1059 | } |
| 1060 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1061 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1062 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1063 | return TRACE_RETURN (c->check_struct (this) && markCoverage.sanitize (c, this) && baseCoverage.sanitize (c, this) && |
| 1064 | markArray.sanitize (c, this) && baseArray.sanitize (c, this, (unsigned int) classCount)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1065 | } |
| 1066 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1067 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1068 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | fb3b5cc | 2009-05-21 04:47:05 -0400 | [diff] [blame] | 1069 | OffsetTo<Coverage> |
| 1070 | markCoverage; /* Offset to MarkCoverage table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1071 | * beginning of MarkBasePos subtable */ |
Behdad Esfahbod | fb3b5cc | 2009-05-21 04:47:05 -0400 | [diff] [blame] | 1072 | OffsetTo<Coverage> |
| 1073 | baseCoverage; /* Offset to BaseCoverage table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1074 | * beginning of MarkBasePos subtable */ |
| 1075 | USHORT classCount; /* Number of classes defined for marks */ |
Behdad Esfahbod | fb3b5cc | 2009-05-21 04:47:05 -0400 | [diff] [blame] | 1076 | OffsetTo<MarkArray> |
| 1077 | markArray; /* Offset to MarkArray table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1078 | * beginning of MarkBasePos subtable */ |
Behdad Esfahbod | fb3b5cc | 2009-05-21 04:47:05 -0400 | [diff] [blame] | 1079 | OffsetTo<BaseArray> |
| 1080 | baseArray; /* Offset to BaseArray table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1081 | * beginning of MarkBasePos subtable */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1082 | public: |
| 1083 | DEFINE_SIZE_STATIC (12); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1084 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1085 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1086 | struct MarkBasePos |
| 1087 | { |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 1088 | template <typename context_t> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1089 | inline typename context_t::return_t dispatch (context_t *c) const |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1090 | { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1091 | TRACE_DISPATCH (this); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1092 | switch (u.format) { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1093 | case 1: return TRACE_RETURN (c->dispatch (u.format1)); |
Behdad Esfahbod | f48ec0e | 2012-11-23 17:23:41 -0500 | [diff] [blame] | 1094 | default:return TRACE_RETURN (c->default_return_value ()); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1098 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1099 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1100 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1101 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1102 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 1103 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1107 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1108 | union { |
| 1109 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1110 | MarkBasePosFormat1 format1; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1111 | } u; |
| 1112 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1113 | |
| 1114 | |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 1115 | typedef AnchorMatrix LigatureAttach; /* component-major-- |
| 1116 | * in order of writing direction--, |
| 1117 | * mark-minor-- |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1118 | * ordered by class--zero-based. */ |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1119 | |
Behdad Esfahbod | 3564ee5 | 2009-08-14 18:32:56 -0400 | [diff] [blame] | 1120 | typedef OffsetListOf<LigatureAttach> LigatureArray; |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1121 | /* Array of LigatureAttach |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1122 | * tables ordered by |
| 1123 | * LigatureCoverage Index */ |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1124 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1125 | struct MarkLigPosFormat1 |
| 1126 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 1127 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 1128 | { |
| 1129 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 1130 | (this+markCoverage).add_coverage (c->input); |
| 1131 | (this+ligatureCoverage).add_coverage (c->input); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 1132 | } |
| 1133 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1134 | inline const Coverage &get_coverage (void) const |
| 1135 | { |
| 1136 | return this+markCoverage; |
| 1137 | } |
| 1138 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1139 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1140 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1141 | TRACE_APPLY (this); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1142 | hb_buffer_t *buffer = c->buffer; |
| 1143 | unsigned int mark_index = (this+markCoverage).get_coverage (buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1144 | if (likely (mark_index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1145 | |
| 1146 | /* now we search backwards for a non-mark glyph */ |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1147 | hb_apply_context_t::skipping_backward_iterator_t skippy_iter (c, buffer->idx, 1); |
Behdad Esfahbod | c074ebc | 2013-02-13 11:22:42 -0500 | [diff] [blame] | 1148 | skippy_iter.set_lookup_props (LookupFlag::IgnoreMarks); |
| 1149 | if (!skippy_iter.prev ()) return TRACE_RETURN (false); |
Behdad Esfahbod | 0532ed1 | 2009-08-12 15:40:04 -0400 | [diff] [blame] | 1150 | |
Behdad Esfahbod | 101303d | 2013-10-18 00:42:39 +0200 | [diff] [blame] | 1151 | /* Checking that matched glyph is actually a ligature by GDEF is too strong; disabled */ |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1152 | if (!_hb_glyph_info_is_ligature (&buffer->info[skippy_iter.idx])) { /*return TRACE_RETURN (false);*/ } |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1153 | |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 1154 | unsigned int j = skippy_iter.idx; |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1155 | unsigned int lig_index = (this+ligatureCoverage).get_coverage (buffer->info[j].codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1156 | if (lig_index == NOT_COVERED) return TRACE_RETURN (false); |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1157 | |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1158 | const LigatureArray& lig_array = this+ligatureArray; |
Behdad Esfahbod | 3564ee5 | 2009-08-14 18:32:56 -0400 | [diff] [blame] | 1159 | const LigatureAttach& lig_attach = lig_array[lig_index]; |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 1160 | |
| 1161 | /* Find component to attach to */ |
Behdad Esfahbod | b2b18ef | 2009-08-14 19:37:18 -0400 | [diff] [blame] | 1162 | unsigned int comp_count = lig_attach.rows; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1163 | if (unlikely (!comp_count)) return TRACE_RETURN (false); |
| 1164 | |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1165 | /* We must now check whether the ligature ID of the current mark glyph |
| 1166 | * is identical to the ligature ID of the found ligature. If yes, we |
| 1167 | * can directly use the component index. If not, we attach the mark |
| 1168 | * glyph to the last component of the ligature. */ |
Behdad Esfahbod | 0aef425 | 2012-07-30 00:55:15 -0400 | [diff] [blame] | 1169 | unsigned int comp_index; |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1170 | unsigned int lig_id = _hb_glyph_info_get_lig_id (&buffer->info[j]); |
| 1171 | unsigned int mark_id = _hb_glyph_info_get_lig_id (&buffer->cur()); |
| 1172 | unsigned int mark_comp = _hb_glyph_info_get_lig_comp (&buffer->cur()); |
Behdad Esfahbod | 0aef425 | 2012-07-30 00:55:15 -0400 | [diff] [blame] | 1173 | if (lig_id && lig_id == mark_id && mark_comp > 0) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1174 | comp_index = MIN (comp_count, _hb_glyph_info_get_lig_comp (&buffer->cur())) - 1; |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1175 | else |
Behdad Esfahbod | b2b18ef | 2009-08-14 19:37:18 -0400 | [diff] [blame] | 1176 | comp_index = comp_count - 1; |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1177 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1178 | return TRACE_RETURN ((this+markArray).apply (c, mark_index, comp_index, lig_attach, classCount, j)); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1179 | } |
| 1180 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1181 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1182 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1183 | return TRACE_RETURN (c->check_struct (this) && markCoverage.sanitize (c, this) && ligatureCoverage.sanitize (c, this) && |
| 1184 | markArray.sanitize (c, this) && ligatureArray.sanitize (c, this, (unsigned int) classCount)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1185 | } |
| 1186 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1187 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1188 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1189 | OffsetTo<Coverage> |
| 1190 | markCoverage; /* Offset to Mark Coverage table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1191 | * beginning of MarkLigPos subtable */ |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1192 | OffsetTo<Coverage> |
| 1193 | ligatureCoverage; /* Offset to Ligature Coverage |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1194 | * table--from beginning of MarkLigPos |
| 1195 | * subtable */ |
| 1196 | USHORT classCount; /* Number of defined mark classes */ |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1197 | OffsetTo<MarkArray> |
| 1198 | markArray; /* Offset to MarkArray table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1199 | * beginning of MarkLigPos subtable */ |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1200 | OffsetTo<LigatureArray> |
| 1201 | ligatureArray; /* Offset to LigatureArray table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1202 | * beginning of MarkLigPos subtable */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1203 | public: |
| 1204 | DEFINE_SIZE_STATIC (12); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1205 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1206 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1207 | struct MarkLigPos |
| 1208 | { |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 1209 | template <typename context_t> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1210 | inline typename context_t::return_t dispatch (context_t *c) const |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1211 | { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1212 | TRACE_DISPATCH (this); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1213 | switch (u.format) { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1214 | case 1: return TRACE_RETURN (c->dispatch (u.format1)); |
Behdad Esfahbod | f48ec0e | 2012-11-23 17:23:41 -0500 | [diff] [blame] | 1215 | default:return TRACE_RETURN (c->default_return_value ()); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1216 | } |
| 1217 | } |
| 1218 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1219 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1220 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1221 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1222 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1223 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 1224 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1228 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1229 | union { |
| 1230 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1231 | MarkLigPosFormat1 format1; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1232 | } u; |
| 1233 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1234 | |
| 1235 | |
Behdad Esfahbod | cb71a2f | 2009-08-14 18:14:03 -0400 | [diff] [blame] | 1236 | typedef AnchorMatrix Mark2Array; /* mark2-major-- |
| 1237 | * in order of Mark2Coverage Index--, |
| 1238 | * mark1-minor-- |
| 1239 | * ordered by class--zero-based. */ |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1240 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1241 | struct MarkMarkPosFormat1 |
| 1242 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 1243 | inline void collect_glyphs (hb_collect_glyphs_context_t *c) const |
| 1244 | { |
| 1245 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 8303593 | 2012-12-04 17:08:41 -0500 | [diff] [blame] | 1246 | (this+mark1Coverage).add_coverage (c->input); |
| 1247 | (this+mark2Coverage).add_coverage (c->input); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 1248 | } |
| 1249 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1250 | inline const Coverage &get_coverage (void) const |
| 1251 | { |
| 1252 | return this+mark1Coverage; |
| 1253 | } |
| 1254 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1255 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1256 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1257 | TRACE_APPLY (this); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1258 | hb_buffer_t *buffer = c->buffer; |
| 1259 | unsigned int mark1_index = (this+mark1Coverage).get_coverage (buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1260 | if (likely (mark1_index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1261 | |
| 1262 | /* now we search backwards for a suitable mark glyph until a non-mark glyph */ |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1263 | hb_apply_context_t::skipping_backward_iterator_t skippy_iter (c, buffer->idx, 1); |
Behdad Esfahbod | c074ebc | 2013-02-13 11:22:42 -0500 | [diff] [blame] | 1264 | skippy_iter.set_lookup_props (c->lookup_props & ~LookupFlag::IgnoreFlags); |
| 1265 | if (!skippy_iter.prev ()) return TRACE_RETURN (false); |
Behdad Esfahbod | 0532ed1 | 2009-08-12 15:40:04 -0400 | [diff] [blame] | 1266 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1267 | if (!_hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx])) { return TRACE_RETURN (false); } |
Behdad Esfahbod | 80ea5bd | 2009-05-26 17:58:37 -0400 | [diff] [blame] | 1268 | |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 1269 | unsigned int j = skippy_iter.idx; |
| 1270 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1271 | unsigned int id1 = _hb_glyph_info_get_lig_id (&buffer->cur()); |
| 1272 | unsigned int id2 = _hb_glyph_info_get_lig_id (&buffer->info[j]); |
| 1273 | unsigned int comp1 = _hb_glyph_info_get_lig_comp (&buffer->cur()); |
| 1274 | unsigned int comp2 = _hb_glyph_info_get_lig_comp (&buffer->info[j]); |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1275 | |
Behdad Esfahbod | 5d874d5 | 2012-07-28 21:05:25 -0400 | [diff] [blame] | 1276 | if (likely (id1 == id2)) { |
| 1277 | if (id1 == 0) /* Marks belonging to the same base. */ |
| 1278 | goto good; |
| 1279 | else if (comp1 == comp2) /* Marks belonging to the same ligature component. */ |
| 1280 | goto good; |
| 1281 | } else { |
| 1282 | /* If ligature ids don't match, it may be the case that one of the marks |
| 1283 | * itself is a ligature. In which case match. */ |
| 1284 | if ((id1 > 0 && !comp1) || (id2 > 0 && !comp2)) |
| 1285 | goto good; |
| 1286 | } |
| 1287 | |
| 1288 | /* Didn't match. */ |
| 1289 | return TRACE_RETURN (false); |
| 1290 | |
| 1291 | good: |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 1292 | unsigned int mark2_index = (this+mark2Coverage).get_coverage (buffer->info[j].codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1293 | if (mark2_index == NOT_COVERED) return TRACE_RETURN (false); |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1294 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1295 | return TRACE_RETURN ((this+mark1Array).apply (c, mark1_index, mark2_index, this+mark2Array, classCount, j)); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1296 | } |
| 1297 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1298 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1299 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1300 | return TRACE_RETURN (c->check_struct (this) && mark1Coverage.sanitize (c, this) && |
| 1301 | mark2Coverage.sanitize (c, this) && mark1Array.sanitize (c, this) |
| 1302 | && mark2Array.sanitize (c, this, (unsigned int) classCount)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1303 | } |
| 1304 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1305 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1306 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1307 | OffsetTo<Coverage> |
| 1308 | mark1Coverage; /* Offset to Combining Mark1 Coverage |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1309 | * table--from beginning of MarkMarkPos |
| 1310 | * subtable */ |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1311 | OffsetTo<Coverage> |
| 1312 | mark2Coverage; /* Offset to Combining Mark2 Coverage |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1313 | * table--from beginning of MarkMarkPos |
| 1314 | * subtable */ |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1315 | USHORT classCount; /* Number of defined mark classes */ |
| 1316 | OffsetTo<MarkArray> |
| 1317 | mark1Array; /* Offset to Mark1Array table--from |
| 1318 | * beginning of MarkMarkPos subtable */ |
| 1319 | OffsetTo<Mark2Array> |
| 1320 | mark2Array; /* Offset to Mark2Array table--from |
| 1321 | * beginning of MarkMarkPos subtable */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1322 | public: |
| 1323 | DEFINE_SIZE_STATIC (12); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1324 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1325 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1326 | struct MarkMarkPos |
| 1327 | { |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 1328 | template <typename context_t> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1329 | inline typename context_t::return_t dispatch (context_t *c) const |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1330 | { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1331 | TRACE_DISPATCH (this); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1332 | switch (u.format) { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1333 | case 1: return TRACE_RETURN (c->dispatch (u.format1)); |
Behdad Esfahbod | f48ec0e | 2012-11-23 17:23:41 -0500 | [diff] [blame] | 1334 | default:return TRACE_RETURN (c->default_return_value ()); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1335 | } |
| 1336 | } |
| 1337 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1338 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1339 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1340 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1341 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1342 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 1343 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1344 | } |
| 1345 | } |
| 1346 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1347 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1348 | union { |
| 1349 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1350 | MarkMarkPosFormat1 format1; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1351 | } u; |
| 1352 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1353 | |
| 1354 | |
Behdad Esfahbod | 08f1eed | 2012-11-23 16:51:43 -0500 | [diff] [blame] | 1355 | struct ContextPos : Context {}; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1356 | |
Behdad Esfahbod | 08f1eed | 2012-11-23 16:51:43 -0500 | [diff] [blame] | 1357 | struct ChainContextPos : ChainContext {}; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1358 | |
Behdad Esfahbod | 653eeb2 | 2012-11-23 16:57:36 -0500 | [diff] [blame] | 1359 | struct ExtensionPos : Extension<ExtensionPos> |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1360 | { |
Behdad Esfahbod | 7dddd4e | 2012-11-23 17:04:55 -0500 | [diff] [blame] | 1361 | typedef struct PosLookupSubTable LookupSubTable; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1362 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1363 | |
| 1364 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1365 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1366 | /* |
| 1367 | * PosLookup |
| 1368 | */ |
| 1369 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1370 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1371 | struct PosLookupSubTable |
| 1372 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1373 | friend struct PosLookup; |
| 1374 | |
Behdad Esfahbod | c6035cf | 2012-04-12 13:23:59 -0400 | [diff] [blame] | 1375 | enum Type { |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 1376 | Single = 1, |
| 1377 | Pair = 2, |
| 1378 | Cursive = 3, |
| 1379 | MarkBase = 4, |
| 1380 | MarkLig = 5, |
| 1381 | MarkMark = 6, |
| 1382 | Context = 7, |
| 1383 | ChainContext = 8, |
Behdad Esfahbod | 8f034d5 | 2009-08-18 16:41:59 -0400 | [diff] [blame] | 1384 | Extension = 9 |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 1385 | }; |
| 1386 | |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 1387 | template <typename context_t> |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1388 | inline typename context_t::return_t dispatch (context_t *c, unsigned int lookup_type) const |
Behdad Esfahbod | faf0f20 | 2012-06-09 03:02:36 -0400 | [diff] [blame] | 1389 | { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1390 | TRACE_DISPATCH (this); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1391 | switch (lookup_type) { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1392 | case Single: return TRACE_RETURN (u.single.dispatch (c)); |
| 1393 | case Pair: return TRACE_RETURN (u.pair.dispatch (c)); |
| 1394 | case Cursive: return TRACE_RETURN (u.cursive.dispatch (c)); |
| 1395 | case MarkBase: return TRACE_RETURN (u.markBase.dispatch (c)); |
| 1396 | case MarkLig: return TRACE_RETURN (u.markLig.dispatch (c)); |
| 1397 | case MarkMark: return TRACE_RETURN (u.markMark.dispatch (c)); |
| 1398 | case Context: return TRACE_RETURN (u.context.dispatch (c)); |
| 1399 | case ChainContext: return TRACE_RETURN (u.chainContext.dispatch (c)); |
| 1400 | case Extension: return TRACE_RETURN (u.extension.dispatch (c)); |
Behdad Esfahbod | f48ec0e | 2012-11-23 17:23:41 -0500 | [diff] [blame] | 1401 | default: return TRACE_RETURN (c->default_return_value ()); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1402 | } |
Behdad Esfahbod | faf0f20 | 2012-06-09 03:02:36 -0400 | [diff] [blame] | 1403 | } |
| 1404 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1405 | inline bool sanitize (hb_sanitize_context_t *c, unsigned int lookup_type) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1406 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1407 | if (!u.header.sub_format.sanitize (c)) |
Behdad Esfahbod | faf0f20 | 2012-06-09 03:02:36 -0400 | [diff] [blame] | 1408 | return TRACE_RETURN (false); |
Behdad Esfahbod | fe9bc07 | 2010-05-10 21:39:24 -0400 | [diff] [blame] | 1409 | switch (lookup_type) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1410 | case Single: return TRACE_RETURN (u.single.sanitize (c)); |
| 1411 | case Pair: return TRACE_RETURN (u.pair.sanitize (c)); |
| 1412 | case Cursive: return TRACE_RETURN (u.cursive.sanitize (c)); |
| 1413 | case MarkBase: return TRACE_RETURN (u.markBase.sanitize (c)); |
| 1414 | case MarkLig: return TRACE_RETURN (u.markLig.sanitize (c)); |
| 1415 | case MarkMark: return TRACE_RETURN (u.markMark.sanitize (c)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1416 | case Context: return TRACE_RETURN (u.context.sanitize (c)); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1417 | case ChainContext: return TRACE_RETURN (u.chainContext.sanitize (c)); |
| 1418 | case Extension: return TRACE_RETURN (u.extension.sanitize (c)); |
| 1419 | default: return TRACE_RETURN (true); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1420 | } |
| 1421 | } |
| 1422 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1423 | protected: |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1424 | union { |
Behdad Esfahbod | 4e766ff | 2012-06-09 02:53:57 -0400 | [diff] [blame] | 1425 | struct { |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 1426 | USHORT sub_format; |
Behdad Esfahbod | 4e766ff | 2012-06-09 02:53:57 -0400 | [diff] [blame] | 1427 | } header; |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1428 | SinglePos single; |
| 1429 | PairPos pair; |
| 1430 | CursivePos cursive; |
| 1431 | MarkBasePos markBase; |
| 1432 | MarkLigPos markLig; |
| 1433 | MarkMarkPos markMark; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1434 | ContextPos context; |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1435 | ChainContextPos chainContext; |
| 1436 | ExtensionPos extension; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1437 | } u; |
Behdad Esfahbod | ed07422 | 2010-05-10 18:08:46 -0400 | [diff] [blame] | 1438 | public: |
Behdad Esfahbod | 4e766ff | 2012-06-09 02:53:57 -0400 | [diff] [blame] | 1439 | DEFINE_SIZE_UNION (2, header.sub_format); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1440 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1441 | |
| 1442 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1443 | struct PosLookup : Lookup |
| 1444 | { |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 1445 | inline const PosLookupSubTable& get_subtable (unsigned int i) const |
| 1446 | { return this+CastR<OffsetArrayOf<PosLookupSubTable> > (subTable)[i]; } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1447 | |
Behdad Esfahbod | e015b8f | 2013-05-03 17:34:29 -0400 | [diff] [blame] | 1448 | inline bool is_reverse (void) const |
| 1449 | { |
| 1450 | return false; |
| 1451 | } |
| 1452 | |
Behdad Esfahbod | 780cd93 | 2013-05-03 17:33:16 -0400 | [diff] [blame] | 1453 | inline hb_collect_glyphs_context_t::return_t collect_glyphs (hb_collect_glyphs_context_t *c) const |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 1454 | { |
| 1455 | TRACE_COLLECT_GLYPHS (this); |
Behdad Esfahbod | 1bcfa06 | 2012-12-04 16:58:09 -0500 | [diff] [blame] | 1456 | c->set_recurse_func (NULL); |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1457 | return TRACE_RETURN (dispatch (c)); |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 1458 | } |
| 1459 | |
Behdad Esfahbod | a878c58 | 2012-08-01 21:18:54 -0400 | [diff] [blame] | 1460 | template <typename set_t> |
| 1461 | inline void add_coverage (set_t *glyphs) const |
| 1462 | { |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 1463 | hb_get_coverage_context_t c; |
Behdad Esfahbod | a878c58 | 2012-08-01 21:18:54 -0400 | [diff] [blame] | 1464 | const Coverage *last = NULL; |
| 1465 | unsigned int count = get_subtable_count (); |
| 1466 | for (unsigned int i = 0; i < count; i++) { |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1467 | const Coverage *coverage = &get_subtable (i).dispatch (&c, get_type ()); |
Behdad Esfahbod | 2005fa5 | 2012-11-22 14:38:10 -0500 | [diff] [blame] | 1468 | if (coverage != last) { |
| 1469 | coverage->add_coverage (glyphs); |
| 1470 | last = coverage; |
Behdad Esfahbod | a878c58 | 2012-08-01 21:18:54 -0400 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | } |
| 1474 | |
Behdad Esfahbod | 41ae674 | 2012-04-11 17:11:05 -0400 | [diff] [blame] | 1475 | inline bool apply_once (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1476 | { |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1477 | TRACE_APPLY (this); |
Behdad Esfahbod | 407fc12 | 2013-02-13 11:13:06 -0500 | [diff] [blame] | 1478 | if (!c->check_glyph_property (&c->buffer->cur(), c->lookup_props)) |
Behdad Esfahbod | 26514d5 | 2012-11-23 18:13:48 -0500 | [diff] [blame] | 1479 | return TRACE_RETURN (false); |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1480 | return TRACE_RETURN (dispatch (c)); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1481 | } |
| 1482 | |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1483 | static bool apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index); |
| 1484 | |
Behdad Esfahbod | ee5464d | 2013-03-09 01:59:30 -0500 | [diff] [blame] | 1485 | template <typename context_t> |
| 1486 | static inline typename context_t::return_t dispatch_recurse_func (context_t *c, unsigned int lookup_index); |
| 1487 | |
| 1488 | template <typename context_t> |
| 1489 | inline typename context_t::return_t dispatch (context_t *c) const |
| 1490 | { |
| 1491 | TRACE_DISPATCH (this); |
| 1492 | unsigned int lookup_type = get_type (); |
| 1493 | unsigned int count = get_subtable_count (); |
| 1494 | for (unsigned int i = 0; i < count; i++) { |
| 1495 | typename context_t::return_t r = get_subtable (i).dispatch (c, lookup_type); |
| 1496 | if (c->stop_sublookup_iteration (r)) |
| 1497 | return TRACE_RETURN (r); |
| 1498 | } |
| 1499 | return TRACE_RETURN (c->default_return_value ()); |
| 1500 | } |
| 1501 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1502 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1503 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1504 | if (unlikely (!Lookup::sanitize (c))) return TRACE_RETURN (false); |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 1505 | OffsetArrayOf<PosLookupSubTable> &list = CastR<OffsetArrayOf<PosLookupSubTable> > (subTable); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1506 | return TRACE_RETURN (list.sanitize (c, this, get_type ())); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1507 | } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1508 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1509 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1510 | typedef OffsetListOf<PosLookup> PosLookupList; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1511 | |
| 1512 | /* |
Behdad Esfahbod | ae9877d | 2011-08-17 14:43:45 +0200 | [diff] [blame] | 1513 | * GPOS -- The Glyph Positioning Table |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1514 | */ |
| 1515 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1516 | struct GPOS : GSUBGPOS |
| 1517 | { |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 1518 | static const hb_tag_t tableTag = HB_OT_TAG_GPOS; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1519 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1520 | inline const PosLookup& get_lookup (unsigned int i) const |
Behdad Esfahbod | 187454c | 2010-04-23 16:35:01 -0400 | [diff] [blame] | 1521 | { return CastR<PosLookup> (GSUBGPOS::get_lookup (i)); } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1522 | |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 1523 | static inline void position_start (hb_font_t *font, hb_buffer_t *buffer); |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 1524 | static inline void position_finish (hb_font_t *font, hb_buffer_t *buffer); |
Behdad Esfahbod | 1e7c1fc | 2010-10-27 22:48:31 -0400 | [diff] [blame] | 1525 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1526 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1527 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1528 | if (unlikely (!GSUBGPOS::sanitize (c))) return TRACE_RETURN (false); |
Behdad Esfahbod | 187454c | 2010-04-23 16:35:01 -0400 | [diff] [blame] | 1529 | OffsetTo<PosLookupList> &list = CastR<OffsetTo<PosLookupList> > (lookupList); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1530 | return TRACE_RETURN (list.sanitize (c, this)); |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1531 | } |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1532 | public: |
| 1533 | DEFINE_SIZE_STATIC (10); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1534 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1535 | |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1536 | |
| 1537 | static void |
| 1538 | fix_cursive_minor_offset (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction) |
| 1539 | { |
Behdad Esfahbod | df5d5c6 | 2012-08-23 09:33:30 -0400 | [diff] [blame] | 1540 | unsigned int j = pos[i].cursive_chain(); |
| 1541 | if (likely (!j)) |
| 1542 | return; |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1543 | |
Behdad Esfahbod | df5d5c6 | 2012-08-23 09:33:30 -0400 | [diff] [blame] | 1544 | j += i; |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1545 | |
Behdad Esfahbod | df5d5c6 | 2012-08-23 09:33:30 -0400 | [diff] [blame] | 1546 | pos[i].cursive_chain() = 0; |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1547 | |
Behdad Esfahbod | df5d5c6 | 2012-08-23 09:33:30 -0400 | [diff] [blame] | 1548 | fix_cursive_minor_offset (pos, j, direction); |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1549 | |
Behdad Esfahbod | df5d5c6 | 2012-08-23 09:33:30 -0400 | [diff] [blame] | 1550 | if (HB_DIRECTION_IS_HORIZONTAL (direction)) |
| 1551 | pos[i].y_offset += pos[j].y_offset; |
| 1552 | else |
| 1553 | pos[i].x_offset += pos[j].x_offset; |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | static void |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 1557 | fix_mark_attachment (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction) |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1558 | { |
| 1559 | if (likely (!(pos[i].attach_lookback()))) |
| 1560 | return; |
| 1561 | |
| 1562 | unsigned int j = i - pos[i].attach_lookback(); |
| 1563 | |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1564 | pos[i].x_offset += pos[j].x_offset; |
| 1565 | pos[i].y_offset += pos[j].y_offset; |
| 1566 | |
| 1567 | if (HB_DIRECTION_IS_FORWARD (direction)) |
Behdad Esfahbod | 21deab2 | 2011-05-30 11:08:40 -0400 | [diff] [blame] | 1568 | for (unsigned int k = j; k < i; k++) { |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1569 | pos[i].x_offset -= pos[k].x_advance; |
| 1570 | pos[i].y_offset -= pos[k].y_advance; |
| 1571 | } |
| 1572 | else |
Behdad Esfahbod | 21deab2 | 2011-05-30 11:08:40 -0400 | [diff] [blame] | 1573 | for (unsigned int k = j + 1; k < i + 1; k++) { |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1574 | pos[i].x_offset += pos[k].x_advance; |
| 1575 | pos[i].y_offset += pos[k].y_advance; |
| 1576 | } |
| 1577 | } |
| 1578 | |
Behdad Esfahbod | 1e7c1fc | 2010-10-27 22:48:31 -0400 | [diff] [blame] | 1579 | void |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 1580 | GPOS::position_start (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer) |
Behdad Esfahbod | a9ad3d3 | 2011-07-28 15:42:18 -0400 | [diff] [blame] | 1581 | { |
| 1582 | buffer->clear_positions (); |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 1583 | |
| 1584 | unsigned int count = buffer->len; |
| 1585 | for (unsigned int i = 0; i < count; i++) |
| 1586 | buffer->pos[i].attach_lookback() = buffer->pos[i].cursive_chain() = 0; |
Behdad Esfahbod | a9ad3d3 | 2011-07-28 15:42:18 -0400 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | void |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 1590 | GPOS::position_finish (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer) |
Behdad Esfahbod | 1e7c1fc | 2010-10-27 22:48:31 -0400 | [diff] [blame] | 1591 | { |
Ryan Lortie | 70566be | 2011-04-15 18:32:36 -0400 | [diff] [blame] | 1592 | unsigned int len; |
| 1593 | hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, &len); |
Behdad Esfahbod | 1e7c1fc | 2010-10-27 22:48:31 -0400 | [diff] [blame] | 1594 | hb_direction_t direction = buffer->props.direction; |
| 1595 | |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1596 | /* Handle cursive connections */ |
| 1597 | for (unsigned int i = 0; i < len; i++) |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1598 | fix_cursive_minor_offset (pos, i, direction); |
Behdad Esfahbod | 1e7c1fc | 2010-10-27 22:48:31 -0400 | [diff] [blame] | 1599 | |
| 1600 | /* Handle attachments */ |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 1601 | for (unsigned int i = 0; i < len; i++) |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 1602 | fix_mark_attachment (pos, i, direction); |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 1603 | |
Behdad Esfahbod | 101303d | 2013-10-18 00:42:39 +0200 | [diff] [blame] | 1604 | _hb_buffer_deallocate_gsubgpos_vars (buffer); |
Behdad Esfahbod | 1e7c1fc | 2010-10-27 22:48:31 -0400 | [diff] [blame] | 1605 | } |
| 1606 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1607 | |
| 1608 | /* Out-of-class implementation for methods recursing */ |
| 1609 | |
Behdad Esfahbod | c6fb843 | 2012-11-23 18:04:08 -0500 | [diff] [blame] | 1610 | template <typename context_t> |
Behdad Esfahbod | 6faff8e | 2014-04-28 14:29:39 -0700 | [diff] [blame] | 1611 | /*static*/ inline typename context_t::return_t PosLookup::dispatch_recurse_func (context_t *c, unsigned int lookup_index) |
Behdad Esfahbod | c6fb843 | 2012-11-23 18:04:08 -0500 | [diff] [blame] | 1612 | { |
| 1613 | const GPOS &gpos = *(hb_ot_layout_from_face (c->face)->gpos); |
| 1614 | const PosLookup &l = gpos.get_lookup (lookup_index); |
Behdad Esfahbod | 9c5a9ee | 2013-03-09 01:55:04 -0500 | [diff] [blame] | 1615 | return l.dispatch (c); |
Behdad Esfahbod | c6fb843 | 2012-11-23 18:04:08 -0500 | [diff] [blame] | 1616 | } |
| 1617 | |
Behdad Esfahbod | 6faff8e | 2014-04-28 14:29:39 -0700 | [diff] [blame] | 1618 | /*static*/ inline bool PosLookup::apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index) |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1619 | { |
Behdad Esfahbod | ea278d3 | 2012-07-27 02:12:28 -0400 | [diff] [blame] | 1620 | const GPOS &gpos = *(hb_ot_layout_from_face (c->face)->gpos); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1621 | const PosLookup &l = gpos.get_lookup (lookup_index); |
Behdad Esfahbod | 4c4e8f0 | 2012-11-24 01:13:20 -0500 | [diff] [blame] | 1622 | unsigned int saved_lookup_props = c->lookup_props; |
Behdad Esfahbod | ec35a72 | 2012-11-22 16:05:59 -0500 | [diff] [blame] | 1623 | c->set_lookup (l); |
Behdad Esfahbod | 4c4e8f0 | 2012-11-24 01:13:20 -0500 | [diff] [blame] | 1624 | bool ret = l.apply_once (c); |
| 1625 | c->lookup_props = saved_lookup_props; |
Behdad Esfahbod | 4c4e8f0 | 2012-11-24 01:13:20 -0500 | [diff] [blame] | 1626 | return ret; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | |
Behdad Esfahbod | 194d456 | 2010-10-27 23:09:10 -0400 | [diff] [blame] | 1630 | #undef attach_lookback |
| 1631 | #undef cursive_chain |
| 1632 | |
| 1633 | |
Behdad Esfahbod | 7d52e66 | 2012-11-16 18:49:54 -0800 | [diff] [blame] | 1634 | } /* namespace OT */ |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 1635 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 1636 | |
Behdad Esfahbod | 7a750ac | 2011-08-17 14:19:59 +0200 | [diff] [blame] | 1637 | #endif /* HB_OT_LAYOUT_GPOS_TABLE_HH */ |