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 05:32:32 +0300
committerHarley Acheson <harley.acheson@gmail.com>2022-02-05 05:32:32 +0300
commit835dd950467fe5215911a81485393fb6ce3a03cd (patch)
tree94d2a6eaeb4f8cbb755ef31b92b417117d461889 /source/blender/blenfont
parentb1cee3619062124497c73a24c3d87853f544c5f1 (diff)
BLF: Cleanup blf_glyph_cache_find & blf_font_size
Removes unnecessary calls to blf_glyph_cache_find, simplifies blf_font_size, and reduces calls to it. blf_glyph_cache_new and blf_glyph_cache_find made static. See D13374 for more details. Differential Revision: https://developer.blender.org/D13374 Reviewed by Campbell Barton
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r--source/blender/blenfont/intern/blf_font.c28
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c4
-rw-r--r--source/blender/blenfont/intern/blf_internal.h14
-rw-r--r--source/blender/blenfont/intern/blf_thumbs.c7
4 files changed, 18 insertions, 35 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index da533820d72..c1410447de6 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -1342,35 +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);
+ return true;
}
/** \} */
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index c8cc15e804b..bcd9e1fb3a2 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -74,7 +74,7 @@ static FT_Fixed to_16dot16(double val)
/** \name Glyph Cache
* \{ */
-GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, float size, unsigned int dpi)
+static GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, float size, unsigned int dpi)
{
GlyphCacheBLF *gc = (GlyphCacheBLF *)font->cache.first;
while (gc) {
@@ -87,7 +87,7 @@ GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, float size, unsigned int dpi)
return NULL;
}
-GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
+static GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
{
GlyphCacheBLF *gc = (GlyphCacheBLF *)MEM_callocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new");
diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h
index 1a80be0503c..d0bb3385e2c 100644
--- a/source/blender/blenfont/intern/blf_internal.h
+++ b/source/blender/blenfont/intern/blf_internal.h
@@ -56,7 +56,11 @@ struct FontBLF *blf_font_new(const char *name, const char *filename);
struct FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, int mem_size);
void blf_font_attach_from_mem(struct FontBLF *font, const unsigned char *mem, int mem_size);
-void blf_font_size(struct FontBLF *font, float size, unsigned int dpi);
+/**
+ * Change font's output size. Returns true if successful in changing the size.
+ */
+bool blf_font_size(struct FontBLF *font, float size, unsigned int dpi);
+
void blf_font_draw(struct FontBLF *font,
const char *str,
size_t str_len,
@@ -134,14 +138,6 @@ int blf_font_count_missing_chars(struct FontBLF *font,
void blf_font_free(struct FontBLF *font);
-/**
- * Find a glyph cache that matches a size, DPI & styles.
- */
-struct GlyphCacheBLF *blf_glyph_cache_find(struct FontBLF *font, float size, unsigned int dpi);
-/**
- * Create a new glyph cache for the current size, DPI & styles.
- */
-struct GlyphCacheBLF *blf_glyph_cache_new(struct FontBLF *font);
struct GlyphCacheBLF *blf_glyph_cache_acquire(struct FontBLF *font);
void blf_glyph_cache_release(struct FontBLF *font);
void blf_glyph_cache_clear(struct FontBLF *font);
diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c
index 06bbd0cf521..f666976547e 100644
--- a/source/blender/blenfont/intern/blf_thumbs.c
+++ b/source/blender/blenfont/intern/blf_thumbs.c
@@ -61,7 +61,6 @@ void BLF_thumb_preview(const char *filename,
int font_shrink = 4;
FontBLF *font;
- GlyphCacheBLF *gc;
/* Create a new blender font obj and fill it with default values */
font = blf_font_new("thumb_font", filename);
@@ -90,10 +89,8 @@ void BLF_thumb_preview(const char *filename,
const size_t draw_str_i18n_len = strlen(draw_str_i18n);
int draw_str_i18n_nbr = 0;
- blf_font_size(font, (float)MAX2(font_size_min, font_size_curr), dpi);
- gc = blf_glyph_cache_find(font, font->size, font->dpi);
- /* There will be no matching glyph cache if blf_font_size() failed to set font size. */
- if (!gc) {
+ CLAMP_MIN(font_size_curr, font_size_min);
+ if (!blf_font_size(font, (float)font_size_curr, dpi)) {
break;
}