提交 5dadbb0f 编写于 作者: G Garret Rieger 提交者: Behdad Esfahbod

[subset] Add implementation of cmap format 12 codepoint listing. (#988)

上级 6771e79b
......@@ -204,6 +204,8 @@ struct CmapSubtableLongGroup
{
friend struct CmapSubtableFormat12;
friend struct CmapSubtableFormat13;
template<typename U>
friend struct CmapSubtableLongSegmented;
friend struct cmap;
int cmp (hb_codepoint_t codepoint) const
......@@ -276,6 +278,15 @@ struct CmapSubtableLongSegmented
return true;
}
inline void get_all_codepoints (hb_set_t *out) const
{
for (unsigned int i = 0; i < this->groups.len; i++) {
hb_set_add_range (out,
this->groups[i].startCharCode,
this->groups[i].endCharCode);
}
}
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
......@@ -690,7 +701,7 @@ struct cmap
break;
case 12:
this->get_glyph_func = get_glyph_from<OT::CmapSubtableFormat12>;
this->get_all_codepoints_func = null_get_all_codepoints_func;
this->get_all_codepoints_func = get_all_codepoints_from<OT::CmapSubtableFormat12>;
break;
case 4:
{
......@@ -757,6 +768,14 @@ struct cmap
return typed_obj->get_glyph (codepoint, glyph);
}
template <typename Type>
static inline void get_all_codepoints_from (const void *obj,
hb_set_t *out)
{
const Type *typed_obj = (const Type *) obj;
typed_obj->get_all_codepoints (out);
}
template <typename Type>
static inline bool get_glyph_from_symbol (const void *obj,
hb_codepoint_t codepoint,
......
......@@ -48,12 +48,56 @@ test_get_all_codepoints_format4 (void)
hb_face_destroy (face);
}
static void
test_get_all_codepoints_format12 (void)
{
hb_face_t *face = hb_subset_test_open_font("fonts/Roboto-Regular.abc.format12.ttf");
hb_set_t *codepoints = hb_set_create();
hb_subset_get_all_codepoints (face, codepoints);
hb_codepoint_t cp = HB_SET_VALUE_INVALID;
g_assert (hb_set_next (codepoints, &cp));
g_assert_cmpuint (0x61, ==, cp);
g_assert (hb_set_next (codepoints, &cp));
g_assert_cmpuint (0x62, ==, cp);
g_assert (hb_set_next (codepoints, &cp));
g_assert_cmpuint (0x63, ==, cp);
g_assert (!hb_set_next (codepoints, &cp));
hb_set_destroy (codepoints);
hb_face_destroy (face);
}
static void
test_get_all_codepoints (void)
{
hb_face_t *face = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf");
hb_set_t *codepoints = hb_set_create();
hb_subset_get_all_codepoints (face, codepoints);
hb_codepoint_t cp = HB_SET_VALUE_INVALID;
g_assert (hb_set_next (codepoints, &cp));
g_assert_cmpuint (0x61, ==, cp);
g_assert (hb_set_next (codepoints, &cp));
g_assert_cmpuint (0x62, ==, cp);
g_assert (hb_set_next (codepoints, &cp));
g_assert_cmpuint (0x63, ==, cp);
g_assert (!hb_set_next (codepoints, &cp));
hb_set_destroy (codepoints);
hb_face_destroy (face);
}
int
main (int argc, char **argv)
{
hb_test_init (&argc, &argv);
hb_test_add (test_get_all_codepoints);
hb_test_add (test_get_all_codepoints_format4);
hb_test_add (test_get_all_codepoints_format12);
return hb_test_run();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册