Title: [167773] trunk/Source/WebCore
Revision
167773
Author
mmaxfi...@apple.com
Date
2014-04-24 14:20:54 -0700 (Thu, 24 Apr 2014)

Log Message

Unify platformWidthForGlyph across OS X and iOS
https://bugs.webkit.org/show_bug.cgi?id=132036

Reviewed by Darin Adler.

This patch creates on shared SimpleFontData::platformWidthForGlyph() function for both OS X and iOS.

No new tests are necessary because there should be no behavior changes.

* platform/graphics/SimpleFontData.h: Signatures for two helper functions
* platform/graphics/ios/SimpleFontDataIOS.mm: Replace iOS implementation of platformWidthForGlyph() with
implementations of only the two helper functions
(WebCore::SimpleFontData::getRenderingStyle): Compute style argument to CGFontGetGlyphAdvancesForStyle()
(WebCore::SimpleFontData::advanceForColorBitmapFont): iOS doesn't have color bitmap fonts
(WebCore::SimpleFontData::platformWidthForGlyph): Deleted.
* platform/graphics/mac/SimpleFontDataMac.mm:
(WebCore::SimpleFontData::getRenderingStyle): Compute style argument to CGFontGetGlyphAdvancesForStyle()
(WebCore::SimpleFontData::advanceForColorBitmapFont): Use [NSFont advancementForGlyph] to compute the advance
(WebCore::hasCustomTracking): Removed #if
(WebCore::isEmoji): Only relevant on iOS
(WebCore::SimpleFontData::platformWidthForGlyph): Shared implementation. Calls helper functions.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (167772 => 167773)


--- trunk/Source/WebCore/ChangeLog	2014-04-24 21:12:56 UTC (rev 167772)
+++ trunk/Source/WebCore/ChangeLog	2014-04-24 21:20:54 UTC (rev 167773)
@@ -1,3 +1,27 @@
+2014-04-24  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        Unify platformWidthForGlyph across OS X and iOS
+        https://bugs.webkit.org/show_bug.cgi?id=132036
+
+        Reviewed by Darin Adler.
+
+        This patch creates on shared SimpleFontData::platformWidthForGlyph() function for both OS X and iOS.
+
+        No new tests are necessary because there should be no behavior changes.
+
+        * platform/graphics/SimpleFontData.h: Signatures for two helper functions
+        * platform/graphics/ios/SimpleFontDataIOS.mm: Replace iOS implementation of platformWidthForGlyph() with
+        implementations of only the two helper functions
+        (WebCore::SimpleFontData::getRenderingStyle): Compute style argument to CGFontGetGlyphAdvancesForStyle()
+        (WebCore::SimpleFontData::advanceForColorBitmapFont): iOS doesn't have color bitmap fonts
+        (WebCore::SimpleFontData::platformWidthForGlyph): Deleted.
+        * platform/graphics/mac/SimpleFontDataMac.mm:
+        (WebCore::SimpleFontData::getRenderingStyle): Compute style argument to CGFontGetGlyphAdvancesForStyle()
+        (WebCore::SimpleFontData::advanceForColorBitmapFont): Use [NSFont advancementForGlyph] to compute the advance
+        (WebCore::hasCustomTracking): Removed #if
+        (WebCore::isEmoji): Only relevant on iOS
+        (WebCore::SimpleFontData::platformWidthForGlyph): Shared implementation. Calls helper functions.
+
 2014-04-24  Zalan Bujtas  <za...@apple.com>
 
         Subpixel rendering: Clipping on text areas when shifted by one device pixel.

Modified: trunk/Source/WebCore/platform/graphics/SimpleFontData.h (167772 => 167773)


--- trunk/Source/WebCore/platform/graphics/SimpleFontData.h	2014-04-24 21:12:56 UTC (rev 167772)
+++ trunk/Source/WebCore/platform/graphics/SimpleFontData.h	2014-04-24 21:20:54 UTC (rev 167773)
@@ -54,6 +54,22 @@
 #include <cairo.h>
 #endif
 
+#if USE(CG)
+#if defined(__has_include) && __has_include(<CoreGraphics/CGFontRendering.h>)
+#include <CoreGraphics/CGFontRendering.h>
+#else
+enum {
+    kCGFontRenderingStyleAntialiasing = (1 << 0),
+    kCGFontRenderingStyleSmoothing = (1 << 1),
+    kCGFontRenderingStyleSubpixelPositioning = (1 << 2),
+    kCGFontRenderingStyleSubpixelQuantization = (1 << 3),
+    kCGFontRenderingStylePlatformNative = (1 << 9),
+    kCGFontRenderingStyleMask = 0x20F
+};
+#endif
+typedef uint32_t CGFontRenderingStyle;
+#endif
+
 namespace WebCore {
 
 class FontDescription;
@@ -245,6 +261,12 @@
     float widthForGDIGlyph(Glyph glyph) const;
 #endif
 
+#if USE(CG)
+    bool canUseFastGlyphAdvanceGetter(Glyph glyph, CGSize& advance, bool& populatedAdvance) const;
+    CGFontRenderingStyle renderingStyle() const;
+    bool advanceForColorBitmapFont(Glyph, CGSize& result) const; // Returns true if the font is a color bitmap font
+#endif
+
     FontMetrics m_fontMetrics;
     float m_maxCharWidth;
     float m_avgCharWidth;

Modified: trunk/Source/WebCore/platform/graphics/ios/SimpleFontDataIOS.mm (167772 => 167773)


--- trunk/Source/WebCore/platform/graphics/ios/SimpleFontDataIOS.mm	2014-04-24 21:12:56 UTC (rev 167772)
+++ trunk/Source/WebCore/platform/graphics/ios/SimpleFontDataIOS.mm	2014-04-24 21:20:54 UTC (rev 167773)
@@ -32,9 +32,7 @@
 #import "FontCache.h"
 #import "FontDescription.h"
 #import "FontServicesIOS.h"
-#import <CoreGraphics/CGFontGlyphSupport.h>
 #import <CoreGraphics/CGFontInfo.h>
-#import <CoreGraphics/CGFontRendering.h>
 #import <CoreText/CoreText.h>
 #import <float.h>
 #import <unicode/uchar.h>
@@ -187,26 +185,14 @@
     }
 }
 
-float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
+CGFontRenderingStyle SimpleFontData::renderingStyle() const
 {
-    CGSize advance = CGSizeZero;
-    if (platformData().orientation() == Horizontal || m_isBrokenIdeographFallback) {
-        if (platformData().m_isEmoji)
-            CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), kCTFontHorizontalOrientation, &glyph, &advance, 1);
-        else {
-            float pointSize = platformData().m_size;
-            CGAffineTransform transform = CGAffineTransformMakeScale(pointSize, pointSize);
-            static const CGFontRenderingStyle renderingStyle = kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization | kCGFontAntialiasingStyleUnfiltered;
-            if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &transform, renderingStyle, &glyph, 1, &advance)) {
-                RetainPtr<CFStringRef> fullName = adoptCF(CGFontCopyFullName(platformData().cgFont()));
-                LOG_ERROR("Unable to cache glyph widths for %@ %f", fullName.get(), pointSize);
-                advance.width = 0;
-            }
-        }
-    } else
-        CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), kCTFontVerticalOrientation, &glyph, &advance, 1);
+    return kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization | kCGFontAntialiasingStyleUnfiltered;
+}
 
-    return advance.width + m_syntheticBoldOffset;
+bool SimpleFontData::advanceForColorBitmapFont(Glyph, CGSize&) const
+{
+    return false;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm (167772 => 167773)


--- trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm	2014-04-24 21:12:56 UTC (rev 167772)
+++ trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm	2014-04-24 21:20:54 UTC (rev 167773)
@@ -50,9 +50,15 @@
 #if defined(__has_include) && __has_include(<CoreText/CTFontDescriptorPriv.h>)
 #import <CoreText/CTFontDescriptorPriv.h>
 #endif
-
 extern "C" bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
 
+#if defined(__has_include) && __has_include(<CoreGraphics/CGFontGlyphSupport.h>)
+#import <CoreGraphics/CGFontGlyphSupport.h>
+#endif
+extern "C" bool CGFontGetGlyphAdvancesForStyle(CGFontRef font,
+    const CGAffineTransform *t, CGFontRenderingStyle style,
+    const CGGlyph glyphs[], size_t count, CGSize advances[]);
+
 #if !PLATFORM(IOS)
 @interface NSFont (WebAppKitSecretAPI)
 - (BOOL)_isFakeFixedPitch;
@@ -365,10 +371,39 @@
     return boundingBox;
 }
 
-#if !PLATFORM(IOS)
+#if PLATFORM(MAC)
+inline CGFontRenderingStyle SimpleFontData::renderingStyle() const
+{
+    CGFontRenderingStyle style = kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization;
+    NSFont *font = platformData().font();
+    if (font) {
+        switch ([font renderingMode]) {
+        case NSFontIntegerAdvancementsRenderingMode:
+            style = 0;
+            break;
+        case NSFontAntialiasedIntegerAdvancementsRenderingMode:
+            style = kCGFontRenderingStyleAntialiasing;
+            break;
+        default:
+            break;
+        }
+    }
+    return style;
+}
+
+inline bool SimpleFontData::advanceForColorBitmapFont(Glyph glyph, CGSize& advance) const
+{
+    NSFont *font = platformData().font();
+    if (!font || !platformData().isColorBitmapFont())
+        return false;
+    advance = NSSizeToCGSize([font advancementForGlyph:glyph]);
+    return true;
+}
+#endif
+
 static bool hasCustomTracking(CTFontRef font)
 {
-#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1090
     UNUSED_PARAM(font);
     return false;
 #else
@@ -376,28 +411,50 @@
 #endif
 }
 
+static inline bool isEmoji(const FontPlatformData& platformData)
+{
+#if PLATFORM(IOS)
+    return platformData.m_isEmoji;
+#else
+    UNUSED_PARAM(platformData);
+    return false;
+#endif
+}
+
+inline bool SimpleFontData::canUseFastGlyphAdvanceGetter(Glyph glyph, CGSize& advance, bool& populatedAdvance) const
+{
+    // Fast getter doesn't take custom tracking into account
+    if (hasCustomTracking(platformData().ctFont()))
+        return false;
+    // Fast getter doesn't work for emoji
+    if (isEmoji(platformData()))
+        return false;
+    // ... or for any bitmap fonts in general
+    if (advanceForColorBitmapFont(glyph, advance)) {
+        populatedAdvance = true;
+        return false;
+    }
+    return true;
+}
+
 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
 {
     CGSize advance = CGSizeZero;
     bool horizontal = platformData().orientation() == Horizontal;
-    if ((horizontal || m_isBrokenIdeographFallback) && !hasCustomTracking(m_platformData.ctFont())) {
-        NSFont *font = platformData().font();
-        if (font && platformData().isColorBitmapFont())
-            advance = NSSizeToCGSize([font advancementForGlyph:glyph]);
-        else {
-            float pointSize = platformData().m_size;
-            CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize);
-            if (!wkGetGlyphTransformedAdvances(platformData().cgFont(), font, &m, &glyph, &advance)) {
-                LOG_ERROR("Unable to cache glyph widths for %@ %f", [font displayName], pointSize);
-                advance.width = 0;
-            }
+    bool populatedAdvance = false;
+    if ((horizontal || m_isBrokenIdeographFallback) && canUseFastGlyphAdvanceGetter(glyph, advance, populatedAdvance)) {
+        float pointSize = platformData().m_size;
+        CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize);
+        if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &m, renderingStyle(), &glyph, 1, &advance)) {
+            RetainPtr<CFStringRef> fullName = adoptCF(CGFontCopyFullName(platformData().cgFont()));
+            LOG_ERROR("Unable to cache glyph widths for %@ %f", fullName.get(), pointSize);
+            advance.width = 0;
         }
-    } else
+    } else if (!populatedAdvance)
         CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), horizontal ? kCTFontHorizontalOrientation : kCTFontVerticalOrientation, &glyph, &advance, 1);
 
     return advance.width + m_syntheticBoldOffset;
 }
-#endif // !PLATFORM(IOS)
 
 struct ProviderInfo {
     const UChar* characters;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to