[Bf-blender-cvs] [be8ee05dcba] master: Fix for T53332: BFont 43 Inaccessible Glyphs

Harley Acheson noreply at git.blender.org
Thu Oct 6 19:37:06 CEST 2022


Commit: be8ee05dcba6987fd4098cc61d414b0b8cef4b3e
Author: Harley Acheson
Date:   Thu Oct 6 10:35:36 2022 -0700
Branches: master
https://developer.blender.org/rBbe8ee05dcba6987fd4098cc61d414b0b8cef4b3e

Fix for T53332: BFont 43 Inaccessible Glyphs

Preloading of BFont (default for 3D Text Objects) glyphs will not load
any with a character code greater than 256, resulting in 43 characters
that are inaccessible. This patch corrects that preloading code.

See D16122 for more details

Differential Revision: https://developer.blender.org/D16122

Reviewed by Campbell Barton

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

M	source/blender/blenkernel/intern/vfontdata_freetype.c

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

diff --git a/source/blender/blenkernel/intern/vfontdata_freetype.c b/source/blender/blenkernel/intern/vfontdata_freetype.c
index 30e5f29e6a8..91ca3100f8c 100644
--- a/source/blender/blenkernel/intern/vfontdata_freetype.c
+++ b/source/blender/blenkernel/intern/vfontdata_freetype.c
@@ -270,9 +270,6 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
 {
   /* Variables */
   FT_Face face;
-  const FT_ULong charcode_reserve = 256;
-  FT_ULong charcode = 0, lcode;
-  FT_UInt glyph_index;
   VFontData *vfd;
 
   /* load the freetype font */
@@ -305,9 +302,6 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
     return NULL;
   }
 
-  /* Extract the first 256 character from TTF */
-  lcode = charcode = FT_Get_First_Char(face, &glyph_index);
-
   /* Blender default BFont is not "complete". */
   const bool complete_font = (face->ascender != 0) && (face->descender != 0) &&
                              (face->ascender != face->descender);
@@ -335,21 +329,19 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
     vfd->scale = 1.0f / 1000.0f;
   }
 
-  /* Load characters */
-  vfd->characters = BLI_ghash_int_new_ex(__func__, charcode_reserve);
+  /* Load the first 256 glyphs. */
 
-  while (charcode < charcode_reserve) {
-    /* Generate the font data */
-    freetypechar_to_vchar(face, charcode, vfd);
+  const FT_ULong preload_count = 256;
+  vfd->characters = BLI_ghash_int_new_ex(__func__, preload_count);
 
-    /* Next glyph */
+  FT_ULong charcode = 0;
+  FT_UInt glyph_index;
+  for (int i = 0; i < preload_count; i++) {
     charcode = FT_Get_Next_Char(face, charcode, &glyph_index);
-
-    /* Check that we won't start infinite loop */
-    if (charcode <= lcode) {
+    if (!charcode || !glyph_index) {
       break;
     }
-    lcode = charcode;
+    freetypechar_to_vchar(face, charcode, vfd);
   }
 
   return vfd;



More information about the Bf-blender-cvs mailing list