Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-03-31 16:24:10 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-03-31 20:32:53 +0300
commitf9691bae840a136ff0f55e8a99b42dd10f0fa8d8 (patch)
tree27dcc5a2e426c2560804ceb1e60a55ec061696fe /source/blender/blenfont/intern/blf_glyph.c
parent0ef38879b3adc200f65b24ab11e1134c6eeec161 (diff)
BLF: Perf: Add a kerning cache table for ascii chars.
This adds less than a megabyte of mem usage. FT_Get_Kerning was the 2nd hotspot when profilling. This commit completly remove this cost. One concern though: I don't know if the kerning data is constant for every sizes but it seems to be the case. I tested different fonts at different dpi scalling and saw no differences.
Diffstat (limited to 'source/blender/blenfont/intern/blf_glyph.c')
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index d472825e940..f5a645af5e0 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -65,6 +65,61 @@
#include "BLI_strict_flags.h"
#include "BLI_math_vector.h"
+KerningCacheBLF *blf_kerning_cache_find(FontBLF *font)
+{
+ KerningCacheBLF *p;
+
+ p = (KerningCacheBLF *)font->kerning_caches.first;
+ while (p) {
+ if (p->mode == font->kerning_mode)
+ return p;
+ p = p->next;
+ }
+ return NULL;
+}
+
+/* Create a new glyph cache for the current kerning mode. */
+KerningCacheBLF *blf_kerning_cache_new(FontBLF *font)
+{
+ KerningCacheBLF *kc;
+
+ kc = (KerningCacheBLF *)MEM_callocN(sizeof(KerningCacheBLF), "blf_kerning_cache_new");
+ kc->next = NULL;
+ kc->prev = NULL;
+ kc->mode = font->kerning_mode;
+
+ unsigned int i, j;
+ for (i = 0; i < 0x80; i++) {
+ for (j = 0; j < 0x80; j++) {
+ GlyphBLF *g = blf_glyph_search(font->glyph_cache, i);
+ if (!g) {
+ FT_UInt glyph_index = FT_Get_Char_Index(font->face, i);
+ g = blf_glyph_add(font, glyph_index, i);
+ }
+ /* Cannot fail since it has been added just before. */
+ GlyphBLF *g_prev = blf_glyph_search(font->glyph_cache, j);
+
+ FT_Vector delta = {.x = 0, .y = 0};
+ if (FT_Get_Kerning(font->face, g_prev->idx, g->idx, kc->mode,
+ &delta) == 0) {
+ kc->table[i][j] = (int)delta.x >> 6;
+ }
+ else {
+ kc->table[i][j] = 0;
+ }
+ }
+ }
+
+ BLI_addhead(&font->kerning_caches, kc);
+ return kc;
+}
+
+void blf_kerning_cache_clear(FontBLF *font)
+{
+ font->kerning_cache = NULL;
+ BLI_freelistN(&font->kerning_caches);
+}
+
GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, unsigned int size, unsigned int dpi)
{
GlyphCacheBLF *p;