[iOS] baidu.com: Synthetic bold renders too far apart, appears doubled.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 May 2019 20:30:05 +0000 (20:30 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 May 2019 20:30:05 +0000 (20:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197781
<rdar://problem/48027412>

Reviewed by Simon Fraser.

Source/WebCore:

Synthetic bold is essentially two regular glyphs painted with an offset. While on macOS this offset is always 1px (CSS), on iOS larger font produces higher offset value. At paint time, this offset value (in CSS px unit) get converted
to a device pixel value taking context scale into account. This conversion ensures that the gap between the 2 regular glyphs won't get wider (in device pixels) as the user pinch zooms in.
This works as long as the scale on the context is >= 1. This patch ensures that a scaled down context won't blow up this gap.

Test: fast/text/large-synthetic-bold-with-scale-transform.html

* platform/graphics/cocoa/FontCascadeCocoa.mm:
(WebCore::FontCascade::drawGlyphs):

LayoutTests:

* fast/text/large-synthetic-bold-with-scale-transform-expected.html: Added.
* fast/text/large-synthetic-bold-with-scale-transform.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/text/large-synthetic-bold-with-scale-transform-expected.html [new file with mode: 0644]
LayoutTests/fast/text/large-synthetic-bold-with-scale-transform.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm

index 7a8e888..512e521 100644 (file)
@@ -1,3 +1,14 @@
+2019-05-10  Zalan Bujtas  <zalan@apple.com>
+
+        [iOS] baidu.com: Synthetic bold renders too far apart, appears doubled.
+        https://bugs.webkit.org/show_bug.cgi?id=197781
+        <rdar://problem/48027412>
+
+        Reviewed by Simon Fraser.
+
+        * fast/text/large-synthetic-bold-with-scale-transform-expected.html: Added.
+        * fast/text/large-synthetic-bold-with-scale-transform.html: Added.
+
 2019-05-10  Simon Fraser  <simon.fraser@apple.com>
 
         ASSERT(isSelfPaintingLayer() || hasSelfPaintingLayerDescendant()) on nytimes.com after r245170
diff --git a/LayoutTests/fast/text/large-synthetic-bold-with-scale-transform-expected.html b/LayoutTests/fast/text/large-synthetic-bold-with-scale-transform-expected.html
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/LayoutTests/fast/text/large-synthetic-bold-with-scale-transform.html b/LayoutTests/fast/text/large-synthetic-bold-with-scale-transform.html
new file mode 100644 (file)
index 0000000..44702d0
--- /dev/null
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we don't end up painting large gaps for synthetic bold when tall text gets scaled down.</title>
+<style>
+       body {
+               font-family: 'Hiragino Maru Gothic ProN';
+               font-weight: bold;
+               font-size: 900px;
+               margin: 0px;
+       }
+
+       div {
+               transform: scale(0.01);
+               height: 20px;
+               width: 20px;
+       }
+
+       .cover {
+               transform: none;
+               background-color: white;
+               position: absolute;
+               top: 0px;
+               left: 0px;
+               height: 150px;
+               width: 20px;
+       }
+</style>
+</head>
+<body>
+<div>F</div>
+<div>o</div>
+<div>o</div>
+<div>B</div>
+<div>a</div>
+<div>r</div>
+<div class=cover></div>
+</div>
+</body>
+</html>
index eec131f..417f39f 100644 (file)
@@ -1,3 +1,20 @@
+2019-05-10  Zalan Bujtas  <zalan@apple.com>
+
+        [iOS] baidu.com: Synthetic bold renders too far apart, appears doubled.
+        https://bugs.webkit.org/show_bug.cgi?id=197781
+        <rdar://problem/48027412>
+
+        Reviewed by Simon Fraser.
+
+        Synthetic bold is essentially two regular glyphs painted with an offset. While on macOS this offset is always 1px (CSS), on iOS larger font produces higher offset value. At paint time, this offset value (in CSS px unit) get converted
+        to a device pixel value taking context scale into account. This conversion ensures that the gap between the 2 regular glyphs won't get wider (in device pixels) as the user pinch zooms in.
+        This works as long as the scale on the context is >= 1. This patch ensures that a scaled down context won't blow up this gap.
+
+        Test: fast/text/large-synthetic-bold-with-scale-transform.html
+
+        * platform/graphics/cocoa/FontCascadeCocoa.mm:
+        (WebCore::FontCascade::drawGlyphs):
+
 2019-05-10  Brent Fulgham  <bfulgham@apple.com>
 
         Gracefully handle inaccessible font face data
index 9ad8ffe..f599b4e 100644 (file)
@@ -276,8 +276,10 @@ void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const G
     if (syntheticBoldOffset && !contextCTM.isIdentityOrTranslationOrFlipped()) {
         FloatSize horizontalUnitSizeInDevicePixels = contextCTM.mapSize(FloatSize(1, 0));
         float horizontalUnitLengthInDevicePixels = sqrtf(horizontalUnitSizeInDevicePixels.width() * horizontalUnitSizeInDevicePixels.width() + horizontalUnitSizeInDevicePixels.height() * horizontalUnitSizeInDevicePixels.height());
-        if (horizontalUnitLengthInDevicePixels)
-            syntheticBoldOffset /= horizontalUnitLengthInDevicePixels;
+        if (horizontalUnitLengthInDevicePixels) {
+            // Make sure that a scaled down context won't blow up the gap between the glyphs. 
+            syntheticBoldOffset = std::min(syntheticBoldOffset, syntheticBoldOffset / horizontalUnitLengthInDevicePixels);
+        }
     };
 
     bool hasSimpleShadow = context.textDrawingMode() == TextModeFill && shadowColor.isValid() && !shadowBlur && !platformData.isColorBitmapFont() && (!context.shadowsIgnoreTransforms() || contextCTM.isIdentityOrTranslationOrFlipped()) && !context.isInTransparencyLayer();