OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2010, 2011 Apple Inc. All rights reserved. |
3 * Copyright (C) 2006 Alexey Proskuryakov | 3 * Copyright (C) 2006 Alexey Proskuryakov |
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 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 return true; | 101 return true; |
102 } | 102 } |
103 | 103 |
104 static NSString *webFallbackFontFamily(void) | 104 static NSString *webFallbackFontFamily(void) |
105 { | 105 { |
106 DEFINE_STATIC_LOCAL(RetainPtr<NSString>, webFallbackFontFamily, ([[NSFont sy
stemFontOfSize:16.0f] familyName])); | 106 DEFINE_STATIC_LOCAL(RetainPtr<NSString>, webFallbackFontFamily, ([[NSFont sy
stemFontOfSize:16.0f] familyName])); |
107 return webFallbackFontFamily.get(); | 107 return webFallbackFontFamily.get(); |
108 } | 108 } |
109 | 109 |
110 #if !ERROR_DISABLED | |
111 #if defined(__LP64__) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 || (__MAC_OS_X_
VERSION_MAX_ALLOWED >= 1070 && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) | |
112 static NSString* pathFromFont(NSFont*) | |
113 { | |
114 // FMGetATSFontRefFromFont is not available. As pathFromFont is only used fo
r debugging purposes, | |
115 // returning nil is acceptable. | |
116 return nil; | |
117 } | |
118 #else | |
119 static NSString* pathFromFont(NSFont *font) | |
120 { | |
121 ATSFontRef atsFont = FMGetATSFontRefFromFont(CTFontGetPlatformFont(toCTFontR
ef(font), 0)); | |
122 FSRef fileRef; | |
123 | |
124 OSStatus status = ATSFontGetFileReference(atsFont, &fileRef); | |
125 if (status != noErr) | |
126 return nil; | |
127 | |
128 UInt8 filePathBuffer[PATH_MAX]; | |
129 status = FSRefMakePath(&fileRef, filePathBuffer, PATH_MAX); | |
130 if (status == noErr) | |
131 return [NSString stringWithUTF8String:(const char*)filePathBuffer]; | |
132 | |
133 return nil; | |
134 } | |
135 #endif // __LP64__ | |
136 #endif // !ERROR_DISABLED | |
137 | |
138 const SimpleFontData* SimpleFontData::getCompositeFontReferenceFontData(NSFont *
key) const | 110 const SimpleFontData* SimpleFontData::getCompositeFontReferenceFontData(NSFont *
key) const |
139 { | 111 { |
140 if (key && !CFEqual(RetainPtr<CFStringRef>(AdoptCF, CTFontCopyPostScriptName
(CTFontRef(key))).get(), CFSTR("LastResort"))) { | 112 if (key && !CFEqual(RetainPtr<CFStringRef>(AdoptCF, CTFontCopyPostScriptName
(CTFontRef(key))).get(), CFSTR("LastResort"))) { |
141 if (!m_derivedFontData) | 113 if (!m_derivedFontData) |
142 m_derivedFontData = DerivedFontData::create(isCustomFont()); | 114 m_derivedFontData = DerivedFontData::create(isCustomFont()); |
143 if (!m_derivedFontData->compositeFontReferences) | 115 if (!m_derivedFontData->compositeFontReferences) |
144 m_derivedFontData->compositeFontReferences.adoptCF(CFDictionaryCreat
eMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, NULL)); | 116 m_derivedFontData->compositeFontReferences.adoptCF(CFDictionaryCreat
eMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, NULL)); |
145 else { | 117 else { |
146 const SimpleFontData* found = static_cast<const SimpleFontData*>(CFD
ictionaryGetValue(m_derivedFontData->compositeFontReferences.get(), static_cast<
const void *>(key))); | 118 const SimpleFontData* found = static_cast<const SimpleFontData*>(CFD
ictionaryGetValue(m_derivedFontData->compositeFontReferences.get(), static_cast<
const void *>(key))); |
147 if (found) | 119 if (found) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 159 |
188 // Try setting up the alternate font. | 160 // Try setting up the alternate font. |
189 // This is a last ditch effort to use a substitute font when something h
as gone wrong. | 161 // This is a last ditch effort to use a substitute font when something h
as gone wrong. |
190 #if !ERROR_DISABLED | 162 #if !ERROR_DISABLED |
191 RetainPtr<NSFont> initialFont = m_platformData.font(); | 163 RetainPtr<NSFont> initialFont = m_platformData.font(); |
192 #endif | 164 #endif |
193 if (m_platformData.font()) | 165 if (m_platformData.font()) |
194 m_platformData.setFont([[NSFontManager sharedFontManager] convertFon
t:m_platformData.font() toFamily:fallbackFontFamily]); | 166 m_platformData.setFont([[NSFontManager sharedFontManager] convertFon
t:m_platformData.font() toFamily:fallbackFontFamily]); |
195 else | 167 else |
196 m_platformData.setFont([NSFont fontWithName:fallbackFontFamily size:
m_platformData.size()]); | 168 m_platformData.setFont([NSFont fontWithName:fallbackFontFamily size:
m_platformData.size()]); |
197 #if !ERROR_DISABLED | 169 |
198 NSString *filePath = pathFromFont(initialFont.get()); | |
199 if (!filePath) | |
200 filePath = @"not known"; | |
201 #endif | |
202 if (!initFontData(this)) { | 170 if (!initFontData(this)) { |
203 if ([fallbackFontFamily isEqual:@"Times New Roman"]) { | 171 if ([fallbackFontFamily isEqual:@"Times New Roman"]) { |
204 // OK, couldn't setup Times New Roman as an alternate to Times,
fallback | 172 // OK, couldn't setup Times New Roman as an alternate to Times,
fallback |
205 // on the system font. If this fails we have no alternative lef
t. | 173 // on the system font. If this fails we have no alternative lef
t. |
206 m_platformData.setFont([[NSFontManager sharedFontManager] conver
tFont:m_platformData.font() toFamily:webFallbackFontFamily()]); | 174 m_platformData.setFont([[NSFontManager sharedFontManager] conver
tFont:m_platformData.font() toFamily:webFallbackFontFamily()]); |
207 if (!initFontData(this)) { | 175 if (!initFontData(this)) { |
208 // We tried, Times, Times New Roman, and the system font. No
joy. We have to give up. | 176 // We tried, Times, Times New Roman, and the system font. No
joy. We have to give up. |
209 LOG_ERROR("unable to initialize with font %@ at %@", initial
Font.get(), filePath); | 177 LOG_ERROR("unable to initialize with font %@", initialFont.g
et()); |
210 failedSetup = true; | 178 failedSetup = true; |
211 } | 179 } |
212 } else { | 180 } else { |
213 // We tried the requested font and the system font. No joy. We h
ave to give up. | 181 // We tried the requested font and the system font. No joy. We h
ave to give up. |
214 LOG_ERROR("unable to initialize with font %@ at %@", initialFont
.get(), filePath); | 182 LOG_ERROR("unable to initialize with font %@", initialFont.get()
); |
215 failedSetup = true; | 183 failedSetup = true; |
216 } | 184 } |
217 } | 185 } |
218 | 186 |
219 // Report the problem. | 187 // Report the problem. |
220 LOG_ERROR("Corrupt font detected, using %@ in place of %@ located at \"%
@\".", | 188 LOG_ERROR("Corrupt font detected, using %@ in place of %@.", |
221 [m_platformData.font() familyName], [initialFont.get() familyName],
filePath); | 189 [m_platformData.font() familyName], [initialFont.get() familyName]); |
222 } | 190 } |
223 | 191 |
224 // If all else fails, try to set up using the system font. | 192 // If all else fails, try to set up using the system font. |
225 // This is probably because Times and Times New Roman are both unavailable. | 193 // This is probably because Times and Times New Roman are both unavailable. |
226 if (failedSetup) { | 194 if (failedSetup) { |
227 m_platformData.setFont([NSFont systemFontOfSize:[m_platformData.font() p
ointSize]]); | 195 m_platformData.setFont([NSFont systemFontOfSize:[m_platformData.font() p
ointSize]]); |
228 LOG_ERROR("failed to set up font, using system font %s", m_platformData.
font()); | 196 LOG_ERROR("failed to set up font, using system font %s", m_platformData.
font()); |
229 initFontData(this); | 197 initFontData(this); |
230 } | 198 } |
231 | 199 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 RetainPtr<CGFontRef> runCGFont(AdoptCF, CTFontCopyGraphicsFont(runFont,
0)); | 444 RetainPtr<CGFontRef> runCGFont(AdoptCF, CTFontCopyGraphicsFont(runFont,
0)); |
477 if (!CFEqual(runCGFont.get(), cgFont.get())) | 445 if (!CFEqual(runCGFont.get(), cgFont.get())) |
478 return false; | 446 return false; |
479 } | 447 } |
480 | 448 |
481 addResult.iterator->value = true; | 449 addResult.iterator->value = true; |
482 return true; | 450 return true; |
483 } | 451 } |
484 | 452 |
485 } // namespace WebCore | 453 } // namespace WebCore |
OLD | NEW |