<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[167773] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/167773">167773</a></dd>
<dt>Author</dt> <dd>mmaxfield@apple.com</dd>
<dt>Date</dt> <dd>2014-04-24 14:20:54 -0700 (Thu, 24 Apr 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>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.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsSimpleFontDatah">trunk/Source/WebCore/platform/graphics/SimpleFontData.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsiosSimpleFontDataIOSmm">trunk/Source/WebCore/platform/graphics/ios/SimpleFontDataIOS.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacSimpleFontDataMacmm">trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (167772 => 167773)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2014-04-24 Myles C. Maxfield <mmaxfield@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.
+
</ins><span class="cx"> 2014-04-24 Zalan Bujtas <zalan@apple.com>
</span><span class="cx">
</span><span class="cx"> Subpixel rendering: Clipping on text areas when shifted by one device pixel.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsSimpleFontDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/SimpleFontData.h (167772 => 167773)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -54,6 +54,22 @@
</span><span class="cx"> #include <cairo.h>
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#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
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="cx"> class FontDescription;
</span><span class="lines">@@ -245,6 +261,12 @@
</span><span class="cx"> float widthForGDIGlyph(Glyph glyph) const;
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#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
+
</ins><span class="cx"> FontMetrics m_fontMetrics;
</span><span class="cx"> float m_maxCharWidth;
</span><span class="cx"> float m_avgCharWidth;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsiosSimpleFontDataIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/ios/SimpleFontDataIOS.mm (167772 => 167773)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -32,9 +32,7 @@
</span><span class="cx"> #import "FontCache.h"
</span><span class="cx"> #import "FontDescription.h"
</span><span class="cx"> #import "FontServicesIOS.h"
</span><del>-#import <CoreGraphics/CGFontGlyphSupport.h>
</del><span class="cx"> #import <CoreGraphics/CGFontInfo.h>
</span><del>-#import <CoreGraphics/CGFontRendering.h>
</del><span class="cx"> #import <CoreText/CoreText.h>
</span><span class="cx"> #import <float.h>
</span><span class="cx"> #import <unicode/uchar.h>
</span><span class="lines">@@ -187,26 +185,14 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
</del><ins>+CGFontRenderingStyle SimpleFontData::renderingStyle() const
</ins><span class="cx"> {
</span><del>- 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);
</del><ins>+ return kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization | kCGFontAntialiasingStyleUnfiltered;
+}
</ins><span class="cx">
</span><del>- return advance.width + m_syntheticBoldOffset;
</del><ins>+bool SimpleFontData::advanceForColorBitmapFont(Glyph, CGSize&) const
+{
+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacSimpleFontDataMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm (167772 => 167773)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -50,9 +50,15 @@
</span><span class="cx"> #if defined(__has_include) && __has_include(<CoreText/CTFontDescriptorPriv.h>)
</span><span class="cx"> #import <CoreText/CTFontDescriptorPriv.h>
</span><span class="cx"> #endif
</span><del>-
</del><span class="cx"> extern "C" bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
</span><span class="cx">
</span><ins>+#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[]);
+
</ins><span class="cx"> #if !PLATFORM(IOS)
</span><span class="cx"> @interface NSFont (WebAppKitSecretAPI)
</span><span class="cx"> - (BOOL)_isFakeFixedPitch;
</span><span class="lines">@@ -365,10 +371,39 @@
</span><span class="cx"> return boundingBox;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#if !PLATFORM(IOS)
</del><ins>+#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
+
</ins><span class="cx"> static bool hasCustomTracking(CTFontRef font)
</span><span class="cx"> {
</span><del>-#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1090
</del><ins>+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1090
</ins><span class="cx"> UNUSED_PARAM(font);
</span><span class="cx"> return false;
</span><span class="cx"> #else
</span><span class="lines">@@ -376,28 +411,50 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+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;
+}
+
</ins><span class="cx"> float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
</span><span class="cx"> {
</span><span class="cx"> CGSize advance = CGSizeZero;
</span><span class="cx"> bool horizontal = platformData().orientation() == Horizontal;
</span><del>- 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;
- }
</del><ins>+ 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;
</ins><span class="cx"> }
</span><del>- } else
</del><ins>+ } else if (!populatedAdvance)
</ins><span class="cx"> CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), horizontal ? kCTFontHorizontalOrientation : kCTFontVerticalOrientation, &glyph, &advance, 1);
</span><span class="cx">
</span><span class="cx"> return advance.width + m_syntheticBoldOffset;
</span><span class="cx"> }
</span><del>-#endif // !PLATFORM(IOS)
</del><span class="cx">
</span><span class="cx"> struct ProviderInfo {
</span><span class="cx"> const UChar* characters;
</span></span></pre>
</div>
</div>
</body>
</html>