From bc65ebbce765545bc4455d8ae5ba4a6a99201e41 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Wed, 24 Jul 2019 02:28:09 +0430 Subject: [PATCH] [meta] hb_ot_metadata_get_entries, tags iteration API --- src/hb-ot-meta-table.hh | 17 +++++++++++++++++ src/hb-ot-metadata.cc | 28 ++++++++++++++++++++++++---- src/hb-ot-metadata.h | 8 +++++++- test/api/test-ot-metadata.c | 26 ++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src/hb-ot-meta-table.hh b/src/hb-ot-meta-table.hh index d36c3e94f..7d60c7662 100644 --- a/src/hb-ot-meta-table.hh +++ b/src/hb-ot-meta-table.hh @@ -42,6 +42,8 @@ struct DataMap { int cmp (hb_tag_t a) const { return tag.cmp (a); } + hb_tag_t get_tag () const { return tag; } + hb_blob_t *reference_entry (hb_blob_t *meta_blob) const { return hb_blob_create_sub_blob (meta_blob, dataZ, dataLength); } @@ -76,6 +78,21 @@ struct meta hb_blob_t *reference_entry (hb_tag_t tag) const { return table->dataMaps.lsearch (tag, Null (DataMap)).reference_entry (table.get_blob ()); } + unsigned int get_entries (unsigned int start_offset, + unsigned int *count, + hb_ot_metadata_t *entries) const + { + unsigned int entries_count = table->dataMaps.len; + if (count && *count) + { + unsigned int len = hb_min (entries_count - start_offset, *count); + for (unsigned int i = 0; i < len; i++) + entries[i] = (hb_ot_metadata_t) table->dataMaps[i + start_offset].get_tag (); + *count = len; + } + return table->dataMaps.len; + } + private: hb_blob_ptr_t table; }; diff --git a/src/hb-ot-metadata.cc b/src/hb-ot-metadata.cc index 42153be73..8ad602a91 100644 --- a/src/hb-ot-metadata.cc +++ b/src/hb-ot-metadata.cc @@ -38,9 +38,29 @@ **/ /** - * hb_ot_meta_reference_entry: + * hb_ot_metadata_reference_entry: + * @face: a face object + * @start_offset: iteration's start offset + * @entries_count:(inout) (allow-none): buffer size as input, filled size as output + * @entries: (out caller-allocates) (array length=entries_count): entries tags buffer + * + * Return value: Number of all available feature types. + * + * Since: REPLACEME + **/ +unsigned int +hb_ot_metadata_get_entries (hb_face_t *face, + unsigned int start_offset, + unsigned int *entries_count, /* IN/OUT. May be NULL. */ + hb_ot_metadata_t *entries /* OUT. May be NULL. */) +{ + return face->table.meta->get_entries (start_offset, entries_count, entries); +} + +/** + * hb_ot_metadata_reference_entry: * @face: a #hb_face_t object. - * @meta_tag: tag of metadata you like to have. + * @metadata_tag: tag of metadata you like to have. * * It fetches metadata entry of a given tag from a font. * @@ -49,9 +69,9 @@ * Since: REPLACEME **/ hb_blob_t * -hb_ot_metadata_reference_entry (hb_face_t *face, hb_ot_metadata_t meta_tag) +hb_ot_metadata_reference_entry (hb_face_t *face, hb_ot_metadata_t metadata_tag) { - return face->table.meta->reference_entry (meta_tag); + return face->table.meta->reference_entry (metadata_tag); } #endif diff --git a/src/hb-ot-metadata.h b/src/hb-ot-metadata.h index 3654458a1..5d26e1d5a 100644 --- a/src/hb-ot-metadata.h +++ b/src/hb-ot-metadata.h @@ -49,8 +49,14 @@ typedef enum { HB_OT_METADATA_SUPPORTED_LANGUAGES = HB_TAG ('s','l','n','g') } hb_ot_metadata_t; +HB_EXTERN unsigned int +hb_ot_metadata_get_entries (hb_face_t *face, + unsigned int start_offset, + unsigned int *entries_count, /* IN/OUT. May be NULL. */ + hb_ot_metadata_t *entries /* OUT. May be NULL. */); + HB_EXTERN hb_blob_t * -hb_ot_metadata_reference_entry (hb_face_t *face, hb_ot_metadata_t tag); +hb_ot_metadata_reference_entry (hb_face_t *face, hb_ot_metadata_t metadata_tag); HB_END_DECLS diff --git a/test/api/test-ot-metadata.c b/test/api/test-ot-metadata.c index d5f922415..f0e633e50 100644 --- a/test/api/test-ot-metadata.c +++ b/test/api/test-ot-metadata.c @@ -28,6 +28,31 @@ /* Unit tests for hb-ot-metadata.h */ +static void +test_ot_metadata_get_entries (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/meta.ttf"); + hb_ot_metadata_t entries[2]; + + unsigned int entries_count = 2; + g_assert_cmpint (hb_ot_metadata_get_entries (face, 0, &entries_count, entries), ==, 5); + g_assert_cmpint (entries_count, ==, 2); + g_assert_cmpint (entries[0], ==, HB_TAG ('a','p','p','l')); + g_assert_cmpint (entries[1], ==, HB_TAG ('b','i','l','d')); + + entries_count = 1; + g_assert_cmpint (hb_ot_metadata_get_entries (face, 2, &entries_count, entries), ==, 5); + g_assert_cmpint (entries_count, ==, 1); + g_assert_cmpint (entries[0], ==, HB_TAG ('d','l','n','g')); + + entries_count = 2; + g_assert_cmpint (hb_ot_metadata_get_entries (face, 4, &entries_count, entries), ==, 5); + g_assert_cmpint (entries_count, ==, 1); + g_assert_cmpint (entries[0], ==, HB_TAG ('s','l','n','g')); + + hb_face_destroy (face); +} + static void test_ot_metadata_reference_entry (void) { @@ -53,6 +78,7 @@ int main (int argc, char **argv) { hb_test_init (&argc, &argv); + hb_test_add (test_ot_metadata_get_entries); hb_test_add (test_ot_metadata_reference_entry); return hb_test_run (); }