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
11
#include "
platform/graphics/texture.h
"
12
13
namespace
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
28
struct
FontResource
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
}
visutwin::canvas::GraphicsDevice
Abstract GPU interface for resource creation, state management, and draw submission.
Definition
graphicsDevice.h:239
visutwin::canvas::Texture
GPU texture resource supporting 2D, cubemap, volume, and array formats with mipmap management.
Definition
texture.h:57
visutwin::canvas
Definition
eventHandler.cpp:9
visutwin::canvas::loadBitmapFontResource
std::optional< FontResource * > loadBitmapFontResource(const std::string &jsonPath, const std::shared_ptr< GraphicsDevice > &graphicsDevice)
Definition
fontResource.cpp:144
visutwin::canvas::FontGlyph
Definition
fontResource.h:17
visutwin::canvas::FontGlyph::y
float y
Definition
fontResource.h:20
visutwin::canvas::FontGlyph::height
float height
Definition
fontResource.h:22
visutwin::canvas::FontGlyph::xadvance
float xadvance
Definition
fontResource.h:23
visutwin::canvas::FontGlyph::x
float x
Definition
fontResource.h:19
visutwin::canvas::FontGlyph::yoffset
float yoffset
Definition
fontResource.h:25
visutwin::canvas::FontGlyph::xoffset
float xoffset
Definition
fontResource.h:24
visutwin::canvas::FontGlyph::width
float width
Definition
fontResource.h:21
visutwin::canvas::FontResource
Definition
fontResource.h:29
visutwin::canvas::FontResource::texture
Texture * texture
Definition
fontResource.h:30
visutwin::canvas::FontResource::atlasWidth
int atlasWidth
Definition
fontResource.h:31
visutwin::canvas::FontResource::kerningValue
float kerningValue(const int left, const int right) const
Definition
fontResource.h:37
visutwin::canvas::FontResource::glyphs
std::unordered_map< int, FontGlyph > glyphs
Definition
fontResource.h:34
visutwin::canvas::FontResource::atlasHeight
int atlasHeight
Definition
fontResource.h:32
visutwin::canvas::FontResource::kerning
std::unordered_map< uint64_t, float > kerning
Definition
fontResource.h:35
visutwin::canvas::FontResource::lineHeight
float lineHeight
Definition
fontResource.h:33
texture.h
framework
handlers
fontResource.h
Generated by
1.16.1