Un-Ra U+09F1. According to the test suite this is correct.
[profile/ivi/org.tizen.video-player.git] / src / hb-open-file-private.hh
index c7ddff9..7d43e46 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007,2008,2009  Red Hat, Inc.
+ * Copyright © 2007,2008,2009  Red Hat, Inc.
  *
  *  This is part of HarfBuzz, a text shaping library.
  *
@@ -29,6 +29,8 @@
 
 #include "hb-open-type-private.hh"
 
+HB_BEGIN_DECLS
+
 
 /*
  *
@@ -45,13 +47,12 @@ struct OpenTypeFontFile;
 struct OffsetTable;
 struct TTCHeader;
 
-typedef struct TableDirectory
-{
-  static inline unsigned int get_size () { return sizeof (TableDirectory); }
 
-  inline bool sanitize (SANITIZE_ARG_DEF) {
+typedef struct TableRecord
+{
+  inline bool sanitize (hb_sanitize_context_t *c) {
     TRACE_SANITIZE ();
-    return SANITIZE_SELF ();
+    return c->check_struct (this);
   }
 
   Tag          tag;            /* 4-byte identifier. */
@@ -59,57 +60,49 @@ typedef struct TableDirectory
   ULONG                offset;         /* Offset from beginning of TrueType font
                                 * file. */
   ULONG                length;         /* Length of this table. */
+  public:
+  DEFINE_SIZE_STATIC (16);
 } OpenTypeTable;
-ASSERT_SIZE (TableDirectory, 16);
 
 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
+  inline const TableRecord& get_table (unsigned int i) const
   {
-    if (HB_UNLIKELY (i >= numTables)) return Null(Tag);
-    return tableDir[i].tag;
-  }
-  inline const TableDirectory& get_table (unsigned int i) const
-  {
-    if (HB_UNLIKELY (i >= numTables)) return Null(TableDirectory);
-    return tableDir[i];
+    if (unlikely (i >= numTables)) return Null(TableRecord);
+    return tables[i];
   }
   inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
   {
     Tag t;
     t.set (tag);
-    // TODO: bsearch (need to sort in sanitize)
     unsigned int count = numTables;
     for (unsigned int i = 0; i < count; i++)
     {
-      if (t == tableDir[i].tag)
+      if (t == tables[i].tag)
       {
         if (table_index) *table_index = i;
         return true;
       }
     }
-    if (table_index) *table_index = NO_INDEX;
+    if (table_index) *table_index = Index::NOT_FOUND_INDEX;
     return false;
   }
-  inline const TableDirectory& get_table_by_tag (hb_tag_t tag) const
+  inline const TableRecord& get_table_by_tag (hb_tag_t tag) const
   {
     unsigned int table_index;
     find_table_index (tag, &table_index);
     return get_table (table_index);
   }
 
-  inline unsigned int get_face_count (void) const { return 1; }
-
   public:
-  inline bool sanitize (SANITIZE_ARG_DEF, void *base) {
+  inline bool sanitize (hb_sanitize_context_t *c) {
     TRACE_SANITIZE ();
-    return SANITIZE_SELF () && SANITIZE_ARRAY (tableDir, TableDirectory::get_size (), numTables);
+    return c->check_struct (this)
+       && c->check_array (tables, TableRecord::static_size, numTables);
   }
 
   private:
@@ -118,9 +111,11 @@ typedef struct OffsetTable
   USHORT       searchRange;    /* (Maximum power of 2 <= numTables) x 16 */
   USHORT       entrySelector;  /* Log2(maximum power of 2 <= numTables). */
   USHORT       rangeShift;     /* NumTables x 16-searchRange. */
-  TableDirectory tableDir[VAR];        /* TableDirectory entries. numTables items */
+  TableRecord  tables[VAR];    /* TableRecord entries. numTables items */
+  public:
+  DEFINE_SIZE_ARRAY (12, tables);
 } OpenTypeFontFace;
-ASSERT_SIZE_VAR (OffsetTable, 12, TableDirectory);
+
 
 /*
  * TrueType Collections
@@ -133,9 +128,9 @@ struct TTCHeaderVersion1
   inline unsigned int get_face_count (void) const { return table.len; }
   inline const OpenTypeFontFace& get_face (unsigned int i) const { return this+table[i]; }
 
-  inline bool sanitize (SANITIZE_ARG_DEF) {
+  inline bool sanitize (hb_sanitize_context_t *c) {
     TRACE_SANITIZE ();
-    return HB_LIKELY (table.sanitize (SANITIZE_ARG, CharP(this), CharP(this)));
+    return table.sanitize (c, this);
   }
 
   private:
@@ -145,8 +140,9 @@ struct TTCHeaderVersion1
   LongOffsetLongArrayOf<OffsetTable>
                table;          /* Array of offsets to the OffsetTable for each font
                                 * from the beginning of the file */
+  public:
+  DEFINE_SIZE_ARRAY (12, table);
 };
-ASSERT_SIZE (TTCHeaderVersion1, 12);
 
 struct TTCHeader
 {
@@ -156,27 +152,27 @@ struct TTCHeader
 
   inline unsigned int get_face_count (void) const
   {
-    switch (u.header.version) {
+    switch (u.header.version.major) {
     case 2: /* version 2 is compatible with version 1 */
-    case 1: return u.version1->get_face_count ();
+    case 1: return u.version1.get_face_count ();
     default:return 0;
     }
   }
   inline const OpenTypeFontFace& get_face (unsigned int i) const
   {
-    switch (u.header.version) {
+    switch (u.header.version.major) {
     case 2: /* version 2 is compatible with version 1 */
-    case 1: return u.version1->get_face (i);
-    default: return Null(OpenTypeFontFace);
+    case 1: return u.version1.get_face (i);
+    default:return Null(OpenTypeFontFace);
     }
   }
 
-  inline bool sanitize (SANITIZE_ARG_DEF) {
+  inline bool sanitize (hb_sanitize_context_t *c) {
     TRACE_SANITIZE ();
-    if (!SANITIZE (u.header.version)) return false;
-    switch (u.header.version) {
+    if (unlikely (!u.header.version.sanitize (c))) return false;
+    switch (u.header.version.major) {
     case 2: /* version 2 is compatible with version 1 */
-    case 1: return u.version1->sanitize (SANITIZE_ARG);
+    case 1: return u.version1.sanitize (c);
     default:return true;
     }
   }
@@ -188,7 +184,7 @@ struct TTCHeader
   FixedVersion version;        /* Version of the TTC Header (1.0 or 2.0),
                                 * 0x00010000 or 0x00020000 */
   }                    header;
-  TTCHeaderVersion1    version1[VAR];
+  TTCHeaderVersion1    version1;
   } u;
 };
 
@@ -199,45 +195,64 @@ struct TTCHeader
 
 struct OpenTypeFontFile
 {
-  static const hb_tag_t TrueTypeTag    = HB_TAG ( 0 , 1 , 0 , 0 );
-  static const hb_tag_t CFFTag         = HB_TAG ('O','T','T','O');
-  static const hb_tag_t TTCTag         = HB_TAG ('t','t','c','f');
+  static const hb_tag_t CFFTag         = HB_TAG ('O','T','T','O'); /* OpenType with Postscript outlines */
+  static const hb_tag_t TrueTypeTag    = HB_TAG ( 0 , 1 , 0 , 0 ); /* OpenType with TrueType outlines */
+  static const hb_tag_t TTCTag         = HB_TAG ('t','t','c','f'); /* TrueType Collection */
+  static const hb_tag_t TrueTag                = HB_TAG ('t','r','u','e'); /* Obsolete Apple TrueType */
+  static const hb_tag_t Typ1Tag                = HB_TAG ('t','y','p','1'); /* Obsolete Apple Type1 font in SFNT container */
 
-  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
   {
-    switch (tag) {
-    case TrueTypeTag: case CFFTag: return Cast<OpenTypeFontFace> (*this).get_face_count ();
-    case TTCTag: return Cast<TTCHeader> (*this).get_face_count ();
-    default: return 0;
+    switch (u.tag) {
+    case CFFTag:       /* All the non-collection tags */
+    case TrueTag:
+    case Typ1Tag:
+    case TrueTypeTag:  return 1;
+    case TTCTag:       return u.ttcHeader.get_face_count ();
+    default:           return 0;
     }
   }
   inline const OpenTypeFontFace& get_face (unsigned int i) const
   {
-    switch (tag) {
+    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
      * non-TTC, but the index is more than zero. */
-    case TrueTypeTag: case CFFTag: return Cast<OpenTypeFontFace> (*this);
-    case TTCTag: return Cast<TTCHeader> (*this).get_face (i);
-    default: return Null(OpenTypeFontFace);
+    case CFFTag:       /* All the non-collection tags */
+    case TrueTag:
+    case Typ1Tag:
+    case TrueTypeTag:  return u.fontFace;
+    case TTCTag:       return u.ttcHeader.get_face (i);
+    default:           return Null(OpenTypeFontFace);
     }
   }
 
-  inline bool sanitize (SANITIZE_ARG_DEF) {
+  inline bool sanitize (hb_sanitize_context_t *c) {
     TRACE_SANITIZE ();
-    if (!SANITIZE_SELF ()) return false;
-    switch (tag) {
-    default: return true;
-    case TrueTypeTag: case CFFTag: return SANITIZE_THIS (Cast<OpenTypeFontFace> (*this));
-    case TTCTag: return SANITIZE (Cast<TTCHeader> (*this));
+    if (unlikely (!u.tag.sanitize (c))) return false;
+    switch (u.tag) {
+    case CFFTag:       /* All the non-collection tags */
+    case TrueTag:
+    case Typ1Tag:
+    case TrueTypeTag:  return u.fontFace.sanitize (c);
+    case TTCTag:       return u.ttcHeader.sanitize (c);
+    default:           return true;
     }
   }
 
-  Tag          tag;            /* 4-byte identifier. */
+  private:
+  union {
+  Tag                  tag;            /* 4-byte identifier. */
+  OpenTypeFontFace     fontFace;
+  TTCHeader            ttcHeader;
+  } u;
+  public:
+  DEFINE_SIZE_UNION (4, tag);
 };
-ASSERT_SIZE (OpenTypeFontFile, 4);
 
 
+HB_END_DECLS
+
 #endif /* HB_OPEN_FILE_PRIVATE_HH */