From c69ef385fcb99c7fbce0b031d76f517cc028a176 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 6 Sep 2025 14:11:41 +1000 Subject: [PATCH] Cleanup: use const arguments in BLF funcitons --- source/blender/blenfont/intern/blf_default.cc | 7 ++-- source/blender/blenfont/intern/blf_font.cc | 38 +++++++++---------- source/blender/blenfont/intern/blf_glyph.cc | 31 ++++++++------- source/blender/blenfont/intern/blf_thumbs.cc | 5 ++- 4 files changed, 44 insertions(+), 37 deletions(-) diff --git a/source/blender/blenfont/intern/blf_default.cc b/source/blender/blenfont/intern/blf_default.cc index be1d9a5110a..771b00915b8 100644 --- a/source/blender/blenfont/intern/blf_default.cc +++ b/source/blender/blenfont/intern/blf_default.cc @@ -22,12 +22,12 @@ static int global_font_default = -1; /* Keep in sync with `UI_DEFAULT_TEXT_POINTS` */ static float global_font_size = 11.0f; -void BLF_default_size(float size) +void BLF_default_size(const float size) { global_font_size = size; } -void BLF_default_set(int fontid) +void BLF_default_set(const int fontid) { if ((fontid == -1) || BLF_is_loaded_id(fontid)) { global_font_default = fontid; @@ -49,7 +49,8 @@ int BLF_set_default() return global_font_default; } -void BLF_draw_default(float x, float y, float z, const char *str, const size_t str_len) +void BLF_draw_default( + const float x, const float y, const float z, const char *str, const size_t str_len) { ASSERT_DEFAULT_SET; BLF_size(global_font_default, global_font_size * UI_SCALE_FAC); diff --git a/source/blender/blenfont/intern/blf_font.cc b/source/blender/blenfont/intern/blf_font.cc index 82d4a07c545..bc89b8683fc 100644 --- a/source/blender/blenfont/intern/blf_font.cc +++ b/source/blender/blenfont/intern/blf_font.cc @@ -145,7 +145,7 @@ static void blf_size_finalizer(void *object) /** \name FreeType Utilities (Internal) * \{ */ -uint blf_get_char_index(FontBLF *font, uint charcode) +uint blf_get_char_index(FontBLF *font, const uint charcode) { if (font->flags & BLF_CACHED) { /* Use char-map cache for much faster lookup. */ @@ -156,7 +156,7 @@ uint blf_get_char_index(FontBLF *font, uint charcode) } /* Convert a FreeType 26.6 value representing an unscaled design size to fractional pixels. */ -static ft_pix blf_unscaled_F26Dot6_to_pixels(FontBLF *font, FT_Pos value) +static ft_pix blf_unscaled_F26Dot6_to_pixels(FontBLF *font, const FT_Pos value) { /* Make sure we have a valid font->ft_size. */ blf_ensure_size(font); @@ -386,7 +386,7 @@ BLI_INLINE GlyphBLF *blf_glyph_from_utf8_and_step(FontBLF *font, GlyphCacheBLF *gc, const GlyphBLF *g_prev, const char *str, - size_t str_len, + const size_t str_len, size_t *i_p, int32_t *pen_x) { @@ -481,7 +481,7 @@ void blf_font_draw(FontBLF *font, const char *str, const size_t str_len, ResultB } int blf_font_draw_mono( - FontBLF *font, const char *str, const size_t str_len, int cwidth, int tab_columns) + FontBLF *font, const char *str, const size_t str_len, const int cwidth, const int tab_columns) { GlyphBLF *g; int columns = 0; @@ -517,13 +517,13 @@ int blf_font_draw_mono( #ifndef WITH_HEADLESS void blf_draw_svg_icon(FontBLF *font, - uint icon_id, - float x, - float y, - float size, + const uint icon_id, + const float x, + const float y, + const float size, const float color[4], - float outline_alpha, - bool multicolor, + const float outline_alpha, + const bool multicolor, blender::FunctionRef edit_source_cb) { BLI_assert(outline_alpha <= 1.0f); /* Higher values overflow, caller must ensure. */ @@ -564,11 +564,11 @@ void blf_draw_svg_icon(FontBLF *font, } blender::Array blf_svg_icon_bitmap(FontBLF *font, - uint icon_id, - float size, + const uint icon_id, + const float size, int *r_width, int *r_height, - bool multicolor, + const bool multicolor, blender::FunctionRef edit_source_cb) { blf_font_size(font, size); @@ -726,8 +726,8 @@ static void blf_font_draw_buffer_ex(FontBLF *font, GlyphCacheBLF *gc, const char *str, const size_t str_len, - ResultBLF *r_info, - ft_pix pen_y) + const ft_pix pen_y, + ResultBLF *r_info) { GlyphBLF *g = nullptr; ft_pix pen_x = ft_pix_from_int(font->pos[0]); @@ -758,7 +758,7 @@ static void blf_font_draw_buffer_ex(FontBLF *font, void blf_font_draw_buffer(FontBLF *font, const char *str, const size_t str_len, ResultBLF *r_info) { GlyphCacheBLF *gc = blf_glyph_cache_acquire(font); - blf_font_draw_buffer_ex(font, gc, str, str_len, r_info, 0); + blf_font_draw_buffer_ex(font, gc, str, str_len, 0, r_info); blf_glyph_cache_release(font); } @@ -1467,10 +1467,10 @@ static void blf_font_draw_buffer__wrap_cb(FontBLF *font, GlyphCacheBLF *gc, const char *str, const size_t str_len, - ft_pix pen_y, + const ft_pix pen_y, void * /*userdata*/) { - blf_font_draw_buffer_ex(font, gc, str, str_len, nullptr, pen_y); + blf_font_draw_buffer_ex(font, gc, str, str_len, pen_y, nullptr); } void blf_font_draw_buffer__wrap(FontBLF *font, const char *str, @@ -1492,7 +1492,7 @@ static void blf_font_string_wrap_cb(FontBLF * /*font*/, GlyphCacheBLF * /*gc*/, const char *str, const size_t str_len, - ft_pix /*pen_y*/, + const ft_pix /*pen_y*/, void *str_list_ptr) { blender::Vector *list = static_cast *>( diff --git a/source/blender/blenfont/intern/blf_glyph.cc b/source/blender/blenfont/intern/blf_glyph.cc index 2db5e4b22f2..5a144003aa4 100644 --- a/source/blender/blenfont/intern/blf_glyph.cc +++ b/source/blender/blenfont/intern/blf_glyph.cc @@ -64,7 +64,7 @@ /** * Convert a floating point value to a FreeType 16.16 fixed point value. */ -static FT_Fixed to_16dot16(double val) +static FT_Fixed to_16dot16(const double val) { return (FT_Fixed)lround(val * 65536.0); } @@ -72,7 +72,7 @@ static FT_Fixed to_16dot16(double val) /** * Convert a floating point value to a FreeType 16.16 fixed point value. */ -static float from_16dot16(FT_Fixed value) +static float from_16dot16(const FT_Fixed value) { return float(value) / 65536.0f; } @@ -171,8 +171,8 @@ void blf_glyph_cache_clear(FontBLF *font) * \return nullptr if not found. */ static GlyphBLF *blf_glyph_cache_find_glyph(const GlyphCacheBLF *gc, - uint charcode, - uint8_t subpixel) + const uint charcode, + const uint8_t subpixel) { const std::unique_ptr *ptr = gc->glyphs.lookup_ptr_as( GlyphCacheKey{charcode, subpixel}); @@ -195,7 +195,7 @@ static GlyphBLF *blf_glyph_cache_find_glyph(const GlyphCacheBLF *gc, * heavy." * https://www.puredevsoftware.com/blog/2019/01/22/sub-pixel-gamma-correct-font-rendering/ */ -static uchar blf_glyph_gamma(uchar c) +static uchar blf_glyph_gamma(const uchar c) { /* The following is `char(powf(c / 256.0f, 1.0f / 1.43f) * 256.0f)`. */ static const uchar gamma[256] = { @@ -222,8 +222,11 @@ static uchar blf_glyph_gamma(uchar c) /** * Add a rendered glyph to a cache. */ -static GlyphBLF *blf_glyph_cache_add_glyph( - GlyphCacheBLF *gc, FT_GlyphSlot glyph, uint charcode, FT_UInt glyph_index, uint8_t subpixel) +static GlyphBLF *blf_glyph_cache_add_glyph(GlyphCacheBLF *gc, + const FT_GlyphSlot glyph, + const uint charcode, + const FT_UInt glyph_index, + const uint8_t subpixel) { std::unique_ptr g = std::make_unique(); g->c = charcode; @@ -338,7 +341,7 @@ static GlyphBLF *blf_glyph_cache_add_glyph( } #ifndef WITH_HEADLESS -static GlyphBLF *blf_glyph_cache_add_blank(GlyphCacheBLF *gc, uint charcode) +static GlyphBLF *blf_glyph_cache_add_blank(GlyphCacheBLF *gc, const uint charcode) { /* Add an empty GlyphBLF to the cache and return it. With * zero dimensions it will be skipped by blf_glyph_draw. */ @@ -352,8 +355,8 @@ static GlyphBLF *blf_glyph_cache_add_blank(GlyphCacheBLF *gc, uint charcode) static GlyphBLF *blf_glyph_cache_add_svg( GlyphCacheBLF *gc, - uint charcode, - bool color, + const uint charcode, + const bool color, blender::FunctionRef edit_source_cb = nullptr) { std::string svg_source = blf_get_icon_svg(int(charcode) - BLF_ICON_OFFSET); @@ -751,7 +754,7 @@ static const UnicodeBlock *blf_charcode_to_unicode_block(const uint charcode) return nullptr; } -static int blf_charcode_to_coverage_bit(uint charcode) +static int blf_charcode_to_coverage_bit(const uint charcode) { int coverage_bit = -1; const UnicodeBlock *block = blf_charcode_to_unicode_block(charcode); @@ -768,7 +771,7 @@ static int blf_charcode_to_coverage_bit(uint charcode) return coverage_bit; } -static bool blf_font_has_coverage_bit(const FontBLF *font, int coverage_bit) +static bool blf_font_has_coverage_bit(const FontBLF *font, const int coverage_bit) { if (coverage_bit < 0) { return false; @@ -842,7 +845,9 @@ static FT_UInt blf_glyph_index_from_charcode(FontBLF **font, const uint charcode /** * Load a glyph into the glyph slot of a font's face object. */ -static FT_GlyphSlot blf_glyph_load(FontBLF *font, FT_UInt glyph_index, bool outline_only) +static FT_GlyphSlot blf_glyph_load(FontBLF *font, + const FT_UInt glyph_index, + const bool outline_only) { int load_flags; diff --git a/source/blender/blenfont/intern/blf_thumbs.cc b/source/blender/blenfont/intern/blf_thumbs.cc index 4d93a497db5..6089d5221ec 100644 --- a/source/blender/blenfont/intern/blf_thumbs.cc +++ b/source/blender/blenfont/intern/blf_thumbs.cc @@ -215,7 +215,7 @@ static const UnicodeSample unicode_samples[] = { {U"\u0533\u0537\u0539", 1, TT_UCR_ARMENIAN}, }; -static const char32_t *blf_get_sample_text(FT_Face face) +static const char32_t *blf_get_sample_text(const FT_Face face) { /* First check for fonts with MS Symbol character map. */ if (face->charmap->encoding == FT_ENCODING_MS_SYMBOL) { @@ -299,7 +299,8 @@ static const char32_t *blf_get_sample_text(FT_Face face) return sample; } -bool BLF_thumb_preview(const char *filepath, uchar *buf, int w, int h, int /*channels*/) +bool BLF_thumb_preview( + const char *filepath, uchar *buf, const int w, const int h, const int /*channels*/) { /* Use own FT_Library and direct FreeType calls as this is called from multiple threads. */ FT_Library ft_lib = nullptr;