<rdar://problem/10475450> Synthetic bold is illegible under some scaling transforms
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Feb 2012 00:59:11 +0000 (00:59 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Feb 2012 00:59:11 +0000 (00:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78044

Reviewed by Beth Dakin.

Source/WebCore:

Tests: fast/text/synthetic-bold-transformed-expected.html
       fast/text/synthetic-bold-transformed.html

* platform/graphics/mac/FontMac.mm:
(WebCore::Font::drawGlyphs): Changed to interpret syntheticBoldOffset as a length in device pixels.

LayoutTests:

* fast/text/synthetic-bold-transformed-expected.html: Added.
* fast/text/synthetic-bold-transformed.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/text/synthetic-bold-transformed-expected.html [new file with mode: 0644]
LayoutTests/fast/text/synthetic-bold-transformed.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/mac/FontMac.mm

index a771e89cfa5ba6e27b8f69cb7669ac2987b8f274..21c45ff905d7262e9ec1d6e02be9ebb80137bfa9 100644 (file)
@@ -1,3 +1,13 @@
+2012-02-07  Dan Bernstein  <mitz@apple.com>
+
+        <rdar://problem/10475450> Synthetic bold is illegible under some scaling transforms
+        https://bugs.webkit.org/show_bug.cgi?id=78044
+
+        Reviewed by Beth Dakin.
+
+        * fast/text/synthetic-bold-transformed-expected.html: Added.
+        * fast/text/synthetic-bold-transformed.html: Added.
+
 2012-02-07  Adam Klein  <adamk@chromium.org>
 
         Add JSC support for delivering mutations when the outermost script context exits
diff --git a/LayoutTests/fast/text/synthetic-bold-transformed-expected.html b/LayoutTests/fast/text/synthetic-bold-transformed-expected.html
new file mode 100644 (file)
index 0000000..8d3be39
--- /dev/null
@@ -0,0 +1,4 @@
+<div style="position: relative;">
+    <div style="-webkit-transform-origin: 0 0; -webkit-transform: scale(8); font-family: STSong;">|</div>
+    <div style="position: absolute; top: 0; -webkit-transform-origin: 0 0; -webkit-transform: translatex(1px) scale(8); font-family: STSong;">|</div>
+</div>
diff --git a/LayoutTests/fast/text/synthetic-bold-transformed.html b/LayoutTests/fast/text/synthetic-bold-transformed.html
new file mode 100644 (file)
index 0000000..426f6ce
--- /dev/null
@@ -0,0 +1 @@
+<div style="-webkit-transform-origin: 0 0; -webkit-transform: scale(8); font-family: STSong; font-weight: bold;">|</div>
index ae1c8b9e111010f6f56ba810badf9c1f16c5313a..57897609ce89d680c38a18fcaddb249e42e94139 100644 (file)
@@ -1,3 +1,16 @@
+2012-02-07  Dan Bernstein  <mitz@apple.com>
+
+        <rdar://problem/10475450> Synthetic bold is illegible under some scaling transforms
+        https://bugs.webkit.org/show_bug.cgi?id=78044
+
+        Reviewed by Beth Dakin.
+
+        Tests: fast/text/synthetic-bold-transformed-expected.html
+               fast/text/synthetic-bold-transformed.html
+
+        * platform/graphics/mac/FontMac.mm:
+        (WebCore::Font::drawGlyphs): Changed to interpret syntheticBoldOffset as a length in device pixels.
+
 2012-02-07  Levi Weintraub  <leviw@chromium.org>
 
         Update LayoutUnit usage in ColumnInfo and RenderFrameSet
index 8e23339f736947d7e2748686ec9517540c8706f7..4afb5fbdbf7944c94aa2eb53aa5a844b202782ff 100644 (file)
@@ -222,7 +222,16 @@ void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* font, cons
     ColorSpace fillColorSpace = context->fillColorSpace();
     context->getShadow(shadowOffset, shadowBlur, shadowColor, shadowColorSpace);
 
-    bool hasSimpleShadow = context->textDrawingMode() == TextModeFill && shadowColor.isValid() && !shadowBlur && !platformData.isColorBitmapFont() && (!context->shadowsIgnoreTransforms() || context->getCTM().isIdentityOrTranslationOrFlipped()) && !context->isInTransparencyLayer();
+    AffineTransform contextCTM = context->getCTM();
+    float syntheticBoldOffset = font->syntheticBoldOffset();
+    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;
+    };
+
+    bool hasSimpleShadow = context->textDrawingMode() == TextModeFill && shadowColor.isValid() && !shadowBlur && !platformData.isColorBitmapFont() && (!context->shadowsIgnoreTransforms() || contextCTM.isIdentityOrTranslationOrFlipped()) && !context->isInTransparencyLayer();
     if (hasSimpleShadow) {
         // Paint simple shadows ourselves instead of relying on CG shadows, to avoid losing subpixel antialiasing.
         context->clearShadow();
@@ -233,14 +242,14 @@ void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* font, cons
         // If shadows are ignoring transforms, then we haven't applied the Y coordinate flip yet, so down is negative.
         float shadowTextY = point.y() + shadowOffset.height() * (context->shadowsIgnoreTransforms() ? -1 : 1);
         showGlyphsWithAdvances(FloatPoint(shadowTextX, shadowTextY), font, cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
-        if (font->syntheticBoldOffset())
-            showGlyphsWithAdvances(FloatPoint(shadowTextX + font->syntheticBoldOffset(), shadowTextY), font, cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
+        if (syntheticBoldOffset)
+            showGlyphsWithAdvances(FloatPoint(shadowTextX + syntheticBoldOffset, shadowTextY), font, cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
         context->setFillColor(fillColor, fillColorSpace);
     }
 
     showGlyphsWithAdvances(point, font, cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
-    if (font->syntheticBoldOffset())
-        showGlyphsWithAdvances(FloatPoint(point.x() + font->syntheticBoldOffset(), point.y()), font, cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
+    if (syntheticBoldOffset)
+        showGlyphsWithAdvances(FloatPoint(point.x() + syntheticBoldOffset, point.y()), font, cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs);
 
     if (hasSimpleShadow)
         context->setShadow(shadowOffset, shadowBlur, shadowColor, shadowColorSpace);