summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/text.cc47
-rw-r--r--src/text.h8
2 files changed, 51 insertions, 4 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);
diff --git a/src/text.h b/src/text.h
index 13b0dcd..5b578d0 100644
--- a/src/text.h
+++ b/src/text.h
@@ -46,8 +46,8 @@ enum font_error_e : u8 {
};
struct font_s {
+ struct font_context_s* context;
FT_Face face;
- u32 font_size;
struct atlas_s atlas;
struct hashmap_s<codepoint_t, struct glyph_s> cached;
@@ -58,7 +58,7 @@ enum font_error_e wayc_font_init(struct font_s* font,
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,
+enum font_error_e wayc_font_raster(struct font_s* font, codepoint_t codepoint,
struct glyph_s* glyph);
static inline enum font_error_e wayc_font_flush(struct font_s* font) {
@@ -66,4 +66,8 @@ static inline enum font_error_e wayc_font_flush(struct font_s* font) {
return (enum font_error_e)wayc_max(atlas_err, 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);
+
void wayc_font_deinit(struct font_s* font);