test-ot-math.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. /*
  2. * Copyright © 2016 Igalia S.L.
  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. * Igalia Author(s): Frédéric Wang
  25. */
  26. #include "hb-test.h"
  27. #include "hb-ft.h"
  28. #include "hb-ot.h"
  29. /* Unit tests for hb-ot-math.h - OpenType MATH table */
  30. static FT_Library ft_library;
  31. static FT_Face ft_face;
  32. static hb_font_t *hb_font;
  33. static hb_face_t *hb_face;
  34. static inline void
  35. initFreeType (void)
  36. {
  37. FT_Error ft_error;
  38. if ((ft_error = FT_Init_FreeType (&ft_library)))
  39. abort();
  40. }
  41. static inline void
  42. cleanupFreeType (void)
  43. {
  44. FT_Done_FreeType (ft_library);
  45. }
  46. static void
  47. openFont(const char* fontFile)
  48. {
  49. #if GLIB_CHECK_VERSION(2,37,2)
  50. gchar* path = g_test_build_filename(G_TEST_DIST, fontFile, NULL);
  51. #else
  52. gchar* path = g_strdup(fontFile);
  53. #endif
  54. FT_Error ft_error;
  55. if ((ft_error = FT_New_Face (ft_library, path, 0, &ft_face))) {
  56. g_free(path);
  57. abort();
  58. }
  59. g_free(path);
  60. if ((ft_error = FT_Set_Char_Size (ft_face, 2000, 1000, 0, 0)))
  61. abort();
  62. hb_font = hb_ft_font_create (ft_face, NULL);
  63. hb_face = hb_face_reference (hb_font_get_face (hb_font));
  64. }
  65. static inline void
  66. closeFont (void)
  67. {
  68. hb_face_destroy (hb_face);
  69. hb_font_destroy (hb_font);
  70. FT_Done_Face (ft_face);
  71. hb_face = NULL;
  72. hb_font = NULL;
  73. ft_face = NULL;
  74. }
  75. static void
  76. test_has_data (void)
  77. {
  78. initFreeType();
  79. openFont("fonts/MathTestFontNone.otf");
  80. g_assert(!hb_ot_math_has_data (hb_face)); // MATH table not available
  81. closeFont();
  82. openFont("fonts/MathTestFontEmpty.otf");
  83. g_assert(hb_ot_math_has_data (hb_face)); // MATH table available
  84. closeFont();
  85. hb_face = hb_face_get_empty ();
  86. hb_font = hb_font_create (hb_face);
  87. g_assert(!hb_ot_math_has_data (hb_face)); // MATH table not available
  88. hb_font_destroy (hb_font);
  89. hb_face_destroy (hb_face);
  90. hb_font = hb_font_get_empty ();
  91. hb_face = hb_font_get_face (hb_font);
  92. g_assert(!hb_ot_math_has_data (hb_face)); // MATH table not available
  93. hb_font_destroy (hb_font);
  94. hb_face_destroy (hb_face);
  95. cleanupFreeType();
  96. }
  97. static void
  98. test_get_constant (void)
  99. {
  100. initFreeType();
  101. openFont("fonts/MathTestFontEmpty.otf");
  102. g_assert_cmpint(hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_DELIMITED_SUB_FORMULA_MIN_HEIGHT), ==, 0); // MathConstants not available
  103. closeFont();
  104. openFont("fonts/MathTestFontFull.otf");
  105. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_DELIMITED_SUB_FORMULA_MIN_HEIGHT)), ==, 100);
  106. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_DISPLAY_OPERATOR_MIN_HEIGHT)), ==, 200);
  107. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_MATH_LEADING)), ==, 300);
  108. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_AXIS_HEIGHT)), ==, 400);
  109. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_ACCENT_BASE_HEIGHT)), ==, 500);
  110. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_FLATTENED_ACCENT_BASE_HEIGHT)), ==, 600);
  111. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SUBSCRIPT_SHIFT_DOWN)), ==, 700);
  112. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SUBSCRIPT_TOP_MAX)), ==, 800);
  113. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SUBSCRIPT_BASELINE_DROP_MIN)), ==, 900);
  114. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SUPERSCRIPT_SHIFT_UP)), ==, 1100);
  115. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SUPERSCRIPT_SHIFT_UP_CRAMPED)), ==, 1200);
  116. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SUPERSCRIPT_BOTTOM_MIN)), ==, 1300);
  117. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SUPERSCRIPT_BASELINE_DROP_MAX)), ==, 1400);
  118. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SUB_SUPERSCRIPT_GAP_MIN)), ==, 1500);
  119. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SUPERSCRIPT_BOTTOM_MAX_WITH_SUBSCRIPT)), ==, 1600);
  120. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SPACE_AFTER_SCRIPT)), ==, 3400);
  121. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_UPPER_LIMIT_GAP_MIN)), ==, 1800);
  122. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_UPPER_LIMIT_BASELINE_RISE_MIN)), ==, 1900);
  123. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_LOWER_LIMIT_GAP_MIN)), ==, 2200);
  124. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_LOWER_LIMIT_BASELINE_DROP_MIN)), ==, 2300);
  125. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_STACK_TOP_SHIFT_UP)), ==, 2400);
  126. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_STACK_TOP_DISPLAY_STYLE_SHIFT_UP)), ==, 2500);
  127. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_STACK_BOTTOM_SHIFT_DOWN)), ==, 2600);
  128. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_STACK_BOTTOM_DISPLAY_STYLE_SHIFT_DOWN)), ==, 2700);
  129. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_STACK_GAP_MIN)), ==, 2800);
  130. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_STACK_DISPLAY_STYLE_GAP_MIN)), ==, 2900);
  131. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_STRETCH_STACK_TOP_SHIFT_UP)), ==, 3000);
  132. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_STRETCH_STACK_BOTTOM_SHIFT_DOWN)), ==, 3100);
  133. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_STRETCH_STACK_GAP_ABOVE_MIN)), ==, 3200);
  134. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_STRETCH_STACK_GAP_BELOW_MIN)), ==, 3300);
  135. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_FRACTION_NUMERATOR_SHIFT_UP)), ==, 3400);
  136. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_FRACTION_NUMERATOR_DISPLAY_STYLE_SHIFT_UP)), ==, 3500);
  137. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_FRACTION_DENOMINATOR_SHIFT_DOWN)), ==, 3600);
  138. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_FRACTION_DENOMINATOR_DISPLAY_STYLE_SHIFT_DOWN)), ==, 3700);
  139. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_FRACTION_NUMERATOR_GAP_MIN)), ==, 3800);
  140. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_FRACTION_NUM_DISPLAY_STYLE_GAP_MIN)), ==, 3900);
  141. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_FRACTION_RULE_THICKNESS)), ==, 4000);
  142. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_FRACTION_DENOMINATOR_GAP_MIN)), ==, 4100);
  143. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_FRACTION_DENOM_DISPLAY_STYLE_GAP_MIN)), ==, 4200);
  144. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SKEWED_FRACTION_HORIZONTAL_GAP)), ==, 8600);
  145. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SKEWED_FRACTION_VERTICAL_GAP)), ==, 4400);
  146. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_OVERBAR_VERTICAL_GAP)), ==, 4500);
  147. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_OVERBAR_RULE_THICKNESS)), ==, 4600);
  148. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_OVERBAR_EXTRA_ASCENDER)), ==, 4700);
  149. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_UNDERBAR_VERTICAL_GAP)), ==, 4800);
  150. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_UNDERBAR_RULE_THICKNESS)), ==, 4900);
  151. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_UNDERBAR_EXTRA_DESCENDER)), ==, 5000);
  152. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_RADICAL_VERTICAL_GAP)), ==, 5100);
  153. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_RADICAL_DISPLAY_STYLE_VERTICAL_GAP)), ==, 5200);
  154. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_RADICAL_RULE_THICKNESS)), ==, 5300);
  155. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_RADICAL_EXTRA_ASCENDER)), ==, 5400);
  156. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_RADICAL_KERN_BEFORE_DEGREE)), ==, 11000);
  157. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_RADICAL_KERN_AFTER_DEGREE)), ==, 11200);
  158. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN)), ==, 87);
  159. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_SCRIPT_SCRIPT_PERCENT_SCALE_DOWN)), ==, 76);
  160. g_assert_cmpint((hb_ot_math_get_constant (hb_font, HB_OT_MATH_CONSTANT_RADICAL_DEGREE_BOTTOM_RAISE_PERCENT)), ==, 65);
  161. closeFont();
  162. cleanupFreeType();
  163. }
  164. static void
  165. test_get_glyph_italics_correction (void)
  166. {
  167. hb_codepoint_t glyph;
  168. initFreeType();
  169. openFont("fonts/MathTestFontEmpty.otf");
  170. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  171. g_assert_cmpint(hb_ot_math_get_glyph_italics_correction (hb_font, glyph), ==, 0); // MathGlyphInfo not available
  172. closeFont();
  173. openFont("fonts/MathTestFontPartial1.otf");
  174. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  175. g_assert_cmpint(hb_ot_math_get_glyph_italics_correction (hb_font, glyph), ==, 0); // MathGlyphInfo empty
  176. closeFont();
  177. openFont("fonts/MathTestFontPartial2.otf");
  178. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  179. g_assert_cmpint(hb_ot_math_get_glyph_italics_correction (hb_font, glyph), ==, 0); // MathItalicsCorrectionInfo empty
  180. closeFont();
  181. openFont("fonts/MathTestFontFull.otf");
  182. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  183. g_assert_cmpint(hb_ot_math_get_glyph_italics_correction (hb_font, glyph), ==, 0); // Glyph without italic correction.
  184. g_assert(hb_font_get_glyph_from_name (hb_font, "A", -1, &glyph));
  185. g_assert_cmpint(hb_ot_math_get_glyph_italics_correction (hb_font, glyph), ==, 394);
  186. g_assert(hb_font_get_glyph_from_name (hb_font, "B", -1, &glyph));
  187. g_assert_cmpint(hb_ot_math_get_glyph_italics_correction (hb_font, glyph), ==, 300);
  188. g_assert(hb_font_get_glyph_from_name (hb_font, "C", -1, &glyph));
  189. g_assert_cmpint(hb_ot_math_get_glyph_italics_correction (hb_font, glyph), ==, 904);
  190. closeFont();
  191. cleanupFreeType();
  192. }
  193. static void
  194. test_get_glyph_top_accent_attachment (void)
  195. {
  196. hb_codepoint_t glyph;
  197. initFreeType();
  198. openFont("fonts/MathTestFontEmpty.otf");
  199. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  200. g_assert_cmpint(hb_ot_math_get_glyph_top_accent_attachment (hb_font, glyph), ==, 1000); // MathGlyphInfo not available
  201. closeFont();
  202. openFont("fonts/MathTestFontPartial1.otf");
  203. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  204. g_assert_cmpint(hb_ot_math_get_glyph_top_accent_attachment (hb_font, glyph), ==, 1000); // MathGlyphInfo empty
  205. closeFont();
  206. openFont("fonts/MathTestFontPartial2.otf");
  207. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  208. g_assert_cmpint(hb_ot_math_get_glyph_top_accent_attachment (hb_font, glyph), ==, 1000); // MathTopAccentAttachment empty
  209. closeFont();
  210. openFont("fonts/MathTestFontFull.otf");
  211. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  212. g_assert_cmpint(hb_ot_math_get_glyph_top_accent_attachment (hb_font, glyph), ==, 1000); // Glyph without top accent attachment.
  213. g_assert(hb_font_get_glyph_from_name (hb_font, "D", -1, &glyph));
  214. g_assert_cmpint(hb_ot_math_get_glyph_top_accent_attachment (hb_font, glyph), ==, 748);
  215. g_assert(hb_font_get_glyph_from_name (hb_font, "E", -1, &glyph));
  216. g_assert_cmpint(hb_ot_math_get_glyph_top_accent_attachment (hb_font, glyph), ==, 692);
  217. g_assert(hb_font_get_glyph_from_name (hb_font, "F", -1, &glyph));
  218. g_assert_cmpint(hb_ot_math_get_glyph_top_accent_attachment (hb_font, glyph), ==, 636);
  219. closeFont();
  220. cleanupFreeType();
  221. }
  222. static void
  223. test_is_glyph_extended_shape (void)
  224. {
  225. hb_codepoint_t glyph;
  226. initFreeType();
  227. openFont("fonts/MathTestFontEmpty.otf");
  228. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  229. g_assert(!hb_ot_math_is_glyph_extended_shape (hb_face, glyph)); // MathGlyphInfo not available
  230. closeFont();
  231. openFont("fonts/MathTestFontPartial1.otf");
  232. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  233. g_assert(!hb_ot_math_is_glyph_extended_shape (hb_face, glyph)); // MathGlyphInfo empty
  234. closeFont();
  235. openFont("fonts/MathTestFontFull.otf");
  236. g_assert(hb_font_get_glyph_from_name (hb_font, "G", -1, &glyph));
  237. g_assert(!hb_ot_math_is_glyph_extended_shape (hb_face, glyph));
  238. g_assert(hb_font_get_glyph_from_name (hb_font, "H", -1, &glyph));
  239. g_assert(hb_ot_math_is_glyph_extended_shape (hb_face, glyph));
  240. closeFont();
  241. cleanupFreeType();
  242. }
  243. static void
  244. test_get_glyph_kerning (void)
  245. {
  246. hb_codepoint_t glyph;
  247. initFreeType();
  248. openFont("fonts/MathTestFontEmpty.otf");
  249. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  250. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 0), ==, 0); // MathGlyphInfo not available
  251. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_LEFT, 0), ==, 0); // MathGlyphInfo not available
  252. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0), ==, 0); // MathGlyphInfo not available
  253. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_LEFT, 0), ==, 0); // MathGlyphInfo not available
  254. closeFont();
  255. openFont("fonts/MathTestFontPartial2.otf");
  256. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  257. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 0), ==, 0); // MathKernInfo empty
  258. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_LEFT, 0), ==, 0); // MathKernInfo empty
  259. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0), ==, 0); // MathKernInfo empty
  260. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_LEFT, 0), ==, 0); // MathKernInfo empty
  261. closeFont();
  262. openFont("fonts/MathTestFontPartial3.otf");
  263. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  264. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 0), ==, 0); // MathKernInfoRecords empty
  265. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_LEFT, 0), ==, 0); // MathKernInfoRecords empty
  266. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0), ==, 0); // MathKernInfoRecords empty
  267. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_LEFT, 0), ==, 0); // MathKernInfoRecords empty
  268. closeFont();
  269. openFont("fonts/MathTestFontFull.otf");
  270. g_assert(hb_font_get_glyph_from_name (hb_font, "I", -1, &glyph));
  271. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 7), ==, 62); // lower than min height
  272. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 14), ==, 104); // equal to min height
  273. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 20), ==, 104);
  274. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 23), ==, 146);
  275. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 31), ==, 146);
  276. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 32), ==, 188);
  277. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 86), ==, 440); // equal to max height
  278. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 91), ==, 440); // larger than max height
  279. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 96), ==, 440); // larger than max height
  280. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 39), ==, 188); // top right
  281. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_TOP_LEFT, 39), ==, 110); // top left
  282. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_RIGHT, 39), ==, 44); // bottom right
  283. g_assert_cmpint(hb_ot_math_get_glyph_kerning (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_LEFT, 39), ==, 100); // bottom left
  284. closeFont();
  285. cleanupFreeType();
  286. }
  287. static void
  288. test_get_glyph_kernings (void)
  289. {
  290. hb_codepoint_t glyph;
  291. hb_ot_math_kern_entry_t entries[20];
  292. const unsigned entries_size = sizeof (entries) / sizeof (entries[0]);
  293. unsigned int count;
  294. initFreeType();
  295. openFont("fonts/MathTestFontEmpty.otf");
  296. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  297. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 0, NULL, NULL), ==, 0); // MathGlyphInfo not available
  298. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_TOP_LEFT, 0, NULL, NULL), ==, 0); // MathGlyphInfo not available
  299. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0, NULL, NULL), ==, 0); // MathGlyphInfo not available
  300. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_LEFT, 0, NULL, NULL), ==, 0); // MathGlyphInfo not available
  301. closeFont();
  302. openFont("fonts/MathTestFontPartial2.otf");
  303. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  304. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 0, NULL, NULL), ==, 0); // MathKernInfo empty
  305. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_TOP_LEFT, 0, NULL, NULL), ==, 0); // MathKernInfo empty
  306. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0, NULL, NULL), ==, 0); // MathKernInfo empty
  307. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_LEFT, 0, NULL, NULL), ==, 0); // MathKernInfo empty
  308. closeFont();
  309. openFont("fonts/MathTestFontPartial3.otf");
  310. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  311. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 0, NULL, NULL), ==, 0); // MathKernInfoRecords empty
  312. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_TOP_LEFT, 0, NULL, NULL), ==, 0); // MathKernInfoRecords empty
  313. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0, NULL, NULL), ==, 0); // MathKernInfoRecords empty
  314. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_LEFT, 0, NULL, NULL), ==, 0); // MathKernInfoRecords empty
  315. closeFont();
  316. openFont("fonts/MathTestFontFull.otf");
  317. g_assert(hb_font_get_glyph_from_name (hb_font, "I", -1, &glyph));
  318. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 0, NULL, NULL), ==, 10);
  319. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_TOP_LEFT, 0, NULL, NULL), ==, 3);
  320. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_RIGHT, 0, NULL, NULL), ==, 9);
  321. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_BOTTOM_LEFT, 0, NULL, NULL), ==, 7);
  322. count = entries_size;
  323. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_TOP_RIGHT, 0, &count, entries), ==, 10);
  324. g_assert_cmpint(count, ==, 10);
  325. g_assert_cmpint(entries[0].max_correction_height, ==, 14);
  326. g_assert_cmpint(entries[0].kern_value, ==, 62);
  327. g_assert_cmpint(entries[1].max_correction_height, ==, 23);
  328. g_assert_cmpint(entries[1].kern_value, ==, 104);
  329. g_assert_cmpint(entries[2].max_correction_height, ==, 32);
  330. g_assert_cmpint(entries[2].kern_value, ==, 146);
  331. g_assert_cmpint(entries[3].max_correction_height, ==, 41);
  332. g_assert_cmpint(entries[3].kern_value, ==, 188);
  333. g_assert_cmpint(entries[4].max_correction_height, ==, 50);
  334. g_assert_cmpint(entries[4].kern_value, ==, 230);
  335. g_assert_cmpint(entries[5].max_correction_height, ==, 59);
  336. g_assert_cmpint(entries[5].kern_value, ==, 272);
  337. g_assert_cmpint(entries[6].max_correction_height, ==, 68);
  338. g_assert_cmpint(entries[6].kern_value, ==, 314);
  339. g_assert_cmpint(entries[7].max_correction_height, ==, 77);
  340. g_assert_cmpint(entries[7].kern_value, ==, 356);
  341. g_assert_cmpint(entries[8].max_correction_height, ==, 86);
  342. g_assert_cmpint(entries[8].kern_value, ==, 398);
  343. g_assert_cmpint(entries[9].max_correction_height, ==, INT32_MAX);
  344. g_assert_cmpint(entries[9].kern_value, ==, 440);
  345. count = entries_size;
  346. g_assert_cmpint(hb_ot_math_get_glyph_kernings (hb_font, glyph, HB_OT_MATH_KERN_TOP_LEFT, 0, &count, entries), ==, 3);
  347. g_assert_cmpint(count, ==, 3);
  348. g_assert_cmpint(entries[0].max_correction_height, ==, 20);
  349. g_assert_cmpint(entries[0].kern_value, ==, 50);
  350. g_assert_cmpint(entries[1].max_correction_height, ==, 35);
  351. g_assert_cmpint(entries[1].kern_value, ==, 80);
  352. g_assert_cmpint(entries[2].max_correction_height, ==, INT32_MAX);
  353. g_assert_cmpint(entries[2].kern_value, ==, 110);
  354. closeFont();
  355. cleanupFreeType();
  356. }
  357. static hb_position_t
  358. get_glyph_assembly_italics_correction (hb_font_t *font,
  359. hb_codepoint_t glyph,
  360. hb_bool_t horizontal)
  361. {
  362. hb_position_t corr;
  363. hb_ot_math_get_glyph_assembly (font, glyph,
  364. horizontal ? HB_DIRECTION_LTR : HB_DIRECTION_TTB,
  365. 0, NULL, NULL,
  366. &corr);
  367. return corr;
  368. }
  369. static void
  370. test_get_glyph_assembly_italics_correction (void)
  371. {
  372. hb_codepoint_t glyph;
  373. initFreeType();
  374. openFont("fonts/MathTestFontEmpty.otf");
  375. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  376. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, TRUE), ==, 0); // MathVariants not available
  377. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, FALSE), ==, 0); // MathVariants not available
  378. closeFont();
  379. openFont("fonts/MathTestFontPartial1.otf");
  380. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  381. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, TRUE), ==, 0); // VertGlyphCoverage and HorizGlyphCoverage absent
  382. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, FALSE), ==, 0); // VertGlyphCoverage and HorizGlyphCoverage absent
  383. closeFont();
  384. openFont("fonts/MathTestFontPartial2.otf");
  385. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  386. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, TRUE), ==, 0); // VertGlyphCoverage and HorizGlyphCoverage empty
  387. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, FALSE), ==, 0); // VertGlyphCoverage and HorizGlyphCoverage empty
  388. closeFont();
  389. openFont("fonts/MathTestFontPartial3.otf");
  390. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  391. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, TRUE), ==, 0); // HorizGlyphConstruction and VertGlyphConstruction empty
  392. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, FALSE), ==, 0); // HorizGlyphConstruction and VertGlyphConstruction empty
  393. closeFont();
  394. openFont("fonts/MathTestFontPartial4.otf");
  395. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  396. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, TRUE), ==, 0);
  397. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, FALSE), ==, 0);
  398. closeFont();
  399. openFont("fonts/MathTestFontFull.otf");
  400. g_assert(hb_font_get_glyph_from_name (hb_font, "arrowleft", -1, &glyph));
  401. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, TRUE), ==, 248);
  402. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, FALSE), ==, 0);
  403. g_assert(hb_font_get_glyph_from_name (hb_font, "arrowup", -1, &glyph));
  404. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, TRUE), ==, 0);
  405. g_assert_cmpint(get_glyph_assembly_italics_correction (hb_font, glyph, FALSE), ==, 662);
  406. closeFont();
  407. cleanupFreeType();
  408. }
  409. static void
  410. test_get_min_connector_overlap (void)
  411. {
  412. initFreeType();
  413. openFont("fonts/MathTestFontEmpty.otf");
  414. g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, HB_DIRECTION_LTR), ==, 0); // MathVariants not available
  415. g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, HB_DIRECTION_TTB), ==, 0); // MathVariants not available
  416. closeFont();
  417. openFont("fonts/MathTestFontPartial1.otf");
  418. g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, HB_DIRECTION_LTR), ==, 108);
  419. g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, HB_DIRECTION_TTB), ==, 54);
  420. closeFont();
  421. cleanupFreeType();
  422. }
  423. static void
  424. test_get_glyph_variants (void)
  425. {
  426. hb_codepoint_t glyph;
  427. hb_ot_math_glyph_variant_t variants[20];
  428. unsigned variantsSize = sizeof (variants) / sizeof (variants[0]);
  429. unsigned int count;
  430. unsigned int offset = 0;
  431. initFreeType();
  432. openFont("fonts/MathTestFontEmpty.otf");
  433. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  434. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL), ==, 0);
  435. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL), ==, 0);
  436. closeFont();
  437. openFont("fonts/MathTestFontPartial1.otf");
  438. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  439. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL), ==, 0);
  440. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL), ==, 0);
  441. closeFont();
  442. openFont("fonts/MathTestFontPartial2.otf");
  443. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  444. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL), ==, 0);
  445. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL), ==, 0);
  446. closeFont();
  447. openFont("fonts/MathTestFontPartial3.otf");
  448. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  449. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL), ==, 0);
  450. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL), ==, 0);
  451. closeFont();
  452. openFont("fonts/MathTestFontPartial4.otf");
  453. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  454. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL), ==, 0);
  455. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL), ==, 0);
  456. closeFont();
  457. openFont("fonts/MathTestFontFull.otf");
  458. g_assert(hb_font_get_glyph_from_name (hb_font, "arrowleft", -1, &glyph));
  459. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font,
  460. glyph,
  461. HB_DIRECTION_BTT,
  462. 0,
  463. NULL,
  464. NULL), ==, 0);
  465. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font,
  466. glyph,
  467. HB_DIRECTION_RTL,
  468. 0,
  469. NULL,
  470. NULL), ==, 3);
  471. g_assert(hb_font_get_glyph_from_name (hb_font, "arrowup", -1, &glyph));
  472. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font,
  473. glyph,
  474. HB_DIRECTION_BTT,
  475. 0,
  476. NULL,
  477. NULL), ==, 4);
  478. g_assert_cmpint(hb_ot_math_get_glyph_variants (hb_font,
  479. glyph,
  480. HB_DIRECTION_RTL,
  481. 0,
  482. NULL,
  483. NULL), ==, 0);
  484. g_assert(hb_font_get_glyph_from_name (hb_font, "arrowleft", -1, &glyph));
  485. do {
  486. count = variantsSize;
  487. hb_ot_math_get_glyph_variants (hb_font,
  488. glyph,
  489. HB_DIRECTION_RTL,
  490. offset,
  491. &count,
  492. variants);
  493. offset += count;
  494. } while (count == variantsSize);
  495. g_assert_cmpint(offset, ==, 3);
  496. g_assert(hb_font_get_glyph_from_name (hb_font, "uni2190_size2", -1, &glyph));
  497. g_assert_cmpint(variants[0].glyph, ==, glyph);
  498. g_assert_cmpint(variants[0].advance, ==, 4302);
  499. g_assert(hb_font_get_glyph_from_name (hb_font, "uni2190_size3", -1, &glyph));
  500. g_assert_cmpint(variants[1].glyph, ==, glyph);
  501. g_assert_cmpint(variants[1].advance, ==, 4802);
  502. g_assert(hb_font_get_glyph_from_name (hb_font, "uni2190_size4", -1, &glyph));
  503. g_assert_cmpint(variants[2].glyph, ==, glyph);
  504. g_assert_cmpint(variants[2].advance, ==, 5802);
  505. g_assert(hb_font_get_glyph_from_name (hb_font, "arrowup", -1, &glyph));
  506. offset = 0;
  507. do {
  508. count = variantsSize;
  509. hb_ot_math_get_glyph_variants (hb_font,
  510. glyph,
  511. HB_DIRECTION_BTT,
  512. offset,
  513. &count,
  514. variants);
  515. offset += count;
  516. } while (count == variantsSize);
  517. g_assert_cmpint(offset, ==, 4);
  518. g_assert(hb_font_get_glyph_from_name (hb_font, "uni2191_size2", -1, &glyph));
  519. g_assert_cmpint(variants[0].glyph, ==, glyph);
  520. g_assert_cmpint(variants[0].advance, ==, 2251);
  521. g_assert(hb_font_get_glyph_from_name (hb_font, "uni2191_size3", -1, &glyph));
  522. g_assert_cmpint(variants[1].glyph, ==, glyph);
  523. g_assert_cmpint(variants[1].advance, ==, 2501);
  524. g_assert(hb_font_get_glyph_from_name (hb_font, "uni2191_size4", -1, &glyph));
  525. g_assert_cmpint(variants[2].glyph, ==, glyph);
  526. g_assert_cmpint(variants[2].advance, ==, 3001);
  527. g_assert(hb_font_get_glyph_from_name (hb_font, "uni2191_size5", -1, &glyph));
  528. g_assert_cmpint(variants[3].glyph, ==, glyph);
  529. g_assert_cmpint(variants[3].advance, ==, 3751);
  530. closeFont();
  531. cleanupFreeType();
  532. }
  533. static void
  534. test_get_glyph_assembly (void)
  535. {
  536. hb_codepoint_t glyph;
  537. hb_ot_math_glyph_part_t parts[20];
  538. unsigned partsSize = sizeof (parts) / sizeof (parts[0]);
  539. unsigned int count;
  540. unsigned int offset = 0;
  541. initFreeType();
  542. openFont("fonts/MathTestFontEmpty.otf");
  543. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  544. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL, NULL), ==, 0);
  545. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL, NULL), ==, 0);
  546. closeFont();
  547. openFont("fonts/MathTestFontPartial1.otf");
  548. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  549. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL, NULL), ==, 0);
  550. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL, NULL), ==, 0);
  551. closeFont();
  552. openFont("fonts/MathTestFontPartial2.otf");
  553. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  554. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL, NULL), ==, 0);
  555. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL, NULL), ==, 0);
  556. closeFont();
  557. openFont("fonts/MathTestFontPartial3.otf");
  558. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  559. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL, NULL), ==, 0);
  560. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL, NULL), ==, 0);
  561. closeFont();
  562. openFont("fonts/MathTestFontPartial4.otf");
  563. g_assert(hb_font_get_glyph_from_name (hb_font, "space", -1, &glyph));
  564. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_RTL, 0, NULL, NULL, NULL), ==, 0);
  565. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font, glyph, HB_DIRECTION_BTT, 0, NULL, NULL, NULL), ==, 0);
  566. closeFont();
  567. openFont("fonts/MathTestFontFull.otf");
  568. g_assert(hb_font_get_glyph_from_name (hb_font, "arrowright", -1, &glyph));
  569. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font,
  570. glyph,
  571. HB_DIRECTION_BTT,
  572. 0,
  573. NULL,
  574. NULL,
  575. NULL), ==, 0);
  576. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font,
  577. glyph,
  578. HB_DIRECTION_RTL,
  579. 0,
  580. NULL,
  581. NULL,
  582. NULL), ==, 3);
  583. g_assert(hb_font_get_glyph_from_name (hb_font, "arrowdown", -1, &glyph));
  584. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font,
  585. glyph,
  586. HB_DIRECTION_BTT,
  587. 0,
  588. NULL,
  589. NULL,
  590. NULL), ==, 5);
  591. g_assert_cmpint(hb_ot_math_get_glyph_assembly (hb_font,
  592. glyph,
  593. HB_DIRECTION_RTL,
  594. 0,
  595. NULL,
  596. NULL,
  597. NULL), ==, 0);
  598. g_assert(hb_font_get_glyph_from_name (hb_font, "arrowright", -1, &glyph));
  599. do {
  600. count = partsSize;
  601. hb_ot_math_get_glyph_assembly (hb_font,
  602. glyph,
  603. HB_DIRECTION_RTL,
  604. offset,
  605. &count,
  606. parts,
  607. NULL);
  608. offset += count;
  609. } while (count == partsSize);
  610. g_assert_cmpint(offset, ==, 3);
  611. g_assert(hb_font_get_glyph_from_name (hb_font, "left", -1, &glyph));
  612. g_assert_cmpint(parts[0].glyph, ==, glyph);
  613. g_assert_cmpint(parts[0].start_connector_length, ==, 800);
  614. g_assert_cmpint(parts[0].end_connector_length, ==, 384);
  615. g_assert_cmpint(parts[0].full_advance, ==, 2000);
  616. g_assert(!(parts[0].flags & HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER));
  617. g_assert(hb_font_get_glyph_from_name (hb_font, "horizontal", -1, &glyph));
  618. g_assert_cmpint(parts[1].glyph, ==, glyph);
  619. g_assert_cmpint(parts[1].start_connector_length, ==, 524);
  620. g_assert_cmpint(parts[1].end_connector_length, ==, 800);
  621. g_assert_cmpint(parts[1].full_advance, ==, 2000);
  622. g_assert(parts[1].flags & HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER);
  623. g_assert(hb_font_get_glyph_from_name (hb_font, "right", -1, &glyph));
  624. g_assert_cmpint(parts[2].glyph, ==, glyph);
  625. g_assert_cmpint(parts[2].start_connector_length, ==, 316);
  626. g_assert_cmpint(parts[2].end_connector_length, ==, 454);
  627. g_assert_cmpint(parts[2].full_advance, ==, 2000);
  628. g_assert(!(parts[2].flags & HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER));
  629. g_assert(hb_font_get_glyph_from_name (hb_font, "arrowdown", -1, &glyph));
  630. offset = 0;
  631. do {
  632. count = partsSize;
  633. hb_ot_math_get_glyph_assembly (hb_font,
  634. glyph,
  635. HB_DIRECTION_BTT,
  636. offset,
  637. &count,
  638. parts,
  639. NULL);
  640. offset += count;
  641. } while (count == partsSize);
  642. g_assert_cmpint(offset, ==, 5);
  643. g_assert(hb_font_get_glyph_from_name (hb_font, "bottom", -1, &glyph));
  644. g_assert_cmpint(parts[0].glyph, ==, glyph);
  645. g_assert_cmpint(parts[0].start_connector_length, ==, 365);
  646. g_assert_cmpint(parts[0].end_connector_length, ==, 158);
  647. g_assert_cmpint(parts[0].full_advance, ==, 1000);
  648. g_assert(!(parts[0].flags & HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER));
  649. g_assert(hb_font_get_glyph_from_name (hb_font, "vertical", -1, &glyph));
  650. g_assert_cmpint(parts[1].glyph, ==, glyph);
  651. g_assert_cmpint(parts[1].start_connector_length, ==, 227);
  652. g_assert_cmpint(parts[1].end_connector_length, ==, 365);
  653. g_assert_cmpint(parts[1].full_advance, ==, 1000);
  654. g_assert(parts[1].flags & HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER);
  655. g_assert(hb_font_get_glyph_from_name (hb_font, "center", -1, &glyph));
  656. g_assert_cmpint(parts[2].glyph, ==, glyph);
  657. g_assert_cmpint(parts[2].start_connector_length, ==, 54);
  658. g_assert_cmpint(parts[2].end_connector_length, ==, 158);
  659. g_assert_cmpint(parts[2].full_advance, ==, 1000);
  660. g_assert(!(parts[2].flags & HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER));
  661. g_assert(hb_font_get_glyph_from_name (hb_font, "vertical", -1, &glyph));
  662. g_assert_cmpint(parts[3].glyph, ==, glyph);
  663. g_assert_cmpint(parts[3].start_connector_length, ==, 400);
  664. g_assert_cmpint(parts[3].end_connector_length, ==, 296);
  665. g_assert_cmpint(parts[3].full_advance, ==, 1000);
  666. g_assert(parts[1].flags & HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER);
  667. g_assert(hb_font_get_glyph_from_name (hb_font, "top", -1, &glyph));
  668. g_assert_cmpint(parts[4].glyph, ==, glyph);
  669. g_assert_cmpint(parts[4].start_connector_length, ==, 123);
  670. g_assert_cmpint(parts[4].end_connector_length, ==, 192);
  671. g_assert_cmpint(parts[4].full_advance, ==, 1000);
  672. g_assert(!(parts[4].flags & HB_OT_MATH_GLYPH_PART_FLAG_EXTENDER));
  673. closeFont();
  674. cleanupFreeType();
  675. }
  676. int
  677. main (int argc, char **argv)
  678. {
  679. hb_test_init (&argc, &argv);
  680. hb_test_add (test_has_data);
  681. hb_test_add (test_get_constant);
  682. hb_test_add (test_get_glyph_italics_correction);
  683. hb_test_add (test_get_glyph_top_accent_attachment);
  684. hb_test_add (test_is_glyph_extended_shape);
  685. hb_test_add (test_get_glyph_kerning);
  686. hb_test_add (test_get_glyph_kernings);
  687. hb_test_add (test_get_glyph_assembly_italics_correction);
  688. hb_test_add (test_get_min_connector_overlap);
  689. hb_test_add (test_get_glyph_variants);
  690. hb_test_add (test_get_glyph_assembly);
  691. return hb_test_run();
  692. }