From 94b3cafc3a042aea69ee7040227557fe98a21d87 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Oct 2017 17:22:44 +0200 Subject: [PATCH] Add hb_face_get_table_tags() New API: hb_face_get_table_tags() Fixes https://github.com/behdad/harfbuzz/issues/560 --- src/hb-face.cc | 29 +++++++++++++++++++++++++++++ src/hb-face.h | 5 +++++ src/hb-open-file-private.hh | 18 ++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/src/hb-face.cc b/src/hb-face.cc index 0f90b59f3..e96c8acd3 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -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::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); +} diff --git a/src/hb-face.h b/src/hb-face.h index 91237b708..9842d52b6 100644 --- a/src/hb-face.h +++ b/src/hb-face.h @@ -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 diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index f208419aa..dcfdfd6ca 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -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;