1// Copyright 2013 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Data model and I/O for glyph data within sfnt format files for the purpose of
16// performing the preprocessing step of the WOFF 2.0 conversion.
17
18#ifndef WOFF2_GLYPH_H_
19#define WOFF2_GLYPH_H_
20
21#include <stddef.h>
22#include <inttypes.h>
23#include <vector>
24
25namespace woff2 {
26
27// Represents a parsed simple or composite glyph. The composite glyph data and
28// instructions are un-parsed and we keep only pointers to the raw data,
29// therefore the glyph is valid only so long the data from which it was parsed
30// is around.
31class Glyph {
32 public:
33  Glyph() : instructions_size(0), composite_data_size(0) {}
34
35  // Bounding box.
36  int16_t x_min;
37  int16_t x_max;
38  int16_t y_min;
39  int16_t y_max;
40
41  // Instructions.
42  uint16_t instructions_size;
43  const uint8_t* instructions_data;
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.
62bool 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.
67bool StoreGlyph(const Glyph& glyph, uint8_t* dst, size_t* dst_size);
68
69} // namespace woff2
70
71#endif  // WOFF2_GLYPH_H_
72