/* * 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 #if __has_include("msdfgen.h") #include "FontAtlasGeneratorBase.hpp" #include #include #include #include #define MSDFGEN_AVAILABLE 1 namespace OpenVulkano::Scene { struct SdfFontAtlasGeneratorConfig { static SdfFontAtlasGeneratorConfig sdfDefaultConfig; static SdfFontAtlasGeneratorConfig msdfDefaultConfig; int glyphSize; double miterLimit; msdfgen::Range pixelRange; }; template class SdfFontAtlasGeneratorGeneric final : public FontAtlasGeneratorBase { using SdfGenerator = msdf_atlas::ImmediateAtlasGenerator>; using MsdfGenerator = msdf_atlas::ImmediateAtlasGenerator>; public: using Generator = typename std::conditional::type; using Config = SdfFontAtlasGeneratorConfig; static constexpr int channelsCount = (Channels == 1 ? 1 : 4); SdfFontAtlasGeneratorGeneric(); void GenerateAtlas(const Array& fontData, const std::set& charset) override; void GenerateAtlas(const std::filesystem::path& fontFile, const msdf_atlas::Charset& charset = msdf_atlas::Charset::ASCII); void GenerateAtlas(const msdfgen::byte* fontData, int length, const msdf_atlas::Charset& charset = msdf_atlas::Charset::ASCII); void SetGeneratorConfig(const Config& config) { m_config = config; } Config& GetGeneratorConfig() { return m_config; } private: void InitFreetypeFromBuffer(msdfgen::FreetypeHandle*& ft, msdfgen::FontHandle*& font, const msdfgen::byte* fontData, int length); void Generate(msdfgen::FreetypeHandle* ft, msdfgen::FontHandle* font, const msdf_atlas::Charset& chset); Config m_config; }; using SdfFontAtlasGenerator = SdfFontAtlasGeneratorGeneric<1>; using MsdfFontAtlasGenerator = SdfFontAtlasGeneratorGeneric<3>; } #endif