Title: [222065] trunk/Source/WebCore
Revision
222065
Author
[email protected]
Date
2017-09-14 16:52:31 -0700 (Thu, 14 Sep 2017)

Log Message

[Mac] Spelling, grammar and correction dots are painted upside down
https://bugs.webkit.org/show_bug.cgi?id=176949
<rdar://problem/34441098>

Reviewed by Simon Fraser.

Painting occurs in a vertically flipped context. Vertically flip the context ("unflip" it)
before painting the document markers on macOS so that they are painted right-side. This makes
the appearance of spelling, grammar and correction dots in WebKit match the AppKit appearance
of these dots.

* platform/graphics/cocoa/GraphicsContextCocoa.mm:
(WebCore::GraphicsContext::drawLineForDocumentMarker): Flip the context as described above.
Also make use of RAII object CGContextStateSaver instead of manually saving and restoring
the state of the context.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (222064 => 222065)


--- trunk/Source/WebCore/ChangeLog	2017-09-14 23:49:19 UTC (rev 222064)
+++ trunk/Source/WebCore/ChangeLog	2017-09-14 23:52:31 UTC (rev 222065)
@@ -1,3 +1,21 @@
+2017-09-14  Daniel Bates  <[email protected]>
+
+        [Mac] Spelling, grammar and correction dots are painted upside down
+        https://bugs.webkit.org/show_bug.cgi?id=176949
+        <rdar://problem/34441098>
+
+        Reviewed by Simon Fraser.
+
+        Painting occurs in a vertically flipped context. Vertically flip the context ("unflip" it)
+        before painting the document markers on macOS so that they are painted right-side. This makes
+        the appearance of spelling, grammar and correction dots in WebKit match the AppKit appearance
+        of these dots.
+
+        * platform/graphics/cocoa/GraphicsContextCocoa.mm:
+        (WebCore::GraphicsContext::drawLineForDocumentMarker): Flip the context as described above.
+        Also make use of RAII object CGContextStateSaver instead of manually saving and restoring
+        the state of the context.
+
 2017-09-14  Joseph Pecoraro  <[email protected]>
 
         Unreviewed rollout r222036.

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextCocoa.mm (222064 => 222065)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextCocoa.mm	2017-09-14 23:49:19 UTC (rev 222064)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextCocoa.mm	2017-09-14 23:52:31 UTC (rev 222065)
@@ -308,7 +308,7 @@
 
     // Draw underline.
     CGContextRef context = platformContext();
-    CGContextSaveGState(context);
+    CGContextStateSaver stateSaver { context };
 
 #if PLATFORM(IOS)
     WKSetPattern(context, dotPattern, YES, YES);
@@ -319,11 +319,19 @@
     CGRect destinationRect = CGRectMake(offsetPoint.x(), offsetPoint.y(), width, patternHeight);
 #if !PLATFORM(IOS)
     if (image) {
+        CGContextClipToRect(context, destinationRect);
+
+        // We explicitly flip coordinates so as to ensure we paint the image right-side up. We do this because
+        // -[NSImage CGImageForProposedRect:context:hints:] does not guarantee that the returned image will respect
+        // any transforms applied to the context or any specified hints.
+        CGContextTranslateCTM(context, 0, patternHeight);
+        CGContextScaleCTM(context, 1, -1);
+
+        NSRect dotRect = NSMakeRect(offsetPoint.x(), patternHeight - offsetPoint.y(), patternWidth, patternHeight); // Adjust y position as we flipped coordinates.
+
         // FIXME: Rather than getting the NSImage and then picking the CGImage from it, we should do what iOS does and
         // just load the CGImage in the first place.
-        NSRect dotRect = NSMakeRect(offsetPoint.x(), offsetPoint.y(), patternWidth, patternHeight);
-        CGImageRef cgImage = [image CGImageForProposedRect:&dotRect context:[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES] hints:nullptr];
-        CGContextClipToRect(context, destinationRect);
+        CGImageRef cgImage = [image CGImageForProposedRect:&dotRect context:[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO] hints:nullptr];
         CGContextDrawTiledImage(context, NSRectToCGRect(dotRect), cgImage);
     } else {
         CGContextSetFillColorWithColor(context, [fallbackColor CGColor]);
@@ -332,8 +340,6 @@
 #else
     WKRectFillUsingOperation(context, destinationRect, kCGCompositeSover);
 #endif
-    
-    CGContextRestoreGState(context);
 }
 
 CGColorSpaceRef linearRGBColorSpaceRef()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to