Title: [204592] trunk
Revision
204592
Author
mmaxfi...@apple.com
Date
2016-08-17 23:38:14 -0700 (Wed, 17 Aug 2016)

Log Message

[Cocoa] Migrate off of deprecated CoreGraphics API CGContextSelectFont() and CGContextShowTextAtPoint()
https://bugs.webkit.org/show_bug.cgi?id=160895

Reviewed by Dean Jackson.

Source/WebCore:

Migrate to CTLineDraw() instead.

This patch also adds support for linking to the existing CoreText framework on Windows.

No new tests because there is no behavior change.

* PlatformWin.cmake:
* page/cocoa/ResourceUsageOverlayCocoa.mm:
(WebCore::showText):
* platform/graphics/ca/PlatformCALayer.cpp:
(WebCore::PlatformCALayer::drawTextAtPoint):
* platform/ios/LegacyTileCache.mm:
(WebCore::LegacyTileCache::drawLayer):
* platform/spi/win/CoreTextSPIWin.cpp: Added.
* platform/spi/win/CoreTextSPIWin.h: Added.

Source/WebKit:

Link to the existing CoreText framework.

* PlatformWin.cmake:

Tools:

Link to the existing CoreText framework.

* DumpRenderTree/PlatformWin.cmake:
* TestWebKitAPI/PlatformWin.cmake:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (204591 => 204592)


--- trunk/Source/WebCore/ChangeLog	2016-08-18 06:22:40 UTC (rev 204591)
+++ trunk/Source/WebCore/ChangeLog	2016-08-18 06:38:14 UTC (rev 204592)
@@ -1,3 +1,26 @@
+2016-08-17  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Cocoa] Migrate off of deprecated CoreGraphics API CGContextSelectFont() and CGContextShowTextAtPoint()
+        https://bugs.webkit.org/show_bug.cgi?id=160895
+
+        Reviewed by Dean Jackson.
+
+        Migrate to CTLineDraw() instead.
+
+        This patch also adds support for linking to the existing CoreText framework on Windows.
+
+        No new tests because there is no behavior change.
+
+        * PlatformWin.cmake:
+        * page/cocoa/ResourceUsageOverlayCocoa.mm:
+        (WebCore::showText):
+        * platform/graphics/ca/PlatformCALayer.cpp:
+        (WebCore::PlatformCALayer::drawTextAtPoint):
+        * platform/ios/LegacyTileCache.mm:
+        (WebCore::LegacyTileCache::drawLayer):
+        * platform/spi/win/CoreTextSPIWin.cpp: Added.
+        * platform/spi/win/CoreTextSPIWin.h: Added.
+
 2016-08-17  Benjamin Poulain  <benja...@webkit.org>
 
         [CSS] The parser should not get rid of empty namespace specification in front of element name selectors

Modified: trunk/Source/WebCore/PlatformWin.cmake (204591 => 204592)


--- trunk/Source/WebCore/PlatformWin.cmake	2016-08-18 06:22:40 UTC (rev 204591)
+++ trunk/Source/WebCore/PlatformWin.cmake	2016-08-18 06:38:14 UTC (rev 204592)
@@ -34,6 +34,7 @@
     "${WEBCORE_DIR}/platform/graphics/opentype"
     "${WEBCORE_DIR}/platform/graphics/win"
     "${WEBCORE_DIR}/platform/network/win"
+    "${WEBCORE_DIR}/platform/spi/win"
     "${WEBCORE_DIR}/platform/win"
     "${THIRDPARTY_DIR}/ANGLE/include"
     "${THIRDPARTY_DIR}/ANGLE/include/egl"
@@ -104,6 +105,8 @@
     platform/network/win/DownloadBundleWin.cpp
     platform/network/win/NetworkStateNotifierWin.cpp
 
+    platform/spi/win/CoreTextSPIWin.cpp
+
     platform/text/LocaleNone.cpp
 
     platform/text/cf/HyphenationCF.cpp

Modified: trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm (204591 => 204592)


--- trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm	2016-08-18 06:22:40 UTC (rev 204591)
+++ trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm	2016-08-18 06:38:14 UTC (rev 204592)
@@ -28,6 +28,8 @@
 
 #if ENABLE(RESOURCE_USAGE)
 
+#include <CoreText/CoreText.h>
+
 #include "JSDOMWindow.h"
 #include "PlatformCALayer.h"
 #include "ResourceUsageThread.h"
@@ -252,21 +254,24 @@
     CGContextSetTextDrawingMode(context, kCGTextFill);
     CGContextSetFillColorWithColor(context, color);
 
-    CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));
-
-    // FIXME: Don't use deprecated APIs.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-
+    CGAffineTransform matrix = CGAffineTransformMakeScale(1, -1);
 #if PLATFORM(IOS)
-    CGContextSelectFont(context, "Courier", 10, kCGEncodingMacRoman);
+    CFStringRef fontName = CFSTR("Courier");
+    CGFloat fontSize = 10;
 #else
-    CGContextSelectFont(context, "Menlo", 11, kCGEncodingMacRoman);
+    CFStringRef fontName = CFSTR("Menlo");
+    CGFloat fontSize = 11;
 #endif
-
+    RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithName(fontName, fontSize, &matrix));
+    CFTypeRef keys[] = { kCTFontAttributeName, kCTForegroundColorFromContextAttributeName };
+    CFTypeRef values[] = { font.get(), kCFBooleanTrue };
+    RetainPtr<CFDictionaryRef> attributes = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
     CString cstr = text.ascii();
-    CGContextShowTextAtPoint(context, x, y, cstr.data(), cstr.length());
-#pragma clang diagnostic pop
+    RetainPtr<CFStringRef> string = adoptCF(CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(cstr.data()), cstr.length(), kCFStringEncodingASCII, false, kCFAllocatorNull));
+    RetainPtr<CFAttributedStringRef> attributedString = adoptCF(CFAttributedStringCreate(kCFAllocatorDefault, string.get(), attributes.get()));
+    RetainPtr<CTLineRef> line = adoptCF(CTLineCreateWithAttributedString(attributedString.get()));
+    CGContextSetTextPosition(context, x, y);
+    CTLineDraw(line.get(), context);
 
     CGContextRestoreGState(context);
 }

Modified: trunk/Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp (204591 => 204592)


--- trunk/Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp	2016-08-18 06:22:40 UTC (rev 204591)
+++ trunk/Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp	2016-08-18 06:38:14 UTC (rev 204592)
@@ -26,6 +26,9 @@
 #include "config.h"
 #include "PlatformCALayer.h"
 
+#include <CoreFoundation/CoreFoundation.h>
+#include <CoreText/CoreText.h>
+
 #include "GraphicsContextCG.h"
 #include "LayerPool.h"
 #include "PlatformCALayerClient.h"
@@ -32,6 +35,10 @@
 #include "TextStream.h"
 #include <wtf/StringExtras.h>
 
+#if PLATFORM(WIN)
+#include "CoreTextSPIWin.h"
+#endif
+
 #if USE(CA)
 
 namespace WebCore {
@@ -121,12 +128,16 @@
 // This function is needed to work around a bug in Windows CG <rdar://problem/22703470>
 void PlatformCALayer::drawTextAtPoint(CGContextRef context, CGFloat x, CGFloat y, CGSize scale, CGFloat fontSize, const char* text, size_t length) const
 {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-    CGContextSetTextMatrix(context, CGAffineTransformMakeScale(scale.width, scale.height));
-    CGContextSelectFont(context, "Helvetica", fontSize, kCGEncodingMacRoman);
-    CGContextShowTextAtPoint(context, x, y, text, length);
-#pragma clang diagnostic pop
+    CGAffineTransform matrix = CGAffineTransformMakeScale(scale.width, scale.height);
+    RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithName(CFSTR("Helvetica"), fontSize, &matrix));
+    CFTypeRef keys[] = { kCTFontAttributeName, kCTForegroundColorFromContextAttributeName };
+    CFTypeRef values[] = { font.get(), kCFBooleanTrue };
+    RetainPtr<CFDictionaryRef> attributes = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+    RetainPtr<CFStringRef> string = adoptCF(CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(text), length, kCFStringEncodingUTF8, false, kCFAllocatorNull));
+    RetainPtr<CFAttributedStringRef> attributedString = adoptCF(CFAttributedStringCreate(kCFAllocatorDefault, string.get(), attributes.get()));
+    RetainPtr<CTLineRef> line = adoptCF(CTLineCreateWithAttributedString(attributedString.get()));
+    CGContextSetTextPosition(context, x, y);
+    CTLineDraw(line.get(), context);
 }
 
 PassRefPtr<PlatformCALayer> PlatformCALayer::createCompatibleLayerOrTakeFromPool(PlatformCALayer::LayerType layerType, PlatformCALayerClient* client, IntSize size)

Modified: trunk/Source/WebCore/platform/ios/LegacyTileCache.mm (204591 => 204592)


--- trunk/Source/WebCore/platform/ios/LegacyTileCache.mm	2016-08-18 06:22:40 UTC (rev 204591)
+++ trunk/Source/WebCore/platform/ios/LegacyTileCache.mm	2016-08-18 06:38:14 UTC (rev 204592)
@@ -28,6 +28,8 @@
 
 #if PLATFORM(IOS)
 
+#include <CoreText/CoreText.h>
+
 #include "FontAntialiasingStateSaver.h"
 #include "LegacyTileGrid.h"
 #include "LegacyTileGridTile.h"
@@ -591,14 +593,17 @@
             CGContextSetRGBFillColor(context, 1, 0, 0, 0.4f);
         else
             CGContextSetRGBFillColor(context, 1, 1, 1, 0.6f);
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-        CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-        CGContextSelectFont(context, "Helvetica", 25, kCGEncodingMacRoman);
-        CGContextShowTextAtPoint(context, labelBounds.origin.x + 3, labelBounds.origin.y + 20, text, strlen(text));
-#pragma clang diagnostic pop
+
+        CGAffineTransform matrix = CGAffineTransformMakeScale(1, -1);
+        RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithName(CFSTR("Helvetica"), 25, &matrix));
+        CFTypeRef keys[] = { kCTFontAttributeName, kCTForegroundColorFromContextAttributeName };
+        CFTypeRef values[] = { font.get(), kCFBooleanTrue };
+        RetainPtr<CFDictionaryRef> attributes = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+        RetainPtr<CFStringRef> string = adoptCF(CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(text), strlen(text), kCFStringEncodingUTF8, false, kCFAllocatorNull));
+        RetainPtr<CFAttributedStringRef> attributedString = adoptCF(CFAttributedStringCreate(kCFAllocatorDefault, string.get(), attributes.get()));
+        RetainPtr<CTLineRef> line = adoptCF(CTLineCreateWithAttributedString(attributedString.get()));
+        CGContextSetTextPosition(context, labelBounds.origin.x + 3, labelBounds.origin.y + 20);
+        CTLineDraw(line.get(), context);
     
         CGContextRestoreGState(context);        
     }

Added: trunk/Source/WebCore/platform/spi/win/CoreTextSPIWin.cpp (0 => 204592)


--- trunk/Source/WebCore/platform/spi/win/CoreTextSPIWin.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/spi/win/CoreTextSPIWin.cpp	2016-08-18 06:38:14 UTC (rev 204592)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CoreTextSPIWin.h"
+
+extern "C" {
+
+const CFStringRef kCTFontAttributeName = CFSTR("NSFont");
+const CFStringRef kCTForegroundColorFromContextAttributeName = CFSTR("CTForegroundColorFromContext");
+
+}
+

Added: trunk/Source/WebCore/platform/spi/win/CoreTextSPIWin.h (0 => 204592)


--- trunk/Source/WebCore/platform/spi/win/CoreTextSPIWin.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/spi/win/CoreTextSPIWin.h	2016-08-18 06:38:14 UTC (rev 204592)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <CoreGraphics/CoreGraphics.h>
+#include <CoreText/CoreText.h>
+
+extern "C" {
+
+typedef const struct __CTFont* CTFontRef;
+typedef const struct __CTLine* CTLineRef;
+
+extern const CFStringRef kCTFontAttributeName;
+extern const CFStringRef kCTForegroundColorFromContextAttributeName;
+
+CTFontRef CTFontCreateWithName(CFStringRef name, CGFloat size, const CGAffineTransform* matrix);
+CTLineRef CTLineCreateWithAttributedString(CFAttributedStringRef);
+void CTLineDraw(CTLineRef, CGContextRef);
+
+}
+

Modified: trunk/Source/WebKit/ChangeLog (204591 => 204592)


--- trunk/Source/WebKit/ChangeLog	2016-08-18 06:22:40 UTC (rev 204591)
+++ trunk/Source/WebKit/ChangeLog	2016-08-18 06:38:14 UTC (rev 204592)
@@ -1,3 +1,14 @@
+2016-08-17  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Cocoa] Migrate off of deprecated CoreGraphics API CGContextSelectFont() and CGContextShowTextAtPoint()
+        https://bugs.webkit.org/show_bug.cgi?id=160895
+
+        Reviewed by Dean Jackson.
+
+        Link to the existing CoreText framework.
+
+        * PlatformWin.cmake:
+
 2016-08-16  Hunseop Jeong  <hs85.je...@samsung.com>
 
         Unreviewed, CMake build fix

Modified: trunk/Source/WebKit/PlatformWin.cmake (204591 => 204592)


--- trunk/Source/WebKit/PlatformWin.cmake	2016-08-18 06:22:40 UTC (rev 204591)
+++ trunk/Source/WebKit/PlatformWin.cmake	2016-08-18 06:38:14 UTC (rev 204592)
@@ -25,6 +25,7 @@
         PRIVATE CFNetwork${DEBUG_SUFFIX}
         PRIVATE CoreFoundation${DEBUG_SUFFIX}
         PRIVATE CoreGraphics${DEBUG_SUFFIX}
+        PRIVATE CoreText${DEBUG_SUFFIX}
         PRIVATE SQLite3${DEBUG_SUFFIX}
         PRIVATE WebKitSystemInterface${DEBUG_SUFFIX}
         PRIVATE libdispatch${DEBUG_SUFFIX}

Modified: trunk/Tools/ChangeLog (204591 => 204592)


--- trunk/Tools/ChangeLog	2016-08-18 06:22:40 UTC (rev 204591)
+++ trunk/Tools/ChangeLog	2016-08-18 06:38:14 UTC (rev 204592)
@@ -1,3 +1,15 @@
+2016-08-17  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Cocoa] Migrate off of deprecated CoreGraphics API CGContextSelectFont() and CGContextShowTextAtPoint()
+        https://bugs.webkit.org/show_bug.cgi?id=160895
+
+        Reviewed by Dean Jackson.
+
+        Link to the existing CoreText framework.
+
+        * DumpRenderTree/PlatformWin.cmake:
+        * TestWebKitAPI/PlatformWin.cmake:
+
 2016-08-17  Brent Fulgham  <bfulg...@apple.com>
 
         [Win] Remove old libraries from build inputs

Modified: trunk/Tools/DumpRenderTree/PlatformWin.cmake (204591 => 204592)


--- trunk/Tools/DumpRenderTree/PlatformWin.cmake	2016-08-18 06:22:40 UTC (rev 204591)
+++ trunk/Tools/DumpRenderTree/PlatformWin.cmake	2016-08-18 06:38:14 UTC (rev 204592)
@@ -116,6 +116,7 @@
     list(APPEND DumpRenderTreeLib_LIBRARIES
         CFNetwork
         CoreGraphics
+        CoreText
     )
     list(APPEND ImageDiff_SOURCES
         cg/ImageDiffCG.cpp
@@ -123,6 +124,7 @@
     list(APPEND ImageDiff_LIBRARIES
        CoreFoundation
        CoreGraphics
+       CoreText
     )
 endif ()
 

Modified: trunk/Tools/TestWebKitAPI/PlatformWin.cmake (204591 => 204592)


--- trunk/Tools/TestWebKitAPI/PlatformWin.cmake	2016-08-18 06:22:40 UTC (rev 204591)
+++ trunk/Tools/TestWebKitAPI/PlatformWin.cmake	2016-08-18 06:38:14 UTC (rev 204592)
@@ -72,6 +72,7 @@
         CFNetwork${DEBUG_SUFFIX}
         CoreFoundation${DEBUG_SUFFIX}
         CoreGraphics${DEBUG_SUFFIX}
+        CoreText${DEBUG_SUFFIX}
         QuartzCore${DEBUG_SUFFIX}
         SQLite3${DEBUG_SUFFIX}
         WebKitSystemInterface${DEBUG_SUFFIX}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to