#pragma once
#include "modules/modules_enabled.gen.h"
#include "scene/resources/font.h"
#include "tests/test_macros.h"
namespace TestFontfile {
TEST_CASE("[FontFile] Load Dynamic Font - getters") {
#ifdef MODULE_FREETYPE_ENABLED
String test_dynamic_font = "thirdparty/fonts/NotoSansHebrew_Regular.woff2";
Ref<FontFile> ff;
ff.instantiate();
CHECK(ff->load_dynamic_font(test_dynamic_font) == OK);
CHECK(ff->get_font_name() == "Noto Sans Hebrew");
CHECK(ff->get_font_style_name() == "Regular");
CHECK(ff->get_font_weight() == 400);
CHECK(ff->get_font_stretch() == 100);
CHECK(ff->get_opentype_features() == Dictionary());
Dictionary expected_ot_name_strings;
Dictionary en_dict;
en_dict["copyright"] = "Copyright 2024 The Noto Project Authors (https://github.com/notofonts/hebrew)";
en_dict["family_name"] = "Noto Sans Hebrew";
en_dict["subfamily_name"] = "Regular";
en_dict["unique_identifier"] = "3.001;GOOG;NotoSansHebrew-Regular";
en_dict["full_name"] = "Noto Sans Hebrew Regular";
en_dict["version"] = "Version 3.001";
en_dict["postscript_name"] = "NotoSansHebrew-Regular";
en_dict["trademark"] = "Noto is a trademark of Google Inc.";
en_dict["manufacturer"] = "Google LLC";
en_dict["designer"] = "Ben Nathan";
en_dict["description"] = "Designed by Ben Nathan";
en_dict["vendor_url"] = "http://www.google.com/get/noto/";
en_dict["designer_url"] = "https://hafontia.com/";
en_dict["license"] = "This Font Software is licensed under the SIL Open Font License, Version 1.1. This Font Software is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the SIL Open Font License for the specific language, permissions and limitations governing your use of this Font Software.";
en_dict["license_url"] = "http://scripts.sil.org/OFL";
expected_ot_name_strings["en"] = en_dict;
CHECK(ff->get_ot_name_strings() == expected_ot_name_strings);
CHECK(ff->get_height(10) == doctest::Approx((real_t)14));
CHECK(ff->get_ascent(10) == doctest::Approx((real_t)11));
CHECK(ff->get_descent(10) == doctest::Approx((real_t)3));
CHECK(ff->get_underline_position(10) == doctest::Approx((real_t)1.25));
CHECK(ff->get_underline_thickness(10) == doctest::Approx((real_t)0.5));
CHECK(ff->get_height(100) == doctest::Approx((real_t)137));
CHECK(ff->get_ascent(100) == doctest::Approx((real_t)107));
CHECK(ff->get_descent(100) == doctest::Approx((real_t)30));
CHECK(ff->get_underline_position(100) == doctest::Approx((real_t)12.5));
CHECK(ff->get_underline_thickness(100) == doctest::Approx((real_t)5));
#endif
}
TEST_CASE("[FontFile] Create font file and check data") {
Ref<FontFile> font_file;
font_file.instantiate();
#ifdef MODULE_FREETYPE_ENABLED
ERR_PRINT_OFF
CHECK(font_file->load_dynamic_font("") == OK);
CHECK_MESSAGE(font_file->get_data().is_empty() == true, "Invalid fontfile should not be loaded.");
CHECK(font_file->load_dynamic_font("thirdparty/fonts/nofonthasthisname.woff2") == OK);
CHECK_MESSAGE(font_file->get_data().is_empty() == true, "Invalid fontfile should not be loaded.");
ERR_PRINT_ON
CHECK(font_file->load_dynamic_font("thirdparty/fonts/Inter_Regular.woff2") == OK);
CHECK_MESSAGE(font_file->get_data().is_empty() == false, "Fontfile should have been loaded.");
CHECK_MESSAGE(font_file->get_font_name() == "Inter", "Loaded correct font name.");
CHECK_MESSAGE(font_file->get_font_style_name() == "Regular", "Loaded correct font style.");
CHECK_MESSAGE(font_file->get_data().size() == 111268llu, "Whole fontfile was loaded.");
CHECK_MESSAGE(font_file->get_glyph_index(2, 'a', 0) != 0, "Glyph index for 'a' is valid.");
CHECK_MESSAGE(font_file->get_glyph_index(2, 'b', 0) != 0, "Glyph index for 'b' is valid.");
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x0103, 0) != 0, "Glyph index for 'latin small letter a with breve' is valid.");
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x03a8, 0) != 0, "Glyph index for 'Greek psi' is valid.");
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x0416, 0) != 0, "Glyph index for 'Cyrillic zhe' is valid.");
CHECK_MESSAGE(font_file->get_glyph_index(2, '&', 0) != 0, "Glyph index for '&' is valid.");
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x4416, 0) == 0, "Glyph index is invalid.");
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x5555, 0) == 0, "Glyph index is invalid.");
CHECK_MESSAGE(font_file->get_glyph_index(2, 0x2901, 0) == 0, "Glyph index is invalid.");
#endif
}
}