summaryrefslogtreecommitdiff
path: root/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-open-file.hh
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/harfbuzz/harfbuzz-src/src/hb-open-file.hh')
-rw-r--r--Build/source/libs/harfbuzz/harfbuzz-src/src/hb-open-file.hh221
1 files changed, 97 insertions, 124 deletions
diff --git a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-open-file.hh b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-open-file.hh
index d3b748602ba..8772c79fa10 100644
--- a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-open-file.hh
+++ b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-open-file.hh
@@ -287,188 +287,159 @@ struct TTCHeader
/*
* Mac Resource Fork
+ *
+ * http://mirror.informatimago.com/next/developer.apple.com/documentation/mac/MoreToolbox/MoreToolbox-99.html
*/
-struct ResourceRefItem
+struct ResourceRecord
{
- inline bool sanitize (hb_sanitize_context_t *c) const
+ inline const OpenTypeFontFace & get_face (const void *data_base) const
+ { return CastR<OpenTypeFontFace> ((data_base+offset).arrayZ); }
+
+ inline bool sanitize (hb_sanitize_context_t *c,
+ const void *data_base) const
{
TRACE_SANITIZE (this);
- // actual data sanitization is done on ResourceForkHeader sanitizer
- return_trace (likely (c->check_struct (this)));
+ return_trace (c->check_struct (this) &&
+ offset.sanitize (c, data_base) &&
+ get_face (data_base).sanitize (c));
}
- HBINT16 id; /* Resource ID, is really should be signed? */
+ protected:
+ HBUINT16 id; /* Resource ID. */
HBINT16 nameOffset; /* Offset from beginning of resource name list
- * to resource name, minus means there is no */
- HBUINT8 attr; /* Resource attributes */
- HBUINT24 dataOffset; /* Offset from beginning of resource data to
+ * to resource name, -1 means there is none. */
+ HBUINT8 attrs; /* Resource attributes */
+ OffsetTo<LArrayOf<HBUINT8>, HBUINT24, false>
+ offset; /* Offset from beginning of data block to
* data for this resource */
HBUINT32 reserved; /* Reserved for handle to resource */
public:
DEFINE_SIZE_STATIC (12);
};
-struct ResourceTypeItem
+#define HB_TAG_sfnt HB_TAG ('s','f','n','t')
+
+struct ResourceTypeRecord
{
- inline bool sanitize (hb_sanitize_context_t *c) const
- {
- TRACE_SANITIZE (this);
- // RefList sanitization is done on ResourceMap sanitizer
- return_trace (likely (c->check_struct (this)));
- }
+ inline unsigned int get_resource_count (void) const
+ { return tag == HB_TAG_sfnt ? resCountM1 + 1 : 0; }
- inline unsigned int get_resource_count () const
- {
- return numRes + 1;
- }
+ inline bool is_sfnt (void) const { return tag == HB_TAG_sfnt; }
- inline bool is_sfnt () const
+ inline const ResourceRecord& get_resource_record (unsigned int i,
+ const void *type_base) const
{
- return type == HB_TAG ('s','f','n','t');
+ return hb_array_t<ResourceRecord> ((type_base+resourcesZ).arrayZ,
+ get_resource_count ()) [i];
}
- inline const ResourceRefItem& get_ref_item (const void *base,
- unsigned int i) const
+ inline bool sanitize (hb_sanitize_context_t *c,
+ const void *type_base,
+ const void *data_base) const
{
- return (base+refList)[i];
+ TRACE_SANITIZE (this);
+ return_trace (c->check_struct (this) &&
+ resourcesZ.sanitize (c, type_base,
+ get_resource_count (),
+ data_base));
}
protected:
- Tag type; /* Resource type */
- HBUINT16 numRes; /* Number of resource this type in map minus 1 */
- OffsetTo<UnsizedArrayOf<ResourceRefItem> >
- refList; /* Offset from beginning of resource type list
- * to reference list for this type */
+ Tag tag; /* Resource type. */
+ HBUINT16 resCountM1; /* Number of resources minus 1. */
+ OffsetTo<UnsizedArrayOf<ResourceRecord>, HBUINT16, false>
+ resourcesZ; /* Offset from beginning of resource type list
+ * to reference item list for this type. */
public:
DEFINE_SIZE_STATIC (8);
};
struct ResourceMap
{
- inline bool sanitize (hb_sanitize_context_t *c) const
+ inline unsigned int get_face_count (void) const
{
- TRACE_SANITIZE (this);
- if (unlikely (!c->check_struct (this)))
- return_trace (false);
- for (unsigned int i = 0; i < get_types_count (); ++i)
+ unsigned int count = get_type_count ();
+ for (unsigned int i = 0; i < count; i++)
{
- const ResourceTypeItem& type = get_type (i);
- if (unlikely (!type.sanitize (c)))
- return_trace (false);
- for (unsigned int j = 0; j < type.get_resource_count (); ++j)
- if (unlikely (!get_ref_item (type, j).sanitize (c)))
- return_trace (false);
+ const ResourceTypeRecord& type = get_type_record (i);
+ if (type.is_sfnt ())
+ return type.get_resource_count ();
}
- return_trace (true);
- }
-
- inline const ResourceTypeItem& get_type (unsigned int i) const
- {
- // Why offset from the second byte of the object? I'm not sure
- return ((&reserved[2])+typeList)[i];
+ return 0;
}
- inline unsigned int get_types_count () const
+ inline const OpenTypeFontFace& get_face (unsigned int idx,
+ const void *data_base) const
{
- return nTypes + 1;
+ unsigned int count = get_type_count ();
+ for (unsigned int i = 0; i < count; i++)
+ {
+ const ResourceTypeRecord& type = get_type_record (i);
+ /* The check for idx < count is here because ResourceRecord is NOT null-safe.
+ * Because an offset of 0 there does NOT mean null. */
+ if (type.is_sfnt () && idx < type.get_resource_count ())
+ return type.get_resource_record (idx, &(this+typeList)).get_face (data_base);
+ }
+ return Null (OpenTypeFontFace);
}
- inline const ResourceRefItem &get_ref_item (const ResourceTypeItem &type,
- unsigned int i) const
+ inline bool sanitize (hb_sanitize_context_t *c, const void *data_base) const
{
- return type.get_ref_item (&(this+typeList), i);
+ TRACE_SANITIZE (this);
+ return_trace (c->check_struct (this) &&
+ typeList.sanitize (c, this,
+ &(this+typeList),
+ data_base));
}
- inline const PString& get_name (const ResourceRefItem &item,
- unsigned int i) const
- {
- if (item.nameOffset == -1)
- return Null (PString);
+ private:
+ inline unsigned int get_type_count (void) const { return (this+typeList).lenM1 + 1; }
- return StructAtOffset<PString> (this, nameList + item.nameOffset);
- }
+ inline const ResourceTypeRecord& get_type_record (unsigned int i) const
+ { return (this+typeList)[i]; }
protected:
- HBUINT8 reserved[16]; /* Reserved for copy of resource header */
- LOffsetTo<ResourceMap>
- reserved1; /* Reserved for handle to next resource map */
- HBUINT16 reserved2; /* Reserved for file reference number */
- HBUINT16 attr; /* Resource fork attribute */
- OffsetTo<UnsizedArrayOf<ResourceTypeItem> >
+ 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 */
+ OffsetTo<ArrayOfM1<ResourceTypeRecord>, HBUINT16, false>
typeList; /* Offset from beginning of map to
* resource type list */
- HBUINT16 nameList; /* Offset from beginning of map to
+ Offset16 nameList; /* Offset from beginning of map to
* resource name list */
- HBUINT16 nTypes; /* Number of types in the map minus 1 */
public:
- DEFINE_SIZE_STATIC (30);
+ DEFINE_SIZE_STATIC (28);
};
struct ResourceForkHeader
{
- inline unsigned int get_face_count () const
- {
- const ResourceMap &resource_map = this+map;
- for (unsigned int i = 0; i < resource_map.get_types_count (); ++i)
- {
- const ResourceTypeItem& type = resource_map.get_type (i);
- if (type.is_sfnt ())
- return type.get_resource_count ();
- }
- return 0;
- }
+ inline unsigned int get_face_count (void) const
+ { return (this+map).get_face_count (); }
- inline const LArrayOf<HBUINT8>& get_data (const ResourceTypeItem& type,
- unsigned int idx) const
+ inline const OpenTypeFontFace& get_face (unsigned int idx,
+ unsigned int *base_offset = nullptr) const
{
- const ResourceMap &resource_map = this+map;
- unsigned int offset = dataOffset;
- offset += resource_map.get_ref_item (type, idx).dataOffset;
- return StructAtOffset<LArrayOf<HBUINT8> > (this, offset);
- }
-
- inline const OpenTypeFontFace& get_face (unsigned int idx) const
- {
- const ResourceMap &resource_map = this+map;
- for (unsigned int i = 0; i < resource_map.get_types_count (); ++i)
- {
- const ResourceTypeItem& type = resource_map.get_type (i);
- if (type.is_sfnt () && idx < type.get_resource_count ())
- return (OpenTypeFontFace&) get_data (type, idx).arrayZ;
- }
- return Null (OpenTypeFontFace);
+ const OpenTypeFontFace &face = (this+map).get_face (idx, &(this+data));
+ if (base_offset)
+ *base_offset = (const char *) &face - (const char *) this;
+ return face;
}
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
- if (unlikely (!c->check_struct (this)))
- return_trace (false);
-
- const ResourceMap &resource_map = this+map;
- if (unlikely (!resource_map.sanitize (c)))
- return_trace (false);
-
- for (unsigned int i = 0; i < resource_map.get_types_count (); ++i)
- {
- const ResourceTypeItem& type = resource_map.get_type (i);
- for (unsigned int j = 0; j < type.get_resource_count (); ++j)
- {
- const LArrayOf<HBUINT8>& data = get_data (type, j);
- if (unlikely (!(data.sanitize (c) &&
- ((OpenTypeFontFace&) data.arrayZ).sanitize (c))))
- return_trace (false);
- }
- }
-
- return_trace (true);
+ return_trace (c->check_struct (this) &&
+ data.sanitize (c, this, dataLen) &&
+ map.sanitize (c, this, &(this+data)));
}
protected:
- HBUINT32 dataOffset; /* Offset from beginning of resource fork
+ LOffsetTo<UnsizedArrayOf<HBUINT8>, false>
+ data; /* Offset from beginning of resource fork
* to resource data */
- LOffsetTo<ResourceMap>
+ LOffsetTo<ResourceMap, false>
map; /* Offset from beginning of resource fork
* to resource map */
HBUINT32 dataLen; /* Length of resource data */
@@ -485,7 +456,7 @@ struct OpenTypeFontFile
{
enum {
CFFTag = HB_TAG ('O','T','T','O'), /* OpenType with Postscript outlines */
- TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 ), /* OpenType with TrueType outlines */
+ TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 ), /* OpenType with TrueType outlines */
TTCTag = HB_TAG ('t','t','c','f'), /* TrueType Collection */
DFontTag = HB_TAG ( 0 , 0 , 1 , 0 ), /* DFont Mac Resource Fork */
TrueTag = HB_TAG ('t','r','u','e'), /* Obsolete Apple TrueType */
@@ -502,12 +473,14 @@ struct OpenTypeFontFile
case Typ1Tag:
case TrueTypeTag: return 1;
case TTCTag: return u.ttcHeader.get_face_count ();
-// case DFontTag: return u.rfHeader.get_face_count ();
+ case DFontTag: return u.rfHeader.get_face_count ();
default: return 0;
}
}
- inline const OpenTypeFontFace& get_face (unsigned int i) const
+ inline const OpenTypeFontFace& get_face (unsigned int i, unsigned int *base_offset = nullptr) const
{
+ if (base_offset)
+ *base_offset = 0;
switch (u.tag) {
/* 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
@@ -517,7 +490,7 @@ struct OpenTypeFontFile
case Typ1Tag:
case TrueTypeTag: return u.fontFace;
case TTCTag: return u.ttcHeader.get_face (i);
-// case DFontTag: return u.rfHeader.get_face (i);
+ case DFontTag: return u.rfHeader.get_face (i, base_offset);
default: return Null(OpenTypeFontFace);
}
}
@@ -544,7 +517,7 @@ struct OpenTypeFontFile
case Typ1Tag:
case TrueTypeTag: return_trace (u.fontFace.sanitize (c));
case TTCTag: return_trace (u.ttcHeader.sanitize (c));
-// case DFontTag: return_trace (u.rfHeader.sanitize (c));
+ case DFontTag: return_trace (u.rfHeader.sanitize (c));
default: return_trace (true);
}
}