/src/harfbuzz/src/hb-ot-vorg-table.hh
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2018 Adobe Inc. |
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 | | * Adobe Author(s): Michiharu Ariza |
25 | | */ |
26 | | |
27 | | #ifndef HB_OT_VORG_TABLE_HH |
28 | | #define HB_OT_VORG_TABLE_HH |
29 | | |
30 | | #include "hb-open-type.hh" |
31 | | #include "hb-ot-dual.hh" |
32 | | |
33 | | /* |
34 | | * VORG -- Vertical Origin Table |
35 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/vorg |
36 | | */ |
37 | | #define HB_OT_TAG_VORG HB_TAG('V','O','R','G') |
38 | | |
39 | | namespace OT { |
40 | | |
41 | | template <typename Types> |
42 | | struct VertOriginMetric |
43 | | { |
44 | 0 | int cmp (hb_codepoint_t g) const { return glyph.cmp (g); } |
45 | | |
46 | | bool sanitize (hb_sanitize_context_t *c) const |
47 | 0 | { |
48 | 0 | TRACE_SANITIZE (this); |
49 | 0 | return_trace (c->check_struct (this)); |
50 | 0 | } |
51 | | |
52 | | public: |
53 | | typename Types::HBGlyphID |
54 | | glyph; |
55 | | FWORD vertOriginY; |
56 | | |
57 | | public: |
58 | | DEFINE_SIZE_STATIC (Types::HBGlyphID::static_size + FWORD::static_size); |
59 | | }; |
60 | | |
61 | | template <typename Types> |
62 | | struct VORGFormat1_2 |
63 | | { |
64 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_VORG; |
65 | | |
66 | | bool has_data () const { return version.to_int (); } |
67 | | |
68 | | HB_ALWAYS_INLINE |
69 | | int get_y_origin (hb_codepoint_t glyph) const |
70 | 0 | { |
71 | 0 | unsigned int i; |
72 | 0 | if (!vertYOrigins.bfind (glyph, &i)) |
73 | 0 | return defaultVertOriginY; |
74 | 0 | return vertYOrigins[i].vertOriginY; |
75 | 0 | } |
76 | | |
77 | | template <typename Iterator, |
78 | | hb_requires (hb_is_iterator (Iterator))> |
79 | | void serialize (hb_serialize_context_t *c, |
80 | | Iterator it, |
81 | | FWORD defaultVertOriginY) |
82 | 0 | { |
83 | 0 |
|
84 | 0 | if (unlikely (!c->extend_min ((*this)))) return; |
85 | 0 |
|
86 | 0 | this->version.major = Types::size == 2 ? 1 : 2; |
87 | 0 | this->version.minor = 0; |
88 | 0 |
|
89 | 0 | this->defaultVertOriginY = defaultVertOriginY; |
90 | 0 | this->vertYOrigins.len = it.len (); |
91 | 0 |
|
92 | 0 | c->copy_all (it); |
93 | 0 | } |
94 | | |
95 | | bool subset (hb_subset_context_t *c) const |
96 | 0 | { |
97 | 0 | TRACE_SUBSET (this); |
98 | 0 | auto *vorg_prime = c->serializer->start_embed<VORGFormat1_2> (); |
99 | 0 | if (unlikely (!c->serializer->check_success (vorg_prime))) return_trace (false); |
100 | 0 |
|
101 | 0 | auto it = |
102 | 0 | + vertYOrigins.as_array () |
103 | 0 | | hb_filter (c->plan->glyphset (), &VertOriginMetric<Types>::glyph) |
104 | 0 | | hb_map ([&] (const VertOriginMetric<Types>& _) |
105 | 0 | { |
106 | 0 | hb_codepoint_t new_glyph = HB_SET_VALUE_INVALID; |
107 | 0 | c->plan->new_gid_for_old_gid (_.glyph, &new_glyph); |
108 | 0 |
|
109 | 0 | VertOriginMetric<Types> metric; |
110 | 0 | metric.glyph = new_glyph; |
111 | 0 | metric.vertOriginY = _.vertOriginY; |
112 | 0 | return metric; |
113 | 0 | }) |
114 | 0 | ; |
115 | 0 |
|
116 | 0 | /* serialize the new table */ |
117 | 0 | vorg_prime->serialize (c->serializer, it, defaultVertOriginY); |
118 | 0 | return_trace (true); |
119 | 0 | } |
120 | | |
121 | | bool sanitize (hb_sanitize_context_t *c) const |
122 | 0 | { |
123 | 0 | TRACE_SANITIZE (this); |
124 | 0 | return_trace (c->check_struct (this) && |
125 | 0 | hb_barrier () && |
126 | 0 | version.major == (Types::size == 2 ? 1 : 2) && |
127 | 0 | vertYOrigins.sanitize (c)); |
128 | 0 | } |
129 | | |
130 | | protected: |
131 | | FixedVersion<>version; /* Version of VORG table. */ |
132 | | FWORD defaultVertOriginY; |
133 | | /* The default vertical origin. */ |
134 | | typename Types::template SortedArrayOf<VertOriginMetric<Types>> |
135 | | vertYOrigins; /* The array of vertical origins. */ |
136 | | |
137 | | public: |
138 | | DEFINE_SIZE_ARRAY(6 + Types::HBUINT::static_size, vertYOrigins); |
139 | | }; |
140 | | |
141 | | struct VORG |
142 | | { |
143 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_VORG; |
144 | | |
145 | 0 | bool has_data () const { return u.version.v.to_int (); } |
146 | | |
147 | | HB_ALWAYS_INLINE |
148 | | int get_y_origin (hb_codepoint_t glyph) const |
149 | 0 | { |
150 | 0 | switch (u.version.v.major) { |
151 | 0 | case 1: return u.version1.get_y_origin (glyph); |
152 | | #ifndef HB_NO_BEYOND_64K |
153 | | case 2: return u.version2.get_y_origin (glyph); |
154 | | #endif |
155 | 0 | default: return 0; |
156 | 0 | } |
157 | 0 | } |
158 | | |
159 | | bool subset (hb_subset_context_t *c) const |
160 | 0 | { |
161 | 0 | TRACE_SUBSET (this); |
162 | 0 | switch (u.version.v.major) { |
163 | 0 | case 1: return_trace (u.version1.subset (c)); |
164 | 0 | #ifndef HB_NO_BEYOND_64K |
165 | 0 | case 2: return_trace (u.version2.subset (c)); |
166 | 0 | #endif |
167 | 0 | default: return_trace (false); |
168 | 0 | } |
169 | 0 | } |
170 | | |
171 | | bool sanitize (hb_sanitize_context_t *c) const |
172 | 0 | { |
173 | 0 | TRACE_SANITIZE (this); |
174 | 0 | if (unlikely (!u.version.v.sanitize (c))) return_trace (false); |
175 | 0 | hb_barrier (); |
176 | 0 | switch (u.version.v.major) { |
177 | 0 | case 1: hb_barrier (); return_trace (u.version1.sanitize (c)); |
178 | | #ifndef HB_NO_BEYOND_64K |
179 | | case 2: hb_barrier (); return_trace (u.version2.sanitize (c)); |
180 | | #endif |
181 | 0 | default: return_trace (false); |
182 | 0 | } |
183 | 0 | } |
184 | | |
185 | | protected: |
186 | | union { |
187 | | struct { |
188 | | FixedVersion<>v; /* Version of VORG table. */ |
189 | | } version; |
190 | | VORGFormat1_2<Layout::SmallTypes>version1; |
191 | | #ifndef HB_NO_BEYOND_64K |
192 | | VORGFormat1_2<Layout::MediumTypes>version2; |
193 | | #endif |
194 | | } u; |
195 | | |
196 | | public: |
197 | | DEFINE_SIZE_UNION (4, version.v); |
198 | | }; |
199 | | } /* namespace OT */ |
200 | | |
201 | | #endif /* HB_OT_VORG_TABLE_HH */ |