のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

loadFontInfoLocked

$ adb root
$ adb shell ps | grep system_server
$ gdbclient app_process :5039 5078
(gdb) b SkFontHost::CreateTypeface
(gdb) c

(gdb) b SkFontHost::CreateTypeface
(gdb) b SkFontHost::GetAdvancedTypefaceMetrics

(gdb) b SkGlyphCache::lookupMetrics
(gdb) b SkGlyphCache::getGlyphIDMetrics

(gdb) b SkScalerContext::getNextContext
(gdb) b SkScalerContext::getContextFromChar
(gdb) b SkScalerContext::SkScalerContext
    926 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
    927                                        const char familyName[],
    928                                        const void* data, size_t bytelength,
    929                                        SkTypeface::Style style) {
    930     SkAutoMutexAcquire  ac(gFamilyHeadAndNameListMutex);
    931     return createTypefaceLocked(familyFace, familyName, data, bytelength, style);
    932 }
    934 static SkTypeface* createTypefaceLocked(const SkTypeface* familyFace,
    935         const char familyName[], const void* data, size_t bytelength,
    936         SkTypeface::Style style) {
    937     loadSystemFontsLocked(); <=========
    938 
    939     // clip to legal style bits
    940     style = (SkTypeface::Style)(style & SkTypeface::kBoldItalic);
    941 
    942     SkTypeface* tf = NULL;
    943 
    944     if (NULL != familyFace) {
    945         tf = findTypefaceLocked(familyFace, style);
    946     } else if (NULL != familyName) {
    947 //        SkDebugf("======= familyName <%s>\n", familyName);
    948         tf = findTypefaceLocked(familyName, style);
    949     }
    950 
    951     if (NULL == tf) {
    952         tf = findBestFaceLocked(gDefaultFamily, style);
    953     }
    954 
    955     // we ref(), since the semantic is to return a new instance
    956     tf->ref();
    957     return tf;
    958 }
    824 static void loadSystemFontsLocked() {
    825     if (!gDefaultNormal) {
    826         initSystemFontsLocked(); <=========
    827     }
    828 }
    737 static void initSystemFontsLocked() {
    738     // check if we've already been called
    739     if (gDefaultNormal) {
    740         return;
    741     }
    742 
    743     SkASSERT(gUniqueFontID == 0);
    744 
    745     loadFontInfoLocked(); <============================
    746 
    747     SkTypeface* firstInFamily = NULL;
    748     for (int i = 0; i < gSystemFonts.count(); i++) {
    749         // if we're the first in a new family, clear firstInFamily
    750         const char* const* names = gSystemFonts[i].fNames;
    751         if (names != NULL) {
    752             firstInFamily = NULL;
    753         }
    754 
    755         bool isFixedWidth;
    756         SkString name;
    757         SkTypeface::Style style;
    758 
    759         // we expect all the fonts, except the "fallback" fonts
    760         bool isExpected = (names != gFBNames);
    761         if (!getNameAndStyle(gSystemFonts[i].fFileName, &name, &style,
    762                 &isFixedWidth, isExpected)) {
    763             // We need to increase gUniqueFontID here so that the unique id of
    764             // each font matches its index in gSystemFonts array, as expected
    765             // by findUniqueIDLocked.
    766             sk_atomic_inc(&gUniqueFontID);
    767             continue;
    768         }
    769 
    770         SkString fullpath;
    771         getFullPathForSysFonts(&fullpath, gSystemFonts[i].fFileName);
    772 
    773         SkTypeface* tf = SkNEW_ARGS(FileTypeface, (style,
    774                 true,  // system-font (cannot delete)
    775                 fullpath.c_str(), // filename
    776                 isFixedWidth));
    777         addTypefaceLocked(tf, firstInFamily);
    778 
    779         SkDEBUGF(("---- SkTypeface[%d] %s fontID %d\n",
    780                   i, gSystemFonts[i].fFileName, tf->uniqueID()));
    781 
    782         if (names != NULL) {
    783             // see if this is one of our fallback fonts
    784             if (names == gFBNames) {
    785                 // add to appropriate fallback chains
    786                 FallbackFontRec fallbackRec;
    787                 fallbackRec.fFontID = tf->uniqueID();
    788                 fallbackRec.fVariant = gSystemFonts[i].fVariant;
    789                 addFallbackFontLocked(fallbackRec, gSystemFonts[i].fLanguage);
    790             }
    791 
    792             firstInFamily = tf;
    793             FamilyRec* family = findFamilyLocked(tf);
    794 
    795             // record the default family if this is it
    796             if (names == gDefaultNames) {
    797                 gDefaultFamily = family;
    798             }
    799             // add the names to map to this family
    800             while (*names) {
    801                 addNameLocked(*names, family);
    802                 names += 1;
    803             }
    804         }
    805     }
    806     finaliseFallbackFontListsLocked();
    807 
    808     // do this after all fonts are loaded. This is our default font, and it
    809     // acts as a sentinel so we only execute loadSystemFontsLocked() once
    810     gDefaultNormal = findBestFaceLocked(gDefaultFamily, SkTypeface::kNormal);
    811 
    812     SkDEBUGCODE(dumpGlobalsLocked());
    813 }
    674 /*  Load info from a configuration file that populates the system/fallback font structures
    675 */
    676 static void loadFontInfoLocked() {
    677     resetFallbackFontListsLocked();
    678 
    679     SkTDArray<FontFamily*> fontFamilies;
    680     getFontFamilies(fontFamilies);
    681 
    682     gSystemFonts.reset();
    683 
    684     for (int i = 0; i < fontFamilies.count(); ++i) {
    685         FontFamily *family = fontFamilies[i];
    686         for (int j = 0; j < family->fFontFileArray.count(); ++j) {
    687             const char* filename = family->fFontFileArray[j]->fFileName;
    688             if (haveSystemFont(filename)) {
    689                 SkDebugf("---- system font and fallback font files specify a duplicate "
    690                         "font %s, skipping the second occurrence", filename);
    691                 continue;
    692             }
    693 
    694             FontInitRec fontInfoRecord;
    695             fontInfoRecord.fFileName = filename;
    696             fontInfoRecord.fVariant = family->fFontFileArray[j]->fVariant;
    697             fontInfoRecord.fLanguage = family->fFontFileArray[j]->fLanguage;
    698             if (j == 0) {
    699                 if (family->fNames.count() == 0) {
    700                     // Fallback font
    701                     fontInfoRecord.fNames = (char **)gFBNames;
    702                 } else {
    703                     SkTDArray<const char*> names = family->fNames;
    704                     const char **nameList = (const char**)
    705                             malloc((names.count() + 1) * sizeof(char*));
    706                     if (nameList == NULL) {
    707                         // shouldn't get here
    708                         break;
    709                     }
    710                     if (gDefaultNames == NULL) {
    711                         gDefaultNames = (char**) nameList;
    712                     }
    713                     for (int i = 0; i < names.count(); ++i) {
    714                         nameList[i] = names[i];
    715                     }
    716                     nameList[names.count()] = NULL;
    717                     fontInfoRecord.fNames = nameList;
    718                 }
    719             } else {
    720                 fontInfoRecord.fNames = NULL;
    721             }
    722             gSystemFonts.push_back(fontInfoRecord);
    723         }
    724     }
    725     fontFamilies.deleteAll();
    726 
    727     SkDEBUGF(("---- We have %d system fonts", gSystemFonts.count()));
    728     for (int i = 0; i < gSystemFonts.count(); ++i) {
    729         SkDEBUGF(("---- gSystemFonts[%d] fileName=%s", i, gSystemFonts[i].fFileName));
    730     }
    731 }