Ebrahim Byagowi | b986fea | 2018-11-05 12:31:58 +0330 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2018 Ebrahim Byagowi |
| 3 | * |
| 4 | * This is part of HarfBuzz, a text shaping 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 | #ifndef HB_AAT_LAYOUT_LCAR_TABLE_HH |
| 25 | #define HB_AAT_LAYOUT_LCAR_TABLE_HH |
| 26 | |
| 27 | #include "hb-open-type.hh" |
| 28 | #include "hb-aat-layout-common.hh" |
| 29 | |
| 30 | /* |
| 31 | * lcar -- Ligature caret |
| 32 | * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6lcar.html |
| 33 | */ |
| 34 | #define HB_AAT_TAG_lcar HB_TAG('l','c','a','r') |
| 35 | |
| 36 | |
| 37 | namespace AAT { |
| 38 | |
| 39 | typedef ArrayOf<HBINT16> LigCaretClassEntry; |
| 40 | |
| 41 | struct lcar |
| 42 | { |
Behdad Esfahbod | ef00654 | 2019-01-22 12:08:57 +0100 | [diff] [blame] | 43 | static constexpr hb_tag_t tableTag = HB_AAT_TAG_lcar; |
Ebrahim Byagowi | b986fea | 2018-11-05 12:31:58 +0330 | [diff] [blame] | 44 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 45 | unsigned int get_lig_carets (hb_font_t *font, |
| 46 | hb_direction_t direction, |
| 47 | hb_codepoint_t glyph, |
| 48 | unsigned int start_offset, |
| 49 | unsigned int *caret_count /* IN/OUT */, |
| 50 | hb_position_t *caret_array /* OUT */) const |
Ebrahim Byagowi | b986fea | 2018-11-05 12:31:58 +0330 | [diff] [blame] | 51 | { |
Behdad Esfahbod | fc44dea | 2018-11-13 11:54:33 -0500 | [diff] [blame] | 52 | const OffsetTo<LigCaretClassEntry>* entry_offset = lookup.get_value (glyph, |
| 53 | font->face->get_num_glyphs ()); |
Ebrahim Byagowi | b986fea | 2018-11-05 12:31:58 +0330 | [diff] [blame] | 54 | const LigCaretClassEntry& array = entry_offset ? this+*entry_offset : Null (LigCaretClassEntry); |
Behdad Esfahbod | f47c5da | 2018-11-24 21:36:57 -0500 | [diff] [blame] | 55 | if (caret_count) |
Ebrahim Byagowi | b986fea | 2018-11-05 12:31:58 +0330 | [diff] [blame] | 56 | { |
Behdad Esfahbod | f47c5da | 2018-11-24 21:36:57 -0500 | [diff] [blame] | 57 | hb_array_t<const HBINT16> arr = array.sub_array (start_offset, caret_count); |
Behdad Esfahbod | 474a120 | 2018-12-21 18:46:51 -0500 | [diff] [blame] | 58 | unsigned int count = arr.length; |
Ebrahim Byagowi | b986fea | 2018-11-05 12:31:58 +0330 | [diff] [blame] | 59 | for (unsigned int i = 0; i < count; ++i) |
| 60 | switch (format) |
| 61 | { |
| 62 | case 0: caret_array[i] = font->em_scale_dir (arr[i], direction); break; |
| 63 | case 1: |
| 64 | hb_position_t x, y; |
| 65 | font->get_glyph_contour_point_for_origin (glyph, arr[i], direction, &x, &y); |
| 66 | caret_array[i] = HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y; |
| 67 | break; |
| 68 | } |
| 69 | } |
| 70 | return array.len; |
| 71 | } |
| 72 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 73 | bool sanitize (hb_sanitize_context_t *c) const |
Ebrahim Byagowi | b986fea | 2018-11-05 12:31:58 +0330 | [diff] [blame] | 74 | { |
| 75 | TRACE_SANITIZE (this); |
| 76 | return_trace (likely (c->check_struct (this) && |
| 77 | version.major == 1 && |
| 78 | lookup.sanitize (c, this))); |
| 79 | } |
| 80 | |
| 81 | protected: |
| 82 | FixedVersion<>version; /* Version number of the ligature caret table */ |
| 83 | HBUINT16 format; /* Format of the ligature caret table. */ |
| 84 | Lookup<OffsetTo<LigCaretClassEntry> > |
| 85 | lookup; /* data Lookup table associating glyphs */ |
| 86 | |
| 87 | public: |
| 88 | DEFINE_SIZE_MIN (8); |
| 89 | }; |
| 90 | |
| 91 | } /* namespace AAT */ |
| 92 | |
| 93 | #endif /* HB_AAT_LAYOUT_LCAR_TABLE_HH */ |