OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2007,2008,2009 Red Hat, Inc. | 2 * Copyright © 2007,2008,2009 Red Hat, Inc. |
3 * Copyright © 2010,2012 Google, Inc. | 3 * Copyright © 2010,2012 Google, Inc. |
4 * | 4 * |
5 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
6 * | 6 * |
7 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
8 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
9 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
10 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
(...skipping 16 matching lines...) Expand all Loading... |
27 */ | 27 */ |
28 | 28 |
29 #ifndef HB_OT_LAYOUT_COMMON_PRIVATE_HH | 29 #ifndef HB_OT_LAYOUT_COMMON_PRIVATE_HH |
30 #define HB_OT_LAYOUT_COMMON_PRIVATE_HH | 30 #define HB_OT_LAYOUT_COMMON_PRIVATE_HH |
31 | 31 |
32 #include "hb-ot-layout-private.hh" | 32 #include "hb-ot-layout-private.hh" |
33 #include "hb-open-type-private.hh" | 33 #include "hb-open-type-private.hh" |
34 #include "hb-set-private.hh" | 34 #include "hb-set-private.hh" |
35 | 35 |
36 | 36 |
37 #define NOT_COVERED» » ((unsigned int) 0x110000) | 37 namespace OT { |
| 38 |
| 39 |
| 40 #define NOT_COVERED» » ((unsigned int) -1) |
38 #define MAX_NESTING_LEVEL 8 | 41 #define MAX_NESTING_LEVEL 8 |
39 | 42 |
40 | 43 |
41 | 44 |
42 /* | 45 /* |
43 * | 46 * |
44 * OpenType Layout Common Table Formats | 47 * OpenType Layout Common Table Formats |
45 * | 48 * |
46 */ | 49 */ |
47 | 50 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 130 |
128 inline bool sanitize (hb_sanitize_context_t *c) { | 131 inline bool sanitize (hb_sanitize_context_t *c) { |
129 TRACE_SANITIZE (); | 132 TRACE_SANITIZE (); |
130 return TRACE_RETURN (c->check_struct (this)); | 133 return TRACE_RETURN (c->check_struct (this)); |
131 } | 134 } |
132 | 135 |
133 inline bool intersects (const hb_set_t *glyphs) const { | 136 inline bool intersects (const hb_set_t *glyphs) const { |
134 return glyphs->intersects (start, end); | 137 return glyphs->intersects (start, end); |
135 } | 138 } |
136 | 139 |
| 140 template <typename set_t> |
| 141 inline void add_coverage (set_t *glyphs) const { |
| 142 glyphs->add_range (start, end); |
| 143 } |
| 144 |
137 GlyphID start; /* First GlyphID in the range */ | 145 GlyphID start; /* First GlyphID in the range */ |
138 GlyphID end; /* Last GlyphID in the range */ | 146 GlyphID end; /* Last GlyphID in the range */ |
139 USHORT value; /* Value */ | 147 USHORT value; /* Value */ |
140 public: | 148 public: |
141 DEFINE_SIZE_STATIC (6); | 149 DEFINE_SIZE_STATIC (6); |
142 }; | 150 }; |
143 DEFINE_NULL_DATA (RangeRecord, "\000\001"); | 151 DEFINE_NULL_DATA (RangeRecord, "\000\001"); |
144 | 152 |
145 | 153 |
146 struct IndexArray : ArrayOf<Index> | 154 struct IndexArray : ArrayOf<Index> |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 { return langSys.find_index (tag, index); } | 228 { return langSys.find_index (tag, index); } |
221 | 229 |
222 inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; } | 230 inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; } |
223 inline const LangSys& get_default_lang_sys (void) const { return this+defaultL
angSys; } | 231 inline const LangSys& get_default_lang_sys (void) const { return this+defaultL
angSys; } |
224 | 232 |
225 inline bool sanitize (hb_sanitize_context_t *c) { | 233 inline bool sanitize (hb_sanitize_context_t *c) { |
226 TRACE_SANITIZE (); | 234 TRACE_SANITIZE (); |
227 return TRACE_RETURN (defaultLangSys.sanitize (c, this) && langSys.sanitize (
c, this)); | 235 return TRACE_RETURN (defaultLangSys.sanitize (c, this) && langSys.sanitize (
c, this)); |
228 } | 236 } |
229 | 237 |
230 private: | 238 protected: |
231 OffsetTo<LangSys> | 239 OffsetTo<LangSys> |
232 defaultLangSys; /* Offset to DefaultLangSys table--from | 240 defaultLangSys; /* Offset to DefaultLangSys table--from |
233 * beginning of Script table--may be Null */ | 241 * beginning of Script table--may be Null */ |
234 RecordArrayOf<LangSys> | 242 RecordArrayOf<LangSys> |
235 langSys; /* Array of LangSysRecords--listed | 243 langSys; /* Array of LangSysRecords--listed |
236 * alphabetically by LangSysTag */ | 244 * alphabetically by LangSysTag */ |
237 public: | 245 public: |
238 DEFINE_SIZE_ARRAY (4, langSys); | 246 DEFINE_SIZE_ARRAY (4, langSys); |
239 }; | 247 }; |
240 | 248 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 { | 306 { |
299 unsigned int flag = lookupFlag; | 307 unsigned int flag = lookupFlag; |
300 if (unlikely (flag & LookupFlag::UseMarkFilteringSet)) | 308 if (unlikely (flag & LookupFlag::UseMarkFilteringSet)) |
301 { | 309 { |
302 const USHORT &markFilteringSet = StructAfter<USHORT> (subTable); | 310 const USHORT &markFilteringSet = StructAfter<USHORT> (subTable); |
303 flag += (markFilteringSet << 16); | 311 flag += (markFilteringSet << 16); |
304 } | 312 } |
305 return flag; | 313 return flag; |
306 } | 314 } |
307 | 315 |
| 316 inline bool serialize (hb_serialize_context_t *c, |
| 317 unsigned int lookup_type, |
| 318 uint32_t lookup_props, |
| 319 unsigned int num_subtables) |
| 320 { |
| 321 TRACE_SERIALIZE (); |
| 322 if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
| 323 lookupType.set (lookup_type); |
| 324 lookupFlag.set (lookup_props & 0xFFFF); |
| 325 if (unlikely (!subTable.serialize (c, num_subtables))) return TRACE_RETURN (
false); |
| 326 if (lookupFlag & LookupFlag::UseMarkFilteringSet) |
| 327 { |
| 328 USHORT &markFilteringSet = StructAfter<USHORT> (subTable); |
| 329 markFilteringSet.set (lookup_props >> 16); |
| 330 } |
| 331 return TRACE_RETURN (true); |
| 332 } |
| 333 |
308 inline bool sanitize (hb_sanitize_context_t *c) { | 334 inline bool sanitize (hb_sanitize_context_t *c) { |
309 TRACE_SANITIZE (); | 335 TRACE_SANITIZE (); |
310 /* Real sanitize of the subtables is done by GSUB/GPOS/... */ | 336 /* Real sanitize of the subtables is done by GSUB/GPOS/... */ |
311 if (!(c->check_struct (this) && subTable.sanitize (c))) return TRACE_RETURN
(false); | 337 if (!(c->check_struct (this) && subTable.sanitize (c))) return TRACE_RETURN
(false); |
312 if (unlikely (lookupFlag & LookupFlag::UseMarkFilteringSet)) | 338 if (lookupFlag & LookupFlag::UseMarkFilteringSet) |
313 { | 339 { |
314 USHORT &markFilteringSet = StructAfter<USHORT> (subTable); | 340 USHORT &markFilteringSet = StructAfter<USHORT> (subTable); |
315 if (!markFilteringSet.sanitize (c)) return TRACE_RETURN (false); | 341 if (!markFilteringSet.sanitize (c)) return TRACE_RETURN (false); |
316 } | 342 } |
317 return TRACE_RETURN (true); | 343 return TRACE_RETURN (true); |
318 } | 344 } |
319 | 345 |
320 USHORT lookupType; /* Different enumerations for GSUB and G
POS */ | 346 USHORT lookupType; /* Different enumerations for GSUB and G
POS */ |
321 USHORT lookupFlag; /* Lookup qualifiers */ | 347 USHORT lookupFlag; /* Lookup qualifiers */ |
322 ArrayOf<Offset> | 348 ArrayOf<Offset> |
(...skipping 13 matching lines...) Expand all Loading... |
336 */ | 362 */ |
337 | 363 |
338 struct CoverageFormat1 | 364 struct CoverageFormat1 |
339 { | 365 { |
340 friend struct Coverage; | 366 friend struct Coverage; |
341 | 367 |
342 private: | 368 private: |
343 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const | 369 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const |
344 { | 370 { |
345 int i = glyphArray.search (glyph_id); | 371 int i = glyphArray.search (glyph_id); |
346 if (i != -1) | 372 ASSERT_STATIC (((unsigned int) -1) == NOT_COVERED); |
347 return i; | 373 return i; |
348 return NOT_COVERED; | 374 } |
| 375 |
| 376 inline bool serialize (hb_serialize_context_t *c, |
| 377 » » » Supplier<GlyphID> &glyphs, |
| 378 » » » unsigned int num_glyphs) |
| 379 { |
| 380 TRACE_SERIALIZE (); |
| 381 if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
| 382 glyphArray.len.set (num_glyphs); |
| 383 if (unlikely (!c->extend (glyphArray))) return TRACE_RETURN (false); |
| 384 for (unsigned int i = 0; i < num_glyphs; i++) |
| 385 glyphArray[i] = glyphs[i]; |
| 386 glyphs.advance (num_glyphs); |
| 387 return TRACE_RETURN (true); |
349 } | 388 } |
350 | 389 |
351 inline bool sanitize (hb_sanitize_context_t *c) { | 390 inline bool sanitize (hb_sanitize_context_t *c) { |
352 TRACE_SANITIZE (); | 391 TRACE_SANITIZE (); |
353 return TRACE_RETURN (glyphArray.sanitize (c)); | 392 return TRACE_RETURN (glyphArray.sanitize (c)); |
354 } | 393 } |
355 | 394 |
356 inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) c
onst { | 395 inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) c
onst { |
357 return glyphs->has (glyphArray[index]); | 396 return glyphs->has (glyphArray[index]); |
358 } | 397 } |
359 | 398 |
| 399 template <typename set_t> |
| 400 inline void add_coverage (set_t *glyphs) const { |
| 401 unsigned int count = glyphArray.len; |
| 402 for (unsigned int i = 0; i < count; i++) |
| 403 glyphs->add (glyphArray[i]); |
| 404 } |
| 405 |
360 struct Iter { | 406 struct Iter { |
361 inline void init (const struct CoverageFormat1 &c_) { c = &c_; i = 0; }; | 407 inline void init (const struct CoverageFormat1 &c_) { c = &c_; i = 0; }; |
362 inline bool more (void) { return i < c->glyphArray.len; } | 408 inline bool more (void) { return i < c->glyphArray.len; } |
363 inline void next (void) { i++; } | 409 inline void next (void) { i++; } |
364 inline uint16_t get_glyph (void) { return c->glyphArray[i]; } | 410 inline uint16_t get_glyph (void) { return c->glyphArray[i]; } |
365 inline uint16_t get_coverage (void) { return i; } | 411 inline uint16_t get_coverage (void) { return i; } |
366 | 412 |
367 private: | 413 private: |
368 const struct CoverageFormat1 *c; | 414 const struct CoverageFormat1 *c; |
369 unsigned int i; | 415 unsigned int i; |
370 }; | 416 }; |
371 | 417 |
372 private: | 418 protected: |
373 USHORT coverageFormat; /* Format identifier--format = 1 */ | 419 USHORT coverageFormat; /* Format identifier--format = 1 */ |
374 SortedArrayOf<GlyphID> | 420 SortedArrayOf<GlyphID> |
375 glyphArray; /* Array of GlyphIDs--in numerical order */ | 421 glyphArray; /* Array of GlyphIDs--in numerical order */ |
376 public: | 422 public: |
377 DEFINE_SIZE_ARRAY (4, glyphArray); | 423 DEFINE_SIZE_ARRAY (4, glyphArray); |
378 }; | 424 }; |
379 | 425 |
380 struct CoverageFormat2 | 426 struct CoverageFormat2 |
381 { | 427 { |
382 friend struct Coverage; | 428 friend struct Coverage; |
383 | 429 |
384 private: | 430 private: |
385 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const | 431 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const |
386 { | 432 { |
387 int i = rangeRecord.search (glyph_id); | 433 int i = rangeRecord.search (glyph_id); |
388 if (i != -1) { | 434 if (i != -1) { |
389 const RangeRecord &range = rangeRecord[i]; | 435 const RangeRecord &range = rangeRecord[i]; |
390 return (unsigned int) range.value + (glyph_id - range.start); | 436 return (unsigned int) range.value + (glyph_id - range.start); |
391 } | 437 } |
392 return NOT_COVERED; | 438 return NOT_COVERED; |
393 } | 439 } |
394 | 440 |
| 441 inline bool serialize (hb_serialize_context_t *c, |
| 442 Supplier<GlyphID> &glyphs, |
| 443 unsigned int num_glyphs) |
| 444 { |
| 445 TRACE_SERIALIZE (); |
| 446 if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
| 447 |
| 448 if (unlikely (!num_glyphs)) return TRACE_RETURN (true); |
| 449 |
| 450 unsigned int num_ranges = 1; |
| 451 for (unsigned int i = 1; i < num_glyphs; i++) |
| 452 if (glyphs[i - 1] + 1 != glyphs[i]) |
| 453 num_ranges++; |
| 454 rangeRecord.len.set (num_ranges); |
| 455 if (unlikely (!c->extend (rangeRecord))) return TRACE_RETURN (false); |
| 456 |
| 457 unsigned int range = 0; |
| 458 rangeRecord[range].start = glyphs[0]; |
| 459 rangeRecord[range].value.set (0); |
| 460 for (unsigned int i = 1; i < num_glyphs; i++) |
| 461 if (glyphs[i - 1] + 1 != glyphs[i]) { |
| 462 range++; |
| 463 rangeRecord[range].start = glyphs[i]; |
| 464 rangeRecord[range].value.set (i); |
| 465 rangeRecord[range].end = glyphs[i]; |
| 466 } else { |
| 467 rangeRecord[range].end = glyphs[i]; |
| 468 } |
| 469 glyphs.advance (num_glyphs); |
| 470 return TRACE_RETURN (true); |
| 471 } |
| 472 |
395 inline bool sanitize (hb_sanitize_context_t *c) { | 473 inline bool sanitize (hb_sanitize_context_t *c) { |
396 TRACE_SANITIZE (); | 474 TRACE_SANITIZE (); |
397 return TRACE_RETURN (rangeRecord.sanitize (c)); | 475 return TRACE_RETURN (rangeRecord.sanitize (c)); |
398 } | 476 } |
399 | 477 |
400 inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) c
onst { | 478 inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) c
onst { |
401 unsigned int i; | 479 unsigned int i; |
402 unsigned int count = rangeRecord.len; | 480 unsigned int count = rangeRecord.len; |
403 for (i = 0; i < count; i++) { | 481 for (i = 0; i < count; i++) { |
404 const RangeRecord &range = rangeRecord[i]; | 482 const RangeRecord &range = rangeRecord[i]; |
405 if (range.value <= index && | 483 if (range.value <= index && |
406 index < (unsigned int) range.value + (range.end - range.start) && | 484 index < (unsigned int) range.value + (range.end - range.start) && |
407 range.intersects (glyphs)) | 485 range.intersects (glyphs)) |
408 return true; | 486 return true; |
409 else if (index < range.value) | 487 else if (index < range.value) |
410 return false; | 488 return false; |
411 } | 489 } |
412 return false; | 490 return false; |
413 } | 491 } |
414 | 492 |
| 493 template <typename set_t> |
| 494 inline void add_coverage (set_t *glyphs) const { |
| 495 unsigned int count = rangeRecord.len; |
| 496 for (unsigned int i = 0; i < count; i++) |
| 497 rangeRecord[i].add_coverage (glyphs); |
| 498 } |
| 499 |
415 struct Iter { | 500 struct Iter { |
416 inline void init (const CoverageFormat2 &c_) { | 501 inline void init (const CoverageFormat2 &c_) { |
417 c = &c_; | 502 c = &c_; |
418 coverage = 0; | 503 coverage = 0; |
419 i = 0; | 504 i = 0; |
420 j = c->rangeRecord.len ? c_.rangeRecord[0].start : 0; | 505 j = c->rangeRecord.len ? c_.rangeRecord[0].start : 0; |
421 } | 506 } |
422 inline bool more (void) { return i < c->rangeRecord.len; } | 507 inline bool more (void) { return i < c->rangeRecord.len; } |
423 inline void next (void) { | 508 inline void next (void) { |
424 coverage++; | 509 coverage++; |
425 if (j == c->rangeRecord[i].end) { | 510 if (j == c->rangeRecord[i].end) { |
426 i++; | 511 i++; |
427 if (more ()) | 512 if (more ()) |
428 j = c->rangeRecord[i].start; | 513 j = c->rangeRecord[i].start; |
429 return; | 514 return; |
430 } | 515 } |
431 j++; | 516 j++; |
432 } | 517 } |
433 inline uint16_t get_glyph (void) { return j; } | 518 inline uint16_t get_glyph (void) { return j; } |
434 inline uint16_t get_coverage (void) { return coverage; } | 519 inline uint16_t get_coverage (void) { return coverage; } |
435 | 520 |
436 private: | 521 private: |
437 const struct CoverageFormat2 *c; | 522 const struct CoverageFormat2 *c; |
438 unsigned int i, j, coverage; | 523 unsigned int i, j, coverage; |
439 }; | 524 }; |
440 | 525 |
441 private: | 526 protected: |
442 USHORT coverageFormat; /* Format identifier--format = 2 */ | 527 USHORT coverageFormat; /* Format identifier--format = 2 */ |
443 SortedArrayOf<RangeRecord> | 528 SortedArrayOf<RangeRecord> |
444 rangeRecord; /* Array of glyph ranges--ordered by | 529 rangeRecord; /* Array of glyph ranges--ordered by |
445 * Start GlyphID. rangeCount entries | 530 * Start GlyphID. rangeCount entries |
446 * long */ | 531 * long */ |
447 public: | 532 public: |
448 DEFINE_SIZE_ARRAY (4, rangeRecord); | 533 DEFINE_SIZE_ARRAY (4, rangeRecord); |
449 }; | 534 }; |
450 | 535 |
451 struct Coverage | 536 struct Coverage |
452 { | 537 { |
453 inline unsigned int operator () (hb_codepoint_t glyph_id) const { return get_c
overage (glyph_id); } | 538 inline unsigned int operator () (hb_codepoint_t glyph_id) const { return get_c
overage (glyph_id); } |
454 | 539 |
455 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const | 540 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const |
456 { | 541 { |
457 switch (u.format) { | 542 switch (u.format) { |
458 case 1: return u.format1.get_coverage(glyph_id); | 543 case 1: return u.format1.get_coverage(glyph_id); |
459 case 2: return u.format2.get_coverage(glyph_id); | 544 case 2: return u.format2.get_coverage(glyph_id); |
460 default:return NOT_COVERED; | 545 default:return NOT_COVERED; |
461 } | 546 } |
462 } | 547 } |
463 | 548 |
| 549 inline bool serialize (hb_serialize_context_t *c, |
| 550 Supplier<GlyphID> &glyphs, |
| 551 unsigned int num_glyphs) |
| 552 { |
| 553 TRACE_SERIALIZE (); |
| 554 if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
| 555 unsigned int num_ranges = 1; |
| 556 for (unsigned int i = 1; i < num_glyphs; i++) |
| 557 if (glyphs[i - 1] + 1 != glyphs[i]) |
| 558 num_ranges++; |
| 559 u.format.set (num_glyphs * 2 < num_ranges * 3 ? 1 : 2); |
| 560 switch (u.format) { |
| 561 case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, num_glyphs)); |
| 562 case 2: return TRACE_RETURN (u.format2.serialize (c, glyphs, num_glyphs)); |
| 563 default:return TRACE_RETURN (false); |
| 564 } |
| 565 } |
| 566 |
464 inline bool sanitize (hb_sanitize_context_t *c) { | 567 inline bool sanitize (hb_sanitize_context_t *c) { |
465 TRACE_SANITIZE (); | 568 TRACE_SANITIZE (); |
466 if (!u.format.sanitize (c)) return TRACE_RETURN (false); | 569 if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
467 switch (u.format) { | 570 switch (u.format) { |
468 case 1: return TRACE_RETURN (u.format1.sanitize (c)); | 571 case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
469 case 2: return TRACE_RETURN (u.format2.sanitize (c)); | 572 case 2: return TRACE_RETURN (u.format2.sanitize (c)); |
470 default:return TRACE_RETURN (true); | 573 default:return TRACE_RETURN (true); |
471 } | 574 } |
472 } | 575 } |
473 | 576 |
474 inline bool intersects (const hb_set_t *glyphs) const { | 577 inline bool intersects (const hb_set_t *glyphs) const { |
475 /* TODO speed this up */ | 578 /* TODO speed this up */ |
476 Coverage::Iter iter; | 579 Coverage::Iter iter; |
477 for (iter.init (*this); iter.more (); iter.next ()) { | 580 for (iter.init (*this); iter.more (); iter.next ()) { |
478 if (glyphs->has (iter.get_glyph ())) | 581 if (glyphs->has (iter.get_glyph ())) |
479 return true; | 582 return true; |
480 } | 583 } |
481 return false; | 584 return false; |
482 } | 585 } |
483 | 586 |
484 inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) c
onst { | 587 inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) c
onst { |
485 switch (u.format) { | 588 switch (u.format) { |
486 case 1: return u.format1.intersects_coverage (glyphs, index); | 589 case 1: return u.format1.intersects_coverage (glyphs, index); |
487 case 2: return u.format2.intersects_coverage (glyphs, index); | 590 case 2: return u.format2.intersects_coverage (glyphs, index); |
488 default:return false; | 591 default:return false; |
489 } | 592 } |
490 } | 593 } |
491 | 594 |
| 595 template <typename set_t> |
| 596 inline void add_coverage (set_t *glyphs) const { |
| 597 switch (u.format) { |
| 598 case 1: u.format1.add_coverage (glyphs); break; |
| 599 case 2: u.format2.add_coverage (glyphs); break; |
| 600 default: break; |
| 601 } |
| 602 } |
| 603 |
492 struct Iter { | 604 struct Iter { |
493 Iter (void) : format (0) {}; | 605 Iter (void) : format (0) {}; |
494 inline void init (const Coverage &c_) { | 606 inline void init (const Coverage &c_) { |
495 format = c_.u.format; | 607 format = c_.u.format; |
496 switch (format) { | 608 switch (format) { |
497 case 1: return u.format1.init (c_.u.format1); | 609 case 1: return u.format1.init (c_.u.format1); |
498 case 2: return u.format2.init (c_.u.format2); | 610 case 2: return u.format2.init (c_.u.format2); |
499 default:return; | 611 default:return; |
500 } | 612 } |
501 } | 613 } |
(...skipping 27 matching lines...) Expand all Loading... |
529 } | 641 } |
530 | 642 |
531 private: | 643 private: |
532 unsigned int format; | 644 unsigned int format; |
533 union { | 645 union { |
534 CoverageFormat1::Iter format1; | 646 CoverageFormat1::Iter format1; |
535 CoverageFormat2::Iter format2; | 647 CoverageFormat2::Iter format2; |
536 } u; | 648 } u; |
537 }; | 649 }; |
538 | 650 |
539 private: | 651 protected: |
540 union { | 652 union { |
541 USHORT format; /* Format identifier */ | 653 USHORT format; /* Format identifier */ |
542 CoverageFormat1 format1; | 654 CoverageFormat1 format1; |
543 CoverageFormat2 format2; | 655 CoverageFormat2 format2; |
544 } u; | 656 } u; |
545 public: | 657 public: |
546 DEFINE_SIZE_UNION (2, format); | 658 DEFINE_SIZE_UNION (2, format); |
547 }; | 659 }; |
548 | 660 |
549 | 661 |
550 /* | 662 /* |
551 * Class Definition Table | 663 * Class Definition Table |
552 */ | 664 */ |
553 | 665 |
554 struct ClassDefFormat1 | 666 struct ClassDefFormat1 |
555 { | 667 { |
556 friend struct ClassDef; | 668 friend struct ClassDef; |
557 | 669 |
558 private: | 670 private: |
559 inline unsigned int get_class (hb_codepoint_t glyph_id) const | 671 inline unsigned int get_class (hb_codepoint_t glyph_id) const |
560 { | 672 { |
561 if ((unsigned int) (glyph_id - startGlyph) < classValue.len) | 673 if (unlikely ((unsigned int) (glyph_id - startGlyph) < classValue.len)) |
562 return classValue[glyph_id - startGlyph]; | 674 return classValue[glyph_id - startGlyph]; |
563 return 0; | 675 return 0; |
564 } | 676 } |
565 | 677 |
566 inline bool sanitize (hb_sanitize_context_t *c) { | 678 inline bool sanitize (hb_sanitize_context_t *c) { |
567 TRACE_SANITIZE (); | 679 TRACE_SANITIZE (); |
568 return TRACE_RETURN (c->check_struct (this) && classValue.sanitize (c)); | 680 return TRACE_RETURN (c->check_struct (this) && classValue.sanitize (c)); |
569 } | 681 } |
570 | 682 |
571 inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) cons
t { | 683 inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) cons
t { |
572 unsigned int count = classValue.len; | 684 unsigned int count = classValue.len; |
573 for (unsigned int i = 0; i < count; i++) | 685 for (unsigned int i = 0; i < count; i++) |
574 if (classValue[i] == klass && glyphs->has (startGlyph + i)) | 686 if (classValue[i] == klass && glyphs->has (startGlyph + i)) |
575 return true; | 687 return true; |
576 return false; | 688 return false; |
577 } | 689 } |
578 | 690 |
| 691 protected: |
579 USHORT classFormat; /* Format identifier--format = 1 */ | 692 USHORT classFormat; /* Format identifier--format = 1 */ |
580 GlyphID startGlyph; /* First GlyphID of the classValueArray
*/ | 693 GlyphID startGlyph; /* First GlyphID of the classValueArray
*/ |
581 ArrayOf<USHORT> | 694 ArrayOf<USHORT> |
582 classValue; /* Array of Class Values--one per GlyphI
D */ | 695 classValue; /* Array of Class Values--one per GlyphI
D */ |
583 public: | 696 public: |
584 DEFINE_SIZE_ARRAY (6, classValue); | 697 DEFINE_SIZE_ARRAY (6, classValue); |
585 }; | 698 }; |
586 | 699 |
587 struct ClassDefFormat2 | 700 struct ClassDefFormat2 |
588 { | 701 { |
(...skipping 14 matching lines...) Expand all Loading... |
603 } | 716 } |
604 | 717 |
605 inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) cons
t { | 718 inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) cons
t { |
606 unsigned int count = rangeRecord.len; | 719 unsigned int count = rangeRecord.len; |
607 for (unsigned int i = 0; i < count; i++) | 720 for (unsigned int i = 0; i < count; i++) |
608 if (rangeRecord[i].value == klass && rangeRecord[i].intersects (glyphs)) | 721 if (rangeRecord[i].value == klass && rangeRecord[i].intersects (glyphs)) |
609 return true; | 722 return true; |
610 return false; | 723 return false; |
611 } | 724 } |
612 | 725 |
| 726 protected: |
613 USHORT classFormat; /* Format identifier--format = 2 */ | 727 USHORT classFormat; /* Format identifier--format = 2 */ |
614 SortedArrayOf<RangeRecord> | 728 SortedArrayOf<RangeRecord> |
615 rangeRecord; /* Array of glyph ranges--ordered by | 729 rangeRecord; /* Array of glyph ranges--ordered by |
616 * Start GlyphID */ | 730 * Start GlyphID */ |
617 public: | 731 public: |
618 DEFINE_SIZE_ARRAY (4, rangeRecord); | 732 DEFINE_SIZE_ARRAY (4, rangeRecord); |
619 }; | 733 }; |
620 | 734 |
621 struct ClassDef | 735 struct ClassDef |
622 { | 736 { |
(...skipping 19 matching lines...) Expand all Loading... |
642 } | 756 } |
643 | 757 |
644 inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) cons
t { | 758 inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) cons
t { |
645 switch (u.format) { | 759 switch (u.format) { |
646 case 1: return u.format1.intersects_class (glyphs, klass); | 760 case 1: return u.format1.intersects_class (glyphs, klass); |
647 case 2: return u.format2.intersects_class (glyphs, klass); | 761 case 2: return u.format2.intersects_class (glyphs, klass); |
648 default:return false; | 762 default:return false; |
649 } | 763 } |
650 } | 764 } |
651 | 765 |
652 private: | 766 protected: |
653 union { | 767 union { |
654 USHORT format; /* Format identifier */ | 768 USHORT format; /* Format identifier */ |
655 ClassDefFormat1 format1; | 769 ClassDefFormat1 format1; |
656 ClassDefFormat2 format2; | 770 ClassDefFormat2 format2; |
657 } u; | 771 } u; |
658 public: | 772 public: |
659 DEFINE_SIZE_UNION (2, format); | 773 DEFINE_SIZE_UNION (2, format); |
660 }; | 774 }; |
661 | 775 |
662 | 776 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 unsigned int f = deltaFormat; | 827 unsigned int f = deltaFormat; |
714 if (unlikely (f < 1 || f > 3 || startSize > endSize)) return 3 * USHORT::sta
tic_size; | 828 if (unlikely (f < 1 || f > 3 || startSize > endSize)) return 3 * USHORT::sta
tic_size; |
715 return USHORT::static_size * (4 + ((endSize - startSize) >> (4 - f))); | 829 return USHORT::static_size * (4 + ((endSize - startSize) >> (4 - f))); |
716 } | 830 } |
717 | 831 |
718 inline bool sanitize (hb_sanitize_context_t *c) { | 832 inline bool sanitize (hb_sanitize_context_t *c) { |
719 TRACE_SANITIZE (); | 833 TRACE_SANITIZE (); |
720 return TRACE_RETURN (c->check_struct (this) && c->check_range (this, this->g
et_size ())); | 834 return TRACE_RETURN (c->check_struct (this) && c->check_range (this, this->g
et_size ())); |
721 } | 835 } |
722 | 836 |
723 private: | 837 protected: |
724 USHORT startSize; /* Smallest size to correct--in ppem */ | 838 USHORT startSize; /* Smallest size to correct--in ppem */ |
725 USHORT endSize; /* Largest size to correct--in ppem */ | 839 USHORT endSize; /* Largest size to correct--in ppem */ |
726 USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2
, or 3 | 840 USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2
, or 3 |
727 * 1 Signed 2-bit value, 8 values per
uint16 | 841 * 1 Signed 2-bit value, 8 values per
uint16 |
728 * 2 Signed 4-bit value, 4 values per
uint16 | 842 * 2 Signed 4-bit value, 4 values per
uint16 |
729 * 3 Signed 8-bit value, 2 values per
uint16 | 843 * 3 Signed 8-bit value, 2 values per
uint16 |
730 */ | 844 */ |
731 USHORT deltaValue[VAR]; /* Array of compressed data */ | 845 USHORT deltaValue[VAR]; /* Array of compressed data */ |
732 public: | 846 public: |
733 DEFINE_SIZE_ARRAY (6, deltaValue); | 847 DEFINE_SIZE_ARRAY (6, deltaValue); |
734 }; | 848 }; |
735 | 849 |
736 | 850 |
| 851 } // namespace OT |
| 852 |
737 | 853 |
738 #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ | 854 #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ |
OLD | NEW |