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 f25522e..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,8 +60,9 @@ 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
 {
@@ -68,29 +70,28 @@ typedef struct OffsetTable
 
   inline unsigned int get_table_count (void) const
   { return numTables; }
-  inline const TableDirectory& get_table (unsigned int i) const
+  inline const TableRecord& get_table (unsigned int i) const
   {
-    if (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);
@@ -98,9 +99,10 @@ typedef struct OffsetTable
   }
 
   public:
-  inline bool sanitize (SANITIZE_ARG_DEF) {
+  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:
@@ -109,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
@@ -124,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 SANITIZE_THIS (table);
+    return table.sanitize (c, this);
   }
 
   private:
@@ -136,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
 {
@@ -147,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);
+    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;
     }
   }
@@ -179,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;
 };
 
@@ -193,8 +198,8 @@ struct OpenTypeFontFile
   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'); /* Apple obsolete tag */
-  static const hb_tag_t Typ1Tag                = HB_TAG ('t','y','p','1'); /* Apple obsolete tag */
+  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 */
 
   inline hb_tag_t get_tag (void) const { return u.tag; }
 
@@ -205,7 +210,7 @@ struct OpenTypeFontFile
     case TrueTag:
     case Typ1Tag:
     case TrueTypeTag:  return 1;
-    case TTCTag:       return u.ttcHeader->get_face_count ();
+    case TTCTag:       return u.ttcHeader.get_face_count ();
     default:           return 0;
     }
   }
@@ -218,21 +223,21 @@ struct OpenTypeFontFile
     case CFFTag:       /* All the non-collection tags */
     case TrueTag:
     case Typ1Tag:
-    case TrueTypeTag:  return u.fontFace[0];
-    case TTCTag:       return u.ttcHeader->get_face (i);
+    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 (u.tag)) return false;
+    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 (SANITIZE_ARG);
-    case TTCTag:       return u.ttcHeader->sanitize (SANITIZE_ARG);
+    case TrueTypeTag:  return u.fontFace.sanitize (c);
+    case TTCTag:       return u.ttcHeader.sanitize (c);
     default:           return true;
     }
   }
@@ -240,10 +245,14 @@ struct OpenTypeFontFile
   private:
   union {
   Tag                  tag;            /* 4-byte identifier. */
-  OpenTypeFontFace     fontFace[VAR];
-  TTCHeader            ttcHeader[VAR];
+  OpenTypeFontFace     fontFace;
+  TTCHeader            ttcHeader;
   } u;
+  public:
+  DEFINE_SIZE_UNION (4, tag);
 };
 
 
+HB_END_DECLS
+
 #endif /* HB_OPEN_FILE_PRIVATE_HH */