src/java.desktop/share/native/libfontmanager/harfbuzz/hb-open-file-private.hh
changeset 48274 51772bf1fb0c
parent 47216 71c04702a3d5
child 50352 25db2c8f3cf8
equal deleted inserted replaced
48273:e2065f7505eb 48274:51772bf1fb0c
    51 struct TTCHeader;
    51 struct TTCHeader;
    52 
    52 
    53 
    53 
    54 typedef struct TableRecord
    54 typedef struct TableRecord
    55 {
    55 {
       
    56   int cmp (Tag t) const
       
    57   { return t.cmp (tag); }
       
    58 
    56   inline bool sanitize (hb_sanitize_context_t *c) const
    59   inline bool sanitize (hb_sanitize_context_t *c) const
    57   {
    60   {
    58     TRACE_SANITIZE (this);
    61     TRACE_SANITIZE (this);
    59     return_trace (c->check_struct (this));
    62     return_trace (c->check_struct (this));
    60   }
    63   }
    71 typedef struct OffsetTable
    74 typedef struct OffsetTable
    72 {
    75 {
    73   friend struct OpenTypeFontFile;
    76   friend struct OpenTypeFontFile;
    74 
    77 
    75   inline unsigned int get_table_count (void) const
    78   inline unsigned int get_table_count (void) const
    76   { return numTables; }
    79   { return tables.len; }
    77   inline const TableRecord& get_table (unsigned int i) const
    80   inline const TableRecord& get_table (unsigned int i) const
    78   {
    81   {
    79     if (unlikely (i >= numTables)) return Null(TableRecord);
       
    80     return tables[i];
    82     return tables[i];
       
    83   }
       
    84   inline unsigned int get_table_tags (unsigned int start_offset,
       
    85                                       unsigned int *table_count, /* IN/OUT */
       
    86                                       hb_tag_t     *table_tags /* OUT */) const
       
    87   {
       
    88     if (table_count)
       
    89     {
       
    90       if (start_offset >= tables.len)
       
    91         *table_count = 0;
       
    92       else
       
    93         *table_count = MIN<unsigned int> (*table_count, tables.len - start_offset);
       
    94 
       
    95       const TableRecord *sub_tables = tables.array + start_offset;
       
    96       unsigned int count = *table_count;
       
    97       for (unsigned int i = 0; i < count; i++)
       
    98         table_tags[i] = sub_tables[i].tag;
       
    99     }
       
   100     return tables.len;
    81   }
   101   }
    82   inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
   102   inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
    83   {
   103   {
    84     Tag t;
   104     Tag t;
    85     t.set (tag);
   105     t.set (tag);
    86     unsigned int count = numTables;
   106     /* Linear-search for small tables to work around fonts with unsorted
    87     for (unsigned int i = 0; i < count; i++)
   107      * table list. */
    88     {
   108     int i = tables.len < 64 ? tables.lsearch (t) : tables.bsearch (t);
    89       if (t == tables[i].tag)
   109     if (table_index)
    90       {
   110       *table_index = i == -1 ? Index::NOT_FOUND_INDEX : (unsigned int) i;
    91         if (table_index) *table_index = i;
   111     return i != -1;
    92         return true;
       
    93       }
       
    94     }
       
    95     if (table_index) *table_index = Index::NOT_FOUND_INDEX;
       
    96     return false;
       
    97   }
   112   }
    98   inline const TableRecord& get_table_by_tag (hb_tag_t tag) const
   113   inline const TableRecord& get_table_by_tag (hb_tag_t tag) const
    99   {
   114   {
   100     unsigned int table_index;
   115     unsigned int table_index;
   101     find_table_index (tag, &table_index);
   116     find_table_index (tag, &table_index);
   104 
   119 
   105   public:
   120   public:
   106   inline bool sanitize (hb_sanitize_context_t *c) const
   121   inline bool sanitize (hb_sanitize_context_t *c) const
   107   {
   122   {
   108     TRACE_SANITIZE (this);
   123     TRACE_SANITIZE (this);
   109     return_trace (c->check_struct (this) && c->check_array (tables, TableRecord::static_size, numTables));
   124     return_trace (c->check_struct (this) && tables.sanitize (c));
   110   }
   125   }
   111 
   126 
   112   protected:
   127   protected:
   113   Tag           sfnt_version;   /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
   128   Tag           sfnt_version;   /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
   114   USHORT        numTables;      /* Number of tables. */
   129   BinSearchArrayOf<TableRecord>
   115   USHORT        searchRangeZ;   /* (Maximum power of 2 <= numTables) x 16 */
   130                 tables;
   116   USHORT        entrySelectorZ; /* Log2(maximum power of 2 <= numTables). */
       
   117   USHORT        rangeShiftZ;    /* NumTables x 16-searchRange. */
       
   118   TableRecord   tables[VAR];    /* TableRecord entries. numTables items */
       
   119   public:
   131   public:
   120   DEFINE_SIZE_ARRAY (12, tables);
   132   DEFINE_SIZE_ARRAY (12, tables);
   121 } OpenTypeFontFace;
   133 } OpenTypeFontFace;
   122 
   134 
   123 
   135 
   140 
   152 
   141   protected:
   153   protected:
   142   Tag           ttcTag;         /* TrueType Collection ID string: 'ttcf' */
   154   Tag           ttcTag;         /* TrueType Collection ID string: 'ttcf' */
   143   FixedVersion<>version;        /* Version of the TTC Header (1.0),
   155   FixedVersion<>version;        /* Version of the TTC Header (1.0),
   144                                  * 0x00010000u */
   156                                  * 0x00010000u */
   145   ArrayOf<OffsetTo<OffsetTable, ULONG>, ULONG>
   157   ArrayOf<LOffsetTo<OffsetTable>, ULONG>
   146                 table;          /* Array of offsets to the OffsetTable for each font
   158                 table;          /* Array of offsets to the OffsetTable for each font
   147                                  * from the beginning of the file */
   159                                  * from the beginning of the file */
   148   public:
   160   public:
   149   DEFINE_SIZE_ARRAY (12, table);
   161   DEFINE_SIZE_ARRAY (12, table);
   150 };
   162 };