< prev index next >

src/java.desktop/share/native/libfontmanager/harfbuzz/hb-open-file-private.hh

Print this page




  36 
  37 
  38 /*
  39  *
  40  * The OpenType Font File
  41  *
  42  */
  43 
  44 
  45 /*
  46  * Organization of an OpenType Font
  47  */
  48 
  49 struct OpenTypeFontFile;
  50 struct OffsetTable;
  51 struct TTCHeader;
  52 
  53 
  54 typedef struct TableRecord
  55 {



  56   inline bool sanitize (hb_sanitize_context_t *c) const
  57   {
  58     TRACE_SANITIZE (this);
  59     return_trace (c->check_struct (this));
  60   }
  61 
  62   Tag           tag;            /* 4-byte identifier. */
  63   CheckSum      checkSum;       /* CheckSum for this table. */
  64   ULONG         offset;         /* Offset from beginning of TrueType font
  65                                  * file. */
  66   ULONG         length;         /* Length of this table. */
  67   public:
  68   DEFINE_SIZE_STATIC (16);
  69 } OpenTypeTable;
  70 
  71 typedef struct OffsetTable
  72 {
  73   friend struct OpenTypeFontFile;
  74 
  75   inline unsigned int get_table_count (void) const
  76   { return numTables; }
  77   inline const TableRecord& get_table (unsigned int i) const
  78   {
  79     if (unlikely (i >= numTables)) return Null(TableRecord);
  80     return tables[i];
  81   }


















  82   inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
  83   {
  84     Tag t;
  85     t.set (tag);
  86     unsigned int count = numTables;
  87     for (unsigned int i = 0; i < count; i++)
  88     {
  89       if (t == tables[i].tag)
  90       {
  91         if (table_index) *table_index = i;
  92         return true;
  93       }
  94     }
  95     if (table_index) *table_index = Index::NOT_FOUND_INDEX;
  96     return false;
  97   }
  98   inline const TableRecord& get_table_by_tag (hb_tag_t tag) const
  99   {
 100     unsigned int table_index;
 101     find_table_index (tag, &table_index);
 102     return get_table (table_index);
 103   }
 104 
 105   public:
 106   inline bool sanitize (hb_sanitize_context_t *c) const
 107   {
 108     TRACE_SANITIZE (this);
 109     return_trace (c->check_struct (this) && c->check_array (tables, TableRecord::static_size, numTables));
 110   }
 111 
 112   protected:
 113   Tag           sfnt_version;   /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
 114   USHORT        numTables;      /* Number of tables. */
 115   USHORT        searchRangeZ;   /* (Maximum power of 2 <= numTables) x 16 */
 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:
 120   DEFINE_SIZE_ARRAY (12, tables);
 121 } OpenTypeFontFace;
 122 
 123 
 124 /*
 125  * TrueType Collections
 126  */
 127 
 128 struct TTCHeaderVersion1
 129 {
 130   friend struct TTCHeader;
 131 
 132   inline unsigned int get_face_count (void) const { return table.len; }
 133   inline const OpenTypeFontFace& get_face (unsigned int i) const { return this+table[i]; }
 134 
 135   inline bool sanitize (hb_sanitize_context_t *c) const
 136   {
 137     TRACE_SANITIZE (this);
 138     return_trace (table.sanitize (c, this));
 139   }
 140 
 141   protected:
 142   Tag           ttcTag;         /* TrueType Collection ID string: 'ttcf' */
 143   FixedVersion<>version;        /* Version of the TTC Header (1.0),
 144                                  * 0x00010000u */
 145   ArrayOf<OffsetTo<OffsetTable, ULONG>, ULONG>
 146                 table;          /* Array of offsets to the OffsetTable for each font
 147                                  * from the beginning of the file */
 148   public:
 149   DEFINE_SIZE_ARRAY (12, table);
 150 };
 151 
 152 struct TTCHeader
 153 {
 154   friend struct OpenTypeFontFile;
 155 
 156   private:
 157 
 158   inline unsigned int get_face_count (void) const
 159   {
 160     switch (u.header.version.major) {
 161     case 2: /* version 2 is compatible with version 1 */
 162     case 1: return u.version1.get_face_count ();
 163     default:return 0;
 164     }
 165   }




  36 
  37 
  38 /*
  39  *
  40  * The OpenType Font File
  41  *
  42  */
  43 
  44 
  45 /*
  46  * Organization of an OpenType Font
  47  */
  48 
  49 struct OpenTypeFontFile;
  50 struct OffsetTable;
  51 struct TTCHeader;
  52 
  53 
  54 typedef struct TableRecord
  55 {
  56   int cmp (Tag t) const
  57   { return t.cmp (tag); }
  58 
  59   inline bool sanitize (hb_sanitize_context_t *c) const
  60   {
  61     TRACE_SANITIZE (this);
  62     return_trace (c->check_struct (this));
  63   }
  64 
  65   Tag           tag;            /* 4-byte identifier. */
  66   CheckSum      checkSum;       /* CheckSum for this table. */
  67   ULONG         offset;         /* Offset from beginning of TrueType font
  68                                  * file. */
  69   ULONG         length;         /* Length of this table. */
  70   public:
  71   DEFINE_SIZE_STATIC (16);
  72 } OpenTypeTable;
  73 
  74 typedef struct OffsetTable
  75 {
  76   friend struct OpenTypeFontFile;
  77 
  78   inline unsigned int get_table_count (void) const
  79   { return tables.len; }
  80   inline const TableRecord& get_table (unsigned int i) const
  81   {

  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;
 101   }
 102   inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
 103   {
 104     Tag t;
 105     t.set (tag);
 106     /* Linear-search for small tables to work around fonts with unsorted
 107      * table list. */
 108     int i = tables.len < 64 ? tables.lsearch (t) : tables.bsearch (t);
 109     if (table_index)
 110       *table_index = i == -1 ? Index::NOT_FOUND_INDEX : (unsigned int) i;
 111     return i != -1;





 112   }
 113   inline const TableRecord& get_table_by_tag (hb_tag_t tag) const
 114   {
 115     unsigned int table_index;
 116     find_table_index (tag, &table_index);
 117     return get_table (table_index);
 118   }
 119 
 120   public:
 121   inline bool sanitize (hb_sanitize_context_t *c) const
 122   {
 123     TRACE_SANITIZE (this);
 124     return_trace (c->check_struct (this) && tables.sanitize (c));
 125   }
 126 
 127   protected:
 128   Tag           sfnt_version;   /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
 129   BinSearchArrayOf<TableRecord>
 130                 tables;



 131   public:
 132   DEFINE_SIZE_ARRAY (12, tables);
 133 } OpenTypeFontFace;
 134 
 135 
 136 /*
 137  * TrueType Collections
 138  */
 139 
 140 struct TTCHeaderVersion1
 141 {
 142   friend struct TTCHeader;
 143 
 144   inline unsigned int get_face_count (void) const { return table.len; }
 145   inline const OpenTypeFontFace& get_face (unsigned int i) const { return this+table[i]; }
 146 
 147   inline bool sanitize (hb_sanitize_context_t *c) const
 148   {
 149     TRACE_SANITIZE (this);
 150     return_trace (table.sanitize (c, this));
 151   }
 152 
 153   protected:
 154   Tag           ttcTag;         /* TrueType Collection ID string: 'ttcf' */
 155   FixedVersion<>version;        /* Version of the TTC Header (1.0),
 156                                  * 0x00010000u */
 157   ArrayOf<LOffsetTo<OffsetTable>, ULONG>
 158                 table;          /* Array of offsets to the OffsetTable for each font
 159                                  * from the beginning of the file */
 160   public:
 161   DEFINE_SIZE_ARRAY (12, table);
 162 };
 163 
 164 struct TTCHeader
 165 {
 166   friend struct OpenTypeFontFile;
 167 
 168   private:
 169 
 170   inline unsigned int get_face_count (void) const
 171   {
 172     switch (u.header.version.major) {
 173     case 2: /* version 2 is compatible with version 1 */
 174     case 1: return u.version1.get_face_count ();
 175     default:return 0;
 176     }
 177   }


< prev index next >