Cogs.Core
Font.h
1#pragma once
2
3#include <vector>
4#include <string>
5
6#include "Resources.h"
7
8namespace Cogs
9{
10 namespace Core
11 {
21 struct Font : public ResourceBase
22 {
28 struct Character
29 {
30 uint16_t x0;
31 uint16_t y0;
32 uint16_t x1;
33 uint16_t y1;
34
35 float xOffset;
36 float yOffset;
37 float xAdvance;
38
39 float xOffset2;
40 float yOffset2;
41 };
42
48 {
49 float x0, y0, s0, t0; // Top-left
50 float x1, y1, s1, t1;
51 };
52
54 Font() = default;
55
57 Font(Font && other) noexcept = default;
58
60 Font & operator=(Font && other) noexcept = default;
61
63 std::vector<Character> characters;
64
66 float size = 16.0f;
67
69 float ascent = 12.0f;
70
72 float descent = 12.0f;
73
75 int bitmapSize = 512;
76
78 bool sdf = false;
79
81 std::vector<uint8_t> bitmap;
82
85 };
86
91 {
93 std::string fontFamily;
94
96 float fontSize = 0.0f;
97
99 bool operator==(const FontDefinition& other) const noexcept = default;
100 };
101 }
102}
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Defines a Font.
Definition: Font.h:91
std::string fontFamily
Font family name, such as "Arial" or "Tahoma".
Definition: Font.h:93
bool operator==(const FontDefinition &other) const noexcept=default
Compares font definitions.
float fontSize
Size of the font in pixels.
Definition: Font.h:96
Defines a quad with locations in screen space defined by [x0, y0] and [x1, y1].
Definition: Font.h:48
Defines a single character from a font resource.
Definition: Font.h:29
Font resources are used to render text with a specific font and size.
Definition: Font.h:22
bool sdf
If the font is generated as a distance field.
Definition: Font.h:78
float ascent
Font ascent given in pixels.
Definition: Font.h:69
Font()=default
Default construct a new Font resource.
std::vector< uint8_t > bitmap
Bitmap font data storage.
Definition: Font.h:81
std::vector< Character > characters
Contains all available characters in the font, defining their locations in the cached bitmap.
Definition: Font.h:63
Font & operator=(Font &&other) noexcept=default
Move assign Font from other.
TextureHandle texture
Handle to the texture used to hold the bitmap font data.
Definition: Font.h:84
float size
Desired font size given in pixels.
Definition: Font.h:66
Font(Font &&other) noexcept=default
Move construct Font from other.
float descent
Font descent given in pixels.
Definition: Font.h:72
int bitmapSize
Bitmap font size in pixels. The font cache bitmap will be bitmapSize * bitmapSize * 4 bytes.
Definition: Font.h:75
Base class for engine resources.
Definition: ResourceBase.h:107
static const ResourceHandle_t NoHandle
Handle representing a default (or none if default not present) resource.