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:
Diffstat (limited to 'source/blender/blenfont/intern/blf_font.c')
-rw-r--r--source/blender/blenfont/intern/blf_font.c59
1 files changed, 14 insertions, 45 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 14d3a208f69..c1410447de6 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -34,7 +34,6 @@
#include FT_FREETYPE_H
#include FT_GLYPH_H
-#include FT_ADVANCES_H /* For FT_Get_Advance */
#include "MEM_guardedalloc.h"
@@ -826,7 +825,10 @@ float blf_font_height(FontBLF *font,
float blf_font_fixed_width(FontBLF *font)
{
- return (float)font->fixed_width;
+ GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
+ float width = (gc) ? (float)gc->fixed_width : font->size / 2.0f;
+ blf_glyph_cache_release(font);
+ return width;
}
static void blf_font_boundbox_foreach_glyph_ex(FontBLF *font,
@@ -1318,12 +1320,7 @@ FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, int m
void blf_font_free(FontBLF *font)
{
- BLI_spin_lock(&blf_glyph_cache_mutex);
- GlyphCacheBLF *gc;
-
- while ((gc = BLI_pophead(&font->cache))) {
- blf_glyph_cache_free(gc);
- }
+ blf_glyph_cache_clear(font);
if (font->kerning_cache) {
MEM_freeN(font->kerning_cache);
@@ -1337,8 +1334,6 @@ void blf_font_free(FontBLF *font)
MEM_freeN(font->name);
}
MEM_freeN(font);
-
- BLI_spin_unlock(&blf_glyph_cache_mutex);
}
/** \} */
@@ -1347,51 +1342,25 @@ void blf_font_free(FontBLF *font)
/** \name Font Configure
* \{ */
-void blf_font_size(FontBLF *font, float size, unsigned int dpi)
+bool blf_font_size(FontBLF *font, float size, unsigned int dpi)
{
- blf_glyph_cache_acquire(font);
-
/* FreeType uses fixed-point integers in 64ths. */
FT_F26Dot6 ft_size = lroundf(size * 64.0f);
- /* Adjust our size to be on even 64ths. */
+ /* Adjust our new size to be on even 64ths. */
size = (float)ft_size / 64.0f;
- GlyphCacheBLF *gc = blf_glyph_cache_find(font, size, dpi);
- if (gc && (font->size == size && font->dpi == dpi)) {
- /* Optimization: do not call FT_Set_Char_Size if size did not change. */
- }
- else {
- const FT_Error err = FT_Set_Char_Size(font->face, 0, ft_size, dpi, dpi);
- if (err) {
- /* FIXME: here we can go through the fixed size and choice a close one */
- printf("The current font don't support the size, %f and dpi, %u\n", size, dpi);
- }
- else {
+ if (font->size != size || font->dpi != dpi) {
+ if (FT_Set_Char_Size(font->face, 0, ft_size, dpi, dpi) == 0) {
font->size = size;
font->dpi = dpi;
- if (gc == NULL) {
- blf_glyph_cache_new(font);
- }
+ }
+ else {
+ printf("The current font does not support the size, %f and dpi, %u\n", size, dpi);
+ return false;
}
}
- blf_glyph_cache_release(font);
-
- /* Set 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. */
- font->fixed_width = (int)(advance >> 16);
- }
- else {
- /* Font does not contain "0" so use CSS fallback of 1/2 of em. */
- font->fixed_width = (int)((font->face->size->metrics.height / 2) >> 6);
- }
- if (font->fixed_width < 1) {
- font->fixed_width = 1;
- }
+ return true;
}
/** \} */