VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
fontResource.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3#pragma once
4
5#include <cstdint>
6#include <memory>
7#include <optional>
8#include <string>
9#include <unordered_map>
10
12
13namespace visutwin::canvas
14{
15 class GraphicsDevice;
16 struct FontGlyph
17 {
18 int id = 0;
19 float x = 0.0f;
20 float y = 0.0f;
21 float width = 0.0f;
22 float height = 0.0f;
23 float xadvance = 0.0f;
24 float xoffset = 0.0f;
25 float yoffset = 0.0f;
26 };
27
29 {
30 Texture* texture = nullptr;
31 int atlasWidth = 0;
32 int atlasHeight = 0;
33 float lineHeight = 64.0f;
34 std::unordered_map<int, FontGlyph> glyphs;
35 std::unordered_map<uint64_t, float> kerning;
36
37 float kerningValue(const int left, const int right) const
38 {
39 const uint64_t key = (static_cast<uint64_t>(static_cast<uint32_t>(left)) << 32u) |
40 static_cast<uint32_t>(right);
41 if (const auto it = kerning.find(key); it != kerning.end()) {
42 return it->second;
43 }
44 return 0.0f;
45 }
46 };
47
48 std::optional<FontResource*> loadBitmapFontResource(const std::string& jsonPath,
49 const std::shared_ptr<GraphicsDevice>& graphicsDevice);
50}
Abstract GPU interface for resource creation, state management, and draw submission.
GPU texture resource supporting 2D, cubemap, volume, and array formats with mipmap management.
Definition texture.h:57
std::optional< FontResource * > loadBitmapFontResource(const std::string &jsonPath, const std::shared_ptr< GraphicsDevice > &graphicsDevice)
float kerningValue(const int left, const int right) const
std::unordered_map< int, FontGlyph > glyphs
std::unordered_map< uint64_t, float > kerning