| 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 <inttypes.h> |
| 14 |
#include <stddef.h> |
| 15 |
|
| 16 |
#include <cstdint> |
| 17 |
#include <vector> |
| 18 |
|
| 19 |
namespace woff2 { |
| 20 |
|
| 21 |
// Represents a parsed simple or composite glyph. The composite glyph data and |
| 22 |
// instructions are un-parsed and we keep only pointers to the raw data, |
| 23 |
// therefore the glyph is valid only so long the data from which it was parsed |
| 24 |
// is around. |
| 25 |
class Glyph { |
| 26 |
public: |
| 27 |
Glyph() |
| 28 |
: instructions_size(0), |
| 29 |
overlap_simple_flag_set(false), |
| 30 |
composite_data_size(0) {} |
| 31 |
|
| 32 |
// Bounding box. |
| 33 |
int16_t x_min; |
| 34 |
int16_t x_max; |
| 35 |
int16_t y_min; |
| 36 |
int16_t y_max; |
| 37 |
|
| 38 |
// Instructions. |
| 39 |
uint16_t instructions_size; |
| 40 |
const uint8_t* instructions_data; |
| 41 |
|
| 42 |
// Flags. |
| 43 |
bool overlap_simple_flag_set; |
| 44 |
|
| 45 |
// Data model for simple glyphs. |
| 46 |
struct Point { |
| 47 |
int x; |
| 48 |
int y; |
| 49 |
bool on_curve; |
| 50 |
}; |
| 51 |
std::vector<std::vector<Point> > contours; |
| 52 |
|
| 53 |
// Data for composite glyphs. |
| 54 |
const uint8_t* composite_data; |
| 55 |
uint32_t composite_data_size; |
| 56 |
bool have_instructions; |
| 57 |
}; |
| 58 |
|
| 59 |
// Parses the glyph from the given data. Returns false on parsing failure or |
| 60 |
// buffer overflow. The glyph is valid only so long the input data pointer is |
| 61 |
// valid. |
| 62 |
bool ReadGlyph(const uint8_t* data, size_t len, Glyph* glyph); |
| 63 |
|
| 64 |
// Stores the glyph into the specified dst buffer. The *dst_size is the buffer |
| 65 |
// size on entry and is set to the actual (unpadded) stored size on exit. |
| 66 |
// Returns false on buffer overflow. |
| 67 |
bool StoreGlyph(const Glyph& glyph, uint8_t* dst, size_t* dst_size); |
| 68 |
|
| 69 |
} // namespace woff2 |
| 70 |
|
| 71 |
#endif // WOFF2_GLYPH_H_ |