[meta] hb_ot_metadata_get_entries, tags iteration API

pull/1871/head
Ebrahim Byagowi 5 years ago committed by Behdad Esfahbod
parent 3ac03bd67c
commit bc65ebbce7
  1. 17
      src/hb-ot-meta-table.hh
  2. 28
      src/hb-ot-metadata.cc
  3. 8
      src/hb-ot-metadata.h
  4. 26
      test/api/test-ot-metadata.c

@ -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<meta> table;
};

@ -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

@ -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

@ -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 ();
}

Loading…
Cancel
Save