| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 else { | 124 else { |
| 125 const SimpleFontData* found = static_cast<const SimpleFontData*>(CFD
ictionaryGetValue(m_derivedFontData->compositeFontReferences.get(), static_cast<
const void *>(key))); | 125 const SimpleFontData* found = static_cast<const SimpleFontData*>(CFD
ictionaryGetValue(m_derivedFontData->compositeFontReferences.get(), static_cast<
const void *>(key))); |
| 126 if (found) | 126 if (found) |
| 127 return found; | 127 return found; |
| 128 } | 128 } |
| 129 if (CFMutableDictionaryRef dictionary = m_derivedFontData->compositeFont
References.get()) { | 129 if (CFMutableDictionaryRef dictionary = m_derivedFontData->compositeFont
References.get()) { |
| 130 NSFont *substituteFont = [key printerFont]; | 130 NSFont *substituteFont = [key printerFont]; |
| 131 | 131 |
| 132 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(toCTFontRef(su
bstituteFont)); | 132 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(toCTFontRef(su
bstituteFont)); |
| 133 bool syntheticBold = platformData().syntheticBold() && !(traits & kC
TFontBoldTrait); | 133 bool syntheticBold = platformData().syntheticBold() && !(traits & kC
TFontBoldTrait); |
| 134 bool syntheticItalic = platformData().syntheticItalic() && !(traits
& kCTFontItalicTrait); | 134 bool syntheticOblique = platformData().syntheticOblique() && !(trait
s & kCTFontItalicTrait); |
| 135 | 135 |
| 136 FontPlatformData substitutePlatform(substituteFont, platformData().s
ize(), syntheticBold, syntheticItalic, platformData().orientation(), platformDat
a().widthVariant()); | 136 FontPlatformData substitutePlatform(substituteFont, platformData().s
ize(), syntheticBold, syntheticOblique, platformData().orientation(), platformDa
ta().widthVariant()); |
| 137 SimpleFontData* value = new SimpleFontData(substitutePlatform, isCus
tomFont() ? CustomFontData::create() : nullptr); | 137 SimpleFontData* value = new SimpleFontData(substitutePlatform, isCus
tomFont() ? CustomFontData::create() : nullptr); |
| 138 if (value) { | 138 if (value) { |
| 139 CFDictionaryAddValue(dictionary, key, value); | 139 CFDictionaryAddValue(dictionary, key, value); |
| 140 return value; | 140 return value; |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 return 0; | 144 return 0; |
| 145 } | 145 } |
| 146 | 146 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 int iLineGap; | 208 int iLineGap; |
| 209 unsigned unitsPerEm; | 209 unsigned unitsPerEm; |
| 210 | 210 |
| 211 iAscent = CGFontGetAscent(m_platformData.cgFont()); | 211 iAscent = CGFontGetAscent(m_platformData.cgFont()); |
| 212 // Some fonts erroneously specify a positive descender value. We follow Core
Text in assuming that | 212 // Some fonts erroneously specify a positive descender value. We follow Core
Text in assuming that |
| 213 // such fonts meant the same distance, but in the reverse direction. | 213 // such fonts meant the same distance, but in the reverse direction. |
| 214 iDescent = -abs(CGFontGetDescent(m_platformData.cgFont())); | 214 iDescent = -abs(CGFontGetDescent(m_platformData.cgFont())); |
| 215 iLineGap = CGFontGetLeading(m_platformData.cgFont()); | 215 iLineGap = CGFontGetLeading(m_platformData.cgFont()); |
| 216 unitsPerEm = CGFontGetUnitsPerEm(m_platformData.cgFont()); | 216 unitsPerEm = CGFontGetUnitsPerEm(m_platformData.cgFont()); |
| 217 | 217 |
| 218 float pointSize = m_platformData.m_textSize; | 218 float pointSize = m_platformData.m_size; |
| 219 float ascent = scaleEmToUnits(iAscent, unitsPerEm) * pointSize; | 219 float ascent = scaleEmToUnits(iAscent, unitsPerEm) * pointSize; |
| 220 float descent = -scaleEmToUnits(iDescent, unitsPerEm) * pointSize; | 220 float descent = -scaleEmToUnits(iDescent, unitsPerEm) * pointSize; |
| 221 float lineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize; | 221 float lineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize; |
| 222 float underlineThickness = CTFontGetUnderlineThickness(m_platformData.ctFont
()); | 222 float underlineThickness = CTFontGetUnderlineThickness(m_platformData.ctFont
()); |
| 223 float underlinePosition = CTFontGetUnderlinePosition(m_platformData.ctFont()
); | 223 float underlinePosition = CTFontGetUnderlinePosition(m_platformData.ctFont()
); |
| 224 | 224 |
| 225 // We need to adjust Times, Helvetica, and Courier to closely match the | 225 // We need to adjust Times, Helvetica, and Courier to closely match the |
| 226 // vertical metrics of their Microsoft counterparts that are the de facto | 226 // vertical metrics of their Microsoft counterparts that are the de facto |
| 227 // web standard. The AppKit adjustment of 20% is too big and is | 227 // web standard. The AppKit adjustment of 20% is too big and is |
| 228 // incorrectly added to line spacing, so we use a 15% adjustment instead | 228 // incorrectly added to line spacing, so we use a 15% adjustment instead |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 274 |
| 275 void SimpleFontData::platformCharWidthInit() | 275 void SimpleFontData::platformCharWidthInit() |
| 276 { | 276 { |
| 277 m_avgCharWidth = 0; | 277 m_avgCharWidth = 0; |
| 278 m_maxCharWidth = 0; | 278 m_maxCharWidth = 0; |
| 279 | 279 |
| 280 RetainPtr<CFDataRef> os2Table(AdoptCF, copyFontTableForTag(m_platformData, '
OS/2')); | 280 RetainPtr<CFDataRef> os2Table(AdoptCF, copyFontTableForTag(m_platformData, '
OS/2')); |
| 281 if (os2Table && CFDataGetLength(os2Table.get()) >= 4) { | 281 if (os2Table && CFDataGetLength(os2Table.get()) >= 4) { |
| 282 const UInt8* os2 = CFDataGetBytePtr(os2Table.get()); | 282 const UInt8* os2 = CFDataGetBytePtr(os2Table.get()); |
| 283 SInt16 os2AvgCharWidth = os2[2] * 256 + os2[3]; | 283 SInt16 os2AvgCharWidth = os2[2] * 256 + os2[3]; |
| 284 m_avgCharWidth = scaleEmToUnits(os2AvgCharWidth, m_fontMetrics.unitsPerE
m()) * m_platformData.m_textSize; | 284 m_avgCharWidth = scaleEmToUnits(os2AvgCharWidth, m_fontMetrics.unitsPerE
m()) * m_platformData.m_size; |
| 285 } | 285 } |
| 286 | 286 |
| 287 RetainPtr<CFDataRef> headTable(AdoptCF, copyFontTableForTag(m_platformData,
'head')); | 287 RetainPtr<CFDataRef> headTable(AdoptCF, copyFontTableForTag(m_platformData,
'head')); |
| 288 if (headTable && CFDataGetLength(headTable.get()) >= 42) { | 288 if (headTable && CFDataGetLength(headTable.get()) >= 42) { |
| 289 const UInt8* head = CFDataGetBytePtr(headTable.get()); | 289 const UInt8* head = CFDataGetBytePtr(headTable.get()); |
| 290 ushort uxMin = head[36] * 256 + head[37]; | 290 ushort uxMin = head[36] * 256 + head[37]; |
| 291 ushort uxMax = head[40] * 256 + head[41]; | 291 ushort uxMax = head[40] * 256 + head[41]; |
| 292 SInt16 xMin = static_cast<SInt16>(uxMin); | 292 SInt16 xMin = static_cast<SInt16>(uxMin); |
| 293 SInt16 xMax = static_cast<SInt16>(uxMax); | 293 SInt16 xMax = static_cast<SInt16>(uxMax); |
| 294 float diff = static_cast<float>(xMax - xMin); | 294 float diff = static_cast<float>(xMax - xMin); |
| 295 m_maxCharWidth = scaleEmToUnits(diff, m_fontMetrics.unitsPerEm()) * m_pl
atformData.m_textSize; | 295 m_maxCharWidth = scaleEmToUnits(diff, m_fontMetrics.unitsPerEm()) * m_pl
atformData.m_size; |
| 296 } | 296 } |
| 297 | 297 |
| 298 // Fallback to a cross-platform estimate, which will populate these values i
f they are non-positive. | 298 // Fallback to a cross-platform estimate, which will populate these values i
f they are non-positive. |
| 299 initCharWidths(); | 299 initCharWidths(); |
| 300 } | 300 } |
| 301 | 301 |
| 302 void SimpleFontData::platformDestroy() | 302 void SimpleFontData::platformDestroy() |
| 303 { | 303 { |
| 304 if (!isCustomFont() && m_derivedFontData) { | 304 if (!isCustomFont() && m_derivedFontData) { |
| 305 // These come from the cache. | 305 // These come from the cache. |
| 306 if (m_derivedFontData->smallCaps) | 306 if (m_derivedFontData->smallCaps) |
| 307 FontCache::fontCache()->releaseFontData(m_derivedFontData->smallCaps
.get()); | 307 FontCache::fontCache()->releaseFontData(m_derivedFontData->smallCaps
.get()); |
| 308 | 308 |
| 309 if (m_derivedFontData->emphasisMark) | 309 if (m_derivedFontData->emphasisMark) |
| 310 FontCache::fontCache()->releaseFontData(m_derivedFontData->emphasisM
ark.get()); | 310 FontCache::fontCache()->releaseFontData(m_derivedFontData->emphasisM
ark.get()); |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| 314 PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const Fo
ntDescription& fontDescription, float scaleFactor) const | 314 PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const Fo
ntDescription& fontDescription, float scaleFactor) const |
| 315 { | 315 { |
| 316 if (isCustomFont()) { | 316 if (isCustomFont()) { |
| 317 FontPlatformData scaledFontData(m_platformData); | 317 FontPlatformData scaledFontData(m_platformData); |
| 318 scaledFontData.m_textSize = scaledFontData.m_textSize * scaleFactor; | 318 scaledFontData.m_size = scaledFontData.m_size * scaleFactor; |
| 319 return SimpleFontData::create(scaledFontData, CustomFontData::create()); | 319 return SimpleFontData::create(scaledFontData, CustomFontData::create()); |
| 320 } | 320 } |
| 321 | 321 |
| 322 BEGIN_BLOCK_OBJC_EXCEPTIONS; | 322 BEGIN_BLOCK_OBJC_EXCEPTIONS; |
| 323 float size = m_platformData.size() * scaleFactor; | 323 float size = m_platformData.size() * scaleFactor; |
| 324 FontPlatformData scaledFontData([[NSFontManager sharedFontManager] convertFo
nt:m_platformData.font() toSize:size], size, false, false, m_platformData.orient
ation()); | 324 FontPlatformData scaledFontData([[NSFontManager sharedFontManager] convertFo
nt:m_platformData.font() toSize:size], size, false, false, m_platformData.orient
ation()); |
| 325 | 325 |
| 326 // AppKit forgets about hinting property when scaling, so we have to remind
it. | 326 // AppKit forgets about hinting property when scaling, so we have to remind
it. |
| 327 scaledFontData.setFont(useHinting() ? [scaledFontData.font() screenFont] : [
scaledFontData.font() printerFont]); | 327 scaledFontData.setFont(useHinting() ? [scaledFontData.font() screenFont] : [
scaledFontData.font() printerFont]); |
| 328 | 328 |
| 329 if (scaledFontData.font()) { | 329 if (scaledFontData.font()) { |
| 330 NSFontManager *fontManager = [NSFontManager sharedFontManager]; | 330 NSFontManager *fontManager = [NSFontManager sharedFontManager]; |
| 331 NSFontTraitMask fontTraits = [fontManager traitsOfFont:m_platformData.fo
nt()]; | 331 NSFontTraitMask fontTraits = [fontManager traitsOfFont:m_platformData.fo
nt()]; |
| 332 | 332 |
| 333 if (m_platformData.m_syntheticBold) | 333 if (m_platformData.m_syntheticBold) |
| 334 fontTraits |= NSBoldFontMask; | 334 fontTraits |= NSBoldFontMask; |
| 335 if (m_platformData.m_syntheticItalic) | 335 if (m_platformData.m_syntheticOblique) |
| 336 fontTraits |= NSItalicFontMask; | 336 fontTraits |= NSItalicFontMask; |
| 337 | 337 |
| 338 NSFontTraitMask scaledFontTraits = [fontManager traitsOfFont:scaledFontD
ata.font()]; | 338 NSFontTraitMask scaledFontTraits = [fontManager traitsOfFont:scaledFontD
ata.font()]; |
| 339 scaledFontData.m_syntheticBold = (fontTraits & NSBoldFontMask) && !(scal
edFontTraits & NSBoldFontMask); | 339 scaledFontData.m_syntheticBold = (fontTraits & NSBoldFontMask) && !(scal
edFontTraits & NSBoldFontMask); |
| 340 scaledFontData.m_syntheticItalic = (fontTraits & NSItalicFontMask) && !(
scaledFontTraits & NSItalicFontMask); | 340 scaledFontData.m_syntheticOblique = (fontTraits & NSItalicFontMask) && !
(scaledFontTraits & NSItalicFontMask); |
| 341 | 341 |
| 342 // SimpleFontData::platformDestroy() takes care of not deleting the cach
ed font data twice. | 342 // SimpleFontData::platformDestroy() takes care of not deleting the cach
ed font data twice. |
| 343 return FontCache::fontCache()->fontDataFromFontPlatformData(&scaledFontD
ata); | 343 return FontCache::fontCache()->fontDataFromFontPlatformData(&scaledFontD
ata); |
| 344 } | 344 } |
| 345 END_BLOCK_OBJC_EXCEPTIONS; | 345 END_BLOCK_OBJC_EXCEPTIONS; |
| 346 | 346 |
| 347 return nullptr; | 347 return nullptr; |
| 348 } | 348 } |
| 349 | 349 |
| 350 void SimpleFontData::determinePitch() | 350 void SimpleFontData::determinePitch() |
| (...skipping 30 matching lines...) Expand all Loading... |
| 381 } | 381 } |
| 382 | 382 |
| 383 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const | 383 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const |
| 384 { | 384 { |
| 385 CGSize advance = CGSizeZero; | 385 CGSize advance = CGSizeZero; |
| 386 if (platformData().orientation() == Horizontal || m_isBrokenIdeographFallbac
k) { | 386 if (platformData().orientation() == Horizontal || m_isBrokenIdeographFallbac
k) { |
| 387 NSFont *font = platformData().font(); | 387 NSFont *font = platformData().font(); |
| 388 if (font && platformData().isColorBitmapFont()) | 388 if (font && platformData().isColorBitmapFont()) |
| 389 advance = NSSizeToCGSize([font advancementForGlyph:glyph]); | 389 advance = NSSizeToCGSize([font advancementForGlyph:glyph]); |
| 390 else { | 390 else { |
| 391 float pointSize = platformData().m_textSize; | 391 float pointSize = platformData().m_size; |
| 392 CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSiz
e); | 392 CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSiz
e); |
| 393 if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &m, cgF
ontRenderingModeForNSFont(font), &glyph, 1, &advance)) { | 393 if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &m, cgF
ontRenderingModeForNSFont(font), &glyph, 1, &advance)) { |
| 394 WTF_LOG_ERROR("Unable to cache glyph widths for %@ %f", [font di
splayName], pointSize); | 394 WTF_LOG_ERROR("Unable to cache glyph widths for %@ %f", [font di
splayName], pointSize); |
| 395 advance.width = 0; | 395 advance.width = 0; |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 } else | 398 } else |
| 399 CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), kCTFontVerticalOrien
tation, &glyph, &advance, 1); | 399 CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), kCTFontVerticalOrien
tation, &glyph, &advance, 1); |
| 400 | 400 |
| 401 return advance.width + m_syntheticBoldOffset; | 401 return advance.width + m_syntheticBoldOffset; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 RetainPtr<CGFontRef> runCGFont(AdoptCF, CTFontCopyGraphicsFont(runFont,
0)); | 445 RetainPtr<CGFontRef> runCGFont(AdoptCF, CTFontCopyGraphicsFont(runFont,
0)); |
| 446 if (!CFEqual(runCGFont.get(), cgFont.get())) | 446 if (!CFEqual(runCGFont.get(), cgFont.get())) |
| 447 return false; | 447 return false; |
| 448 } | 448 } |
| 449 | 449 |
| 450 addResult.storedValue->value = true; | 450 addResult.storedValue->value = true; |
| 451 return true; | 451 return true; |
| 452 } | 452 } |
| 453 | 453 |
| 454 } // namespace blink | 454 } // namespace blink |
| OLD | NEW |