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

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

Issue 226183002: Prevent potential leaking of memory by using SkString and SkTArray. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 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 | src/ports/SkFontConfigParser_android.h » ('j') | 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 /* 2 /*
3 * Copyright 2013 The Android Open Source Project 3 * Copyright 2013 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkFontConfigInterface.h" 9 #include "SkFontConfigInterface.h"
10 #include "SkTypeface_android.h" 10 #include "SkTypeface_android.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return true; 167 return true;
168 } 168 }
169 } 169 }
170 return false; 170 return false;
171 } 171 }
172 172
173 #ifndef SK_FONT_FILE_PREFIX 173 #ifndef SK_FONT_FILE_PREFIX
174 #define SK_FONT_FILE_PREFIX "/fonts/" 174 #define SK_FONT_FILE_PREFIX "/fonts/"
175 #endif 175 #endif
176 176
177 static void get_path_for_sys_fonts(SkString* full, const char name[]) { 177 static void get_path_for_sys_fonts(SkString* full, const SkString& name) {
178 if (gTestFontFilePrefix) { 178 if (gTestFontFilePrefix) {
179 full->set(gTestFontFilePrefix); 179 full->set(gTestFontFilePrefix);
180 } else { 180 } else {
181 full->set(getenv("ANDROID_ROOT")); 181 full->set(getenv("ANDROID_ROOT"));
182 full->append(SK_FONT_FILE_PREFIX); 182 full->append(SK_FONT_FILE_PREFIX);
183 } 183 }
184 full->append(name); 184 full->append(name);
185 } 185 }
186 186
187 static void insert_into_name_dict(SkTDict<FamilyRecID>& familyNameDict, 187 static void insert_into_name_dict(SkTDict<FamilyRecID>& familyNameDict,
(...skipping 25 matching lines...) Expand all
213 for (int i = 0; i < fontFamilies.count(); ++i) { 213 for (int i = 0; i < fontFamilies.count(); ++i) {
214 FontFamily* family = fontFamilies[i]; 214 FontFamily* family = fontFamilies[i];
215 215
216 // defer initializing the familyRec until we can be sure that at least 216 // defer initializing the familyRec until we can be sure that at least
217 // one of it's children contains a valid font file 217 // one of it's children contains a valid font file
218 FamilyRec* familyRec = NULL; 218 FamilyRec* familyRec = NULL;
219 FamilyRecID familyRecID = INVALID_FAMILY_REC_ID; 219 FamilyRecID familyRecID = INVALID_FAMILY_REC_ID;
220 220
221 for (int j = 0; j < family->fFontFiles.count(); ++j) { 221 for (int j = 0; j < family->fFontFiles.count(); ++j) {
222 SkString filename; 222 SkString filename;
223 get_path_for_sys_fonts(&filename, family->fFontFiles[j]->fFileName); 223 get_path_for_sys_fonts(&filename, family->fFontFiles[j].fFileName);
224 224
225 if (has_font(fFonts, filename)) { 225 if (has_font(fFonts, filename)) {
226 SkDebugf("---- system font and fallback font files specify a dup licate " 226 SkDebugf("---- system font and fallback font files specify a dup licate "
227 "font %s, skipping the second occurrence", filename.c_st r()); 227 "font %s, skipping the second occurrence", filename.c_st r());
228 continue; 228 continue;
229 } 229 }
230 230
231 FontRec& fontRec = fFonts.push_back(); 231 FontRec& fontRec = fFonts.push_back();
232 fontRec.fFileName = filename; 232 fontRec.fFileName = filename;
233 fontRec.fStyle = SkTypeface::kNormal; 233 fontRec.fStyle = SkTypeface::kNormal;
(...skipping 24 matching lines...) Expand all
258 } 258 }
259 259
260 // create a familyRec now that we know that at least one font in 260 // create a familyRec now that we know that at least one font in
261 // the family is valid 261 // the family is valid
262 if (familyRec == NULL) { 262 if (familyRec == NULL) {
263 familyRec = &fFontFamilies.push_back(); 263 familyRec = &fFontFamilies.push_back();
264 familyRecID = fFontFamilies.count() - 1; 264 familyRecID = fFontFamilies.count() - 1;
265 fontRec.fFamilyRecID = familyRecID; 265 fontRec.fFamilyRecID = familyRecID;
266 266
267 familyRec->fIsFallbackFont = family->fIsFallbackFont; 267 familyRec->fIsFallbackFont = family->fIsFallbackFont;
268 familyRec->fPaintOptions = family->fFontFiles[j]->fPaintOptions; 268 familyRec->fPaintOptions = family->fFontFiles[j].fPaintOptions;
269 269
270 } else if (familyRec->fPaintOptions != family->fFontFiles[j]->fPaint Options) { 270 } else if (familyRec->fPaintOptions != family->fFontFiles[j].fPaintO ptions) {
271 SkDebugf("Every font file within a family must have identical" 271 SkDebugf("Every font file within a family must have identical"
272 "language and variant attributes"); 272 "language and variant attributes");
273 sk_throw(); 273 sk_throw();
274 } 274 }
275 275
276 // add this font to the current familyRec 276 // add this font to the current familyRec
277 if (INVALID_FONT_REC_ID != familyRec->fFontRecID[fontRec.fStyle]) { 277 if (INVALID_FONT_REC_ID != familyRec->fFontRecID[fontRec.fStyle]) {
278 DEBUG_FONT(("Overwriting familyRec for style[%d] old,new:(%d,%d) ", 278 DEBUG_FONT(("Overwriting familyRec for style[%d] old,new:(%d,%d) ",
279 fontRec.fStyle, familyRec->fFontRecID[fontRec.fStyle ], 279 fontRec.fStyle, familyRec->fFontRecID[fontRec.fStyle ],
280 fontRecID)); 280 fontRecID));
281 } 281 }
282 familyRec->fFontRecID[fontRec.fStyle] = fontRecID; 282 familyRec->fFontRecID[fontRec.fStyle] = fontRecID;
283 } 283 }
284 284
285 if (familyRec) { 285 if (familyRec) {
286 if (familyRec->fIsFallbackFont) { 286 if (familyRec->fIsFallbackFont) {
287 // add the font to the appropriate fallback chains and also inse rt a 287 // add the font to the appropriate fallback chains and also inse rt a
288 // unique name into the familyNameDict for internal usage 288 // unique name into the familyNameDict for internal usage
289 addFallbackFamily(familyRecID); 289 addFallbackFamily(familyRecID);
290 } else { 290 } else {
291 // add the names that map to this family to the dictionary for e asy lookup 291 // add the names that map to this family to the dictionary for e asy lookup
292 const SkTDArray<const char*>& names = family->fNames; 292 const SkTArray<SkString>& names = family->fNames;
293 if (names.isEmpty()) { 293 if (names.empty()) {
294 SkDEBUGFAIL("ERROR: non-fallback font with no name"); 294 SkDEBUGFAIL("ERROR: non-fallback font with no name");
295 continue; 295 continue;
296 } 296 }
297 297
298 for (int i = 0; i < names.count(); i++) { 298 for (int i = 0; i < names.count(); i++) {
299 insert_into_name_dict(fFamilyNameDict, names[i], familyRecID ); 299 insert_into_name_dict(fFamilyNameDict, names[i].c_str(), fam ilyRecID);
300 } 300 }
301 } 301 }
302 } 302 }
303 } 303 }
304 304
305 DEBUG_FONT(("---- We have %d system fonts", fFonts.count())); 305 DEBUG_FONT(("---- We have %d system fonts", fFonts.count()));
306 306
307 if (fFontFamilies.count() > 0) { 307 if (fFontFamilies.count() > 0) {
308 fDefaultFamilyRecID = 0; 308 fDefaultFamilyRecID = 0;
309 } 309 }
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 return SkSafeRef(retTypeface); 906 return SkSafeRef(retTypeface);
907 } 907 }
908 908
909 #endif 909 #endif
910 910
911 /////////////////////////////////////////////////////////////////////////////// 911 ///////////////////////////////////////////////////////////////////////////////
912 912
913 SkFontMgr* SkFontMgr::Factory() { 913 SkFontMgr* SkFontMgr::Factory() {
914 return NULL; 914 return NULL;
915 } 915 }
OLDNEW
« no previous file with comments | « no previous file | src/ports/SkFontConfigParser_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698