[ot-glyph] minor on tests

This commit is contained in:
Ebrahim Byagowi 2020-01-13 17:35:57 +03:30
parent 42f4f1ea50
commit d7c3cb18ee
3 changed files with 77 additions and 45 deletions

View File

@ -39,39 +39,35 @@ struct user_data_t
};
static void
move_to (hb_position_t to_x, hb_position_t to_y, void *user_data)
move_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
{
user_data_t u = *((user_data_t *) user_data);
fprintf (u.f, "M%d,%d", to_x, u.ascender - to_y);
fprintf (user_data.f, "M%d,%d", to_x, user_data.ascender - to_y);
}
static void
line_to (hb_position_t to_x, hb_position_t to_y, void *user_data)
line_to (hb_position_t to_x, hb_position_t to_y, user_data_t &user_data)
{
user_data_t u = *((user_data_t *) user_data);
fprintf (u.f, "L%d,%d", to_x, u.ascender - to_y);
fprintf (user_data.f, "L%d,%d", to_x, user_data.ascender - to_y);
}
static void
conic_to (hb_position_t control_x, hb_position_t control_y,
hb_position_t to_x, hb_position_t to_y,
void *user_data)
user_data_t &user_data)
{
user_data_t u = *((user_data_t *) user_data);
fprintf (u.f, "Q%d,%d %d,%d", control_x, u.ascender - control_y,
to_x, u.ascender - to_y);
fprintf (user_data.f, "Q%d,%d %d,%d", control_x, user_data.ascender - control_y,
to_x, user_data.ascender - to_y);
}
static void
cubic_to (hb_position_t control1_x, hb_position_t control1_y,
hb_position_t control2_x, hb_position_t control2_y,
hb_position_t to_x, hb_position_t to_y,
void *user_data)
user_data_t &user_data)
{
user_data_t u = *((user_data_t *) user_data);
fprintf (u.f, "C%d,%d %d,%d %d,%d", control1_x, u.ascender - control1_y,
control2_x, u.ascender - control2_y,
to_x, u.ascender - to_y);
fprintf (user_data.f, "C%d,%d %d,%d %d,%d", control1_x, user_data.ascender - control1_y,
control2_x, user_data.ascender - control2_y,
to_x, user_data.ascender - to_y);
}
int
@ -109,7 +105,7 @@ main (int argc, char **argv)
hb_glyph_extents_t extents = {0};
if (!hb_font_get_glyph_extents (font, gid, &extents))
{
printf ("Skip gid: %d\n", gid);
printf ("Skip gid: %d\n", gid);
continue;
}

View File

@ -25,17 +25,18 @@
*/
#ifndef TEST_OT_FACE_NO_MAIN
#include "hb-test.h"
# include "hb-test.h"
#else
# if defined(__GNUC__) && (__GNUC__ >= 4) || (__clang__)
# define HB_UNUSED __attribute__((unused))
# else
# define HB_UNUSED
# endif
#endif
#include <hb-ot.h>
/* Unit tests for hb-ot-*.h */
#if defined(__GNUC__) && (__GNUC__ >= 4) || (__clang__)
#define HB_UNUSED __attribute__((unused))
#else
#define HB_UNUSED
#endif
static void
move_to (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {}

View File

@ -26,42 +26,52 @@
#include <hb-ot.h>
typedef struct user_data_t {
char *str;
unsigned size;
unsigned consumed;
} user_data_t;
static void
move_to (hb_position_t to_x, hb_position_t to_y, void *user_data)
move_to (hb_position_t to_x, hb_position_t to_y, user_data_t *user_data)
{
char *str = (char *) user_data;
sprintf (str+strlen (str), "M%d,%d", to_x, to_y);
user_data->consumed += snprintf (user_data->str + user_data->consumed,
user_data->size - user_data->consumed,
"M%d,%d", to_x, to_y);
}
static void
line_to (hb_position_t to_x, hb_position_t to_y, void *user_data)
line_to (hb_position_t to_x, hb_position_t to_y, user_data_t *user_data)
{
char *str = (char *) user_data;
sprintf (str+strlen (str), "L%d,%d", to_x, to_y);
user_data->consumed += snprintf (user_data->str + user_data->consumed,
user_data->size - user_data->consumed,
"L%d,%d", to_x, to_y);
}
static void
conic_to (hb_position_t control_x, hb_position_t control_y,
hb_position_t to_x, hb_position_t to_y,
void *user_data)
user_data_t *user_data)
{
char *str = (char *) user_data;
sprintf (str+strlen (str), "Q%d,%d %d,%d",
control_x, control_y,
to_x, to_y);
user_data->consumed += snprintf (user_data->str + user_data->consumed,
user_data->size - user_data->consumed,
"Q%d,%d %d,%d",
control_x, control_y,
to_x, to_y);
}
static void
cubic_to (hb_position_t control1_x, hb_position_t control1_y,
hb_position_t control2_x, hb_position_t control2_y,
hb_position_t to_x, hb_position_t to_y,
void *user_data)
user_data_t *user_data)
{
char *str = (char *) user_data;
sprintf (str+strlen (str), "C%d,%d %d,%d %d,%d",
control1_x, control1_y,
control2_x, control2_y,
to_x, to_y);
user_data->consumed += snprintf (user_data->str + user_data->consumed,
user_data->size - user_data->consumed,
"C%d,%d %d,%d %d,%d",
control1_x, control1_y,
control2_x, control2_y,
to_x, to_y);
}
static void
@ -90,8 +100,13 @@ test_hb_ot_glyph_glyf (void)
hb_face_destroy (face);
char str[1024] = {0};
g_assert (!hb_ot_glyph_decompose (font, 4, &funcs, str));
g_assert (hb_ot_glyph_decompose (font, 3, &funcs, str));
user_data_t user_data = {
.str = str,
.size = sizeof (str),
.consumed = 0
};
g_assert (!hb_ot_glyph_decompose (font, 4, &funcs, &user_data));
g_assert (hb_ot_glyph_decompose (font, 3, &funcs, &user_data));
char expected[] = "M275,442L275,442Q232,442 198,420Q164,397 145,353Q126,309 126,245L126,245"
"Q126,182 147,139Q167,95 204,73Q240,50 287,50L287,50Q330,50 367,70Q404,90 427,128L427,128L451,116"
"Q431,54 384,21Q336,-13 266,-13L266,-13Q198,-13 148,18Q97,48 70,104Q43,160 43,236L43,236Q43,314 76,371"
@ -106,7 +121,12 @@ test_hb_ot_glyph_glyf (void)
hb_font_set_variations (font, &var, 1);
char str2[1024] = {0};
g_assert (hb_ot_glyph_decompose (font, 3, &funcs, str2));
user_data_t user_data2 = {
.str = str2,
.size = sizeof (str2),
.consumed = 0
};
g_assert (hb_ot_glyph_decompose (font, 3, &funcs, &user_data2));
char expected2[] = "M323,448L323,448Q297,448 271,430Q244,412 227,371Q209,330 209,261L209,261Q209,204 226,166"
"Q242,127 273,107Q303,86 344,86L344,86Q378,86 404,101Q430,115 451,137L451,137L488,103"
"Q458,42 404,13Q350,-16 279,-16L279,-16Q211,-16 153,13Q95,41 60,99Q25,156 25,241L25,241"
@ -132,7 +152,12 @@ test_hb_ot_glyph_cff1 (void)
hb_face_destroy (face);
char str[1024] = {0};
g_assert (hb_ot_glyph_decompose (font, 3, &funcs, str));
user_data_t user_data = {
.str = str,
.size = sizeof (str),
.consumed = 0
};
g_assert (hb_ot_glyph_decompose (font, 3, &funcs, &user_data));
char expected[] = "M203,367C227,440 248,512 268,588L272,588C293,512 314,440 338,367"
"L369,267L172,267M3,0L88,0L151,200L390,200L452,0L541,0L319,656L225,656"
"M300,653L342,694L201,861L143,806";
@ -155,7 +180,12 @@ test_hb_ot_glyph_cff2 (void)
hb_face_destroy (face);
char str[1024] = {0};
g_assert (hb_ot_glyph_decompose (font, 3, &funcs, str));
user_data_t user_data = {
.str = str,
.size = sizeof (str),
.consumed = 0
};
g_assert (hb_ot_glyph_decompose (font, 3, &funcs, &user_data));
char expected[] = "M275,442C303,442 337,435 371,417L325,454L350,366C357,341 370,321 403,321"
"C428,321 443,333 448,358C435,432 361,487 272,487C153,487 43,393 43,236"
"C43,83 129,-13 266,-13C360,-13 424,33 451,116L427,128C396,78 345,50 287,50"
@ -168,7 +198,12 @@ test_hb_ot_glyph_cff2 (void)
hb_font_set_variations (font, &var, 1);
char str2[1024] = {0};
g_assert (hb_ot_glyph_decompose (font, 3, &funcs, str2));
user_data_t user_data2 = {
.str = str2,
.size = sizeof (str2),
.consumed = 0
};
g_assert (hb_ot_glyph_decompose (font, 3, &funcs, &user_data2));
char expected2[] = "M323,448C356,448 380,441 411,427L333,469L339,401C343,322 379,297 420,297"
"C458,297 480,314 492,352C486,433 412,501 303,501C148,501 25,406 25,241"
"C25,70 143,-16 279,-16C374,-16 447,22 488,103L451,137C423,107 390,86 344,86"