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:
authorHarley Acheson <harley.acheson@gmail.com>2022-02-05 04:49:21 +0300
committerHarley Acheson <harley.acheson@gmail.com>2022-02-05 04:49:21 +0300
commitbb3bcf744c9c4d316ddbdcffcdf81c1367bab2b1 (patch)
treec45238c8e2ada7c5550d599c1273aef0d3bab313 /source/blender/blenfont/intern/blf_glyph.c
parent2a967d444f11514891c5d229993d486df06c066e (diff)
BLF: Save fixed_width value in cache
Cache the font size's ideal fixed width column size in the glyph cache rather than the font itself to improve performance. See D13226 for more details. Differential Revision: https://developer.blender.org/D13226 Reviewed by Campbell Barton
Diffstat (limited to 'source/blender/blenfont/intern/blf_glyph.c')
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index b87a784adff..c8cc15e804b 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -34,6 +34,7 @@
#include FT_GLYPH_H
#include FT_OUTLINE_H
#include FT_BITMAP_H
+#include FT_ADVANCES_H /* For FT_Get_Advance. */
#include "MEM_guardedalloc.h"
@@ -100,6 +101,22 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
memset(gc->glyph_ascii_table, 0, sizeof(gc->glyph_ascii_table));
memset(gc->bucket, 0, sizeof(gc->bucket));
+ /* Determine ideal fixed-width size for monospaced output. */
+ FT_UInt gindex = FT_Get_Char_Index(font->face, U'0');
+ if (gindex) {
+ FT_Fixed advance = 0;
+ FT_Get_Advance(font->face, gindex, FT_LOAD_NO_HINTING, &advance);
+ /* Use CSS 'ch unit' width, advance of zero character. */
+ gc->fixed_width = (int)(advance >> 16);
+ }
+ else {
+ /* Font does not contain "0" so use CSS fallback of 1/2 of em. */
+ gc->fixed_width = (int)((font->face->size->metrics.height / 2) >> 6);
+ }
+ if (gc->fixed_width < 1) {
+ gc->fixed_width = 1;
+ }
+
BLI_addhead(&font->cache, gc);
return gc;
}