Many HarfBuzz functions return a list of items: the table tags of a face, the script tags of a layout table, the variation axes of a variable font. HarfBuzz does not allocate these lists. The caller passes an array, and the function fills it in. Such functions follow one convention:
start_offset is the index of the first
item to fetch.
The count is passed by pointer. Going in, it is the capacity of the array; coming out, the number of items written to it.
The return value is the total number of items, whatever offset, count and array were passed.
There are two ways to call such a function: with an array and
its capacity, or with NULL for both the count
and the array, to ask only for the total. The usual pattern is
to do one and then the other:
unsigned int count; hb_tag_t *tags; count = hb_ot_layout_table_get_script_tags(face, HB_OT_TAG_GSUB, 0, NULL, NULL); tags = malloc(count * sizeof(hb_tag_t)); hb_ot_layout_table_get_script_tags(face, HB_OT_TAG_GSUB, 0, &count, tags);
A client with an array of fixed size can instead fetch the list
a piece at a time, adding the count that comes back
to start_offset until it reaches the total.
hb_tag_t tags[32];
unsigned int offset = 0;
unsigned int total;
do
{
unsigned int count = sizeof(tags) / sizeof(tags[0]);
total = hb_ot_layout_table_get_script_tags(face, HB_OT_TAG_GSUB, offset, &count, tags);
for (unsigned int i = 0; i < count; i++)
use_script_tag(tags[i]);
offset += count;
}
while (offset < total);
Each call sets count to the capacity of the
array before it is passed, since it comes back as the number of
items written.
The array may be NULL only if the count
is NULL or zero. A non-zero count with no
array is not a valid call. HarfBuzz answers it by setting the
count to zero and writing nothing; the return value is still the
total.
A few of these functions leave out the offset or the return value; the API Reference manual describes each.