Remove GET_FOR_DATA macros
authorBehdad Esfahbod <behdad@behdad.org>
Fri, 23 Apr 2010 20:22:54 +0000 (16:22 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Fri, 23 Apr 2010 20:28:27 +0000 (16:28 -0400)
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
src/hb-open-type-private.hh
src/hb-ot-layout-gdef-private.hh
src/hb-ot-layout-gpos-private.hh
src/hb-ot-layout-gsub-private.hh
src/hb-ot-layout-gsubgpos-private.hh
src/main.cc

index f45ba8f..a3efaf1 100644 (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
index 1a11cd1..232a61e 100644 (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));
   }
 };
 
index 4de5740..14bef8c 100644 (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); }
index 65937fb..73ac56d 100644 (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)); }
 
index 0d6bbc9..fc3bb29 100644 (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)); }
 
index 74d9b04..73e6283 100644 (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
index b4123b5..badf91b 100644 (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 ");