Debian Codegraph @

src/glyph.h

raw
1 /* Copyright 2013 Google Inc. All Rights Reserved.
2
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6
7 /* Data model and I/O for glyph data within sfnt format files for the purpose of
8 performing the preprocessing step of the WOFF 2.0 conversion. */
9
10 #ifndef WOFF2_GLYPH_H_
11 #define WOFF2_GLYPH_H_
12
13 #include <stddef.h>
14 #include <inttypes.h>
15 #include <vector>
16
17 namespace woff2 {
18
19 // Represents a parsed simple or composite glyph. The composite glyph data and
20 // instructions are un-parsed and we keep only pointers to the raw data,
21 // therefore the glyph is valid only so long the data from which it was parsed
22 // is around.
23 class Glyph {
24 public:
25 Glyph() : instructions_size(0), composite_data_size(0) {}
26
27 // Bounding box.
28 int16_t x_min;
29 int16_t x_max;
30 int16_t y_min;
31 int16_t y_max;
32
33 // Instructions.
34 uint16_t instructions_size;
35 const uint8_t* instructions_data;
36
37 // Data model for simple glyphs.
38 struct Point {
39 int x;
40 int y;
41 bool on_curve;
42 };
43 std::vector<std::vector<Point> > contours;
44
45 // Data for composite glyphs.
46 const uint8_t* composite_data;
47 uint32_t composite_data_size;
48 bool have_instructions;
49 };
50
51 // Parses the glyph from the given data. Returns false on parsing failure or
52 // buffer overflow. The glyph is valid only so long the input data pointer is
53 // valid.
54 bool ReadGlyph(const uint8_t* data, size_t len, Glyph* glyph);
55
56 // Stores the glyph into the specified dst buffer. The *dst_size is the buffer
57 // size on entry and is set to the actual (unpadded) stored size on exit.
58 // Returns false on buffer overflow.
59 bool StoreGlyph(const Glyph& glyph, uint8_t* dst, size_t* dst_size);
60
61 } // namespace woff2
62
63 #endif // WOFF2_GLYPH_H_