Add hb_shape_list_shapers()
This commit is contained in:
parent
d7bf473ef2
commit
9da554504e
|
@ -66,8 +66,16 @@ static struct static_shaper_list_t
|
|||
{
|
||||
char *env = getenv ("HB_SHAPER_LIST");
|
||||
shaper_list = NULL;
|
||||
if (!env || !*env)
|
||||
if (!env || !*env) {
|
||||
fallback:
|
||||
ASSERT_STATIC ((ARRAY_LENGTH (shapers) + 1) * sizeof (*shaper_list) <= sizeof (static_buffer));
|
||||
shaper_list = (const char **) static_buffer;
|
||||
unsigned int i;
|
||||
for (i = 0; i < ARRAY_LENGTH (shapers); i++)
|
||||
shaper_list[i] = shapers[i].name;
|
||||
shaper_list[i] = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int count = 3; /* initial, fallback, null */
|
||||
for (const char *p = env; (p == strchr (p, ',')) && p++; )
|
||||
|
@ -76,7 +84,7 @@ static struct static_shaper_list_t
|
|||
unsigned int len = strlen (env);
|
||||
|
||||
if (count > 100 || len > 1000)
|
||||
return;
|
||||
goto fallback;
|
||||
|
||||
len += count * sizeof (*shaper_list) + 1;
|
||||
char *buffer = len < sizeof (static_buffer) ? static_buffer : (char *) malloc (len);
|
||||
|
@ -100,7 +108,13 @@ static struct static_shaper_list_t
|
|||
|
||||
const char **shaper_list;
|
||||
char static_buffer[32];
|
||||
} env_shaper_list;
|
||||
} static_shaper_list;
|
||||
|
||||
const char **
|
||||
hb_shape_list_shapers (void)
|
||||
{
|
||||
return static_shaper_list.shaper_list;
|
||||
}
|
||||
|
||||
hb_bool_t
|
||||
hb_shape_full (hb_font_t *font,
|
||||
|
@ -111,7 +125,7 @@ hb_shape_full (hb_font_t *font,
|
|||
const char **shaper_list)
|
||||
{
|
||||
if (likely (!shaper_list))
|
||||
shaper_list = env_shaper_list.shaper_list;
|
||||
shaper_list = static_shaper_list.shaper_list;
|
||||
|
||||
if (likely (!shaper_list)) {
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH (shapers); i++)
|
||||
|
|
|
@ -56,6 +56,9 @@ hb_shape_full (hb_font_t *font,
|
|||
const char *shaper_options,
|
||||
const char **shaper_list);
|
||||
|
||||
const char **
|
||||
hb_shape_list_shapers (void);
|
||||
|
||||
|
||||
HB_END_DECLS
|
||||
|
||||
|
|
|
@ -25,9 +25,11 @@ TEST_PROGS = \
|
|||
test-version \
|
||||
$(NULL)
|
||||
|
||||
if HAVE_OT
|
||||
TEST_PROGS += \
|
||||
test-ot-tag \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
# Tests for header compilation
|
||||
TEST_PROGS += \
|
||||
|
|
|
@ -43,6 +43,14 @@
|
|||
#include <hb-ft.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_OT
|
||||
#include <hb-ot.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_UNISCRIBE
|
||||
#include <hb-uniscribe.h>
|
||||
#endif
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
|
|
|
@ -138,6 +138,18 @@ test_shape (void)
|
|||
hb_font_destroy (font);
|
||||
}
|
||||
|
||||
static void
|
||||
test_shape_list (void)
|
||||
{
|
||||
const char **shapers = hb_shape_list_shapers ();
|
||||
|
||||
unsigned int i;
|
||||
for (i = 0; shapers[i]; i++)
|
||||
;
|
||||
|
||||
g_assert_cmpint (i, >, 1);
|
||||
g_assert (!strcmp (shapers[i - 1], "fallback"));
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
|
@ -145,6 +157,9 @@ main (int argc, char **argv)
|
|||
hb_test_init (&argc, &argv);
|
||||
|
||||
hb_test_add (test_shape);
|
||||
/* TODO test fallback shaper */
|
||||
/* TODO test shaper_full */
|
||||
hb_test_add (test_shape_list);
|
||||
|
||||
return hb_test_run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue