Diff
Modified: trunk/Source/WebCore/ChangeLog (183268 => 183269)
--- trunk/Source/WebCore/ChangeLog 2015-04-24 18:02:30 UTC (rev 183268)
+++ trunk/Source/WebCore/ChangeLog 2015-04-24 18:12:31 UTC (rev 183269)
@@ -1,3 +1,53 @@
+2015-04-24 Myles C. Maxfield <[email protected]>
+
+ [Cocoa] Start cleaning up FontPlatformData
+ https://bugs.webkit.org/show_bug.cgi?id=144133
+
+ Reviewed by Enrica Casucci.
+
+ This is the start of a crusade to ultimately remove one of the CTFontRefs which we have inside
+ FontPlatformData. This patch starts this effort out by removing the FontPlatformData
+ constructor which accepts an NSFont. This constructor simply casts the NSFont to a CTFontRef,
+ and forwards to another constructor. This patch moves this cast to callers of this constructor,
+ thereby enumerating the places we have left that use NSFont with FontPlatformData.
+
+ This patch also cleans up two of the constructors in FontPlatformData.cpp to forward on to
+ a common constructor.
+
+ This patch also collects places inside FontPlatformDataCocoa.mm where we check if a pointer is
+ not 0 and not -1, and puts this common code inside a new function,
+ FontPlatformData::isValidCTFontRef().
+
+ No new tests because there is no behavior change.
+
+ * platform/graphics/FontPlatformData.cpp:
+ (WebCore::FontPlatformData::FontPlatformData): Coalesce constructors.
+ * platform/graphics/FontPlatformData.h:
+ (WebCore::FontPlatformData::isValidCTFontRef): Check if a pointer is not 0 and not -1.
+ (WebCore::FontPlatformData::hashTableDeletedFontValue): Deleted.
+ * platform/graphics/cocoa/FontCocoa.mm:
+ (WebCore::Font::platformCreateScaledFont): Receive cast which has been hoisted from the deleted
+ FontPlatformData constructor.
+ (WebCore::Font::compositeFontReferenceFont): Ditto.
+ * platform/graphics/cocoa/FontPlatformDataCocoa.mm:
+ (WebCore::FontPlatformData::~FontPlatformData): Use isValidCTFontRef().
+ (WebCore::FontPlatformData::platformDataInit): Ditto.
+ (WebCore::FontPlatformData::platformDataAssign): Ditto.
+ (WebCore::FontPlatformData::platformIsEqual): Simplify preprocessor macros.
+ (WebCore::FontPlatformData::allowsLigatures): Remove unnecessary NSFont use.
+ (WebCore::FontPlatformData::FontPlatformData): Deleted.
+ * platform/graphics/mac/ComplexTextControllerCoreText.mm:
+ (WebCore::ComplexTextController::collectComplexTextRunsForCharacters): Remove unnecessary
+ NSFont use.
+ * platform/graphics/mac/FontCacheMac.mm:
+ (WebCore::FontCache::systemFallbackForCharacters): Receive cast which has been hoisted from the
+ deleted FontPlatformData constructor.
+ (WebCore::FontCache::createFontPlatformData): Ditto.
+ * platform/mac/DragImageMac.mm:
+ (WebCore::fontFromNSFont): Ditto.
+ (WebCore::widthWithFont): Ditto.
+ (WebCore::drawAtPoint): Ditto.
+
2015-04-24 Doug Russell <[email protected]>
AX: richer text change notifications (142719)
Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp (183268 => 183269)
--- trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp 2015-04-24 18:02:30 UTC (rev 183268)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp 2015-04-24 18:12:31 UTC (rev 183269)
@@ -61,25 +61,17 @@
#if USE(CG)
FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant)
- : m_syntheticBold(syntheticBold)
- , m_syntheticOblique(syntheticOblique)
- , m_orientation(orientation)
- , m_size(size)
- , m_widthVariant(widthVariant)
- , m_cgFont(cgFont)
+ : FontPlatformData(size, syntheticBold, syntheticOblique, orientation, widthVariant)
{
+ m_cgFont = cgFont;
}
#endif
FontPlatformData::FontPlatformData(const FontPlatformData& source)
- : m_syntheticBold(source.m_syntheticBold)
- , m_syntheticOblique(source.m_syntheticOblique)
- , m_orientation(source.m_orientation)
- , m_size(source.m_size)
- , m_widthVariant(source.m_widthVariant)
- , m_isColorBitmapFont(source.m_isColorBitmapFont)
- , m_isCompositeFontReference(source.m_isCompositeFontReference)
+ : FontPlatformData(source.m_size, source.m_syntheticBold, source.m_syntheticOblique, source.m_orientation, source.m_widthVariant)
{
+ m_isColorBitmapFont = source.m_isColorBitmapFont;
+ m_isCompositeFontReference = source.m_isCompositeFontReference;
platformDataInit(source);
}
Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.h (183268 => 183269)
--- trunk/Source/WebCore/platform/graphics/FontPlatformData.h 2015-04-24 18:02:30 UTC (rev 183268)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.h 2015-04-24 18:12:31 UTC (rev 183269)
@@ -86,11 +86,7 @@
#if PLATFORM(COCOA)
WEBCORE_EXPORT FontPlatformData(CTFontRef, float size, bool syntheticBold = false, bool syntheticOblique = false, FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
-#if USE(APPKIT)
- // FIXME: Remove this when all NSFont usage is removed.
- WEBCORE_EXPORT FontPlatformData(NSFont *, float size, bool syntheticBold = false, bool syntheticOblique = false, FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
#endif
-#endif
#if USE(CG)
FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant);
@@ -206,6 +202,7 @@
const FontPlatformData& platformDataAssign(const FontPlatformData&);
#if PLATFORM(COCOA)
static CTFontRef hashTableDeletedFontValue() { return reinterpret_cast<CTFontRef>(-1); }
+ static bool isValidCTFontRef(CTFontRef font) { return font && font != hashTableDeletedFontValue(); }
#endif
#if PLATFORM(WIN)
void platformDataInit(HFONT, float size, HDC, WCHAR* faceName);
Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm (183268 => 183269)
--- trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm 2015-04-24 18:02:30 UTC (rev 183268)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm 2015-04-24 18:12:31 UTC (rev 183269)
@@ -325,7 +325,7 @@
#if USE(APPKIT)
BEGIN_BLOCK_OBJC_EXCEPTIONS;
- FontPlatformData scaledFontData([[NSFontManager sharedFontManager] convertFont:m_platformData.nsFont() toSize:size], size, false, false, m_platformData.orientation());
+ FontPlatformData scaledFontData(reinterpret_cast<CTFontRef>([[NSFontManager sharedFontManager] convertFont:m_platformData.nsFont() toSize:size]), size, false, false, m_platformData.orientation());
if (scaledFontData.font()) {
NSFontManager *fontManager = [NSFontManager sharedFontManager];
@@ -571,7 +571,7 @@
bool syntheticBold = platformData().syntheticBold() && !(traits & kCTFontBoldTrait);
bool syntheticOblique = platformData().syntheticOblique() && !(traits & kCTFontItalicTrait);
- FontPlatformData substitutePlatform(substituteFont, platformData().size(), syntheticBold, syntheticOblique, platformData().orientation(), platformData().widthVariant());
+ FontPlatformData substitutePlatform(reinterpret_cast<CTFontRef>(substituteFont), platformData().size(), syntheticBold, syntheticOblique, platformData().orientation(), platformData().widthVariant());
addResult.iterator->value = Font::create(substitutePlatform, isCustomFont());
}
return addResult.iterator->value.get();
Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm (183268 => 183269)
--- trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm 2015-04-24 18:02:30 UTC (rev 183268)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm 2015-04-24 18:12:31 UTC (rev 183269)
@@ -42,37 +42,24 @@
enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidth, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth };
FontPlatformData::FontPlatformData(CTFontRef font, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant)
- : m_syntheticBold(syntheticBold)
- , m_syntheticOblique(syntheticOblique)
- , m_orientation(orientation)
- , m_size(size)
- , m_widthVariant(widthVariant)
- , m_font(font)
- , m_cgFont(adoptCF(CTFontCopyGraphicsFont(font, NULL)))
- , m_isColorBitmapFont(CTFontGetSymbolicTraits(font) & kCTFontTraitColorGlyphs)
- , m_isCompositeFontReference(CTFontGetSymbolicTraits(font) & kCTFontCompositeTrait)
+ : FontPlatformData(adoptCF(CTFontCopyGraphicsFont(font, NULL)), size, syntheticBold, syntheticOblique, orientation, widthVariant)
{
ASSERT_ARG(font, font);
+ m_font = font;
CFRetain(m_font);
+ m_isColorBitmapFont = CTFontGetSymbolicTraits(font) & kCTFontTraitColorGlyphs;
+ m_isCompositeFontReference = CTFontGetSymbolicTraits(font) & kCTFontCompositeTrait;
}
-#if USE(APPKIT)
-// FIXME: Remove this when all NSFont usage is removed.
-FontPlatformData::FontPlatformData(NSFont *font, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant)
- : FontPlatformData((CTFontRef)font, size, syntheticBold, syntheticOblique, orientation, widthVariant)
-{
-}
-#endif
-
FontPlatformData::~FontPlatformData()
{
- if (m_font && m_font != reinterpret_cast<CTFontRef>(-1))
+ if (isValidCTFontRef(m_font))
CFRelease(m_font);
}
void FontPlatformData::platformDataInit(const FontPlatformData& f)
{
- m_font = f.m_font && f.m_font != reinterpret_cast<CTFontRef>(-1) ? static_cast<CTFontRef>(const_cast<void *>(CFRetain(f.m_font))) : f.m_font;
+ m_font = isValidCTFontRef(f.m_font) ? static_cast<CTFontRef>(const_cast<void *>(CFRetain(f.m_font))) : f.m_font;
#if PLATFORM(IOS)
m_isEmoji = f.m_isEmoji;
@@ -87,11 +74,11 @@
#if PLATFORM(IOS)
m_isEmoji = f.m_isEmoji;
#endif
- if (m_font && m_font != reinterpret_cast<CTFontRef>(-1) && f.m_font && f.m_font != reinterpret_cast<CTFontRef>(-1) && CFEqual(m_font, f.m_font))
+ if (isValidCTFontRef(m_font) && isValidCTFontRef(f.m_font) && CFEqual(m_font, f.m_font))
return *this;
- if (f.m_font && f.m_font != reinterpret_cast<CTFontRef>(-1))
+ if (isValidCTFontRef(f.m_font))
CFRetain(f.m_font);
- if (m_font && m_font != reinterpret_cast<CTFontRef>(-1))
+ if (isValidCTFontRef(m_font))
CFRelease(m_font);
m_font = f.m_font;
m_ctFont = f.m_ctFont;
@@ -104,7 +91,7 @@
bool result = false;
if (m_font || other.m_font) {
#if PLATFORM(IOS)
- result = m_font && m_font != reinterpret_cast<CTFontRef>(-1) && other.m_font && other.m_font != reinterpret_cast<CTFontRef>(-1) && CFEqual(m_font, other.m_font);
+ result = isValidCTFontRef(m_font) && isValidCTFontRef(other.m_font) && CFEqual(m_font, other.m_font);
#if !ASSERT_DISABLED
if (result)
ASSERT(m_isEmoji == other.m_isEmoji);
@@ -114,12 +101,10 @@
#endif // PLATFORM(IOS)
return result;
}
-#if PLATFORM(IOS)
-#if !ASSERT_DISABLED
+#if PLATFORM(IOS) && !ASSERT_DISABLED
if (m_cgFont == other.m_cgFont)
ASSERT(m_isEmoji == other.m_isEmoji);
#endif
-#endif // PLATFORM(IOS)
return m_cgFont == other.m_cgFont;
}
@@ -157,15 +142,11 @@
bool FontPlatformData::allowsLigatures() const
{
-#if USE(APPKIT)
- return ![[(NSFont *)m_font coveredCharacterSet] characterIsMember:'a'];
-#else
if (!m_font)
return false;
RetainPtr<CFCharacterSetRef> characterSet = adoptCF(CTFontCopyCharacterSet(ctFont()));
return !(characterSet.get() && CFCharacterSetIsCharacterMember(characterSet.get(), 'a'));
-#endif
}
inline int mapFontWidthVariantToCTFeatureSelector(FontWidthVariant variant)
Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm (183268 => 183269)
--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm 2015-04-24 18:02:30 UTC (rev 183268)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm 2015-04-24 18:12:31 UTC (rev 183269)
@@ -286,7 +286,7 @@
// Core Text may have used a font that is not known to NSFontManager. In that case, fall back on
// using the font as returned, even though it may not have the best NSFontRenderingMode.
if (!runFont) {
- FontPlatformData runFontPlatformData((NSFont *)runCTFont, CTFontGetSize(runCTFont));
+ FontPlatformData runFontPlatformData(runCTFont, CTFontGetSize(runCTFont));
runFont = fontCache.fontForPlatformData(runFontPlatformData).ptr();
}
#else
Modified: trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm (183268 => 183269)
--- trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm 2015-04-24 18:02:30 UTC (rev 183268)
+++ trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm 2015-04-24 18:12:31 UTC (rev 183269)
@@ -403,7 +403,7 @@
substituteFontTraits = [fontManager traitsOfFont:substituteFont];
substituteFontWeight = [fontManager weightOfFont:substituteFont];
- FontPlatformData alternateFont(substituteFont, platformData.size(),
+ FontPlatformData alternateFont(reinterpret_cast<CTFontRef>(substituteFont), platformData.size(),
!isPlatformFont && isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(substituteFontWeight),
!isPlatformFont && (traits & NSFontItalicTrait) && !(substituteFontTraits & NSFontItalicTrait),
platformData.m_orientation);
@@ -512,7 +512,7 @@
bool syntheticBold = isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(actualWeight);
bool syntheticOblique = (traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait);
- return std::make_unique<FontPlatformData>(platformFont, size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant());
+ return std::make_unique<FontPlatformData>(reinterpret_cast<CTFontRef>(platformFont), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant());
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/mac/DragImageMac.mm (183268 => 183269)
--- trunk/Source/WebCore/platform/mac/DragImageMac.mm 2015-04-24 18:02:30 UTC (rev 183268)
+++ trunk/Source/WebCore/platform/mac/DragImageMac.mm 2015-04-24 18:12:31 UTC (rev 183269)
@@ -168,7 +168,7 @@
CFRelease(currentFont);
currentFont = font;
CFRetain(currentFont);
- currentRenderer = FontCascade(FontPlatformData(font, [font pointSize]));
+ currentRenderer = FontCascade(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]));
return currentRenderer;
}
@@ -191,7 +191,7 @@
[string getCharacters:buffer.data()];
if (canUseFastRenderer(buffer.data(), length)) {
- FontCascade webCoreFont(FontPlatformData(font, [font pointSize]));
+ FontCascade webCoreFont(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]));
TextRun run(buffer.data(), length);
run.disableRoundingHacks();
return webCoreFont.width(run);
@@ -223,7 +223,7 @@
if (!flipped)
CGContextScaleCTM(cgContext, 1, -1);
- FontCascade webCoreFont(FontPlatformData(font, [font pointSize]), Antialiased);
+ FontCascade webCoreFont(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]), Antialiased);
TextRun run(buffer.data(), length);
run.disableRoundingHacks();
Modified: trunk/Source/WebKit/mac/ChangeLog (183268 => 183269)
--- trunk/Source/WebKit/mac/ChangeLog 2015-04-24 18:02:30 UTC (rev 183268)
+++ trunk/Source/WebKit/mac/ChangeLog 2015-04-24 18:12:31 UTC (rev 183269)
@@ -1,3 +1,19 @@
+2015-04-24 Myles C. Maxfield <[email protected]>
+
+ [Cocoa] Start cleaning up FontPlatformData
+ https://bugs.webkit.org/show_bug.cgi?id=144133
+
+ Reviewed by Enrica Casucci.
+
+ Receive casts which have been hoisted from the deleted FontPlatformData constructor.
+
+ * Misc/WebKitNSStringExtras.mm:
+ (-[NSString _web_drawAtPoint:font:textColor:allowingFontSmoothing:]): Receive cast which has
+ been hoisted from the deleted FontPlatformData constructor.
+ (-[NSString _web_widthWithFont:]): Ditto.
+ * Misc/WebStringTruncator.mm:
+ (fontFromNSFont): Ditto.
+
2015-04-24 Doug Russell <[email protected]>
AX: richer text change notifications (142719)
Modified: trunk/Source/WebKit/mac/Misc/WebKitNSStringExtras.mm (183268 => 183269)
--- trunk/Source/WebKit/mac/Misc/WebKitNSStringExtras.mm 2015-04-24 18:02:30 UTC (rev 183268)
+++ trunk/Source/WebKit/mac/Misc/WebKitNSStringExtras.mm 2015-04-24 18:12:31 UTC (rev 183269)
@@ -92,7 +92,7 @@
if (!flipped)
CGContextScaleCTM(cgContext, 1, -1);
- FontCascade webCoreFont(FontPlatformData(font, [font pointSize]), fontSmoothingIsAllowed ? AutoSmoothing : Antialiased);
+ FontCascade webCoreFont(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]), fontSmoothingIsAllowed ? AutoSmoothing : Antialiased);
TextRun run(buffer.data(), length);
run.disableRoundingHacks();
@@ -138,7 +138,7 @@
[self getCharacters:buffer.data()];
if (canUseFastRenderer(buffer.data(), length)) {
- FontCascade webCoreFont(FontPlatformData(font, [font pointSize]));
+ FontCascade webCoreFont(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]));
TextRun run(buffer.data(), length);
run.disableRoundingHacks();
return webCoreFont.width(run);
Modified: trunk/Source/WebKit/mac/Misc/WebStringTruncator.mm (183268 => 183269)
--- trunk/Source/WebKit/mac/Misc/WebStringTruncator.mm 2015-04-24 18:02:30 UTC (rev 183268)
+++ trunk/Source/WebKit/mac/Misc/WebStringTruncator.mm 2015-04-24 18:12:31 UTC (rev 183269)
@@ -43,7 +43,7 @@
if ([font isEqual:currentNSFont.get().get()])
return currentFont;
currentNSFont.get() = font;
- currentFont.get() = WebCore::FontCascade(WebCore::FontPlatformData(font, [font pointSize]));
+ currentFont.get() = WebCore::FontCascade(WebCore::FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]));
return currentFont;
}