Files
OpenVulkano/openVulkanoCpp/Scene/Text/FontAtlasFactory.hpp
2025-01-26 18:16:18 +01:00

45 lines
1.5 KiB
C++

/*
* 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& font_, const std::set<uint32_t>& charset, SubpixelLayout subpixelLayout_,
float ptSize_, FontAtlasType atlasType_);
bool operator<(const FontIdentifier& other) const;
std::string font;
uint32_t charsetHash = 0;
SubpixelLayout subpixelLayout = SubpixelLayout::UNKNOWN;
float ptSize = 0;
FontAtlasType atlasType;
};
public:
FontAtlasFactory(bool allowSystemFonts = true) : m_allowSystemFonts(allowSystemFonts) {}
[[nodiscard]] FontAtlas::Ptr GetFontAtlasScalable(const std::string& fontIdentifier, bool msdf = true,
const std::set<uint32_t>& charset = {}) const;
[[nodiscard]] FontAtlas::Ptr GetFontAtlas(const std::string& fontIdentifier, float ptSize,
SubpixelLayout subpixelLayout = SubpixelLayout::UNKNOWN,
const std::set<uint32_t>& charset = {}) const;
private:
Array<char> FindFont(const std::string& fontFile) const;
private:
const bool m_allowSystemFonts;
mutable std::map<FontIdentifier, FontAtlas::Ptr> m_atlasesCache;
};
}