SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, const char familyName[], const void* data, size_t bytelength, SkTypeface::Style style) { load_system_fonts(); SkAutoMutexAcquire ac(gFamilyMutex); // clip to legal style bits style = (SkTypeface::Style)(style & SkTypeface::kBoldItalic); SkTypeface* tf = NULL; if (NULL != familyFace) { tf = find_typeface(familyFace, style); } else if (NULL != familyName) { // SkDebugf("======= familyName <%s>\n", familyName); tf = find_typeface(familyName, style); } if (NULL == tf) { tf = find_best_face(gDefaultFamily, style); } SkSafeRef(tf); return tf; }
SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, const char familyName[], SkTypeface::Style style) { SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); load_system_fonts(); // clip to legal style bits style = (SkTypeface::Style)(style & SkTypeface::kBoldItalic); SkTypeface* tf = NULL; if (NULL != familyFace) { tf = find_typeface(familyFace, style); } else if (NULL != familyName) { // SkDebugf("======= familyName <%s>\n", familyName); tf = find_typeface(familyName, style); } if (NULL == tf) { tf = find_best_face(gDefaultFamily, style); } // we ref(), since the semantic is to return a new instance tf->ref(); return tf; }
static SkTypeface* find_typeface(const char name[], SkTypeface::Style style) { NameFamilyPair* list = gNameList.begin(); int count = gNameList.count(); int index = SkStrLCSearch(&list[0].fName, count, name, sizeof(list[0])); if (index >= 0) { return find_best_face(list[index].fFamily, style); } return NULL; }
static SkTypeface* find_typeface(const SkTypeface* familyMember, SkTypeface::Style style) { const FamilyRec* family = find_family(familyMember); return family ? find_best_face(family, style) : NULL; }
static SkTypeface* find_typeface(const char name[], SkTypeface::Style style) { FamilyRec* rec = find_familyrec(name); return rec ? find_best_face(rec, style) : NULL; }
/* Called once (ensured by the sentinel check at the beginning of our body). Initializes all the globals, and register the system fonts. */ static void load_system_fonts() { // check if we've already be called if (NULL != gDefaultNormal) { return; } const FontInitRec* rec = gSystemFonts; SkTypeface* firstInFamily = NULL; int fallbackCount = 0; for (size_t i = 0; i < SK_ARRAY_COUNT(gSystemFonts); i++) { // if we're the first in a new family, clear firstInFamily if (rec[i].fNames != NULL) { firstInFamily = NULL; } SkString name; SkTypeface::Style style; // we expect all the fonts, except the "fallback" fonts bool isExpected = (rec[i].fNames != gFBNames); if (!get_name_and_style(rec[i].fFileName, &name, &style, isExpected)) { continue; } SkTypeface* tf = SkNEW_ARGS(FileTypeface, (style, true, // system-font (cannot delete) firstInFamily, // what family to join rec[i].fFileName) // filename ); if (rec[i].fNames != NULL) { // see if this is one of our fallback fonts if (rec[i].fNames == gFBNames) { // SkDebugf("---- adding %s as fallback[%d] fontID %d\n", // rec[i].fFileName, fallbackCount, tf->uniqueID()); gFallbackFonts[fallbackCount++] = tf->uniqueID(); } firstInFamily = tf; FamilyRec* family = find_family(tf); const char* const* names = rec[i].fNames; // record the default family if this is it if (names == DEFAULT_NAMES) { gDefaultFamily = family; } // add the names to map to this family while (*names) { add_name(*names, family); names += 1; } } } // do this after all fonts are loaded. This is our default font, and it // acts as a sentinel so we only execute load_system_fonts() once gDefaultNormal = find_best_face(gDefaultFamily, SkTypeface::kNormal); // now terminate our fallback list with the sentinel value gFallbackFonts[fallbackCount] = 0; }
/* * Called once (ensured by the sentinel check at the beginning of our body). * Initializes all the globals, and register the system fonts. * * gFamilyHeadAndNameListMutex must already be acquired. */ static void init_system_fonts() { // check if we've already been called if (gDefaultNormal) { return; } SkASSERT(gUniqueFontID == 0); load_font_info(); FontInitRec* rec = gSystemFonts; SkTypeface* firstInFamily = NULL; int fallbackCount = 0; for (size_t i = 0; i < gNumSystemFonts; i++) { // if we're the first in a new family, clear firstInFamily if (rec[i].fNames != NULL) { firstInFamily = NULL; } bool isFixedWidth; SkString name; SkTypeface::Style style; // we expect all the fonts, except the "fallback" fonts bool isExpected = (rec[i].fNames != gFBNames); if (!get_name_and_style(rec[i].fFileName, &name, &style, &isFixedWidth, isExpected)) { // We need to increase gUniqueFontID here so that the unique id of // each font matches its index in gSystemFonts array, as expected // by find_uniqueID. sk_atomic_inc(&gUniqueFontID); continue; } SkTypeface* tf = SkNEW_ARGS(FileTypeface, (style, true, // system-font (cannot delete) firstInFamily, // what family to join rec[i].fFileName, isFixedWidth) // filename ); #if SK_DEBUG_FONTS SkDebugf("---- SkTypeface[%d] %s fontID %d", i, rec[i].fFileName, tf->uniqueID()); #endif if (rec[i].fNames != NULL) { // see if this is one of our fallback fonts if (rec[i].fNames == gFBNames) { #if SK_DEBUG_FONTS SkDebugf("---- adding %s as fallback[%d] fontID %d", rec[i].fFileName, fallbackCount, tf->uniqueID()); #endif gFallbackFonts[fallbackCount++] = tf->uniqueID(); // Use the font file name as the name of the typeface. const char **nameList = (const char**)malloc(2 * sizeof(char*)); if (nameList == NULL) { // shouldn't get here SkDEBUGFAIL("Failed to allocate nameList"); break; } nameList[0] = rec[i].fFileName; nameList[1] = NULL; rec[i].fNames = nameList; } firstInFamily = tf; FamilyRec* family = find_family(tf); const char* const* names = rec[i].fNames; // record the default family if this is it if (names == gDefaultNames) { gDefaultFamily = family; } // add the names to map to this family while (*names) { add_name(*names, family); names += 1; } } } // do this after all fonts are loaded. This is our default font, and it // acts as a sentinel so we only execute load_system_fonts() once gDefaultNormal = find_best_face(gDefaultFamily, SkTypeface::kNormal); // now terminate our fallback list with the sentinel value gFallbackFonts[fallbackCount] = 0; // SkDEBUGCODE(dump_globals()); }