test-ot-extents-cff.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Copyright © 2018 Adobe 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. * Adobe Author(s): Michiharu Ariza
  25. */
  26. #include "hb-test.h"
  27. #include <hb-ot.h>
  28. /* Unit tests for CFF/CFF2 glyph extents */
  29. static void
  30. test_extents_cff1 (void)
  31. {
  32. hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansPro-Regular.abc.otf");
  33. g_assert (face);
  34. hb_font_t *font = hb_font_create (face);
  35. hb_face_destroy (face);
  36. g_assert (font);
  37. hb_ot_font_set_funcs (font);
  38. hb_glyph_extents_t extents;
  39. hb_bool_t result = hb_font_get_glyph_extents (font, 1, &extents);
  40. g_assert (result);
  41. g_assert_cmpint (extents.x_bearing, ==, 52);
  42. g_assert_cmpint (extents.y_bearing, ==, 498);
  43. g_assert_cmpint (extents.width, ==, 381);
  44. g_assert_cmpint (extents.height, ==, -510);
  45. hb_font_destroy (font);
  46. hb_face_t *face_j = hb_test_open_font_file ("fonts/SourceHanSans-Regular.41,3041,4C2E.otf");
  47. g_assert (face_j);
  48. hb_font_t *font_j = hb_font_create (face_j);
  49. hb_face_destroy (face_j);
  50. g_assert (font_j);
  51. hb_ot_font_set_funcs (font_j);
  52. hb_bool_t result_j = hb_font_get_glyph_extents (font_j, 3, &extents);
  53. g_assert (result_j);
  54. g_assert_cmpint (extents.x_bearing, ==, 34);
  55. g_assert_cmpint (extents.y_bearing, ==, 840);
  56. g_assert_cmpint (extents.width, ==, 920);
  57. g_assert_cmpint (extents.height, ==, -907);
  58. hb_font_destroy (font_j);
  59. }
  60. static void
  61. test_extents_cff1_flex (void)
  62. {
  63. hb_face_t *face = hb_test_open_font_file ("fonts/cff1_flex.otf");
  64. g_assert (face);
  65. hb_font_t *font = hb_font_create (face);
  66. hb_face_destroy (face);
  67. g_assert (font);
  68. hb_ot_font_set_funcs (font);
  69. hb_glyph_extents_t extents;
  70. hb_bool_t result = hb_font_get_glyph_extents (font, 1, &extents);
  71. g_assert (result);
  72. g_assert_cmpint (extents.x_bearing, ==, -20);
  73. g_assert_cmpint (extents.y_bearing, ==, 520);
  74. g_assert_cmpint (extents.width, ==, 540);
  75. g_assert_cmpint (extents.height, ==, -540);
  76. hb_font_destroy (font);
  77. }
  78. static void
  79. test_extents_cff1_seac (void)
  80. {
  81. hb_face_t *face = hb_test_open_font_file ("fonts/cff1_seac.otf");
  82. g_assert (face);
  83. hb_font_t *font = hb_font_create (face);
  84. hb_face_destroy (face);
  85. g_assert (font);
  86. hb_ot_font_set_funcs (font);
  87. hb_glyph_extents_t extents;
  88. hb_bool_t result = hb_font_get_glyph_extents (font, 3, &extents); /* Agrave */
  89. g_assert (result);
  90. g_assert_cmpint (extents.x_bearing, ==, 3);
  91. g_assert_cmpint (extents.y_bearing, ==, 861);
  92. g_assert_cmpint (extents.width, ==, 538);
  93. g_assert_cmpint (extents.height, ==, -861);
  94. result = hb_font_get_glyph_extents (font, 4, &extents); /* Udieresis */
  95. g_assert (result);
  96. g_assert_cmpint (extents.x_bearing, ==, 87);
  97. g_assert_cmpint (extents.y_bearing, ==, 827);
  98. g_assert_cmpint (extents.width, ==, 471);
  99. g_assert_cmpint (extents.height, ==, -839);
  100. hb_font_destroy (font);
  101. }
  102. static void
  103. test_extents_cff2 (void)
  104. {
  105. hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype.abc.otf");
  106. g_assert (face);
  107. hb_font_t *font = hb_font_create (face);
  108. hb_face_destroy (face);
  109. g_assert (font);
  110. hb_ot_font_set_funcs (font);
  111. hb_glyph_extents_t extents;
  112. hb_bool_t result = hb_font_get_glyph_extents (font, 1, &extents);
  113. g_assert (result);
  114. g_assert_cmpint (extents.x_bearing, ==, 46);
  115. g_assert_cmpint (extents.y_bearing, ==, 487);
  116. g_assert_cmpint (extents.width, ==, 455);
  117. g_assert_cmpint (extents.height, ==, -500);
  118. float coords[2] = { 600.0f, 50.0f };
  119. hb_font_set_var_coords_design (font, coords, 2);
  120. result = hb_font_get_glyph_extents (font, 1, &extents);
  121. g_assert (result);
  122. g_assert_cmpint (extents.x_bearing, ==, 38);
  123. g_assert_cmpint (extents.y_bearing, ==, 493);
  124. g_assert_cmpint (extents.width, ==, 480);
  125. g_assert_cmpint (extents.height, ==, -507);
  126. hb_font_destroy (font);
  127. }
  128. static void
  129. test_extents_cff2_vsindex (void)
  130. {
  131. hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype_vsindex.otf");
  132. g_assert (face);
  133. hb_font_t *font = hb_font_create (face);
  134. hb_face_destroy (face);
  135. g_assert (font);
  136. hb_ot_font_set_funcs (font);
  137. hb_glyph_extents_t extents;
  138. float coords[2] = { 800.0f, 50.0f };
  139. hb_font_set_var_coords_design (font, coords, 2);
  140. hb_bool_t result = hb_font_get_glyph_extents (font, 1, &extents);
  141. g_assert (result);
  142. g_assert_cmpint (extents.x_bearing, ==, 12);
  143. g_assert_cmpint (extents.y_bearing, ==, 655);
  144. g_assert_cmpint (extents.width, ==, 651);
  145. g_assert_cmpint (extents.height, ==, -655);
  146. result = hb_font_get_glyph_extents (font, 2, &extents);
  147. g_assert (result);
  148. g_assert_cmpint (extents.x_bearing, ==, 8);
  149. g_assert_cmpint (extents.y_bearing, ==, 669);
  150. g_assert_cmpint (extents.width, ==, 648);
  151. g_assert_cmpint (extents.height, ==, -669);
  152. hb_font_destroy (font);
  153. }
  154. static void
  155. test_extents_cff2_vsindex_named_instance (void)
  156. {
  157. hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype_vsindex.otf");
  158. g_assert (face);
  159. hb_font_t *font = hb_font_create (face);
  160. hb_face_destroy (face);
  161. g_assert (font);
  162. hb_ot_font_set_funcs (font);
  163. hb_font_set_var_named_instance (font, 6); // 6 (BlackMediumContrast): 900, 50
  164. hb_glyph_extents_t extents;
  165. hb_bool_t result = hb_font_get_glyph_extents (font, 1, &extents);
  166. g_assert (result);
  167. g_assert_cmpint (extents.x_bearing, ==, 13);
  168. g_assert_cmpint (extents.y_bearing, ==, 652);
  169. g_assert_cmpint (extents.width, ==, 652);
  170. g_assert_cmpint (extents.height, ==, -652);
  171. result = hb_font_get_glyph_extents (font, 2, &extents);
  172. g_assert (result);
  173. g_assert_cmpint (extents.x_bearing, ==, 6);
  174. g_assert_cmpint (extents.y_bearing, ==, 675);
  175. g_assert_cmpint (extents.width, ==, 647);
  176. g_assert_cmpint (extents.height, ==, -675);
  177. hb_font_destroy (font);
  178. }
  179. int
  180. main (int argc, char **argv)
  181. {
  182. hb_test_init (&argc, &argv);
  183. hb_test_add (test_extents_cff1);
  184. hb_test_add (test_extents_cff1_flex);
  185. hb_test_add (test_extents_cff1_seac);
  186. hb_test_add (test_extents_cff2);
  187. hb_test_add (test_extents_cff2_vsindex);
  188. hb_test_add (test_extents_cff2_vsindex_named_instance);
  189. return hb_test_run ();
  190. }