| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "modules/modules_enabled.gen.h" |
| 34 |
|
| 35 |
#include "scene/resources/font.h" |
| 36 |
#include "tests/test_macros.h" |
| 37 |
|
| 38 |
namespace TestFontfile { |
| 39 |
|
| 40 |
TEST_CASE("[FontFile] Load Dynamic Font - getters") { |
| 41 |
#ifdef MODULE_FREETYPE_ENABLED |
| 42 |
String test_dynamic_font = "thirdparty/fonts/NotoSansHebrew_Regular.woff2"; |
| 43 |
Ref<FontFile> ff; |
| 44 |
ff.instantiate(); |
| 45 |
CHECK(ff->load_dynamic_font(test_dynamic_font) == OK); |
| 46 |
|
| 47 |
|
| 48 |
CHECK(ff->get_font_name() == "Noto Sans Hebrew"); |
| 49 |
CHECK(ff->get_font_style_name() == "Regular"); |
| 50 |
CHECK(ff->get_font_weight() == 400); |
| 51 |
CHECK(ff->get_font_stretch() == 100); |
| 52 |
CHECK(ff->get_opentype_features() == Dictionary()); |
| 53 |
|
| 54 |
Dictionary expected_ot_name_strings; |
| 55 |
Dictionary en_dict; |
| 56 |
en_dict["copyright"] = "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/hebrew)"; |
| 57 |
en_dict["family_name"] = "Noto Sans Hebrew"; |
| 58 |
en_dict["subfamily_name"] = "Regular"; |
| 59 |
en_dict["full_name"] = "Noto Sans Hebrew Regular"; |
| 60 |
en_dict["unique_identifier"] = "2.003;GOOG;NotoSansHebrew-Regular"; |
| 61 |
en_dict["version"] = "Version 2.003"; |
| 62 |
en_dict["postscript_name"] = "NotoSansHebrew-Regular"; |
| 63 |
en_dict["trademark"] = "Noto is a trademark of Google Inc."; |
| 64 |
en_dict["license"] = "This Font Software is licensed under the SIL Open Font License, Version 1.1. This license is available with a FAQ at: https://scripts.sil.org/OFL"; |
| 65 |
en_dict["license_url"] = "https://scripts.sil.org/OFL"; |
| 66 |
en_dict["designer"] = "Monotype Design Team"; |
| 67 |
en_dict["designer_url"] = "http://www.monotype.com/studio"; |
| 68 |
en_dict["description"] = "Designed by Monotype design team."; |
| 69 |
en_dict["manufacturer"] = "Monotype Imaging Inc."; |
| 70 |
en_dict["vendor_url"] = "http://www.google.com/get/noto/"; |
| 71 |
expected_ot_name_strings["en"] = en_dict; |
| 72 |
CHECK(ff->get_ot_name_strings() == expected_ot_name_strings); |
| 73 |
|
| 74 |
|
| 75 |
CHECK(ff->get_height(10) == doctest::Approx((real_t)14)); |
| 76 |
CHECK(ff->get_ascent(10) == doctest::Approx((real_t)11)); |
| 77 |
CHECK(ff->get_descent(10) == doctest::Approx((real_t)3)); |
| 78 |
CHECK(ff->get_underline_position(10) == doctest::Approx((real_t)1.25)); |
| 79 |
CHECK(ff->get_underline_thickness(10) == doctest::Approx((real_t)0.5)); |
| 80 |
CHECK(ff->get_height(100) == doctest::Approx((real_t)137)); |
| 81 |
CHECK(ff->get_ascent(100) == doctest::Approx((real_t)107)); |
| 82 |
CHECK(ff->get_descent(100) == doctest::Approx((real_t)30)); |
| 83 |
CHECK(ff->get_underline_position(100) == doctest::Approx((real_t)12.5)); |
| 84 |
CHECK(ff->get_underline_thickness(100) == doctest::Approx((real_t)5)); |
| 85 |
#endif |
| 86 |
} |
| 87 |
|
| 88 |
TEST_CASE("[FontFile] Create font file and check data") { |
| 89 |
|
| 90 |
Ref<FontFile> font_file; |
| 91 |
font_file.instantiate(); |
| 92 |
|
| 93 |
#ifdef MODULE_FREETYPE_ENABLED |
| 94 |
|
| 95 |
ERR_PRINT_OFF |
| 96 |
CHECK(font_file->load_dynamic_font("") == OK); |
| 97 |
CHECK_MESSAGE(font_file->get_data().is_empty() == true, "Invalid fontfile should not be loaded."); |
| 98 |
|
| 99 |
CHECK(font_file->load_dynamic_font("thirdparty/fonts/nofonthasthisname.woff2") == OK); |
| 100 |
CHECK_MESSAGE(font_file->get_data().is_empty() == true, "Invalid fontfile should not be loaded."); |
| 101 |
ERR_PRINT_ON |
| 102 |
|
| 103 |
|
| 104 |
CHECK(font_file->load_dynamic_font("thirdparty/fonts/Inter_Regular.woff2") == OK); |
| 105 |
|
| 106 |
|
| 107 |
CHECK_MESSAGE(font_file->get_data().is_empty() == false, "Fontfile should have been loaded."); |
| 108 |
CHECK_MESSAGE(font_file->get_font_name() == "Inter", "Loaded correct font name."); |
| 109 |
CHECK_MESSAGE(font_file->get_font_style_name() == "Regular", "Loaded correct font style."); |
| 110 |
CHECK_MESSAGE(font_file->get_data().size() == 111268llu, "Whole fontfile was loaded."); |
| 111 |
|
| 112 |
|
| 113 |
CHECK_MESSAGE(font_file->get_glyph_index(2, 'a', 0) != 0, "Glyph index for 'a' is valid."); |
| 114 |
CHECK_MESSAGE(font_file->get_glyph_index(2, 'b', 0) != 0, "Glyph index for 'b' is valid."); |
| 115 |
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x0103, 0) != 0, "Glyph index for 'latin small letter a with breve' is valid."); |
| 116 |
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x03a8, 0) != 0, "Glyph index for 'Greek psi' is valid."); |
| 117 |
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x0416, 0) != 0, "Glyph index for 'Cyrillic zhe' is valid."); |
| 118 |
CHECK_MESSAGE(font_file->get_glyph_index(2, '&', 0) != 0, "Glyph index for '&' is valid."); |
| 119 |
|
| 120 |
|
| 121 |
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x4416, 0) == 0, "Glyph index is invalid."); |
| 122 |
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x5555, 0) == 0, "Glyph index is invalid."); |
| 123 |
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x2901, 0) == 0, "Glyph index is invalid."); |
| 124 |
#endif |
| 125 |
} |
| 126 |
|
| 127 |
} |