Cleanup font generators
This commit is contained in:
@@ -34,7 +34,6 @@ namespace OpenVulkano
|
|||||||
using namespace Math;
|
using namespace Math;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
constexpr int CREATE_BITMAP_ATLAS = 0;
|
|
||||||
//#define CREATE_NEW_ATLAS
|
//#define CREATE_NEW_ATLAS
|
||||||
|
|
||||||
class TextExampleAppImpl final : public TextExampleApp
|
class TextExampleAppImpl final : public TextExampleApp
|
||||||
@@ -67,12 +66,6 @@ namespace OpenVulkano
|
|||||||
m_nodesPool.resize(textsCount * atlasesCount);
|
m_nodesPool.resize(textsCount * atlasesCount);
|
||||||
m_drawablesPool.resize(textsCount * atlasesCount);
|
m_drawablesPool.resize(textsCount * atlasesCount);
|
||||||
|
|
||||||
if constexpr (CREATE_BITMAP_ATLAS)
|
|
||||||
{
|
|
||||||
// ReSharper disable once CppDFAUnreachableCode
|
|
||||||
FontAtlasFactory().GetFontAtlas("Roboto-Regular", 14.0f, SubpixelLayout::RGB)->Save("bitmap_atlas_rgb.ovfont");
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(MSDFGEN_AVAILABLE) && defined(CREATE_NEW_ATLAS)
|
#if defined(MSDFGEN_AVAILABLE) && defined(CREATE_NEW_ATLAS)
|
||||||
std::set<uint32_t> s = SdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
|
std::set<uint32_t> s = SdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
|
||||||
m_atlasGenerator.GenerateAtlas(fontPath, s);
|
m_atlasGenerator.GenerateAtlas(fontPath, s);
|
||||||
|
|||||||
@@ -11,21 +11,18 @@
|
|||||||
|
|
||||||
namespace OpenVulkano::Scene
|
namespace OpenVulkano::Scene
|
||||||
{
|
{
|
||||||
void BitmapFontAtlasGenerator::GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& charset,
|
void BitmapFontAtlasGenerator::GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& charset)
|
||||||
const std::optional<std::string>& pngOutput)
|
|
||||||
{
|
{
|
||||||
GenerateAtlas(Utils::ReadFile(fontFile), charset, pngOutput);
|
GenerateAtlas(Utils::ReadFile(fontFile), charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapFontAtlasGenerator::GenerateAtlas(const Array<char>& fontData, const std::set<uint32_t>& charset,
|
void BitmapFontAtlasGenerator::GenerateAtlas(const Array<char>& fontData, const std::set<uint32_t>& charset)
|
||||||
const std::optional<std::string>& pngOutput)
|
|
||||||
{
|
{
|
||||||
Generate({ reinterpret_cast<const uint8_t*>(fontData.Data()), fontData.Size() }, charset, pngOutput);
|
Generate(fontData.AsBytes(), charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapFontAtlasGenerator::Generate(const std::span<const uint8_t>& fontData,
|
void BitmapFontAtlasGenerator::Generate(const std::span<const uint8_t>& fontData,
|
||||||
const std::set<uint32_t>& inCs,
|
const std::set<uint32_t>& inCs)
|
||||||
const std::optional<std::string>& pngOutput)
|
|
||||||
{
|
{
|
||||||
const auto& [lib, face] = FontAtlasGeneratorBase::InitFreetype(fontData);
|
const auto& [lib, face] = FontAtlasGeneratorBase::InitFreetype(fontData);
|
||||||
|
|
||||||
@@ -64,7 +61,6 @@ namespace OpenVulkano::Scene
|
|||||||
FontAtlasType::BITMAP,
|
FontAtlasType::BITMAP,
|
||||||
m_subpixelLayout.GetTextureDataFormat());
|
m_subpixelLayout.GetTextureDataFormat());
|
||||||
FillGlyphsInfo(allGlyphs, face, scaleFactor);
|
FillGlyphsInfo(allGlyphs, face, scaleFactor);
|
||||||
if (pngOutput) m_atlasData->Save(*pngOutput);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::vector<GlyphForPacking>, double>
|
std::pair<std::vector<GlyphForPacking>, double>
|
||||||
|
|||||||
@@ -42,12 +42,10 @@ namespace OpenVulkano::Scene
|
|||||||
, m_subpixelLayout(subpixelLayout.value_or(SubpixelLayout::UNKNOWN))
|
, m_subpixelLayout(subpixelLayout.value_or(SubpixelLayout::UNKNOWN))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
[[deprecated]] void GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& charset,
|
[[deprecated]] void GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& charset) override;
|
||||||
const std::optional<std::string>& pngOutput = std::nullopt) override;
|
void GenerateAtlas(const Array<char>& fontData, const std::set<uint32_t>& charset) override;
|
||||||
void GenerateAtlas(const Array<char>& fontData, const std::set<uint32_t>& charset,
|
|
||||||
const std::optional<std::string>& pngOutput = std::nullopt) override;
|
|
||||||
private:
|
private:
|
||||||
void Generate(const std::span<const uint8_t>& fontData, const std::set<uint32_t>& chset, const std::optional<std::string>& pngOutput);
|
void Generate(const std::span<const uint8_t>& fontData, const std::set<uint32_t>& chset);
|
||||||
void FillGlyphsInfo(const std::vector<GlyphForPacking>& allGlyphs, const FtFaceRecPtr& face, double scaleFactor);
|
void FillGlyphsInfo(const std::vector<GlyphForPacking>& allGlyphs, const FtFaceRecPtr& face, double scaleFactor);
|
||||||
void FillSubpixelData(const FT_Bitmap& bitmap, const GlyphForPacking& glyph);
|
void FillSubpixelData(const FT_Bitmap& bitmap, const GlyphForPacking& glyph);
|
||||||
FT_Int32 GetGlyphRenderMode() const;
|
FT_Int32 GetGlyphRenderMode() const;
|
||||||
|
|||||||
@@ -20,10 +20,8 @@ namespace OpenVulkano::Scene
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IFontAtlasGenerator() = default;
|
virtual ~IFontAtlasGenerator() = default;
|
||||||
[[deprecated]] virtual void GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& charset,
|
[[deprecated]] virtual void GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& charset) = 0;
|
||||||
const std::optional<std::string>& pngOutput = std::nullopt) = 0;
|
virtual void GenerateAtlas(const Array<char>& fontData, const std::set<uint32_t>& charset) = 0;
|
||||||
virtual void GenerateAtlas(const Array<char>& fontData, const std::set<uint32_t>& charset,
|
|
||||||
const std::optional<std::string>& pngOutput = std::nullopt) = 0;
|
|
||||||
virtual const std::shared_ptr<FontAtlas>& GetAtlas() const = 0;
|
virtual const std::shared_ptr<FontAtlas>& GetAtlas() const = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,15 +18,9 @@ namespace OpenVulkano::Scene
|
|||||||
SdfFontAtlasGeneratorConfig SdfFontAtlasGeneratorConfig::msdfDefaultConfig = { 32, 1.0, 3 };
|
SdfFontAtlasGeneratorConfig SdfFontAtlasGeneratorConfig::msdfDefaultConfig = { 32, 1.0, 3 };
|
||||||
|
|
||||||
template<int Channels>
|
template<int Channels>
|
||||||
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& charset,
|
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& inCs)
|
||||||
const std::optional<std::string>& pngOutput)
|
|
||||||
{
|
{
|
||||||
msdfgen::FreetypeHandle* ft;
|
GenerateAtlas(Utils::ReadFile(fontFile), inCs);
|
||||||
msdfgen::FontHandle* font;
|
|
||||||
InitFreetypeFromFile(ft, font, fontFile);
|
|
||||||
msdf_atlas::Charset s;
|
|
||||||
std::for_each(charset.begin(), charset.end(), [&](uint32_t unicode) { s.add(unicode); });
|
|
||||||
Generate(ft, font, s, pngOutput);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int Channels> SdfFontAtlasGeneratorGeneric<Channels>::SdfFontAtlasGeneratorGeneric() : FontAtlasGeneratorBase(Channels)
|
template<int Channels> SdfFontAtlasGeneratorGeneric<Channels>::SdfFontAtlasGeneratorGeneric() : FontAtlasGeneratorBase(Channels)
|
||||||
@@ -36,8 +30,7 @@ namespace OpenVulkano::Scene
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<int Channels>
|
template<int Channels>
|
||||||
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const Array<char>& fontData, const std::set<uint32_t>& inCs,
|
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const Array<char>& fontData, const std::set<uint32_t>& inCs)
|
||||||
const std::optional<std::string>& pngOutput)
|
|
||||||
{
|
{
|
||||||
msdfgen::FreetypeHandle* ft;
|
msdfgen::FreetypeHandle* ft;
|
||||||
msdfgen::FontHandle* font;
|
msdfgen::FontHandle* font;
|
||||||
@@ -50,30 +43,26 @@ namespace OpenVulkano::Scene
|
|||||||
}
|
}
|
||||||
const auto& charset = inCs.empty() ? fallback : inCs;
|
const auto& charset = inCs.empty() ? fallback : inCs;
|
||||||
std::for_each(charset.begin(), charset.end(), [&](uint32_t unicode) { s.add(unicode); });
|
std::for_each(charset.begin(), charset.end(), [&](uint32_t unicode) { s.add(unicode); });
|
||||||
Generate(ft, font, s, pngOutput);
|
Generate(ft, font, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int Channels>
|
template<int Channels>
|
||||||
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const std::string& fontFile,
|
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const std::string& fontFile, const msdf_atlas::Charset& charset)
|
||||||
const msdf_atlas::Charset& charset,
|
|
||||||
const std::optional<std::string>& pngOutput)
|
|
||||||
{
|
{
|
||||||
// TODO: dynamic atlas and add only those symbols which are not present yet in current atlas
|
// TODO: dynamic atlas and add only those symbols which are not present yet in current atlas
|
||||||
msdfgen::FreetypeHandle* ft;
|
msdfgen::FreetypeHandle* ft;
|
||||||
msdfgen::FontHandle* font;
|
msdfgen::FontHandle* font;
|
||||||
InitFreetypeFromFile(ft, font, fontFile);
|
InitFreetypeFromFile(ft, font, fontFile);
|
||||||
Generate(ft, font, charset, pngOutput);
|
Generate(ft, font, charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int Channels>
|
template<int Channels>
|
||||||
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const msdfgen::byte* fontData, int length,
|
void SdfFontAtlasGeneratorGeneric<Channels>::GenerateAtlas(const msdfgen::byte* fontData, int length, const msdf_atlas::Charset& charset)
|
||||||
const msdf_atlas::Charset& charset,
|
|
||||||
const std::optional<std::string>& pngOutput)
|
|
||||||
{
|
{
|
||||||
msdfgen::FreetypeHandle* ft;
|
msdfgen::FreetypeHandle* ft;
|
||||||
msdfgen::FontHandle* font;
|
msdfgen::FontHandle* font;
|
||||||
InitFreetypeFromBuffer(ft, font, fontData, length);
|
InitFreetypeFromBuffer(ft, font, fontData, length);
|
||||||
Generate(ft, font, charset, pngOutput);
|
Generate(ft, font, charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int Channels>
|
template<int Channels>
|
||||||
@@ -115,9 +104,7 @@ namespace OpenVulkano::Scene
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<int Channels>
|
template<int Channels>
|
||||||
void SdfFontAtlasGeneratorGeneric<Channels>::Generate(msdfgen::FreetypeHandle* ft, msdfgen::FontHandle* font,
|
void SdfFontAtlasGeneratorGeneric<Channels>::Generate(msdfgen::FreetypeHandle* ft, msdfgen::FontHandle* font, const msdf_atlas::Charset& chset)
|
||||||
const msdf_atlas::Charset& chset,
|
|
||||||
const std::optional<std::string>& pngOutput)
|
|
||||||
{
|
{
|
||||||
std::vector<msdf_atlas::GlyphGeometry> glyphsGeometry;
|
std::vector<msdf_atlas::GlyphGeometry> glyphsGeometry;
|
||||||
// FontGeometry is a helper class that loads a set of glyphs from a single font.
|
// FontGeometry is a helper class that loads a set of glyphs from a single font.
|
||||||
@@ -212,10 +199,6 @@ namespace OpenVulkano::Scene
|
|||||||
SetGlyphData(info, { bearingX, bearingY }, { w, h }, glyphAtlasAABB, glyphBox.advance);
|
SetGlyphData(info, { bearingX, bearingY }, { w, h }, glyphAtlasAABB, glyphBox.advance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pngOutput && !pngOutput->empty())
|
|
||||||
{
|
|
||||||
m_atlasData->Save(*pngOutput);
|
|
||||||
}
|
|
||||||
destroyFont(font);
|
destroyFont(font);
|
||||||
deinitializeFreetype(ft);
|
deinitializeFreetype(ft);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,24 +42,19 @@ namespace OpenVulkano::Scene
|
|||||||
using Config = SdfFontAtlasGeneratorConfig;
|
using Config = SdfFontAtlasGeneratorConfig;
|
||||||
static constexpr int channelsCount = (Channels == 1 ? 1 : 4);
|
static constexpr int channelsCount = (Channels == 1 ? 1 : 4);
|
||||||
SdfFontAtlasGeneratorGeneric();
|
SdfFontAtlasGeneratorGeneric();
|
||||||
[[deprecated]] void GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& charset,
|
[[deprecated]] void GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& charset) override;
|
||||||
const std::optional<std::string>& pngOutput = std::nullopt) override;
|
void GenerateAtlas(const Array<char>& fontData, const std::set<uint32_t>& charset) override;
|
||||||
void GenerateAtlas(const Array<char>& fontData, const std::set<uint32_t>& charset,
|
|
||||||
const std::optional<std::string>& pngOutput = std::nullopt) override;
|
|
||||||
[[deprecated]] void GenerateAtlas(const std::string& fontFile,
|
[[deprecated]] void GenerateAtlas(const std::string& fontFile,
|
||||||
const msdf_atlas::Charset& charset = msdf_atlas::Charset::ASCII,
|
const msdf_atlas::Charset& charset = msdf_atlas::Charset::ASCII);
|
||||||
const std::optional<std::string>& pngOutput = std::nullopt);
|
|
||||||
void GenerateAtlas(const msdfgen::byte* fontData, int length,
|
void GenerateAtlas(const msdfgen::byte* fontData, int length,
|
||||||
const msdf_atlas::Charset& charset = msdf_atlas::Charset::ASCII,
|
const msdf_atlas::Charset& charset = msdf_atlas::Charset::ASCII);
|
||||||
const std::optional<std::string>& pngOutput = std::nullopt);
|
|
||||||
void SetGeneratorConfig(const Config& config) { m_config = config; }
|
void SetGeneratorConfig(const Config& config) { m_config = config; }
|
||||||
Config& GetGeneratorConfig() { return m_config; }
|
Config& GetGeneratorConfig() { return m_config; }
|
||||||
private:
|
private:
|
||||||
void InitFreetypeFromFile(msdfgen::FreetypeHandle*& ft, msdfgen::FontHandle*& font, const std::string& file);
|
void InitFreetypeFromFile(msdfgen::FreetypeHandle*& ft, msdfgen::FontHandle*& font, const std::string& file);
|
||||||
void InitFreetypeFromBuffer(msdfgen::FreetypeHandle*& ft, msdfgen::FontHandle*& font,
|
void InitFreetypeFromBuffer(msdfgen::FreetypeHandle*& ft, msdfgen::FontHandle*& font,
|
||||||
const msdfgen::byte* fontData, int length);
|
const msdfgen::byte* fontData, int length);
|
||||||
void Generate(msdfgen::FreetypeHandle* ft, msdfgen::FontHandle* font, const msdf_atlas::Charset& chset,
|
void Generate(msdfgen::FreetypeHandle* ft, msdfgen::FontHandle* font, const msdf_atlas::Charset& chset);
|
||||||
const std::optional<std::string>& pngOutput);
|
|
||||||
private:
|
private:
|
||||||
Config m_config;
|
Config m_config;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user