test-glyph-names.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright © 2023 Red Hat, 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. * Author(s): Matthias Clasen
  25. */
  26. #include "hb-test.h"
  27. static void
  28. test_glyph_names_post (void)
  29. {
  30. hb_face_t *face;
  31. hb_font_t *font;
  32. hb_bool_t ret;
  33. char name [64];
  34. face = hb_test_open_font_file ("fonts/adwaita.ttf");
  35. font = hb_font_create (face);
  36. ret = hb_font_get_glyph_name (font, 0, name, 64);
  37. g_assert_true (ret);
  38. g_assert_cmpstr (name, ==, ".notdef");
  39. ret = hb_font_get_glyph_name (font, 1, name, 64);
  40. g_assert_true (ret);
  41. g_assert_cmpstr (name, ==, ".space");
  42. ret = hb_font_get_glyph_name (font, 2, name, 64);
  43. g_assert_true (ret);
  44. g_assert_cmpstr (name, ==, "icon0");
  45. ret = hb_font_get_glyph_name (font, 3, name, 64);
  46. g_assert_true (ret);
  47. g_assert_cmpstr (name, ==, "icon0.0");
  48. ret = hb_font_get_glyph_name (font, 4, name, 64);
  49. g_assert_true (ret);
  50. g_assert_cmpstr (name, ==, "icon0.1");
  51. ret = hb_font_get_glyph_name (font, 5, name, 64);
  52. g_assert_true (ret);
  53. g_assert_cmpstr (name, ==, "icon0.2");
  54. /* beyond last glyph */
  55. ret = hb_font_get_glyph_name (font, 100, name, 64);
  56. g_assert_false (ret);
  57. hb_font_destroy (font);
  58. hb_face_destroy (face);
  59. }
  60. static void
  61. test_glyph_names_cff (void)
  62. {
  63. hb_face_t *face;
  64. hb_font_t *font;
  65. hb_bool_t ret;
  66. char name [64];
  67. face = hb_test_open_font_file ("fonts/SourceSansPro-Regular.otf");
  68. font = hb_font_create (face);
  69. ret = hb_font_get_glyph_name (font, 0, name, 64);
  70. g_assert_true (ret);
  71. g_assert_cmpstr (name, ==, ".notdef");
  72. ret = hb_font_get_glyph_name (font, 1, name, 64);
  73. g_assert_true (ret);
  74. g_assert_cmpstr (name, ==, "space");
  75. ret = hb_font_get_glyph_name (font, 2, name, 64);
  76. g_assert_true (ret);
  77. g_assert_cmpstr (name, ==, "A");
  78. /* beyond last glyph */
  79. ret = hb_font_get_glyph_name (font, 2000, name, 64);
  80. g_assert_false (ret);
  81. hb_font_destroy (font);
  82. hb_face_destroy (face);
  83. }
  84. int
  85. main (int argc, char **argv)
  86. {
  87. hb_test_init (&argc, &argv);
  88. hb_test_add (test_glyph_names_post);
  89. hb_test_add (test_glyph_names_cff);
  90. return hb_test_run();
  91. }