gfx/harfbuzz/src/hb-open-file-private.hh

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/harfbuzz/src/hb-open-file-private.hh	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,261 @@
     1.4 +/*
     1.5 + * Copyright © 2007,2008,2009  Red Hat, Inc.
     1.6 + * Copyright © 2012  Google, Inc.
     1.7 + *
     1.8 + *  This is part of HarfBuzz, a text shaping library.
     1.9 + *
    1.10 + * Permission is hereby granted, without written agreement and without
    1.11 + * license or royalty fees, to use, copy, modify, and distribute this
    1.12 + * software and its documentation for any purpose, provided that the
    1.13 + * above copyright notice and the following two paragraphs appear in
    1.14 + * all copies of this software.
    1.15 + *
    1.16 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
    1.17 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
    1.18 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
    1.19 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
    1.20 + * DAMAGE.
    1.21 + *
    1.22 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
    1.23 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    1.24 + * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
    1.25 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
    1.26 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
    1.27 + *
    1.28 + * Red Hat Author(s): Behdad Esfahbod
    1.29 + * Google Author(s): Behdad Esfahbod
    1.30 + */
    1.31 +
    1.32 +#ifndef HB_OPEN_FILE_PRIVATE_HH
    1.33 +#define HB_OPEN_FILE_PRIVATE_HH
    1.34 +
    1.35 +#include "hb-open-type-private.hh"
    1.36 +
    1.37 +
    1.38 +namespace OT {
    1.39 +
    1.40 +
    1.41 +/*
    1.42 + *
    1.43 + * The OpenType Font File
    1.44 + *
    1.45 + */
    1.46 +
    1.47 +
    1.48 +/*
    1.49 + * Organization of an OpenType Font
    1.50 + */
    1.51 +
    1.52 +struct OpenTypeFontFile;
    1.53 +struct OffsetTable;
    1.54 +struct TTCHeader;
    1.55 +
    1.56 +
    1.57 +typedef struct TableRecord
    1.58 +{
    1.59 +  inline bool sanitize (hb_sanitize_context_t *c) {
    1.60 +    TRACE_SANITIZE (this);
    1.61 +    return TRACE_RETURN (c->check_struct (this));
    1.62 +  }
    1.63 +
    1.64 +  Tag		tag;		/* 4-byte identifier. */
    1.65 +  CheckSum	checkSum;	/* CheckSum for this table. */
    1.66 +  ULONG		offset;		/* Offset from beginning of TrueType font
    1.67 +				 * file. */
    1.68 +  ULONG		length;		/* Length of this table. */
    1.69 +  public:
    1.70 +  DEFINE_SIZE_STATIC (16);
    1.71 +} OpenTypeTable;
    1.72 +
    1.73 +typedef struct OffsetTable
    1.74 +{
    1.75 +  friend struct OpenTypeFontFile;
    1.76 +
    1.77 +  inline unsigned int get_table_count (void) const
    1.78 +  { return numTables; }
    1.79 +  inline const TableRecord& get_table (unsigned int i) const
    1.80 +  {
    1.81 +    if (unlikely (i >= numTables)) return Null(TableRecord);
    1.82 +    return tables[i];
    1.83 +  }
    1.84 +  inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
    1.85 +  {
    1.86 +    Tag t;
    1.87 +    t.set (tag);
    1.88 +    unsigned int count = numTables;
    1.89 +    for (unsigned int i = 0; i < count; i++)
    1.90 +    {
    1.91 +      if (t == tables[i].tag)
    1.92 +      {
    1.93 +        if (table_index) *table_index = i;
    1.94 +        return true;
    1.95 +      }
    1.96 +    }
    1.97 +    if (table_index) *table_index = Index::NOT_FOUND_INDEX;
    1.98 +    return false;
    1.99 +  }
   1.100 +  inline const TableRecord& get_table_by_tag (hb_tag_t tag) const
   1.101 +  {
   1.102 +    unsigned int table_index;
   1.103 +    find_table_index (tag, &table_index);
   1.104 +    return get_table (table_index);
   1.105 +  }
   1.106 +
   1.107 +  public:
   1.108 +  inline bool sanitize (hb_sanitize_context_t *c) {
   1.109 +    TRACE_SANITIZE (this);
   1.110 +    return TRACE_RETURN (c->check_struct (this) && c->check_array (tables, TableRecord::static_size, numTables));
   1.111 +  }
   1.112 +
   1.113 +  protected:
   1.114 +  Tag		sfnt_version;	/* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
   1.115 +  USHORT	numTables;	/* Number of tables. */
   1.116 +  USHORT	searchRange;	/* (Maximum power of 2 <= numTables) x 16 */
   1.117 +  USHORT	entrySelector;	/* Log2(maximum power of 2 <= numTables). */
   1.118 +  USHORT	rangeShift;	/* NumTables x 16-searchRange. */
   1.119 +  TableRecord	tables[VAR];	/* TableRecord entries. numTables items */
   1.120 +  public:
   1.121 +  DEFINE_SIZE_ARRAY (12, tables);
   1.122 +} OpenTypeFontFace;
   1.123 +
   1.124 +
   1.125 +/*
   1.126 + * TrueType Collections
   1.127 + */
   1.128 +
   1.129 +struct TTCHeaderVersion1
   1.130 +{
   1.131 +  friend struct TTCHeader;
   1.132 +
   1.133 +  inline unsigned int get_face_count (void) const { return table.len; }
   1.134 +  inline const OpenTypeFontFace& get_face (unsigned int i) const { return this+table[i]; }
   1.135 +
   1.136 +  inline bool sanitize (hb_sanitize_context_t *c) {
   1.137 +    TRACE_SANITIZE (this);
   1.138 +    return TRACE_RETURN (table.sanitize (c, this));
   1.139 +  }
   1.140 +
   1.141 +  protected:
   1.142 +  Tag		ttcTag;		/* TrueType Collection ID string: 'ttcf' */
   1.143 +  FixedVersion	version;	/* Version of the TTC Header (1.0),
   1.144 +				 * 0x00010000 */
   1.145 +  LongOffsetLongArrayOf<OffsetTable>
   1.146 +		table;		/* Array of offsets to the OffsetTable for each font
   1.147 +				 * from the beginning of the file */
   1.148 +  public:
   1.149 +  DEFINE_SIZE_ARRAY (12, table);
   1.150 +};
   1.151 +
   1.152 +struct TTCHeader
   1.153 +{
   1.154 +  friend struct OpenTypeFontFile;
   1.155 +
   1.156 +  private:
   1.157 +
   1.158 +  inline unsigned int get_face_count (void) const
   1.159 +  {
   1.160 +    switch (u.header.version.major) {
   1.161 +    case 2: /* version 2 is compatible with version 1 */
   1.162 +    case 1: return u.version1.get_face_count ();
   1.163 +    default:return 0;
   1.164 +    }
   1.165 +  }
   1.166 +  inline const OpenTypeFontFace& get_face (unsigned int i) const
   1.167 +  {
   1.168 +    switch (u.header.version.major) {
   1.169 +    case 2: /* version 2 is compatible with version 1 */
   1.170 +    case 1: return u.version1.get_face (i);
   1.171 +    default:return Null(OpenTypeFontFace);
   1.172 +    }
   1.173 +  }
   1.174 +
   1.175 +  inline bool sanitize (hb_sanitize_context_t *c) {
   1.176 +    TRACE_SANITIZE (this);
   1.177 +    if (unlikely (!u.header.version.sanitize (c))) return TRACE_RETURN (false);
   1.178 +    switch (u.header.version.major) {
   1.179 +    case 2: /* version 2 is compatible with version 1 */
   1.180 +    case 1: return TRACE_RETURN (u.version1.sanitize (c));
   1.181 +    default:return TRACE_RETURN (true);
   1.182 +    }
   1.183 +  }
   1.184 +
   1.185 +  protected:
   1.186 +  union {
   1.187 +  struct {
   1.188 +  Tag		ttcTag;		/* TrueType Collection ID string: 'ttcf' */
   1.189 +  FixedVersion	version;	/* Version of the TTC Header (1.0 or 2.0),
   1.190 +				 * 0x00010000 or 0x00020000 */
   1.191 +  }			header;
   1.192 +  TTCHeaderVersion1	version1;
   1.193 +  } u;
   1.194 +};
   1.195 +
   1.196 +
   1.197 +/*
   1.198 + * OpenType Font File
   1.199 + */
   1.200 +
   1.201 +struct OpenTypeFontFile
   1.202 +{
   1.203 +  static const hb_tag_t CFFTag		= HB_TAG ('O','T','T','O'); /* OpenType with Postscript outlines */
   1.204 +  static const hb_tag_t TrueTypeTag	= HB_TAG ( 0 , 1 , 0 , 0 ); /* OpenType with TrueType outlines */
   1.205 +  static const hb_tag_t TTCTag		= HB_TAG ('t','t','c','f'); /* TrueType Collection */
   1.206 +  static const hb_tag_t TrueTag		= HB_TAG ('t','r','u','e'); /* Obsolete Apple TrueType */
   1.207 +  static const hb_tag_t Typ1Tag		= HB_TAG ('t','y','p','1'); /* Obsolete Apple Type1 font in SFNT container */
   1.208 +
   1.209 +  inline hb_tag_t get_tag (void) const { return u.tag; }
   1.210 +
   1.211 +  inline unsigned int get_face_count (void) const
   1.212 +  {
   1.213 +    switch (u.tag) {
   1.214 +    case CFFTag:	/* All the non-collection tags */
   1.215 +    case TrueTag:
   1.216 +    case Typ1Tag:
   1.217 +    case TrueTypeTag:	return 1;
   1.218 +    case TTCTag:	return u.ttcHeader.get_face_count ();
   1.219 +    default:		return 0;
   1.220 +    }
   1.221 +  }
   1.222 +  inline const OpenTypeFontFace& get_face (unsigned int i) const
   1.223 +  {
   1.224 +    switch (u.tag) {
   1.225 +    /* Note: for non-collection SFNT data we ignore index.  This is because
   1.226 +     * Apple dfont container is a container of SFNT's.  So each SFNT is a
   1.227 +     * non-TTC, but the index is more than zero. */
   1.228 +    case CFFTag:	/* All the non-collection tags */
   1.229 +    case TrueTag:
   1.230 +    case Typ1Tag:
   1.231 +    case TrueTypeTag:	return u.fontFace;
   1.232 +    case TTCTag:	return u.ttcHeader.get_face (i);
   1.233 +    default:		return Null(OpenTypeFontFace);
   1.234 +    }
   1.235 +  }
   1.236 +
   1.237 +  inline bool sanitize (hb_sanitize_context_t *c) {
   1.238 +    TRACE_SANITIZE (this);
   1.239 +    if (unlikely (!u.tag.sanitize (c))) return TRACE_RETURN (false);
   1.240 +    switch (u.tag) {
   1.241 +    case CFFTag:	/* All the non-collection tags */
   1.242 +    case TrueTag:
   1.243 +    case Typ1Tag:
   1.244 +    case TrueTypeTag:	return TRACE_RETURN (u.fontFace.sanitize (c));
   1.245 +    case TTCTag:	return TRACE_RETURN (u.ttcHeader.sanitize (c));
   1.246 +    default:		return TRACE_RETURN (true);
   1.247 +    }
   1.248 +  }
   1.249 +
   1.250 +  protected:
   1.251 +  union {
   1.252 +  Tag			tag;		/* 4-byte identifier. */
   1.253 +  OpenTypeFontFace	fontFace;
   1.254 +  TTCHeader		ttcHeader;
   1.255 +  } u;
   1.256 +  public:
   1.257 +  DEFINE_SIZE_UNION (4, tag);
   1.258 +};
   1.259 +
   1.260 +
   1.261 +} /* namespace OT */
   1.262 +
   1.263 +
   1.264 +#endif /* HB_OPEN_FILE_PRIVATE_HH */

mercurial