test-aat-layout.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #include "hb-test.h"
  25. #include <hb.h>
  26. #include <hb-ot.h>
  27. #include <hb-aat.h>
  28. /* Unit tests for hb-aat.h */
  29. static hb_face_t *face;
  30. static hb_face_t *sbix;
  31. #ifndef HB_NO_AAT
  32. static void
  33. test_aat_get_feature_types (void)
  34. {
  35. hb_aat_layout_feature_type_t features[3];
  36. unsigned int count = 3;
  37. g_assert_cmpuint (11, ==, hb_aat_layout_get_feature_types (face, 0, &count, features));
  38. g_assert_cmpuint (1, ==, features[0]);
  39. g_assert_cmpuint (3, ==, features[1]);
  40. g_assert_cmpuint (6, ==, features[2]);
  41. g_assert_cmpuint (258, ==, hb_aat_layout_feature_type_get_name_id (face, features[0]));
  42. g_assert_cmpuint (261, ==, hb_aat_layout_feature_type_get_name_id (face, features[1]));
  43. g_assert_cmpuint (265, ==, hb_aat_layout_feature_type_get_name_id (face, features[2]));
  44. }
  45. static void
  46. test_aat_get_feature_selectors (void)
  47. {
  48. unsigned int default_index;
  49. hb_aat_layout_feature_selector_info_t settings[3];
  50. unsigned int count = 3;
  51. g_assert_cmpuint (4, ==, hb_aat_layout_feature_type_get_selector_infos (face,
  52. HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE,
  53. 0, &count, settings,
  54. &default_index));
  55. g_assert_cmpuint (3, ==, count);
  56. g_assert_cmpuint (0, ==, default_index);
  57. g_assert_cmpuint (0, ==, settings[0].enable);
  58. g_assert_cmpuint (294, ==, settings[0].name_id);
  59. g_assert_cmpuint (1, ==, settings[1].enable);
  60. g_assert_cmpuint (295, ==, settings[1].name_id);
  61. g_assert_cmpuint (2, ==, settings[2].enable);
  62. g_assert_cmpuint (296, ==, settings[2].name_id);
  63. count = 3;
  64. g_assert_cmpuint (4, ==, hb_aat_layout_feature_type_get_selector_infos (face,
  65. HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE,
  66. 3, &count, settings,
  67. &default_index));
  68. g_assert_cmpuint (1, ==, count);
  69. g_assert_cmpuint (0, ==, default_index);
  70. g_assert_cmpuint (3, ==, settings[0].enable);
  71. g_assert_cmpuint (297, ==, settings[0].name_id);
  72. count = 1;
  73. g_assert_cmpuint (1, ==, hb_aat_layout_feature_type_get_selector_infos (face,
  74. HB_AAT_LAYOUT_FEATURE_TYPE_TYPOGRAPHIC_EXTRAS,
  75. 0, &count, settings,
  76. &default_index));
  77. g_assert_cmpuint (1, ==, count);
  78. g_assert_cmpuint (HB_AAT_LAYOUT_NO_SELECTOR_INDEX, ==, default_index);
  79. g_assert_cmpuint (8, ==, settings[0].enable);
  80. g_assert_cmpuint (308, ==, settings[0].name_id);
  81. count = 100;
  82. g_assert_cmpuint (0, ==, hb_aat_layout_feature_type_get_selector_infos (face, HB_AAT_LAYOUT_FEATURE_TYPE_INVALID,
  83. 0, &count, settings,
  84. NULL));
  85. g_assert_cmpuint (0, ==, count);
  86. }
  87. static void
  88. test_aat_has (void)
  89. {
  90. hb_face_t *morx = hb_test_open_font_file ("fonts/aat-morx.ttf");
  91. hb_face_t *trak;
  92. g_assert (hb_aat_layout_has_substitution (morx));
  93. hb_face_destroy (morx);
  94. trak = hb_test_open_font_file ("fonts/aat-trak.ttf");
  95. g_assert (hb_aat_layout_has_tracking (trak));
  96. hb_face_destroy (trak);
  97. }
  98. #endif
  99. int
  100. main (int argc, char **argv)
  101. {
  102. unsigned int status;
  103. hb_test_init (&argc, &argv);
  104. #ifndef HB_NO_AAT
  105. hb_test_add (test_aat_get_feature_types);
  106. hb_test_add (test_aat_get_feature_selectors);
  107. hb_test_add (test_aat_has);
  108. #endif
  109. face = hb_test_open_font_file ("fonts/aat-feat.ttf");
  110. sbix = hb_test_open_font_file ("fonts/chromacheck-sbix.ttf");
  111. status = hb_test_run ();
  112. hb_face_destroy (sbix);
  113. hb_face_destroy (face);
  114. return status;
  115. }