2 * Copyright © 2007,2008,2009 Red Hat, Inc.
3 * Copyright © 2012 Google, Inc.
5 * This is part of HarfBuzz, a text shaping library.
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 * Red Hat Author(s): Behdad Esfahbod
26 * Google Author(s): Behdad Esfahbod
29 #ifndef HB_OPEN_FILE_PRIVATE_HH
30 #define HB_OPEN_FILE_PRIVATE_HH
32 #include "hb-open-type-private.hh"
38 * The OpenType Font File
44 * Organization of an OpenType Font
47 struct OpenTypeFontFile;
52 typedef struct TableRecord
54 inline bool sanitize (hb_sanitize_context_t *c) {
56 return TRACE_RETURN (c->check_struct (this));
59 Tag tag; /* 4-byte identifier. */
60 CheckSum checkSum; /* CheckSum for this table. */
61 ULONG offset; /* Offset from beginning of TrueType font
63 ULONG length; /* Length of this table. */
65 DEFINE_SIZE_STATIC (16);
68 typedef struct OffsetTable
70 friend struct OpenTypeFontFile;
72 inline unsigned int get_table_count (void) const
74 inline const TableRecord& get_table (unsigned int i) const
76 if (unlikely (i >= numTables)) return Null(TableRecord);
79 inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
83 unsigned int count = numTables;
84 for (unsigned int i = 0; i < count; i++)
86 if (t == tables[i].tag)
88 if (table_index) *table_index = i;
92 if (table_index) *table_index = Index::NOT_FOUND_INDEX;
95 inline const TableRecord& get_table_by_tag (hb_tag_t tag) const
97 unsigned int table_index;
98 find_table_index (tag, &table_index);
99 return get_table (table_index);
103 inline bool sanitize (hb_sanitize_context_t *c) {
105 return TRACE_RETURN (c->check_struct (this) && c->check_array (tables, TableRecord::static_size, numTables));
109 Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
110 USHORT numTables; /* Number of tables. */
111 USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */
112 USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */
113 USHORT rangeShift; /* NumTables x 16-searchRange. */
114 TableRecord tables[VAR]; /* TableRecord entries. numTables items */
116 DEFINE_SIZE_ARRAY (12, tables);
121 * TrueType Collections
124 struct TTCHeaderVersion1
126 friend struct TTCHeader;
128 inline unsigned int get_face_count (void) const { return table.len; }
129 inline const OpenTypeFontFace& get_face (unsigned int i) const { return this+table[i]; }
131 inline bool sanitize (hb_sanitize_context_t *c) {
133 return TRACE_RETURN (table.sanitize (c, this));
137 Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */
138 FixedVersion version; /* Version of the TTC Header (1.0),
140 LongOffsetLongArrayOf<OffsetTable>
141 table; /* Array of offsets to the OffsetTable for each font
142 * from the beginning of the file */
144 DEFINE_SIZE_ARRAY (12, table);
149 friend struct OpenTypeFontFile;
153 inline unsigned int get_face_count (void) const
155 switch (u.header.version.major) {
156 case 2: /* version 2 is compatible with version 1 */
157 case 1: return u.version1.get_face_count ();
161 inline const OpenTypeFontFace& get_face (unsigned int i) const
163 switch (u.header.version.major) {
164 case 2: /* version 2 is compatible with version 1 */
165 case 1: return u.version1.get_face (i);
166 default:return Null(OpenTypeFontFace);
170 inline bool sanitize (hb_sanitize_context_t *c) {
172 if (unlikely (!u.header.version.sanitize (c))) return TRACE_RETURN (false);
173 switch (u.header.version.major) {
174 case 2: /* version 2 is compatible with version 1 */
175 case 1: return TRACE_RETURN (u.version1.sanitize (c));
176 default:return TRACE_RETURN (true);
183 Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */
184 FixedVersion version; /* Version of the TTC Header (1.0 or 2.0),
185 * 0x00010000 or 0x00020000 */
187 TTCHeaderVersion1 version1;
196 struct OpenTypeFontFile
198 static const hb_tag_t CFFTag = HB_TAG ('O','T','T','O'); /* OpenType with Postscript outlines */
199 static const hb_tag_t TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 ); /* OpenType with TrueType outlines */
200 static const hb_tag_t TTCTag = HB_TAG ('t','t','c','f'); /* TrueType Collection */
201 static const hb_tag_t TrueTag = HB_TAG ('t','r','u','e'); /* Obsolete Apple TrueType */
202 static const hb_tag_t Typ1Tag = HB_TAG ('t','y','p','1'); /* Obsolete Apple Type1 font in SFNT container */
204 inline hb_tag_t get_tag (void) const { return u.tag; }
206 inline unsigned int get_face_count (void) const
209 case CFFTag: /* All the non-collection tags */
212 case TrueTypeTag: return 1;
213 case TTCTag: return u.ttcHeader.get_face_count ();
217 inline const OpenTypeFontFace& get_face (unsigned int i) const
220 /* Note: for non-collection SFNT data we ignore index. This is because
221 * Apple dfont container is a container of SFNT's. So each SFNT is a
222 * non-TTC, but the index is more than zero. */
223 case CFFTag: /* All the non-collection tags */
226 case TrueTypeTag: return u.fontFace;
227 case TTCTag: return u.ttcHeader.get_face (i);
228 default: return Null(OpenTypeFontFace);
232 inline bool sanitize (hb_sanitize_context_t *c) {
234 if (unlikely (!u.tag.sanitize (c))) return TRACE_RETURN (false);
236 case CFFTag: /* All the non-collection tags */
239 case TrueTypeTag: return TRACE_RETURN (u.fontFace.sanitize (c));
240 case TTCTag: return TRACE_RETURN (u.ttcHeader.sanitize (c));
241 default: return TRACE_RETURN (true);
247 Tag tag; /* 4-byte identifier. */
248 OpenTypeFontFace fontFace;
252 DEFINE_SIZE_UNION (4, tag);
257 #endif /* HB_OPEN_FILE_PRIVATE_HH */