OLD | NEW |
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 14 matching lines...) Expand all Loading... |
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 */ | 28 */ |
29 | 29 |
30 #import "platform/fonts/mac/FontFamilyMatcherMac.h" | 30 #import "platform/fonts/mac/FontFamilyMatcherMac.h" |
31 | 31 |
32 #import <AppKit/AppKit.h> | 32 #import <AppKit/AppKit.h> |
33 #import <Foundation/Foundation.h> | 33 #import <Foundation/Foundation.h> |
34 #import <math.h> | 34 #import <math.h> |
| 35 #include "platform/fonts/FontCache.h" |
35 #include "platform/fonts/FontTraits.h" | 36 #include "platform/fonts/FontTraits.h" |
36 #include "platform/LayoutTestSupport.h" | 37 #include "platform/LayoutTestSupport.h" |
37 #include "platform/mac/VersionUtilMac.h" | 38 #include "platform/mac/VersionUtilMac.h" |
38 #import "wtf/HashSet.h" | 39 #import "wtf/HashSet.h" |
39 #import "wtf/text/AtomicStringHash.h" | 40 #import "wtf/text/AtomicStringHash.h" |
40 | 41 |
41 @interface NSFont (YosemiteAdditions) | 42 @interface NSFont (YosemiteAdditions) |
42 + (NSFont*)systemFontOfSize:(CGFloat)size weight:(CGFloat)weight; | 43 + (NSFont*)systemFontOfSize:(CGFloat)size weight:(CGFloat)weight; |
43 @end | 44 @end |
44 | 45 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return abs(candidateWeight - 6) > abs(chosenWeight - 6); | 119 return abs(candidateWeight - 6) > abs(chosenWeight - 6); |
119 | 120 |
120 // Otherwise, prefer the one closer to the desired weight. | 121 // Otherwise, prefer the one closer to the desired weight. |
121 return candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude; | 122 return candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude; |
122 } | 123 } |
123 | 124 |
124 // Family name is somewhat of a misnomer here. We first attempt to find an | 125 // Family name is somewhat of a misnomer here. We first attempt to find an |
125 // exact match comparing the desiredFamily to the PostScript name of the | 126 // exact match comparing the desiredFamily to the PostScript name of the |
126 // installed fonts. If that fails we then do a search based on the family | 127 // installed fonts. If that fails we then do a search based on the family |
127 // names of the installed fonts. | 128 // names of the installed fonts. |
128 NSFont* MatchNSFontFamily(NSString* desiredFamily, | 129 NSFont* MatchNSFontFamily(const AtomicString& desiredFamilyString, |
129 NSFontTraitMask desiredTraits, | 130 NSFontTraitMask desiredTraits, |
130 FontWeight desiredWeight, | 131 FontWeight desiredWeight, |
131 float size) { | 132 float size) { |
132 if ([desiredFamily isEqualToString:@"BlinkMacSystemFont"]) { | 133 DCHECK_NE(desiredFamilyString, FontCache::legacySystemFontFamily()); |
| 134 if (desiredFamilyString == FontFamilyNames::system_ui) { |
133 // On OSX 10.9, the default system font depends on the SDK version. When | 135 // On OSX 10.9, the default system font depends on the SDK version. When |
134 // compiled against the OSX 10.10 SDK, the font is .LucidaGrandeUI. When | 136 // compiled against the OSX 10.10 SDK, the font is .LucidaGrandeUI. When |
135 // compiled against the OSX 10.6 SDK, the font is Lucida Grande. Layout | 137 // compiled against the OSX 10.6 SDK, the font is Lucida Grande. Layout |
136 // tests don't support different expectations based on the SDK version, | 138 // tests don't support different expectations based on the SDK version, |
137 // so force layout tests to use "Lucida Grande". Once the 10.10 SDK | 139 // so force layout tests to use "Lucida Grande". Once the 10.10 SDK |
138 // switch is made, this should be changed to return .LucidaGrandeUI and | 140 // switch is made, this should be changed to return .LucidaGrandeUI and |
139 // the Layout Expectations should be updated. http://crbug.com/515836. | 141 // the Layout Expectations should be updated. http://crbug.com/515836. |
140 if (LayoutTestSupport::isRunningLayoutTest() && IsOS10_9()) { | 142 if (LayoutTestSupport::isRunningLayoutTest() && IsOS10_9()) { |
141 if (desiredWeight >= blink::FontWeightBold) | 143 if (desiredWeight >= blink::FontWeightBold) |
142 return [NSFont fontWithName:@"Lucida Grande Bold" size:size]; | 144 return [NSFont fontWithName:@"Lucida Grande Bold" size:size]; |
(...skipping 13 matching lines...) Expand all Loading... |
156 font = [NSFont systemFontOfSize:size | 158 font = [NSFont systemFontOfSize:size |
157 weight:toYosemiteFontWeight(desiredWeight)]; | 159 weight:toYosemiteFontWeight(desiredWeight)]; |
158 } | 160 } |
159 | 161 |
160 if (desiredTraits & IMPORTANT_FONT_TRAITS) | 162 if (desiredTraits & IMPORTANT_FONT_TRAITS) |
161 font = [[NSFontManager sharedFontManager] convertFont:font | 163 font = [[NSFontManager sharedFontManager] convertFont:font |
162 toHaveTrait:desiredTraits]; | 164 toHaveTrait:desiredTraits]; |
163 return font; | 165 return font; |
164 } | 166 } |
165 | 167 |
| 168 NSString* desiredFamily = desiredFamilyString; |
166 NSFontManager* fontManager = [NSFontManager sharedFontManager]; | 169 NSFontManager* fontManager = [NSFontManager sharedFontManager]; |
167 | 170 |
168 // Do a simple case insensitive search for a matching font family. | 171 // Do a simple case insensitive search for a matching font family. |
169 // NSFontManager requires exact name matches. | 172 // NSFontManager requires exact name matches. |
170 // This addresses the problem of matching arial to Arial, etc., but perhaps | 173 // This addresses the problem of matching arial to Arial, etc., but perhaps |
171 // not all the issues. | 174 // not all the issues. |
172 NSEnumerator* e = [[fontManager availableFontFamilies] objectEnumerator]; | 175 NSEnumerator* e = [[fontManager availableFontFamilies] objectEnumerator]; |
173 NSString* availableFamily; | 176 NSString* availableFamily; |
174 while ((availableFamily = [e nextObject])) { | 177 while ((availableFamily = [e nextObject])) { |
175 if ([desiredFamily caseInsensitiveCompare:availableFamily] == NSOrderedSame) | 178 if ([desiredFamily caseInsensitiveCompare:availableFamily] == NSOrderedSame) |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 6, // FontWeight500 | 305 6, // FontWeight500 |
303 8, // FontWeight600 | 306 8, // FontWeight600 |
304 9, // FontWeight700 | 307 9, // FontWeight700 |
305 10, // FontWeight800 | 308 10, // FontWeight800 |
306 12, // FontWeight900 | 309 12, // FontWeight900 |
307 }; | 310 }; |
308 return appKitFontWeights[fontWeight]; | 311 return appKitFontWeights[fontWeight]; |
309 } | 312 } |
310 | 313 |
311 } // namespace blink | 314 } // namespace blink |
OLD | NEW |