[post] Touch up and fixes

The get_glyph_from_name() is incorrect; needs fixing.
This commit is contained in:
Behdad Esfahbod 2017-10-25 17:40:50 -06:00
parent d9e166f74c
commit 543bd58d7a
2 changed files with 81 additions and 67 deletions

View File

@ -322,16 +322,13 @@ struct hb_ot_face_post_accelerator_t
inline bool get_glyph_name (hb_codepoint_t glyph,
char *name, unsigned int size) const
{
if (unlikely (!name) || unlikely(!size))
return false;
return this->post->get_glyph_name (glyph, name, size, this->post_len);
}
inline bool get_glyph_from_name (const char *name, int len,
hb_codepoint_t *glyph) const
{
if (unlikely (!name) || unlikely(!len))
if (unlikely (!len))
return false;
return this->post->get_glyph_from_name (name, len, glyph, this->post_len);

View File

@ -128,8 +128,10 @@ struct post
if (glyph >= NUM_FORMAT1_NAMES)
return false;
if (!buffer_length)
return true;
strncpy (buffer, format1_names[glyph], buffer_length);
buffer[buffer_length] = '\0';
buffer[buffer_length - 1] = '\0';
return true;
}
@ -140,19 +142,34 @@ struct post
if (glyph >= v2.numberOfGlyphs)
return false;
if (!buffer_length)
return true;
unsigned int index = v2.glyphNameIndex[glyph];
if (index >= NUM_FORMAT1_NAMES)
if (index < NUM_FORMAT1_NAMES)
{
if (!buffer_length)
return true;
strncpy (buffer, format1_names[index], buffer_length);
buffer[buffer_length - 1] = '\0';
return true;
}
index -= NUM_FORMAT1_NAMES;
unsigned int offset = min_size + v2.min_size + 2 * v2.numberOfGlyphs;
char* data = (char*) this + offset;
for (unsigned int i = 0; data < (char*) this + blob_len; i++)
unsigned char *data = (unsigned char *) this + offset;
unsigned char *end = (unsigned char *) this + blob_len;
for (unsigned int i = 0; data < end; i++)
{
unsigned int name_length = data[0];
data++;
if (i == index - NUM_FORMAT1_NAMES)
if (i == index)
{
unsigned int remaining = (char*) this + blob_len - data;
name_length = MIN (name_length, buffer_length);
if (unlikely (!name_length))
return false;
unsigned int remaining = end - data;
name_length = MIN (name_length, buffer_length - 1);
name_length = MIN (name_length, remaining);
memcpy (buffer, data, name_length);
buffer[name_length] = '\0';
@ -160,15 +177,9 @@ struct post
}
data += name_length;
}
return false;
}
else
{
strncpy(buffer, format1_names[index], buffer_length);
buffer[buffer_length] = '\0';
return true;
}
}
return false;
}
@ -184,7 +195,7 @@ struct post
{
for (int i = 0; i < NUM_FORMAT1_NAMES; i++)
{
if (strncmp (name, format1_names[i], len) == 0)
if (strncmp (name, format1_names[i], len) == 0 && format1_names[len] == '\0')
{
*glyph = i;
return true;
@ -199,17 +210,29 @@ struct post
unsigned int offset = min_size + v2.min_size + 2 * v2.numberOfGlyphs;
char* data = (char*) this + offset;
/* XXX The following code is wrong. */
return false;
for (hb_codepoint_t gid = 0; gid < v2.numberOfGlyphs; gid++)
{
unsigned int index = v2.glyphNameIndex[gid];
if (index >= NUM_FORMAT1_NAMES)
if (index < NUM_FORMAT1_NAMES)
{
if (strncmp (name, format1_names[index], len) == 0 && format1_names[len] == '\0')
{
*glyph = gid;
return true;
}
continue;
}
index -= NUM_FORMAT1_NAMES;
for (unsigned int i = 0; data < (char*) this + blob_len; i++)
{
unsigned int name_length = data[0];
unsigned int remaining = (char*) this + blob_len - data - 1;
name_length = MIN (name_length, remaining);
if (name_length == len && strncmp (name, data + 1, len) == 0)
if (name_length == (unsigned int) len && strncmp (name, data + 1, len) == 0)
{
*glyph = gid;
return true;
@ -218,12 +241,6 @@ struct post
}
return false;
}
else if (strncmp (name, format1_names[index], len) == 0)
{
*glyph = gid;
return true;
}
}
return false;
}