test-ft.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright © 2022 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: Matthias Clasen
  25. */
  26. #include "hb-test.h"
  27. #include "hb-ft.h"
  28. #include FT_FONT_FORMATS_H
  29. static FT_Library ft_library;
  30. static void
  31. init_freetype (void)
  32. {
  33. FT_Error ft_error;
  34. if ((ft_error = FT_Init_FreeType (&ft_library)))
  35. abort ();
  36. }
  37. static void
  38. cleanup_freetype (void)
  39. {
  40. FT_Done_FreeType (ft_library);
  41. }
  42. static FT_Face
  43. get_ft_face (const char *file)
  44. {
  45. FT_Face ft_face;
  46. #if GLIB_CHECK_VERSION(2,37,2)
  47. char* path = g_test_build_filename (G_TEST_DIST, file, NULL);
  48. #else
  49. char* path = g_strdup (file);
  50. #endif
  51. FT_Error ft_error;
  52. if ((ft_error = FT_New_Face (ft_library, path, 0, &ft_face))) {
  53. g_free (path);
  54. abort();
  55. }
  56. g_free (path);
  57. if ((ft_error = FT_Set_Char_Size (ft_face, 2000, 1000, 0, 0)))
  58. abort ();
  59. return ft_face;
  60. }
  61. static void
  62. test_native_ft_basic (void)
  63. {
  64. FT_Face ft_face;
  65. hb_font_t *font;
  66. FT_Face ft_face2;
  67. init_freetype ();
  68. ft_face = get_ft_face ("fonts/Cantarell.A.otf");
  69. g_assert_nonnull (ft_face);
  70. g_assert_nonnull (FT_Get_Font_Format (ft_face));
  71. font = hb_ft_font_create_referenced (ft_face);
  72. ft_face2 = hb_ft_font_get_face (font);
  73. g_assert_true (ft_face2 == ft_face);
  74. ft_face2 = hb_ft_font_lock_face (font);
  75. g_assert_true (ft_face2 == ft_face);
  76. hb_ft_font_unlock_face (font);
  77. hb_ft_font_set_load_flags (font, FT_LOAD_NO_SCALE | FT_LOAD_NO_AUTOHINT);
  78. int load_flags = hb_ft_font_get_load_flags (font);
  79. g_assert_true (load_flags == (FT_LOAD_NO_SCALE | FT_LOAD_NO_AUTOHINT));
  80. hb_font_destroy (font);
  81. FT_Done_Face (ft_face);
  82. cleanup_freetype ();
  83. }
  84. int
  85. main (int argc, char **argv)
  86. {
  87. hb_test_init (&argc, &argv);
  88. hb_test_add (test_native_ft_basic);
  89. return hb_test_run ();
  90. }