Title: [183696] trunk
Revision
183696
Author
mmaxfi...@apple.com
Date
2015-05-01 16:25:41 -0700 (Fri, 01 May 2015)

Log Message

[OS X] Text dilation parameters are not restored after being set
https://bugs.webkit.org/show_bug.cgi?id=144507
<rdar://problem/19446938>

Patch by Myles C. Maxfield <mmaxfi...@apple.com> on 2015-05-01
Reviewed by Simon Fraser and Ned Holbrook.

Source/WebCore:

Create a RAII class who is in charge of saving, applying, and restoring dilation parameters. Use this class
around our text drawing routines.

Note that this migrates our use of CTFontSetRenderingParameters() to CTFontSetRenderingStyle().

Test: fast/text/dilation-save-restore.html

* platform/graphics/cocoa/FontCascadeCocoa.mm:
(WebCore::RenderingStyleSaver::RenderingStyleSaver):
(WebCore::RenderingStyleSaver::~RenderingStyleSaver):
(WebCore::showGlyphsWithAdvances):
* platform/spi/cg/CoreGraphicsSPI.h:
* platform/spi/cocoa/CoreTextSPI.h:

LayoutTests:

See below.

* fast/text/dilation-save-restore-expected.html: Added. Never sets dilation parameters, draws two strings.
* fast/text/dilation-save-restore.html: Added. Draws one string without dilation, sets the dilation, then draws a
second string. If saving and restoring doesn't work correctly, these two lines will appear different.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (183695 => 183696)


--- trunk/LayoutTests/ChangeLog	2015-05-01 22:53:09 UTC (rev 183695)
+++ trunk/LayoutTests/ChangeLog	2015-05-01 23:25:41 UTC (rev 183696)
@@ -1,3 +1,17 @@
+2015-05-01  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [OS X] Text dilation parameters are not restored after being set
+        https://bugs.webkit.org/show_bug.cgi?id=144507
+        <rdar://problem/19446938>
+
+        Reviewed by Simon Fraser and Ned Holbrook.
+
+        See below.
+
+        * fast/text/dilation-save-restore-expected.html: Added. Never sets dilation parameters, draws two strings.
+        * fast/text/dilation-save-restore.html: Added. Draws one string without dilation, sets the dilation, then draws a
+        second string. If saving and restoring doesn't work correctly, these two lines will appear different.
+
 2015-05-01  Jordan Harband  <ljh...@gmail.com>
 
         String#startsWith/endsWith/includes don't handle Infinity position/endPosition args correctly

Added: trunk/LayoutTests/fast/text/dilation-save-restore-expected.html (0 => 183696)


--- trunk/LayoutTests/fast/text/dilation-save-restore-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/dilation-save-restore-expected.html	2015-05-01 23:25:41 UTC (rev 183696)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+This test makes sure that we save and restore state properly when issuing dilation rendering parameters.
+<div>Hello, World!</div>
+<br>
+<div>Hello, World!</div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/text/dilation-save-restore.html (0 => 183696)


--- trunk/LayoutTests/fast/text/dilation-save-restore.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/dilation-save-restore.html	2015-05-01 23:25:41 UTC (rev 183696)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+This test makes sure that we save and restore state properly when issuing dilation rendering parameters.
+<div>Hello, World!</div>
+<div style="margin-top: -100px; color: white;">Hello, World!</div>
+<div style="margin-top: 100px;">Hello, World!</div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (183695 => 183696)


--- trunk/Source/WebCore/ChangeLog	2015-05-01 22:53:09 UTC (rev 183695)
+++ trunk/Source/WebCore/ChangeLog	2015-05-01 23:25:41 UTC (rev 183696)
@@ -1,3 +1,25 @@
+2015-05-01  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [OS X] Text dilation parameters are not restored after being set
+        https://bugs.webkit.org/show_bug.cgi?id=144507
+        <rdar://problem/19446938>
+
+        Reviewed by Simon Fraser and Ned Holbrook.
+
+        Create a RAII class who is in charge of saving, applying, and restoring dilation parameters. Use this class
+        around our text drawing routines.
+
+        Note that this migrates our use of CTFontSetRenderingParameters() to CTFontSetRenderingStyle().
+
+        Test: fast/text/dilation-save-restore.html
+
+        * platform/graphics/cocoa/FontCascadeCocoa.mm:
+        (WebCore::RenderingStyleSaver::RenderingStyleSaver):
+        (WebCore::RenderingStyleSaver::~RenderingStyleSaver):
+        (WebCore::showGlyphsWithAdvances):
+        * platform/spi/cg/CoreGraphicsSPI.h:
+        * platform/spi/cocoa/CoreTextSPI.h:
+
 2015-05-01  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, rolling out r183687.

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm (183695 => 183696)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2015-05-01 22:53:09 UTC (rev 183695)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2015-05-01 23:25:41 UTC (rev 183696)
@@ -131,6 +131,56 @@
 #endif
 }
 
+class RenderingStyleSaver {
+public:
+#if !PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000
+
+    RenderingStyleSaver(CTFontRef, CGContextRef) { }
+
+#elif !defined(CORETEXT_HAS_CTFontSetRenderingStyle) || CORETEXT_HAS_CTFontSetRenderingStyle != 1
+
+    // This is very slow, but it's just a holdover until everyone migrates to CTFontSetRenderingStyle()
+    // FIXME: Delete this implementation when everyone has migrated off
+    RenderingStyleSaver(CTFontRef font, CGContextRef context)
+        : m_context(context)
+    {
+        CGContextSaveGState(context);
+        CTFontSetRenderingParameters(font, context);
+    }
+
+    ~RenderingStyleSaver()
+    {
+        CGContextRestoreGState(m_context);
+    }
+
+private:
+    CGContextRef m_context;
+
+#else
+
+    RenderingStyleSaver(CTFontRef font, CGContextRef context)
+        : m_context(context)
+    {
+        m_changed = CTFontSetRenderingStyle(font, context, &m_originalStyle, &m_originalDilation);
+    }
+
+    ~RenderingStyleSaver()
+    {
+        if (!m_changed)
+            return;
+        CGContextSetFontRenderingStyle(m_context, m_originalStyle);
+        CGContextSetFontDilation(m_context, m_originalDilation);
+    }
+
+private:
+    bool m_changed;
+    CGContextRef m_context;
+    CGFontRenderingStyle m_originalStyle;
+    CGSize m_originalDilation;
+
+#endif
+};
+
 static void showGlyphsWithAdvances(const FloatPoint& point, const Font* font, CGContextRef context, const CGGlyph* glyphs, const CGSize* advances, size_t count)
 {
     if (!count)
@@ -162,18 +212,14 @@
             position.y += advances[i].height;
         }
         if (!platformData.isColorBitmapFont()) {
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101000
-            CTFontSetRenderingParameters(platformData.ctFont(), context);
-#endif
+            RenderingStyleSaver saver(platformData.ctFont(), context);
             CGContextShowGlyphsAtPositions(context, glyphs, positions.data(), count);
         } else
             CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context);
         CGContextSetTextMatrix(context, savedMatrix);
     } else {
         if (!platformData.isColorBitmapFont()) {
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101000
-            CTFontSetRenderingParameters(platformData.ctFont(), context);
-#endif
+            RenderingStyleSaver saver(platformData.ctFont(), context);
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
             CGContextShowGlyphsWithAdvances(context, glyphs, advances, count);

Modified: trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h (183695 => 183696)


--- trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h	2015-05-01 22:53:09 UTC (rev 183695)
+++ trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h	2015-05-01 23:25:41 UTC (rev 183696)
@@ -144,6 +144,7 @@
 void CGContextSetShouldAntialiasFonts(CGContextRef, bool shouldAntialiasFonts);
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
 void CGContextSetFontDilation(CGContextRef, CGSize);
+void CGContextSetFontRenderingStyle(CGContextRef, CGFontRenderingStyle);
 #endif
 
 CFStringRef CGFontCopyFamilyName(CGFontRef);

Modified: trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h (183695 => 183696)


--- trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h	2015-05-01 22:53:09 UTC (rev 183695)
+++ trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h	2015-05-01 23:25:41 UTC (rev 183696)
@@ -66,8 +66,12 @@
 CTTypesetterRef CTTypesetterCreateWithUniCharProviderAndOptions(CTUniCharProviderCallback provide, CTUniCharDisposeCallback dispose, void* refCon, CFDictionaryRef options);
 bool CTFontGetVerticalGlyphsForCharacters(CTFontRef, const UniChar characters[], CGGlyph glyphs[], CFIndex count);
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101000
+#if defined(CORETEXT_HAS_CTFontSetRenderingStyle) && CORETEXT_HAS_CTFontSetRenderingStyle == 1
+bool CTFontSetRenderingStyle(CTFontRef, CGContextRef, CGFontRenderingStyle* originalStyle, CGSize* originalDilation);
+#else
 void CTFontSetRenderingParameters(CTFontRef, CGContextRef);
 #endif
+#endif
 
 CTFontDescriptorRef CTFontDescriptorCreateForUIType(CTFontUIFontType, CGFloat size, CFStringRef language);
 CTFontDescriptorRef CTFontDescriptorCreateWithTextStyle(CFStringRef style, CFStringRef size, CFStringRef language);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to