calculate hb_string_array length automatically

This commit is contained in:
blueshade7 2019-11-18 15:09:24 -08:00 committed by Behdad Esfahbod
parent 57da16bc59
commit a75983690d
2 changed files with 7 additions and 6 deletions

View File

@ -35,8 +35,6 @@
#undef HB_STRING_ARRAY_LIST #undef HB_STRING_ARRAY_LIST
#undef HB_STRING_ARRAY_NAME #undef HB_STRING_ARRAY_NAME
#define NUM_FORMAT1_NAMES 258
/* /*
* post -- PostScript * post -- PostScript
* https://docs.microsoft.com/en-us/typography/opentype/spec/post * https://docs.microsoft.com/en-us/typography/opentype/spec/post
@ -185,7 +183,7 @@ struct post
unsigned int get_glyph_count () const unsigned int get_glyph_count () const
{ {
if (version == 0x00010000) if (version == 0x00010000)
return NUM_FORMAT1_NAMES; return format1_names_length;
if (version == 0x00020000) if (version == 0x00020000)
return glyphNameIndex->len; return glyphNameIndex->len;
@ -213,7 +211,7 @@ struct post
{ {
if (version == 0x00010000) if (version == 0x00010000)
{ {
if (glyph >= NUM_FORMAT1_NAMES) if (glyph >= format1_names_length)
return hb_bytes_t (); return hb_bytes_t ();
return format1_names (glyph); return format1_names (glyph);
@ -223,9 +221,9 @@ struct post
return hb_bytes_t (); return hb_bytes_t ();
unsigned int index = glyphNameIndex->arrayZ[glyph]; unsigned int index = glyphNameIndex->arrayZ[glyph];
if (index < NUM_FORMAT1_NAMES) if (index < format1_names_length)
return format1_names (index); return format1_names (index);
index -= NUM_FORMAT1_NAMES; index -= format1_names_length;
if (index >= index_to_offset.length) if (index >= index_to_offset.length)
return hb_bytes_t (); return hb_bytes_t ();

View File

@ -37,6 +37,7 @@
#define HB_STRING_ARRAY_TYPE_NAME HB_PASTE(HB_STRING_ARRAY_NAME, _msgstr_t) #define HB_STRING_ARRAY_TYPE_NAME HB_PASTE(HB_STRING_ARRAY_NAME, _msgstr_t)
#define HB_STRING_ARRAY_POOL_NAME HB_PASTE(HB_STRING_ARRAY_NAME, _msgstr) #define HB_STRING_ARRAY_POOL_NAME HB_PASTE(HB_STRING_ARRAY_NAME, _msgstr)
#define HB_STRING_ARRAY_OFFS_NAME HB_PASTE(HB_STRING_ARRAY_NAME, _msgidx) #define HB_STRING_ARRAY_OFFS_NAME HB_PASTE(HB_STRING_ARRAY_NAME, _msgidx)
#define HB_STRING_ARRAY_LENG_NAME HB_PASTE(HB_STRING_ARRAY_NAME, _length)
static const union HB_STRING_ARRAY_TYPE_NAME { static const union HB_STRING_ARRAY_TYPE_NAME {
struct { struct {
@ -66,6 +67,8 @@ static const unsigned int HB_STRING_ARRAY_OFFS_NAME[] =
sizeof (HB_STRING_ARRAY_TYPE_NAME) sizeof (HB_STRING_ARRAY_TYPE_NAME)
}; };
static const unsigned int HB_STRING_ARRAY_LENG_NAME = ARRAY_LENGTH (HB_STRING_ARRAY_OFFS_NAME) - 1;
static inline hb_bytes_t static inline hb_bytes_t
HB_STRING_ARRAY_NAME (unsigned int i) HB_STRING_ARRAY_NAME (unsigned int i)
{ {