[Bf-blender-cvs] [1e2589bfa58] master: Cleanup: remove redundant BLI_UTF8_ERR check

Campbell Barton noreply at git.blender.org
Fri Oct 29 04:34:37 CEST 2021


Commit: 1e2589bfa580aaa087dd9a6dffd5e0785bb91322
Author: Campbell Barton
Date:   Fri Oct 29 13:15:39 2021 +1100
Branches: master
https://developer.blender.org/rB1e2589bfa580aaa087dd9a6dffd5e0785bb91322

Cleanup: remove redundant BLI_UTF8_ERR check

===================================================================

M	source/blender/blenfont/intern/blf_font.c

===================================================================

diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 52c412a42bb..4125dde1fd1 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -301,6 +301,9 @@ BLI_INLINE GlyphBLF *blf_utf8_next_fast(
     FontBLF *font, GlyphCacheBLF *gc, const char *str, size_t str_len, size_t *i_p)
 {
   uint charcode = BLI_str_utf8_as_unicode_step(str, str_len, i_p);
+  /* Invalid unicode sequences return the byte value, stepping forward one.
+   * This allows `latin1` to display (which is sometimes used for file-paths). */
+  BLI_assert(charcode != BLI_UTF8_ERR);
   return blf_glyph_ensure(font, gc, charcode);
 }
 
@@ -366,9 +369,6 @@ static void blf_font_draw_ex(FontBLF *font,
     if (UNLIKELY(g == NULL)) {
       continue;
     }
-    if (UNLIKELY(g->c == BLI_UTF8_ERR)) {
-      break;
-    }
     pen_x += blf_kerning(font, g_prev, g);
 
     /* do not return this loop if clipped, we want every character tested */
@@ -410,10 +410,6 @@ int blf_font_draw_mono(FontBLF *font, const char *str, const size_t str_len, int
     if (UNLIKELY(g == NULL)) {
       continue;
     }
-    if (UNLIKELY(g->c == BLI_UTF8_ERR)) {
-      break;
-    }
-
     /* do not return this loop if clipped, we want every character tested */
     blf_glyph_draw(font, gc, g, (float)pen_x, (float)pen_y);
 
@@ -466,9 +462,6 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
     if (UNLIKELY(g == NULL)) {
       continue;
     }
-    if (UNLIKELY(g->c == BLI_UTF8_ERR)) {
-      break;
-    }
     pen_x += blf_kerning(font, g_prev, g);
 
     chx = pen_x + ((int)g->pos[0]);
@@ -600,12 +593,10 @@ static bool blf_font_width_to_strlen_glyph_process(
   if (UNLIKELY(g == NULL)) {
     return false; /* continue the calling loop. */
   }
-  if (UNLIKELY(g->c == BLI_UTF8_ERR)) {
-    return true; /* break the calling loop. */
-  }
   *pen_x += blf_kerning(font, g_prev, g);
   *pen_x += g->advance_i;
 
+  /* When true, break the calling loop. */
   return (*pen_x >= width_i);
 }
 
@@ -709,9 +700,6 @@ static void blf_font_boundbox_ex(FontBLF *font,
     if (UNLIKELY(g == NULL)) {
       continue;
     }
-    if (UNLIKELY(g->c == BLI_UTF8_ERR)) {
-      break;
-    }
     pen_x += blf_kerning(font, g_prev, g);
 
     gbox.xmin = (float)pen_x;
@@ -880,9 +868,6 @@ static void blf_font_boundbox_foreach_glyph_ex(FontBLF *font,
     if (UNLIKELY(g == NULL)) {
       continue;
     }
-    if (UNLIKELY(g->c == BLI_UTF8_ERR)) {
-      break;
-    }
     pen_x += blf_kerning(font, g_prev, g);
 
     gbox.xmin = pen_x;
@@ -968,9 +953,6 @@ static void blf_font_wrap_apply(FontBLF *font,
     if (UNLIKELY(g == NULL)) {
       continue;
     }
-    if (UNLIKELY(g->c == BLI_UTF8_ERR)) {
-      break;
-    }
     pen_x += blf_kerning(font, g_prev, g);
 
     /**



More information about the Bf-blender-cvs mailing list