atlas factory Windows implementation

This commit is contained in:
ohyzha
2025-01-17 13:11:04 +02:00
parent 45ca54feb7
commit 169d6c4129
9 changed files with 260 additions and 2 deletions

View File

@@ -0,0 +1,79 @@
/*
* 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 "FontAtlasFactory.hpp"
#include "Scene/SdfFontAtlasGenerator.hpp"
#include "Scene/BitmapFontAtlasGenerator.hpp"
#include "Host/SystemInfo.hpp"
namespace OpenVulkano::Scene
{
FontAtlas::Ptr FontAtlasFactory::GetFontAtlasScalable(const std::string& fontIdentifier,
const std::set<uint32_t>& charset, bool msdf) const
{
const std::string fileName = FindFont(fontIdentifier);
if (fileName.empty())
{
return nullptr;
}
const std::set<uint32_t>& setRef = (charset.empty() ? FontAtlasGeneratorBase::LoadAllGlyphs(fontIdentifier) : charset);
FontIdentifier id(fontIdentifier, setRef, SubpixelLayout::UNKNOWN, 0, msdf);
if (m_atlasesCache.contains(id))
{
return m_atlasesCache.at(id);
}
if (msdf)
{
MsdfFontAtlasGenerator msdfGen;
msdfGen.GenerateAtlas(fileName, setRef);
m_atlasesCache[id] = msdfGen.GetAtlas();
return m_atlasesCache.at(id);
}
SdfFontAtlasGenerator sdfGen;
sdfGen.GenerateAtlas(fileName, setRef);
m_atlasesCache[id] = sdfGen.GetAtlas();
return m_atlasesCache.at(id);
}
FontAtlas::Ptr FontAtlasFactory::GetFontAtlas(const std::string& fontIdentifier, float ptSize,
const std::set<uint32_t>& charset,
std::optional<SubpixelLayout> subpixelLayout) const
{
const std::string fileName = FindFont(fontIdentifier);
if (fileName.empty())
{
return nullptr;
}
const std::set<uint32_t>& setRef = (charset.empty() ? FontAtlasGeneratorBase::LoadAllGlyphs(fontIdentifier) : charset);
FontIdentifier id(fontIdentifier, setRef, subpixelLayout.value_or(SubpixelLayout::UNKNOWN), ptSize, false);
if (m_atlasesCache.contains(id))
{
return m_atlasesCache.at(id);
}
FontPixelSizeConfig cfg(ptSize);
BitmapFontAtlasGenerator bitmapGen(cfg, subpixelLayout);
bitmapGen.GenerateAtlas(fileName, setRef);
m_atlasesCache[id] = bitmapGen.GetAtlas();
return m_atlasesCache.at(id);
}
std::string FontAtlasFactory::FindFont(const std::string& fontIdentifier) const
{
if (!std::filesystem::exists(fontIdentifier))
{
if (!m_allowSystemFonts)
{
return "";
}
return SystemInfo::GetSystemFontPath(fontIdentifier);
}
return fontIdentifier;
}
}