12098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod/*
22409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2007,2008,2009  Red Hat, Inc.
30ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod * Copyright © 2012  Google, Inc.
42098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod *
5c755cb3e3ac55156d0d2ec05adea7a650b97cc41Behdad Esfahbod *  This is part of HarfBuzz, a text shaping library.
62098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod *
72098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * Permission is hereby granted, without written agreement and without
82098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
92098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * software and its documentation for any purpose, provided that the
102098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * above copyright notice and the following two paragraphs appear in
112098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * all copies of this software.
122098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod *
132098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
142098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
152098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
162098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
172098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * DAMAGE.
182098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod *
192098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
202098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
212098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
222098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
232098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
242098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod *
252098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * Red Hat Author(s): Behdad Esfahbod
260ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod * Google Author(s): Behdad Esfahbod
272098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod */
282098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
295f5b24f99f52bbc922e238b65c06061ba07c8548Behdad Esfahbod#ifndef HB_OPEN_FILE_PRIVATE_HH
305f5b24f99f52bbc922e238b65c06061ba07c8548Behdad Esfahbod#define HB_OPEN_FILE_PRIVATE_HH
312098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
327edb430f9182723b7b720708c56088cec1200a70Behdad Esfahbod#include "hb-open-type-private.hh"
332098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
34acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod
357c8e844d92aa604fc4b396343721ea90eb83adb8Behdad Esfahbodnamespace OT {
367c8e844d92aa604fc4b396343721ea90eb83adb8Behdad Esfahbod
372098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
382098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod/*
392098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod *
402098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * The OpenType Font File
412098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod *
422098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod */
432098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
442098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
452098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod/*
462098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * Organization of an OpenType Font
472098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod */
482098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
492098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbodstruct OpenTypeFontFile;
502098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbodstruct OffsetTable;
512098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbodstruct TTCHeader;
522098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
53569da92bc6956f42d9b2d65c784e184fb6380efeBehdad Esfahbod
5422c537657cee1f47a4056a21e2cddfcbe6ab1c01Behdad Esfahbodtypedef struct TableRecord
552098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod{
56d7cfb3b2d1dd2e9fdae2b3e540bbe313660895e8Behdad Esfahbod  inline bool sanitize (hb_sanitize_context_t *c) {
57be218c688cbb037a99c8c64bb835f3c980040c0bBehdad Esfahbod    TRACE_SANITIZE (this);
580ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod    return TRACE_RETURN (c->check_struct (this));
59b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod  }
60b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod
612098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  Tag		tag;		/* 4-byte identifier. */
622098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  CheckSum	checkSum;	/* CheckSum for this table. */
632098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  ULONG		offset;		/* Offset from beginning of TrueType font
642098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod				 * file. */
652098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  ULONG		length;		/* Length of this table. */
66569da92bc6956f42d9b2d65c784e184fb6380efeBehdad Esfahbod  public:
67569da92bc6956f42d9b2d65c784e184fb6380efeBehdad Esfahbod  DEFINE_SIZE_STATIC (16);
682098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod} OpenTypeTable;
692098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
702098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbodtypedef struct OffsetTable
712098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod{
722098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  friend struct OpenTypeFontFile;
732098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
74bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod  inline unsigned int get_table_count (void) const
75bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod  { return numTables; }
7622c537657cee1f47a4056a21e2cddfcbe6ab1c01Behdad Esfahbod  inline const TableRecord& get_table (unsigned int i) const
77bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod  {
7822c537657cee1f47a4056a21e2cddfcbe6ab1c01Behdad Esfahbod    if (unlikely (i >= numTables)) return Null(TableRecord);
7922c537657cee1f47a4056a21e2cddfcbe6ab1c01Behdad Esfahbod    return tables[i];
80bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod  }
81bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod  inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
82bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod  {
83ffd321afd91429c5de7ab03d71ef1030044f53cbBehdad Esfahbod    Tag t;
84ffd321afd91429c5de7ab03d71ef1030044f53cbBehdad Esfahbod    t.set (tag);
85bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod    unsigned int count = numTables;
86bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod    for (unsigned int i = 0; i < count; i++)
87bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod    {
8822c537657cee1f47a4056a21e2cddfcbe6ab1c01Behdad Esfahbod      if (t == tables[i].tag)
89bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod      {
90bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod        if (table_index) *table_index = i;
91bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod        return true;
92bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod      }
93bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod    }
94b5db4f1e4eefa266a71a28b5496f47ff9d1a81e8Behdad Esfahbod    if (table_index) *table_index = Index::NOT_FOUND_INDEX;
95bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod    return false;
96bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod  }
9722c537657cee1f47a4056a21e2cddfcbe6ab1c01Behdad Esfahbod  inline const TableRecord& get_table_by_tag (hb_tag_t tag) const
98bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod  {
99bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod    unsigned int table_index;
100bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod    find_table_index (tag, &table_index);
101bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod    return get_table (table_index);
102bff3c0fde5da04a70d1f7aeeb9fa2a75fe5c07f6Behdad Esfahbod  }
103b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod
104b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod  public:
105d7cfb3b2d1dd2e9fdae2b3e540bbe313660895e8Behdad Esfahbod  inline bool sanitize (hb_sanitize_context_t *c) {
106be218c688cbb037a99c8c64bb835f3c980040c0bBehdad Esfahbod    TRACE_SANITIZE (this);
1070ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod    return TRACE_RETURN (c->check_struct (this) && c->check_array (tables, TableRecord::static_size, numTables));
108b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod  }
109b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod
110ec8d2494694275dfbbac2dd0d33ca2894b0463d6Behdad Esfahbod  protected:
1112098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  Tag		sfnt_version;	/* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
1122098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  USHORT	numTables;	/* Number of tables. */
1137d4ada66c96a748ce92f8e8edac149361c3dc829Behdad Esfahbod  USHORT	searchRangeZ;	/* (Maximum power of 2 <= numTables) x 16 */
1147d4ada66c96a748ce92f8e8edac149361c3dc829Behdad Esfahbod  USHORT	entrySelectorZ;	/* Log2(maximum power of 2 <= numTables). */
1157d4ada66c96a748ce92f8e8edac149361c3dc829Behdad Esfahbod  USHORT	rangeShiftZ;	/* NumTables x 16-searchRange. */
11622c537657cee1f47a4056a21e2cddfcbe6ab1c01Behdad Esfahbod  TableRecord	tables[VAR];	/* TableRecord entries. numTables items */
117569da92bc6956f42d9b2d65c784e184fb6380efeBehdad Esfahbod  public:
11822c537657cee1f47a4056a21e2cddfcbe6ab1c01Behdad Esfahbod  DEFINE_SIZE_ARRAY (12, tables);
1192098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod} OpenTypeFontFace;
120569da92bc6956f42d9b2d65c784e184fb6380efeBehdad Esfahbod
1212098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
1222098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod/*
1232098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * TrueType Collections
1242098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod */
1252098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
126ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbodstruct TTCHeaderVersion1
1272098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod{
128ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  friend struct TTCHeader;
1292098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
13020b035dad41247076815a2bbb0346d63058b322fBehdad Esfahbod  inline unsigned int get_face_count (void) const { return table.len; }
131df3f505dcfeefc8cd395900b116767d22549f756Behdad Esfahbod  inline const OpenTypeFontFace& get_face (unsigned int i) const { return this+table[i]; }
132b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod
133d7cfb3b2d1dd2e9fdae2b3e540bbe313660895e8Behdad Esfahbod  inline bool sanitize (hb_sanitize_context_t *c) {
134be218c688cbb037a99c8c64bb835f3c980040c0bBehdad Esfahbod    TRACE_SANITIZE (this);
1350ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod    return TRACE_RETURN (table.sanitize (c, this));
136b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod  }
137b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod
138ec8d2494694275dfbbac2dd0d33ca2894b0463d6Behdad Esfahbod  protected:
1392098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  Tag		ttcTag;		/* TrueType Collection ID string: 'ttcf' */
140ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  FixedVersion	version;	/* Version of the TTC Header (1.0),
1417627100f428ac0ec8509d961d368d2d25d8f0b6eBehdad Esfahbod				 * 0x00010000u */
1423084767e92483c669f38319f153c498e9a6b92c7Behdad Esfahbod  ArrayOf<OffsetTo<OffsetTable, ULONG>, ULONG>
1432098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod		table;		/* Array of offsets to the OffsetTable for each font
1442098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod				 * from the beginning of the file */
145b3651231bf80bb7009214547a75ed90e21815c68Behdad Esfahbod  public:
1460eb9fc6e37935707dba2bf4b3705de2161a08cb7Behdad Esfahbod  DEFINE_SIZE_ARRAY (12, table);
1472098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod};
148ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod
149ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbodstruct TTCHeader
150ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod{
151ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  friend struct OpenTypeFontFile;
152ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod
153ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  private:
154ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod
155ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  inline unsigned int get_face_count (void) const
156ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  {
1574f28fbdd804fabeec57a98fe267d892ab58b3a6dBehdad Esfahbod    switch (u.header.version.major) {
158ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod    case 2: /* version 2 is compatible with version 1 */
159dacebcadae36b35531d635d81df2afb937677b7aBehdad Esfahbod    case 1: return u.version1.get_face_count ();
160ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod    default:return 0;
161ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod    }
162ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  }
163ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  inline const OpenTypeFontFace& get_face (unsigned int i) const
164ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  {
1654f28fbdd804fabeec57a98fe267d892ab58b3a6dBehdad Esfahbod    switch (u.header.version.major) {
166ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod    case 2: /* version 2 is compatible with version 1 */
167dacebcadae36b35531d635d81df2afb937677b7aBehdad Esfahbod    case 1: return u.version1.get_face (i);
1681aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod    default:return Null(OpenTypeFontFace);
169ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod    }
170ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  }
171ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod
172d7cfb3b2d1dd2e9fdae2b3e540bbe313660895e8Behdad Esfahbod  inline bool sanitize (hb_sanitize_context_t *c) {
173be218c688cbb037a99c8c64bb835f3c980040c0bBehdad Esfahbod    TRACE_SANITIZE (this);
1740ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod    if (unlikely (!u.header.version.sanitize (c))) return TRACE_RETURN (false);
1754f28fbdd804fabeec57a98fe267d892ab58b3a6dBehdad Esfahbod    switch (u.header.version.major) {
176ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod    case 2: /* version 2 is compatible with version 1 */
1770ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod    case 1: return TRACE_RETURN (u.version1.sanitize (c));
1780ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod    default:return TRACE_RETURN (true);
179ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod    }
180ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  }
181ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod
182ec8d2494694275dfbbac2dd0d33ca2894b0463d6Behdad Esfahbod  protected:
183ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  union {
184ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  struct {
185ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  Tag		ttcTag;		/* TrueType Collection ID string: 'ttcf' */
186ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  FixedVersion	version;	/* Version of the TTC Header (1.0 or 2.0),
1877627100f428ac0ec8509d961d368d2d25d8f0b6eBehdad Esfahbod				 * 0x00010000u or 0x00020000u */
188ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  }			header;
189dacebcadae36b35531d635d81df2afb937677b7aBehdad Esfahbod  TTCHeaderVersion1	version1;
190ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod  } u;
191ae4190cafe927649f8ff8be6a0082478d1298fdaBehdad Esfahbod};
1922098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
1932098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
1942098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod/*
1952098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod * OpenType Font File
1962098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod */
1972098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
1982098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbodstruct OpenTypeFontFile
1992098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod{
200710500a93ecc2a0c595045602aa367073485ff91Behdad Esfahbod  static const hb_tag_t CFFTag		= HB_TAG ('O','T','T','O'); /* OpenType with Postscript outlines */
201710500a93ecc2a0c595045602aa367073485ff91Behdad Esfahbod  static const hb_tag_t TrueTypeTag	= HB_TAG ( 0 , 1 , 0 , 0 ); /* OpenType with TrueType outlines */
202710500a93ecc2a0c595045602aa367073485ff91Behdad Esfahbod  static const hb_tag_t TTCTag		= HB_TAG ('t','t','c','f'); /* TrueType Collection */
203ce5694c79671bf75990923c1da17bb611e4e7d15Behdad Esfahbod  static const hb_tag_t TrueTag		= HB_TAG ('t','r','u','e'); /* Obsolete Apple TrueType */
204ce5694c79671bf75990923c1da17bb611e4e7d15Behdad Esfahbod  static const hb_tag_t Typ1Tag		= HB_TAG ('t','y','p','1'); /* Obsolete Apple Type1 font in SFNT container */
2052098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
2061aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod  inline hb_tag_t get_tag (void) const { return u.tag; }
2071aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod
20820b035dad41247076815a2bbb0346d63058b322fBehdad Esfahbod  inline unsigned int get_face_count (void) const
2092098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  {
2101aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod    switch (u.tag) {
2111aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod    case CFFTag:	/* All the non-collection tags */
2124ce578ed369f1526c91deedcf9e72537b3e4328fJeff Muizelaar    case TrueTag:
2134ce578ed369f1526c91deedcf9e72537b3e4328fJeff Muizelaar    case Typ1Tag:
2141aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod    case TrueTypeTag:	return 1;
215dacebcadae36b35531d635d81df2afb937677b7aBehdad Esfahbod    case TTCTag:	return u.ttcHeader.get_face_count ();
2161aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod    default:		return 0;
2172098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod    }
2182098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  }
21920b035dad41247076815a2bbb0346d63058b322fBehdad Esfahbod  inline const OpenTypeFontFace& get_face (unsigned int i) const
2202098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  {
2211aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod    switch (u.tag) {
2222098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod    /* Note: for non-collection SFNT data we ignore index.  This is because
2232098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod     * Apple dfont container is a container of SFNT's.  So each SFNT is a
2242098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod     * non-TTC, but the index is more than zero. */
2251aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod    case CFFTag:	/* All the non-collection tags */
2264ce578ed369f1526c91deedcf9e72537b3e4328fJeff Muizelaar    case TrueTag:
2274ce578ed369f1526c91deedcf9e72537b3e4328fJeff Muizelaar    case Typ1Tag:
228dacebcadae36b35531d635d81df2afb937677b7aBehdad Esfahbod    case TrueTypeTag:	return u.fontFace;
229dacebcadae36b35531d635d81df2afb937677b7aBehdad Esfahbod    case TTCTag:	return u.ttcHeader.get_face (i);
2301aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod    default:		return Null(OpenTypeFontFace);
2312098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod    }
2322098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod  }
2332098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
234d7cfb3b2d1dd2e9fdae2b3e540bbe313660895e8Behdad Esfahbod  inline bool sanitize (hb_sanitize_context_t *c) {
235be218c688cbb037a99c8c64bb835f3c980040c0bBehdad Esfahbod    TRACE_SANITIZE (this);
2360ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod    if (unlikely (!u.tag.sanitize (c))) return TRACE_RETURN (false);
2371aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod    switch (u.tag) {
2381aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod    case CFFTag:	/* All the non-collection tags */
2394ce578ed369f1526c91deedcf9e72537b3e4328fJeff Muizelaar    case TrueTag:
2404ce578ed369f1526c91deedcf9e72537b3e4328fJeff Muizelaar    case Typ1Tag:
2410ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod    case TrueTypeTag:	return TRACE_RETURN (u.fontFace.sanitize (c));
2420ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod    case TTCTag:	return TRACE_RETURN (u.ttcHeader.sanitize (c));
2430ab8c8621712d33e1e91dfdb4ad0b335e3d2a3fbBehdad Esfahbod    default:		return TRACE_RETURN (true);
244b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod    }
245b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod  }
246b508e5ccd528f3f0f49f545bd5f30a525d5abd5aBehdad Esfahbod
247ec8d2494694275dfbbac2dd0d33ca2894b0463d6Behdad Esfahbod  protected:
2481aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod  union {
2491aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod  Tag			tag;		/* 4-byte identifier. */
250dacebcadae36b35531d635d81df2afb937677b7aBehdad Esfahbod  OpenTypeFontFace	fontFace;
251dacebcadae36b35531d635d81df2afb937677b7aBehdad Esfahbod  TTCHeader		ttcHeader;
2521aa4666b914da7747fc58a8f6f2d913c94e3b8daBehdad Esfahbod  } u;
253dacebcadae36b35531d635d81df2afb937677b7aBehdad Esfahbod  public:
254dacebcadae36b35531d635d81df2afb937677b7aBehdad Esfahbod  DEFINE_SIZE_UNION (4, tag);
2552098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod};
2562098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
2572098a021a826e76ee27d5db74e32738d7d1c3d30Behdad Esfahbod
2587d52e6601f0e695690cd168a288466746cf25300Behdad Esfahbod} /* namespace OT */
2597c8e844d92aa604fc4b396343721ea90eb83adb8Behdad Esfahbod
260acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod
2615f5b24f99f52bbc922e238b65c06061ba07c8548Behdad Esfahbod#endif /* HB_OPEN_FILE_PRIVATE_HH */
262