test-ot-ligature-carets.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright © 2018 Ebrahim Byagowi
  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. */
  25. #include "hb-test.h"
  26. #include <hb-ot.h>
  27. static void
  28. test_ot_layout_get_ligature_carets_ot_gdef (void)
  29. {
  30. hb_face_t *face = hb_test_open_font_file ("fonts/NotoNastaliqUrdu-Regular.ttf");
  31. hb_font_t *font = hb_font_create (face);
  32. hb_font_set_scale (font, hb_face_get_upem (face) * 2, hb_face_get_upem (face) * 4);
  33. hb_position_t caret_array[16];
  34. /* call with no result */
  35. {
  36. unsigned caret_count = 16;
  37. g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
  38. 188, 0, &caret_count,
  39. caret_array));
  40. g_assert_cmpuint (0, ==, caret_count);
  41. }
  42. /* call with no result and some offset */
  43. {
  44. unsigned caret_count = 16;
  45. g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
  46. 188, 10, &caret_count,
  47. caret_array));
  48. g_assert_cmpuint (0, ==, caret_count);
  49. }
  50. /* a glyph with 3 ligature carets */
  51. {
  52. unsigned caret_count = 16;
  53. g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
  54. 1020, 0, &caret_count,
  55. caret_array));
  56. g_assert_cmpuint (3, ==, caret_count);
  57. g_assert_cmpuint (2718, ==, caret_array[0]);
  58. g_assert_cmpuint (5438, ==, caret_array[1]);
  59. g_assert_cmpuint (8156, ==, caret_array[2]);
  60. }
  61. /* the same glyph as above but with offset */
  62. {
  63. caret_array[2] = 123;
  64. unsigned caret_count = 16;
  65. g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
  66. 1020, 1, &caret_count,
  67. caret_array));
  68. g_assert_cmpuint (2, ==, caret_count);
  69. g_assert_cmpuint (5438, ==, caret_array[0]);
  70. g_assert_cmpuint (8156, ==, caret_array[1]);
  71. g_assert_cmpuint (123, ==, caret_array[2]);
  72. }
  73. /* the same glyph as above but with another offset */
  74. {
  75. unsigned caret_count = 16;
  76. g_assert_cmpuint (3, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
  77. 1020, 2, &caret_count,
  78. caret_array));
  79. g_assert_cmpuint (1, ==, caret_count);
  80. g_assert_cmpuint (8156, ==, caret_array[0]);
  81. }
  82. /* call with no result */
  83. {
  84. unsigned caret_count = 16;
  85. g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
  86. 1021, 0, &caret_count,
  87. caret_array));
  88. g_assert_cmpuint (0, ==, caret_count);
  89. }
  90. /* a glyph with 1 ligature caret */
  91. {
  92. unsigned caret_count = 16;
  93. g_assert_cmpuint (1, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
  94. 1022, 0, &caret_count,
  95. caret_array));
  96. g_assert_cmpuint (1, ==, caret_count);
  97. g_assert_cmpuint (3530, ==, caret_array[0]);
  98. }
  99. /* the same glyph as above but with offset */
  100. {
  101. unsigned caret_count = 16;
  102. g_assert_cmpuint (1, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
  103. 1022, 1, &caret_count,
  104. caret_array));
  105. g_assert_cmpuint (0, ==, caret_count);
  106. }
  107. /* a glyph with 2 ligature carets */
  108. {
  109. unsigned caret_count = 16;
  110. g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_LTR,
  111. 1023, 0, &caret_count,
  112. caret_array));
  113. g_assert_cmpuint (2, ==, caret_count);
  114. g_assert_cmpuint (2352, ==, caret_array[0]);
  115. g_assert_cmpuint (4706, ==, caret_array[1]);
  116. }
  117. hb_font_destroy (font);
  118. hb_face_destroy (face);
  119. }
  120. static void
  121. test_ot_layout_get_ligature_carets_empty (void)
  122. {
  123. hb_face_t *face = hb_face_get_empty ();
  124. hb_font_t *font = hb_font_create (face);
  125. hb_font_set_scale (font, hb_face_get_upem (face) * 2, hb_face_get_upem (face) * 4);
  126. hb_position_t caret_array[3];
  127. unsigned int caret_count = 3;
  128. g_assert_cmpuint (0, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_RTL,
  129. 1024, 0, &caret_count,
  130. caret_array));
  131. g_assert_cmpuint (0, ==, caret_count);
  132. hb_font_destroy (font);
  133. hb_face_destroy (face);
  134. }
  135. int
  136. main (int argc, char **argv)
  137. {
  138. g_test_init (&argc, &argv, NULL);
  139. hb_test_add (test_ot_layout_get_ligature_carets_ot_gdef);
  140. hb_test_add (test_ot_layout_get_ligature_carets_empty);
  141. return hb_test_run ();
  142. }