test-ot-layout.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * Copyright © 2021 Khaled Hosny
  3. *
  4. * This is part of HarfBuzz, a text shaping library.
  5. *
  6. * Permission is hereby granted, without written agreement and without
  7. * license or royalty fees, to use, copy, modify, and distribute this
  8. * software and its documentation for any purpose, provided that the
  9. * above copyright notice and the following two paragraphs appear in
  10. * all copies of this software.
  11. *
  12. * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
  13. * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  14. * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
  15. * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
  16. * DAMAGE.
  17. *
  18. * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
  19. * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  20. * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
  21. * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
  22. * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  23. */
  24. #include "hb-test.h"
  25. #include <hb.h>
  26. #include <hb-ot.h>
  27. #define STATIC_ARRAY_SIZE 255
  28. static void
  29. test_ot_layout_table_get_script_tags (void)
  30. {
  31. hb_face_t *face = hb_test_open_font_file ("fonts/NotoNastaliqUrdu-Regular.ttf");
  32. unsigned int total = 0;
  33. unsigned int count = STATIC_ARRAY_SIZE;
  34. unsigned int offset = 0;
  35. hb_tag_t tags[STATIC_ARRAY_SIZE];
  36. while (count == STATIC_ARRAY_SIZE)
  37. {
  38. total = hb_ot_layout_table_get_script_tags (face, HB_OT_TAG_GSUB, offset, &count, tags);
  39. g_assert_cmpuint (3, ==, total);
  40. offset += count;
  41. if (count)
  42. {
  43. g_assert_cmpuint (3, ==, count);
  44. g_assert_cmpuint (HB_TAG ('a','r','a','b'), ==, tags[0]);
  45. g_assert_cmpuint (HB_TAG ('d','f','l','t'), ==, tags[1]);
  46. g_assert_cmpuint (HB_TAG ('l','a','t','n'), ==, tags[2]);
  47. }
  48. }
  49. count = STATIC_ARRAY_SIZE;
  50. offset = 0;
  51. while (count == STATIC_ARRAY_SIZE)
  52. {
  53. total = hb_ot_layout_table_get_script_tags (face, HB_OT_TAG_GPOS, offset, &count, tags);
  54. g_assert_cmpuint (1, ==, total);
  55. offset += count;
  56. if (count)
  57. {
  58. g_assert_cmpuint (1, ==, count);
  59. g_assert_cmpuint (HB_TAG ('a','r','a','b'), ==, tags[0]);
  60. }
  61. }
  62. hb_face_destroy (face);
  63. }
  64. static void
  65. test_ot_layout_table_find_script (void)
  66. {
  67. hb_face_t *face = hb_test_open_font_file ("fonts/NotoNastaliqUrdu-Regular.ttf");
  68. unsigned int index;
  69. g_assert (hb_ot_layout_table_find_script (face, HB_OT_TAG_GSUB, HB_TAG ('a','r','a','b'), &index));
  70. g_assert_cmpuint (0, ==, index);
  71. g_assert (hb_ot_layout_table_find_script (face, HB_OT_TAG_GSUB, HB_TAG ('d','f','l','t'), &index));
  72. g_assert_cmpuint (1, ==, index);
  73. g_assert (hb_ot_layout_table_find_script (face, HB_OT_TAG_GSUB, HB_TAG ('l','a','t','n'), &index));
  74. g_assert_cmpuint (2, ==, index);
  75. g_assert (hb_ot_layout_table_find_script (face, HB_OT_TAG_GPOS, HB_TAG ('a','r','a','b'), &index));
  76. g_assert_cmpuint (0, ==, index);
  77. g_assert (!hb_ot_layout_table_find_script (face, HB_OT_TAG_GPOS, HB_TAG ('d','f','l','t'), &index));
  78. g_assert_cmpuint (0xFFFF, ==, index);
  79. g_assert (!hb_ot_layout_table_find_script (face, HB_OT_TAG_GPOS, HB_TAG ('l','a','t','n'), &index));
  80. g_assert_cmpuint (0xFFFF, ==, index);
  81. hb_face_destroy (face);
  82. }
  83. static void
  84. test_ot_layout_table_get_feature_tags (void)
  85. {
  86. hb_face_t *face = hb_test_open_font_file ("fonts/NotoNastaliqUrdu-Regular.ttf");
  87. unsigned int total = 0;
  88. unsigned int count = STATIC_ARRAY_SIZE;
  89. unsigned int offset = 0;
  90. hb_tag_t tags[STATIC_ARRAY_SIZE];
  91. while (count == STATIC_ARRAY_SIZE)
  92. {
  93. total = hb_ot_layout_table_get_feature_tags (face, HB_OT_TAG_GSUB, offset, &count, tags);
  94. g_assert_cmpuint (14, ==, total);
  95. offset += count;
  96. if (count)
  97. {
  98. g_assert_cmpuint (14, ==, count);
  99. g_assert_cmpuint (HB_TAG ('c','c','m','p'), ==, tags[0]);
  100. g_assert_cmpuint (HB_TAG ('i','s','o','l'), ==, tags[10]);
  101. g_assert_cmpuint (HB_TAG ('r','l','i','g'), ==, tags[13]);
  102. }
  103. }
  104. count = STATIC_ARRAY_SIZE;
  105. offset = 0;
  106. while (count == STATIC_ARRAY_SIZE)
  107. {
  108. total = hb_ot_layout_table_get_feature_tags (face, HB_OT_TAG_GPOS, offset, &count, tags);
  109. g_assert_cmpuint (3, ==, total);
  110. offset += count;
  111. if (count)
  112. {
  113. g_assert_cmpuint (3, ==, count);
  114. g_assert_cmpuint (HB_TAG ('c','u','r','s'), ==, tags[0]);
  115. g_assert_cmpuint (HB_TAG ('m','a','r','k'), ==, tags[1]);
  116. g_assert_cmpuint (HB_TAG ('m','k','m','k'), ==, tags[2]);
  117. }
  118. }
  119. hb_face_destroy (face);
  120. }
  121. static void
  122. test_ot_layout_script_get_language_tags (void)
  123. {
  124. hb_face_t *face = hb_test_open_font_file ("fonts/Estedad-VF.ttf");
  125. unsigned int total = 0;
  126. unsigned int count = STATIC_ARRAY_SIZE;
  127. unsigned int offset = 0;
  128. hb_tag_t tags[STATIC_ARRAY_SIZE];
  129. while (count == STATIC_ARRAY_SIZE)
  130. {
  131. total = hb_ot_layout_script_get_language_tags (face, HB_OT_TAG_GSUB, 0, offset, &count, tags);
  132. g_assert_cmpuint (2, ==, total);
  133. offset += count;
  134. if (count)
  135. {
  136. g_assert_cmpuint (2, ==, count);
  137. g_assert_cmpuint (HB_TAG ('F','A','R',' '), ==, tags[0]);
  138. g_assert_cmpuint (HB_TAG ('K','U','R',' '), ==, tags[1]);
  139. }
  140. }
  141. count = STATIC_ARRAY_SIZE;
  142. offset = 0;
  143. while (count == STATIC_ARRAY_SIZE)
  144. {
  145. total = hb_ot_layout_script_get_language_tags (face, HB_OT_TAG_GPOS, 1, offset, &count, tags);
  146. g_assert_cmpuint (2, ==, total);
  147. offset += count;
  148. if (count)
  149. {
  150. g_assert_cmpuint (2, ==, count);
  151. g_assert_cmpuint (HB_TAG ('F','A','R',' '), ==, tags[0]);
  152. g_assert_cmpuint (HB_TAG ('K','U','R',' '), ==, tags[1]);
  153. }
  154. }
  155. hb_face_destroy (face);
  156. }
  157. static void
  158. test_ot_layout_language_get_feature_tags (void)
  159. {
  160. hb_face_t *face = hb_test_open_font_file ("fonts/Estedad-VF.ttf");
  161. unsigned int total = 0;
  162. unsigned int count = STATIC_ARRAY_SIZE;
  163. unsigned int offset = 0;
  164. hb_tag_t tags[STATIC_ARRAY_SIZE];
  165. while (count == STATIC_ARRAY_SIZE)
  166. {
  167. total = hb_ot_layout_language_get_feature_tags (face, HB_OT_TAG_GSUB, 0, 0, offset, &count, tags);
  168. g_assert_cmpuint (6, ==, total);
  169. offset += count;
  170. if (count)
  171. {
  172. g_assert_cmpuint (6, ==, count);
  173. g_assert_cmpuint (HB_TAG ('c','a','l','t'), ==, tags[0]);
  174. g_assert_cmpuint (HB_TAG ('f','i','n','a'), ==, tags[1]);
  175. g_assert_cmpuint (HB_TAG ('i','n','i','t'), ==, tags[2]);
  176. g_assert_cmpuint (HB_TAG ('l','i','g','a'), ==, tags[3]);
  177. g_assert_cmpuint (HB_TAG ('m','e','d','i'), ==, tags[4]);
  178. g_assert_cmpuint (HB_TAG ('r','l','i','g'), ==, tags[5]);
  179. }
  180. }
  181. count = STATIC_ARRAY_SIZE;
  182. offset = 0;
  183. while (count == STATIC_ARRAY_SIZE)
  184. {
  185. total = hb_ot_layout_language_get_feature_tags (face, HB_OT_TAG_GPOS, 1, 0, offset, &count, tags);
  186. g_assert_cmpuint (3, ==, total);
  187. offset += count;
  188. if (count)
  189. {
  190. g_assert_cmpuint (3, ==, count);
  191. g_assert_cmpuint (HB_TAG ('k','e','r','n'), ==, tags[0]);
  192. g_assert_cmpuint (HB_TAG ('m','a','r','k'), ==, tags[1]);
  193. g_assert_cmpuint (HB_TAG ('m','k','m','k'), ==, tags[2]);
  194. }
  195. }
  196. hb_face_destroy (face);
  197. }
  198. int
  199. main (int argc, char **argv)
  200. {
  201. hb_test_init (&argc, &argv);
  202. hb_test_add (test_ot_layout_table_get_script_tags);
  203. hb_test_add (test_ot_layout_table_find_script);
  204. hb_test_add (test_ot_layout_script_get_language_tags);
  205. hb_test_add (test_ot_layout_table_get_feature_tags);
  206. hb_test_add (test_ot_layout_language_get_feature_tags);
  207. return hb_test_run ();
  208. }