summaryrefslogtreecommitdiff
path: root/src/text.cc
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-11 22:50:21 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-11 22:50:21 +0100
commita0a68b7b3a5430fea5aaa2ad1da75fdda5cd5c7a (patch)
treef30c9d90ce0d864dc65cb1307a7196b80e63d71c /src/text.cc
parent64b0664a648ec4a6c424e932b605f09dc4ee6151 (diff)
packing corrections
Diffstat (limited to 'src/text.cc')
-rw-r--r--src/text.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/text.cc b/src/text.cc
index 2bfc7a3..d02cc77 100644
--- a/src/text.cc
+++ b/src/text.cc
@@ -5,7 +5,7 @@
#include <unistd.h>
#include <utils.h>
-#include "cglm/ivec2.h"
+#include "cglm/types.h"
#include "freetype/freetype.h"
#include "hash.h"
#include "rendering.h"
@@ -72,13 +72,13 @@ enum font_error_e wayc_font_init(struct font_s* font,
font->data = data;
wayc_hashmap_init(&font->cache);
- glm_ivec2_zero(font->cursor);
success = true;
return FONT_ERROR_NONE;
}
enum font_error_e wayc_font_lookup(struct font_s* font, struct atlas_s* atlas,
+ struct atlas_packer_s* packer,
codepoint_t codepoint, struct glyph_s* out) {
wayc_notnull(font);
wayc_notnull(atlas);
@@ -100,20 +100,21 @@ enum font_error_e wayc_font_lookup(struct font_s* font, struct atlas_s* atlas,
if (bitmap.pitch != (i32)bitmap.width) wayc_panic("unsupported pitch");
ivec2 size = {(i32)bitmap.width, (i32)bitmap.rows};
+ ivec2 uv0;
- wayc_atlas_set(atlas, IMAGE_DATA_TYPE_UNSIGNED_BYTE, font->cursor, size[0],
- size[1], IMAGE_FORMAT_RED_ALIGNMENT, bitmap.buffer);
+ bool ok = wayc_atlas_packer_allocate(packer, WAYC_X(size), WAYC_Y(size), uv0);
+ if (!ok) return FONT_ERROR_ATLAS_FULL;
+
+ ok = wayc_atlas_set(atlas, IMAGE_DATA_TYPE_UNSIGNED_BYTE, uv0, WAYC_X(size),
+ WAYC_Y(size), IMAGE_FORMAT_RED_ALIGNMENT, bitmap.buffer);
+ if (!ok) return FONT_ERROR_ATLAS_FULL;
struct glyph_s glyph = {};
glyph.bearing_x = slot->bitmap_left;
glyph.bearing_y = slot->bitmap_top;
glyph.advance = (f32)slot->advance.x / WAYC_SCALE;
- 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;