test-ot-name.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 hb_face_t *face;
  28. static void
  29. test_ot_layout_feature_get_name_ids_and_characters (void)
  30. {
  31. hb_tag_t cv01 = HB_TAG ('c','v','0','1');
  32. unsigned int feature_index;
  33. unsigned int num_named_parameters;
  34. hb_ot_name_id_t label_id;
  35. hb_ot_name_id_t tooltip_id;
  36. hb_ot_name_id_t sample_id;
  37. hb_ot_name_id_t first_param_id;
  38. hb_codepoint_t characters[100];
  39. unsigned int char_count = 100;
  40. unsigned int all_chars;
  41. if (!hb_ot_layout_language_find_feature (face,
  42. HB_OT_TAG_GSUB,
  43. 0,
  44. HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX,
  45. cv01,
  46. &feature_index))
  47. g_error ("Failed to find feature index");
  48. if (!hb_ot_layout_feature_get_name_ids (face, HB_OT_TAG_GSUB, feature_index,
  49. &label_id, &tooltip_id, &sample_id,
  50. &num_named_parameters, &first_param_id))
  51. g_error ("Failed to get name ids");
  52. g_assert_cmpint (label_id, ==, 256);
  53. g_assert_cmpint (tooltip_id, ==, 257);
  54. g_assert_cmpint (sample_id, ==, 258);
  55. g_assert_cmpint (num_named_parameters, ==, 2);
  56. g_assert_cmpint (first_param_id, ==, 259);
  57. all_chars = hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB, feature_index,
  58. 0, &char_count, characters);
  59. g_assert_cmpint (all_chars, ==, 2);
  60. g_assert_cmpint (char_count, ==, 2);
  61. g_assert_cmpint (characters[0], ==, 10);
  62. g_assert_cmpint (characters[1], ==, 24030);
  63. char_count = 100;
  64. characters[1] = 1234;
  65. all_chars = hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB, feature_index,
  66. 1, &char_count, characters);
  67. g_assert_cmpint (all_chars, ==, 2);
  68. g_assert_cmpint (char_count, ==, 1);
  69. g_assert_cmpint (characters[0], ==, 24030);
  70. g_assert_cmpint (characters[1], ==, 1234);
  71. }
  72. static void
  73. test_ot_name (void)
  74. {
  75. unsigned int num_entries;
  76. const hb_ot_name_entry_t *entries;
  77. hb_ot_name_id_t name_id;
  78. hb_language_t lang;
  79. char text[10];
  80. unsigned int text_size = 10;
  81. entries = hb_ot_name_list_names (face, &num_entries);
  82. g_assert_cmpuint (12, ==, num_entries);
  83. name_id = entries[3].name_id;
  84. g_assert_cmpuint (3, ==, name_id);
  85. lang = entries[3].language;
  86. g_assert_cmpstr (hb_language_to_string (lang), ==, "en");
  87. g_assert_cmpuint (27, ==, hb_ot_name_get_utf8 (face, name_id, lang, &text_size, text));
  88. g_assert_cmpuint (9, ==, text_size);
  89. g_assert_cmpstr (text, ==, "FontForge");
  90. g_assert_cmpuint (27, ==, hb_ot_name_get_utf8 (face, name_id, hb_language_from_string ("en_US", -1), &text_size, text));
  91. g_assert_cmpuint (8, ==, text_size);
  92. g_assert_cmpstr (text, ==, "FontForg");
  93. g_assert_cmpuint (0, ==, hb_ot_name_get_utf8 (face, name_id, hb_language_from_string ("fa_IR", -1), &text_size, text));
  94. }
  95. int
  96. main (int argc, char **argv)
  97. {
  98. unsigned int status;
  99. g_test_init (&argc, &argv, NULL);
  100. hb_test_add (test_ot_layout_feature_get_name_ids_and_characters);
  101. hb_test_add (test_ot_name);
  102. face = hb_test_open_font_file ("fonts/cv01.otf");
  103. status = hb_test_run ();
  104. hb_face_destroy (face);
  105. return status;
  106. }