Changeset 167773 in webkit
- Timestamp:
- Apr 24, 2014, 2:20:54 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
platform/graphics/SimpleFontData.h (modified) (2 diffs)
-
platform/graphics/ios/SimpleFontDataIOS.mm (modified) (2 diffs)
-
platform/graphics/mac/SimpleFontDataMac.mm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r167771 r167773 1 2014-04-24 Myles C. Maxfield <mmaxfield@apple.com> 2 3 Unify platformWidthForGlyph across OS X and iOS 4 https://bugs.webkit.org/show_bug.cgi?id=132036 5 6 Reviewed by Darin Adler. 7 8 This patch creates on shared SimpleFontData::platformWidthForGlyph() function for both OS X and iOS. 9 10 No new tests are necessary because there should be no behavior changes. 11 12 * platform/graphics/SimpleFontData.h: Signatures for two helper functions 13 * platform/graphics/ios/SimpleFontDataIOS.mm: Replace iOS implementation of platformWidthForGlyph() with 14 implementations of only the two helper functions 15 (WebCore::SimpleFontData::getRenderingStyle): Compute style argument to CGFontGetGlyphAdvancesForStyle() 16 (WebCore::SimpleFontData::advanceForColorBitmapFont): iOS doesn't have color bitmap fonts 17 (WebCore::SimpleFontData::platformWidthForGlyph): Deleted. 18 * platform/graphics/mac/SimpleFontDataMac.mm: 19 (WebCore::SimpleFontData::getRenderingStyle): Compute style argument to CGFontGetGlyphAdvancesForStyle() 20 (WebCore::SimpleFontData::advanceForColorBitmapFont): Use [NSFont advancementForGlyph] to compute the advance 21 (WebCore::hasCustomTracking): Removed #if 22 (WebCore::isEmoji): Only relevant on iOS 23 (WebCore::SimpleFontData::platformWidthForGlyph): Shared implementation. Calls helper functions. 24 1 25 2014-04-24 Zalan Bujtas <zalan@apple.com> 2 26 -
trunk/Source/WebCore/platform/graphics/SimpleFontData.h
r166633 r167773 53 53 #if USE(CAIRO) 54 54 #include <cairo.h> 55 #endif 56 57 #if USE(CG) 58 #if defined(__has_include) && __has_include(<CoreGraphics/CGFontRendering.h>) 59 #include <CoreGraphics/CGFontRendering.h> 60 #else 61 enum { 62 kCGFontRenderingStyleAntialiasing = (1 << 0), 63 kCGFontRenderingStyleSmoothing = (1 << 1), 64 kCGFontRenderingStyleSubpixelPositioning = (1 << 2), 65 kCGFontRenderingStyleSubpixelQuantization = (1 << 3), 66 kCGFontRenderingStylePlatformNative = (1 << 9), 67 kCGFontRenderingStyleMask = 0x20F 68 }; 69 #endif 70 typedef uint32_t CGFontRenderingStyle; 55 71 #endif 56 72 … … 246 262 #endif 247 263 264 #if USE(CG) 265 bool canUseFastGlyphAdvanceGetter(Glyph glyph, CGSize& advance, bool& populatedAdvance) const; 266 CGFontRenderingStyle renderingStyle() const; 267 bool advanceForColorBitmapFont(Glyph, CGSize& result) const; // Returns true if the font is a color bitmap font 268 #endif 269 248 270 FontMetrics m_fontMetrics; 249 271 float m_maxCharWidth; -
trunk/Source/WebCore/platform/graphics/ios/SimpleFontDataIOS.mm
r167768 r167773 33 33 #import "FontDescription.h" 34 34 #import "FontServicesIOS.h" 35 #import <CoreGraphics/CGFontGlyphSupport.h>36 35 #import <CoreGraphics/CGFontInfo.h> 37 #import <CoreGraphics/CGFontRendering.h>38 36 #import <CoreText/CoreText.h> 39 37 #import <float.h> … … 188 186 } 189 187 190 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const188 CGFontRenderingStyle SimpleFontData::renderingStyle() const 191 189 { 192 CGSize advance = CGSizeZero; 193 if (platformData().orientation() == Horizontal || m_isBrokenIdeographFallback) { 194 if (platformData().m_isEmoji) 195 CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), kCTFontHorizontalOrientation, &glyph, &advance, 1); 196 else { 197 float pointSize = platformData().m_size; 198 CGAffineTransform transform = CGAffineTransformMakeScale(pointSize, pointSize); 199 static const CGFontRenderingStyle renderingStyle = kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization | kCGFontAntialiasingStyleUnfiltered; 200 if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &transform, renderingStyle, &glyph, 1, &advance)) { 201 RetainPtr<CFStringRef> fullName = adoptCF(CGFontCopyFullName(platformData().cgFont())); 202 LOG_ERROR("Unable to cache glyph widths for %@ %f", fullName.get(), pointSize); 203 advance.width = 0; 204 } 205 } 206 } else 207 CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), kCTFontVerticalOrientation, &glyph, &advance, 1); 190 return kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization | kCGFontAntialiasingStyleUnfiltered; 191 } 208 192 209 return advance.width + m_syntheticBoldOffset; 193 bool SimpleFontData::advanceForColorBitmapFont(Glyph, CGSize&) const 194 { 195 return false; 210 196 } 211 197 -
trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm
r167768 r167773 51 51 #import <CoreText/CTFontDescriptorPriv.h> 52 52 #endif 53 54 53 extern "C" bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef); 54 55 #if defined(__has_include) && __has_include(<CoreGraphics/CGFontGlyphSupport.h>) 56 #import <CoreGraphics/CGFontGlyphSupport.h> 57 #endif 58 extern "C" bool CGFontGetGlyphAdvancesForStyle(CGFontRef font, 59 const CGAffineTransform *t, CGFontRenderingStyle style, 60 const CGGlyph glyphs[], size_t count, CGSize advances[]); 55 61 56 62 #if !PLATFORM(IOS) … … 366 372 } 367 373 368 #if !PLATFORM(IOS) 374 #if PLATFORM(MAC) 375 inline CGFontRenderingStyle SimpleFontData::renderingStyle() const 376 { 377 CGFontRenderingStyle style = kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization; 378 NSFont *font = platformData().font(); 379 if (font) { 380 switch ([font renderingMode]) { 381 case NSFontIntegerAdvancementsRenderingMode: 382 style = 0; 383 break; 384 case NSFontAntialiasedIntegerAdvancementsRenderingMode: 385 style = kCGFontRenderingStyleAntialiasing; 386 break; 387 default: 388 break; 389 } 390 } 391 return style; 392 } 393 394 inline bool SimpleFontData::advanceForColorBitmapFont(Glyph glyph, CGSize& advance) const 395 { 396 NSFont *font = platformData().font(); 397 if (!font || !platformData().isColorBitmapFont()) 398 return false; 399 advance = NSSizeToCGSize([font advancementForGlyph:glyph]); 400 return true; 401 } 402 #endif 403 369 404 static bool hasCustomTracking(CTFontRef font) 370 405 { 371 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1090406 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1090 372 407 UNUSED_PARAM(font); 373 408 return false; … … 377 412 } 378 413 414 static inline bool isEmoji(const FontPlatformData& platformData) 415 { 416 #if PLATFORM(IOS) 417 return platformData.m_isEmoji; 418 #else 419 UNUSED_PARAM(platformData); 420 return false; 421 #endif 422 } 423 424 inline bool SimpleFontData::canUseFastGlyphAdvanceGetter(Glyph glyph, CGSize& advance, bool& populatedAdvance) const 425 { 426 // Fast getter doesn't take custom tracking into account 427 if (hasCustomTracking(platformData().ctFont())) 428 return false; 429 // Fast getter doesn't work for emoji 430 if (isEmoji(platformData())) 431 return false; 432 // ... or for any bitmap fonts in general 433 if (advanceForColorBitmapFont(glyph, advance)) { 434 populatedAdvance = true; 435 return false; 436 } 437 return true; 438 } 439 379 440 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const 380 441 { 381 442 CGSize advance = CGSizeZero; 382 443 bool horizontal = platformData().orientation() == Horizontal; 383 if ((horizontal || m_isBrokenIdeographFallback) && !hasCustomTracking(m_platformData.ctFont())) { 384 NSFont *font = platformData().font(); 385 if (font && platformData().isColorBitmapFont()) 386 advance = NSSizeToCGSize([font advancementForGlyph:glyph]); 387 else { 388 float pointSize = platformData().m_size; 389 CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize); 390 if (!wkGetGlyphTransformedAdvances(platformData().cgFont(), font, &m, &glyph, &advance)) { 391 LOG_ERROR("Unable to cache glyph widths for %@ %f", [font displayName], pointSize); 392 advance.width = 0; 393 } 444 bool populatedAdvance = false; 445 if ((horizontal || m_isBrokenIdeographFallback) && canUseFastGlyphAdvanceGetter(glyph, advance, populatedAdvance)) { 446 float pointSize = platformData().m_size; 447 CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize); 448 if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &m, renderingStyle(), &glyph, 1, &advance)) { 449 RetainPtr<CFStringRef> fullName = adoptCF(CGFontCopyFullName(platformData().cgFont())); 450 LOG_ERROR("Unable to cache glyph widths for %@ %f", fullName.get(), pointSize); 451 advance.width = 0; 394 452 } 395 } else 453 } else if (!populatedAdvance) 396 454 CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), horizontal ? kCTFontHorizontalOrientation : kCTFontVerticalOrientation, &glyph, &advance, 1); 397 455 398 456 return advance.width + m_syntheticBoldOffset; 399 457 } 400 #endif // !PLATFORM(IOS)401 458 402 459 struct ProviderInfo {
Note:
See TracChangeset
for help on using the changeset viewer.