summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-13 06:25:08 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-13 06:25:08 +0100
commit2600ac4737d0098d650b792a30ccc557f6d76d16 (patch)
tree84c29db38a482647303bd143f10c7e1fee4f21eb
parent5630b919ea8cd4432fc3a9ce722e37a9e2740b40 (diff)
working on glyph
-rw-r--r--src/text.cc19
-rw-r--r--src/text.h12
2 files changed, 31 insertions, 0 deletions
diff --git a/src/text.cc b/src/text.cc
index e6ce175..b703ad1 100644
--- a/src/text.cc
+++ b/src/text.cc
@@ -5,6 +5,7 @@
#include "atlas.h"
#include "freetype/freetype.h"
+#include "hash.h"
#include "shaders.h"
#include "utils.h"
@@ -134,14 +135,32 @@ enum font_error_e wayc_font_init(struct font_s* font,
font->face = face;
font->font_size = font_size;
font->atlas = atlas;
+ wayc_hashmap_init(&font->cached);
success = true;
return FONT_ERROR_NONE;
}
+enum font_error_e wayc_font_render(struct font_s* font, codepoint_t codepoint,
+ struct glyph_s* glyph) {
+ wayc_notnull(font);
+ wayc_notnull(glyph);
+
+ struct glyph_s cached;
+ if (wayc_hashmap_get(&font->cached, &codepoint, &cached)) {
+ *glyph = cached;
+ return FONT_ERROR_NONE;
+ }
+
+
+
+ return FONT_ERROR_NONE;
+}
+
void wayc_font_deinit(struct font_s* font) {
wayc_notnull(font);
+ wayc_hashmap_deinit(&font->cached);
wayc_atlas_deinit(&font->atlas);
FT_Done_Face(font->face);
}
diff --git a/src/text.h b/src/text.h
index 6b74e34..4dd495b 100644
--- a/src/text.h
+++ b/src/text.h
@@ -3,6 +3,7 @@
#include "atlas.h"
#include "cglm/types.h"
#include "freetype/freetype.h"
+#include "hash.h"
#include "sokol_gfx.h"
#include "utils.h"
@@ -11,6 +12,8 @@ struct text_vertex_s {
vec2 uv;
};
+typedef u32 codepoint_t;
+
enum font_context_error_e : u8 {
FONT_CONTEXT_ERROR_NONE = 0,
FONT_CONTEXT_ERROR_LOAD_LIBRARY,
@@ -29,6 +32,12 @@ enum font_context_error_e wayc_font_context_init(
struct font_context_s* context);
void wayc_font_context_deinit(struct font_context_s* context);
+struct glyph_s {
+ vec2 bearing;
+ vec2 size;
+ vec2 uv;
+};
+
enum font_error_e : u8 {
FONT_ERROR_NONE = 0,
FONT_ERROR_LOAD_FACE,
@@ -40,10 +49,13 @@ struct font_s {
u32 font_size;
struct atlas_s atlas;
+ struct hashmap_s<codepoint_t, struct glyph_s> cached;
};
enum font_error_e wayc_font_init(struct font_s* font,
struct font_context_s* context,
const char* path, u32 font_size,
u32 atlas_width, u32 atlas_height);
+enum font_error_e wayc_font_render(struct font_s* font, codepoint_t codepoint,
+ struct glyph_s* glyph);
void wayc_font_deinit(struct font_s* font);