diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 88502ac5c..a491a17df 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -46,6 +46,7 @@ TEST_PROGS = \ test-ot-face \ test-ot-glyphname \ test-ot-ligature-carets \ + test-ot-layout \ test-ot-name \ test-ot-meta \ test-ot-metrics \ diff --git a/test/api/meson.build b/test/api/meson.build index a1c862b61..cba80f018 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -21,6 +21,7 @@ tests = [ 'test-ot-color.c', 'test-ot-face.c', 'test-ot-glyphname.c', + 'test-ot-layout.c', 'test-ot-ligature-carets.c', 'test-ot-name.c', 'test-ot-meta.c', diff --git a/test/api/test-ot-layout.c b/test/api/test-ot-layout.c new file mode 100644 index 000000000..5c6ccce4d --- /dev/null +++ b/test/api/test-ot-layout.c @@ -0,0 +1,228 @@ +/* + * Copyright © 2021 Khaled Hosny + * + * 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. + */ + +#include "hb-test.h" + +#include +#include + +#define STATIC_ARRAY_SIZE 255 + +static void +test_ot_layout_table_get_script_tags (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/NotoNastaliqUrdu-Regular.ttf"); + + unsigned int total = 0; + unsigned int count = STATIC_ARRAY_SIZE; + unsigned int offset = 0; + hb_tag_t tags[STATIC_ARRAY_SIZE]; + while (count == STATIC_ARRAY_SIZE) + { + total = hb_ot_layout_table_get_script_tags (face, HB_OT_TAG_GSUB, offset, &count, tags); + g_assert_cmpuint (3, ==, total); + offset += count; + if (count) + { + g_assert_cmpuint (3, ==, count); + g_assert_cmpuint (HB_TAG ('a','r','a','b'), ==, tags[0]); + g_assert_cmpuint (HB_TAG ('d','f','l','t'), ==, tags[1]); + g_assert_cmpuint (HB_TAG ('l','a','t','n'), ==, tags[2]); + } + } + count = STATIC_ARRAY_SIZE; + offset = 0; + while (count == STATIC_ARRAY_SIZE) + { + total = hb_ot_layout_table_get_script_tags (face, HB_OT_TAG_GPOS, offset, &count, tags); + g_assert_cmpuint (1, ==, total); + offset += count; + if (count) + { + g_assert_cmpuint (1, ==, count); + g_assert_cmpuint (HB_TAG ('a','r','a','b'), ==, tags[0]); + } + } + + hb_face_destroy (face); +} + +static void +test_ot_layout_table_find_script (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/NotoNastaliqUrdu-Regular.ttf"); + unsigned int index; + + g_assert (hb_ot_layout_table_find_script (face, HB_OT_TAG_GSUB, HB_TAG ('a','r','a','b'), &index)); + g_assert_cmpuint (0, ==, index); + g_assert (hb_ot_layout_table_find_script (face, HB_OT_TAG_GSUB, HB_TAG ('d','f','l','t'), &index)); + g_assert_cmpuint (1, ==, index); + g_assert (hb_ot_layout_table_find_script (face, HB_OT_TAG_GSUB, HB_TAG ('l','a','t','n'), &index)); + g_assert_cmpuint (2, ==, index); + + g_assert (hb_ot_layout_table_find_script (face, HB_OT_TAG_GPOS, HB_TAG ('a','r','a','b'), &index)); + g_assert_cmpuint (0, ==, index); + g_assert (!hb_ot_layout_table_find_script (face, HB_OT_TAG_GPOS, HB_TAG ('d','f','l','t'), &index)); + g_assert_cmpuint (0xFFFF, ==, index); + g_assert (!hb_ot_layout_table_find_script (face, HB_OT_TAG_GPOS, HB_TAG ('l','a','t','n'), &index)); + g_assert_cmpuint (0xFFFF, ==, index); + + hb_face_destroy (face); +} + +static void +test_ot_layout_table_get_feature_tags (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/NotoNastaliqUrdu-Regular.ttf"); + + unsigned int total = 0; + unsigned int count = STATIC_ARRAY_SIZE; + unsigned int offset = 0; + hb_tag_t tags[STATIC_ARRAY_SIZE]; + while (count == STATIC_ARRAY_SIZE) + { + total = hb_ot_layout_table_get_feature_tags (face, HB_OT_TAG_GSUB, offset, &count, tags); + g_assert_cmpuint (14, ==, total); + offset += count; + if (count) + { + g_assert_cmpuint (14, ==, count); + g_assert_cmpuint (HB_TAG ('c','c','m','p'), ==, tags[0]); + g_assert_cmpuint (HB_TAG ('i','s','o','l'), ==, tags[10]); + g_assert_cmpuint (HB_TAG ('r','l','i','g'), ==, tags[13]); + } + } + count = STATIC_ARRAY_SIZE; + offset = 0; + while (count == STATIC_ARRAY_SIZE) + { + total = hb_ot_layout_table_get_feature_tags (face, HB_OT_TAG_GPOS, offset, &count, tags); + g_assert_cmpuint (3, ==, total); + offset += count; + if (count) + { + g_assert_cmpuint (3, ==, count); + g_assert_cmpuint (HB_TAG ('c','u','r','s'), ==, tags[0]); + g_assert_cmpuint (HB_TAG ('m','a','r','k'), ==, tags[1]); + g_assert_cmpuint (HB_TAG ('m','k','m','k'), ==, tags[2]); + } + } + + hb_face_destroy (face); +} + +static void +test_ot_layout_script_get_language_tags (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/Estedad-VF.ttf"); + + unsigned int total = 0; + unsigned int count = STATIC_ARRAY_SIZE; + unsigned int offset = 0; + hb_tag_t tags[STATIC_ARRAY_SIZE]; + while (count == STATIC_ARRAY_SIZE) + { + total = hb_ot_layout_script_get_language_tags (face, HB_OT_TAG_GSUB, 0, offset, &count, tags); + g_assert_cmpuint (2, ==, total); + offset += count; + if (count) + { + g_assert_cmpuint (2, ==, count); + g_assert_cmpuint (HB_TAG ('F','A','R',' '), ==, tags[0]); + g_assert_cmpuint (HB_TAG ('K','U','R',' '), ==, tags[1]); + } + } + count = STATIC_ARRAY_SIZE; + offset = 0; + while (count == STATIC_ARRAY_SIZE) + { + total = hb_ot_layout_script_get_language_tags (face, HB_OT_TAG_GPOS, 1, offset, &count, tags); + g_assert_cmpuint (2, ==, total); + offset += count; + if (count) + { + g_assert_cmpuint (2, ==, count); + g_assert_cmpuint (HB_TAG ('F','A','R',' '), ==, tags[0]); + g_assert_cmpuint (HB_TAG ('K','U','R',' '), ==, tags[1]); + } + } + + hb_face_destroy (face); +} + +static void +test_ot_layout_language_get_feature_tags (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/Estedad-VF.ttf"); + + unsigned int total = 0; + unsigned int count = STATIC_ARRAY_SIZE; + unsigned int offset = 0; + hb_tag_t tags[STATIC_ARRAY_SIZE]; + while (count == STATIC_ARRAY_SIZE) + { + total = hb_ot_layout_language_get_feature_tags (face, HB_OT_TAG_GSUB, 0, 0, offset, &count, tags); + g_assert_cmpuint (6, ==, total); + offset += count; + if (count) + { + g_assert_cmpuint (6, ==, count); + g_assert_cmpuint (HB_TAG ('c','a','l','t'), ==, tags[0]); + g_assert_cmpuint (HB_TAG ('f','i','n','a'), ==, tags[1]); + g_assert_cmpuint (HB_TAG ('i','n','i','t'), ==, tags[2]); + g_assert_cmpuint (HB_TAG ('l','i','g','a'), ==, tags[3]); + g_assert_cmpuint (HB_TAG ('m','e','d','i'), ==, tags[4]); + g_assert_cmpuint (HB_TAG ('r','l','i','g'), ==, tags[5]); + } + } + count = STATIC_ARRAY_SIZE; + offset = 0; + while (count == STATIC_ARRAY_SIZE) + { + total = hb_ot_layout_language_get_feature_tags (face, HB_OT_TAG_GPOS, 1, 0, offset, &count, tags); + g_assert_cmpuint (3, ==, total); + offset += count; + if (count) + { + g_assert_cmpuint (3, ==, count); + g_assert_cmpuint (HB_TAG ('k','e','r','n'), ==, tags[0]); + g_assert_cmpuint (HB_TAG ('m','a','r','k'), ==, tags[1]); + g_assert_cmpuint (HB_TAG ('m','k','m','k'), ==, tags[2]); + } + } + + hb_face_destroy (face); +} + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + hb_test_add (test_ot_layout_table_get_script_tags); + hb_test_add (test_ot_layout_table_find_script); + hb_test_add (test_ot_layout_script_get_language_tags); + hb_test_add (test_ot_layout_table_get_feature_tags); + hb_test_add (test_ot_layout_language_get_feature_tags); + return hb_test_run (); +} diff --git a/test/shape/data/in-house/fonts/1b66a1f4b076b734caa6397b3e57231af1feaafb.ttf b/test/shape/data/in-house/fonts/1b66a1f4b076b734caa6397b3e57231af1feaafb.ttf new file mode 100644 index 000000000..906f5bf82 Binary files /dev/null and b/test/shape/data/in-house/fonts/1b66a1f4b076b734caa6397b3e57231af1feaafb.ttf differ diff --git a/test/shape/data/in-house/fonts/3f24aff8b768e586162e9b9d03b15c36508dd2ae.ttf b/test/shape/data/in-house/fonts/3f24aff8b768e586162e9b9d03b15c36508dd2ae.ttf new file mode 100644 index 000000000..7449e489d Binary files /dev/null and b/test/shape/data/in-house/fonts/3f24aff8b768e586162e9b9d03b15c36508dd2ae.ttf differ diff --git a/test/shape/data/in-house/tests/reverse-sub.tests b/test/shape/data/in-house/tests/reverse-sub.tests index 9563a58b6..60a536956 100644 --- a/test/shape/data/in-house/tests/reverse-sub.tests +++ b/test/shape/data/in-house/tests/reverse-sub.tests @@ -1 +1,3 @@ ../fonts/a706511c65fb278fda87eaf2180ca6684a80f423.ttf;;U+0041,U+0020,U+0041,U+0042;[A.alt1=0+1000|space=1+1000|A.alt1=2+1000|B=3+1000] +../fonts/3f24aff8b768e586162e9b9d03b15c36508dd2ae.ttf;--features=salt=2;U+0635,U+0644,U+0637,U+062E,U+0644,U+0637,U+062C;[gid43=6@143,-124+0|gid8=6+178|gid25=5@0,110+670|gid33=4@0,110+120|gid41=3@-8,343+0|gid10=3@0,110+88|gid26=2@0,220+670|gid34=1@0,220+120|gid21=0@0,220+670] +../fonts/1b66a1f4b076b734caa6397b3e57231af1feaafb.ttf;;U+0031,U+0032,U+0033,U+0034,U+0035,U+0036,U+0037,U+0038,U+0039,U+0030,U+2044,U+0031,U+0032,U+0033,U+0034,U+0035,U+0036,U+0037,U+0038,U+0039,U+0030;[one.numr=0+350|two.numr=1+350|three.numr=2+350|four.numr=3+350|five.numr=4+350|six.numr=5+350|seven.numr=6+350|eight.numr=7+350|nine.numr=8+350|zero.numr=9+350|fraction=10+130|one.dnom=11+350|two.dnom=12+350|three.dnom=13+350|four.dnom=14+350|five.dnom=15+350|six.dnom=16+350|seven.dnom=17+350|eight.dnom=18+350|nine.dnom=19+350|zero.dnom=20+350] diff --git a/test/subset/generate-expected-outputs.py b/test/subset/generate-expected-outputs.py index fabdfef4b..2182643ab 100755 --- a/test/subset/generate-expected-outputs.py +++ b/test/subset/generate-expected-outputs.py @@ -28,7 +28,7 @@ def strip_check_sum (ttx_string): def generate_expected_output(input_file, unicodes, profile_flags, output_directory, font_name): - fonttools_path = os.path.join(output_directory, font_name) + fonttools_path = os.path.join(tempfile.mkdtemp (), font_name) args = ["fonttools", "subset", input_file] args.extend(["--drop-tables+=DSIG", "--drop-tables-=sbix", @@ -57,7 +57,7 @@ def generate_expected_output(input_file, unicodes, profile_flags, output_directo harfbuzz_ttx = strip_check_sum (fp.getvalue ()) if harfbuzz_ttx != fonttools_ttx: - for line in unified_diff (fonttools_ttx.splitlines (1), harfbuzz_ttx.splitlines (1)): + for line in unified_diff (fonttools_ttx.splitlines (1), harfbuzz_ttx.splitlines (1), fonttools_path, harfbuzz_path): sys.stdout.write (line) sys.stdout.flush () raise Exception ('ttx for fonttools and harfbuzz does not match.')