/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "FontResolver.hpp" #include "Base/Utils.hpp" #include "ResourceLoader.hpp" #include "SystemFontResolver.hpp" #include "fmt/format.h" #include #include #include namespace OpenVulkano { namespace { static constexpr std::array FONT_EXTENSIONS = { ".ttf" }; static constexpr std::array FONT_POSTFIXES = { "-Regular" }; static constexpr std::array FONT_FILE_CHECKS = { "", FONT_EXTENSIONS[0], "-Regular.ttf" }; // TODO automate } Array FontResolver::GetFontData(const std::string& fontName, bool checkSystemFonts) { Array data; for (const auto& ext : FONT_FILE_CHECKS) { std::string fName = fmt::format("{}{}", fontName, ext); data = ResourceLoader::GetInstance().GetResource(fName); if (!data.Empty()) return data; if (std::filesystem::exists(fName)) { data = Utils::ReadFile(fName, true); if (!data.Empty()) return data; } } if (checkSystemFonts) { data = Utils::ReadFile(SystemFontResolver::GetSystemFontPath(fontName), true); } return data; } }