Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007,2008,2009 Red Hat, Inc. |
| 3 | * |
| 4 | * This is part of HarfBuzz, an OpenType Layout engine library. |
| 5 | * |
| 6 | * Permission is hereby granted, without written agreement and without |
| 7 | * license or royalty fees, to use, copy, modify, and distribute this |
| 8 | * software and its documentation for any purpose, provided that the |
| 9 | * above copyright notice and the following two paragraphs appear in |
| 10 | * all copies of this software. |
| 11 | * |
| 12 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 13 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 14 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 15 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 16 | * DAMAGE. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 21 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 22 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 23 | * |
| 24 | * Red Hat Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 27 | #ifndef HB_OT_LAYOUT_GPOS_PRIVATE_HH |
| 28 | #define HB_OT_LAYOUT_GPOS_PRIVATE_HH |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 29 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 30 | #include "hb-ot-layout-gsubgpos-private.hh" |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 31 | |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 32 | #define HB_OT_LAYOUT_GPOS_NO_LAST ((unsigned int) -1) |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 33 | |
| 34 | /* Shared Tables: ValueRecord, Anchor Table, and MarkArray */ |
| 35 | |
| 36 | typedef SHORT Value; |
| 37 | typedef Value ValueRecord[]; |
| 38 | |
Behdad Esfahbod | fca6a0d | 2009-05-21 04:49:04 -0400 | [diff] [blame] | 39 | struct ValueFormat : USHORT |
| 40 | { |
| 41 | enum |
| 42 | { |
| 43 | xPlacement = 0x0001, /* Includes horizontal adjustment for placement */ |
| 44 | yPlacement = 0x0002, /* Includes vertical adjustment for placement */ |
| 45 | xAdvance = 0x0004, /* Includes horizontal adjustment for advance */ |
| 46 | yAdvance = 0x0008, /* Includes vertical adjustment for advance */ |
| 47 | xPlaDevice = 0x0010, /* Includes horizontal Device table for placement */ |
| 48 | yPlaDevice = 0x0020, /* Includes vertical Device table for placement */ |
| 49 | xAdvDevice = 0x0040, /* Includes horizontal Device table for advance */ |
| 50 | yAdvDevice = 0x0080, /* Includes vertical Device table for advance */ |
Behdad Esfahbod | e4b92b8 | 2009-05-26 15:38:53 -0400 | [diff] [blame] | 51 | ignored = 0x0F00, /* Was used in TrueType Open for MM fonts */ |
Behdad Esfahbod | fca6a0d | 2009-05-21 04:49:04 -0400 | [diff] [blame] | 52 | reserved = 0xF000, /* For future use */ |
| 53 | }; |
| 54 | |
| 55 | inline unsigned int get_len () const |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 56 | { return _hb_popcount32 ((unsigned int) *this); } |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 57 | inline unsigned int get_size () const |
| 58 | { return get_len () * sizeof (Value); } |
Behdad Esfahbod | fca6a0d | 2009-05-21 04:49:04 -0400 | [diff] [blame] | 59 | |
Behdad Esfahbod | 15164d9 | 2009-08-04 13:57:41 -0400 | [diff] [blame] | 60 | void apply_value (hb_ot_layout_context_t *context, |
| 61 | const char *base, |
| 62 | const Value *values, |
| 63 | hb_internal_glyph_position_t *glyph_pos) const |
Behdad Esfahbod | fca6a0d | 2009-05-21 04:49:04 -0400 | [diff] [blame] | 64 | { |
| 65 | unsigned int x_ppem, y_ppem; |
| 66 | hb_16dot16_t x_scale, y_scale; |
Behdad Esfahbod | fca6a0d | 2009-05-21 04:49:04 -0400 | [diff] [blame] | 67 | unsigned int format = *this; |
| 68 | |
| 69 | if (!format) |
| 70 | return; |
| 71 | |
| 72 | /* All fields are options. Only those available advance the value |
| 73 | * pointer. */ |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 74 | #if 0 |
| 75 | struct ValueRecord { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 76 | SHORT xPlacement; /* Horizontal adjustment for |
| 77 | * placement--in design units */ |
| 78 | SHORT yPlacement; /* Vertical adjustment for |
| 79 | * placement--in design units */ |
| 80 | SHORT xAdvance; /* Horizontal adjustment for |
| 81 | * advance--in design units (only used |
| 82 | * for horizontal writing) */ |
| 83 | SHORT yAdvance; /* Vertical adjustment for advance--in |
| 84 | * design units (only used for vertical |
| 85 | * writing) */ |
| 86 | Offset xPlaDevice; /* Offset to Device table for |
| 87 | * horizontal placement--measured from |
| 88 | * beginning of PosTable (may be NULL) */ |
| 89 | Offset yPlaDevice; /* Offset to Device table for vertical |
| 90 | * placement--measured from beginning |
| 91 | * of PosTable (may be NULL) */ |
| 92 | Offset xAdvDevice; /* Offset to Device table for |
| 93 | * horizontal advance--measured from |
| 94 | * beginning of PosTable (may be NULL) */ |
| 95 | Offset yAdvDevice; /* Offset to Device table for vertical |
| 96 | * advance--measured from beginning of |
| 97 | * PosTable (may be NULL) */ |
| 98 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 99 | #endif |
| 100 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 101 | x_scale = context->font->x_scale; |
| 102 | y_scale = context->font->y_scale; |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 103 | /* design units -> fractional pixel */ |
| 104 | if (format & xPlacement) |
Behdad Esfahbod | 64e33f0 | 2009-05-26 18:57:56 -0400 | [diff] [blame] | 105 | glyph_pos->x_pos += x_scale * *(SHORT*)values++ / 0x10000; |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 106 | if (format & yPlacement) |
Behdad Esfahbod | 64e33f0 | 2009-05-26 18:57:56 -0400 | [diff] [blame] | 107 | glyph_pos->y_pos += y_scale * *(SHORT*)values++ / 0x10000; |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 108 | if (format & xAdvance) |
Behdad Esfahbod | 64e33f0 | 2009-05-26 18:57:56 -0400 | [diff] [blame] | 109 | glyph_pos->x_advance += x_scale * *(SHORT*)values++ / 0x10000; |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 110 | if (format & yAdvance) |
Behdad Esfahbod | 64e33f0 | 2009-05-26 18:57:56 -0400 | [diff] [blame] | 111 | glyph_pos->y_advance += y_scale * *(SHORT*)values++ / 0x10000; |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 112 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 113 | x_ppem = context->font->x_ppem; |
| 114 | y_ppem = context->font->y_ppem; |
Behdad Esfahbod | 0090dc0 | 2009-07-30 16:28:45 -0400 | [diff] [blame] | 115 | /* pixel -> fractional pixel */ |
| 116 | if (format & xPlaDevice) { |
| 117 | if (x_ppem) |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 118 | glyph_pos->x_pos += (base+*(OffsetTo<Device>*)values++).get_delta (x_ppem) << 6; |
Behdad Esfahbod | 0090dc0 | 2009-07-30 16:28:45 -0400 | [diff] [blame] | 119 | else |
| 120 | values++; |
| 121 | } |
| 122 | if (format & yPlaDevice) { |
| 123 | if (y_ppem) |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 124 | glyph_pos->y_pos += (base+*(OffsetTo<Device>*)values++).get_delta (y_ppem) << 6; |
Behdad Esfahbod | 0090dc0 | 2009-07-30 16:28:45 -0400 | [diff] [blame] | 125 | else |
| 126 | values++; |
| 127 | } |
| 128 | if (format & xAdvDevice) { |
| 129 | if (x_ppem) |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 130 | glyph_pos->x_advance += (base+*(OffsetTo<Device>*)values++).get_delta (x_ppem) << 6; |
Behdad Esfahbod | 0090dc0 | 2009-07-30 16:28:45 -0400 | [diff] [blame] | 131 | else |
| 132 | values++; |
| 133 | } |
| 134 | if (format & yAdvDevice) { |
| 135 | if (y_ppem) |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 136 | glyph_pos->y_advance += (base+*(OffsetTo<Device>*)values++).get_delta (y_ppem) << 6; |
Behdad Esfahbod | 0090dc0 | 2009-07-30 16:28:45 -0400 | [diff] [blame] | 137 | else |
| 138 | values++; |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 139 | } |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 140 | } |
| 141 | }; |
| 142 | ASSERT_SIZE (ValueFormat, 2); |
| 143 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 144 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 145 | struct AnchorFormat1 |
| 146 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 147 | friend struct Anchor; |
| 148 | |
| 149 | private: |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 150 | inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id, |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 151 | hb_position_t *x, hb_position_t *y) const |
| 152 | { |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 153 | *x = context->font->x_scale * xCoordinate / 0x10000; |
| 154 | *y = context->font->y_scale * yCoordinate / 0x10000; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 155 | } |
| 156 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 157 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 158 | return SANITIZE_SELF (); |
| 159 | } |
| 160 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 161 | private: |
| 162 | USHORT format; /* Format identifier--format = 1 */ |
| 163 | SHORT xCoordinate; /* Horizontal value--in design units */ |
| 164 | SHORT yCoordinate; /* Vertical value--in design units */ |
| 165 | }; |
| 166 | ASSERT_SIZE (AnchorFormat1, 6); |
| 167 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 168 | struct AnchorFormat2 |
| 169 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 170 | friend struct Anchor; |
| 171 | |
| 172 | private: |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 173 | inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id, |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 174 | hb_position_t *x, hb_position_t *y) const |
| 175 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 176 | /* TODO Contour */ |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 177 | *x = context->font->x_scale * xCoordinate / 0x10000; |
| 178 | *y = context->font->y_scale * yCoordinate / 0x10000; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 179 | } |
| 180 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 181 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 182 | return SANITIZE_SELF (); |
| 183 | } |
| 184 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 185 | private: |
| 186 | USHORT format; /* Format identifier--format = 2 */ |
| 187 | SHORT xCoordinate; /* Horizontal value--in design units */ |
| 188 | SHORT yCoordinate; /* Vertical value--in design units */ |
| 189 | USHORT anchorPoint; /* Index to glyph contour point */ |
| 190 | }; |
| 191 | ASSERT_SIZE (AnchorFormat2, 8); |
| 192 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 193 | struct AnchorFormat3 |
| 194 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 195 | friend struct Anchor; |
| 196 | |
| 197 | private: |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 198 | inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id, |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 199 | hb_position_t *x, hb_position_t *y) const |
| 200 | { |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 201 | *x = context->font->x_scale * xCoordinate / 0x10000; |
| 202 | *y = context->font->y_scale * yCoordinate / 0x10000; |
Behdad Esfahbod | c18ec2b | 2009-05-21 04:54:01 -0400 | [diff] [blame] | 203 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 204 | if (context->font->x_ppem) |
| 205 | *x += (this+xDeviceTable).get_delta (context->font->x_ppem) << 6; |
| 206 | if (context->font->y_ppem) |
| 207 | *y += (this+yDeviceTable).get_delta (context->font->y_ppem) << 6; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 208 | } |
| 209 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 210 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 211 | return SANITIZE_SELF () && SANITIZE_THIS2 (xDeviceTable, yDeviceTable); |
| 212 | } |
| 213 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 214 | private: |
| 215 | USHORT format; /* Format identifier--format = 3 */ |
| 216 | SHORT xCoordinate; /* Horizontal value--in design units */ |
| 217 | SHORT yCoordinate; /* Vertical value--in design units */ |
| 218 | OffsetTo<Device> |
| 219 | xDeviceTable; /* Offset to Device table for X |
| 220 | * coordinate-- from beginning of |
| 221 | * Anchor table (may be NULL) */ |
| 222 | OffsetTo<Device> |
| 223 | yDeviceTable; /* Offset to Device table for Y |
| 224 | * coordinate-- from beginning of |
| 225 | * Anchor table (may be NULL) */ |
| 226 | }; |
| 227 | ASSERT_SIZE (AnchorFormat3, 10); |
| 228 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 229 | struct Anchor |
| 230 | { |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 231 | inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id, |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 232 | hb_position_t *x, hb_position_t *y) const |
| 233 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 234 | *x = *y = 0; |
| 235 | switch (u.format) { |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 236 | case 1: u.format1->get_anchor (context, glyph_id, x, y); return; |
| 237 | case 2: u.format2->get_anchor (context, glyph_id, x, y); return; |
| 238 | case 3: u.format3->get_anchor (context, glyph_id, x, y); return; |
| 239 | default: return; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 243 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 244 | if (!SANITIZE (u.format)) return false; |
| 245 | switch (u.format) { |
| 246 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 247 | case 2: return u.format2->sanitize (SANITIZE_ARG); |
| 248 | case 3: return u.format3->sanitize (SANITIZE_ARG); |
| 249 | default:return true; |
| 250 | } |
| 251 | } |
| 252 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 253 | private: |
| 254 | union { |
| 255 | USHORT format; /* Format identifier */ |
| 256 | AnchorFormat1 format1[]; |
| 257 | AnchorFormat2 format2[]; |
| 258 | AnchorFormat3 format3[]; |
| 259 | } u; |
| 260 | }; |
| 261 | ASSERT_SIZE (Anchor, 2); |
| 262 | |
| 263 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 264 | struct MarkRecord |
| 265 | { |
Behdad Esfahbod | 377bfc5 | 2009-05-21 04:58:24 -0400 | [diff] [blame] | 266 | friend struct MarkArray; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 267 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 268 | inline bool sanitize (SANITIZE_ARG_DEF, const void *base) { |
| 269 | return SANITIZE_SELF () && SANITIZE_BASE (markAnchor, base); |
| 270 | } |
| 271 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 272 | private: |
| 273 | USHORT klass; /* Class defined for this mark */ |
| 274 | OffsetTo<Anchor> |
| 275 | markAnchor; /* Offset to Anchor table--from |
| 276 | * beginning of MarkArray table */ |
| 277 | }; |
| 278 | ASSERT_SIZE (MarkRecord, 4); |
| 279 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 280 | struct MarkArray |
| 281 | { |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 282 | inline unsigned int get_class (unsigned int index) const { return markRecord[index].klass; } |
| 283 | inline const Anchor& get_anchor (unsigned int index) const { return this+markRecord[index].markAnchor; } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 284 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 285 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 286 | return SANITIZE_THIS (markRecord); |
| 287 | } |
| 288 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 289 | private: |
| 290 | ArrayOf<MarkRecord> |
| 291 | markRecord; /* Array of MarkRecords--in Coverage order */ |
| 292 | }; |
| 293 | ASSERT_SIZE (MarkArray, 2); |
| 294 | |
| 295 | |
| 296 | /* Lookups */ |
| 297 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 298 | struct SinglePosFormat1 |
| 299 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 300 | friend struct SinglePos; |
| 301 | |
| 302 | private: |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 303 | inline bool apply (APPLY_ARG_DEF) const |
| 304 | { |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 305 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
| 306 | if (HB_LIKELY (index == NOT_COVERED)) |
| 307 | return false; |
| 308 | |
Behdad Esfahbod | 196598b | 2009-08-04 11:04:32 -0400 | [diff] [blame] | 309 | valueFormat.apply_value (context, CONST_CHARP(this), values, CURPOSITION ()); |
Behdad Esfahbod | f53d434 | 2009-05-30 22:17:32 -0400 | [diff] [blame] | 310 | |
| 311 | buffer->in_pos++; |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 312 | return true; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 313 | } |
| 314 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 315 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 316 | return SANITIZE_SELF () && SANITIZE_THIS (coverage) && |
| 317 | SANITIZE_MEM (values, valueFormat.get_size ()); |
| 318 | } |
| 319 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 320 | private: |
| 321 | USHORT format; /* Format identifier--format = 1 */ |
| 322 | OffsetTo<Coverage> |
| 323 | coverage; /* Offset to Coverage table--from |
| 324 | * beginning of subtable */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 325 | ValueFormat valueFormat; /* Defines the types of data in the |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 326 | * ValueRecord */ |
| 327 | ValueRecord values; /* Defines positioning |
| 328 | * value(s)--applied to all glyphs in |
| 329 | * the Coverage table */ |
| 330 | }; |
| 331 | ASSERT_SIZE (SinglePosFormat1, 6); |
| 332 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 333 | struct SinglePosFormat2 |
| 334 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 335 | friend struct SinglePos; |
| 336 | |
| 337 | private: |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 338 | inline bool apply (APPLY_ARG_DEF) const |
| 339 | { |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 340 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
| 341 | if (HB_LIKELY (index == NOT_COVERED)) |
| 342 | return false; |
| 343 | |
| 344 | if (HB_LIKELY (index >= valueCount)) |
| 345 | return false; |
| 346 | |
Behdad Esfahbod | 196598b | 2009-08-04 11:04:32 -0400 | [diff] [blame] | 347 | valueFormat.apply_value (context, CONST_CHARP(this), |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 348 | values + index * valueFormat.get_len (), |
| 349 | CURPOSITION ()); |
Behdad Esfahbod | f53d434 | 2009-05-30 22:17:32 -0400 | [diff] [blame] | 350 | |
| 351 | buffer->in_pos++; |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 352 | return true; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 353 | } |
| 354 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 355 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 356 | return SANITIZE_SELF () && SANITIZE_THIS (coverage) && |
| 357 | SANITIZE_MEM (values, valueFormat.get_size () * valueCount); |
| 358 | } |
| 359 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 360 | private: |
| 361 | USHORT format; /* Format identifier--format = 2 */ |
| 362 | OffsetTo<Coverage> |
| 363 | coverage; /* Offset to Coverage table--from |
| 364 | * beginning of subtable */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 365 | ValueFormat valueFormat; /* Defines the types of data in the |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 366 | * ValueRecord */ |
| 367 | USHORT valueCount; /* Number of ValueRecords */ |
| 368 | ValueRecord values; /* Array of ValueRecords--positioning |
| 369 | * values applied to glyphs */ |
| 370 | }; |
| 371 | ASSERT_SIZE (SinglePosFormat2, 8); |
| 372 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 373 | struct SinglePos |
| 374 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 375 | friend struct PosLookupSubTable; |
| 376 | |
| 377 | private: |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 378 | inline bool apply (APPLY_ARG_DEF) const |
| 379 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 380 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 381 | case 1: return u.format1->apply (APPLY_ARG); |
| 382 | case 2: return u.format2->apply (APPLY_ARG); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 383 | default:return false; |
| 384 | } |
| 385 | } |
| 386 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 387 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 388 | if (!SANITIZE (u.format)) return false; |
| 389 | switch (u.format) { |
| 390 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 391 | case 2: return u.format2->sanitize (SANITIZE_ARG); |
| 392 | default:return true; |
| 393 | } |
| 394 | } |
| 395 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 396 | private: |
| 397 | union { |
| 398 | USHORT format; /* Format identifier */ |
| 399 | SinglePosFormat1 format1[]; |
| 400 | SinglePosFormat2 format2[]; |
| 401 | } u; |
| 402 | }; |
| 403 | ASSERT_SIZE (SinglePos, 2); |
| 404 | |
| 405 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 406 | struct PairValueRecord |
| 407 | { |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 408 | friend struct PairPosFormat1; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 409 | |
| 410 | private: |
| 411 | GlyphID secondGlyph; /* GlyphID of second glyph in the |
| 412 | * pair--first glyph is listed in the |
| 413 | * Coverage table */ |
| 414 | ValueRecord values; /* Positioning data for the first glyph |
| 415 | * followed by for second glyph */ |
| 416 | }; |
| 417 | ASSERT_SIZE (PairValueRecord, 2); |
| 418 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 419 | struct PairSet |
| 420 | { |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 421 | friend struct PairPosFormat1; |
| 422 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 423 | inline bool sanitize (SANITIZE_ARG_DEF, unsigned int format_len) { |
| 424 | if (!SANITIZE_SELF ()) return false; |
| 425 | unsigned int count = (1 + format_len) * len; |
| 426 | return SANITIZE_MEM (array, sizeof (array[0]) * count); |
| 427 | } |
| 428 | |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 429 | private: |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 430 | USHORT len; /* Number of PairValueRecords */ |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 431 | PairValueRecord |
| 432 | array[]; /* Array of PairValueRecords--ordered |
| 433 | * by GlyphID of the second glyph */ |
| 434 | }; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 435 | ASSERT_SIZE (PairSet, 2); |
| 436 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 437 | struct PairPosFormat1 |
| 438 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 439 | friend struct PairPos; |
| 440 | |
| 441 | private: |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 442 | inline bool apply (APPLY_ARG_DEF) const |
| 443 | { |
| 444 | unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length); |
| 445 | if (HB_UNLIKELY (buffer->in_pos + 2 > end)) |
| 446 | return false; |
| 447 | |
| 448 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
| 449 | if (HB_LIKELY (index == NOT_COVERED)) |
| 450 | return false; |
| 451 | |
| 452 | unsigned int j = buffer->in_pos + 1; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 453 | while (_hb_ot_layout_skip_mark (context->face, IN_INFO (j), lookup_flag, NULL)) |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 454 | { |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 455 | if (HB_UNLIKELY (j == end)) |
| 456 | return false; |
| 457 | j++; |
| 458 | } |
| 459 | |
| 460 | const PairSet &pair_set = this+pairSet[index]; |
| 461 | |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 462 | unsigned int len1 = valueFormat1.get_len (); |
| 463 | unsigned int len2 = valueFormat2.get_len (); |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 464 | unsigned int record_len = 1 + len1 + len2; |
| 465 | |
| 466 | unsigned int count = pair_set.len; |
| 467 | const PairValueRecord *record = pair_set.array; |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 468 | for (unsigned int i = 0; i < count; i++) |
| 469 | { |
| 470 | if (IN_GLYPH (j) == record->secondGlyph) |
| 471 | { |
Behdad Esfahbod | 196598b | 2009-08-04 11:04:32 -0400 | [diff] [blame] | 472 | valueFormat1.apply_value (context, CONST_CHARP(this), record->values, CURPOSITION ()); |
| 473 | valueFormat2.apply_value (context, CONST_CHARP(this), record->values + len1, POSITION (j)); |
Behdad Esfahbod | b24ecba | 2009-05-19 22:16:04 -0400 | [diff] [blame] | 474 | if (len2) |
| 475 | j++; |
| 476 | buffer->in_pos = j; |
| 477 | return true; |
| 478 | } |
| 479 | record += record_len; |
| 480 | } |
| 481 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 482 | return false; |
| 483 | } |
| 484 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 485 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 486 | return SANITIZE_SELF () && SANITIZE_THIS (coverage) && |
| 487 | pairSet.sanitize (SANITIZE_ARG, CONST_CHARP(this), |
| 488 | valueFormat1.get_len () + valueFormat2.get_len ()); |
| 489 | } |
| 490 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 491 | private: |
| 492 | USHORT format; /* Format identifier--format = 1 */ |
| 493 | OffsetTo<Coverage> |
| 494 | coverage; /* Offset to Coverage table--from |
| 495 | * beginning of subtable */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 496 | ValueFormat valueFormat1; /* Defines the types of data in |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 497 | * ValueRecord1--for the first glyph |
| 498 | * in the pair--may be zero (0) */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 499 | ValueFormat valueFormat2; /* Defines the types of data in |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 500 | * ValueRecord2--for the second glyph |
| 501 | * in the pair--may be zero (0) */ |
| 502 | OffsetArrayOf<PairSet> |
| 503 | pairSet; /* Array of PairSet tables |
| 504 | * ordered by Coverage Index */ |
| 505 | }; |
| 506 | ASSERT_SIZE (PairPosFormat1, 10); |
| 507 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 508 | struct PairPosFormat2 |
| 509 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 510 | friend struct PairPos; |
| 511 | |
| 512 | private: |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 513 | inline bool apply (APPLY_ARG_DEF) const |
| 514 | { |
| 515 | unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length); |
| 516 | if (HB_UNLIKELY (buffer->in_pos + 2 > end)) |
| 517 | return false; |
| 518 | |
| 519 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
| 520 | if (HB_LIKELY (index == NOT_COVERED)) |
| 521 | return false; |
| 522 | |
| 523 | unsigned int j = buffer->in_pos + 1; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 524 | while (_hb_ot_layout_skip_mark (context->face, IN_INFO (j), lookup_flag, NULL)) |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 525 | { |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 526 | if (HB_UNLIKELY (j == end)) |
| 527 | return false; |
| 528 | j++; |
| 529 | } |
| 530 | |
| 531 | unsigned int len1 = valueFormat1.get_len (); |
| 532 | unsigned int len2 = valueFormat2.get_len (); |
| 533 | unsigned int record_len = len1 + len2; |
| 534 | |
| 535 | unsigned int klass1 = (this+classDef1) (IN_CURGLYPH ()); |
| 536 | unsigned int klass2 = (this+classDef2) (IN_GLYPH (j)); |
| 537 | if (HB_UNLIKELY (klass1 >= class1Count || klass2 >= class2Count)) |
| 538 | return false; |
| 539 | |
| 540 | const Value *v = values + record_len * (klass1 * class2Count + klass2); |
Behdad Esfahbod | 196598b | 2009-08-04 11:04:32 -0400 | [diff] [blame] | 541 | valueFormat1.apply_value (context, CONST_CHARP(this), v, CURPOSITION ()); |
| 542 | valueFormat2.apply_value (context, CONST_CHARP(this), v + len1, POSITION (j)); |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 543 | |
| 544 | if (len2) |
| 545 | j++; |
| 546 | buffer->in_pos = j; |
| 547 | |
| 548 | return true; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 549 | } |
| 550 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 551 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 552 | return SANITIZE_SELF () && SANITIZE_THIS (coverage) && |
| 553 | SANITIZE_THIS2 (classDef1, classDef2) && |
| 554 | SANITIZE_MEM (values, |
| 555 | (valueFormat1.get_size () + valueFormat2.get_size ()) * |
| 556 | class1Count * class2Count); |
| 557 | } |
Behdad Esfahbod | 70632ad | 2009-05-19 22:30:09 -0400 | [diff] [blame] | 558 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 559 | private: |
| 560 | USHORT format; /* Format identifier--format = 2 */ |
| 561 | OffsetTo<Coverage> |
| 562 | coverage; /* Offset to Coverage table--from |
| 563 | * beginning of subtable */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 564 | ValueFormat valueFormat1; /* ValueRecord definition--for the |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 565 | * first glyph of the pair--may be zero |
| 566 | * (0) */ |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 567 | ValueFormat valueFormat2; /* ValueRecord definition--for the |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 568 | * second glyph of the pair--may be |
| 569 | * zero (0) */ |
| 570 | OffsetTo<ClassDef> |
| 571 | classDef1; /* Offset to ClassDef table--from |
| 572 | * beginning of PairPos subtable--for |
| 573 | * the first glyph of the pair */ |
| 574 | OffsetTo<ClassDef> |
| 575 | classDef2; /* Offset to ClassDef table--from |
| 576 | * beginning of PairPos subtable--for |
| 577 | * the second glyph of the pair */ |
| 578 | USHORT class1Count; /* Number of classes in ClassDef1 |
| 579 | * table--includes Class0 */ |
| 580 | USHORT class2Count; /* Number of classes in ClassDef2 |
| 581 | * table--includes Class0 */ |
| 582 | ValueRecord values; /* Matrix of value pairs: |
| 583 | * class1-major, class2-minor, |
| 584 | * Each entry has value1 and value2 */ |
| 585 | }; |
| 586 | ASSERT_SIZE (PairPosFormat2, 16); |
| 587 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 588 | struct PairPos |
| 589 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 590 | friend struct PosLookupSubTable; |
| 591 | |
| 592 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 593 | inline bool apply (APPLY_ARG_DEF) const |
| 594 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 595 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 596 | case 1: return u.format1->apply (APPLY_ARG); |
| 597 | case 2: return u.format2->apply (APPLY_ARG); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 598 | default:return false; |
| 599 | } |
| 600 | } |
| 601 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 602 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 603 | if (!SANITIZE (u.format)) return false; |
| 604 | switch (u.format) { |
| 605 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 606 | case 2: return u.format2->sanitize (SANITIZE_ARG); |
| 607 | default:return true; |
| 608 | } |
| 609 | } |
| 610 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 611 | private: |
| 612 | union { |
| 613 | USHORT format; /* Format identifier */ |
| 614 | PairPosFormat1 format1[]; |
| 615 | PairPosFormat2 format2[]; |
| 616 | } u; |
| 617 | }; |
| 618 | ASSERT_SIZE (PairPos, 2); |
| 619 | |
| 620 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 621 | struct EntryExitRecord |
| 622 | { |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 623 | inline bool sanitize (SANITIZE_ARG_DEF, const void *base) { |
| 624 | return SANITIZE_BASE2 (entryAnchor, exitAnchor, base); |
| 625 | } |
| 626 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 627 | OffsetTo<Anchor> |
| 628 | entryAnchor; /* Offset to EntryAnchor table--from |
| 629 | * beginning of CursivePos |
| 630 | * subtable--may be NULL */ |
| 631 | OffsetTo<Anchor> |
| 632 | exitAnchor; /* Offset to ExitAnchor table--from |
| 633 | * beginning of CursivePos |
| 634 | * subtable--may be NULL */ |
| 635 | }; |
| 636 | ASSERT_SIZE (EntryExitRecord, 4); |
| 637 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 638 | struct CursivePosFormat1 |
| 639 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 640 | friend struct CursivePos; |
| 641 | |
| 642 | private: |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 643 | inline bool apply (APPLY_ARG_DEF) const |
| 644 | { |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 645 | /* Now comes the messiest part of the whole OpenType |
| 646 | specification. At first glance, cursive connections seem easy |
| 647 | to understand, but there are pitfalls! The reason is that |
| 648 | the specs don't mention how to compute the advance values |
| 649 | resp. glyph offsets. I was told it would be an omission, to |
| 650 | be fixed in the next OpenType version... Again many thanks to |
| 651 | Andrei Burago <andreib@microsoft.com> for clarifications. |
| 652 | |
| 653 | Consider the following example: |
| 654 | |
| 655 | | xadv1 | |
| 656 | +---------+ |
| 657 | | | |
| 658 | +-----+--+ 1 | |
| 659 | | | .| | |
| 660 | | 0+--+------+ |
| 661 | | 2 | |
| 662 | | | |
| 663 | 0+--------+ |
| 664 | | xadv2 | |
| 665 | |
| 666 | glyph1: advance width = 12 |
| 667 | anchor point = (3,1) |
| 668 | |
| 669 | glyph2: advance width = 11 |
| 670 | anchor point = (9,4) |
| 671 | |
| 672 | LSB is 1 for both glyphs (so the boxes drawn above are glyph |
| 673 | bboxes). Writing direction is R2L; `0' denotes the glyph's |
| 674 | coordinate origin. |
| 675 | |
| 676 | Now the surprising part: The advance width of the *left* glyph |
| 677 | (resp. of the *bottom* glyph) will be modified, no matter |
| 678 | whether the writing direction is L2R or R2L (resp. T2B or |
| 679 | B2T)! This assymetry is caused by the fact that the glyph's |
| 680 | coordinate origin is always the lower left corner for all |
| 681 | writing directions. |
| 682 | |
| 683 | Continuing the above example, we can compute the new |
| 684 | (horizontal) advance width of glyph2 as |
| 685 | |
| 686 | 9 - 3 = 6 , |
| 687 | |
| 688 | and the new vertical offset of glyph2 as |
| 689 | |
| 690 | 1 - 4 = -3 . |
| 691 | |
| 692 | |
| 693 | Vertical writing direction is far more complicated: |
| 694 | |
| 695 | a) Assuming that we recompute the advance height of the lower glyph: |
| 696 | |
| 697 | -- |
| 698 | +---------+ |
| 699 | -- | | |
| 700 | +-----+--+ 1 | yadv1 |
| 701 | | | .| | |
| 702 | yadv2 | 0+--+------+ -- BSB1 -- |
| 703 | | 2 | -- -- y_offset |
| 704 | | | |
| 705 | BSB2 -- 0+--------+ -- |
| 706 | -- -- |
| 707 | |
| 708 | glyph1: advance height = 6 |
| 709 | anchor point = (3,1) |
| 710 | |
| 711 | glyph2: advance height = 7 |
| 712 | anchor point = (9,4) |
| 713 | |
| 714 | TSB is 1 for both glyphs; writing direction is T2B. |
| 715 | |
| 716 | |
| 717 | BSB1 = yadv1 - (TSB1 + ymax1) |
| 718 | BSB2 = yadv2 - (TSB2 + ymax2) |
| 719 | y_offset = y2 - y1 |
| 720 | |
| 721 | vertical advance width of glyph2 |
| 722 | = y_offset + BSB2 - BSB1 |
| 723 | = (y2 - y1) + (yadv2 - (TSB2 + ymax2)) - (yadv1 - (TSB1 + ymax1)) |
| 724 | = y2 - y1 + yadv2 - TSB2 - ymax2 - (yadv1 - TSB1 - ymax1) |
| 725 | = y2 - y1 + yadv2 - TSB2 - ymax2 - yadv1 + TSB1 + ymax1 |
| 726 | |
| 727 | |
| 728 | b) Assuming that we recompute the advance height of the upper glyph: |
| 729 | |
| 730 | -- -- |
| 731 | +---------+ -- TSB1 |
| 732 | -- -- | | |
| 733 | TSB2 -- +-----+--+ 1 | yadv1 ymax1 |
| 734 | | | .| | |
| 735 | yadv2 | 0+--+------+ -- -- |
| 736 | ymax2 | 2 | -- y_offset |
| 737 | | | |
| 738 | -- 0+--------+ -- |
| 739 | -- |
| 740 | |
| 741 | glyph1: advance height = 6 |
| 742 | anchor point = (3,1) |
| 743 | |
| 744 | glyph2: advance height = 7 |
| 745 | anchor point = (9,4) |
| 746 | |
| 747 | TSB is 1 for both glyphs; writing direction is T2B. |
| 748 | |
| 749 | y_offset = y2 - y1 |
| 750 | |
| 751 | vertical advance width of glyph2 |
| 752 | = TSB1 + ymax1 + y_offset - (TSB2 + ymax2) |
| 753 | = TSB1 + ymax1 + y2 - y1 - TSB2 - ymax2 |
| 754 | |
| 755 | |
| 756 | Comparing a) with b) shows that b) is easier to compute. I'll wait |
| 757 | for a reply from Andrei to see what should really be implemented... |
| 758 | |
| 759 | Since horizontal advance widths or vertical advance heights |
| 760 | can be used alone but not together, no ambiguity occurs. */ |
| 761 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 762 | struct hb_ot_layout_context_t::info_t::gpos_t *gpi = &context->info.gpos; |
Behdad Esfahbod | 0f7e6b2 | 2009-05-20 04:16:35 -0400 | [diff] [blame] | 763 | hb_codepoint_t last_pos = gpi->last; |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 764 | gpi->last = HB_OT_LAYOUT_GPOS_NO_LAST; |
Behdad Esfahbod | 0f7e6b2 | 2009-05-20 04:16:35 -0400 | [diff] [blame] | 765 | |
| 766 | /* We don't handle mark glyphs here. */ |
| 767 | if (property == HB_OT_LAYOUT_GLYPH_CLASS_MARK) |
| 768 | return false; |
| 769 | |
| 770 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
| 771 | if (HB_LIKELY (index == NOT_COVERED)) |
| 772 | return false; |
| 773 | |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 774 | const EntryExitRecord &record = entryExitRecord[index]; |
| 775 | |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 776 | if (last_pos == HB_OT_LAYOUT_GPOS_NO_LAST || !record.entryAnchor) |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 777 | goto end; |
| 778 | |
Behdad Esfahbod | 6c8108c | 2009-05-26 22:26:08 -0400 | [diff] [blame] | 779 | hb_position_t entry_x, entry_y; |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 780 | (this+record.entryAnchor).get_anchor (context, IN_CURGLYPH (), &entry_x, &entry_y); |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 781 | |
Behdad Esfahbod | cc83ae1 | 2009-05-27 00:17:37 -0400 | [diff] [blame] | 782 | /* TODO vertical */ |
| 783 | |
Behdad Esfahbod | 02a3706 | 2009-07-29 18:41:25 -0400 | [diff] [blame] | 784 | if (buffer->direction == HB_DIRECTION_RTL) |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 785 | { |
| 786 | POSITION (buffer->in_pos)->x_advance = entry_x - gpi->anchor_x; |
| 787 | POSITION (buffer->in_pos)->new_advance = TRUE; |
| 788 | } |
| 789 | else |
| 790 | { |
Behdad Esfahbod | 0f7e6b2 | 2009-05-20 04:16:35 -0400 | [diff] [blame] | 791 | POSITION (last_pos)->x_advance = gpi->anchor_x - entry_x; |
| 792 | POSITION (last_pos)->new_advance = TRUE; |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | if (lookup_flag & LookupFlag::RightToLeft) |
| 796 | { |
Behdad Esfahbod | 0f7e6b2 | 2009-05-20 04:16:35 -0400 | [diff] [blame] | 797 | POSITION (last_pos)->cursive_chain = last_pos - buffer->in_pos; |
| 798 | POSITION (last_pos)->y_pos = entry_y - gpi->anchor_y; |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 799 | } |
| 800 | else |
| 801 | { |
Behdad Esfahbod | 0f7e6b2 | 2009-05-20 04:16:35 -0400 | [diff] [blame] | 802 | POSITION (buffer->in_pos)->cursive_chain = buffer->in_pos - last_pos; |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 803 | POSITION (buffer->in_pos)->y_pos = gpi->anchor_y - entry_y; |
| 804 | } |
| 805 | |
| 806 | end: |
| 807 | if (record.exitAnchor) |
Behdad Esfahbod | 0f7e6b2 | 2009-05-20 04:16:35 -0400 | [diff] [blame] | 808 | { |
| 809 | gpi->last = buffer->in_pos; |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 810 | (this+record.exitAnchor).get_anchor (context, IN_CURGLYPH (), &gpi->anchor_x, &gpi->anchor_y); |
Behdad Esfahbod | 0f7e6b2 | 2009-05-20 04:16:35 -0400 | [diff] [blame] | 811 | } |
Behdad Esfahbod | d18fd8e | 2009-05-19 23:25:41 -0400 | [diff] [blame] | 812 | |
| 813 | buffer->in_pos++; |
| 814 | return true; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 815 | } |
| 816 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 817 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 818 | return SANITIZE_THIS2 (coverage, entryExitRecord); |
| 819 | } |
| 820 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 821 | private: |
| 822 | USHORT format; /* Format identifier--format = 1 */ |
| 823 | OffsetTo<Coverage> |
| 824 | coverage; /* Offset to Coverage table--from |
| 825 | * beginning of subtable */ |
| 826 | ArrayOf<EntryExitRecord> |
| 827 | entryExitRecord; /* Array of EntryExit records--in |
| 828 | * Coverage Index order */ |
| 829 | }; |
| 830 | ASSERT_SIZE (CursivePosFormat1, 6); |
| 831 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 832 | struct CursivePos |
| 833 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 834 | friend struct PosLookupSubTable; |
| 835 | |
| 836 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 837 | inline bool apply (APPLY_ARG_DEF) const |
| 838 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 839 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 840 | case 1: return u.format1->apply (APPLY_ARG); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 841 | default:return false; |
| 842 | } |
| 843 | } |
| 844 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 845 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 846 | if (!SANITIZE (u.format)) return false; |
| 847 | switch (u.format) { |
| 848 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 849 | default:return true; |
| 850 | } |
| 851 | } |
| 852 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 853 | private: |
| 854 | union { |
| 855 | USHORT format; /* Format identifier */ |
| 856 | CursivePosFormat1 format1[]; |
| 857 | } u; |
| 858 | }; |
| 859 | ASSERT_SIZE (CursivePos, 2); |
| 860 | |
| 861 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 862 | struct BaseArray |
| 863 | { |
Behdad Esfahbod | fb3b5cc | 2009-05-21 04:47:05 -0400 | [diff] [blame] | 864 | friend struct MarkBasePosFormat1; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 865 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 866 | inline bool sanitize (SANITIZE_ARG_DEF, unsigned int cols) { |
| 867 | if (!SANITIZE_SELF ()) return false; |
| 868 | unsigned int count = cols * len; |
| 869 | if (!SANITIZE_MEM (matrix, sizeof (matrix[0]) * count)) return false; |
| 870 | for (unsigned int i = 0; i < count; i++) |
| 871 | if (!SANITIZE_THIS (matrix[i])) return false; |
| 872 | return true; |
| 873 | } |
| 874 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 875 | private: |
Behdad Esfahbod | fb3b5cc | 2009-05-21 04:47:05 -0400 | [diff] [blame] | 876 | USHORT len; /* Number of rows */ |
| 877 | OffsetTo<Anchor> |
| 878 | matrix[]; /* Matrix of offsets to Anchor tables-- |
| 879 | * from beginning of BaseArray table-- |
| 880 | * base-major--in order of |
| 881 | * BaseCoverage Index--, mark-minor-- |
| 882 | * ordered by class--zero-based. */ |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 883 | }; |
| 884 | ASSERT_SIZE (BaseArray, 2); |
| 885 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 886 | struct MarkBasePosFormat1 |
| 887 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 888 | friend struct MarkBasePos; |
| 889 | |
| 890 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 891 | inline bool apply (APPLY_ARG_DEF) const |
| 892 | { |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 893 | unsigned int mark_index = (this+markCoverage) (IN_CURGLYPH ()); |
| 894 | if (HB_LIKELY (mark_index == NOT_COVERED)) |
| 895 | return false; |
| 896 | |
| 897 | /* now we search backwards for a non-mark glyph */ |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 898 | unsigned int count = buffer->in_pos; |
| 899 | unsigned int i = 1, j = count - 1; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 900 | while (_hb_ot_layout_skip_mark (context->face, IN_INFO (j), LookupFlag::IgnoreMarks, &property)) |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 901 | { |
Behdad Esfahbod | 80ea5bd | 2009-05-26 17:58:37 -0400 | [diff] [blame] | 902 | if (HB_UNLIKELY (i == count)) |
| 903 | return false; |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 904 | i++, j--; |
| 905 | } |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 906 | #if 0 |
Behdad Esfahbod | 80ea5bd | 2009-05-26 17:58:37 -0400 | [diff] [blame] | 907 | /* The following assertion is too strong. */ |
| 908 | if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH)) |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 909 | return false; |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 910 | #endif |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 911 | |
| 912 | unsigned int base_index = (this+baseCoverage) (IN_GLYPH (j)); |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 913 | if (base_index == NOT_COVERED) |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 914 | return false; |
| 915 | |
| 916 | const MarkArray& mark_array = this+markArray; |
| 917 | const BaseArray& base_array = this+baseArray; |
| 918 | |
| 919 | unsigned int mark_class = mark_array.get_class (mark_index); |
| 920 | const Anchor& mark_anchor = mark_array.get_anchor (mark_index); |
| 921 | |
| 922 | if (HB_UNLIKELY (mark_class >= classCount || base_index >= base_array.len)) |
| 923 | return false; |
| 924 | |
| 925 | hb_position_t mark_x, mark_y, base_x, base_y; |
| 926 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 927 | mark_anchor.get_anchor (context, IN_CURGLYPH (), &mark_x, &mark_y); |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 928 | unsigned int index = base_index * classCount + mark_class; |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 929 | (&base_array+base_array.matrix[index]).get_anchor (context, IN_GLYPH (j), &base_x, &base_y); |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 930 | |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 931 | hb_internal_glyph_position_t *o = POSITION (buffer->in_pos); |
Behdad Esfahbod | 357ccde | 2009-05-21 06:32:01 -0400 | [diff] [blame] | 932 | o->x_pos = base_x - mark_x; |
| 933 | o->y_pos = base_y - mark_y; |
| 934 | o->x_advance = 0; |
| 935 | o->y_advance = 0; |
| 936 | o->back = i; |
| 937 | |
| 938 | buffer->in_pos++; |
| 939 | return true; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 940 | } |
| 941 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 942 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 943 | return SANITIZE_SELF () && SANITIZE_THIS2 (markCoverage, baseCoverage) && |
| 944 | SANITIZE_THIS (markArray) && baseArray.sanitize (SANITIZE_ARG, CONST_CHARP(this), classCount); |
| 945 | } |
| 946 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 947 | private: |
| 948 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | fb3b5cc | 2009-05-21 04:47:05 -0400 | [diff] [blame] | 949 | OffsetTo<Coverage> |
| 950 | markCoverage; /* Offset to MarkCoverage table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 951 | * beginning of MarkBasePos subtable */ |
Behdad Esfahbod | fb3b5cc | 2009-05-21 04:47:05 -0400 | [diff] [blame] | 952 | OffsetTo<Coverage> |
| 953 | baseCoverage; /* Offset to BaseCoverage table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 954 | * beginning of MarkBasePos subtable */ |
| 955 | USHORT classCount; /* Number of classes defined for marks */ |
Behdad Esfahbod | fb3b5cc | 2009-05-21 04:47:05 -0400 | [diff] [blame] | 956 | OffsetTo<MarkArray> |
| 957 | markArray; /* Offset to MarkArray table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 958 | * beginning of MarkBasePos subtable */ |
Behdad Esfahbod | fb3b5cc | 2009-05-21 04:47:05 -0400 | [diff] [blame] | 959 | OffsetTo<BaseArray> |
| 960 | baseArray; /* Offset to BaseArray table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 961 | * beginning of MarkBasePos subtable */ |
| 962 | }; |
| 963 | ASSERT_SIZE (MarkBasePosFormat1, 12); |
| 964 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 965 | struct MarkBasePos |
| 966 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 967 | friend struct PosLookupSubTable; |
| 968 | |
| 969 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 970 | inline bool apply (APPLY_ARG_DEF) const |
| 971 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 972 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 973 | case 1: return u.format1->apply (APPLY_ARG); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 974 | default:return false; |
| 975 | } |
| 976 | } |
| 977 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 978 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 979 | if (!SANITIZE (u.format)) return false; |
| 980 | switch (u.format) { |
| 981 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 982 | default:return true; |
| 983 | } |
| 984 | } |
| 985 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 986 | private: |
| 987 | union { |
| 988 | USHORT format; /* Format identifier */ |
| 989 | MarkBasePosFormat1 format1[]; |
| 990 | } u; |
| 991 | }; |
| 992 | ASSERT_SIZE (MarkBasePos, 2); |
| 993 | |
| 994 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 995 | struct LigatureAttach |
| 996 | { |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 997 | friend struct MarkLigPosFormat1; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 998 | |
| 999 | private: |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1000 | USHORT len; /* Number of ComponentRecords in this |
| 1001 | * ligature, ie. number of rows */ |
| 1002 | OffsetTo<Anchor> |
| 1003 | matrix[]; /* Matrix of offsets to Anchor tables-- |
| 1004 | * from beginning of LigatureAttach table-- |
| 1005 | * component-major--in order of |
| 1006 | * writing direction--, mark-minor-- |
| 1007 | * ordered by class--zero-based. */ |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1008 | }; |
| 1009 | ASSERT_SIZE (LigatureAttach, 2); |
| 1010 | |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1011 | typedef OffsetArrayOf<LigatureAttach> LigatureArray; |
| 1012 | /* Array of LigatureAttach |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1013 | * tables ordered by |
| 1014 | * LigatureCoverage Index */ |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1015 | ASSERT_SIZE (LigatureArray, 2); |
| 1016 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1017 | struct MarkLigPosFormat1 |
| 1018 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1019 | friend struct MarkLigPos; |
| 1020 | |
| 1021 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1022 | inline bool apply (APPLY_ARG_DEF) const |
| 1023 | { |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1024 | unsigned int mark_index = (this+markCoverage) (IN_CURGLYPH ()); |
| 1025 | if (HB_LIKELY (mark_index == NOT_COVERED)) |
| 1026 | return false; |
| 1027 | |
| 1028 | /* now we search backwards for a non-mark glyph */ |
| 1029 | unsigned int count = buffer->in_pos; |
| 1030 | unsigned int i = 1, j = count - 1; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 1031 | while (_hb_ot_layout_skip_mark (context->face, IN_INFO (j), LookupFlag::IgnoreMarks, &property)) |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1032 | { |
Behdad Esfahbod | 80ea5bd | 2009-05-26 17:58:37 -0400 | [diff] [blame] | 1033 | if (HB_UNLIKELY (i == count)) |
| 1034 | return false; |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1035 | i++, j--; |
| 1036 | } |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1037 | #if 0 |
Behdad Esfahbod | 80ea5bd | 2009-05-26 17:58:37 -0400 | [diff] [blame] | 1038 | /* The following assertion is too strong. */ |
| 1039 | if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE)) |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1040 | return false; |
| 1041 | #endif |
| 1042 | |
| 1043 | unsigned int lig_index = (this+ligatureCoverage) (IN_GLYPH (j)); |
| 1044 | if (lig_index == NOT_COVERED) |
| 1045 | return false; |
| 1046 | |
| 1047 | const MarkArray& mark_array = this+markArray; |
| 1048 | const LigatureArray& lig_array = this+ligatureArray; |
| 1049 | |
| 1050 | unsigned int mark_class = mark_array.get_class (mark_index); |
| 1051 | const Anchor& mark_anchor = mark_array.get_anchor (mark_index); |
| 1052 | |
| 1053 | if (HB_UNLIKELY (mark_class >= classCount || lig_index >= lig_array.len)) |
| 1054 | return false; |
| 1055 | |
| 1056 | const LigatureAttach& lig_attach = &lig_array+lig_array[lig_index]; |
| 1057 | count = lig_attach.len; |
| 1058 | if (HB_UNLIKELY (!count)) |
| 1059 | return false; |
| 1060 | |
| 1061 | unsigned int comp_index; |
| 1062 | /* We must now check whether the ligature ID of the current mark glyph |
| 1063 | * is identical to the ligature ID of the found ligature. If yes, we |
| 1064 | * can directly use the component index. If not, we attach the mark |
| 1065 | * glyph to the last component of the ligature. */ |
| 1066 | if (IN_LIGID (j) == IN_LIGID (buffer->in_pos)) |
| 1067 | { |
| 1068 | comp_index = IN_COMPONENT (buffer->in_pos); |
| 1069 | if (comp_index >= count) |
| 1070 | comp_index = count - 1; |
| 1071 | } |
| 1072 | else |
| 1073 | comp_index = count - 1; |
| 1074 | |
| 1075 | hb_position_t mark_x, mark_y, lig_x, lig_y; |
| 1076 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1077 | mark_anchor.get_anchor (context, IN_CURGLYPH (), &mark_x, &mark_y); |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1078 | unsigned int index = comp_index * classCount + mark_class; |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1079 | (&lig_attach+lig_attach.matrix[index]).get_anchor (context, IN_GLYPH (j), &lig_x, &lig_y); |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1080 | |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 1081 | hb_internal_glyph_position_t *o = POSITION (buffer->in_pos); |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1082 | o->x_pos = lig_x - mark_x; |
| 1083 | o->y_pos = lig_y - mark_y; |
| 1084 | o->x_advance = 0; |
| 1085 | o->y_advance = 0; |
| 1086 | o->back = i; |
| 1087 | |
| 1088 | buffer->in_pos++; |
| 1089 | return true; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1090 | } |
| 1091 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1092 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 1093 | return SANITIZE_SELF () && |
| 1094 | SANITIZE_THIS2 (markCoverage, ligatureCoverage) && |
| 1095 | SANITIZE_THIS2 (markArray, ligatureArray); |
| 1096 | } |
| 1097 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1098 | private: |
| 1099 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1100 | OffsetTo<Coverage> |
| 1101 | markCoverage; /* Offset to Mark Coverage table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1102 | * beginning of MarkLigPos subtable */ |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1103 | OffsetTo<Coverage> |
| 1104 | ligatureCoverage; /* Offset to Ligature Coverage |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1105 | * table--from beginning of MarkLigPos |
| 1106 | * subtable */ |
| 1107 | USHORT classCount; /* Number of defined mark classes */ |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1108 | OffsetTo<MarkArray> |
| 1109 | markArray; /* Offset to MarkArray table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1110 | * beginning of MarkLigPos subtable */ |
Behdad Esfahbod | 9b006bc | 2009-05-22 18:29:45 -0400 | [diff] [blame] | 1111 | OffsetTo<LigatureArray> |
| 1112 | ligatureArray; /* Offset to LigatureArray table--from |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1113 | * beginning of MarkLigPos subtable */ |
| 1114 | }; |
| 1115 | ASSERT_SIZE (MarkLigPosFormat1, 12); |
| 1116 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1117 | struct MarkLigPos |
| 1118 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1119 | friend struct PosLookupSubTable; |
| 1120 | |
| 1121 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1122 | inline bool apply (APPLY_ARG_DEF) const |
| 1123 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1124 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 1125 | case 1: return u.format1->apply (APPLY_ARG); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1126 | default:return false; |
| 1127 | } |
| 1128 | } |
| 1129 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1130 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 1131 | if (!SANITIZE (u.format)) return false; |
| 1132 | switch (u.format) { |
| 1133 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 1134 | default:return true; |
| 1135 | } |
| 1136 | } |
| 1137 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1138 | private: |
| 1139 | union { |
| 1140 | USHORT format; /* Format identifier */ |
| 1141 | MarkLigPosFormat1 format1[]; |
| 1142 | } u; |
| 1143 | }; |
| 1144 | ASSERT_SIZE (MarkLigPos, 2); |
| 1145 | |
| 1146 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1147 | struct Mark2Array |
| 1148 | { |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1149 | friend struct MarkMarkPosFormat1; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1150 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1151 | inline bool sanitize (SANITIZE_ARG_DEF, unsigned int cols) { |
| 1152 | if (!SANITIZE_SELF ()) return false; |
| 1153 | unsigned int count = cols * len; |
| 1154 | if (!SANITIZE_MEM (matrix, sizeof (matrix[0]) * count)) return false; |
| 1155 | for (unsigned int i = 0; i < count; i++) |
| 1156 | if (!SANITIZE_THIS (matrix[i])) return false; |
| 1157 | return true; |
| 1158 | } |
| 1159 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1160 | private: |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1161 | USHORT len; /* Number of rows */ |
| 1162 | OffsetTo<Anchor> |
| 1163 | matrix[]; /* Matrix of offsets to Anchor tables-- |
| 1164 | * from beginning of Mark2Array table-- |
| 1165 | * mark2-major--in order of |
| 1166 | * Mark2Coverage Index--, mark1-minor-- |
| 1167 | * ordered by class--zero-based. */ |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1168 | }; |
| 1169 | ASSERT_SIZE (Mark2Array, 2); |
| 1170 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1171 | struct MarkMarkPosFormat1 |
| 1172 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1173 | friend struct MarkMarkPos; |
| 1174 | |
| 1175 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1176 | inline bool apply (APPLY_ARG_DEF) const |
| 1177 | { |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1178 | unsigned int mark1_index = (this+mark1Coverage) (IN_CURGLYPH ()); |
| 1179 | if (HB_LIKELY (mark1_index == NOT_COVERED)) |
| 1180 | return false; |
| 1181 | |
| 1182 | /* now we search backwards for a suitable mark glyph until a non-mark glyph */ |
| 1183 | unsigned int count = buffer->in_pos; |
| 1184 | unsigned int i = 1, j = count - 1; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 1185 | while (_hb_ot_layout_skip_mark (context->face, IN_INFO (j), lookup_flag, &property)) |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1186 | { |
Behdad Esfahbod | 80ea5bd | 2009-05-26 17:58:37 -0400 | [diff] [blame] | 1187 | if (HB_UNLIKELY (i == count)) |
| 1188 | return false; |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1189 | i++, j--; |
| 1190 | } |
Behdad Esfahbod | 80ea5bd | 2009-05-26 17:58:37 -0400 | [diff] [blame] | 1191 | if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_MARK)) |
| 1192 | return false; |
| 1193 | |
| 1194 | /* Two marks match only if they belong to the same base, or same component |
| 1195 | * of the same ligature. */ |
| 1196 | if (IN_LIGID (j) != IN_LIGID (buffer->in_pos) || |
| 1197 | IN_COMPONENT (j) != IN_COMPONENT (buffer->in_pos)) |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1198 | return false; |
| 1199 | |
| 1200 | unsigned int mark2_index = (this+mark2Coverage) (IN_GLYPH (j)); |
| 1201 | if (mark2_index == NOT_COVERED) |
| 1202 | return false; |
| 1203 | |
| 1204 | const MarkArray& mark1_array = this+mark1Array; |
| 1205 | const Mark2Array& mark2_array = this+mark2Array; |
| 1206 | |
| 1207 | unsigned int mark1_class = mark1_array.get_class (mark1_index); |
| 1208 | const Anchor& mark1_anchor = mark1_array.get_anchor (mark1_index); |
| 1209 | |
| 1210 | if (HB_UNLIKELY (mark1_class >= classCount || mark2_index >= mark2_array.len)) |
| 1211 | return false; |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1212 | |
| 1213 | hb_position_t mark1_x, mark1_y, mark2_x, mark2_y; |
| 1214 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1215 | mark1_anchor.get_anchor (context, IN_CURGLYPH (), &mark1_x, &mark1_y); |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1216 | unsigned int index = mark2_index * classCount + mark1_class; |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1217 | (&mark2_array+mark2_array.matrix[index]).get_anchor (context, IN_GLYPH (j), &mark2_x, &mark2_y); |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1218 | |
Behdad Esfahbod | f1322e5 | 2009-08-01 22:53:04 -0400 | [diff] [blame] | 1219 | hb_internal_glyph_position_t *o = POSITION (buffer->in_pos); |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1220 | o->x_pos = mark2_x - mark1_x; |
| 1221 | o->y_pos = mark2_y - mark1_y; |
| 1222 | o->x_advance = 0; |
| 1223 | o->y_advance = 0; |
| 1224 | o->back = i; |
| 1225 | |
| 1226 | buffer->in_pos++; |
| 1227 | return true; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1228 | } |
| 1229 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1230 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 1231 | return SANITIZE_SELF () && SANITIZE_THIS2 (mark1Coverage, mark2Coverage) && |
| 1232 | SANITIZE_THIS (mark1Array) && mark2Array.sanitize (SANITIZE_ARG, CONST_CHARP(this), classCount); |
| 1233 | } |
| 1234 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1235 | private: |
| 1236 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1237 | OffsetTo<Coverage> |
| 1238 | mark1Coverage; /* Offset to Combining Mark1 Coverage |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1239 | * table--from beginning of MarkMarkPos |
| 1240 | * subtable */ |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1241 | OffsetTo<Coverage> |
| 1242 | mark2Coverage; /* Offset to Combining Mark2 Coverage |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1243 | * table--from beginning of MarkMarkPos |
| 1244 | * subtable */ |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1245 | USHORT classCount; /* Number of defined mark classes */ |
| 1246 | OffsetTo<MarkArray> |
| 1247 | mark1Array; /* Offset to Mark1Array table--from |
| 1248 | * beginning of MarkMarkPos subtable */ |
| 1249 | OffsetTo<Mark2Array> |
| 1250 | mark2Array; /* Offset to Mark2Array table--from |
| 1251 | * beginning of MarkMarkPos subtable */ |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1252 | }; |
Behdad Esfahbod | fe550f4 | 2009-05-21 08:27:07 -0400 | [diff] [blame] | 1253 | ASSERT_SIZE (MarkMarkPosFormat1, 12); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1254 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1255 | struct MarkMarkPos |
| 1256 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1257 | friend struct PosLookupSubTable; |
| 1258 | |
| 1259 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1260 | inline bool apply (APPLY_ARG_DEF) const |
| 1261 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1262 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 1263 | case 1: return u.format1->apply (APPLY_ARG); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1264 | default:return false; |
| 1265 | } |
| 1266 | } |
| 1267 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1268 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 1269 | if (!SANITIZE (u.format)) return false; |
| 1270 | switch (u.format) { |
| 1271 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 1272 | default:return true; |
| 1273 | } |
| 1274 | } |
| 1275 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1276 | private: |
| 1277 | union { |
| 1278 | USHORT format; /* Format identifier */ |
| 1279 | MarkMarkPosFormat1 format1[]; |
| 1280 | } u; |
| 1281 | }; |
| 1282 | ASSERT_SIZE (MarkMarkPos, 2); |
| 1283 | |
| 1284 | |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 1285 | static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1286 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1287 | struct ContextPos : Context |
| 1288 | { |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1289 | friend struct PosLookupSubTable; |
| 1290 | |
| 1291 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1292 | inline bool apply (APPLY_ARG_DEF) const |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 1293 | { return Context::apply (APPLY_ARG, position_lookup); } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1294 | }; |
| 1295 | ASSERT_SIZE (ContextPos, 2); |
| 1296 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1297 | struct ChainContextPos : ChainContext |
| 1298 | { |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1299 | friend struct PosLookupSubTable; |
| 1300 | |
| 1301 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1302 | inline bool apply (APPLY_ARG_DEF) const |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 1303 | { return ChainContext::apply (APPLY_ARG, position_lookup); } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1304 | }; |
| 1305 | ASSERT_SIZE (ChainContextPos, 2); |
| 1306 | |
| 1307 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1308 | struct ExtensionPos : Extension |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1309 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1310 | friend struct PosLookupSubTable; |
| 1311 | |
| 1312 | private: |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1313 | inline const struct PosLookupSubTable& get_subtable (void) const |
| 1314 | { return CONST_CAST (PosLookupSubTable, Extension::get_subtable (), 0); } |
| 1315 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1316 | inline bool apply (APPLY_ARG_DEF) const; |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1317 | |
| 1318 | inline bool sanitize (SANITIZE_ARG_DEF); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1319 | }; |
| 1320 | ASSERT_SIZE (ExtensionPos, 2); |
| 1321 | |
| 1322 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1323 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1324 | /* |
| 1325 | * PosLookup |
| 1326 | */ |
| 1327 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1328 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1329 | struct PosLookupSubTable |
| 1330 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1331 | friend struct PosLookup; |
| 1332 | |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 1333 | enum { |
| 1334 | Single = 1, |
| 1335 | Pair = 2, |
| 1336 | Cursive = 3, |
| 1337 | MarkBase = 4, |
| 1338 | MarkLig = 5, |
| 1339 | MarkMark = 6, |
| 1340 | Context = 7, |
| 1341 | ChainContext = 8, |
| 1342 | Extension = 9, |
| 1343 | }; |
| 1344 | |
Behdad Esfahbod | 923923f | 2009-05-22 17:58:09 -0400 | [diff] [blame] | 1345 | bool apply (APPLY_ARG_DEF, unsigned int lookup_type) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1346 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1347 | switch (lookup_type) { |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 1348 | case Single: return u.single->apply (APPLY_ARG); |
| 1349 | case Pair: return u.pair->apply (APPLY_ARG); |
| 1350 | case Cursive: return u.cursive->apply (APPLY_ARG); |
| 1351 | case MarkBase: return u.markBase->apply (APPLY_ARG); |
| 1352 | case MarkLig: return u.markLig->apply (APPLY_ARG); |
| 1353 | case MarkMark: return u.markMark->apply (APPLY_ARG); |
| 1354 | case Context: return u.context->apply (APPLY_ARG); |
| 1355 | case ChainContext: return u.chainContext->apply (APPLY_ARG); |
| 1356 | case Extension: return u.extension->apply (APPLY_ARG); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1357 | default:return false; |
| 1358 | } |
| 1359 | } |
| 1360 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1361 | bool sanitize (SANITIZE_ARG_DEF) { |
| 1362 | if (!SANITIZE (u.format)) return false; |
| 1363 | switch (u.format) { |
| 1364 | case Single: return u.single->sanitize (SANITIZE_ARG); |
| 1365 | case Pair: return u.pair->sanitize (SANITIZE_ARG); |
| 1366 | case Cursive: return u.cursive->sanitize (SANITIZE_ARG); |
| 1367 | case MarkBase: return u.markBase->sanitize (SANITIZE_ARG); |
| 1368 | case MarkLig: return u.markLig->sanitize (SANITIZE_ARG); |
| 1369 | case MarkMark: return u.markMark->sanitize (SANITIZE_ARG); |
| 1370 | case Context: return u.context->sanitize (SANITIZE_ARG); |
| 1371 | case ChainContext: return u.chainContext->sanitize (SANITIZE_ARG); |
| 1372 | case Extension: return u.extension->sanitize (SANITIZE_ARG); |
| 1373 | default:return true; |
| 1374 | } |
| 1375 | } |
| 1376 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1377 | private: |
| 1378 | union { |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 1379 | USHORT format; |
| 1380 | SinglePos single[]; |
| 1381 | PairPos pair[]; |
| 1382 | CursivePos cursive[]; |
| 1383 | MarkBasePos markBase[]; |
| 1384 | MarkLigPos markLig[]; |
| 1385 | MarkMarkPos markMark[]; |
| 1386 | ContextPos context[]; |
| 1387 | ChainContextPos chainContext[]; |
| 1388 | ExtensionPos extension[]; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1389 | } u; |
| 1390 | }; |
| 1391 | ASSERT_SIZE (PosLookupSubTable, 2); |
| 1392 | |
| 1393 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1394 | struct PosLookup : Lookup |
| 1395 | { |
| 1396 | inline const PosLookupSubTable& get_subtable (unsigned int i) const |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 1397 | { return (const PosLookupSubTable&) Lookup::get_subtable (i); } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1398 | |
| 1399 | /* Like get_type(), but looks through extension lookups. |
| 1400 | * Never returns Extension */ |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1401 | inline unsigned int get_effective_type (void) const |
| 1402 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1403 | unsigned int type = get_type (); |
| 1404 | |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 1405 | if (HB_UNLIKELY (type == PosLookupSubTable::Extension)) |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1406 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1407 | unsigned int count = get_subtable_count (); |
| 1408 | type = get_subtable(0).u.extension->get_type (); |
| 1409 | /* The spec says all subtables should have the same type. |
| 1410 | * This is specially important if one has a reverse type! */ |
| 1411 | for (unsigned int i = 1; i < count; i++) |
| 1412 | if (get_subtable(i).u.extension->get_type () != type) |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
| 1416 | return type; |
| 1417 | } |
| 1418 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1419 | inline bool apply_once (hb_ot_layout_context_t *context, |
Behdad Esfahbod | 923923f | 2009-05-22 17:58:09 -0400 | [diff] [blame] | 1420 | hb_buffer_t *buffer, |
| 1421 | unsigned int context_length, |
| 1422 | unsigned int nesting_level_left) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1423 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1424 | unsigned int lookup_type = get_type (); |
| 1425 | unsigned int lookup_flag = get_flag (); |
Behdad Esfahbod | 923923f | 2009-05-22 17:58:09 -0400 | [diff] [blame] | 1426 | unsigned int property; |
| 1427 | |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 1428 | if (!_hb_ot_layout_check_glyph_property (context->face, IN_CURINFO (), lookup_flag, &property)) |
Behdad Esfahbod | 923923f | 2009-05-22 17:58:09 -0400 | [diff] [blame] | 1429 | return false; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1430 | |
| 1431 | for (unsigned int i = 0; i < get_subtable_count (); i++) |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 1432 | if (get_subtable (i).apply (APPLY_ARG, lookup_type)) |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1433 | return true; |
| 1434 | |
| 1435 | return false; |
| 1436 | } |
| 1437 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1438 | bool apply_string (hb_ot_layout_context_t *context, |
Behdad Esfahbod | 2a8e6ac | 2009-05-18 18:21:44 -0400 | [diff] [blame] | 1439 | hb_buffer_t *buffer, |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1440 | hb_ot_layout_feature_mask_t mask) const |
| 1441 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1442 | bool ret = false; |
| 1443 | |
| 1444 | if (HB_UNLIKELY (!buffer->in_length)) |
| 1445 | return false; |
| 1446 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1447 | context->info.gpos.last = HB_OT_LAYOUT_GPOS_NO_LAST; /* no last valid glyph for cursive pos. */ |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 1448 | |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1449 | buffer->in_pos = 0; |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1450 | while (buffer->in_pos < buffer->in_length) |
| 1451 | { |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 1452 | bool done; |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1453 | if (~IN_PROPERTIES (buffer->in_pos) & mask) |
| 1454 | { |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1455 | done = apply_once (context, buffer, NO_CONTEXT, MAX_NESTING_LEVEL); |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 1456 | ret |= done; |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1457 | } |
| 1458 | else |
| 1459 | { |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 1460 | done = false; |
| 1461 | /* Contrary to properties defined in GDEF, user-defined properties |
| 1462 | will always stop a possible cursive positioning. */ |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1463 | context->info.gpos.last = HB_OT_LAYOUT_GPOS_NO_LAST; |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 1464 | } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1465 | |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 1466 | if (!done) |
| 1467 | buffer->in_pos++; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | return ret; |
| 1471 | } |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1472 | |
| 1473 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 1474 | if (Lookup::sanitize (SANITIZE_ARG)) return false; |
| 1475 | OffsetArrayOf<PosLookupSubTable> &list = (OffsetArrayOf<PosLookupSubTable> &) subTable; |
| 1476 | return SANITIZE_THIS (list); |
| 1477 | } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1478 | }; |
| 1479 | ASSERT_SIZE (PosLookup, 6); |
| 1480 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1481 | typedef OffsetListOf<PosLookup> PosLookupList; |
| 1482 | ASSERT_SIZE (PosLookupList, 2); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1483 | |
| 1484 | /* |
| 1485 | * GPOS |
| 1486 | */ |
| 1487 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1488 | struct GPOS : GSUBGPOS |
| 1489 | { |
Behdad Esfahbod | a328d66 | 2009-08-04 20:27:05 -0400 | [diff] [blame] | 1490 | static const hb_tag_t Tag = HB_OT_TAG_GPOS; |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1491 | |
Behdad Esfahbod | 5876bf1 | 2009-05-24 00:53:28 -0400 | [diff] [blame] | 1492 | static inline const GPOS& get_for_data (const char *data) |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 1493 | { return (const GPOS&) GSUBGPOS::get_for_data (data); } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1494 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1495 | inline const PosLookup& get_lookup (unsigned int i) const |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 1496 | { return (const PosLookup&) GSUBGPOS::get_lookup (i); } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1497 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1498 | inline bool position_lookup (hb_ot_layout_context_t *context, |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1499 | hb_buffer_t *buffer, |
| 1500 | unsigned int lookup_index, |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1501 | hb_ot_layout_feature_mask_t mask) const |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1502 | { return get_lookup (lookup_index).apply_string (context, buffer, mask); } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1503 | |
Behdad Esfahbod | e49a84c | 2009-08-04 14:33:23 -0400 | [diff] [blame] | 1504 | bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1505 | if (GSUBGPOS::sanitize (SANITIZE_ARG)) return false; |
| 1506 | OffsetTo<PosLookupList> &list = CAST(OffsetTo<PosLookupList>, lookupList, 0); |
| 1507 | return SANITIZE_THIS (list); |
| 1508 | } |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1509 | }; |
| 1510 | ASSERT_SIZE (GPOS, 10); |
| 1511 | |
| 1512 | |
| 1513 | /* Out-of-class implementation for methods recursing */ |
| 1514 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 1515 | inline bool ExtensionPos::apply (APPLY_ARG_DEF) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1516 | { |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1517 | unsigned int lookup_type = get_type (); |
| 1518 | |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 1519 | if (HB_UNLIKELY (lookup_type == PosLookupSubTable::Extension)) |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1520 | return false; |
| 1521 | |
Behdad Esfahbod | 42b778f | 2009-08-04 13:30:49 -0400 | [diff] [blame] | 1522 | return get_subtable ().apply (APPLY_ARG, lookup_type); |
| 1523 | } |
| 1524 | |
| 1525 | inline bool ExtensionPos::sanitize (SANITIZE_ARG_DEF) |
| 1526 | { |
| 1527 | return Extension::sanitize (SANITIZE_ARG) && |
Behdad Esfahbod | 1893948 | 2009-08-04 14:27:56 -0400 | [diff] [blame] | 1528 | (&(Extension::get_subtable ()) == &Null(LookupSubTable) || |
Behdad Esfahbod | 5ff4e13 | 2009-08-04 21:35:32 -0400 | [diff] [blame] | 1529 | get_type () == PosLookupSubTable::Extension || |
Behdad Esfahbod | 1893948 | 2009-08-04 14:27:56 -0400 | [diff] [blame] | 1530 | DECONST_CAST (PosLookupSubTable, get_subtable (), 0).sanitize (SANITIZE_ARG)); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1531 | } |
| 1532 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1533 | static inline bool position_lookup (APPLY_ARG_DEF, unsigned int lookup_index) |
| 1534 | { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 1535 | const GPOS &gpos = *(context->face->ot_layout.gpos); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1536 | const PosLookup &l = gpos.get_lookup (lookup_index); |
| 1537 | |
| 1538 | if (HB_UNLIKELY (nesting_level_left == 0)) |
| 1539 | return false; |
| 1540 | nesting_level_left--; |
| 1541 | |
| 1542 | if (HB_UNLIKELY (context_length < 1)) |
| 1543 | return false; |
| 1544 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 1545 | return l.apply_once (context, buffer, context_length, nesting_level_left); |
Behdad Esfahbod | 5e5eb05 | 2009-05-18 17:09:33 -0400 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 1549 | #endif /* HB_OT_LAYOUT_GPOS_PRIVATE_HH */ |