Line | Count | Source |
1 | | // Copyright (c) 2009-2017 The OTS Authors. All rights reserved. |
2 | | // Use of this source code is governed by a BSD-style license that can be |
3 | | // found in the LICENSE file. |
4 | | |
5 | | #ifndef OTS_GLYF_H_ |
6 | | #define OTS_GLYF_H_ |
7 | | |
8 | | #include <new> |
9 | | #include <utility> |
10 | | #include <vector> |
11 | | |
12 | | #include "ots.h" |
13 | | |
14 | | namespace ots { |
15 | | class OpenTypeLOCA; |
16 | | class OpenTypeMAXP; |
17 | | |
18 | | class OpenTypeGLYF : public Table { |
19 | | public: |
20 | | explicit OpenTypeGLYF(Font *font, uint32_t tag) |
21 | 83.0k | : Table(font, tag, tag), maxp(NULL) { } |
22 | | |
23 | 83.0k | ~OpenTypeGLYF() { |
24 | 83.0k | for (auto* p : replacements) { |
25 | 19.4k | delete[] p; |
26 | 19.4k | } |
27 | 83.0k | } |
28 | | |
29 | | bool Parse(const uint8_t *data, size_t length); |
30 | | bool Serialize(OTSStream *out); |
31 | | |
32 | | private: |
33 | | // What a glyph contributes when it is used as a component of a composite |
34 | | // glyph. Computed at most once per glyph, so that shared and repeated |
35 | | // components are not expanded again for every path that reaches them. |
36 | | struct ComponentInfo { |
37 | | enum State : uint8_t { kUnvisited, kInProgress, kDone }; |
38 | | State state = kUnvisited; |
39 | | bool empty = true; // no glyph data, or numberOfContours == 0 |
40 | | uint32_t points = 0; // number of points after flattening components |
41 | | uint32_t components = 0; // number of components after flattening |
42 | | uint32_t depth = 0; // levels of nested components below this glyph |
43 | | }; |
44 | | |
45 | | bool ParseFlagsForSimpleGlyph(Buffer &glyph, |
46 | | uint32_t num_flags, |
47 | | std::vector<uint8_t>& flags, |
48 | | uint32_t *flag_index, |
49 | | uint32_t *coordinates_length); |
50 | | bool ParseSimpleGlyph(Buffer &glyph, |
51 | | unsigned gid, |
52 | | int16_t num_contours, |
53 | | int16_t xmin, |
54 | | int16_t ymin, |
55 | | int16_t xmax, |
56 | | int16_t ymax, |
57 | | bool is_tricky_font); |
58 | | |
59 | | // The skip_count outparam returns the number of bytes from the original |
60 | | // glyph description that are being skipped on output (normally zero). |
61 | | bool ParseCompositeGlyph( |
62 | | Buffer &glyph, |
63 | | unsigned glyph_id, |
64 | | unsigned* skip_count); |
65 | | |
66 | | // Fills in component_info for glyph_id and every glyph it refers to, |
67 | | // directly or through nested components. |
68 | | bool ComputeComponentInfo( |
69 | | const uint8_t *data, |
70 | | size_t length, |
71 | | const std::vector<uint32_t>& loca_offsets, |
72 | | uint16_t glyph_id, |
73 | | std::vector<ComponentInfo>* component_info); |
74 | | |
75 | | // Reads the point count of a simple glyph into info, or the component |
76 | | // glyph ids of a composite glyph into components. |
77 | | bool ReadComponentInfo( |
78 | | Buffer& glyph, |
79 | | ComponentInfo* info, |
80 | | std::vector<uint16_t>* components); |
81 | | |
82 | | Buffer GetGlyphBufferSection( |
83 | | const uint8_t *data, |
84 | | size_t length, |
85 | | const std::vector<uint32_t>& loca_offsets, |
86 | | unsigned glyph_id); |
87 | | |
88 | | OpenTypeLOCA* loca; |
89 | | OpenTypeMAXP* maxp; |
90 | | |
91 | | std::vector<std::pair<const uint8_t*, size_t> > iov; |
92 | | |
93 | | // Any blocks of replacement data created during parsing are stored here |
94 | | // to be available during serialization. |
95 | | std::vector<uint8_t*> replacements; |
96 | | }; |
97 | | |
98 | | } // namespace ots |
99 | | |
100 | | #endif // OTS_GLYF_H_ |