Kohi Game Engine
font_system.h
Go to the documentation of this file.
1 
24 #pragma once
25 
26 #include "identifiers/khandle.h"
28 #include "math/math_types.h"
29 #include "strings/kname.h"
30 
31 struct font_system_state;
32 
33 typedef enum font_type {
37 
43 typedef struct system_font_variant {
44  // Handle to the base font.
46  // Handle to the font size variant.
49 
54  // The resource name.
56  // The resource name.
59 
64  // The resource name.
66  // The resource name.
68  // The default font size to be used with the system font.
71 
77 typedef struct font_system_config {
82 
87 
93 
97 typedef struct font_geometry {
109 
117 b8 font_system_deserialize_config(const char* config_str, font_system_config* out_config);
118 
129 b8 font_system_initialize(u64* memory_requirement, void* memory, font_system_config* config);
130 
136 void font_system_shutdown(struct font_system_state* state);
137 
146 KAPI b8 font_system_bitmap_font_acquire(struct font_system_state* state, kname name, khandle* out_font);
147 
156 KAPI b8 font_system_bitmap_font_load(struct font_system_state* state, kname asset_name, kname package_name);
157 
168 KAPI b8 font_system_bitmap_font_measure_string(struct font_system_state* state, khandle font, const char* text, vec2* out_size);
169 
177 KAPI ktexture font_system_bitmap_font_atlas_get(struct font_system_state* state, khandle font);
178 
186 KAPI f32 font_system_bitmap_font_line_height_get(struct font_system_state* state, khandle font);
187 
197 KAPI b8 font_system_bitmap_font_generate_geometry(struct font_system_state* state, khandle font, const char* text, font_geometry* out_geometry);
198 
208 KAPI b8 font_system_system_font_acquire(struct font_system_state* state, kname name, u16 font_size, system_font_variant* out_variant);
209 
219 KAPI b8 font_system_system_font_load(struct font_system_state* state, kname resource_name, kname package_name, u16 default_size);
220 
230 KAPI b8 font_system_system_font_verify_atlas(struct font_system_state* state, system_font_variant variant, const char* text);
231 
242 KAPI b8 font_system_system_font_measure_string(struct font_system_state* state, system_font_variant variant, const char* text, vec2* out_size);
243 
251 KAPI f32 font_system_system_font_line_height_get(struct font_system_state* state, system_font_variant variant);
252 
262 KAPI b8 font_system_system_font_generate_geometry(struct font_system_state* state, system_font_variant variant, const char* text, font_geometry* out_geometry);
263 
271 KAPI ktexture font_system_system_font_atlas_get(struct font_system_state* state, system_font_variant variant);
#define KAPI
Import/export qualifier.
Definition: defines.h:205
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:25
_Bool b8
8-bit boolean type
Definition: defines.h:58
float f32
32-bit floating point number
Definition: defines.h:47
unsigned short u16
Unsigned 16-bit integer.
Definition: defines.h:22
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:28
unsigned char u8
Unsigned 8-bit integer.
Definition: defines.h:19
void font_system_shutdown(struct font_system_state *state)
Shuts down the font system.
font_type
Definition: font_system.h:33
@ FONT_TYPE_SYSTEM
Definition: font_system.h:35
@ FONT_TYPE_BITMAP
Definition: font_system.h:34
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
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_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.
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
u16 ktexture
Represents a texture to be used for rendering purposes, stored on the GPU (VRAM)
Definition: kresource_types.h:45
Contains various math types required for the engine.
Definition: font_system.h:97
u64 index_buffer_size
The size of the index buffer data in bytes.
Definition: font_system.h:103
u32 * index_buffer_data
The index buffer data.
Definition: font_system.h:107
u32 quad_count
The number of quads to be drawn.
Definition: font_system.h:99
vertex_2d * vertex_buffer_data
The vertex buffer data.
Definition: font_system.h:105
u64 vertex_buffer_size
The size of the vertex buffer data in bytes.
Definition: font_system.h:101
The configuration for a bitmap font in the font system config.
Definition: font_system.h:53
kname resource_name
Definition: font_system.h:55
kname package_name
Definition: font_system.h:57
The configuration of the font system. Should be setup by the application during the boot process.
Definition: font_system.h:77
u8 max_bitmap_font_count
The max number of bitmap fonts that can be loaded.
Definition: font_system.h:79
font_system_bitmap_font_config * bitmap_fonts
A collection of bitmap fonts configured in the system.
Definition: font_system.h:86
u8 max_system_font_count
The max number of system fonts that can be loaded.
Definition: font_system.h:81
font_system_system_font_config * system_fonts
A collection of system fonts configured in the system.
Definition: font_system.h:91
u8 bitmap_font_count
The number of bitmap fonts configured in the system.
Definition: font_system.h:84
u8 system_font_count
The number of system fonts configured in the system.
Definition: font_system.h:89
The configuration for a system font in the font system config.
Definition: font_system.h:63
u16 default_size
Definition: font_system.h:69
kname resource_name
Definition: font_system.h:65
kname package_name
Definition: font_system.h:67
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:43
khandle variant
Definition: font_system.h:47
khandle base_font
Definition: font_system.h:45
Represents a single vertex in 2D space.
Definition: math_types.h:239
A 2-element vector.
Definition: math_types.h:19