56 lines
1.7 KiB
C++
56 lines
1.7 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 "IFontAtlasGenerator.hpp"
|
|
#include "Math/AABB.hpp"
|
|
#include <ft2build.h>
|
|
#include FT_FREETYPE_H
|
|
#include <variant>
|
|
#include <set>
|
|
|
|
namespace OpenVulkano::Scene
|
|
{
|
|
class FontAtlasGeneratorBase : public IFontAtlasGenerator
|
|
{
|
|
struct LibDeleter
|
|
{
|
|
void operator()(FT_Library lib)
|
|
{
|
|
FT_Done_FreeType(lib);
|
|
}
|
|
};
|
|
|
|
struct FaceDeleter
|
|
{
|
|
void operator()(FT_Face face)
|
|
{
|
|
FT_Done_Face(face);
|
|
}
|
|
};
|
|
|
|
public:
|
|
using FT_LIB_REC = std::unique_ptr<FT_LibraryRec_, LibDeleter>;
|
|
using FT_FACE_REC = std::unique_ptr<FT_FaceRec_, FaceDeleter>;
|
|
|
|
FontAtlasGeneratorBase(int channelsCount) : m_channelsCount(channelsCount) {}
|
|
void SaveAtlasMetadataInfo(const std::string& outputFile, bool packIntoSingleFile = true) const override;
|
|
std::shared_ptr<AtlasData> GetAtlasData() const { return m_atlasData; }
|
|
int GetAtlasChannelsCount() const { return m_channelsCount; }
|
|
|
|
static std::set<uint32_t> LoadAllGlyphs(const std::variant<std::string, Array<char>>& data);
|
|
|
|
protected:
|
|
void SavePng(const std::string& output) const;
|
|
void SetupAtlasData(Math::Vector2ui textureResolution, double lineHeight, FontAtlasType::Type atlasType);
|
|
void SetGlyphData(GlyphInfo& info, Math::Vector2d bearing, Math::Vector2d size, const Math::AABB& aabb, double advance);
|
|
static std::pair<FT_LIB_REC, FT_FACE_REC> InitFreetype(const std::variant<std::string, Array<char>>& source);
|
|
protected:
|
|
int m_channelsCount;
|
|
std::shared_ptr<AtlasData> m_atlasData;
|
|
};
|
|
} |