/work/workdir/UnpackedTarball/harfbuzz/src/hb-ot-maxp-table.hh
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2011,2012 Google, 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 | | * Google Author(s): Behdad Esfahbod |
25 | | */ |
26 | | |
27 | | #ifndef HB_OT_MAXP_TABLE_HH |
28 | | #define HB_OT_MAXP_TABLE_HH |
29 | | |
30 | | #include "hb-open-type.hh" |
31 | | #include "hb-ot-dual.hh" |
32 | | |
33 | | namespace OT { |
34 | | |
35 | | |
36 | | /* |
37 | | * maxp -- Maximum Profile |
38 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/maxp |
39 | | */ |
40 | | |
41 | | #define HB_OT_TAG_maxp HB_TAG('m','a','x','p') |
42 | | #define HB_OT_TAG_MAXP HB_TAG('M','A','X','P') |
43 | | |
44 | | struct maxpV1Tail |
45 | | { |
46 | | bool sanitize (hb_sanitize_context_t *c) const |
47 | 32.7k | { |
48 | 32.7k | TRACE_SANITIZE (this); |
49 | 32.7k | return_trace (c->check_struct (this)); |
50 | 32.7k | } |
51 | | |
52 | | HBUINT16 maxPoints; /* Maximum points in a non-composite glyph. */ |
53 | | HBUINT16 maxContours; /* Maximum contours in a non-composite glyph. */ |
54 | | HBUINT16 maxCompositePoints; /* Maximum points in a composite glyph. */ |
55 | | HBUINT16 maxCompositeContours; /* Maximum contours in a composite glyph. */ |
56 | | HBUINT16 maxZones; /* 1 if instructions do not use the twilight zone (Z0), |
57 | | * or 2 if instructions do use Z0; should be set to 2 in |
58 | | * most cases. */ |
59 | | HBUINT16 maxTwilightPoints; /* Maximum points used in Z0. */ |
60 | | HBUINT16 maxStorage; /* Number of Storage Area locations. */ |
61 | | HBUINT16 maxFunctionDefs; /* Number of FDEFs, equal to the highest function number + 1. */ |
62 | | HBUINT16 maxInstructionDefs; /* Number of IDEFs. */ |
63 | | HBUINT16 maxStackElements; /* Maximum stack depth. (This includes Font and CVT |
64 | | * Programs, as well as the instructions for each glyph.) */ |
65 | | HBUINT16 maxSizeOfInstructions; /* Maximum byte count for glyph instructions. */ |
66 | | HBUINT16 maxComponentElements; /* Maximum number of components referenced at |
67 | | * "top level" for any composite glyph. */ |
68 | | HBUINT16 maxComponentDepth; /* Maximum levels of recursion; 1 for simple components. */ |
69 | | public: |
70 | | DEFINE_SIZE_STATIC (26); |
71 | | }; |
72 | | |
73 | | |
74 | | template <typename Types> |
75 | | struct maxp_MAXP |
76 | | { |
77 | 16.4k | unsigned int get_num_glyphs () const { return numGlyphs; } |
78 | | |
79 | | void set_num_glyphs (unsigned int count) |
80 | | { |
81 | | numGlyphs = count; |
82 | | } |
83 | | |
84 | | bool sanitize (hb_sanitize_context_t *c) const |
85 | 32.7k | { |
86 | 32.7k | TRACE_SANITIZE (this); |
87 | 32.7k | if (unlikely (!c->check_struct (this))) |
88 | 0 | return_trace (false); |
89 | 32.7k | hb_barrier (); |
90 | 32.7k | if (version.major == 1) |
91 | 32.7k | { |
92 | 32.7k | const maxpV1Tail &v1 = StructAfter<maxpV1Tail> (*this); |
93 | 32.7k | return_trace (v1.sanitize (c)); |
94 | 32.7k | } |
95 | 32.7k | return_trace (likely (version.major == 0 && version.minor == 0x5000u)); |
96 | 32.7k | } |
97 | | |
98 | | bool subset (hb_subset_context_t *c) const |
99 | 16.3k | { |
100 | 16.3k | TRACE_SUBSET (this); |
101 | 16.3k | maxp_MAXP *maxp_prime = c->serializer->embed (this); |
102 | 16.3k | if (unlikely (!maxp_prime)) return_trace (false); |
103 | | |
104 | 16.3k | maxp_prime->numGlyphs = hb_min (c->plan->num_output_glyphs (), |
105 | 16.3k | (1u << (8 * Types::size)) - 1); |
106 | 16.3k | if (maxp_prime->version.major == 1) |
107 | 16.3k | { |
108 | 16.3k | hb_barrier (); |
109 | 16.3k | const maxpV1Tail *src_v1 = &StructAfter<maxpV1Tail> (*this); |
110 | 16.3k | maxpV1Tail *dest_v1 = c->serializer->embed<maxpV1Tail> (src_v1); |
111 | 16.3k | if (unlikely (!dest_v1)) return_trace (false); |
112 | | |
113 | 16.3k | if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING) |
114 | 0 | drop_hint_fields (dest_v1); |
115 | | |
116 | 16.3k | if (c->plan->normalized_coords) |
117 | 0 | instancing_update_fields (c->plan->head_maxp_info, dest_v1); |
118 | 16.3k | } |
119 | | |
120 | 16.3k | return_trace (true); |
121 | 16.3k | } |
122 | | |
123 | | void instancing_update_fields (head_maxp_info_t& maxp_info, maxpV1Tail* dest_v1) const |
124 | 0 | { |
125 | 0 | dest_v1->maxPoints = maxp_info.maxPoints; |
126 | 0 | dest_v1->maxContours = maxp_info.maxContours; |
127 | 0 | dest_v1->maxCompositePoints = maxp_info.maxCompositePoints; |
128 | 0 | dest_v1->maxCompositeContours = maxp_info.maxCompositeContours; |
129 | 0 | dest_v1->maxComponentElements = maxp_info.maxComponentElements; |
130 | 0 | dest_v1->maxComponentDepth = maxp_info.maxComponentDepth; |
131 | 0 | } |
132 | | |
133 | | static void drop_hint_fields (maxpV1Tail* dest_v1) |
134 | 0 | { |
135 | 0 | dest_v1->maxZones = 1; |
136 | 0 | dest_v1->maxTwilightPoints = 0; |
137 | 0 | dest_v1->maxStorage = 0; |
138 | 0 | dest_v1->maxFunctionDefs = 0; |
139 | 0 | dest_v1->maxInstructionDefs = 0; |
140 | 0 | dest_v1->maxStackElements = 0; |
141 | 0 | dest_v1->maxSizeOfInstructions = 0; |
142 | 0 | } |
143 | | |
144 | | protected: |
145 | | FixedVersion<>version;/* Version of the maxp table (0.5 or 1.0), |
146 | | * 0x00005000u or 0x00010000u. */ |
147 | | typename Types::HBUINT |
148 | | numGlyphs; |
149 | | /* The number of glyphs in the font. */ |
150 | | /*maxpV1Tail v1Tail[HB_VAR_ARRAY]; */ |
151 | | public: |
152 | | DEFINE_SIZE_STATIC (4 + Types::HBUINT::static_size); |
153 | | }; |
154 | | |
155 | | struct maxp : maxp_MAXP<Layout::SmallTypes> |
156 | | { |
157 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_maxp; |
158 | | }; |
159 | | |
160 | | struct MAXP : maxp_MAXP<Layout::MediumTypes> |
161 | | { |
162 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_MAXP; |
163 | | }; |
164 | | |
165 | | struct maxp_accelerator_t |
166 | | { |
167 | | maxp_accelerator_t () |
168 | 16.4k | { |
169 | 16.4k | blob = hb_blob_get_empty (); |
170 | 16.4k | numGlyphs = 0; |
171 | 16.4k | } |
172 | | |
173 | 16.4k | maxp_accelerator_t (hb_face_t *face) : maxp_accelerator_t () |
174 | 16.4k | { |
175 | | #ifndef HB_NO_BEYOND_64K |
176 | | if (init_table<MAXP> (face)) |
177 | | return; |
178 | | #endif |
179 | | |
180 | 16.4k | init_table<maxp> (face); |
181 | 16.4k | } |
182 | | |
183 | 16.3k | ~maxp_accelerator_t () { hb_blob_destroy (blob); } |
184 | | |
185 | 32.8k | unsigned int get_num_glyphs () const { return numGlyphs; } |
186 | 0 | hb_blob_t *get_blob () const { return blob; } |
187 | | |
188 | | private: |
189 | | template <typename Table> |
190 | | bool init_table (hb_face_t *face) |
191 | 16.4k | { |
192 | 16.4k | hb_sanitize_context_t c; |
193 | 16.4k | c.set_num_glyphs (0); |
194 | 16.4k | hb_blob_ptr_t<Table> table = c.reference_table<Table> (face); |
195 | 16.4k | bool ret = table.get_length (); |
196 | 16.4k | if (ret) |
197 | 16.4k | { |
198 | 16.4k | blob = hb_blob_reference (table.get_blob ()); |
199 | 16.4k | numGlyphs = table->get_num_glyphs (); |
200 | 16.4k | } |
201 | 16.4k | table.destroy (); |
202 | 16.4k | return ret; |
203 | 16.4k | } |
204 | | |
205 | | hb_blob_t *blob; |
206 | | unsigned int numGlyphs; |
207 | | }; |
208 | | |
209 | | |
210 | | } /* namespace OT */ |
211 | | |
212 | | |
213 | | #endif /* HB_OT_MAXP_TABLE_HH */ |