/* * 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/. */ #pragma once #include "FontAtlas.hpp" #include "SubpixelLayout.hpp" #include "Data/Containers/Array.hpp" namespace OpenVulkano::Scene { class FontAtlasFactory final { struct FontIdentifier { FontIdentifier(const std::string_view& font, FontAtlasType atlasType) : font(font), atlasType(atlasType) { assert(atlasType.IsSDF()); } FontIdentifier(const std::string_view& font, FontAtlasType atlasType, SubpixelLayout subpixelLayout, float ptSize) : font(font), atlasType(atlasType), subpixelLayout(subpixelLayout), ptSize(ptSize) {} bool operator<(const FontIdentifier& other) const; std::string font; FontAtlasType atlasType; SubpixelLayout subpixelLayout = SubpixelLayout::UNKNOWN; float ptSize = 0; }; static FontAtlasFactory INSTANCE; const bool m_allowSystemFonts; mutable std::map m_atlasesCache; public: static FontAtlasFactory& GetInstance() { return INSTANCE; } FontAtlasFactory(const bool allowSystemFonts = true) : m_allowSystemFonts(allowSystemFonts) {} [[nodiscard]] FontAtlas::Ptr GetFontAtlasScalable(const std::string& fontIdentifier, bool msdf = true, const std::set& charset = {}) const; [[nodiscard]] FontAtlas::Ptr GetFontAtlas(const std::string& fontIdentifier, float ptSize, SubpixelLayout subpixelLayout = SubpixelLayout::UNKNOWN, const std::set& charset = {}) const; }; }