OSDN Git Service

Fix SVG text rendering
authorSteve Block <steveblock@google.com>
Thu, 24 Nov 2011 14:02:29 +0000 (14:02 +0000)
committerSteve Block <steveblock@google.com>
Thu, 24 Nov 2011 14:02:29 +0000 (14:02 +0000)
Android's implementation of GraphicsContext::setCTM() is broken, because Skia's
Picture mode does not support setMatrix(). This broken code was added in
https://android-git.corp.google.com/g/#/c/112636 as part of the merge to WebKit
r80534.

This change modifies SVGInlineTextBox to avoid calling
GraphicsContext::setCTM() and makes clear that the method should not be used.

Bug: 5590123
Change-Id: I45a3c8c356b7f068bb943a45b9f10cbc041331e2

Source/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp
Source/WebCore/rendering/svg/SVGInlineTextBox.cpp

index f647673..a490d5f 100644 (file)
@@ -1207,10 +1207,11 @@ AffineTransform GraphicsContext::getCTM() const
 
 void GraphicsContext::setCTM(const AffineTransform& transform)
 {
-    if (paintingDisabled())
-        return;
-
-    GC2CANVAS(this)->setMatrix(transform);
+    // The SkPicture mode of Skia does not support SkCanvas::setMatrix(), so we
+    // can not simply use that method here. We could calculate the transform
+    // required to achieve the desired matrix and use SkCanvas::concat(), but
+    // there's currently no need for this.
+    ASSERT_NOT_REACHED();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index bc550a6..bb34652 100644 (file)
@@ -573,11 +573,18 @@ void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, ETextD
         width *= scalingFactor;
         decorationOrigin.scale(scalingFactor, scalingFactor);
 
+#if PLATFORM(ANDROID)
+        // Android does not support GraphicsContext::setCTM().
+        AffineTransform scaleTransform;
+        scaleTransform.scale(1 / scalingFactor);
+        context->concatCTM(scaleTransform);
+#else
         AffineTransform newTransform = context->getCTM();
         newTransform.scale(1 / scalingFactor);
         normalizeTransform(newTransform);
 
         context->setCTM(newTransform);
+#endif
     }
 
     decorationOrigin.move(0, -scaledFontMetrics.floatAscent() + positionOffsetForDecoration(decoration, scaledFontMetrics, thickness));
@@ -622,6 +629,13 @@ void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyl
 
         AffineTransform originalTransform;
         if (scalingFactor != 1) {
+#if PLATFORM(ANDROID)
+            // Android does not support GraphicsContext::setCTM().
+            context->save();
+            AffineTransform scaleTransform;
+            scaleTransform.scale(1 / scalingFactor);
+            context->concatCTM(scaleTransform);
+#else
             originalTransform = context->getCTM();
 
             AffineTransform newTransform = originalTransform;
@@ -629,12 +643,18 @@ void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyl
             normalizeTransform(newTransform);
 
             context->setCTM(newTransform);
+#endif
         }
 
         scaledFont.drawText(context, textRun, textOrigin + extraOffset, startPosition, endPosition);
 
         if (scalingFactor != 1)
+#if PLATFORM(ANDROID)
+            // Android does not support GraphicsContext::setCTM().
+            context->restore();
+#else
             context->setCTM(originalTransform);
+#endif
 
         restoreGraphicsContextAfterTextPainting(context, textRun);