summaryrefslogtreecommitdiff
path: root/src/text.cc
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-11 21:55:20 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-11 21:55:20 +0100
commit555cfbe1ceeb879ecefcf8666225d3c28a19e6df (patch)
tree37a5b39f3663399ffaa9f1d5ff3cc0339b0ed6c4 /src/text.cc
parent952dc19e0eeec2b0ba695970ac3f5a2997e39c77 (diff)
uploading to atlas
Diffstat (limited to 'src/text.cc')
-rw-r--r--src/text.cc26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/text.cc b/src/text.cc
index 21cee19..fc67626 100644
--- a/src/text.cc
+++ b/src/text.cc
@@ -5,8 +5,10 @@
#include <unistd.h>
#include <utils.h>
+#include "cglm/ivec2.h"
#include "freetype/freetype.h"
#include "hash.h"
+#include "rendering.h"
#include "utils.h"
static bool wayc_font_cache_lookup(struct font_s* font, codepoint_t codepoint,
@@ -39,7 +41,8 @@ void wayc_font_context_deinit(struct font_context_s* ctx) {
}
enum font_error_e wayc_font_init(struct font_s* font,
- struct font_context_s* ctx, const char* path) {
+ struct font_context_s* ctx, u32 fsize,
+ const char* path) {
wayc_notnull(font);
wayc_notnull(ctx);
wayc_notnull(path);
@@ -62,9 +65,14 @@ enum font_error_e wayc_font_init(struct font_s* font,
FT_Error err = FT_New_Memory_Face(ctx->library, data, size, 0, &font->face);
if (err) return FONT_ERROR_FONT_LOAD;
+ wayc_defer_cond(FT_Done_Face(font->face);, success, true);
+
+ err = FT_Set_Pixel_Sizes(font->face, 0, fsize);
+ if (err) return FONT_ERROR_FONT_LOAD;
font->data = data;
wayc_hashmap_init(&font->cache);
+ glm_ivec2_zero(font->cursor);
success = true;
return FONT_ERROR_NONE;
@@ -87,7 +95,21 @@ enum font_error_e wayc_font_lookup(struct font_s* font, struct atlas_s* atlas,
FT_GlyphSlot slot = face->glyph;
FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
- wayc_panic("not yet implemented");
+ FT_Bitmap bitmap = slot->bitmap;
+ ivec2 size = {(i32)bitmap.width, (i32)bitmap.rows};
+
+ wayc_atlas_set(atlas, IMAGE_DATA_TYPE_UNSIGNED_BYTE, font->cursor, size[0],
+ size[1], bitmap.buffer);
+
+ struct glyph_s glyph = {};
+ glm_ivec2(font->cursor, glyph.uv0);
+ glm_ivec2_add(glyph.uv0, size, glyph.uv1);
+
+ wayc_font_cache_insert(font, codepoint, glyph);
+ glm_ivec2_add(font->cursor, size, font->cursor);
+
+ *out = glyph;
+ return FONT_ERROR_NONE;
}
void wayc_font_deinit(struct font_s* font) {