2
0

test-ot-collect-glyphs.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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 BEGIN(tag, idx) \
  28. hb_ot_layout_lookup_collect_glyphs (face, tag, idx, before, input, after, output) \
  29. #define END() \
  30. hb_set_clear (before); \
  31. hb_set_clear (input); \
  32. hb_set_clear (after); \
  33. hb_set_clear (output)
  34. static void
  35. test_ot_layout_lookup_collect_glyphs_source_sans (void)
  36. {
  37. hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansPro-Regular.otf");
  38. hb_set_t *before = hb_set_create();
  39. hb_set_t *input = hb_set_create();
  40. hb_set_t *after = hb_set_create();
  41. hb_set_t *output = hb_set_create();
  42. hb_codepoint_t g = HB_SET_VALUE_INVALID;
  43. /* SingleSubst */
  44. BEGIN(HB_OT_TAG_GSUB, 0);
  45. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  46. g_assert_cmpuint (684, ==, hb_set_get_population (input));
  47. g = HB_SET_VALUE_INVALID;
  48. g_assert (hb_set_next (input, &g));
  49. g_assert_cmpuint (54, ==, g);
  50. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  51. g_assert_cmpuint (372, ==, hb_set_get_population (output));
  52. g = HB_SET_VALUE_INVALID;
  53. g_assert (hb_set_next (output, &g));
  54. g_assert_cmpuint (574, ==, g);
  55. END();
  56. /* AlternateSubst */
  57. BEGIN(HB_OT_TAG_GSUB, 1);
  58. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  59. g_assert_cmpuint (143, ==, hb_set_get_population (input));
  60. g = HB_SET_VALUE_INVALID;
  61. g_assert (hb_set_next (input, &g));
  62. g_assert_cmpuint (2, ==, g);
  63. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  64. g_assert_cmpuint (319, ==, hb_set_get_population (output));
  65. g = HB_SET_VALUE_INVALID;
  66. g_assert (hb_set_next (output, &g));
  67. g_assert_cmpuint (519, ==, g);
  68. END();
  69. /* MultipleSubst */
  70. BEGIN(HB_OT_TAG_GSUB, 7);
  71. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  72. g_assert_cmpuint (10, ==, hb_set_get_population (input));
  73. g = HB_SET_VALUE_INVALID;
  74. g_assert (hb_set_next (input, &g));
  75. g_assert_cmpuint (92, ==, g);
  76. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  77. g_assert_cmpuint (9, ==, hb_set_get_population (output));
  78. g = HB_SET_VALUE_INVALID;
  79. g_assert (hb_set_next (output, &g));
  80. g_assert_cmpuint (6, ==, g);
  81. END();
  82. /* LigatureSubst */
  83. BEGIN(HB_OT_TAG_GSUB, 10);
  84. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  85. g_assert_cmpuint (14, ==, hb_set_get_population (input));
  86. g = HB_SET_VALUE_INVALID;
  87. g_assert (hb_set_next (input, &g));
  88. g_assert_cmpuint (1823, ==, g);
  89. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  90. g_assert_cmpuint (22, ==, hb_set_get_population (output));
  91. g = HB_SET_VALUE_INVALID;
  92. g_assert (hb_set_next (output, &g));
  93. g_assert_cmpuint (1897, ==, g);
  94. END();
  95. /* ChainContextSubstFormat3 */
  96. BEGIN(HB_OT_TAG_GSUB, 8);
  97. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  98. g_assert_cmpuint (10, ==, hb_set_get_population (input));
  99. g = HB_SET_VALUE_INVALID;
  100. g_assert (hb_set_next (input, &g));
  101. g_assert_cmpuint (92, ==, g);
  102. g_assert_cmpuint (2, ==, hb_set_get_population (after));
  103. g = HB_SET_VALUE_INVALID;
  104. g_assert (hb_set_next (after, &g));
  105. g_assert_cmpuint (1826, ==, g);
  106. g_assert (hb_set_next (after, &g));
  107. g_assert_cmpuint (1837, ==, g);
  108. g_assert_cmpuint (9, ==, hb_set_get_population (output));
  109. g = HB_SET_VALUE_INVALID;
  110. g_assert (hb_set_next (output, &g));
  111. g_assert_cmpuint (6, ==, g);
  112. END();
  113. /* ChainContextSubstFormat3 */
  114. BEGIN(HB_OT_TAG_GSUB, 13);
  115. g_assert_cmpuint (771, ==, hb_set_get_population (before));
  116. g = HB_SET_VALUE_INVALID;
  117. g_assert (hb_set_next (before, &g));
  118. g_assert_cmpuint (2, ==, g);
  119. g_assert_cmpuint (28, ==, hb_set_get_population (input));
  120. g = HB_SET_VALUE_INVALID;
  121. g_assert (hb_set_next (input, &g));
  122. g_assert_cmpuint (1823, ==, g);
  123. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  124. g_assert_cmpuint (48, ==, hb_set_get_population (output));
  125. g = HB_SET_VALUE_INVALID;
  126. g_assert (hb_set_next (output, &g));
  127. g_assert_cmpuint (325, ==, g);
  128. END();
  129. /* MarkBasePos */
  130. BEGIN(HB_OT_TAG_GPOS, 0);
  131. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  132. g_assert_cmpuint (179, ==, hb_set_get_population (input));
  133. g = HB_SET_VALUE_INVALID;
  134. g_assert (hb_set_next (input, &g));
  135. g_assert_cmpuint (28, ==, g);
  136. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  137. g_assert_cmpuint (0, ==, hb_set_get_population (output));
  138. END();
  139. /* MarkMarkPos */
  140. BEGIN(HB_OT_TAG_GPOS, 9);
  141. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  142. g_assert_cmpuint (48, ==, hb_set_get_population (input));
  143. g = HB_SET_VALUE_INVALID;
  144. g_assert (hb_set_next (input, &g));
  145. g_assert_cmpuint (1823, ==, g);
  146. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  147. g_assert_cmpuint (0, ==, hb_set_get_population (output));
  148. END();
  149. /* PairPos */
  150. BEGIN(HB_OT_TAG_GPOS, 10);
  151. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  152. g_assert_cmpuint (1426, ==, hb_set_get_population (input));
  153. g = HB_SET_VALUE_INVALID;
  154. g_assert (hb_set_next (input, &g));
  155. g_assert_cmpuint (2, ==, g);
  156. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  157. g_assert_cmpuint (0, ==, hb_set_get_population (output));
  158. END();
  159. hb_face_destroy (face);
  160. face = hb_test_open_font_file ("fonts/SourceHanSans-Regular.41,3041,4C2E.otf");
  161. /* SinglePosFormat2 */
  162. BEGIN(HB_OT_TAG_GPOS, 1);
  163. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  164. g_assert_cmpuint (1, ==, hb_set_get_population (input));
  165. g = HB_SET_VALUE_INVALID;
  166. g_assert (hb_set_next (input, &g));
  167. g_assert_cmpuint (4, ==, g);
  168. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  169. g_assert_cmpuint (0, ==, hb_set_get_population (output));
  170. END();
  171. hb_face_destroy (face);
  172. hb_set_destroy (before);
  173. hb_set_destroy (input);
  174. hb_set_destroy (after);
  175. hb_set_destroy (output);
  176. }
  177. static void
  178. test_ot_layout_lookup_collect_glyphs_noto_nastaliq (void)
  179. {
  180. hb_face_t *face = hb_test_open_font_file ("fonts/NotoNastaliqUrdu-Regular.ttf");
  181. hb_set_t *before = hb_set_create();
  182. hb_set_t *input = hb_set_create();
  183. hb_set_t *after = hb_set_create();
  184. hb_set_t *output = hb_set_create();
  185. hb_codepoint_t g = HB_SET_VALUE_INVALID;
  186. /* ExtensionSubst -> ContextSubstFormat1 */
  187. BEGIN(HB_OT_TAG_GSUB, 9);
  188. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  189. g_assert_cmpuint (3, ==, hb_set_get_population (input));
  190. g = HB_SET_VALUE_INVALID;
  191. g_assert (hb_set_next (input, &g));
  192. g_assert_cmpuint (228, ==, g);
  193. g_assert (hb_set_next (input, &g));
  194. g_assert_cmpuint (416, ==, g);
  195. g_assert (hb_set_next (input, &g));
  196. g_assert_cmpuint (441, ==, g);
  197. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  198. g_assert_cmpuint (3, ==, hb_set_get_population (output));
  199. g = HB_SET_VALUE_INVALID;
  200. g_assert (hb_set_next (output, &g));
  201. g_assert_cmpuint (267, ==, g);
  202. g_assert (hb_set_next (output, &g));
  203. g_assert_cmpuint (268, ==, g);
  204. g_assert (hb_set_next (output, &g));
  205. g_assert_cmpuint (279, ==, g);
  206. END();
  207. /* ExtensionSubst -> SingleSubst */
  208. BEGIN(HB_OT_TAG_GSUB, 10);
  209. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  210. g_assert_cmpuint (3, ==, hb_set_get_population (input));
  211. g = HB_SET_VALUE_INVALID;
  212. g_assert (hb_set_next (input, &g));
  213. g_assert_cmpuint (228, ==, g);
  214. g_assert (hb_set_next (input, &g));
  215. g_assert_cmpuint (416, ==, g);
  216. g_assert (hb_set_next (input, &g));
  217. g_assert_cmpuint (441, ==, g);
  218. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  219. g_assert_cmpuint (3, ==, hb_set_get_population (output));
  220. g = HB_SET_VALUE_INVALID;
  221. g_assert (hb_set_next (output, &g));
  222. g_assert_cmpuint (267, ==, g);
  223. g_assert (hb_set_next (output, &g));
  224. g_assert_cmpuint (268, ==, g);
  225. g_assert (hb_set_next (output, &g));
  226. g_assert_cmpuint (279, ==, g);
  227. END();
  228. /* ExtensionSubst -> ChainContextSubstFormat2 */
  229. BEGIN(HB_OT_TAG_GSUB, 16);
  230. g_assert_cmpuint (16, ==, hb_set_get_population (before));
  231. g = HB_SET_VALUE_INVALID;
  232. g_assert (hb_set_next (before, &g));
  233. g_assert_cmpuint (74, ==, g);
  234. g_assert_cmpuint (27, ==, hb_set_get_population (input));
  235. g = HB_SET_VALUE_INVALID;
  236. g_assert (hb_set_next (input, &g));
  237. g_assert_cmpuint (276, ==, g);
  238. g_assert_cmpuint (14, ==, hb_set_get_population (after));
  239. g = HB_SET_VALUE_INVALID;
  240. g_assert (hb_set_next (after, &g));
  241. g_assert_cmpuint (252, ==, g);
  242. g_assert_cmpuint (43, ==, hb_set_get_population (output));
  243. g = HB_SET_VALUE_INVALID;
  244. g_assert (hb_set_next (output, &g));
  245. g_assert_cmpuint (74, ==, g);
  246. END();
  247. /* ExtensionSubst -> ContextSubstFormat2 */
  248. BEGIN(HB_OT_TAG_GSUB, 39);
  249. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  250. g_assert_cmpuint (246, ==, hb_set_get_population (input));
  251. g = HB_SET_VALUE_INVALID;
  252. g_assert (hb_set_next (input, &g));
  253. g_assert_cmpuint (252, ==, g);
  254. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  255. g_assert_cmpuint (258, ==, hb_set_get_population (output));
  256. g = HB_SET_VALUE_INVALID;
  257. g_assert (hb_set_next (output, &g));
  258. g_assert_cmpuint (74, ==, g);
  259. END();
  260. /* CursivePos */
  261. BEGIN(HB_OT_TAG_GPOS, 0);
  262. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  263. g_assert_cmpuint (616, ==, hb_set_get_population (input));
  264. g = HB_SET_VALUE_INVALID;
  265. g_assert (hb_set_next (input, &g));
  266. g_assert_cmpuint (228, ==, g);
  267. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  268. g_assert_cmpuint (0, ==, hb_set_get_population (output));
  269. END();
  270. /* ExtensionSubst -> MarkLigPos */
  271. BEGIN(HB_OT_TAG_GPOS, 13);
  272. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  273. g_assert_cmpuint (46, ==, hb_set_get_population (input));
  274. g = HB_SET_VALUE_INVALID;
  275. g_assert (hb_set_next (input, &g));
  276. g_assert_cmpuint (1004, ==, g);
  277. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  278. g_assert_cmpuint (0, ==, hb_set_get_population (output));
  279. END();
  280. /* ExtensionSubst -> SinglePosFormat1 */
  281. BEGIN(HB_OT_TAG_GPOS, 17);
  282. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  283. g_assert_cmpuint (242, ==, hb_set_get_population (input));
  284. g = HB_SET_VALUE_INVALID;
  285. g_assert (hb_set_next (input, &g));
  286. g_assert_cmpuint (257, ==, g);
  287. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  288. g_assert_cmpuint (0, ==, hb_set_get_population (output));
  289. END();
  290. hb_face_destroy (face);
  291. hb_set_destroy (before);
  292. hb_set_destroy (input);
  293. hb_set_destroy (after);
  294. hb_set_destroy (output);
  295. }
  296. static void
  297. test_ot_layout_lookup_collect_glyphs_qahiri (void)
  298. {
  299. hb_face_t *face = hb_test_open_font_file ("fonts/Qahiri-Regular.ttf");
  300. hb_set_t *before = hb_set_create();
  301. hb_set_t *input = hb_set_create();
  302. hb_set_t *after = hb_set_create();
  303. hb_set_t *output = hb_set_create();
  304. hb_codepoint_t g = HB_SET_VALUE_INVALID;
  305. /* SingleSubstFormat1 */
  306. BEGIN(HB_OT_TAG_GSUB, 0);
  307. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  308. g_assert_cmpuint (4, ==, hb_set_get_population (input));
  309. g = HB_SET_VALUE_INVALID;
  310. g_assert (hb_set_next (input, &g));
  311. g_assert_cmpuint (52, ==, g);
  312. g_assert (hb_set_next (input, &g));
  313. g_assert_cmpuint (60, ==, g);
  314. g_assert (hb_set_next (input, &g));
  315. g_assert_cmpuint (62, ==, g);
  316. g_assert (hb_set_next (input, &g));
  317. g_assert_cmpuint (159, ==, g);
  318. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  319. g_assert_cmpuint (4, ==, hb_set_get_population (output));
  320. g = HB_SET_VALUE_INVALID;
  321. g_assert (hb_set_next (output, &g));
  322. g_assert_cmpuint (53, ==, g);
  323. g_assert (hb_set_next (output, &g));
  324. g_assert_cmpuint (61, ==, g);
  325. g_assert (hb_set_next (output, &g));
  326. g_assert_cmpuint (63, ==, g);
  327. g_assert (hb_set_next (output, &g));
  328. g_assert_cmpuint (160, ==, g);
  329. END();
  330. /* ChainContextSubstFormat1 */
  331. BEGIN(HB_OT_TAG_GSUB, 11);
  332. g_assert_cmpuint (1, ==, hb_set_get_population (before));
  333. g = HB_SET_VALUE_INVALID;
  334. g_assert (hb_set_next (before, &g));
  335. g_assert_cmpuint (39, ==, g);
  336. g_assert_cmpuint (2, ==, hb_set_get_population (input));
  337. g = HB_SET_VALUE_INVALID;
  338. g_assert (hb_set_next (input, &g));
  339. g_assert_cmpuint (154, ==, g);
  340. g_assert (hb_set_next (input, &g));
  341. g_assert_cmpuint (159, ==, g);
  342. g_assert_cmpuint (1, ==, hb_set_get_population (after));
  343. g = HB_SET_VALUE_INVALID;
  344. g_assert (hb_set_next (after, &g));
  345. g_assert_cmpuint (179, ==, g);
  346. g_assert_cmpuint (2, ==, hb_set_get_population (output));
  347. g = HB_SET_VALUE_INVALID;
  348. g_assert (hb_set_next (output, &g));
  349. g_assert_cmpuint (155, ==, g);
  350. g_assert (hb_set_next (output, &g));
  351. g_assert_cmpuint (162, ==, g);
  352. END();
  353. /* ContextSubstFormat3 */
  354. BEGIN(HB_OT_TAG_GSUB, 31);
  355. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  356. g_assert_cmpuint (4, ==, hb_set_get_population (input));
  357. g = HB_SET_VALUE_INVALID;
  358. g_assert (hb_set_next (input, &g));
  359. g_assert_cmpuint (53, ==, g);
  360. g_assert_cmpuint (0, ==, hb_set_get_population (after));
  361. g_assert_cmpuint (4, ==, hb_set_get_population (output));
  362. g = HB_SET_VALUE_INVALID;
  363. g_assert (hb_set_next (output, &g));
  364. g_assert_cmpuint (52, ==, g);
  365. g_assert (hb_set_next (output, &g));
  366. g_assert_cmpuint (60, ==, g);
  367. g_assert (hb_set_next (output, &g));
  368. g_assert_cmpuint (62, ==, g);
  369. g_assert (hb_set_next (output, &g));
  370. g_assert_cmpuint (159, ==, g);
  371. END();
  372. /* ReverseChainSingleSubst */
  373. BEGIN(HB_OT_TAG_GSUB, 32);
  374. g_assert_cmpuint (0, ==, hb_set_get_population (before));
  375. g_assert_cmpuint (42, ==, hb_set_get_population (input));
  376. g = HB_SET_VALUE_INVALID;
  377. g_assert (hb_set_next (input, &g));
  378. g_assert_cmpuint (47, ==, g);
  379. g_assert_cmpuint (46, ==, hb_set_get_population (after));
  380. g = HB_SET_VALUE_INVALID;
  381. g_assert (hb_set_next (after, &g));
  382. g_assert_cmpuint (61, ==, g);
  383. g_assert_cmpuint (42, ==, hb_set_get_population (output));
  384. g = HB_SET_VALUE_INVALID;
  385. g_assert (hb_set_next (output, &g));
  386. g_assert_cmpuint (463, ==, g);
  387. END();
  388. hb_face_destroy (face);
  389. hb_set_destroy (before);
  390. hb_set_destroy (input);
  391. hb_set_destroy (after);
  392. hb_set_destroy (output);
  393. }
  394. int
  395. main (int argc, char **argv)
  396. {
  397. hb_test_init (&argc, &argv);
  398. hb_test_add (test_ot_layout_lookup_collect_glyphs_source_sans);
  399. hb_test_add (test_ot_layout_lookup_collect_glyphs_noto_nastaliq);
  400. hb_test_add (test_ot_layout_lookup_collect_glyphs_qahiri);
  401. return hb_test_run ();
  402. }