Files
Seele/src/Engine/Asset/FontAsset.h
T

54 lines
1.4 KiB
C++
Raw Normal View History

2022-04-13 13:01:35 +02:00
#pragma once
#include "Asset.h"
2023-02-13 14:56:13 +01:00
#include "Containers/Map.h"
2025-01-19 16:07:38 +01:00
#include "Graphics/Texture.h"
2023-02-13 14:56:13 +01:00
#include "Math/Math.h"
2025-01-08 19:15:12 +01:00
#include <freetype/freetype.h>
2025-01-29 16:15:48 +01:00
#include <harfbuzz/hb.h>
2022-04-13 13:01:35 +02:00
2024-06-09 12:20:04 +02:00
namespace Seele {
class FontAsset : public Asset {
public:
2023-02-13 14:56:13 +01:00
static constexpr uint64 IDENTIFIER = 0x10;
2022-04-13 13:01:35 +02:00
FontAsset();
2023-02-13 14:56:13 +01:00
FontAsset(std::string_view folderPath, std::string_view name);
2022-04-13 13:01:35 +02:00
virtual ~FontAsset();
2023-02-13 14:56:13 +01:00
virtual void save(ArchiveBuffer& buffer) const override;
virtual void load(ArchiveBuffer& buffer) override;
2022-04-15 11:19:30 +02:00
2024-06-09 12:20:04 +02:00
struct Glyph {
2025-01-08 19:15:12 +01:00
UVector2 size = {};
UVector2 bearing = {};
uint32 advance = 0;
Array<uint8> textureData;
Gfx::OTexture2D texture = nullptr;
2023-11-07 16:55:13 +01:00
void save(ArchiveBuffer& buffer) const;
void load(ArchiveBuffer& buffer);
2022-04-13 13:01:35 +02:00
};
2025-01-19 16:07:38 +01:00
struct FontData {
Map<uint32, Glyph> glyphs;
};
void loadFace();
2024-06-09 12:20:04 +02:00
2025-01-29 16:15:48 +01:00
struct RenderGlyph {
Gfx::PTexture2D texture;
UVector2 position;
UVector2 dimensions;
};
UVector2 shapeText(std::string_view view, uint32 fontSize, Array<RenderGlyph>& render);
2024-06-09 12:20:04 +02:00
private:
2025-01-29 16:15:48 +01:00
void loadGlyphs(uint32 fontSize);
2025-01-19 16:07:38 +01:00
Gfx::PGraphics graphics;
2025-01-29 16:15:48 +01:00
hb_blob_t* blob;
hb_face_t* hb_face;
hb_font_t* hb_font;
2025-01-19 16:07:38 +01:00
FT_Library ft;
2025-01-29 16:15:48 +01:00
FT_Face ft_face;
Array<char> ttfFile;
2025-01-19 16:07:38 +01:00
Map<uint32, FontData> fontSizes;
2023-01-29 18:58:59 +01:00
friend class FontLoader;
2022-04-13 13:01:35 +02:00
};
DECLARE_REF(FontAsset)
} // namespace Seele