diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-11 16:47:32 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-11 16:47:32 +0100 |
| commit | cd18a78e924f262fda022cdaab1fc681cce42fec (patch) | |
| tree | de17016bd7a3b189114362deb728d3b623a6af9e | |
| parent | a1dee625dae4c3e39eb6ef16b91be9a374f7874f (diff) | |
starting to upload fonts
| -rw-r--r-- | src/hash.h | 8 | ||||
| -rw-r--r-- | src/text.cc | 43 | ||||
| -rw-r--r-- | src/text.h | 11 |
3 files changed, 45 insertions, 17 deletions
@@ -81,16 +81,18 @@ inline V* wayc_hashmap_insert(hashmap_s<K, V>* map, const K* key, } template <typename K, typename V> -inline V* wayc_hashmap_get(hashmap_s<K, V>* map, const K* key) { +inline bool wayc_hashmap_get(hashmap_s<K, V>* map, const K* key, V* out) { wayc_notnull(map); wayc_notnull(key); + wayc_notnull(out); hashentry_s<K, V> entry{}; entry.key = *key; auto* stored = (hashentry_s<K, V>*)hashmap_get(map->inner, &entry); - if (!stored) return nullptr; + if (!stored) return false; - return &stored->value; + *out = stored->value; + return true; } template <typename K, typename V> diff --git a/src/text.cc b/src/text.cc index a19fe98..d209ed2 100644 --- a/src/text.cc +++ b/src/text.cc @@ -5,18 +5,23 @@ #include <unistd.h> #include <utils.h> -#include "freetype/fttypes.h" +#include "freetype/freetype.h" #include "hash.h" #include "utils.h" -static void wayc_font_cache_init(struct font_cache_s* cache) { - wayc_notnull(cache); - wayc_hashmap_init(&cache->glyphs); +static bool wayc_font_cache_lookup(struct font_s* font, codepoint_t codepoint, + struct glyph_s* out) { + struct glyph_s glyph; + bool ok = wayc_hashmap_get(&font->cache, &codepoint, &glyph); + if (ok) *out = glyph; + return ok; } -static void wayc_font_cache_deinit(struct font_cache_s* cache) { - wayc_notnull(cache); - wayc_hashmap_deinit(&cache->glyphs); +[[maybe_unused]] static void wayc_font_cache_insert(struct font_s* font, + codepoint_t codepoint, + struct glyph_s glyph) { + wayc_notnull(font); + wayc_hashmap_insert(&font->cache, &codepoint, &glyph); } enum font_context_error_e wayc_font_context_init(struct font_context_s* ctx) { @@ -59,16 +64,36 @@ enum font_error_e wayc_font_init(struct font_s* font, if (err) return FONT_ERROR_FONT_LOAD; font->data = data; - wayc_font_cache_init(&font->cache); + wayc_hashmap_init(&font->cache); success = true; return FONT_ERROR_NONE; } +enum font_error_e wayc_font_lookup(struct font_s* font, codepoint_t codepoint, + struct glyph_s* out) { + wayc_notnull(font); + wayc_notnull(out); + + FT_Face face = font->face; + + bool found = wayc_font_cache_lookup(font, codepoint, out); + if (found) return FONT_ERROR_NONE; + + FT_UInt glyph_index = FT_Get_Char_Index(face, codepoint); + if (glyph_index == 0) return FONT_ERROR_NOT_MATCH; + + FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT); + FT_GlyphSlot slot = face->glyph; + FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL); + + wayc_panic("not yet implemented"); +} + void wayc_font_deinit(struct font_s* font) { wayc_notnull(font); - wayc_font_cache_deinit(&font->cache); + wayc_hashmap_deinit(&font->cache); FT_Done_Face(font->face); mi_free(font->data); } @@ -4,6 +4,8 @@ #include "hash.h" #include "utils.h" +typedef u32 codepoint_t; + enum font_context_error_e { FONT_CONTEXT_ERROR_NONE, FONT_CONTEXT_ERROR_LIBRARY, @@ -18,22 +20,21 @@ void wayc_font_context_deinit(struct font_context_s* ctx); struct glyph_s {}; -struct font_cache_s { - struct hashmap_s<u32, struct glyph_s> glyphs; -}; - enum font_error_e { FONT_ERROR_NONE, FONT_ERROR_FILE_LOAD, FONT_ERROR_FONT_LOAD, + FONT_ERROR_NOT_MATCH, }; struct font_s { u8* data; FT_Face face; - struct font_cache_s cache; + struct hashmap_s<codepoint_t, struct glyph_s> cache; }; enum font_error_e wayc_font_init(struct font_s* font, struct font_context_s* ctx, const char* path); +enum font_error_e wayc_font_lookup(struct font_s* font, codepoint_t codepoint, + struct glyph_s* out); void wayc_font_deinit(struct font_s* font); |
