2009-08-02 23:57:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007,2008,2009 Red Hat, Inc.
|
|
|
|
*
|
2010-04-22 04:11:43 +00:00
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
2009-08-02 23:57:00 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Red Hat Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
2009-08-03 00:03:12 +00:00
|
|
|
#ifndef HB_OPEN_FILE_PRIVATE_HH
|
|
|
|
#define HB_OPEN_FILE_PRIVATE_HH
|
2009-08-02 23:57:00 +00:00
|
|
|
|
2009-08-05 02:06:57 +00:00
|
|
|
#include "hb-open-type-private.hh"
|
2009-08-02 23:57:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* The OpenType Font File
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Organization of an OpenType Font
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct OpenTypeFontFile;
|
|
|
|
struct OffsetTable;
|
|
|
|
struct TTCHeader;
|
|
|
|
|
2010-05-10 20:38:32 +00:00
|
|
|
|
2009-08-02 23:57:00 +00:00
|
|
|
typedef struct TableDirectory
|
|
|
|
{
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
return context->check_struct (this);
|
2009-08-04 19:07:24 +00:00
|
|
|
}
|
|
|
|
|
2009-08-02 23:57:00 +00:00
|
|
|
Tag tag; /* 4-byte identifier. */
|
|
|
|
CheckSum checkSum; /* CheckSum for this table. */
|
|
|
|
ULONG offset; /* Offset from beginning of TrueType font
|
|
|
|
* file. */
|
|
|
|
ULONG length; /* Length of this table. */
|
2010-05-10 20:38:32 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (16);
|
2009-08-02 23:57:00 +00:00
|
|
|
} OpenTypeTable;
|
|
|
|
|
|
|
|
typedef struct OffsetTable
|
|
|
|
{
|
|
|
|
friend struct OpenTypeFontFile;
|
|
|
|
|
2009-08-07 23:46:30 +00:00
|
|
|
inline unsigned int get_table_count (void) const
|
|
|
|
{ return numTables; }
|
|
|
|
inline const TableDirectory& get_table (unsigned int i) const
|
|
|
|
{
|
2010-05-04 02:51:19 +00:00
|
|
|
if (unlikely (i >= numTables)) return Null(TableDirectory);
|
2009-08-07 23:46:30 +00:00
|
|
|
return tableDir[i];
|
|
|
|
}
|
|
|
|
inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
|
|
|
|
{
|
2010-04-21 04:14:12 +00:00
|
|
|
Tag t;
|
|
|
|
t.set (tag);
|
2010-04-23 19:19:50 +00:00
|
|
|
/* TODO: bsearch (need to sort in sanitize) */
|
2009-08-07 23:46:30 +00:00
|
|
|
unsigned int count = numTables;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (t == tableDir[i].tag)
|
|
|
|
{
|
|
|
|
if (table_index) *table_index = i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-05-11 02:22:22 +00:00
|
|
|
if (table_index) *table_index = Index::NOT_FOUND_INDEX;
|
2009-08-07 23:46:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
inline const TableDirectory& get_table_by_tag (hb_tag_t tag) const
|
|
|
|
{
|
|
|
|
unsigned int table_index;
|
|
|
|
find_table_index (tag, &table_index);
|
|
|
|
return get_table (table_index);
|
|
|
|
}
|
2009-08-04 19:07:24 +00:00
|
|
|
|
|
|
|
public:
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 18:48:27 +00:00
|
|
|
return context->check_struct (this)
|
2010-05-06 23:33:31 +00:00
|
|
|
&& context->check_array (tableDir, TableDirectory::static_size, numTables);
|
2009-08-04 19:07:24 +00:00
|
|
|
}
|
|
|
|
|
2009-08-02 23:57:00 +00:00
|
|
|
private:
|
|
|
|
Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
|
|
|
|
USHORT numTables; /* Number of tables. */
|
|
|
|
USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */
|
|
|
|
USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */
|
|
|
|
USHORT rangeShift; /* NumTables x 16-searchRange. */
|
2009-11-03 15:47:29 +00:00
|
|
|
TableDirectory tableDir[VAR]; /* TableDirectory entries. numTables items */
|
2010-05-10 20:38:32 +00:00
|
|
|
public:
|
2010-05-10 23:01:17 +00:00
|
|
|
DEFINE_SIZE_ARRAY (12, tableDir);
|
2009-08-02 23:57:00 +00:00
|
|
|
} OpenTypeFontFace;
|
2010-05-10 20:38:32 +00:00
|
|
|
|
2009-08-02 23:57:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TrueType Collections
|
|
|
|
*/
|
|
|
|
|
2010-04-23 16:33:02 +00:00
|
|
|
struct TTCHeaderVersion1
|
2009-08-02 23:57:00 +00:00
|
|
|
{
|
2010-04-23 16:33:02 +00:00
|
|
|
friend struct TTCHeader;
|
2009-08-02 23:57:00 +00:00
|
|
|
|
2009-08-10 23:00:36 +00:00
|
|
|
inline unsigned int get_face_count (void) const { return table.len; }
|
2010-04-22 18:11:33 +00:00
|
|
|
inline const OpenTypeFontFace& get_face (unsigned int i) const { return this+table[i]; }
|
2009-08-04 19:07:24 +00:00
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-06 16:55:14 +00:00
|
|
|
return table.sanitize (context, this);
|
2009-08-04 19:07:24 +00:00
|
|
|
}
|
|
|
|
|
2009-08-02 23:57:00 +00:00
|
|
|
private:
|
|
|
|
Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */
|
2010-04-23 16:33:02 +00:00
|
|
|
FixedVersion version; /* Version of the TTC Header (1.0),
|
|
|
|
* 0x00010000 */
|
2009-08-02 23:57:00 +00:00
|
|
|
LongOffsetLongArrayOf<OffsetTable>
|
|
|
|
table; /* Array of offsets to the OffsetTable for each font
|
|
|
|
* from the beginning of the file */
|
2010-05-10 20:57:29 +00:00
|
|
|
public:
|
2010-05-10 23:01:17 +00:00
|
|
|
DEFINE_SIZE_ARRAY (12, table);
|
2009-08-02 23:57:00 +00:00
|
|
|
};
|
2010-04-23 16:33:02 +00:00
|
|
|
|
|
|
|
struct TTCHeader
|
|
|
|
{
|
|
|
|
friend struct OpenTypeFontFile;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
inline unsigned int get_face_count (void) const
|
|
|
|
{
|
|
|
|
switch (u.header.version) {
|
|
|
|
case 2: /* version 2 is compatible with version 1 */
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.version1.get_face_count ();
|
2010-04-23 16:33:02 +00:00
|
|
|
default:return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inline const OpenTypeFontFace& get_face (unsigned int i) const
|
|
|
|
{
|
|
|
|
switch (u.header.version) {
|
|
|
|
case 2: /* version 2 is compatible with version 1 */
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.version1.get_face (i);
|
2010-04-23 17:32:03 +00:00
|
|
|
default:return Null(OpenTypeFontFace);
|
2010-04-23 16:33:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2010-04-23 16:33:02 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-11 03:27:54 +00:00
|
|
|
if (unlikely (!u.header.version.sanitize (context))) return false;
|
2010-04-23 16:33:02 +00:00
|
|
|
switch (u.header.version) {
|
|
|
|
case 2: /* version 2 is compatible with version 1 */
|
2010-05-10 23:45:41 +00:00
|
|
|
case 1: return u.version1.sanitize (context);
|
2010-04-23 16:33:02 +00:00
|
|
|
default:return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */
|
|
|
|
FixedVersion version; /* Version of the TTC Header (1.0 or 2.0),
|
|
|
|
* 0x00010000 or 0x00020000 */
|
|
|
|
} header;
|
2010-05-10 23:45:41 +00:00
|
|
|
TTCHeaderVersion1 version1;
|
2010-04-23 16:33:02 +00:00
|
|
|
} u;
|
|
|
|
};
|
2009-08-02 23:57:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OpenType Font File
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct OpenTypeFontFile
|
|
|
|
{
|
2010-05-04 03:11:16 +00:00
|
|
|
static const hb_tag_t CFFTag = HB_TAG ('O','T','T','O'); /* OpenType with Postscript outlines */
|
|
|
|
static const hb_tag_t TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 ); /* OpenType with TrueType outlines */
|
|
|
|
static const hb_tag_t TTCTag = HB_TAG ('t','t','c','f'); /* TrueType Collection */
|
2010-05-04 18:10:18 +00:00
|
|
|
static const hb_tag_t TrueTag = HB_TAG ('t','r','u','e'); /* Obsolete Apple TrueType */
|
|
|
|
static const hb_tag_t Typ1Tag = HB_TAG ('t','y','p','1'); /* Obsolete Apple Type1 font in SFNT container */
|
2009-08-02 23:57:00 +00:00
|
|
|
|
2010-04-23 17:32:03 +00:00
|
|
|
inline hb_tag_t get_tag (void) const { return u.tag; }
|
|
|
|
|
2009-08-10 23:00:36 +00:00
|
|
|
inline unsigned int get_face_count (void) const
|
2009-08-02 23:57:00 +00:00
|
|
|
{
|
2010-04-23 17:32:03 +00:00
|
|
|
switch (u.tag) {
|
|
|
|
case CFFTag: /* All the non-collection tags */
|
2010-05-03 19:03:53 +00:00
|
|
|
case TrueTag:
|
|
|
|
case Typ1Tag:
|
2010-04-23 17:32:03 +00:00
|
|
|
case TrueTypeTag: return 1;
|
2010-05-10 23:45:41 +00:00
|
|
|
case TTCTag: return u.ttcHeader.get_face_count ();
|
2010-04-23 17:32:03 +00:00
|
|
|
default: return 0;
|
2009-08-02 23:57:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-10 23:00:36 +00:00
|
|
|
inline const OpenTypeFontFace& get_face (unsigned int i) const
|
2009-08-02 23:57:00 +00:00
|
|
|
{
|
2010-04-23 17:32:03 +00:00
|
|
|
switch (u.tag) {
|
2009-08-02 23:57:00 +00:00
|
|
|
/* Note: for non-collection SFNT data we ignore index. This is because
|
|
|
|
* Apple dfont container is a container of SFNT's. So each SFNT is a
|
|
|
|
* non-TTC, but the index is more than zero. */
|
2010-04-23 17:32:03 +00:00
|
|
|
case CFFTag: /* All the non-collection tags */
|
2010-05-03 19:03:53 +00:00
|
|
|
case TrueTag:
|
|
|
|
case Typ1Tag:
|
2010-05-10 23:45:41 +00:00
|
|
|
case TrueTypeTag: return u.fontFace;
|
|
|
|
case TTCTag: return u.ttcHeader.get_face (i);
|
2010-04-23 17:32:03 +00:00
|
|
|
default: return Null(OpenTypeFontFace);
|
2009-08-02 23:57:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:23:19 +00:00
|
|
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
2009-08-28 21:17:11 +00:00
|
|
|
TRACE_SANITIZE ();
|
2010-05-11 03:27:54 +00:00
|
|
|
if (unlikely (!u.tag.sanitize (context))) return false;
|
2010-04-23 17:32:03 +00:00
|
|
|
switch (u.tag) {
|
|
|
|
case CFFTag: /* All the non-collection tags */
|
2010-05-03 19:03:53 +00:00
|
|
|
case TrueTag:
|
|
|
|
case Typ1Tag:
|
2010-05-10 23:45:41 +00:00
|
|
|
case TrueTypeTag: return u.fontFace.sanitize (context);
|
|
|
|
case TTCTag: return u.ttcHeader.sanitize (context);
|
2010-04-23 17:32:03 +00:00
|
|
|
default: return true;
|
2009-08-04 19:07:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-23 17:32:03 +00:00
|
|
|
private:
|
|
|
|
union {
|
|
|
|
Tag tag; /* 4-byte identifier. */
|
2010-05-10 23:45:41 +00:00
|
|
|
OpenTypeFontFace fontFace;
|
|
|
|
TTCHeader ttcHeader;
|
2010-04-23 17:32:03 +00:00
|
|
|
} u;
|
2010-05-10 23:45:41 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_UNION (4, tag);
|
2009-08-02 23:57:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-03 00:03:12 +00:00
|
|
|
#endif /* HB_OPEN_FILE_PRIVATE_HH */
|