Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: src/ports/SkFontConfigParser_android.cpp

Issue 23621002: fix issue on devices running an OS prior to 4.2 when the fallback font file was potential stored in… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkFontConfigParser_android.h" 8 #include "SkFontConfigParser_android.h"
9 #include "SkTDArray.h" 9 #include "SkTDArray.h"
10 #include "SkTypeface.h" 10 #include "SkTypeface.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Disable the arbitrary text handler installed to load Name data 156 // Disable the arbitrary text handler installed to load Name data
157 XML_SetCharacterDataHandler(*familyData->parser, NULL); 157 XML_SetCharacterDataHandler(*familyData->parser, NULL);
158 } 158 }
159 } 159 }
160 160
161 /** 161 /**
162 * This function parses the given filename and stores the results in the given 162 * This function parses the given filename and stores the results in the given
163 * families array. 163 * families array.
164 */ 164 */
165 static void parseConfigFile(const char *filename, SkTDArray<FontFamily*> &famili es) { 165 static void parseConfigFile(const char *filename, SkTDArray<FontFamily*> &famili es) {
166
167 FILE* file = NULL;
168
169 #if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
scroggo 2013/08/27 19:14:01 So this is only for Android, but not in the framew
djsollen 2013/08/27 19:22:49 This code will not be possible to run as part of t
170 // if we are using a version of Android prior to Android 4.2 (JellyBean MR1
171 // at API Level 17) then we need to look for files with a different suffix.
172 char sdkVersion[PROP_VALUE_MAX];
173 __system_property_get("ro.build.version.sdk", sdkVersion);
174 const int sdkVersionInt = atoi(sdkVersion);
175
176 if (0 != *sdkVersion && sdkVersionInt < 17) {
177 SkString basename;
178 SkString updatedFilename;
179 SkString locale = SkFontConfigParser::GetLocale();
scroggo 2013/08/27 19:14:01 could be const.
180
181 basename.set(filename);
182 // Remove the .xml suffix. We'll add it back in a moment.
183 if (basename.endsWith(".xml")) {
184 basename.resize(basename.size()-4);
185 }
186 // Try first with language and region
187 updatedFilename.printf("%s-%s.xml", basename.c_str(), locale.c_str());
188 file = fopen(updatedFilename.c_str(), "r");
189 if (!file) {
190 // If not found, try next with just language
191 updatedFilename.printf("%s-%.2s.xml", basename.c_str(), locale.c_str ());
192 file = fopen(updatedFilename.c_str(), "r");
193 }
194 }
195 #endif
196
197 if (NULL == file) {
198 file = fopen(filename, "r");
199 }
200
201 // Some of the files we attempt to parse (in particular, /vendor/etc/fallbac k_fonts.xml)
202 // are optional - failure here is okay because one of these optional files m ay not exist.
203 if (NULL == file) {
204 return;
205 }
206
166 XML_Parser parser = XML_ParserCreate(NULL); 207 XML_Parser parser = XML_ParserCreate(NULL);
167 FamilyData *familyData = new FamilyData(&parser, families); 208 FamilyData *familyData = new FamilyData(&parser, families);
168 XML_SetUserData(parser, familyData); 209 XML_SetUserData(parser, familyData);
169 XML_SetElementHandler(parser, startElementHandler, endElementHandler); 210 XML_SetElementHandler(parser, startElementHandler, endElementHandler);
170 FILE *file = fopen(filename, "r"); 211
171 // Some of the files we attempt to parse (in particular, /vendor/etc/fallbac k_fonts.xml)
172 // are optional - failure here is okay because one of these optional files m ay not exist.
173 if (file == NULL) {
174 return;
175 }
176 char buffer[512]; 212 char buffer[512];
177 bool done = false; 213 bool done = false;
178 while (!done) { 214 while (!done) {
179 fgets(buffer, sizeof(buffer), file); 215 fgets(buffer, sizeof(buffer), file);
180 int len = strlen(buffer); 216 int len = strlen(buffer);
181 if (feof(file) != 0) { 217 if (feof(file) != 0) {
182 done = true; 218 done = true;
183 } 219 }
184 XML_Parse(parser, buffer, len, done); 220 XML_Parse(parser, buffer, len, done);
185 } 221 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 SkString locale(6); 309 SkString locale(6);
274 char* localeCStr = locale.writable_str(); 310 char* localeCStr = locale.writable_str();
275 311
276 strncpy(localeCStr, propLang, 2); 312 strncpy(localeCStr, propLang, 2);
277 localeCStr[2] = '-'; 313 localeCStr[2] = '-';
278 strncpy(&localeCStr[3], propRegn, 2); 314 strncpy(&localeCStr[3], propRegn, 2);
279 localeCStr[5] = '\0'; 315 localeCStr[5] = '\0';
280 316
281 return locale; 317 return locale;
282 } 318 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698