Files
OpenVulkano/openVulkanoCpp/Scene/Text/FontAtlasGeneratorBase.hpp
2025-03-01 20:00:27 +01:00

35 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 "IFontAtlasGenerator.hpp"
#include "Math/AABB.hpp"
#include "Extensions/FreetypeHelper.hpp"
namespace OpenVulkano::Scene
{
class GlyphInfo;
class FontAtlasGeneratorBase : public IFontAtlasGenerator
{
protected:
int m_channelsCount;
std::shared_ptr<FontAtlas> m_atlasData;
public:
FontAtlasGeneratorBase(const int channelsCount) : m_channelsCount(channelsCount) {}
[[nodiscard]] const std::shared_ptr<FontAtlas>& GetAtlas() const final { return m_atlasData; }
[[nodiscard]] int GetAtlasChannelsCount() const { return m_channelsCount; }
static size_t LoadAllGlyphs(std::set<uint32_t>& chars, const std::span<const uint8_t>& fontData) { auto [lib, face] = InitFreetype(fontData); return LoadAllGlyphs(chars, face); }
static size_t LoadAllGlyphs(std::set<uint32_t>& chars, const FtFaceRecPtr& face);
protected:
void SetGlyphData(GlyphInfo& info, Math::Vector2d bearing, Math::Vector2d size, const Math::AABB& aabb, double advance);
[[nodiscard]] static std::string GetFreetypeErrorDescription(FT_Error error);
[[nodiscard]] static std::pair<FtLibraryRecPtr, FtFaceRecPtr> InitFreetype(const std::span<const uint8_t>& data);
};
}