Chromium Code Reviews

Side by Side Diff: Source/platform/fonts/mac/FontCacheMac.mm

Issue 879533003: Remove Mac native font type members from FontPlatformData (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Memory management review comments addressed Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 101 matching lines...)
112 if (character <= 0xFFFF) { 112 if (character <= 0xFFFF) {
113 codeUnits[0] = character; 113 codeUnits[0] = character;
114 codeUnitsLength = 1; 114 codeUnitsLength = 1;
115 } else { 115 } else {
116 codeUnits[0] = U16_LEAD(character); 116 codeUnits[0] = U16_LEAD(character);
117 codeUnits[1] = U16_TRAIL(character); 117 codeUnits[1] = U16_TRAIL(character);
118 codeUnitsLength = 2; 118 codeUnitsLength = 2;
119 } 119 }
120 120
121 const FontPlatformData& platformData = fontDataToSubstitute->platformData(); 121 const FontPlatformData& platformData = fontDataToSubstitute->platformData();
122 NSFont *nsFont = platformData.font(); 122 NSFont* nsFont = toNSFont(platformData.ctFont());
123 123
124 NSString *string = [[NSString alloc] initWithCharactersNoCopy:codeUnits leng th:codeUnitsLength freeWhenDone:NO]; 124 NSString *string = [[NSString alloc] initWithCharactersNoCopy:codeUnits leng th:codeUnitsLength freeWhenDone:NO];
125 NSFont *substituteFont = [NSFont findFontLike:nsFont forString:string withRa nge:NSMakeRange(0, codeUnitsLength) inLanguage:nil]; 125 NSFont *substituteFont = [NSFont findFontLike:nsFont forString:string withRa nge:NSMakeRange(0, codeUnitsLength) inLanguage:nil];
126 [string release]; 126 [string release];
127 127
128 // FIXME: Remove this SPI usage: http://crbug.com/255122 128 // FIXME: Remove this SPI usage: http://crbug.com/255122
129 if (!substituteFont && codeUnitsLength == 1) 129 if (!substituteFont && codeUnitsLength == 1)
130 substituteFont = [NSFont findFontLike:nsFont forCharacter:codeUnits[0] i nLanguage:nil]; 130 substituteFont = [NSFont findFontLike:nsFont forCharacter:codeUnits[0] i nLanguage:nil];
131 if (!substituteFont) 131 if (!substituteFont)
132 return nullptr; 132 return nullptr;
(...skipping 80 matching lines...)
213 NSFontManager *fontManager = [NSFontManager sharedFontManager]; 213 NSFontManager *fontManager = [NSFontManager sharedFontManager];
214 NSFontTraitMask actualTraits = 0; 214 NSFontTraitMask actualTraits = 0;
215 if (fontDescription.style()) 215 if (fontDescription.style())
216 actualTraits = [fontManager traitsOfFont:nsFont]; 216 actualTraits = [fontManager traitsOfFont:nsFont];
217 NSInteger actualWeight = [fontManager weightOfFont:nsFont]; 217 NSInteger actualWeight = [fontManager weightOfFont:nsFont];
218 218
219 NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerF ont]; 219 NSFont *platformFont = useHinting() ? [nsFont screenFont] : [nsFont printerF ont];
220 bool syntheticBold = (isAppKitFontWeightBold(weight) && !isAppKitFontWeightB old(actualWeight)) || fontDescription.isSyntheticBold(); 220 bool syntheticBold = (isAppKitFontWeightBold(weight) && !isAppKitFontWeightB old(actualWeight)) || fontDescription.isSyntheticBold();
221 bool syntheticItalic = ((traits & NSFontItalicTrait) && !(actualTraits & NSF ontItalicTrait)) || fontDescription.isSyntheticItalic(); 221 bool syntheticItalic = ((traits & NSFontItalicTrait) && !(actualTraits & NSF ontItalicTrait)) || fontDescription.isSyntheticItalic();
222 222
223 // FontPlatformData::font() can be null for the case of Chromium out-of-proc ess font loading. 223 // FontPlatformData::typeface() is null in the case of Chromium out-of-proce ss font loading failing.
224 // In that case, we don't want to use the platformData. 224 // Out-of-process loading occurs for registered fonts stored in non-system l ocations.
225 // When loading fails, we do not want to use the returned FontPlatformData s ince it will not have
226 // a valid SkTypeface.
225 OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platfo rmFont, size, syntheticBold, syntheticItalic, fontDescription.orientation())); 227 OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platfo rmFont, size, syntheticBold, syntheticItalic, fontDescription.orientation()));
226 if (!platformData->font()) 228 if (!platformData->typeface()) {
227 return 0; 229 return nullptr;
230 }
228 return platformData.leakPtr(); 231 return platformData.leakPtr();
229 } 232 }
230 233
231 } // namespace blink 234 } // namespace blink
OLDNEW

Powered by Google App Engine