1 // Copyright 2013 Google Inc. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 // Data model for a font file in sfnt format, reading and writing functions and
16 // accessors for the glyph data.
28 // Represents an sfnt font file. Only the table directory is parsed, for the
29 // table data we only store a raw pointer, therefore a font object is valid only
30 // as long the data from which it was parsed is around.
42 // Buffer used to mutate the data before writing out.
43 std::vector
<uint8_t> buffer
;
45 std::map
<uint32_t, Table
> tables
;
47 Table
* FindTable(uint32_t tag
);
48 const Table
* FindTable(uint32_t tag
) const;
51 // Parses the font from the given data. Returns false on parsing failure or
52 // buffer overflow. The font is valid only so long the input data pointer is
54 bool ReadFont(const uint8_t* data
, size_t len
, Font
* font
);
56 // Returns the file size of the font.
57 size_t FontFileSize(const Font
& font
);
59 // Writes the font into the specified dst buffer. The dst_size should be the
60 // same as returned by FontFileSize(). Returns false upon buffer overflow (which
61 // should not happen if dst_size was computed by FontFileSize()).
62 bool WriteFont(const Font
& font
, uint8_t* dst
, size_t dst_size
);
64 // Returns the number of glyphs in the font.
65 // NOTE: Currently this works only for TrueType-flavored fonts, will return
66 // zero for CFF-flavored fonts.
67 int NumGlyphs(const Font
& font
);
69 // Returns the index format of the font
70 int IndexFormat(const Font
& font
);
72 // Sets *glyph_data and *glyph_size to point to the location of the glyph data
73 // with the given index. Returns false if the glyph is not found.
74 bool GetGlyphData(const Font
& font
, int glyph_index
,
75 const uint8_t** glyph_data
, size_t* glyph_size
);
77 // Removes the digital signature (DSIG) table
78 bool RemoveDigitalSignature(Font
* font
);
82 #endif // WOFF2_FONT_H_