提交 e1a37f3d 编写于 作者: B Behdad Esfahbod

Add hb_string_t

上级 21ac5678
......@@ -110,48 +110,39 @@ struct post
index_to_offset.finish ();
}
struct str_t
{
inline str_t (void) : bytes (nullptr), len (0) {}
inline str_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {}
const char *bytes;
unsigned int len;
};
inline str_t _find_glyph_name (hb_codepoint_t glyph) const
inline hb_string_t _find_glyph_name (hb_codepoint_t glyph) const
{
if (version == 0x00010000)
{
if (glyph >= NUM_FORMAT1_NAMES)
return str_t ();
return hb_string_t ();
return str_t (format1_names (glyph), strlen (format1_names (glyph)));
return hb_string_t (format1_names (glyph), strlen (format1_names (glyph)));
}
if (version != 0x00020000 || glyph >= glyphNameIndex->len)
return str_t ();
return hb_string_t ();
unsigned int index = glyphNameIndex->array[glyph];
if (index < NUM_FORMAT1_NAMES)
return str_t (format1_names (index), strlen (format1_names (index)));
return hb_string_t (format1_names (index), strlen (format1_names (index)));
index -= NUM_FORMAT1_NAMES;
if (index >= index_to_offset.len)
return str_t ();
return hb_string_t ();
unsigned int offset = index_to_offset.array[index];
const uint8_t *data = pool + offset;
unsigned int name_length = *data;
data++;
return str_t ((const char *) data, name_length);
return hb_string_t ((const char *) data, name_length);
}
inline bool get_glyph_name (hb_codepoint_t glyph,
char *buf, unsigned int buf_len) const
{
str_t s = _find_glyph_name (glyph);
hb_string_t s = _find_glyph_name (glyph);
if (!s.len)
return false;
if (!buf_len)
......
......@@ -1137,4 +1137,31 @@ hb_options (void)
/* Size signifying variable-sized array */
#define VAR 1
/* String type. */
struct hb_string_t
{
inline hb_string_t (void) : bytes (nullptr), len (0) {}
inline hb_string_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {}
inline int cmp (const hb_string_t *a) const
{
if (len != a->len)
return (int) a->len - (int) len;
return memcmp (a->bytes, bytes, len);
}
static inline int cmp (const void *pa, const void *pb)
{
hb_string_t *a = (hb_string_t *) pa;
hb_string_t *b = (hb_string_t *) pb;
return b->cmp (a);
}
const char *bytes;
unsigned int len;
};
#endif /* HB_PRIVATE_HH */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册