test-extents.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_extents_color_v1 (void)
  29. {
  30. hb_face_t *face;
  31. hb_font_t *font;
  32. hb_glyph_extents_t extents;
  33. hb_bool_t ret;
  34. /* This font contains a COLRv1 glyph with a ClipBox,
  35. * and various components without. The main thing
  36. * we test here is that glyphs with no paint return
  37. * 0,0,0,0 and not meaningless numbers.
  38. */
  39. face = hb_test_open_font_file ("fonts/adwaita.ttf");
  40. font = hb_font_create (face);
  41. ret = hb_font_get_glyph_extents (font, 0, &extents);
  42. g_assert_true (ret);
  43. g_assert_true (extents.x_bearing == 0 &&
  44. extents.y_bearing == 0 &&
  45. extents.width == 0 &&
  46. extents.height == 0);
  47. ret = hb_font_get_glyph_extents (font, 1, &extents);
  48. g_assert_true (ret);
  49. g_assert_true (extents.x_bearing == 0 &&
  50. extents.y_bearing == 0 &&
  51. extents.width == 0 &&
  52. extents.height == 0);
  53. ret = hb_font_get_glyph_extents (font, 2, &extents);
  54. g_assert_true (ret);
  55. g_assert_true (extents.x_bearing == 180 &&
  56. extents.y_bearing == 960 &&
  57. extents.width == 1060 &&
  58. extents.height == -1220);
  59. ret = hb_font_get_glyph_extents (font, 3, &extents);
  60. g_assert_true (ret);
  61. g_assert_true (extents.x_bearing == 188 &&
  62. extents.y_bearing == 950 &&
  63. extents.width == 900 &&
  64. extents.height == -1200);
  65. ret = hb_font_get_glyph_extents (font, 4, &extents);
  66. g_assert_true (ret);
  67. g_assert_true (extents.x_bearing == 413 &&
  68. extents.y_bearing == 50 &&
  69. extents.width == 150 &&
  70. extents.height == -75);
  71. ret = hb_font_get_glyph_extents (font, 5, &extents);
  72. g_assert_true (ret);
  73. g_assert_true (extents.x_bearing == 638 &&
  74. extents.y_bearing == 350 &&
  75. extents.width == 600 &&
  76. extents.height == -600);
  77. ret = hb_font_get_glyph_extents (font, 1000, &extents);
  78. g_assert_false (ret);
  79. hb_font_destroy (font);
  80. hb_face_destroy (face);
  81. }
  82. static void
  83. test_glyph_extents_color_v0 (void)
  84. {
  85. hb_face_t *face;
  86. hb_font_t *font;
  87. hb_glyph_extents_t extents;
  88. hb_bool_t ret;
  89. /*
  90. * This font contains a COLRv0 glyph with an empty default glyph
  91. * to make sure we are getting extents from the COLRv0 layers.
  92. */
  93. face = hb_test_open_font_file ("fonts/COLRv0.extents.ttf");
  94. font = hb_font_create (face);
  95. ret = hb_font_get_glyph_extents (font, 13, &extents);
  96. g_assert_true (ret);
  97. g_assert_true (extents.x_bearing == 192 &&
  98. extents.y_bearing == 573 &&
  99. extents.width == 731 &&
  100. extents.height == -758);
  101. hb_font_destroy (font);
  102. hb_face_destroy (face);
  103. }
  104. int
  105. main (int argc, char **argv)
  106. {
  107. hb_test_init (&argc, &argv);
  108. hb_test_add (test_glyph_extents_color_v1);
  109. hb_test_add (test_glyph_extents_color_v0);
  110. return hb_test_run();
  111. }