/src/harfbuzz/src/hb-aat-layout-opbd-table.hh
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright © 2019 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 | | |
25 | | #ifndef HB_AAT_LAYOUT_OPBD_TABLE_HH |
26 | | #define HB_AAT_LAYOUT_OPBD_TABLE_HH |
27 | | |
28 | | #include "hb-aat-layout-common.hh" |
29 | | #include "hb-open-type.hh" |
30 | | |
31 | | /* |
32 | | * opbd -- Optical Bounds |
33 | | * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6opbd.html |
34 | | */ |
35 | | #define HB_AAT_TAG_opbd HB_TAG('o','p','b','d') |
36 | | |
37 | | |
38 | | namespace AAT { |
39 | | |
40 | | struct OpticalBounds |
41 | | { |
42 | | bool sanitize (hb_sanitize_context_t *c) const |
43 | 0 | { |
44 | 0 | TRACE_SANITIZE (this); |
45 | 0 | return_trace (c->check_struct (this)); |
46 | 0 | } |
47 | | |
48 | | FWORD leftSide; |
49 | | FWORD topSide; |
50 | | FWORD rightSide; |
51 | | FWORD bottomSide; |
52 | | public: |
53 | | DEFINE_SIZE_STATIC (8); |
54 | | }; |
55 | | |
56 | | struct opbdFormat0 |
57 | | { |
58 | | bool get_bounds (hb_font_t *font, hb_codepoint_t glyph_id, |
59 | | hb_glyph_extents_t *extents, const void *base) const |
60 | 0 | { |
61 | 0 | const Offset16To<OpticalBounds> *bounds_offset = lookupTable.get_value (glyph_id, font->face->get_num_glyphs ()); |
62 | 0 | if (!bounds_offset) return false; |
63 | 0 | const OpticalBounds &bounds = base+*bounds_offset; |
64 | 0 |
|
65 | 0 | if (extents) |
66 | 0 | *extents = { |
67 | 0 | font->em_scale_x (bounds.leftSide), |
68 | 0 | font->em_scale_y (bounds.topSide), |
69 | 0 | font->em_scale_x (bounds.rightSide), |
70 | 0 | font->em_scale_y (bounds.bottomSide) |
71 | 0 | }; |
72 | 0 | return true; |
73 | 0 | } |
74 | | |
75 | | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
76 | 0 | { |
77 | 0 | TRACE_SANITIZE (this); |
78 | 0 | return_trace (likely (c->check_struct (this) && lookupTable.sanitize (c, base))); |
79 | 0 | } |
80 | | |
81 | | protected: |
82 | | Lookup<Offset16To<OpticalBounds>> |
83 | | lookupTable; /* Lookup table associating glyphs with the four |
84 | | * int16 values for the left-side, top-side, |
85 | | * right-side, and bottom-side optical bounds. */ |
86 | | public: |
87 | | DEFINE_SIZE_MIN (2); |
88 | | }; |
89 | | |
90 | | struct opbdFormat1 |
91 | | { |
92 | | bool get_bounds (hb_font_t *font, hb_codepoint_t glyph_id, |
93 | | hb_glyph_extents_t *extents, const void *base) const |
94 | 0 | { |
95 | 0 | const Offset16To<OpticalBounds> *bounds_offset = lookupTable.get_value (glyph_id, font->face->get_num_glyphs ()); |
96 | 0 | if (!bounds_offset) return false; |
97 | 0 | const OpticalBounds &bounds = base+*bounds_offset; |
98 | 0 |
|
99 | 0 | hb_position_t left = 0, top = 0, right = 0, bottom = 0, ignore; |
100 | 0 | if (font->get_glyph_contour_point (glyph_id, bounds.leftSide, &left, &ignore) || |
101 | 0 | font->get_glyph_contour_point (glyph_id, bounds.topSide, &ignore, &top) || |
102 | 0 | font->get_glyph_contour_point (glyph_id, bounds.rightSide, &right, &ignore) || |
103 | 0 | font->get_glyph_contour_point (glyph_id, bounds.bottomSide, &ignore, &bottom)) |
104 | 0 | { |
105 | 0 | if (extents) |
106 | 0 | *extents = {left, top, right, bottom}; |
107 | 0 | return true; |
108 | 0 | } |
109 | 0 | return false; |
110 | 0 | } |
111 | | |
112 | | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
113 | 0 | { |
114 | 0 | TRACE_SANITIZE (this); |
115 | 0 | return_trace (likely (c->check_struct (this) && lookupTable.sanitize (c, base))); |
116 | 0 | } |
117 | | |
118 | | protected: |
119 | | Lookup<Offset16To<OpticalBounds>> |
120 | | lookupTable; /* Lookup table associating glyphs with the four |
121 | | * int16 values for the left-side, top-side, |
122 | | * right-side, and bottom-side optical bounds. */ |
123 | | public: |
124 | | DEFINE_SIZE_MIN (2); |
125 | | }; |
126 | | |
127 | | struct opbd |
128 | | { |
129 | | static constexpr hb_tag_t tableTag = HB_AAT_TAG_opbd; |
130 | | |
131 | | bool get_bounds (hb_font_t *font, hb_codepoint_t glyph_id, |
132 | | hb_glyph_extents_t *extents) const |
133 | 0 | { |
134 | 0 | switch (format) |
135 | 0 | { |
136 | 0 | case 0: hb_barrier (); return u.format0.get_bounds (font, glyph_id, extents, this); |
137 | 0 | case 1: hb_barrier (); return u.format1.get_bounds (font, glyph_id, extents, this); |
138 | 0 | default:return false; |
139 | 0 | } |
140 | 0 | } |
141 | | |
142 | | bool sanitize (hb_sanitize_context_t *c) const |
143 | 0 | { |
144 | 0 | TRACE_SANITIZE (this); |
145 | 0 | if (unlikely (!c->check_struct (this) || version.major != 1)) |
146 | 0 | return_trace (false); |
147 | 0 | hb_barrier (); |
148 | 0 |
|
149 | 0 | switch (format) |
150 | 0 | { |
151 | 0 | case 0: hb_barrier (); return_trace (u.format0.sanitize (c, this)); |
152 | 0 | case 1: hb_barrier (); return_trace (u.format1.sanitize (c, this)); |
153 | 0 | default:return_trace (true); |
154 | 0 | } |
155 | 0 | } |
156 | | |
157 | | protected: |
158 | | FixedVersion<>version; /* Version number of the optical bounds |
159 | | * table (0x00010000 for the current version). */ |
160 | | HBUINT16 format; /* Format of the optical bounds table. |
161 | | * Format 0 indicates distance and Format 1 indicates |
162 | | * control point. */ |
163 | | union { |
164 | | opbdFormat0 format0; |
165 | | opbdFormat1 format1; |
166 | | } u; |
167 | | public: |
168 | | DEFINE_SIZE_MIN (8); |
169 | | }; |
170 | | |
171 | | } /* namespace AAT */ |
172 | | |
173 | | |
174 | | #endif /* HB_AAT_LAYOUT_OPBD_TABLE_HH */ |