test-be-glyph-advance.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright © 2022 Behdad Esfahbod
  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. #include "hb-test.h"
  25. #include <hb.h>
  26. static void
  27. test_maxp_and_hmtx (void)
  28. {
  29. hb_face_t *face;
  30. hb_font_t *font;
  31. const char maxp_data[] = "\x00\x00\x50\x00" // version
  32. "\x00\x05" // numGlyphs
  33. ;
  34. const char loca_data[18] = "";
  35. const char hhea_data[36] =
  36. "\x00\x01\x00\x00" /* FixedVersion<>version; * 0x00010000u for version 1.0. */
  37. "\x02\x00" /* FWORD ascender; * Typographic ascent. */
  38. "\x00\x10" /* FWORD descender; * Typographic descent. */
  39. "\x00\x00" /* FWORD lineGap; * Typographic line gap. */
  40. "\x00\x00" /* UFWORD advanceMax; * Maximum advance width/height value in metrics table. */
  41. "\x00\x00" /* FWORD minLeadingBearing; * Minimum left/top sidebearing value in metrics table. */
  42. "\x00\x00" /* FWORD minTrailingBearing; * Minimum right/bottom sidebearing value; */
  43. "\x01\x00" /* FWORD maxExtent; * horizontal: Max(lsb + (xMax - xMin)), */
  44. "\x00\x00" /* HBINT16 caretSlopeRise; * Used to calculate the slope of the,*/
  45. "\x00\x00" /* HBINT16 caretSlopeRun; * 0 for vertical caret, 1 for horizontal. */
  46. "\x00\x00" /* HBINT16 caretOffset; * The amount by which a slanted */
  47. "\x00\x00" /* HBINT16 reserved1; * Set to 0. */
  48. "\x00\x00" /* HBINT16 reserved2; * Set to 0. */
  49. "\x00\x00" /* HBINT16 reserved3; * Set to 0. */
  50. "\x00\x00" /* HBINT16 reserved4; * Set to 0. */
  51. "\x00\x00" /* HBINT16 metricDataFormat; * 0 for current format. */
  52. "\x00\x02" /* HBUINT16 numberOfLongMetrics; * Number of LongMetric entries in metric table. */
  53. ;
  54. const char hmtx_data[18] =
  55. "\x00\x01\x00\x02" /* glyph 0 advance lsb */
  56. "\x00\x03\x00\x04" /* glyph 1 advance lsb */
  57. "\x00\x05" /* glyph 2 lsb */
  58. "\x00\x06" /* glyph 3 lsb */
  59. "\x00\x07" /* glyph 4 lsb */
  60. "\x00\x08" /* glyph 5 advance */
  61. "\x00\x09" /* glyph 6 advance */
  62. ;
  63. face = hb_face_builder_create ();
  64. HB_FACE_ADD_TABLE (face, "maxp", maxp_data);
  65. HB_FACE_ADD_TABLE (face, "loca", loca_data);
  66. HB_FACE_ADD_TABLE (face, "hhea", hhea_data);
  67. HB_FACE_ADD_TABLE (face, "hmtx", hmtx_data);
  68. font = hb_font_create (face);
  69. hb_face_destroy (face);
  70. g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 0), ==, 1);
  71. g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 1), ==, 3);
  72. g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 2), ==, 3);
  73. g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 3), ==, 3);
  74. g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 4), ==, 3);
  75. #ifndef HB_NO_BEYOND_64K
  76. g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 5), ==, 8);
  77. g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 6), ==, 9);
  78. g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 7), ==, 9);
  79. #endif
  80. g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 8), ==, 0);
  81. g_assert_cmpuint (hb_font_get_glyph_h_advance (font, 9), ==, 0);
  82. g_assert_cmpuint (hb_font_get_glyph_h_advance (font,10), ==, 0);
  83. g_assert_cmpuint (hb_font_get_glyph_h_advance (font,11), ==, 0);
  84. hb_font_destroy (font);
  85. }
  86. int
  87. main (int argc, char **argv)
  88. {
  89. hb_test_init (&argc, &argv);
  90. hb_test_add (test_maxp_and_hmtx);
  91. return hb_test_run();
  92. }