[ot-font] Implement hb_ot_get_glyph_from_name
This commit is contained in:
parent
9d4d2fb9af
commit
d9e166f74c
@ -327,6 +327,15 @@ struct hb_ot_face_post_accelerator_t
|
||||
|
||||
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))
|
||||
return false;
|
||||
|
||||
return this->post->get_glyph_from_name (name, len, glyph, this->post_len);
|
||||
}
|
||||
};
|
||||
|
||||
typedef bool (*hb_cmap_get_glyph_func_t) (const void *obj,
|
||||
@ -577,6 +586,17 @@ hb_ot_get_glyph_name (hb_font_t *font HB_UNUSED,
|
||||
return ot_font->post->get_glyph_name (glyph, name, size);
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_ot_get_glyph_from_name (hb_font_t *font HB_UNUSED,
|
||||
void *font_data,
|
||||
const char *name, int len,
|
||||
hb_codepoint_t *glyph,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
|
||||
return ot_font->post->get_glyph_from_name (name, len, glyph);
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_ot_get_font_h_extents (hb_font_t *font HB_UNUSED,
|
||||
void *font_data,
|
||||
@ -638,7 +658,7 @@ retry:
|
||||
hb_font_funcs_set_glyph_extents_func (funcs, hb_ot_get_glyph_extents, nullptr, nullptr);
|
||||
//hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ot_get_glyph_contour_point, nullptr, nullptr); TODO
|
||||
hb_font_funcs_set_glyph_name_func (funcs, hb_ot_get_glyph_name, nullptr, nullptr);
|
||||
//hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name, nullptr, nullptr); TODO
|
||||
hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name, nullptr, nullptr);
|
||||
|
||||
hb_font_funcs_make_immutable (funcs);
|
||||
|
||||
|
@ -173,6 +173,64 @@ struct post
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool get_glyph_from_name (const char *name, int len,
|
||||
hb_codepoint_t *glyph,
|
||||
unsigned int blob_len) const
|
||||
{
|
||||
if (len < 0)
|
||||
len = strlen (name);
|
||||
|
||||
if (version.to_int () == 0x00010000)
|
||||
{
|
||||
for (int i = 0; i < NUM_FORMAT1_NAMES; i++)
|
||||
{
|
||||
if (strncmp (name, format1_names[i], len) == 0)
|
||||
{
|
||||
*glyph = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (version.to_int () == 0x00020000)
|
||||
{
|
||||
const postV2Tail &v2 = StructAfter<postV2Tail>(*this);
|
||||
unsigned int offset = min_size + v2.min_size + 2 * v2.numberOfGlyphs;
|
||||
char* data = (char*) this + offset;
|
||||
|
||||
for (hb_codepoint_t gid = 0; gid < v2.numberOfGlyphs; gid++)
|
||||
{
|
||||
unsigned int index = v2.glyphNameIndex[gid];
|
||||
if (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)
|
||||
{
|
||||
*glyph = gid;
|
||||
return true;
|
||||
}
|
||||
data += name_length + 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (strncmp (name, format1_names[index], len) == 0)
|
||||
{
|
||||
*glyph = gid;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
FixedVersion<>version; /* 0x00010000 for version 1.0
|
||||
* 0x00020000 for version 2.0
|
||||
|
Loading…
Reference in New Issue
Block a user