Kohi Game Engine
font_system.h
Go to the documentation of this file.
1 
24 #pragma once
25 
26 #include <containers/array.h>
27 #include <core_render_types.h>
28 #include <identifiers/khandle.h>
29 #include <math/math_types.h>
30 #include <strings/kname.h>
31 
32 struct font_system_state;
33 
34 typedef enum font_type {
38 
39 typedef struct font_glyph {
41  u16 x;
42  u16 y;
50 
51 typedef struct font_kerning {
56 
57 typedef struct font_page {
60 
64 
70 typedef struct system_font_variant {
71  // Handle to the base font.
73  // Handle to the font size variant.
76 
81  // The resource name.
83  // The resource name.
86 
91  // The resource name.
93  // The resource name.
95  // The default font size to be used with the system font.
98 
104 typedef struct font_system_config {
109 
114 
120 
124 typedef struct font_geometry {
136 
144 b8 font_system_deserialize_config(const char* config_str, font_system_config* out_config);
145 
156 b8 font_system_initialize(u64* memory_requirement, void* memory, font_system_config* config);
157 
163 void font_system_shutdown(struct font_system_state* state);
164 
173 KAPI b8 font_system_bitmap_font_acquire(struct font_system_state* state, kname name, khandle* out_font);
174 
183 KAPI b8 font_system_bitmap_font_load(struct font_system_state* state, kname asset_name, kname package_name);
184 
195 KAPI b8 font_system_bitmap_font_measure_string(struct font_system_state* state, khandle font, const char* text, vec2* out_size);
196 
204 KAPI ktexture font_system_bitmap_font_atlas_get(struct font_system_state* state, khandle font);
205 
213 KAPI f32 font_system_bitmap_font_line_height_get(struct font_system_state* state, khandle font);
214 
224 KAPI b8 font_system_bitmap_font_generate_geometry(struct font_system_state* state, khandle font, const char* text, font_geometry* out_geometry);
225 
235 KAPI b8 font_system_system_font_acquire(struct font_system_state* state, kname name, u16 font_size, system_font_variant* out_variant);
236 
246 KAPI b8 font_system_system_font_load(struct font_system_state* state, kname resource_name, kname package_name, u16 default_size);
247 
257 KAPI b8 font_system_system_font_verify_atlas(struct font_system_state* state, system_font_variant variant, const char* text);
258 
269 KAPI b8 font_system_system_font_measure_string(struct font_system_state* state, system_font_variant variant, const char* text, vec2* out_size);
270 
278 KAPI f32 font_system_system_font_line_height_get(struct font_system_state* state, system_font_variant variant);
279 
289 KAPI b8 font_system_system_font_generate_geometry(struct font_system_state* state, system_font_variant variant, const char* text, font_geometry* out_geometry);
290 
298 KAPI ktexture font_system_system_font_atlas_get(struct font_system_state* state, system_font_variant variant);
This files contains an implementation of a static-sized (but dynamically allocated) array.
u16 ktexture
Represents a texture to be used for rendering purposes, stored on the GPU (VRAM)
Definition: core_render_types.h:299
#define KAPI
Import/export qualifier.
Definition: defines.h:209
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:27
_Bool b8
8-bit boolean type
Definition: defines.h:60
float f32
32-bit floating point number
Definition: defines.h:49
signed int i32
Signed 32-bit integer.
Definition: defines.h:41
unsigned short u16
Unsigned 16-bit integer.
Definition: defines.h:24
signed short i16
Signed 16-bit integer.
Definition: defines.h:38
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:30
unsigned char u8
Unsigned 8-bit integer.
Definition: defines.h:21
void font_system_shutdown(struct font_system_state *state)
Shuts down the font system.
font_type
Definition: font_system.h:34
@ FONT_TYPE_SYSTEM
Definition: font_system.h:36
@ FONT_TYPE_BITMAP
Definition: font_system.h:35
ARRAY_TYPE(font_glyph)
struct system_font_variant system_font_variant
KAPI b8 font_system_bitmap_font_measure_string(struct font_system_state *state, khandle font, const char *text, vec2 *out_size)
Measures the given string to find out how large it is at the widest/tallest point using the given bit...
KAPI b8 font_system_bitmap_font_generate_geometry(struct font_system_state *state, khandle font, const char *text, font_geometry *out_geometry)
Generates geometry data for a bitmap font.
KAPI b8 font_system_bitmap_font_load(struct font_system_state *state, kname asset_name, kname package_name)
Attempts to load a bitmap font from the given named resource.
struct font_system_config font_system_config
The configuration of the font system. Should be setup by the application during the boot process.
b8 font_system_initialize(u64 *memory_requirement, void *memory, font_system_config *config)
Initializes the font system. As with other systems, this should be called twice; once to get the memo...
KAPI b8 font_system_system_font_verify_atlas(struct font_system_state *state, system_font_variant variant, const char *text)
Verifies the atlas of the provided system font contains the characters in text.
KAPI f32 font_system_system_font_line_height_get(struct font_system_state *state, system_font_variant variant)
Gets the line height of the given font.
KAPI b8 font_system_system_font_acquire(struct font_system_state *state, kname name, u16 font_size, system_font_variant *out_variant)
Attempts to acquire a system font variant of the given name and size. Must be a registered/loaded fon...
KAPI ktexture font_system_system_font_atlas_get(struct font_system_state *state, system_font_variant variant)
Gets a pointer to the font's atlas.
KAPI b8 font_system_system_font_measure_string(struct font_system_state *state, system_font_variant variant, const char *text, vec2 *out_size)
Measures the given string to find out how large it is at the widest/tallest point using the given sys...
struct font_system_bitmap_font_config font_system_bitmap_font_config
The configuration for a bitmap font in the font system config.
struct font_geometry font_geometry
struct font_page font_page
KAPI ktexture font_system_bitmap_font_atlas_get(struct font_system_state *state, khandle font)
Gets a pointer to the font's atlas.
KAPI f32 font_system_bitmap_font_line_height_get(struct font_system_state *state, khandle font)
Gets the line height of the given font.
struct font_glyph font_glyph
struct font_system_system_font_config font_system_system_font_config
The configuration for a system font in the font system config.
KAPI b8 font_system_bitmap_font_acquire(struct font_system_state *state, kname name, khandle *out_font)
Attempts to acquire a bitmap font of the given name. Must be a registered/loaded font.
KAPI b8 font_system_system_font_load(struct font_system_state *state, kname resource_name, kname package_name, u16 default_size)
Attempts to load a system font from the given named resource.
struct font_kerning font_kerning
b8 font_system_deserialize_config(const char *config_str, font_system_config *out_config)
Deserializes font system configuration from the provided string.
KAPI b8 font_system_system_font_generate_geometry(struct font_system_state *state, system_font_variant variant, const char *text, font_geometry *out_geometry)
Generates geometry data for a system font variant.
A global handle system for Kohi. Handles are used to obtain various resources using a unique handle i...
This files contains an implementation of knames.
u64 kname
A kname is a string hash made for quick comparisons versus traditional string comparisons.
Definition: kname.h:36
Contains various math types required for the engine.
Definition: font_system.h:124
u64 index_buffer_size
The size of the index buffer data in bytes.
Definition: font_system.h:130
u32 * index_buffer_data
The index buffer data.
Definition: font_system.h:134
u32 quad_count
The number of quads to be drawn.
Definition: font_system.h:126
vertex_2d * vertex_buffer_data
The vertex buffer data.
Definition: font_system.h:132
u64 vertex_buffer_size
The size of the vertex buffer data in bytes.
Definition: font_system.h:128
Definition: font_system.h:39
u16 height
Definition: font_system.h:44
u16 width
Definition: font_system.h:43
i16 x_advance
Definition: font_system.h:47
i16 y_offset
Definition: font_system.h:46
u16 y
Definition: font_system.h:42
u8 page_id
Definition: font_system.h:48
u16 x
Definition: font_system.h:41
i16 x_offset
Definition: font_system.h:45
i32 codepoint
Definition: font_system.h:40
Definition: font_system.h:51
i32 codepoint_1
Definition: font_system.h:53
i32 codepoint_0
Definition: font_system.h:52
i16 amount
Definition: font_system.h:54
Definition: font_system.h:57
kname image_asset_name
Definition: font_system.h:58
The configuration for a bitmap font in the font system config.
Definition: font_system.h:80
kname resource_name
Definition: font_system.h:82
kname package_name
Definition: font_system.h:84
The configuration of the font system. Should be setup by the application during the boot process.
Definition: font_system.h:104
u8 max_bitmap_font_count
The max number of bitmap fonts that can be loaded.
Definition: font_system.h:106
font_system_bitmap_font_config * bitmap_fonts
A collection of bitmap fonts configured in the system.
Definition: font_system.h:113
u8 max_system_font_count
The max number of system fonts that can be loaded.
Definition: font_system.h:108
font_system_system_font_config * system_fonts
A collection of system fonts configured in the system.
Definition: font_system.h:118
u8 bitmap_font_count
The number of bitmap fonts configured in the system.
Definition: font_system.h:111
u8 system_font_count
The number of system fonts configured in the system.
Definition: font_system.h:116
The configuration for a system font in the font system config.
Definition: font_system.h:90
u16 default_size
Definition: font_system.h:96
kname resource_name
Definition: font_system.h:92
kname package_name
Definition: font_system.h:94
A handle is a unique identifier used a system in the engine to avoid using raw pointers where possibl...
Definition: khandle.h:25
Definition: font_system.h:70
khandle variant
Definition: font_system.h:74
khandle base_font
Definition: font_system.h:72
Represents a single vertex in 2D space.
Definition: math_types.h:459
A 2-element vector.
Definition: math_types.h:31