From efb324a46ff64adb4ec8612b4089e8daff1e6d8e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 23 Apr 2010 16:22:54 -0400 Subject: [PATCH] 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. --- src/hb-open-file-private.hh | 4 ---- src/hb-open-type-private.hh | 23 ++--------------------- src/hb-ot-layout-gdef-private.hh | 2 -- src/hb-ot-layout-gpos-private.hh | 3 --- src/hb-ot-layout-gsub-private.hh | 3 --- src/hb-ot-layout-gsubgpos-private.hh | 2 -- src/main.cc | 6 +++--- 7 files changed, 5 insertions(+), 38 deletions(-) diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index f45ba8ff4..a3efaf12d 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -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 diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 1a11cd198..232a61e30 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -107,25 +107,6 @@ ASSERT_STATIC (sizeof (Type) + 1 <= sizeof (_Null##Type)) #define Null(Type) Null() -/* 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 (*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 (*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 (* (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 (* (const char *) hb_blob_lock (blob)); } }; diff --git a/src/hb-ot-layout-gdef-private.hh b/src/hb-ot-layout-gdef-private.hh index 4de5740f0..14bef8cd0 100644 --- a/src/hb-ot-layout-gdef-private.hh +++ b/src/hb-ot-layout-gdef-private.hh @@ -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); } diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh index 65937fbac..73ac56df3 100644 --- a/src/hb-ot-layout-gpos-private.hh +++ b/src/hb-ot-layout-gpos-private.hh @@ -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 (GSUBGPOS::get_for_data (data)); } - inline const PosLookup& get_lookup (unsigned int i) const { return Cast (GSUBGPOS::get_lookup (i)); } diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh index 0d6bbc954..fc3bb298b 100644 --- a/src/hb-ot-layout-gsub-private.hh +++ b/src/hb-ot-layout-gsub-private.hh @@ -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 (GSUBGPOS::get_for_data (data)); } - inline const SubstLookup& get_lookup (unsigned int i) const { return Cast (GSUBGPOS::get_lookup (i)); } diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index 74d9b042b..73e628351 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -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 diff --git a/src/main.cc b/src/main.cc index b4123b512..badf91bb1 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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 (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 (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 (font_data + table.offset); printf (" Has %sglyph classes\n", gdef.has_glyph_classes () ? "" : "no ");