2009-08-03 01:57:00 +02:00
|
|
|
/*
|
2011-04-21 23:14:28 +02:00
|
|
|
* Copyright © 2007,2008,2009 Red Hat, Inc.
|
2012-05-11 01:25:34 +02:00
|
|
|
* Copyright © 2012 Google, Inc.
|
2009-08-03 01:57:00 +02:00
|
|
|
*
|
2010-04-22 06:11:43 +02:00
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
2009-08-03 01:57:00 +02: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
|
2012-05-11 01:25:34 +02:00
|
|
|
* Google Author(s): Behdad Esfahbod
|
2009-08-03 01:57:00 +02:00
|
|
|
*/
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#ifndef HB_OPEN_FILE_HH
|
|
|
|
#define HB_OPEN_FILE_HH
|
2009-08-03 01:57:00 +02:00
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-open-type.hh"
|
2018-02-24 01:42:06 +01:00
|
|
|
#include "hb-ot-head-table.hh"
|
2009-08-03 01:57:00 +02:00
|
|
|
|
2010-07-23 21:11:18 +02:00
|
|
|
|
2012-08-28 23:57:49 +02:00
|
|
|
namespace OT {
|
|
|
|
|
2009-08-03 01:57:00 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* The OpenType Font File
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Organization of an OpenType Font
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct OpenTypeFontFile;
|
|
|
|
struct OffsetTable;
|
|
|
|
struct TTCHeader;
|
|
|
|
|
2010-05-10 22:38:32 +02:00
|
|
|
|
2010-12-15 05:51:29 +01:00
|
|
|
typedef struct TableRecord
|
2009-08-03 01:57:00 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
int cmp (Tag t) const { return -t.cmp (tag); }
|
2017-11-01 03:11:00 +01:00
|
|
|
|
2018-02-08 04:13:10 +01:00
|
|
|
static int cmp (const void *pa, const void *pb)
|
|
|
|
{
|
|
|
|
const TableRecord *a = (const TableRecord *) pa;
|
|
|
|
const TableRecord *b = (const TableRecord *) pb;
|
|
|
|
return b->cmp (a->tag);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
2012-11-23 21:32:14 +01:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (c->check_struct (this));
|
2009-08-04 21:07:24 +02:00
|
|
|
}
|
|
|
|
|
2009-08-03 01:57:00 +02:00
|
|
|
Tag tag; /* 4-byte identifier. */
|
|
|
|
CheckSum checkSum; /* CheckSum for this table. */
|
2018-02-08 04:13:10 +01:00
|
|
|
Offset32 offset; /* Offset from beginning of TrueType font
|
2009-08-03 01:57:00 +02:00
|
|
|
* file. */
|
2018-02-08 00:12:55 +01:00
|
|
|
HBUINT32 length; /* Length of this table. */
|
2010-05-10 22:38:32 +02:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (16);
|
2009-08-03 01:57:00 +02:00
|
|
|
} OpenTypeTable;
|
|
|
|
|
|
|
|
typedef struct OffsetTable
|
|
|
|
{
|
|
|
|
friend struct OpenTypeFontFile;
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_table_count () const { return tables.len; }
|
2018-12-16 20:08:10 +01:00
|
|
|
const TableRecord& get_table (unsigned int i) const
|
2018-12-17 19:01:01 +01:00
|
|
|
{ return tables[i]; }
|
2018-12-16 20:08:10 +01:00
|
|
|
unsigned int get_table_tags (unsigned int start_offset,
|
2017-10-11 17:22:44 +02:00
|
|
|
unsigned int *table_count, /* IN/OUT */
|
|
|
|
hb_tag_t *table_tags /* OUT */) const
|
|
|
|
{
|
|
|
|
if (table_count)
|
|
|
|
{
|
2017-11-01 03:05:37 +01:00
|
|
|
if (start_offset >= tables.len)
|
2017-10-11 17:22:44 +02:00
|
|
|
*table_count = 0;
|
|
|
|
else
|
2017-11-01 10:10:18 +01:00
|
|
|
*table_count = MIN<unsigned int> (*table_count, tables.len - start_offset);
|
2017-10-11 17:22:44 +02:00
|
|
|
|
2018-05-09 01:56:11 +02:00
|
|
|
const TableRecord *sub_tables = tables.arrayZ + start_offset;
|
2017-10-11 17:22:44 +02:00
|
|
|
unsigned int count = *table_count;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
table_tags[i] = sub_tables[i].tag;
|
|
|
|
}
|
2017-11-01 03:05:37 +01:00
|
|
|
return tables.len;
|
2017-10-11 17:22:44 +02:00
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
|
2009-08-08 01:46:30 +02:00
|
|
|
{
|
2010-04-21 06:14:12 +02:00
|
|
|
Tag t;
|
|
|
|
t.set (tag);
|
2018-11-24 16:06:13 +01:00
|
|
|
return tables.bfind (t, table_index, HB_BFIND_NOT_FOUND_STORE, Index::NOT_FOUND_INDEX);
|
2009-08-08 01:46:30 +02:00
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
const TableRecord& get_table_by_tag (hb_tag_t tag) const
|
2009-08-08 01:46:30 +02:00
|
|
|
{
|
|
|
|
unsigned int table_index;
|
|
|
|
find_table_index (tag, &table_index);
|
|
|
|
return get_table (table_index);
|
|
|
|
}
|
2009-08-04 21:07:24 +02:00
|
|
|
|
|
|
|
public:
|
2018-02-08 04:13:10 +01:00
|
|
|
|
2018-12-17 04:29:40 +01:00
|
|
|
template <typename item_t>
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
hb_tag_t sfnt_tag,
|
2018-12-18 22:49:08 +01:00
|
|
|
hb_array_t<item_t> items)
|
2018-02-08 04:13:10 +01:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
2018-02-24 00:51:26 +01:00
|
|
|
/* Alloc 12 for the OTHeader. */
|
2018-02-08 04:13:10 +01:00
|
|
|
if (unlikely (!c->extend_min (*this))) return_trace (false);
|
2018-02-24 01:42:06 +01:00
|
|
|
/* Write sfntVersion (bytes 0..3). */
|
2018-02-08 04:13:10 +01:00
|
|
|
sfnt_version.set (sfnt_tag);
|
2018-02-24 00:51:26 +01:00
|
|
|
/* Take space for numTables, searchRange, entrySelector, RangeShift
|
2018-02-24 01:42:06 +01:00
|
|
|
* and the TableRecords themselves. */
|
2018-12-22 00:46:51 +01:00
|
|
|
if (unlikely (!tables.serialize (c, items.length))) return_trace (false);
|
2018-02-08 04:49:01 +01:00
|
|
|
|
2018-02-24 01:42:06 +01:00
|
|
|
const char *dir_end = (const char *) c->head;
|
|
|
|
HBUINT32 *checksum_adjustment = nullptr;
|
|
|
|
|
2018-02-24 00:51:26 +01:00
|
|
|
/* Write OffsetTables, alloc for and write actual table blobs. */
|
2018-12-18 22:49:08 +01:00
|
|
|
for (unsigned int i = 0; i < tables.len; i++)
|
2018-02-08 04:13:10 +01:00
|
|
|
{
|
2018-05-09 01:56:11 +02:00
|
|
|
TableRecord &rec = tables.arrayZ[i];
|
2018-12-17 04:29:40 +01:00
|
|
|
hb_blob_t *blob = items[i].blob;
|
|
|
|
rec.tag.set (items[i].tag);
|
2018-02-08 04:13:10 +01:00
|
|
|
rec.length.set (hb_blob_get_length (blob));
|
|
|
|
rec.offset.serialize (c, this);
|
2018-02-24 01:42:06 +01:00
|
|
|
|
|
|
|
/* Allocate room for the table and copy it. */
|
|
|
|
char *start = (char *) c->allocate_size<void> (rec.length);
|
|
|
|
if (unlikely (!start)) {return false;}
|
|
|
|
|
|
|
|
memcpy (start, hb_blob_get_data (blob, nullptr), rec.length);
|
|
|
|
|
2018-10-19 17:49:21 +02:00
|
|
|
/* 4-byte alignment. */
|
2018-09-01 01:38:04 +02:00
|
|
|
c->align (4);
|
2018-02-24 00:51:26 +01:00
|
|
|
const char *end = (const char *) c->head;
|
2018-02-24 01:42:06 +01:00
|
|
|
|
2018-12-17 04:29:40 +01:00
|
|
|
if (items[i].tag == HB_OT_TAG_head && end - start >= head::static_size)
|
2018-02-24 01:42:06 +01:00
|
|
|
{
|
|
|
|
head *h = (head *) start;
|
|
|
|
checksum_adjustment = &h->checkSumAdjustment;
|
|
|
|
checksum_adjustment->set (0);
|
|
|
|
}
|
|
|
|
|
2018-02-24 00:51:26 +01:00
|
|
|
rec.checkSum.set_for_data (start, end - start);
|
2018-02-08 04:13:10 +01:00
|
|
|
}
|
2018-02-08 04:49:01 +01:00
|
|
|
|
2018-02-08 04:13:10 +01:00
|
|
|
tables.qsort ();
|
2018-02-24 01:42:06 +01:00
|
|
|
|
|
|
|
if (checksum_adjustment)
|
|
|
|
{
|
|
|
|
CheckSum checksum;
|
|
|
|
|
|
|
|
/* The following line is a slower version of the following block. */
|
|
|
|
//checksum.set_for_data (this, (const char *) c->head - (const char *) this);
|
|
|
|
checksum.set_for_data (this, dir_end - (const char *) this);
|
2018-12-22 00:46:51 +01:00
|
|
|
for (unsigned int i = 0; i < items.length; i++)
|
2018-02-24 01:42:06 +01:00
|
|
|
{
|
2018-05-09 01:56:11 +02:00
|
|
|
TableRecord &rec = tables.arrayZ[i];
|
2018-02-24 01:42:06 +01:00
|
|
|
checksum.set (checksum + rec.checkSum);
|
|
|
|
}
|
|
|
|
|
|
|
|
checksum_adjustment->set (0xB1B0AFBAu - checksum);
|
|
|
|
}
|
|
|
|
|
2018-02-08 04:13:10 +01:00
|
|
|
return_trace (true);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
2012-11-23 21:32:14 +01:00
|
|
|
TRACE_SANITIZE (this);
|
2017-11-01 03:05:37 +01:00
|
|
|
return_trace (c->check_struct (this) && tables.sanitize (c));
|
2009-08-04 21:07:24 +02:00
|
|
|
}
|
|
|
|
|
2012-07-24 21:40:37 +02:00
|
|
|
protected:
|
2009-08-03 01:57:00 +02:00
|
|
|
Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
|
2017-11-01 03:05:37 +01:00
|
|
|
BinSearchArrayOf<TableRecord>
|
|
|
|
tables;
|
2010-05-10 22:38:32 +02:00
|
|
|
public:
|
2010-12-15 05:51:29 +01:00
|
|
|
DEFINE_SIZE_ARRAY (12, tables);
|
2009-08-03 01:57:00 +02:00
|
|
|
} OpenTypeFontFace;
|
2010-05-10 22:38:32 +02:00
|
|
|
|
2009-08-03 01:57:00 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TrueType Collections
|
|
|
|
*/
|
|
|
|
|
2010-04-23 18:33:02 +02:00
|
|
|
struct TTCHeaderVersion1
|
2009-08-03 01:57:00 +02:00
|
|
|
{
|
2010-04-23 18:33:02 +02:00
|
|
|
friend struct TTCHeader;
|
2009-08-03 01:57:00 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_face_count () const { return table.len; }
|
2018-12-16 20:08:10 +01:00
|
|
|
const OpenTypeFontFace& get_face (unsigned int i) const { return this+table[i]; }
|
2009-08-04 21:07:24 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
2012-11-23 21:32:14 +01:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
return_trace (table.sanitize (c, this));
|
2009-08-04 21:07:24 +02:00
|
|
|
}
|
|
|
|
|
2012-07-24 21:40:37 +02:00
|
|
|
protected:
|
2009-08-03 01:57:00 +02:00
|
|
|
Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */
|
2016-02-22 03:44:45 +01:00
|
|
|
FixedVersion<>version; /* Version of the TTC Header (1.0),
|
2014-07-11 20:54:42 +02:00
|
|
|
* 0x00010000u */
|
2018-04-11 16:06:09 +02:00
|
|
|
LArrayOf<LOffsetTo<OffsetTable> >
|
2009-08-03 01:57:00 +02:00
|
|
|
table; /* Array of offsets to the OffsetTable for each font
|
|
|
|
* from the beginning of the file */
|
2010-05-10 22:57:29 +02:00
|
|
|
public:
|
2010-05-11 01:01:17 +02:00
|
|
|
DEFINE_SIZE_ARRAY (12, table);
|
2009-08-03 01:57:00 +02:00
|
|
|
};
|
2010-04-23 18:33:02 +02:00
|
|
|
|
|
|
|
struct TTCHeader
|
|
|
|
{
|
|
|
|
friend struct OpenTypeFontFile;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_face_count () const
|
2010-04-23 18:33:02 +02:00
|
|
|
{
|
2011-05-31 18:33:11 +02:00
|
|
|
switch (u.header.version.major) {
|
2010-04-23 18:33:02 +02:00
|
|
|
case 2: /* version 2 is compatible with version 1 */
|
2010-05-11 01:45:41 +02:00
|
|
|
case 1: return u.version1.get_face_count ();
|
2010-04-23 18:33:02 +02:00
|
|
|
default:return 0;
|
|
|
|
}
|
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
const OpenTypeFontFace& get_face (unsigned int i) const
|
2010-04-23 18:33:02 +02:00
|
|
|
{
|
2011-05-31 18:33:11 +02:00
|
|
|
switch (u.header.version.major) {
|
2010-04-23 18:33:02 +02:00
|
|
|
case 2: /* version 2 is compatible with version 1 */
|
2010-05-11 01:45:41 +02:00
|
|
|
case 1: return u.version1.get_face (i);
|
2010-04-23 19:32:03 +02:00
|
|
|
default:return Null(OpenTypeFontFace);
|
2010-04-23 18:33:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
2012-11-23 21:32:14 +01:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
if (unlikely (!u.header.version.sanitize (c))) return_trace (false);
|
2011-05-31 18:33:11 +02:00
|
|
|
switch (u.header.version.major) {
|
2010-04-23 18:33:02 +02:00
|
|
|
case 2: /* version 2 is compatible with version 1 */
|
2015-09-29 15:57:02 +02:00
|
|
|
case 1: return_trace (u.version1.sanitize (c));
|
|
|
|
default:return_trace (true);
|
2010-04-23 18:33:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-24 21:40:37 +02:00
|
|
|
protected:
|
2010-04-23 18:33:02 +02:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */
|
2016-02-22 03:44:45 +01:00
|
|
|
FixedVersion<>version; /* Version of the TTC Header (1.0 or 2.0),
|
2014-07-11 20:54:42 +02:00
|
|
|
* 0x00010000u or 0x00020000u */
|
2010-04-23 18:33:02 +02:00
|
|
|
} header;
|
2010-05-11 01:45:41 +02:00
|
|
|
TTCHeaderVersion1 version1;
|
2010-04-23 18:33:02 +02:00
|
|
|
} u;
|
|
|
|
};
|
2009-08-03 01:57:00 +02:00
|
|
|
|
2018-07-01 12:02:00 +02:00
|
|
|
/*
|
|
|
|
* Mac Resource Fork
|
2018-09-11 18:12:26 +02:00
|
|
|
*
|
|
|
|
* http://mirror.informatimago.com/next/developer.apple.com/documentation/mac/MoreToolbox/MoreToolbox-99.html
|
2018-07-01 12:02:00 +02:00
|
|
|
*/
|
|
|
|
|
2018-09-11 18:12:26 +02:00
|
|
|
struct ResourceRecord
|
2018-07-01 12:02:00 +02:00
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
const OpenTypeFontFace & get_face (const void *data_base) const
|
2018-09-13 19:05:59 +02:00
|
|
|
{ return CastR<OpenTypeFontFace> ((data_base+offset).arrayZ); }
|
2018-09-13 16:49:26 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c,
|
2018-09-13 16:49:26 +02:00
|
|
|
const void *data_base) const
|
2018-07-01 12:02:00 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-09-13 16:49:26 +02:00
|
|
|
return_trace (c->check_struct (this) &&
|
2018-09-13 19:05:59 +02:00
|
|
|
offset.sanitize (c, data_base) &&
|
|
|
|
get_face (data_base).sanitize (c));
|
2018-07-01 12:02:00 +02:00
|
|
|
}
|
|
|
|
|
2018-09-13 16:49:26 +02:00
|
|
|
protected:
|
2018-09-13 18:27:20 +02:00
|
|
|
HBUINT16 id; /* Resource ID. */
|
2018-07-01 12:02:00 +02:00
|
|
|
HBINT16 nameOffset; /* Offset from beginning of resource name list
|
2018-09-11 17:56:03 +02:00
|
|
|
* to resource name, -1 means there is none. */
|
2018-09-11 18:12:26 +02:00
|
|
|
HBUINT8 attrs; /* Resource attributes */
|
2019-01-18 00:17:04 +01:00
|
|
|
NNOffsetTo<LArrayOf<HBUINT8>, HBUINT24>
|
2018-09-13 16:49:26 +02:00
|
|
|
offset; /* Offset from beginning of data block to
|
2018-07-01 12:02:00 +02:00
|
|
|
* data for this resource */
|
|
|
|
HBUINT32 reserved; /* Reserved for handle to resource */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (12);
|
|
|
|
};
|
|
|
|
|
2018-09-13 19:05:59 +02:00
|
|
|
#define HB_TAG_sfnt HB_TAG ('s','f','n','t')
|
|
|
|
|
2018-09-11 18:12:26 +02:00
|
|
|
struct ResourceTypeRecord
|
2018-07-01 12:02:00 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_resource_count () const
|
2018-09-13 19:19:57 +02:00
|
|
|
{ return tag == HB_TAG_sfnt ? resCountM1 + 1 : 0; }
|
2018-07-01 12:02:00 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool is_sfnt () const { return tag == HB_TAG_sfnt; }
|
2018-07-01 12:02:00 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
const ResourceRecord& get_resource_record (unsigned int i,
|
|
|
|
const void *type_base) const
|
2018-12-17 19:01:01 +01:00
|
|
|
{ return (type_base+resourcesZ).as_array (get_resource_count ())[i]; }
|
2018-09-13 16:49:26 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c,
|
|
|
|
const void *type_base,
|
|
|
|
const void *data_base) const
|
2018-09-13 16:49:26 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
resourcesZ.sanitize (c, type_base,
|
|
|
|
get_resource_count (),
|
|
|
|
data_base));
|
2018-07-01 12:02:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-09-11 18:12:26 +02:00
|
|
|
Tag tag; /* Resource type. */
|
|
|
|
HBUINT16 resCountM1; /* Number of resources minus 1. */
|
2019-01-18 00:17:04 +01:00
|
|
|
NNOffsetTo<UnsizedArrayOf<ResourceRecord> >
|
2018-09-13 16:49:26 +02:00
|
|
|
resourcesZ; /* Offset from beginning of resource type list
|
2018-09-11 17:18:21 +02:00
|
|
|
* to reference item list for this type. */
|
2018-07-01 12:02:00 +02:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (8);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ResourceMap
|
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_face_count () const
|
2018-09-13 19:13:01 +02:00
|
|
|
{
|
|
|
|
unsigned int count = get_type_count ();
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
const ResourceTypeRecord& type = get_type_record (i);
|
|
|
|
if (type.is_sfnt ())
|
|
|
|
return type.get_resource_count ();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
const OpenTypeFontFace& get_face (unsigned int idx,
|
|
|
|
const void *data_base) const
|
2018-09-13 19:13:01 +02:00
|
|
|
{
|
|
|
|
unsigned int count = get_type_count ();
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
const ResourceTypeRecord& type = get_type_record (i);
|
2018-09-13 19:19:57 +02:00
|
|
|
/* The check for idx < count is here because ResourceRecord is NOT null-safe.
|
|
|
|
* Because an offset of 0 there does NOT mean null. */
|
2018-09-13 19:13:01 +02:00
|
|
|
if (type.is_sfnt () && idx < type.get_resource_count ())
|
2018-09-13 20:30:04 +02:00
|
|
|
return type.get_resource_record (idx, &(this+typeList)).get_face (data_base);
|
2018-09-13 19:13:01 +02:00
|
|
|
}
|
|
|
|
return Null (OpenTypeFontFace);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c, const void *data_base) const
|
2018-09-13 16:49:26 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
2018-09-13 20:30:04 +02:00
|
|
|
typeList.sanitize (c, this,
|
2018-09-14 10:58:00 +02:00
|
|
|
&(this+typeList),
|
2018-09-13 20:30:04 +02:00
|
|
|
data_base));
|
2018-07-01 12:02:00 +02:00
|
|
|
}
|
|
|
|
|
2018-09-13 19:19:57 +02:00
|
|
|
private:
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_type_count () const { return (this+typeList).lenM1 + 1; }
|
2018-09-13 20:30:04 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
const ResourceTypeRecord& get_type_record (unsigned int i) const
|
2018-09-13 20:30:04 +02:00
|
|
|
{ return (this+typeList)[i]; }
|
2018-09-13 19:19:57 +02:00
|
|
|
|
2018-07-01 12:02:00 +02:00
|
|
|
protected:
|
2018-09-11 18:12:26 +02:00
|
|
|
HBUINT8 reserved0[16]; /* Reserved for copy of resource header */
|
|
|
|
HBUINT32 reserved1; /* Reserved for handle to next resource map */
|
|
|
|
HBUINT16 resreved2; /* Reserved for file reference number */
|
|
|
|
HBUINT16 attrs; /* Resource fork attribute */
|
2019-01-18 00:17:04 +01:00
|
|
|
NNOffsetTo<ArrayOfM1<ResourceTypeRecord> >
|
2018-09-13 20:30:04 +02:00
|
|
|
typeList; /* Offset from beginning of map to
|
2018-07-01 12:02:00 +02:00
|
|
|
* resource type list */
|
2018-09-11 17:26:24 +02:00
|
|
|
Offset16 nameList; /* Offset from beginning of map to
|
2018-07-01 12:02:00 +02:00
|
|
|
* resource name list */
|
|
|
|
public:
|
2018-09-13 20:30:04 +02:00
|
|
|
DEFINE_SIZE_STATIC (28);
|
2018-07-01 12:02:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ResourceForkHeader
|
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_face_count () const
|
2018-09-13 19:13:01 +02:00
|
|
|
{ return (this+map).get_face_count (); }
|
2018-07-01 12:02:00 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
const OpenTypeFontFace& get_face (unsigned int idx,
|
|
|
|
unsigned int *base_offset = nullptr) const
|
2018-07-01 12:02:00 +02:00
|
|
|
{
|
2018-09-13 19:13:01 +02:00
|
|
|
const OpenTypeFontFace &face = (this+map).get_face (idx, &(this+data));
|
|
|
|
if (base_offset)
|
|
|
|
*base_offset = (const char *) &face - (const char *) this;
|
|
|
|
return face;
|
2018-07-01 12:02:00 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-07-01 12:02:00 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2018-09-13 16:49:26 +02:00
|
|
|
return_trace (c->check_struct (this) &&
|
2018-09-13 20:35:21 +02:00
|
|
|
data.sanitize (c, this, dataLen) &&
|
2018-09-13 16:49:26 +02:00
|
|
|
map.sanitize (c, this, &(this+data)));
|
2018-07-01 12:02:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-01-18 00:17:04 +01:00
|
|
|
LNNOffsetTo<UnsizedArrayOf<HBUINT8> >
|
2018-09-13 16:49:26 +02:00
|
|
|
data; /* Offset from beginning of resource fork
|
2018-07-01 12:02:00 +02:00
|
|
|
* to resource data */
|
2019-01-18 00:17:04 +01:00
|
|
|
LNNOffsetTo<ResourceMap >
|
2018-07-01 12:02:00 +02:00
|
|
|
map; /* Offset from beginning of resource fork
|
|
|
|
* to resource map */
|
|
|
|
HBUINT32 dataLen; /* Length of resource data */
|
|
|
|
HBUINT32 mapLen; /* Length of resource map */
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (16);
|
|
|
|
};
|
2009-08-03 01:57:00 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* OpenType Font File
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct OpenTypeFontFile
|
|
|
|
{
|
2018-03-23 15:07:01 +01:00
|
|
|
enum {
|
|
|
|
CFFTag = HB_TAG ('O','T','T','O'), /* OpenType with Postscript outlines */
|
2018-09-11 14:45:23 +02:00
|
|
|
TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 ), /* OpenType with TrueType outlines */
|
2018-03-23 15:07:01 +01:00
|
|
|
TTCTag = HB_TAG ('t','t','c','f'), /* TrueType Collection */
|
2018-07-01 12:02:00 +02:00
|
|
|
DFontTag = HB_TAG ( 0 , 0 , 1 , 0 ), /* DFont Mac Resource Fork */
|
2018-03-23 15:07:01 +01:00
|
|
|
TrueTag = HB_TAG ('t','r','u','e'), /* Obsolete Apple TrueType */
|
|
|
|
Typ1Tag = HB_TAG ('t','y','p','1') /* Obsolete Apple Type1 font in SFNT container */
|
|
|
|
};
|
2009-08-03 01:57:00 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
hb_tag_t get_tag () const { return u.tag; }
|
2010-04-23 19:32:03 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_face_count () const
|
2009-08-03 01:57:00 +02:00
|
|
|
{
|
2010-04-23 19:32:03 +02:00
|
|
|
switch (u.tag) {
|
|
|
|
case CFFTag: /* All the non-collection tags */
|
2010-05-03 21:03:53 +02:00
|
|
|
case TrueTag:
|
|
|
|
case Typ1Tag:
|
2010-04-23 19:32:03 +02:00
|
|
|
case TrueTypeTag: return 1;
|
2010-05-11 01:45:41 +02:00
|
|
|
case TTCTag: return u.ttcHeader.get_face_count ();
|
2018-09-11 16:41:26 +02:00
|
|
|
case DFontTag: return u.rfHeader.get_face_count ();
|
2010-04-23 19:32:03 +02:00
|
|
|
default: return 0;
|
2009-08-03 01:57:00 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-16 20:08:10 +01:00
|
|
|
const OpenTypeFontFace& get_face (unsigned int i, unsigned int *base_offset = nullptr) const
|
2009-08-03 01:57:00 +02:00
|
|
|
{
|
2018-09-11 16:41:26 +02:00
|
|
|
if (base_offset)
|
|
|
|
*base_offset = 0;
|
2010-04-23 19:32:03 +02:00
|
|
|
switch (u.tag) {
|
2009-08-03 01:57:00 +02: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 19:32:03 +02:00
|
|
|
case CFFTag: /* All the non-collection tags */
|
2010-05-03 21:03:53 +02:00
|
|
|
case TrueTag:
|
|
|
|
case Typ1Tag:
|
2010-05-11 01:45:41 +02:00
|
|
|
case TrueTypeTag: return u.fontFace;
|
|
|
|
case TTCTag: return u.ttcHeader.get_face (i);
|
2018-09-11 16:41:26 +02:00
|
|
|
case DFontTag: return u.rfHeader.get_face (i, base_offset);
|
2010-04-23 19:32:03 +02:00
|
|
|
default: return Null(OpenTypeFontFace);
|
2009-08-03 01:57:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 04:29:40 +01:00
|
|
|
template <typename item_t>
|
2018-12-16 20:08:10 +01:00
|
|
|
bool serialize_single (hb_serialize_context_t *c,
|
|
|
|
hb_tag_t sfnt_tag,
|
2018-12-18 22:49:08 +01:00
|
|
|
hb_array_t<item_t> items)
|
2018-02-08 04:13:10 +01:00
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
assert (sfnt_tag != TTCTag);
|
|
|
|
if (unlikely (!c->extend_min (*this))) return_trace (false);
|
2018-12-18 22:49:08 +01:00
|
|
|
return_trace (u.fontFace.serialize (c, sfnt_tag, items));
|
2018-02-08 04:13:10 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2015-02-17 15:27:44 +01:00
|
|
|
{
|
2012-11-23 21:32:14 +01:00
|
|
|
TRACE_SANITIZE (this);
|
2015-09-29 15:57:02 +02:00
|
|
|
if (unlikely (!u.tag.sanitize (c))) return_trace (false);
|
2010-04-23 19:32:03 +02:00
|
|
|
switch (u.tag) {
|
|
|
|
case CFFTag: /* All the non-collection tags */
|
2010-05-03 21:03:53 +02:00
|
|
|
case TrueTag:
|
|
|
|
case Typ1Tag:
|
2015-09-29 15:57:02 +02:00
|
|
|
case TrueTypeTag: return_trace (u.fontFace.sanitize (c));
|
|
|
|
case TTCTag: return_trace (u.ttcHeader.sanitize (c));
|
2018-09-11 16:41:26 +02:00
|
|
|
case DFontTag: return_trace (u.rfHeader.sanitize (c));
|
2015-09-29 15:57:02 +02:00
|
|
|
default: return_trace (true);
|
2009-08-04 21:07:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-24 21:40:37 +02:00
|
|
|
protected:
|
2010-04-23 19:32:03 +02:00
|
|
|
union {
|
|
|
|
Tag tag; /* 4-byte identifier. */
|
2010-05-11 01:45:41 +02:00
|
|
|
OpenTypeFontFace fontFace;
|
|
|
|
TTCHeader ttcHeader;
|
2018-07-01 12:02:00 +02:00
|
|
|
ResourceForkHeader rfHeader;
|
2010-04-23 19:32:03 +02:00
|
|
|
} u;
|
2010-05-11 01:45:41 +02:00
|
|
|
public:
|
|
|
|
DEFINE_SIZE_UNION (4, tag);
|
2009-08-03 01:57:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-11-17 03:49:54 +01:00
|
|
|
} /* namespace OT */
|
2012-08-28 23:57:49 +02:00
|
|
|
|
2010-07-23 21:11:18 +02:00
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#endif /* HB_OPEN_FILE_HH */
|