diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-08-02 16:19:07 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-08-02 16:19:07 +0000 |
| commit | 4d7993b36fa3f97e26c527c37b36eb9321b79791 (patch) | |
| tree | 391b9125d821de5010b5f383813135882d54293d /font.c | |
| parent | term: implement reset (diff) | |
cell: pack more efficiently and store glyph as a wchar
The 'attributes' struct is now 8 bytes and naturally packed (used to
be 9 bytes, artificially packed).
'cell' struct is now 12 bytes, naturally packed (used to be 13 bytes,
artificially packed).
Furthermore, the glyph is stored as a wchar instead of a char*. This
makes it easier (faster) to do glyph lookup when rendering.
Diffstat (limited to 'font.c')
| -rw-r--r-- | font.c | 23 |
1 files changed, 7 insertions, 16 deletions
@@ -381,29 +381,23 @@ glyph_for_wchar(struct font *font, wchar_t wc, struct glyph *glyph) .left = font->face->glyph->bitmap_left, .top = font->face->glyph->bitmap_top, .pixel_size_fixup = font->pixel_size_fixup, + .valid = true, }; return true; err: + *glyph = (struct glyph){ + .valid = false, + }; return false; } const struct glyph * -font_glyph_for_utf8(struct font *font, const char *utf8) +font_glyph_for_wc(struct font *font, wchar_t wc) { mtx_lock(&font->lock); - mbstate_t ps = {0}; - wchar_t wc; - if (mbrtowc(&wc, utf8, 4, &ps) < 0) { - LOG_DBG("failed to convert utf-8 sequence %02x %02x %02x %02x to unicode", - (unsigned char)utf8[0], (unsigned char)utf8[1], - (unsigned char)utf8[2], (unsigned char)utf8[3]); - mtx_unlock(&font->lock); - return NULL; - } - assert(font->cache != NULL); size_t hash_idx = hash_index(wc); hash_entry_t *hash_entry = font->cache[hash_idx]; @@ -418,10 +412,7 @@ font_glyph_for_utf8(struct font *font, const char *utf8) } struct glyph glyph; - if (!glyph_for_wchar(font, wc, &glyph)) { - mtx_unlock(&font->lock); - return NULL; - } + bool got_glyph = glyph_for_wchar(font, wc, &glyph); if (hash_entry == NULL) { hash_entry = calloc(1, sizeof(*hash_entry)); @@ -434,7 +425,7 @@ font_glyph_for_utf8(struct font *font, const char *utf8) tll_push_back(*hash_entry, glyph); mtx_unlock(&font->lock); - return &tll_back(*hash_entry); + return got_glyph ? &tll_back(*hash_entry) : NULL; } void |
