static VChar *objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode) { VChar *che; /* Freetype2 */ FT_Face face; /* Load the font to memory */ if (vfont->temp_pf) { err = FT_New_Memory_Face(library, vfont->temp_pf->data, vfont->temp_pf->size, 0, &face); if (err) { return NULL; } } else { err = TRUE; return NULL; } /* Read the char */ che = freetypechar_to_vchar(face, charcode, vfont->data); /* And everything went ok */ return che; }
static int objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode) { // Freetype2 FT_Face face; struct TmpFont *tf; // Find the correct FreeType font tf= vfont_find_tmpfont(vfont); // What, no font found. Something strange here if(!tf) return FALSE; // Load the font to memory if(tf->pf) { err= FT_New_Memory_Face( library, tf->pf->data, tf->pf->size, 0, &face); if (err) return FALSE; } else { err = TRUE; return FALSE; } // Read the char freetypechar_to_vchar(face, charcode, vfont->data); // And everything went ok return TRUE; }
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; const char *fontname; VFontData *vfd; #if 0 FT_CharMap found = 0; FT_CharMap charmap; FT_UShort my_platform_id = TT_PLATFORM_MICROSOFT; FT_UShort my_encoding_id = TT_MS_ID_UNICODE_CS; int n; #endif /* load the freetype font */ err = FT_New_Memory_Face(library, pf->data, pf->size, 0, &face); if (err) return NULL; #if 0 for (n = 0; n < face->num_charmaps; n++) { charmap = face->charmaps[n]; if (charmap->platform_id == my_platform_id && charmap->encoding_id == my_encoding_id) { found = charmap; break; } } if (!found) { return NULL; } /* now, select the charmap for the face object */ err = FT_Set_Charmap(face, found); if (err) { return NULL; } #endif /* allocate blender font */ vfd = MEM_callocN(sizeof(*vfd), "FTVFontData"); /* get the name */ fontname = FT_Get_Postscript_Name(face); BLI_strncpy(vfd->name, (fontname == NULL) ? "" : fontname, sizeof(vfd->name)); /* 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); } /* Adjust font size */ if (face->bbox.yMax != face->bbox.yMin) { vfd->scale = (float)(1.0 / (double)(face->bbox.yMax - face->bbox.yMin)); } else { vfd->scale = 1.0f / 1000.0f; } /* Load characters */ vfd->characters = BLI_ghash_int_new_ex(__func__, charcode_reserve); while (charcode < charcode_reserve) { /* Generate the font data */ freetypechar_to_vchar(face, charcode, vfd); /* Next glyph */ charcode = FT_Get_Next_Char(face, charcode, &glyph_index); /* Check that we won't start infinite loop */ if (charcode <= lcode) break; lcode = charcode; } return vfd; }
static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) { // Variables FT_Face face; FT_ULong charcode = 0, lcode; FT_UInt glyph_index; const char *fontname; VFontData *vfd; /* FT_CharMap found = 0; FT_CharMap charmap; FT_UShort my_platform_id = TT_PLATFORM_MICROSOFT; FT_UShort my_encoding_id = TT_MS_ID_UNICODE_CS; int n; */ // load the freetype font err = FT_New_Memory_Face( library, pf->data, pf->size, 0, &face ); if(err) return NULL; /* for ( n = 0; n < face->num_charmaps; n++ ) { charmap = face->charmaps[n]; if ( charmap->platform_id == my_platform_id && charmap->encoding_id == my_encoding_id ) { found = charmap; break; } } if ( !found ) { return NULL; } // now, select the charmap for the face object err = FT_Set_Charmap( face, found ); if ( err ) { return NULL; } */ // allocate blender font vfd= MEM_callocN(sizeof(*vfd), "FTVFontData"); // get the name fontname = FT_Get_Postscript_Name(face); strcpy(vfd->name, (fontname == NULL) ? "" : fontname); // 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); } // Load characters while(charcode < 256) { // Generate the font data freetypechar_to_vchar(face, charcode, vfd); // Next glyph charcode = FT_Get_Next_Char(face, charcode, &glyph_index); // Check that we won't start infinite loop if(charcode <= lcode) break; lcode = charcode; } return vfd; }