Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f
[chromium-blink-merge.git] / third_party / woff2 / src / font.h
blob08c414ce765f4485a366375266dc3e3c8110f4a3
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.
15 // Data model for a font file in sfnt format, reading and writing functions and
16 // accessors for the glyph data.
18 #ifndef WOFF2_FONT_H_
19 #define WOFF2_FONT_H_
21 #include <stddef.h>
22 #include <inttypes.h>
23 #include <map>
24 #include <vector>
26 namespace woff2 {
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.
31 struct Font {
32 uint32_t flavor;
33 uint16_t num_tables;
35 struct Table {
36 uint32_t tag;
37 uint32_t checksum;
38 uint32_t offset;
39 uint32_t length;
40 const uint8_t* data;
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
53 // valid.
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);
80 } // namespace woff2
82 #endif // WOFF2_FONT_H_