test-subset-cmap.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright © 2018 Google, Inc.
  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. * Google Author(s): Roderick Sheeter
  25. */
  26. #include "hb-test.h"
  27. #include "hb-subset-test.h"
  28. /* Unit tests for cmap subsetting */
  29. static void
  30. test_subset_cmap (void)
  31. {
  32. hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
  33. hb_face_t *face_ac = hb_test_open_font_file ("fonts/Roboto-Regular.ac.ttf");
  34. hb_set_t *codepoints = hb_set_create ();
  35. hb_face_t *face_abc_subset;
  36. hb_set_add (codepoints, 97);
  37. hb_set_add (codepoints, 99);
  38. face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
  39. hb_set_destroy (codepoints);
  40. hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('c','m','a','p'));
  41. hb_face_destroy (face_abc_subset);
  42. hb_face_destroy (face_abc);
  43. hb_face_destroy (face_ac);
  44. }
  45. static void
  46. test_subset_cmap_non_consecutive_glyphs (void)
  47. {
  48. hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.D7,D8,D9,DA,DE.ttf");
  49. hb_set_t *codepoints = hb_set_create ();
  50. hb_face_t *face_subset;
  51. hb_set_add (codepoints, 0xD7);
  52. hb_set_add (codepoints, 0xD8);
  53. hb_set_add (codepoints, 0xD9);
  54. hb_set_add (codepoints, 0xDA);
  55. hb_set_add (codepoints, 0xDE);
  56. face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
  57. hb_set_destroy (codepoints);
  58. hb_subset_test_check (face, face_subset, HB_TAG ('c','m','a','p'));
  59. hb_face_destroy (face_subset);
  60. hb_face_destroy (face);
  61. }
  62. static void
  63. test_subset_cmap_noop (void)
  64. {
  65. hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
  66. hb_set_t *codepoints = hb_set_create();
  67. hb_face_t *face_abc_subset;
  68. hb_set_add (codepoints, 97);
  69. hb_set_add (codepoints, 98);
  70. hb_set_add (codepoints, 99);
  71. face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
  72. hb_set_destroy (codepoints);
  73. hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('c','m','a','p'));
  74. hb_face_destroy (face_abc_subset);
  75. hb_face_destroy (face_abc);
  76. }
  77. static void
  78. test_subset_cmap4_no_exceeding_maximum_codepoint (void)
  79. {
  80. hb_face_t *face_origin = hb_test_open_font_file ("fonts/Mplus1p-Regular.ttf");
  81. hb_face_t *face_expected = hb_test_open_font_file ("fonts/Mplus1p-Regular-cmap4-testing.ttf");
  82. hb_set_t *codepoints = hb_set_create ();
  83. hb_face_t *face_subset;
  84. hb_set_add (codepoints, 0x20);
  85. hb_set_add (codepoints, 0x21);
  86. hb_set_add (codepoints, 0x1d542);
  87. hb_set_add (codepoints, 0x201a2);
  88. face_subset = hb_subset_test_create_subset (face_origin, hb_subset_test_create_input (codepoints));
  89. hb_set_destroy (codepoints);
  90. hb_subset_test_check (face_expected, face_subset, HB_TAG ('c','m','a','p'));
  91. hb_face_destroy (face_subset);
  92. hb_face_destroy (face_expected);
  93. hb_face_destroy (face_origin);
  94. }
  95. static void
  96. test_subset_cmap_empty_tables (void)
  97. {
  98. hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
  99. hb_face_t *face_empty = hb_test_open_font_file ("fonts/Roboto-Regular.empty.ttf");
  100. hb_set_t *codepoints = hb_set_create ();
  101. hb_face_t *face_abc_subset;
  102. hb_set_add (codepoints, 100);
  103. hb_set_add (codepoints, 101);
  104. face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
  105. hb_set_destroy (codepoints);
  106. hb_subset_test_check (face_empty, face_abc_subset, HB_TAG ('c','m','a','p'));
  107. hb_face_destroy (face_abc_subset);
  108. hb_face_destroy (face_abc);
  109. hb_face_destroy (face_empty);
  110. }
  111. static void
  112. test_subset_cmap_noto_color_emoji_noop (void)
  113. {
  114. hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.cmap.ttf");
  115. hb_set_t *codepoints = hb_set_create ();
  116. hb_face_t *face_subset;
  117. hb_set_add (codepoints, 0x38);
  118. hb_set_add (codepoints, 0x39);
  119. hb_set_add (codepoints, 0xAE);
  120. hb_set_add (codepoints, 0x2049);
  121. hb_set_add (codepoints, 0x20E3);
  122. face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
  123. hb_set_destroy (codepoints);
  124. hb_subset_test_check (face, face_subset, HB_TAG ('c','m','a','p'));
  125. hb_face_destroy (face_subset);
  126. hb_face_destroy (face);
  127. }
  128. static void
  129. test_subset_cmap_noto_color_emoji_non_consecutive_glyphs (void)
  130. {
  131. hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.cmap.ttf");
  132. hb_face_t *face_expected = hb_test_open_font_file ("fonts/NotoColorEmoji.cmap.38,AE,2049.ttf");
  133. hb_set_t *codepoints = hb_set_create ();
  134. hb_face_t *face_subset;
  135. hb_set_add (codepoints, 0x38);
  136. hb_set_add (codepoints, 0xAE);
  137. hb_set_add (codepoints, 0x2049);
  138. face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
  139. hb_set_destroy (codepoints);
  140. hb_subset_test_check (face_expected, face_subset, HB_TAG ('c','m','a','p'));
  141. hb_face_destroy (face_subset);
  142. hb_face_destroy (face_expected);
  143. hb_face_destroy (face);
  144. }
  145. // TODO(rsheeter) test cmap to no codepoints
  146. int
  147. main (int argc, char **argv)
  148. {
  149. hb_test_init (&argc, &argv);
  150. hb_test_add (test_subset_cmap);
  151. hb_test_add (test_subset_cmap_noop);
  152. hb_test_add (test_subset_cmap_non_consecutive_glyphs);
  153. hb_test_add (test_subset_cmap4_no_exceeding_maximum_codepoint);
  154. hb_test_add (test_subset_cmap_empty_tables);
  155. hb_test_add (test_subset_cmap_noto_color_emoji_noop);
  156. hb_test_add (test_subset_cmap_noto_color_emoji_non_consecutive_glyphs);
  157. return hb_test_run();
  158. }