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