<!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>[200070] trunk</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/200070">200070</a></dd>
<dt>Author</dt> <dd>mmaxfield@apple.com</dd>
<dt>Date</dt> <dd>2016-04-25 20:53:31 -0700 (Mon, 25 Apr 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Cocoa] Guarantee FontPlatformData's m_cgFont is never nullptr
https://bugs.webkit.org/show_bug.cgi?id=156929

Reviewed by Darin Adler.

Source/WebCore:

After some investigation, it turns out that there is no place where it is meaningful
to pass us a null CoreText font. Therefore, the CoreGraphics font is also never null.

We should simply check for these null values at the ingestion site in order to
make the guarantee internally of having non-null values.

* platform/graphics/FontPlatformData.cpp:
(WebCore::FontPlatformData::FontPlatformData): Because the pointer is never null, we
can delete the code which handles that case.
* platform/graphics/FontPlatformData.h:
* platform/graphics/cocoa/FontPlatformDataCocoa.mm: Ditto.
(WebCore::webFallbackFontFamily): Deleted.
(WebCore::FontPlatformData::setFallbackCGFont): Deleted.
* platform/graphics/mac/ComplexTextControllerCoreText.mm:
(WebCore::ComplexTextController::collectComplexTextRunsForCharacters): Asking the
CTRun for its kCTFontAttributeName will always return non-null.
* platform/graphics/mac/FontCustomPlatformData.cpp:
(WebCore::FontCustomPlatformData::fontPlatformData): Once we have a font descriptor,
CTFontCreateWithFontDescriptor() will always return non-null. We check if the font
descriptor is null elsewhere.
* platform/mac/DragImageMac.mm: The fonts in this file are gotten by asking for the
system font, which will always return non-null.
(WebCore::fontFromNSFont):
(WebCore::widthWithFont):
(WebCore::drawAtPoint):
(WebCore::createDragImageForLink):

Source/WebKit/mac:

* Misc/WebKitNSStringExtras.mm:
(-[NSString _web_drawAtPoint:font:textColor:allowingFontSmoothing:]): Drawing
a string with a null font shouldn't do anything.
* Misc/WebStringTruncator.mm: We can't truncate a string if we don't have a font
to use.
(+[WebStringTruncator centerTruncateString:toWidth:]):
(+[WebStringTruncator centerTruncateString:toWidth:withFont:]):
(+[WebStringTruncator rightTruncateString:toWidth:withFont:]):
(+[WebStringTruncator widthOfString:font:]):

Tools:

* TestWebKitAPI/Tests/mac/StringTruncator.mm:
(TestWebKitAPI::TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontPlatformDatacpp">trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFontPlatformDatah">trunk/Source/WebCore/platform/graphics/FontPlatformData.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscocoaFontPlatformDataCocoamm">trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacComplexTextControllerCoreTextmm">trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacFontCustomPlatformDatacpp">trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinFontPlatformDataCGWincpp">trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformmacDragImageMacmm">trunk/Source/WebCore/platform/mac/DragImageMac.mm</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacMiscWebKitNSStringExtrasmm">trunk/Source/WebKit/mac/Misc/WebKitNSStringExtras.mm</a></li>
<li><a href="#trunkSourceWebKitmacMiscWebStringTruncatormm">trunk/Source/WebKit/mac/Misc/WebStringTruncator.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsmacStringTruncatormm">trunk/Tools/TestWebKitAPI/Tests/mac/StringTruncator.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Source/WebCore/ChangeLog        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -1,3 +1,37 @@
</span><ins>+2016-04-25  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        [Cocoa] Guarantee FontPlatformData's m_cgFont is never nullptr
+        https://bugs.webkit.org/show_bug.cgi?id=156929
+
+        Reviewed by Darin Adler.
+
+        After some investigation, it turns out that there is no place where it is meaningful
+        to pass us a null CoreText font. Therefore, the CoreGraphics font is also never null.
+
+        We should simply check for these null values at the ingestion site in order to
+        make the guarantee internally of having non-null values.
+
+        * platform/graphics/FontPlatformData.cpp:
+        (WebCore::FontPlatformData::FontPlatformData): Because the pointer is never null, we
+        can delete the code which handles that case.
+        * platform/graphics/FontPlatformData.h:
+        * platform/graphics/cocoa/FontPlatformDataCocoa.mm: Ditto.
+        (WebCore::webFallbackFontFamily): Deleted.
+        (WebCore::FontPlatformData::setFallbackCGFont): Deleted.
+        * platform/graphics/mac/ComplexTextControllerCoreText.mm:
+        (WebCore::ComplexTextController::collectComplexTextRunsForCharacters): Asking the
+        CTRun for its kCTFontAttributeName will always return non-null.
+        * platform/graphics/mac/FontCustomPlatformData.cpp:
+        (WebCore::FontCustomPlatformData::fontPlatformData): Once we have a font descriptor,
+        CTFontCreateWithFontDescriptor() will always return non-null. We check if the font
+        descriptor is null elsewhere.
+        * platform/mac/DragImageMac.mm: The fonts in this file are gotten by asking for the
+        system font, which will always return non-null.
+        (WebCore::fontFromNSFont):
+        (WebCore::widthWithFont):
+        (WebCore::drawAtPoint):
+        (WebCore::createDragImageForLink):
+
</ins><span class="cx"> 2016-04-25  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Crash under MemoryCache::remove()
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontPlatformDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -58,8 +58,7 @@
</span><span class="cx">     : FontPlatformData(size, syntheticBold, syntheticOblique, orientation, widthVariant, textRenderingMode)
</span><span class="cx"> {
</span><span class="cx">     m_cgFont = cgFont;
</span><del>-    if (!m_cgFont)
-        setFallbackCGFont();
</del><ins>+    ASSERT(m_cgFont);
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFontPlatformDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.h (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FontPlatformData.h        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.h        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -109,7 +109,6 @@
</span><span class="cx"> #elif PLATFORM(COCOA)
</span><span class="cx">     CTFontRef font() const { return m_font.get(); }
</span><span class="cx">     WEBCORE_EXPORT CTFontRef registeredFont() const; // Returns nullptr iff the font is not registered, such as web fonts (otherwise returns font()).
</span><del>-    void setFont(CTFontRef);
</del><span class="cx"> 
</span><span class="cx">     CTFontRef ctFont() const;
</span><span class="cx">     static RetainPtr&lt;CFTypeRef&gt; objectForEqualityCheck(CTFontRef);
</span><span class="lines">@@ -120,7 +119,6 @@
</span><span class="cx"> #if USE(APPKIT)
</span><span class="cx">     // FIXME: Remove this when all NSFont usage is removed.
</span><span class="cx">     NSFont *nsFont() const { return (NSFont *)m_font.get(); }
</span><del>-    void setNSFont(NSFont *font) { setFont(reinterpret_cast&lt;CTFontRef&gt;(font)); }
</del><span class="cx"> #endif
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -216,9 +214,6 @@
</span><span class="cx"> #if PLATFORM(WIN)
</span><span class="cx">     void platformDataInit(HFONT, float size, HDC, WCHAR* faceName);
</span><span class="cx"> #endif
</span><del>-#if USE(CG)
-    void setFallbackCGFont();
-#endif
</del><span class="cx"> 
</span><span class="cx"> public:
</span><span class="cx">     bool m_syntheticBold { false };
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscocoaFontPlatformDataCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -58,77 +58,6 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if USE(APPKIT)
-
-static NSString *webFallbackFontFamily(void)
-{
-    static NSString *webFallbackFontFamily = [[[NSFont systemFontOfSize:16.0f] familyName] retain];
-    return webFallbackFontFamily;
-}
-
-void FontPlatformData::setFallbackCGFont()
-{
-    if (cgFont())
-        return;
-
-    // Ack! Something very bad happened, like a corrupt font.
-    // Try looking for an alternate 'base' font for this renderer.
-
-    // Special case hack to use &quot;Times New Roman&quot; in place of &quot;Times&quot;.
-    // &quot;Times RO&quot; is a common font whose family name is &quot;Times&quot;.
-    // It overrides the normal &quot;Times&quot; family font.
-    // It also appears to have a corrupt regular variant.
-    NSString *fallbackFontFamily;
-    if ([[nsFont() familyName] isEqual:@&quot;Times&quot;])
-        fallbackFontFamily = @&quot;Times New Roman&quot;;
-    else
-        fallbackFontFamily = webFallbackFontFamily();
-
-    // Try setting up the alternate font.
-    // This is a last ditch effort to use a substitute font when something has gone wrong.
-#if !ERROR_DISABLED
-    RetainPtr&lt;NSFont&gt; initialFont = nsFont();
-#endif
-    if (font())
-        setNSFont([[NSFontManager sharedFontManager] convertFont:nsFont() toFamily:fallbackFontFamily]);
-    else
-        setNSFont([NSFont fontWithName:fallbackFontFamily size:size()]);
-
-    if (cgFont())
-        return;
-
-    if ([fallbackFontFamily isEqual:@&quot;Times New Roman&quot;]) {
-        // OK, couldn't setup Times New Roman as an alternate to Times, fallback
-        // on the system font. If this fails we have no alternative left.
-        setNSFont([[NSFontManager sharedFontManager] convertFont:nsFont() toFamily:webFallbackFontFamily()]);
-        if (cgFont())
-            return;
-
-        // We tried, Times, Times New Roman, and the system font. No joy. We have to give up.
-        LOG_ERROR(&quot;unable to initialize with font %@&quot;, initialFont.get());
-    } else {
-        // We tried the requested font and the system font. No joy. We have to give up.
-        LOG_ERROR(&quot;unable to initialize with font %@&quot;, initialFont.get());
-    }
-
-    // Report the problem.
-    LOG_ERROR(&quot;Corrupt font detected, using %@ in place of %@.&quot;, [nsFont() familyName], [initialFont.get() familyName]);
-
-    // If all else fails, try to set up using the system font.
-    // This is probably because Times and Times New Roman are both unavailable.
-    ASSERT(!cgFont());
-    setNSFont([NSFont systemFontOfSize:[nsFont() pointSize]]);
-    LOG_ERROR(&quot;failed to set up font, using system font %s&quot;, font());
-}
-
-#else
-
-void FontPlatformData::setFallbackCGFont()
-{
-}
-
-#endif
-
</del><span class="cx"> void FontPlatformData::platformDataInit(const FontPlatformData&amp; f)
</span><span class="cx"> {
</span><span class="cx">     m_font = f.m_font;
</span><span class="lines">@@ -179,28 +108,6 @@
</span><span class="cx">     return nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void FontPlatformData::setFont(CTFontRef font)
-{
-    ASSERT_ARG(font, font);
-
-    if (m_font == font)
-        return;
-
-    m_font = font;
-    m_size = CTFontGetSize(font);
-    m_cgFont = adoptCF(CTFontCopyGraphicsFont(font, nullptr));
-
-    CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(m_font.get());
-    m_isColorBitmapFont = traits &amp; kCTFontTraitColorGlyphs;
-    m_isSystemFont = CTFontDescriptorIsSystemUIFont(adoptCF(CTFontCopyFontDescriptor(m_font.get())).get());
-
-#if PLATFORM(IOS)
-    m_isEmoji = CTFontIsAppleColorEmoji(m_font.get());
-#endif
-    
-    m_ctFont = nullptr;
-}
-
</del><span class="cx"> inline int mapFontWidthVariantToCTFeatureSelector(FontWidthVariant variant)
</span><span class="cx"> {
</span><span class="cx">     switch(variant) {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacComplexTextControllerCoreTextmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -262,7 +262,7 @@
</span><span class="cx">         if (isSystemFallback) {
</span><span class="cx">             CFDictionaryRef runAttributes = CTRunGetAttributes(ctRun);
</span><span class="cx">             CTFontRef runCTFont = static_cast&lt;CTFontRef&gt;(CFDictionaryGetValue(runAttributes, kCTFontAttributeName));
</span><del>-            ASSERT(CFGetTypeID(runCTFont) == CTFontGetTypeID());
</del><ins>+            ASSERT(runCTFont &amp;&amp; CFGetTypeID(runCTFont) == CTFontGetTypeID());
</ins><span class="cx">             RetainPtr&lt;CFTypeRef&gt; runFontEqualityObject = FontPlatformData::objectForEqualityCheck(runCTFont);
</span><span class="cx">             if (!safeCFEqual(runFontEqualityObject.get(), font-&gt;platformData().objectForEqualityCheck().get())) {
</span><span class="cx">                 // Begin trying to see if runFont matches any of the fonts in the fallback list.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacFontCustomPlatformDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -41,6 +41,7 @@
</span><span class="cx">     FontWidthVariant widthVariant = fontDescription.widthVariant();
</span><span class="cx">     RetainPtr&lt;CTFontRef&gt; font = adoptCF(CTFontCreateWithFontDescriptor(m_fontDescriptor.get(), size, nullptr));
</span><span class="cx">     font = preparePlatformFont(font.get(), fontDescription.textRenderingMode(), &amp;fontFaceFeatures, &amp;fontFaceVariantSettings, fontDescription.featureSettings(), fontDescription.variantSettings());
</span><ins>+    ASSERT(font);
</ins><span class="cx">     return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant, fontDescription.textRenderingMode());
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinFontPlatformDataCGWincpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -157,8 +157,4 @@
</span><span class="cx">         &amp;&amp; m_useGDI == other.m_useGDI;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void FontPlatformData::setFallbackCGFont()
-{
</del><span class="cx"> }
</span><del>-
-}
</del></span></pre></div>
<a id="trunkSourceWebCoreplatformmacDragImageMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/DragImageMac.mm (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/DragImageMac.mm        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Source/WebCore/platform/mac/DragImageMac.mm        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -166,6 +166,7 @@
</span><span class="cx">     
</span><span class="cx"> static FontCascade&amp; fontFromNSFont(NSFont *font)
</span><span class="cx"> {
</span><ins>+    ASSERT(font);
</ins><span class="cx">     static NSFont *currentFont;
</span><span class="cx">     static NeverDestroyed&lt;FontCascade&gt; currentRenderer;
</span><span class="cx">     
</span><span class="lines">@@ -192,6 +193,9 @@
</span><span class="cx">     
</span><span class="cx"> static float widthWithFont(NSString *string, NSFont *font)
</span><span class="cx"> {
</span><ins>+    if (!font)
+        return 0;
+
</ins><span class="cx">     unsigned length = [string length];
</span><span class="cx">     Vector&lt;UniChar, 2048&gt; buffer(length);
</span><span class="cx">     
</span><span class="lines">@@ -208,6 +212,9 @@
</span><span class="cx">     
</span><span class="cx"> static void drawAtPoint(NSString *string, NSPoint point, NSFont *font, NSColor *textColor)
</span><span class="cx"> {
</span><ins>+    if (!font)
+        return;
+
</ins><span class="cx">     unsigned length = [string length];
</span><span class="cx">     Vector&lt;UniChar, 2048&gt; buffer(length);
</span><span class="cx">     
</span><span class="lines">@@ -228,7 +235,7 @@
</span><span class="cx">         BOOL flipped = [nsContext isFlipped];
</span><span class="cx">         if (!flipped)
</span><span class="cx">             CGContextScaleCTM(cgContext, 1, -1);
</span><del>-            
</del><ins>+
</ins><span class="cx">         FontCascade webCoreFont(FontPlatformData(toCTFont(font), [font pointSize]), Antialiased);
</span><span class="cx">         TextRun run(StringView(buffer.data(), length));
</span><span class="cx"> 
</span><span class="lines">@@ -281,6 +288,10 @@
</span><span class="cx">     NSFont *labelFont = [[NSFontManager sharedFontManager] convertFont:[NSFont systemFontOfSize:DragLinkLabelFontsize]
</span><span class="cx">                                                            toHaveTrait:NSBoldFontMask];
</span><span class="cx">     NSFont *urlFont = [NSFont systemFontOfSize:DragLinkUrlFontSize];
</span><ins>+
+    ASSERT(labelFont);
+    ASSERT(urlFont);
+
</ins><span class="cx">     NSSize labelSize;
</span><span class="cx">     labelSize.width = widthWithFont(label, labelFont);
</span><span class="cx">     labelSize.height = [labelFont ascender] - [labelFont descender];
</span><span class="lines">@@ -322,16 +333,18 @@
</span><span class="cx"> 
</span><span class="cx">     NSColor *topColor = [NSColor colorWithDeviceWhite:0.0f alpha:0.75f];
</span><span class="cx">     NSColor *bottomColor = [NSColor colorWithDeviceWhite:1.0f alpha:0.5f];
</span><del>-    if (drawURLString) {
</del><ins>+    if (drawURLString &amp;&amp; urlFont) {
</ins><span class="cx">         if (clipURLString)
</span><span class="cx">             urlString = StringTruncator::centerTruncate(urlString, imageSize.width - (DragLabelBorderX * 2), fontFromNSFont(urlFont));
</span><span class="cx"> 
</span><span class="cx">        drawDoubledAtPoint(urlString, NSMakePoint(DragLabelBorderX, DragLabelBorderY - [urlFont descender]), topColor, bottomColor, urlFont);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (clipLabelString)
-        label = StringTruncator::rightTruncate(label, imageSize.width - (DragLabelBorderX * 2), fontFromNSFont(labelFont));
-    drawDoubledAtPoint(label, NSMakePoint(DragLabelBorderX, imageSize.height - LabelBorderYOffset - [labelFont pointSize]), topColor, bottomColor, labelFont);
</del><ins>+    if (labelFont) {
+        if (clipLabelString)
+            label = StringTruncator::rightTruncate(label, imageSize.width - (DragLabelBorderX * 2), fontFromNSFont(labelFont));
+        drawDoubledAtPoint(label, NSMakePoint(DragLabelBorderX, imageSize.height - LabelBorderYOffset - [labelFont pointSize]), topColor, bottomColor, labelFont);
+    }
</ins><span class="cx"> 
</span><span class="cx">     [dragImage unlockFocus];
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Source/WebKit/mac/ChangeLog        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2016-04-25  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        [Cocoa] Guarantee FontPlatformData's m_cgFont is never nullptr
+        https://bugs.webkit.org/show_bug.cgi?id=156929
+
+        Reviewed by Darin Adler.
+
+        * Misc/WebKitNSStringExtras.mm:
+        (-[NSString _web_drawAtPoint:font:textColor:allowingFontSmoothing:]): Drawing
+        a string with a null font shouldn't do anything.
+        * Misc/WebStringTruncator.mm: We can't truncate a string if we don't have a font
+        to use.
+        (+[WebStringTruncator centerTruncateString:toWidth:]):
+        (+[WebStringTruncator centerTruncateString:toWidth:withFont:]):
+        (+[WebStringTruncator rightTruncateString:toWidth:withFont:]):
+        (+[WebStringTruncator widthOfString:font:]):
+
</ins><span class="cx"> 2016-04-25  Beth Dakin  &lt;bdakin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         WebEditorClient should properly write to m_rangeForCandidates
</span></span></pre></div>
<a id="trunkSourceWebKitmacMiscWebKitNSStringExtrasmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/Misc/WebKitNSStringExtras.mm (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/Misc/WebKitNSStringExtras.mm        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Source/WebKit/mac/Misc/WebKitNSStringExtras.mm        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -71,6 +71,9 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)_web_drawAtPoint:(NSPoint)point font:(NSFont *)font textColor:(NSColor *)textColor allowingFontSmoothing:(BOOL)fontSmoothingIsAllowed
</span><span class="cx"> {
</span><ins>+    if (!font)
+        return;
+
</ins><span class="cx">     unsigned length = [self length];
</span><span class="cx">     Vector&lt;UniChar, 2048&gt; buffer(length);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitmacMiscWebStringTruncatormm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/Misc/WebStringTruncator.mm (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/Misc/WebStringTruncator.mm        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Source/WebKit/mac/Misc/WebStringTruncator.mm        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -59,21 +59,35 @@
</span><span class="cx"> + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth
</span><span class="cx"> {
</span><span class="cx">     static NeverDestroyed&lt;RetainPtr&lt;NSFont&gt;&gt; menuFont = [NSFont menuFontOfSize:0];
</span><ins>+
+    ASSERT(menuFont.get());
+    if (!menuFont.get())
+        return nil;
+
</ins><span class="cx">     return WebCore::StringTruncator::centerTruncate(string, maxWidth, fontFromNSFont(menuFont.get().get()));
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font
</span><span class="cx"> {
</span><ins>+    if (!font)
+        return nil;
+
</ins><span class="cx">     return WebCore::StringTruncator::centerTruncate(string, maxWidth, fontFromNSFont(font));
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> + (NSString *)rightTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font
</span><span class="cx"> {
</span><ins>+    if (!font)
+        return nil;
+
</ins><span class="cx">     return WebCore::StringTruncator::rightTruncate(string, maxWidth, fontFromNSFont(font));
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> + (float)widthOfString:(NSString *)string font:(NSFont *)font
</span><span class="cx"> {
</span><ins>+    if (!font)
+        return 0;
+
</ins><span class="cx">     return WebCore::StringTruncator::width(string, fontFromNSFont(font));
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Tools/ChangeLog        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-04-25  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        [Cocoa] Guarantee FontPlatformData's m_cgFont is never nullptr
+        https://bugs.webkit.org/show_bug.cgi?id=156929
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/mac/StringTruncator.mm:
+        (TestWebKitAPI::TEST):
+
</ins><span class="cx"> 2016-04-25  Caitlin Potter  &lt;caitp@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Tools] whitelist all-uppercase JSTokenType enum in JavaScriptCore
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsmacStringTruncatormm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/mac/StringTruncator.mm (200069 => 200070)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/mac/StringTruncator.mm        2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/StringTruncator.mm        2016-04-26 03:53:31 UTC (rev 200070)
</span><span class="lines">@@ -33,15 +33,18 @@
</span><span class="cx"> TEST(WebKit1, StringTruncator)
</span><span class="cx"> {
</span><span class="cx">     @autoreleasepool {
</span><ins>+        EXPECT_EQ(nil, [WebStringTruncator centerTruncateString:@&quot;abcdefghijklmnopqrstuvwxyz&quot; toWidth:100 withFont:nil]);
</ins><span class="cx">         EXPECT_STREQ([[WebStringTruncator centerTruncateString:@&quot;abcdefghijklmnopqrstuvwxyz&quot; toWidth:100 withFont:[NSFont fontWithName:@&quot;Helvetica&quot; size:12]] UTF8String], &quot;abcdefg…tuvwxyz&quot;);
</span><span class="cx"> #if __MAC_OS_X_VERSION_MIN_REQUIRED &gt; 101000
</span><span class="cx">         EXPECT_STREQ([[WebStringTruncator centerTruncateString:@&quot;abcdefghijklmnopqrstuvwxyz&quot; toWidth:100] UTF8String], &quot;abcdef…uvwxyz&quot;);
</span><span class="cx"> #else
</span><span class="cx">         EXPECT_STREQ([[WebStringTruncator centerTruncateString:@&quot;abcdefghijklmnopqrstuvwxyz&quot; toWidth:100] UTF8String], &quot;abcdef…vwxyz&quot;);
</span><span class="cx"> #endif
</span><ins>+        EXPECT_EQ(nil, [WebStringTruncator rightTruncateString:@&quot;abcdefghijklmnopqrstuvwxyz&quot; toWidth:100 withFont:nil]);
</ins><span class="cx">         EXPECT_STREQ([[WebStringTruncator rightTruncateString:@&quot;abcdefghijklmnopqrstuvwxyz&quot; toWidth:100 withFont:[NSFont fontWithName:@&quot;Helvetica&quot; size:12]] UTF8String], &quot;abcdefghijklmno…&quot;);
</span><span class="cx">         EXPECT_STREQ([[WebStringTruncator centerTruncateString:@&quot;ābcdefghijklmnopqrstuvwxyz&quot; toWidth:100 withFont:[NSFont fontWithName:@&quot;Helvetica&quot; size:12]] UTF8String], &quot;ābcdefg…tuvwxyz&quot;);
</span><span class="cx">         EXPECT_STREQ([[WebStringTruncator rightTruncateString:@&quot;ābcdefghijklmnopqrstuvwxyz&quot; toWidth:100 withFont:[NSFont fontWithName:@&quot;Helvetica&quot; size:12]] UTF8String], &quot;ābcdefghijklmno…&quot;);
</span><ins>+        EXPECT_EQ([WebStringTruncator widthOfString:@&quot;abcdefghijklmnopqrstuvwxyz&quot; font:nil], 0);
</ins><span class="cx">         EXPECT_EQ([WebStringTruncator widthOfString:@&quot;abcdefghijklmnopqrstuvwxyz&quot; font:[NSFont fontWithName:@&quot;Helvetica&quot; size:12]], 152.736328125);
</span><span class="cx">         EXPECT_EQ([WebStringTruncator widthOfString:@&quot;ābcdefghijklmnopqrstuvwxyz&quot; font:[NSFont fontWithName:@&quot;Helvetica&quot; size:12]], 152.736328125);
</span><span class="cx">     }
</span></span></pre>
</div>
</div>

</body>
</html>