Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/vfontdata_freetype.c
| Show First 20 Lines • Show All 264 Lines • ▼ Show 20 Lines | static VChar *objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode) | ||||
| /* And everything went ok */ | /* And everything went ok */ | ||||
| return che; | return che; | ||||
| } | } | ||||
| static VFontData *objfnt_to_ftvfontdata(PackedFile *pf) | static VFontData *objfnt_to_ftvfontdata(PackedFile *pf) | ||||
| { | { | ||||
| /* Variables */ | /* Variables */ | ||||
| FT_Face face; | FT_Face face; | ||||
| const FT_ULong charcode_reserve = 256; | |||||
| FT_ULong charcode = 0, lcode; | |||||
| FT_UInt glyph_index; | |||||
| VFontData *vfd; | VFontData *vfd; | ||||
| /* load the freetype font */ | /* load the freetype font */ | ||||
| err = FT_New_Memory_Face(library, pf->data, pf->size, 0, &face); | err = FT_New_Memory_Face(library, pf->data, pf->size, 0, &face); | ||||
| if (err) { | if (err) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| Show All 16 Lines | if (err && face->num_charmaps > 0) { | ||||
| err = FT_Select_Charmap(face, face->charmaps[0]->encoding); | err = FT_Select_Charmap(face, face->charmaps[0]->encoding); | ||||
| } | } | ||||
| if (err) { | if (err) { | ||||
| FT_Done_Face(face); | FT_Done_Face(face); | ||||
| MEM_freeN(vfd); | MEM_freeN(vfd); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* Extract the first 256 character from TTF */ | |||||
| lcode = charcode = FT_Get_First_Char(face, &glyph_index); | |||||
| /* Blender default BFont is not "complete". */ | /* Blender default BFont is not "complete". */ | ||||
| const bool complete_font = (face->ascender != 0) && (face->descender != 0) && | const bool complete_font = (face->ascender != 0) && (face->descender != 0) && | ||||
| (face->ascender != face->descender); | (face->ascender != face->descender); | ||||
| if (complete_font) { | if (complete_font) { | ||||
| /* We can get descender as well, but we simple store descender in relation to the ascender. | /* We can get descender as well, but we simple store descender in relation to the ascender. | ||||
| * Also note that descender is stored as a negative number. */ | * Also note that descender is stored as a negative number. */ | ||||
| vfd->ascender = (float)face->ascender / (face->ascender - face->descender); | vfd->ascender = (float)face->ascender / (face->ascender - face->descender); | ||||
| Show All 11 Lines | if (complete_font) { | ||||
| vfd->em_height = (float)(face->ascender - face->descender) / | vfd->em_height = (float)(face->ascender - face->descender) / | ||||
| (face->bbox.yMax - face->bbox.yMin); | (face->bbox.yMax - face->bbox.yMin); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| vfd->scale = 1.0f / 1000.0f; | vfd->scale = 1.0f / 1000.0f; | ||||
| } | } | ||||
| /* Load characters */ | /* Load the first 256 glyphs. */ | ||||
| vfd->characters = BLI_ghash_int_new_ex(__func__, charcode_reserve); | |||||
| while (charcode < charcode_reserve) { | const FT_ULong preload_count = 256; | ||||
| /* Generate the font data */ | vfd->characters = BLI_ghash_int_new_ex(__func__, preload_count); | ||||
| freetypechar_to_vchar(face, charcode, vfd); | |||||
| /* Next glyph */ | FT_ULong charcode = 0; | ||||
| FT_UInt glyph_index; | |||||
campbellbarton: These can be moved into the body of the for loop. | |||||
| for (int i = 0; i < preload_count; i++) { | |||||
| charcode = FT_Get_Next_Char(face, charcode, &glyph_index); | charcode = FT_Get_Next_Char(face, charcode, &glyph_index); | ||||
| if (!charcode || !glyph_index) { | |||||
| /* Check that we won't start infinite loop */ | |||||
| if (charcode <= lcode) { | |||||
| break; | break; | ||||
| } | } | ||||
| lcode = charcode; | freetypechar_to_vchar(face, charcode, vfd); | ||||
| } | } | ||||
| return vfd; | return vfd; | ||||
| } | } | ||||
| static bool check_freetypefont(PackedFile *pf) | static bool check_freetypefont(PackedFile *pf) | ||||
| { | { | ||||
| FT_Face face = NULL; | FT_Face face = NULL; | ||||
| ▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines | |||||
These can be moved into the body of the for loop.