[Cocoa] Address post-commit review
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Aug 2015 04:55:22 +0000 (04:55 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Aug 2015 04:55:22 +0000 (04:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147864

Reviewed by Darin Adler.

Create helper functions to cast between NSFont*s and CTFontRefs.

No new tests because there is no behavior change.

* platform/graphics/FontPlatformData.h:
(WebCore::toCTFont):
(WebCore::toNSFont):
* platform/graphics/cocoa/FontCacheCoreText.cpp:
* platform/graphics/cocoa/FontCocoa.mm:
(WebCore::Font::platformCreateScaledFont):
(WebCore::Font::compositeFontReferenceFont):
* platform/graphics/mac/FontCacheMac.mm:
(WebCore::FontCache::platformPurgeInactiveFontData):
(WebCore::lookupCTFont):
(WebCore::FontCache::systemFallbackForCharacters):
(WebCore::FontCache::createFontPlatformData):
* platform/mac/DragImageMac.mm:
(WebCore::fontFromNSFont):
(WebCore::widthWithFont):
(WebCore::drawAtPoint):
* platform/spi/mac/NSFontSPI.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188575 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/FontPlatformData.h
Source/WebCore/platform/graphics/cocoa/FontCocoa.mm
Source/WebCore/platform/graphics/mac/FontCacheMac.mm
Source/WebCore/platform/mac/DragImageMac.mm
Source/WebCore/platform/spi/mac/NSFontSPI.h

index 2412c79..da2a07a 100644 (file)
@@ -1,3 +1,32 @@
+2015-08-17  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Address post-commit review
+        https://bugs.webkit.org/show_bug.cgi?id=147864
+
+        Reviewed by Darin Adler.
+
+        Create helper functions to cast between NSFont*s and CTFontRefs.
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/FontPlatformData.h:
+        (WebCore::toCTFont):
+        (WebCore::toNSFont):
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        * platform/graphics/cocoa/FontCocoa.mm:
+        (WebCore::Font::platformCreateScaledFont):
+        (WebCore::Font::compositeFontReferenceFont):
+        * platform/graphics/mac/FontCacheMac.mm:
+        (WebCore::FontCache::platformPurgeInactiveFontData):
+        (WebCore::lookupCTFont):
+        (WebCore::FontCache::systemFallbackForCharacters):
+        (WebCore::FontCache::createFontPlatformData):
+        * platform/mac/DragImageMac.mm:
+        (WebCore::fontFromNSFont):
+        (WebCore::widthWithFont):
+        (WebCore::drawAtPoint):
+        * platform/spi/mac/NSFontSPI.h:
+
 2015-08-17  Alex Christensen  <achristensen@webkit.org>
 
         WinCairo build fix after r188566
index 7fe8d09..ecd9496 100644 (file)
@@ -244,6 +244,19 @@ private:
 #endif
 };
 
+#if USE(APPKIT)
+// NSFonts and CTFontRefs are toll-free-bridged.
+inline CTFontRef toCTFont(NSFont *font)
+{
+    return (CTFontRef)font;
+}
+
+inline NSFont *toNSFont(CTFontRef font)
+{
+    return (NSFont *)font;
+}
+#endif
+
 } // namespace WebCore
 
 #endif // FontPlatformData_h
index ba46888..d3ced39 100644 (file)
@@ -324,7 +324,7 @@ PassRefPtr<Font> Font::platformCreateScaledFont(const FontDescription&, float sc
 #if USE(APPKIT)
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
-    FontPlatformData scaledFontData(reinterpret_cast<CTFontRef>([[NSFontManager sharedFontManager] convertFont:m_platformData.nsFont() toSize:size]), size, false, false, m_platformData.orientation());
+    FontPlatformData scaledFontData(toCTFont([[NSFontManager sharedFontManager] convertFont:m_platformData.nsFont() toSize:size]), size, false, false, m_platformData.orientation());
 
     if (scaledFontData.font()) {
         NSFontManager *fontManager = [NSFontManager sharedFontManager];
index 158fbb0..f27fd2a 100644 (file)
@@ -474,10 +474,10 @@ static FallbackDedupSet& fallbackDedupSet()
 
 void FontCache::platformPurgeInactiveFontData()
 {
-    Vector<RetainPtr<CTFontRef>> toRemove;
+    Vector<CTFontRef> toRemove;
     for (auto& font : fallbackDedupSet()) {
         if (CFGetRetainCount(font.get()) == 1)
-            toRemove.append(font);
+            toRemove.append(font.get());
     }
     for (auto& font : toRemove)
         fallbackDedupSet().remove(font);
@@ -489,7 +489,7 @@ static inline RetainPtr<CTFontRef> lookupCTFont(CTFontRef font, float fontSize,
 #if __MAC_OS_X_VERSION_MIN_REQUIRED == 1090
     UNUSED_PARAM(locale);
     if (!font) {
-        font = reinterpret_cast<CTFontRef>([NSFont userFontOfSize:fontSize]);
+        font = toCTFont([NSFont userFontOfSize:fontSize]);
         bool acceptable = true;
         
         RetainPtr<CFCharacterSetRef> characterSet = adoptCF(CTFontCopyCharacterSet(font));
@@ -527,7 +527,7 @@ RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& descr
     // FontCascade::drawGlyphBuffer() requires that there are no duplicate Font objects which refer to the same thing. This is enforced in
     // FontCache::fontForPlatformData(), where our equality check is based on hashing the FontPlatformData, whose hash includes the raw CoreText
     // font pointer.
-    NSFont *substituteFont = reinterpret_cast<NSFont *>(const_cast<__CTFont*>(fallbackDedupSet().add(result).iterator->get()));
+    NSFont *substituteFont = toNSFont(fallbackDedupSet().add(result).iterator->get());
 
     // Use the family name from the AppKit-supplied substitute font, requesting the
     // traits, weight, and size we want. One way this does better than the original
@@ -575,7 +575,7 @@ RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& descr
     substituteFontTraits = [fontManager traitsOfFont:substituteFont];
     substituteFontWeight = [fontManager weightOfFont:substituteFont];
 
-    FontPlatformData alternateFont(reinterpret_cast<CTFontRef>(substituteFont), platformData.size(),
+    FontPlatformData alternateFont(toCTFont(substituteFont), platformData.size(),
         !isPlatformFont && isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(substituteFontWeight),
         !isPlatformFont && (traits & NSFontItalicTrait) && !(substituteFontTraits & NSFontItalicTrait),
         platformData.m_orientation);
@@ -703,7 +703,7 @@ std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
     bool syntheticBold = (fontDescription.fontSynthesis() & FontSynthesisWeight) && isAppKitFontWeightBold(toAppKitFontWeight(fontDescription.weight())) && !isAppKitFontWeightBold(actualWeight);
     bool syntheticOblique = (fontDescription.fontSynthesis() & FontSynthesisStyle) && (traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait);
 
-    return std::make_unique<FontPlatformData>(reinterpret_cast<CTFontRef>(platformFont), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant());
+    return std::make_unique<FontPlatformData>(toCTFont(platformFont), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant());
 }
 
 } // namespace WebCore
index 66b1eb8..b505fc1 100644 (file)
@@ -168,7 +168,7 @@ static FontCascade& fontFromNSFont(NSFont *font)
         CFRelease(currentFont);
     currentFont = font;
     CFRetain(currentFont);
-    currentRenderer = FontCascade(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]));
+    currentRenderer = FontCascade(FontPlatformData(toCTFont(font), [font pointSize]));
     return currentRenderer;
 }
 
@@ -191,7 +191,7 @@ static float widthWithFont(NSString *string, NSFont *font)
     [string getCharacters:buffer.data()];
     
     if (canUseFastRenderer(buffer.data(), length)) {
-        FontCascade webCoreFont(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]));
+        FontCascade webCoreFont(FontPlatformData(toCTFont(font), [font pointSize]));
         TextRun run(StringView(buffer.data(), length));
         run.disableRoundingHacks();
         return webCoreFont.width(run);
@@ -223,7 +223,7 @@ static void drawAtPoint(NSString *string, NSPoint point, NSFont *font, NSColor *
         if (!flipped)
             CGContextScaleCTM(cgContext, 1, -1);
             
-        FontCascade webCoreFont(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]), Antialiased);
+        FontCascade webCoreFont(FontPlatformData(toCTFont(font), [font pointSize]), Antialiased);
         TextRun run(StringView(buffer.data(), length));
         run.disableRoundingHacks();
 
index f2b9341..00fa986 100644 (file)
@@ -34,7 +34,7 @@
 
 #else
 
-@interface NSFont (Private)
+@interface NSFont ()
 + (NSFont *)systemFontOfSize:(CGFloat)size weight:(CGFloat)weight;
 @end