[ot-glyph] Add fontkits's variations toSVG tests

This commit is contained in:
Ebrahim Byagowi 2020-01-26 17:02:11 +03:30
parent e44982f548
commit 99f8e52d5e
6 changed files with 244 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -229,12 +229,12 @@ test_hb_ot_glyph_cff2 (void)
static void static void
test_hb_ot_glyph_ttf_parser_tests (void) test_hb_ot_glyph_ttf_parser_tests (void)
{ {
/* https://github.com/RazrFalcon/ttf-parser/blob/337e7d1c/tests/tests.rs#L50-L133 */
char str[1024] = {0}; char str[1024] = {0};
user_data_t user_data = { user_data_t user_data = {
.str = str, .str = str,
.size = sizeof (str) .size = sizeof (str)
}; };
/* https://github.com/RazrFalcon/ttf-parser/blob/337e7d1c/tests/tests.rs#L50-L133 */
{ {
hb_face_t *face = hb_test_open_font_file ("fonts/glyphs.ttf"); hb_face_t *face = hb_test_open_font_file ("fonts/glyphs.ttf");
hb_font_t *font = hb_font_create (face); hb_font_t *font = hb_font_create (face);
@ -269,7 +269,6 @@ test_hb_ot_glyph_ttf_parser_tests (void)
user_data.consumed = 0; user_data.consumed = 0;
g_assert (hb_ot_glyph_decompose (font, 5, funcs, &user_data)); g_assert (hb_ot_glyph_decompose (font, 5, funcs, &user_data));
char expected[] = "M15,0Q15,0 15,0Z"; char expected[] = "M15,0Q15,0 15,0Z";
printf ("%s", str);
g_assert_cmpmem (str, user_data.consumed, expected, sizeof (expected) - 1); g_assert_cmpmem (str, user_data.consumed, expected, sizeof (expected) - 1);
} }
{ {
@ -317,6 +316,248 @@ test_hb_ot_glyph_ttf_parser_tests (void)
} }
} }
/* TODO: https://github.com/foliojs/fontkit/blob/master/test/glyphs.js */
static void
test_hb_ot_glyph_font_kit_variations_tests (void)
{
/* https://github.com/foliojs/fontkit/blob/b310db5/test/variations.js */
char str[4096] = {0};
user_data_t user_data = {
.str = str,
.size = sizeof (str)
};
/* Skia */
{
/* Skipping Skia tests for now even the fact we can actually do platform specific tests using our CIs */
}
/* truetype variations */
/* should support sharing all points */
{
hb_face_t *face = hb_test_open_font_file ("fonts/TestGVAROne.ttf");
hb_font_t *font = hb_font_create (face);
hb_face_destroy (face);
hb_variation_t var;
var.tag = HB_TAG ('w','g','h','t');
var.value = 300;
hb_font_set_variations (font, &var, 1);
hb_buffer_t *buffer = hb_buffer_create ();
hb_codepoint_t codepoint = 24396; /* 彌 */
hb_buffer_add_codepoints (buffer, &codepoint, 1, 0, -1);
hb_buffer_set_direction (buffer, HB_DIRECTION_LTR);
hb_shape (font, buffer, NULL, 0);
codepoint = hb_buffer_get_glyph_infos (buffer, NULL)[0].codepoint;
hb_buffer_destroy (buffer);
user_data.consumed = 0;
g_assert (hb_ot_glyph_decompose (font, codepoint, funcs, &user_data));
char expected[] = "M414,-102L371,-102L371,539L914,539L914,-27Q914,-102 840,-102L840,-102Q796,-102 755,-98"
"L755,-98L742,-59Q790,-66 836,-66L836,-66Q871,-66 871,-31L871,-31L871,504L414,504L414,-102Z"
"M203,-94L203,-94Q138,-94 86,-90L86,-90L74,-52Q137,-59 188,-59L188,-59Q211,-59 222,-47"
"Q233,-34 236,12Q238,58 240,135Q242,211 242,262L242,262L74,262L94,527L242,527L242,719"
"L63,719L63,754L285,754L285,492L133,492L117,297L285,297Q285,241 284,185L284,185"
"Q284,104 281,46L281,46Q278,-20 269,-49Q260,-78 242,-86Q223,-94 203,-94ZM461,12L461,12"
"L434,43Q473,73 503,115L503,115Q478,150 441,188L441,188L469,211Q501,179 525,147"
"L525,147Q538,172 559,230L559,230L594,211Q571,152 551,117L551,117Q577,84 602,43L602,43"
"L566,20Q544,64 528,86L528,86Q500,44 461,12ZM465,258L465,258L438,285Q474,316 501,351L501,351"
"Q474,388 445,418L445,418L473,441Q500,414 523,381L523,381Q546,413 563,453L563,453"
"L598,434Q571,382 549,352L549,352Q576,320 598,285L598,285L563,262Q546,294 525,322"
"L525,322Q491,280 465,258ZM707,12L707,12L680,43Q717,68 753,115L753,115Q731,147 691,188"
"L691,188L719,211Q739,190 754,172Q769,154 774,147L774,147Q793,185 809,230L809,230"
"L844,211Q822,155 801,117L801,117Q828,82 852,43L852,43L820,20Q798,58 778,87"
"L778,87Q747,43 707,12ZM664,-94L621,-94L621,730L664,730L664,-94ZM348,570L348,570"
"L324,605Q425,629 527,688L527,688L555,656Q491,621 439,601Q386,581 348,570ZM715,258"
"L715,258L688,285Q727,318 753,351L753,351Q733,378 695,418L695,418L723,441Q754,410 775,381"
"L775,381Q794,407 813,453L813,453L848,434Q826,387 801,352L801,352Q823,321 848,281"
"L848,281L813,262Q791,301 775,323L775,323Q749,288 715,258ZM941,719L348,719L348,754"
"L941,754L941,719ZM957,605L936,570Q870,602 817,622Q764,641 727,652L727,652L749,688"
"Q852,655 957,605L957,605Z";
g_assert_cmpmem (str, user_data.consumed, expected, sizeof (expected) - 1);
hb_font_destroy (font);
}
/* should support sharing enumerated points */
{
hb_face_t *face = hb_test_open_font_file ("fonts/TestGVARTwo.ttf");
hb_font_t *font = hb_font_create (face);
hb_face_destroy (face);
hb_variation_t var;
var.tag = HB_TAG ('w','g','h','t');
var.value = 300;
hb_font_set_variations (font, &var, 1);
hb_buffer_t *buffer = hb_buffer_create ();
hb_codepoint_t codepoint = 24396; /* 彌 */
hb_buffer_add_codepoints (buffer, &codepoint, 1, 0, -1);
hb_buffer_set_direction (buffer, HB_DIRECTION_LTR);
hb_shape (font, buffer, NULL, 0);
codepoint = hb_buffer_get_glyph_infos (buffer, NULL)[0].codepoint;
hb_buffer_destroy (buffer);
user_data.consumed = 0;
g_assert (hb_ot_glyph_decompose (font, codepoint, funcs, &user_data));
char expected[] = "M414,-102L371,-102L371,539L914,539L914,-27Q914,-102 840,-102L840,-102Q796,-102 755,-98"
"L755,-98L742,-59Q790,-66 836,-66L836,-66Q871,-66 871,-31L871,-31L871,504L414,504"
"L414,-102ZM203,-94L203,-94Q138,-94 86,-90L86,-90L74,-52Q137,-59 188,-59L188,-59"
"Q211,-59 222,-47Q233,-34 236,12Q238,58 240,135Q242,211 242,262L242,262L74,262"
"L94,527L242,527L242,719L63,719L63,754L285,754L285,492L133,492L117,297"
"L285,297Q285,241 284,185L284,185Q284,104 281,46L281,46Q278,-20 269,-49Q260,-78 242,-86"
"Q223,-94 203,-94ZM461,12L461,12L434,43Q473,73 503,115L503,115Q478,150 441,188L441,188"
"L469,211Q501,179 525,147L525,147Q538,172 559,230L559,230L594,211Q571,152 551,117"
"L551,117Q577,84 602,43L602,43L566,20Q544,64 528,86L528,86Q500,44 461,12ZM465,258"
"L465,258L438,285Q474,316 501,351L501,351Q474,388 445,418L445,418L473,441"
"Q500,414 523,381L523,381Q546,413 563,453L563,453L598,434Q571,382 549,352L549,352"
"Q576,320 598,285L598,285L563,262Q546,294 525,322L525,322Q491,280 465,258ZM707,12"
"L707,12L680,43Q717,68 753,115L753,115Q731,147 691,188L691,188L719,211Q739,190 754,172"
"Q769,154 774,147L774,147Q793,185 809,230L809,230L844,211Q822,155 801,117L801,117"
"Q828,82 852,43L852,43L820,20Q798,58 778,87L778,87Q747,43 707,12ZM664,-94L621,-94L621,730"
"L664,730L664,-94ZM348,570L348,570L324,605Q425,629 527,688L527,688L555,656Q491,621 439,601"
"Q386,581 348,570ZM715,258L715,258L688,285Q727,318 753,351L753,351Q733,378 695,418"
"L695,418L723,441Q754,410 775,381L775,381Q794,407 813,453L813,453L848,434Q826,387 801,352"
"L801,352Q823,321 848,281L848,281L813,262Q791,301 775,323L775,323Q749,288 715,258ZM941,719"
"L348,719L348,754L941,754L941,719ZM957,605L936,570Q870,602 817,622Q764,641 727,652L727,652"
"L749,688Q852,655 957,605L957,605Z";
g_assert_cmpmem (str, user_data.consumed, expected, sizeof (expected) - 1);
hb_font_destroy (font);
}
/* should support sharing no points */
{
hb_face_t *face = hb_test_open_font_file ("fonts/TestGVARThree.ttf");
hb_font_t *font = hb_font_create (face);
hb_face_destroy (face);
hb_variation_t var;
var.tag = HB_TAG ('w','g','h','t');
var.value = 300;
hb_font_set_variations (font, &var, 1);
hb_buffer_t *buffer = hb_buffer_create ();
hb_codepoint_t codepoint = 24396; /* 彌 */
hb_buffer_add_codepoints (buffer, &codepoint, 1, 0, -1);
hb_buffer_set_direction (buffer, HB_DIRECTION_LTR);
hb_shape (font, buffer, NULL, 0);
codepoint = hb_buffer_get_glyph_infos (buffer, NULL)[0].codepoint;
hb_buffer_destroy (buffer);
user_data.consumed = 0;
g_assert (hb_ot_glyph_decompose (font, codepoint, funcs, &user_data));
char expected[] = "M414,-102L371,-102L371,539L914,539L914,-27Q914,-102 840,-102L840,-102"
"Q796,-102 755,-98L755,-98L742,-59Q790,-66 836,-66L836,-66Q871,-66 871,-31"
"L871,-31L871,504L414,504L414,-102ZM203,-94L203,-94Q138,-94 86,-90"
"L86,-90L74,-52Q137,-59 188,-59L188,-59Q211,-59 222,-47Q233,-34 236,12"
"Q238,58 240,135Q242,211 242,262L242,262L74,262L94,527L242,527L242,719"
"L63,719L63,754L285,754L285,492L133,492L117,297L285,297Q285,241 284,185"
"L284,185Q284,104 281,46L281,46Q278,-20 269,-49Q260,-78 242,-86Q223,-94 203,-94Z"
"M461,12L461,12L434,43Q473,73 503,115L503,115Q478,150 441,188L441,188L469,211"
"Q501,179 525,147L525,147Q538,172 559,230L559,230L594,211Q571,152 551,117L551,117"
"Q577,84 602,43L602,43L566,20Q544,64 528,86L528,86Q500,44 461,12ZM465,258L465,258L438,285"
"Q474,316 501,351L501,351Q474,388 445,418L445,418L473,441Q500,414 523,381L523,381"
"Q546,413 563,453L563,453L598,434Q571,382 549,352L549,352Q576,320 598,285L598,285"
"L563,262Q546,294 525,322L525,322Q491,280 465,258ZM707,12L707,12L680,43Q717,68 753,115"
"L753,115Q731,147 691,188L691,188L719,211Q739,190 754,172Q769,154 774,147L774,147"
"Q793,185 809,230L809,230L844,211Q822,155 801,117L801,117Q828,82 852,43L852,43L820,20"
"Q798,58 778,87L778,87Q747,43 707,12ZM664,-94L621,-94L621,730L664,730L664,-94Z"
"M348,570L348,570L324,605Q425,629 527,688L527,688L555,656Q491,621 439,601"
"Q386,581 348,570ZM715,258L715,258L688,285Q727,318 753,351L753,351Q733,378 695,418"
"L695,418L723,441Q754,410 775,381L775,381Q794,407 813,453L813,453L848,434"
"Q826,387 801,352L801,352Q823,321 848,281L848,281L813,262Q791,301 775,323L775,323"
"Q749,288 715,258ZM941,719L348,719L348,754L941,754L941,719ZM957,605L936,570"
"Q870,602 817,622Q764,641 727,652L727,652L749,688Q852,655 957,605L957,605Z";
g_assert_cmpmem (str, user_data.consumed, expected, sizeof (expected) - 1);
hb_font_destroy (font);
}
/* CFF2 variations */
{
hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype-Subset.otf");
hb_font_t *font = hb_font_create (face);
hb_face_destroy (face);
hb_variation_t var;
var.tag = HB_TAG ('w','g','h','t');
/* applies variations to CFF2 glyphs */
{
var.value = 100;
hb_font_set_variations (font, &var, 1);
hb_buffer_t *buffer = hb_buffer_create ();
hb_codepoint_t codepoint = '$';
hb_buffer_add_codepoints (buffer, &codepoint, 1, 0, -1);
hb_buffer_set_direction (buffer, HB_DIRECTION_LTR);
hb_shape (font, buffer, NULL, 0);
codepoint = hb_buffer_get_glyph_infos (buffer, NULL)[0].codepoint;
hb_buffer_destroy (buffer);
user_data.consumed = 0;
g_assert (hb_ot_glyph_decompose (font, codepoint, funcs, &user_data));
char expected[] = "M246,15C188,15 147,27 101,68L142,23L117,117C111,143 96,149 81,149"
"C65,149 56,141 52,126C71,40 137,-13 244,-13C348,-13 436,46 436,156"
"C436,229 405,295 271,349L247,359C160,393 119,439 119,506"
"C119,592 178,637 262,637C311,637 346,626 390,585L348,629L373,535"
"C380,510 394,503 408,503C424,503 434,510 437,526C418,614 348,665 259,665"
"C161,665 78,606 78,500C78,414 128,361 224,321L261,305C367,259 395,217 395,152"
"C395,65 334,15 246,15ZM267,331L267,759L240,759L240,331L267,331ZM240,-115"
"L267,-115L267,331L240,331L240,-115Z";
g_assert_cmpmem (str, user_data.consumed, expected, sizeof (expected) - 1);
}
{
var.value = 500;
hb_font_set_variations (font, &var, 1);
hb_buffer_t *buffer = hb_buffer_create ();
hb_codepoint_t codepoint = '$';
hb_buffer_add_codepoints (buffer, &codepoint, 1, 0, -1);
hb_buffer_set_direction (buffer, HB_DIRECTION_LTR);
hb_shape (font, buffer, NULL, 0);
codepoint = hb_buffer_get_glyph_infos (buffer, NULL)[0].codepoint;
hb_buffer_destroy (buffer);
user_data.consumed = 0;
g_assert (hb_ot_glyph_decompose (font, codepoint, funcs, &user_data));
char expected[] = "M251,36C206,36 165,42 118,61L176,21L161,99C151,152 129,167 101,167"
"C78,167 61,155 51,131C54,43 133,-14 247,-14C388,-14 474,64 474,171"
"C474,258 430,321 294,370L257,383C188,406 150,438 150,499"
"C150,571 204,606 276,606C308,606 342,601 386,582L327,621"
"L343,546C355,490 382,476 408,476C428,476 448,487 455,512"
"C450,597 370,656 264,656C140,656 57,576 57,474C57,373 119,318 227,279"
"L263,266C345,236 379,208 379,145C379,76 329,36 251,36ZM289,320"
"L289,746L242,746L242,320L289,320ZM240,-115L286,-115L286,320L240,320L240,-115Z";
g_assert_cmpmem (str, user_data.consumed, expected, sizeof (expected) - 1);
}
/* substitutes GSUB features depending on variations */
{
var.value = 900;
hb_font_set_variations (font, &var, 1);
hb_buffer_t *buffer = hb_buffer_create ();
hb_codepoint_t codepoint = '$';
hb_buffer_add_codepoints (buffer, &codepoint, 1, 0, -1);
hb_buffer_set_direction (buffer, HB_DIRECTION_LTR);
hb_shape (font, buffer, NULL, 0);
codepoint = hb_buffer_get_glyph_infos (buffer, NULL)[0].codepoint;
hb_buffer_destroy (buffer);
user_data.consumed = 0;
g_assert (hb_ot_glyph_decompose (font, codepoint, funcs, &user_data));
char expected[] = "M258,38C197,38 167,48 118,71L192,19L183,103C177,155 155,174 115,174"
"C89,174 64,161 51,125C52,36 124,-16 258,-16C417,-16 513,67 513,175"
"C513,278 457,328 322,388L289,403C232,429 203,452 203,500C203,562 244,589 301,589"
"C342,589 370,585 420,562L341,607L352,539C363,468 398,454 434,454C459,454 486,468 492,506"
"C491,590 408,643 290,643C141,643 57,563 57,460C57,357 122,307 233,256L265,241"
"C334,209 363,186 363,130C363,77 320,38 258,38ZM318,616L318,734L252,734L252,616"
"L318,616ZM253,-115L319,-115L319,14L253,14L253,-115Z";
g_assert_cmpmem (str, user_data.consumed, expected, sizeof (expected) - 1);
}
hb_font_destroy (font);
}
}
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
@ -334,6 +575,7 @@ main (int argc, char **argv)
hb_test_add (test_hb_ot_glyph_cff1_rline); hb_test_add (test_hb_ot_glyph_cff1_rline);
hb_test_add (test_hb_ot_glyph_cff2); hb_test_add (test_hb_ot_glyph_cff2);
hb_test_add (test_hb_ot_glyph_ttf_parser_tests); hb_test_add (test_hb_ot_glyph_ttf_parser_tests);
hb_test_add (test_hb_ot_glyph_font_kit_variations_tests);
unsigned result = hb_test_run (); unsigned result = hb_test_run ();
hb_ot_glyph_decompose_funcs_destroy (funcs); hb_ot_glyph_decompose_funcs_destroy (funcs);