52 lines
1.8 KiB
C++
52 lines
1.8 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_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<FontIdentifier, FontAtlas::Ptr> 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<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;
|
|
};
|
|
}
|