Add hb_face_get_table_tags()
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 11 Oct 2017 15:22:44 +0000 (17:22 +0200)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 11 Oct 2017 15:22:44 +0000 (17:22 +0200)
New API:
hb_face_get_table_tags()

Fixes https://github.com/behdad/harfbuzz/issues/560

src/hb-face.cc
src/hb-face.h
src/hb-open-file-private.hh

index 0f90b59f30c91024d842b385e62e7ec709ecdec4..e96c8acd3860ee196d25a01eb2b83a38393e95a8 100644 (file)
@@ -474,4 +474,33 @@ hb_face_t::load_num_glyphs (void) const
   hb_blob_destroy (maxp_blob);
 }
 
+/**
+ * hb_face_get_table_tags:
+ * @face: a face.
+ *
+ * Retrieves table tags for a face, if possible.
+ *
+ * Return value: total number of tables, or 0 if not possible to list.
+ *
+ * Since: 1.6.0
+ **/
+unsigned int
+hb_face_get_table_tags (hb_face_t    *face,
+                       unsigned int  start_offset,
+                       unsigned int *table_count, /* IN/OUT */
+                       hb_tag_t     *table_tags /* OUT */)
+{
+  if (face->destroy != _hb_face_for_data_closure_destroy)
+  {
+    if (table_count)
+      *table_count = 0;
+    return 0;
+  }
 
+  hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) face->user_data;
+
+  const OT::OpenTypeFontFile &ot_file = *OT::Sanitizer<OT::OpenTypeFontFile>::lock_instance (data->blob);
+  const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index);
+
+  return ot_face.get_table_tags (start_offset, table_count, table_tags);
+}
index 91237b70850bc9750516c73aca7051228e5c22c1..9842d52b650034b7010d3a77b0274e40257dce39 100644 (file)
@@ -111,6 +111,11 @@ hb_face_set_glyph_count (hb_face_t    *face,
 HB_EXTERN unsigned int
 hb_face_get_glyph_count (hb_face_t *face);
 
+HB_EXTERN unsigned int
+hb_face_get_table_tags (hb_face_t    *face,
+                       unsigned int  start_offset,
+                       unsigned int *table_count, /* IN/OUT */
+                       hb_tag_t     *table_tags /* OUT */);
 
 HB_END_DECLS
 
index f208419aac5baa521dc6183065cb0457d2b619f9..dcfdfd6cab465b2b5f839b90dd9071ad999ba53b 100644 (file)
@@ -79,6 +79,24 @@ typedef struct OffsetTable
     if (unlikely (i >= numTables)) return Null(TableRecord);
     return tables[i];
   }
+  inline unsigned int get_table_tags (unsigned int start_offset,
+                                     unsigned int *table_count, /* IN/OUT */
+                                     hb_tag_t     *table_tags /* OUT */) const
+  {
+    if (table_count)
+    {
+      if (start_offset >= numTables)
+        *table_count = 0;
+      else
+        *table_count = MIN (*table_count, numTables - start_offset);
+
+      const TableRecord *sub_tables = tables + start_offset;
+      unsigned int count = *table_count;
+      for (unsigned int i = 0; i < count; i++)
+       table_tags[i] = sub_tables[i].tag;
+    }
+    return numTables;
+  }
   inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const
   {
     Tag t;