[Bf-blender-cvs] [ae920d789ed] master: VSE: Allow Wingdings and Symbol Fonts
Harley Acheson
noreply at git.blender.org
Wed Aug 4 18:32:20 CEST 2021
Commit: ae920d789ed3986e7c50049c074739fed7d33f32
Author: Harley Acheson
Date: Wed Aug 4 09:31:01 2021 -0700
Branches: master
https://developer.blender.org/rBae920d789ed3986e7c50049c074739fed7d33f32
VSE: Allow Wingdings and Symbol Fonts
This patch makes us less restrictive on the allowed types of FreeType
font character maps we allow, rather than primarily unicode-only. This
allows us to use some legacy, symbol, specialty, and proprietary fonts
like Wingdings. Note we were a little less restrictive with vfonts,
used for 3D Text Objects, so this patch primarily helps VSE.
See D12124 for details and examples.
Differential Revision: https://developer.blender.org/D12124
Reviewed by Brecht Van Lommel
===================================================================
M source/blender/blenfont/intern/blf_font.c
M source/blender/blenlib/intern/freetypefont.c
===================================================================
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 53c4135254a..6e2be4a8353 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -1359,9 +1359,15 @@ FontBLF *blf_font_new(const char *name, const char *filename)
return NULL;
}
- err = FT_Select_Charmap(font->face, ft_encoding_unicode);
+ err = FT_Select_Charmap(font->face, FT_ENCODING_UNICODE);
if (err) {
- printf("Can't set the unicode character map!\n");
+ err = FT_Select_Charmap(font->face, FT_ENCODING_APPLE_ROMAN);
+ }
+ if (err && font->face->num_charmaps > 0) {
+ err = FT_Select_Charmap(font->face, font->face->charmaps[0]->encoding);
+ }
+ if (err) {
+ printf("Can't set a character map!\n");
FT_Done_Face(font->face);
MEM_freeN(font);
return NULL;
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index 15c4910310f..a8b50b66f5f 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -305,32 +305,23 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
BLI_utf8_invalid_strip(vfd->name, strlen(vfd->name));
}
+ /* Select a character map. */
+ err = FT_Select_Charmap(face, FT_ENCODING_UNICODE);
+ if (err) {
+ err = FT_Select_Charmap(face, FT_ENCODING_APPLE_ROMAN);
+ }
+ if (err && face->num_charmaps > 0) {
+ err = FT_Select_Charmap(face, face->charmaps[0]->encoding);
+ }
+ if (err) {
+ FT_Done_Face(face);
+ MEM_freeN(vfd);
+ return NULL;
+ }
+
/* Extract the first 256 character from TTF */
lcode = charcode = FT_Get_First_Char(face, &glyph_index);
- /* No `charmap` found from the TTF so we need to figure it out. */
- if (glyph_index == 0) {
- FT_CharMap found = NULL;
- FT_CharMap charmap;
- int n;
-
- for (n = 0; n < face->num_charmaps; n++) {
- charmap = face->charmaps[n];
- if (charmap->encoding == FT_ENCODING_APPLE_ROMAN) {
- found = charmap;
- break;
- }
- }
-
- err = FT_Set_Charmap(face, found);
-
- if (err) {
- return NULL;
- }
-
- 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);
More information about the Bf-blender-cvs
mailing list