のねのBlog

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

fallback_fonts.xmlを開いているのはどこか?

    161 FILE* openLocalizedFile(const char* origname) {
    162     FILE* file = 0;
    163 
    164 #if !defined(SK_BUILD_FOR_ANDROID_NDK)
    165     SkString basename;
    166     SkString filename;
    167     char language[3] = "";
    168     char region[3] = "";
    169 
    170     basename.set(origname);
    171     // Remove the .xml suffix. We'll add it back in a moment.
    172     if (basename.endsWith(".xml")) {
    173         basename.resize(basename.size()-4);
    174     }
    175     getLocale(language, region);
    176     // Try first with language and region
    177     filename.printf("%s-%s-%s.xml", basename.c_str(), language, region);
    178     file = fopen(filename.c_str(), "r");
    179     if (!file) {
    180         // If not found, try next with just language
    181         filename.printf("%s-%s.xml", basename.c_str(), language);
    182         file = fopen(filename.c_str(), "r");
    183     }
    184 #endif
    185 
    186     if (!file) {
    187         // If still not found, try just the original name
    188         file = fopen(origname, "r");
    189     }
    190     return file;
    191 }
    197 void parseConfigFile(const char *filename, SkTDArray<FontFamily*> &families) {
    198     XML_Parser parser = XML_ParserCreate(NULL);
    199     FamilyData *familyData = new FamilyData(&parser, families);
    200     XML_SetUserData(parser, familyData);
    201     XML_SetElementHandler(parser, startElementHandler, endElementHandler);
    202     FILE *file = openLocalizedFile(filename);         <===============================================
    203     // Some of the files we attempt to parse (in particular, /vendor/etc/fallback_fonts.xml)
    204     // are optional - failure here is okay because one of these optional files may not exist.
    205     if (file == NULL) {
    206         return;
    207     }
    208     char buffer[512];
    209     bool done = false;
    210     while (!done) {
    211         fgets(buffer, sizeof(buffer), file);
    212         int len = strlen(buffer);
    213         if (feof(file) != 0) {
    214             done = true;
    215         }
    216         XML_Parse(parser, buffer, len, done);
    217     }

      ここに、fclose(file)が必要な気がする。

    218 }
    219
    220 void getSystemFontFamilies(SkTDArray<FontFamily*> &fontFamilies) {
    221     parseConfigFile(SYSTEM_FONTS_FILE, fontFamilies); <===================================
    222 }



    224 void getFallbackFontFamilies(SkTDArray<FontFamily*> &fallbackFonts) {
    225     SkTDArray<FontFamily*> vendorFonts;
    226     parseConfigFile(FALLBACK_FONTS_FILE, fallbackFonts); <=================================
    227     parseConfigFile(VENDOR_FONTS_FILE, vendorFonts);     <=================================
    228 
    229     // This loop inserts the vendor fallback fonts in the correct order in the
    230     // overall fallbacks list.
    231     int currentOrder = -1;
    232     for (int i = 0; i < vendorFonts.count(); ++i) {
    233         FontFamily* family = vendorFonts[i];
    234         int order = family->order;
    235         if (order < 0) {
    236             if (currentOrder < 0) {
    237                 // Default case - just add it to the end of the fallback list
    238                 *fallbackFonts.append() = family;
    239             } else {
    240                 // no order specified on this font, but we're incrementing the order
    241                 // based on an earlier order insertion request
    242                 *fallbackFonts.insert(currentOrder++) = family;
    243             }
    244         } else {
    245             // Add the font into the fallback list in the specified order. Set
    246             // currentOrder for correct placement of other fonts in the vendor list.
    247             *fallbackFonts.insert(order) = family;
    248             currentOrder = order + 1;
    249         }
    250     }
    251 }