Remove GET_FOR_DATA macros

The major-version check is now handled by sanitize.  If major
doesn't match, we reject and fall back to the Null object.
This commit is contained in:
Behdad Esfahbod 2010-04-23 16:22:54 -04:00
parent f1aaa2a436
commit efb324a46f
7 changed files with 5 additions and 38 deletions

View File

@ -66,8 +66,6 @@ typedef struct OffsetTable
{
friend struct OpenTypeFontFile;
STATIC_DEFINE_GET_FOR_DATA (OffsetTable);
inline unsigned int get_table_count (void) const
{ return numTables; }
inline const Tag& get_table_tag (unsigned int i) const
@ -201,8 +199,6 @@ struct OpenTypeFontFile
static const hb_tag_t TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 );
static const hb_tag_t TTCTag = HB_TAG ('t','t','c','f');
STATIC_DEFINE_GET_FOR_DATA (OpenTypeFontFile);
inline hb_tag_t get_tag (void) const { return u.tag; }
inline unsigned int get_face_count (void) const

View File

@ -107,25 +107,6 @@ ASSERT_STATIC (sizeof (Type) + 1 <= sizeof (_Null##Type))
#define Null(Type) Null<Type>()
/* get_for_data() is a static class method returning a reference to an
* instance of Type located at the input data location. It's just a
* fancy, NULL-safe, cast! */
#define STATIC_DEFINE_GET_FOR_DATA(Type) \
static inline const Type& get_for_data (const char *data) \
{ \
if (HB_UNLIKELY (data == NULL)) return Null(Type); \
return Cast<Type> (*data); \
}
/* Like get_for_data(), but checks major version first. */
#define STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION(Type, MajorMin, MajorMax) \
static inline const Type& get_for_data (const char *data) \
{ \
if (HB_UNLIKELY (data == NULL)) return Null(Type); \
const Type& t = Cast<Type> (*data); \
if (HB_UNLIKELY (t.version.major < MajorMin || t.version.major > MajorMax)) return Null(Type); \
return t; \
}
/*
* Sanitize
@ -299,7 +280,7 @@ struct Sanitizer
_hb_sanitize_init (&context, blob);
/* We drop const here */
/* Note: We drop const here */
Type *t = &Cast<Type> (* (char *) CharP(context.start));
sane = t->sanitize (SANITIZE_ARG_INIT);
@ -345,7 +326,7 @@ struct Sanitizer
}
static const Type& lock_instance (hb_blob_t *blob) {
return Type::get_for_data (hb_blob_lock (blob));
return Cast<Type> (* (const char *) hb_blob_lock (blob));
}
};

View File

@ -314,8 +314,6 @@ struct GDEF
ComponentGlyph = 4
};
STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GDEF, 1, 1);
inline bool has_glyph_classes () const { return glyphClassDef != 0; }
inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const
{ return (this+glyphClassDef).get_class (glyph); }

View File

@ -1520,9 +1520,6 @@ struct GPOS : GSUBGPOS
{
static const hb_tag_t Tag = HB_OT_TAG_GPOS;
static inline const GPOS& get_for_data (const char *data)
{ return Cast<GPOS> (GSUBGPOS::get_for_data (data)); }
inline const PosLookup& get_lookup (unsigned int i) const
{ return Cast<PosLookup> (GSUBGPOS::get_lookup (i)); }

View File

@ -855,9 +855,6 @@ struct GSUB : GSUBGPOS
{
static const hb_tag_t Tag = HB_OT_TAG_GSUB;
static inline const GSUB& get_for_data (const char *data)
{ return Cast<GSUB> (GSUBGPOS::get_for_data (data)); }
inline const SubstLookup& get_lookup (unsigned int i) const
{ return Cast<SubstLookup> (GSUBGPOS::get_lookup (i)); }

View File

@ -896,8 +896,6 @@ struct GSUBGPOS
static const hb_tag_t GSUBTag = HB_OT_TAG_GSUB;
static const hb_tag_t GPOSTag = HB_OT_TAG_GPOS;
STATIC_DEFINE_GET_FOR_DATA_CHECK_MAJOR_VERSION (GSUBGPOS, 1, 1);
inline unsigned int get_script_count (void) const
{ return (this+scriptList).len; }
inline const Tag& get_script_tag (unsigned int i) const

View File

@ -61,7 +61,7 @@ main (int argc, char **argv)
printf ("Opened font file %s: %d bytes long\n", argv[1], len);
const OpenTypeFontFile &ot = OpenTypeFontFile::get_for_data (font_data);
const OpenTypeFontFile &ot = Cast<OpenTypeFontFile> (font_data);
switch (ot.get_tag ()) {
case OpenTypeFontFile::TrueTypeTag:
@ -99,7 +99,7 @@ main (int argc, char **argv)
case GSUBGPOS::GPOSTag:
{
const GSUBGPOS &g = GSUBGPOS::get_for_data ((const char *) &ot + table.offset);
const GSUBGPOS &g = Cast<GSUBGPOS> (font_data + table.offset);
int num_scripts = g.get_script_count ();
printf (" %d script(s) found in table\n", num_scripts);
@ -162,7 +162,7 @@ main (int argc, char **argv)
case GDEF::Tag:
{
const GDEF &gdef = GDEF::get_for_data ((const char *) &ot + table.offset);
const GDEF &gdef = Cast<GDEF> (font_data + table.offset);
printf (" Has %sglyph classes\n",
gdef.has_glyph_classes () ? "" : "no ");