43 lines
1.4 KiB
C++
43 lines
1.4 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 <string>
|
|
#include <optional>
|
|
#include <map>
|
|
#include "Scene/AtlasMetadata.hpp"
|
|
#include "Scene/Texture.hpp"
|
|
#include "msdfgen.h"
|
|
#include "msdfgen-ext.h"
|
|
#include "msdf-atlas-gen/msdf-atlas-gen.h"
|
|
|
|
namespace OpenVulkano::Scene
|
|
{
|
|
using namespace msdfgen;
|
|
using namespace msdf_atlas;
|
|
using namespace OpenVulkano::Scene;
|
|
|
|
class FontAtlasGenerator
|
|
{
|
|
public:
|
|
void GenerateAtlas(const std::string& fontFile, const Charset& charset = Charset::ASCII,
|
|
const std::optional<std::string>& pngOutput = std::nullopt);
|
|
void GenerateAtlas(const msdfgen::byte* fontData, int length, const Charset& charset = Charset::ASCII,
|
|
const std::optional<std::string>& pngOutput = std::nullopt);
|
|
void SaveAtlasMetadataInfo(const std::string& outputFile) const;
|
|
const Texture& GetAtlas() const { return m_atlasTex; }
|
|
std::map<uint32_t, GlyphInfo>& GetAtlasInfo() { return m_symbols; }
|
|
private:
|
|
void Generate(FreetypeHandle* ft, FontHandle* font, const Charset& chset,
|
|
const std::optional<std::string>& pngOutput);
|
|
private:
|
|
ImmediateAtlasGenerator<float, 1, sdfGenerator, BitmapAtlasStorage<msdfgen::byte, 1>> m_generator;
|
|
Texture m_atlasTex;
|
|
std::map<uint32_t, GlyphInfo> m_symbols;
|
|
};
|
|
}
|