summaryrefslogtreecommitdiff
path: root/src/text.cc
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-13 07:49:24 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-13 07:49:24 +0100
commit22590b99e826b6ad16303d39b47f4925e9e45c22 (patch)
treef5580c8b01d1ef3a8e7265ae5d5faab9d6897ebd /src/text.cc
parentb22b4f825e25cc41ec2119911db3945642099ab5 (diff)
rasterizing full text
Diffstat (limited to 'src/text.cc')
-rw-r--r--src/text.cc47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/text.cc b/src/text.cc
index 992f20f..fab8cbb 100644
--- a/src/text.cc
+++ b/src/text.cc
@@ -137,8 +137,8 @@ enum font_error_e wayc_font_init(struct font_s* font,
wayc_atlas_init(&atlas, atlas_width, atlas_height, SG_PIXELFORMAT_R8);
if (aterr) return FONT_ERROR_ATLAS_FAILED;
+ font->context = context;
font->face = face;
- font->font_size = font_size;
font->atlas = atlas;
wayc_hashmap_init(&font->cached);
@@ -146,7 +146,7 @@ enum font_error_e wayc_font_init(struct font_s* font,
return FONT_ERROR_NONE;
}
-enum font_error_e wayc_font_render(struct font_s* font, codepoint_t codepoint,
+enum font_error_e wayc_font_raster(struct font_s* font, codepoint_t codepoint,
struct glyph_s* glyph) {
wayc_notnull(font);
wayc_notnull(glyph);
@@ -186,6 +186,49 @@ enum font_error_e wayc_font_render(struct font_s* font, codepoint_t codepoint,
return FONT_ERROR_NONE;
}
+enum font_error_e wayc_font_raster(struct font_s* font, const char* text,
+ usize text_len, struct glyph_s* glyphs,
+ usize max_glyphs) {
+ wayc_notnull(font);
+ wayc_notnull(text);
+ wayc_notnull(glyphs);
+ memset(glyphs, 0, sizeof(*glyphs) * max_glyphs);
+
+ usize count = 0;
+ for (usize i = 0; i < text_len && count < max_glyphs; i++) {
+ codepoint_t codepoint = (codepoint_t)text[i]; // TODO: handle UTF-8
+ struct glyph_s glyph;
+ enum font_error_e err = wayc_font_raster(font, codepoint, &glyph);
+ if (err) return err;
+
+ glyphs[count++] = glyph;
+ }
+
+ return FONT_ERROR_NONE;
+}
+
+enum font_error_e wayc_font_raster_text(struct font_s* font, const char* text,
+ usize text_len, struct glyph_s* glyphs,
+ usize max_glyphs) {
+ wayc_notnull(font);
+ wayc_notnull(text);
+ wayc_notnull(glyphs);
+ memset(glyphs, 0, sizeof(*glyphs) * max_glyphs);
+
+ usize count = 0;
+ for (usize i = 0; i < text_len && count < max_glyphs; i++) {
+ codepoint_t codepoint = (codepoint_t)text[i]; // TODO: handle utf-8
+
+ struct glyph_s glyph;
+ enum font_error_e err = wayc_font_raster(font, codepoint, &glyph);
+ if (err != FONT_ERROR_NONE) return err;
+
+ glyphs[count++] = glyph;
+ }
+
+ return FONT_ERROR_NONE;
+}
+
void wayc_font_deinit(struct font_s* font) {
wayc_notnull(font);