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