Move FreetypeHelper and cleanup glyph creation

This commit is contained in:
Georg Hagen
2025-01-04 11:59:13 +01:00
parent 994ae12b80
commit fad309d96d
3 changed files with 8 additions and 12 deletions

View File

@@ -8,7 +8,7 @@
#include "IFontAtlasGenerator.hpp"
#include "Math/AABB.hpp"
#include "FreetypeHelper.hpp"
#include "Extensions/FreetypeHelper.hpp"
#include <variant>
#include <set>

View File

@@ -1,28 +0,0 @@
/*
* 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 <ft2build.h>
#include FT_FREETYPE_H
#include <memory>
namespace OpenVulkano::Scene
{
struct LibDeleter
{
void operator()(FT_Library lib) { FT_Done_FreeType(lib); }
};
struct FaceDeleter
{
void operator()(FT_Face face) { FT_Done_Face(face); }
};
using FtLibraryRecPtr = std::unique_ptr<FT_LibraryRec_, LibDeleter>;
using FtFaceRecPtr = std::unique_ptr<FT_FaceRec_, FaceDeleter>;
}

View File

@@ -140,22 +140,18 @@ namespace OpenVulkano::Scene
m_text = text;
size_t len = utf8::distance(text.begin(), text.end());
const size_t len = utf8::distance(text.begin(), text.end());
m_geometry.Close();
m_geometry.Init(len * 4, len * 6);
AtlasMetadata* meta;
std::map<uint32_t, GlyphInfo>* symbols;
symbols = &m_atlasData->glyphs;
meta = &m_atlasData->meta;
std::map<uint32_t, GlyphInfo>* symbols = &m_atlasData->glyphs;
AtlasMetadata* meta = &m_atlasData->meta;
double cursorX = pos.x;
auto begin = text.begin();
auto end = text.end();
const double lineHeight = meta->lineHeight;
double posY = pos.y;
int i = 0;
Math::Vector3f bmin(pos), bmax(pos);
while (begin != end)
int i = 0;
for (auto begin = text.begin(), end = text.end(); begin != end;)
{
uint32_t c = utf8::next(begin, end);
if (c == '\n')
@@ -165,7 +161,7 @@ namespace OpenVulkano::Scene
continue;
}
if (symbols->find(c) == symbols->end())
if (!symbols->contains(c))
{
Logger::RENDER->warn("Could not find glyph for character {}, using fallback", c);
c = fallbackGlyph;