[subset] sketch out support for a call that lists all codepoints present in a font. Implement support for it in format 4 cmap sub table.
This commit is contained in:
parent
aef96e246c
commit
21a181af2b
|
@ -127,6 +127,13 @@ struct CmapSubtableFormat4
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void get_all_codepoints_func (const void *obj, hb_set_t *out)
|
||||||
|
{
|
||||||
|
const accelerator_t *thiz = (const accelerator_t *) obj;
|
||||||
|
for (unsigned int i = 0; i < thiz->segCount - 1; i++) // Skip the last segment (0xFFFF)
|
||||||
|
hb_set_add_range (out, thiz->startCount[i], thiz->endCount[i]);
|
||||||
|
}
|
||||||
|
|
||||||
const HBUINT16 *endCount;
|
const HBUINT16 *endCount;
|
||||||
const HBUINT16 *startCount;
|
const HBUINT16 *startCount;
|
||||||
const HBUINT16 *idDelta;
|
const HBUINT16 *idDelta;
|
||||||
|
@ -667,21 +674,31 @@ struct cmap
|
||||||
|
|
||||||
this->get_glyph_data = subtable;
|
this->get_glyph_data = subtable;
|
||||||
if (unlikely (symbol))
|
if (unlikely (symbol))
|
||||||
|
{
|
||||||
this->get_glyph_func = get_glyph_from_symbol<OT::CmapSubtable>;
|
this->get_glyph_func = get_glyph_from_symbol<OT::CmapSubtable>;
|
||||||
else
|
this->get_all_codepoints_func = null_get_all_codepoints_func;
|
||||||
|
} else {
|
||||||
switch (subtable->u.format) {
|
switch (subtable->u.format) {
|
||||||
/* Accelerate format 4 and format 12. */
|
/* Accelerate format 4 and format 12. */
|
||||||
default: this->get_glyph_func = get_glyph_from<OT::CmapSubtable>; break;
|
default:
|
||||||
case 12: this->get_glyph_func = get_glyph_from<OT::CmapSubtableFormat12>; break;
|
this->get_glyph_func = get_glyph_from<OT::CmapSubtable>;
|
||||||
|
this->get_all_codepoints_func = null_get_all_codepoints_func;
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
this->get_glyph_func = get_glyph_from<OT::CmapSubtableFormat12>;
|
||||||
|
this->get_all_codepoints_func = null_get_all_codepoints_func;
|
||||||
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
this->format4_accel.init (&subtable->u.format4);
|
this->format4_accel.init (&subtable->u.format4);
|
||||||
this->get_glyph_data = &this->format4_accel;
|
this->get_glyph_data = &this->format4_accel;
|
||||||
this->get_glyph_func = this->format4_accel.get_glyph_func;
|
this->get_glyph_func = this->format4_accel.get_glyph_func;
|
||||||
|
this->get_all_codepoints_func = this->format4_accel.get_all_codepoints_func;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void fini (void)
|
inline void fini (void)
|
||||||
{
|
{
|
||||||
|
@ -710,10 +727,22 @@ struct cmap
|
||||||
return get_nominal_glyph (unicode, glyph);
|
return get_nominal_glyph (unicode, glyph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void get_all_codepoints (hb_set_t *out) const
|
||||||
|
{
|
||||||
|
this->get_all_codepoints_func (get_glyph_data, out);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef bool (*hb_cmap_get_glyph_func_t) (const void *obj,
|
typedef bool (*hb_cmap_get_glyph_func_t) (const void *obj,
|
||||||
hb_codepoint_t codepoint,
|
hb_codepoint_t codepoint,
|
||||||
hb_codepoint_t *glyph);
|
hb_codepoint_t *glyph);
|
||||||
|
typedef void (*hb_cmap_get_all_codepoints_func_t) (const void *obj,
|
||||||
|
hb_set_t *out);
|
||||||
|
|
||||||
|
static inline void null_get_all_codepoints_func (const void *obj, hb_set_t *out)
|
||||||
|
{
|
||||||
|
// NOOP
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
static inline bool get_glyph_from (const void *obj,
|
static inline bool get_glyph_from (const void *obj,
|
||||||
|
@ -749,6 +778,8 @@ struct cmap
|
||||||
private:
|
private:
|
||||||
hb_cmap_get_glyph_func_t get_glyph_func;
|
hb_cmap_get_glyph_func_t get_glyph_func;
|
||||||
const void *get_glyph_data;
|
const void *get_glyph_data;
|
||||||
|
hb_cmap_get_all_codepoints_func_t get_all_codepoints_func;
|
||||||
|
|
||||||
OT::CmapSubtableFormat4::accelerator_t format4_accel;
|
OT::CmapSubtableFormat4::accelerator_t format4_accel;
|
||||||
|
|
||||||
const OT::CmapSubtableFormat14 *uvs_table;
|
const OT::CmapSubtableFormat14 *uvs_table;
|
||||||
|
|
|
@ -371,3 +371,17 @@ hb_subset (hb_face_t *source,
|
||||||
hb_subset_plan_destroy (plan);
|
hb_subset_plan_destroy (plan);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hb_subset_get_all_codepoints:
|
||||||
|
* @source: font face data to load.
|
||||||
|
* @out: set to add the all codepoints covered by font face, source.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
hb_subset_get_all_codepoints (hb_face_t *source, hb_set_t *out)
|
||||||
|
{
|
||||||
|
OT::cmap::accelerator_t cmap;
|
||||||
|
cmap.init (source);
|
||||||
|
cmap.get_all_codepoints (out);
|
||||||
|
cmap.fini();
|
||||||
|
}
|
||||||
|
|
|
@ -72,12 +72,15 @@ HB_EXTERN hb_bool_t *
|
||||||
hb_subset_input_drop_hints (hb_subset_input_t *subset_input);
|
hb_subset_input_drop_hints (hb_subset_input_t *subset_input);
|
||||||
|
|
||||||
/* hb_subset() */
|
/* hb_subset() */
|
||||||
|
|
||||||
HB_EXTERN hb_face_t *
|
HB_EXTERN hb_face_t *
|
||||||
hb_subset (hb_face_t *source,
|
hb_subset (hb_face_t *source,
|
||||||
hb_subset_profile_t *profile,
|
hb_subset_profile_t *profile,
|
||||||
hb_subset_input_t *input);
|
hb_subset_input_t *input);
|
||||||
|
|
||||||
|
/* hb_subset_get_all_codepoints */
|
||||||
|
HB_EXTERN void
|
||||||
|
hb_subset_get_all_codepoints (hb_face_t *source, hb_set_t *out);
|
||||||
|
|
||||||
HB_END_DECLS
|
HB_END_DECLS
|
||||||
|
|
||||||
#endif /* HB_SUBSET_H */
|
#endif /* HB_SUBSET_H */
|
||||||
|
|
|
@ -32,6 +32,7 @@ TEST_PROGS = \
|
||||||
test-set \
|
test-set \
|
||||||
test-shape \
|
test-shape \
|
||||||
test-subset \
|
test-subset \
|
||||||
|
test-subset-codepoints \
|
||||||
test-subset-cmap \
|
test-subset-cmap \
|
||||||
test-subset-glyf \
|
test-subset-glyf \
|
||||||
test-subset-hdmx \
|
test-subset-hdmx \
|
||||||
|
@ -44,6 +45,7 @@ TEST_PROGS = \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
test_subset_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la
|
test_subset_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la
|
||||||
|
test_subset_codepoints_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la
|
||||||
test_subset_cmap_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la
|
test_subset_cmap_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la
|
||||||
test_subset_glyf_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la
|
test_subset_glyf_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la
|
||||||
test_subset_hdmx_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la
|
test_subset_hdmx_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2018 Google, Inc.
|
||||||
|
*
|
||||||
|
* This is part of HarfBuzz, a text shaping library.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, without written agreement and without
|
||||||
|
* license or royalty fees, to use, copy, modify, and distribute this
|
||||||
|
* software and its documentation for any purpose, provided that the
|
||||||
|
* above copyright notice and the following two paragraphs appear in
|
||||||
|
* all copies of this software.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
||||||
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
||||||
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
|
*
|
||||||
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||||
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
||||||
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*
|
||||||
|
* Google Author(s): Garret Rieger
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "hb-test.h"
|
||||||
|
#include "hb-subset-test.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_get_all_codepoints_format4 (void)
|
||||||
|
{
|
||||||
|
hb_face_t *face = hb_subset_test_open_font("fonts/Roboto-Regular.abc.format4.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_format4);
|
||||||
|
|
||||||
|
return hb_test_run();
|
||||||
|
}
|
Loading…
Reference in New Issue