Diff
Modified: trunk/Source/WebCore/ChangeLog (200069 => 200070)
--- 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)
@@ -1,3 +1,37 @@
+2016-04-25 Myles C. Maxfield <[email protected]>
+
+ [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):
+
2016-04-25 Chris Dumez <[email protected]>
Crash under MemoryCache::remove()
Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp (200069 => 200070)
--- 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)
@@ -58,8 +58,7 @@
: FontPlatformData(size, syntheticBold, syntheticOblique, orientation, widthVariant, textRenderingMode)
{
m_cgFont = cgFont;
- if (!m_cgFont)
- setFallbackCGFont();
+ ASSERT(m_cgFont);
}
#endif
Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.h (200069 => 200070)
--- 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)
@@ -109,7 +109,6 @@
#elif PLATFORM(COCOA)
CTFontRef font() const { return m_font.get(); }
WEBCORE_EXPORT CTFontRef registeredFont() const; // Returns nullptr iff the font is not registered, such as web fonts (otherwise returns font()).
- void setFont(CTFontRef);
CTFontRef ctFont() const;
static RetainPtr<CFTypeRef> objectForEqualityCheck(CTFontRef);
@@ -120,7 +119,6 @@
#if USE(APPKIT)
// FIXME: Remove this when all NSFont usage is removed.
NSFont *nsFont() const { return (NSFont *)m_font.get(); }
- void setNSFont(NSFont *font) { setFont(reinterpret_cast<CTFontRef>(font)); }
#endif
#endif
@@ -216,9 +214,6 @@
#if PLATFORM(WIN)
void platformDataInit(HFONT, float size, HDC, WCHAR* faceName);
#endif
-#if USE(CG)
- void setFallbackCGFont();
-#endif
public:
bool m_syntheticBold { false };
Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm (200069 => 200070)
--- 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)
@@ -58,77 +58,6 @@
{
}
-#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 "Times New Roman" in place of "Times".
- // "Times RO" is a common font whose family name is "Times".
- // It overrides the normal "Times" family font.
- // It also appears to have a corrupt regular variant.
- NSString *fallbackFontFamily;
- if ([[nsFont() familyName] isEqual:@"Times"])
- fallbackFontFamily = @"Times New Roman";
- 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<NSFont> 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:@"Times New Roman"]) {
- // 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("unable to initialize with font %@", initialFont.get());
- } else {
- // We tried the requested font and the system font. No joy. We have to give up.
- LOG_ERROR("unable to initialize with font %@", initialFont.get());
- }
-
- // Report the problem.
- LOG_ERROR("Corrupt font detected, using %@ in place of %@.", [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("failed to set up font, using system font %s", font());
-}
-
-#else
-
-void FontPlatformData::setFallbackCGFont()
-{
-}
-
-#endif
-
void FontPlatformData::platformDataInit(const FontPlatformData& f)
{
m_font = f.m_font;
@@ -179,28 +108,6 @@
return nullptr;
}
-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 & kCTFontTraitColorGlyphs;
- m_isSystemFont = CTFontDescriptorIsSystemUIFont(adoptCF(CTFontCopyFontDescriptor(m_font.get())).get());
-
-#if PLATFORM(IOS)
- m_isEmoji = CTFontIsAppleColorEmoji(m_font.get());
-#endif
-
- m_ctFont = nullptr;
-}
-
inline int mapFontWidthVariantToCTFeatureSelector(FontWidthVariant variant)
{
switch(variant) {
Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm (200069 => 200070)
--- 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)
@@ -262,7 +262,7 @@
if (isSystemFallback) {
CFDictionaryRef runAttributes = CTRunGetAttributes(ctRun);
CTFontRef runCTFont = static_cast<CTFontRef>(CFDictionaryGetValue(runAttributes, kCTFontAttributeName));
- ASSERT(CFGetTypeID(runCTFont) == CTFontGetTypeID());
+ ASSERT(runCTFont && CFGetTypeID(runCTFont) == CTFontGetTypeID());
RetainPtr<CFTypeRef> runFontEqualityObject = FontPlatformData::objectForEqualityCheck(runCTFont);
if (!safeCFEqual(runFontEqualityObject.get(), font->platformData().objectForEqualityCheck().get())) {
// Begin trying to see if runFont matches any of the fonts in the fallback list.
Modified: trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp (200069 => 200070)
--- 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)
@@ -41,6 +41,7 @@
FontWidthVariant widthVariant = fontDescription.widthVariant();
RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(m_fontDescriptor.get(), size, nullptr));
font = preparePlatformFont(font.get(), fontDescription.textRenderingMode(), &fontFaceFeatures, &fontFaceVariantSettings, fontDescription.featureSettings(), fontDescription.variantSettings());
+ ASSERT(font);
return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant, fontDescription.textRenderingMode());
}
Modified: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp (200069 => 200070)
--- 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)
@@ -157,8 +157,4 @@
&& m_useGDI == other.m_useGDI;
}
-void FontPlatformData::setFallbackCGFont()
-{
}
-
-}
Modified: trunk/Source/WebCore/platform/mac/DragImageMac.mm (200069 => 200070)
--- 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)
@@ -166,6 +166,7 @@
static FontCascade& fontFromNSFont(NSFont *font)
{
+ ASSERT(font);
static NSFont *currentFont;
static NeverDestroyed<FontCascade> currentRenderer;
@@ -192,6 +193,9 @@
static float widthWithFont(NSString *string, NSFont *font)
{
+ if (!font)
+ return 0;
+
unsigned length = [string length];
Vector<UniChar, 2048> buffer(length);
@@ -208,6 +212,9 @@
static void drawAtPoint(NSString *string, NSPoint point, NSFont *font, NSColor *textColor)
{
+ if (!font)
+ return;
+
unsigned length = [string length];
Vector<UniChar, 2048> buffer(length);
@@ -228,7 +235,7 @@
BOOL flipped = [nsContext isFlipped];
if (!flipped)
CGContextScaleCTM(cgContext, 1, -1);
-
+
FontCascade webCoreFont(FontPlatformData(toCTFont(font), [font pointSize]), Antialiased);
TextRun run(StringView(buffer.data(), length));
@@ -281,6 +288,10 @@
NSFont *labelFont = [[NSFontManager sharedFontManager] convertFont:[NSFont systemFontOfSize:DragLinkLabelFontsize]
toHaveTrait:NSBoldFontMask];
NSFont *urlFont = [NSFont systemFontOfSize:DragLinkUrlFontSize];
+
+ ASSERT(labelFont);
+ ASSERT(urlFont);
+
NSSize labelSize;
labelSize.width = widthWithFont(label, labelFont);
labelSize.height = [labelFont ascender] - [labelFont descender];
@@ -322,16 +333,18 @@
NSColor *topColor = [NSColor colorWithDeviceWhite:0.0f alpha:0.75f];
NSColor *bottomColor = [NSColor colorWithDeviceWhite:1.0f alpha:0.5f];
- if (drawURLString) {
+ if (drawURLString && urlFont) {
if (clipURLString)
urlString = StringTruncator::centerTruncate(urlString, imageSize.width - (DragLabelBorderX * 2), fontFromNSFont(urlFont));
drawDoubledAtPoint(urlString, NSMakePoint(DragLabelBorderX, DragLabelBorderY - [urlFont descender]), topColor, bottomColor, urlFont);
}
- if (clipLabelString)
- label = StringTruncator::rightTruncate(label, imageSize.width - (DragLabelBorderX * 2), fontFromNSFont(labelFont));
- drawDoubledAtPoint(label, NSMakePoint(DragLabelBorderX, imageSize.height - LabelBorderYOffset - [labelFont pointSize]), topColor, bottomColor, labelFont);
+ 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);
+ }
[dragImage unlockFocus];
Modified: trunk/Source/WebKit/mac/ChangeLog (200069 => 200070)
--- 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)
@@ -1,3 +1,20 @@
+2016-04-25 Myles C. Maxfield <[email protected]>
+
+ [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:]):
+
2016-04-25 Beth Dakin <[email protected]>
WebEditorClient should properly write to m_rangeForCandidates
Modified: trunk/Source/WebKit/mac/Misc/WebKitNSStringExtras.mm (200069 => 200070)
--- 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)
@@ -71,6 +71,9 @@
- (void)_web_drawAtPoint:(NSPoint)point font:(NSFont *)font textColor:(NSColor *)textColor allowingFontSmoothing:(BOOL)fontSmoothingIsAllowed
{
+ if (!font)
+ return;
+
unsigned length = [self length];
Vector<UniChar, 2048> buffer(length);
Modified: trunk/Source/WebKit/mac/Misc/WebStringTruncator.mm (200069 => 200070)
--- 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)
@@ -59,21 +59,35 @@
+ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth
{
static NeverDestroyed<RetainPtr<NSFont>> menuFont = [NSFont menuFontOfSize:0];
+
+ ASSERT(menuFont.get());
+ if (!menuFont.get())
+ return nil;
+
return WebCore::StringTruncator::centerTruncate(string, maxWidth, fontFromNSFont(menuFont.get().get()));
}
+ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font
{
+ if (!font)
+ return nil;
+
return WebCore::StringTruncator::centerTruncate(string, maxWidth, fontFromNSFont(font));
}
+ (NSString *)rightTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font
{
+ if (!font)
+ return nil;
+
return WebCore::StringTruncator::rightTruncate(string, maxWidth, fontFromNSFont(font));
}
+ (float)widthOfString:(NSString *)string font:(NSFont *)font
{
+ if (!font)
+ return 0;
+
return WebCore::StringTruncator::width(string, fontFromNSFont(font));
}
Modified: trunk/Tools/ChangeLog (200069 => 200070)
--- trunk/Tools/ChangeLog 2016-04-26 03:52:08 UTC (rev 200069)
+++ trunk/Tools/ChangeLog 2016-04-26 03:53:31 UTC (rev 200070)
@@ -1,3 +1,13 @@
+2016-04-25 Myles C. Maxfield <[email protected]>
+
+ [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):
+
2016-04-25 Caitlin Potter <[email protected]>
[Tools] whitelist all-uppercase JSTokenType enum in _javascript_Core
Modified: trunk/Tools/TestWebKitAPI/Tests/mac/StringTruncator.mm (200069 => 200070)
--- 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)
@@ -33,15 +33,18 @@
TEST(WebKit1, StringTruncator)
{
@autoreleasepool {
+ EXPECT_EQ(nil, [WebStringTruncator centerTruncateString:@"abcdefghijklmnopqrstuvwxyz" toWidth:100 withFont:nil]);
EXPECT_STREQ([[WebStringTruncator centerTruncateString:@"abcdefghijklmnopqrstuvwxyz" toWidth:100 withFont:[NSFont fontWithName:@"Helvetica" size:12]] UTF8String], "abcdefg…tuvwxyz");
#if __MAC_OS_X_VERSION_MIN_REQUIRED > 101000
EXPECT_STREQ([[WebStringTruncator centerTruncateString:@"abcdefghijklmnopqrstuvwxyz" toWidth:100] UTF8String], "abcdef…uvwxyz");
#else
EXPECT_STREQ([[WebStringTruncator centerTruncateString:@"abcdefghijklmnopqrstuvwxyz" toWidth:100] UTF8String], "abcdef…vwxyz");
#endif
+ EXPECT_EQ(nil, [WebStringTruncator rightTruncateString:@"abcdefghijklmnopqrstuvwxyz" toWidth:100 withFont:nil]);
EXPECT_STREQ([[WebStringTruncator rightTruncateString:@"abcdefghijklmnopqrstuvwxyz" toWidth:100 withFont:[NSFont fontWithName:@"Helvetica" size:12]] UTF8String], "abcdefghijklmno…");
EXPECT_STREQ([[WebStringTruncator centerTruncateString:@"ābcdefghijklmnopqrstuvwxyz" toWidth:100 withFont:[NSFont fontWithName:@"Helvetica" size:12]] UTF8String], "ābcdefg…tuvwxyz");
EXPECT_STREQ([[WebStringTruncator rightTruncateString:@"ābcdefghijklmnopqrstuvwxyz" toWidth:100 withFont:[NSFont fontWithName:@"Helvetica" size:12]] UTF8String], "ābcdefghijklmno…");
+ EXPECT_EQ([WebStringTruncator widthOfString:@"abcdefghijklmnopqrstuvwxyz" font:nil], 0);
EXPECT_EQ([WebStringTruncator widthOfString:@"abcdefghijklmnopqrstuvwxyz" font:[NSFont fontWithName:@"Helvetica" size:12]], 152.736328125);
EXPECT_EQ([WebStringTruncator widthOfString:@"ābcdefghijklmnopqrstuvwxyz" font:[NSFont fontWithName:@"Helvetica" size:12]], 152.736328125);
}