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
37namespace AAT {
38
39typedef ArrayOf<HBINT16> LigCaretClassEntry;
40
41struct lcar
42{
43 static constexpr hb_tag_t tableTag = HB_AAT_TAG_lcar;
44
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
51 {
52 const OffsetTo<LigCaretClassEntry>* entry_offset = lookup.get_value (glyph,
53 font->face->get_num_glyphs ());
54 const LigCaretClassEntry& array = entry_offset ? this+*entry_offset : Null (LigCaretClassEntry);
55 if (caret_count)
56 {
57 hb_array_t<const HBINT16> arr = array.sub_array (start_offset, caret_count);
58 unsigned int count = arr.length;
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
73 bool sanitize (hb_sanitize_context_t *c) const
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 */
94