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
172 if (basename.endsWith(".xml")) {
173 basename.resize(basename.size()-4);
174 }
175 getLocale(language, region);
176
177 filename.printf("%s-%s-%s.xml", basename.c_str(), language, region);
178 file = fopen(filename.c_str(), "r");
179 if (!file) {
180
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
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
204
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
230
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
238 *fallbackFonts.append() = family;
239 } else {
240
241
242 *fallbackFonts.insert(currentOrder++) = family;
243 }
244 } else {
245
246
247 *fallbackFonts.insert(order) = family;
248 currentOrder = order + 1;
249 }
250 }
251 }