<rdar://problem/9052166> Emphasis marks appear over combined text rather than beside it
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Mar 2011 23:11:48 +0000 (23:11 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Mar 2011 23:11:48 +0000 (23:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=56480

Reviewed by Beth Dakin.

Source/WebCore:

Test: fast/text/emphasis-combined-text.html

* rendering/InlineTextBox.cpp:
(WebCore::rotation): Added this helper.
(WebCore::InlineTextBox::paint): Paint a single emphasis mark beside the combined text,
centered vertically.

LayoutTests:

* fast/text/emphasis-combined-text.html: Added.
* platform/mac/fast/text/emphasis-combined-text-expected.checksum: Added.
* platform/mac/fast/text/emphasis-combined-text-expected.png: Added.
* platform/mac/fast/text/emphasis-combined-text-expected.txt: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/text/emphasis-combined-text.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/text/emphasis-combined-text-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/fast/text/emphasis-combined-text-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/text/emphasis-combined-text-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/InlineTextBox.cpp

index dc6704874a4857d8e6b4b2f4a657d69138d3ee39..0e8e2b7d0ed9ec4b906e5c40511a4a7eaa13b6dd 100644 (file)
@@ -1,3 +1,15 @@
+2011-03-17  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Beth Dakin.
+
+        <rdar://problem/9052166> Emphasis marks appear over combined text rather than beside it
+        https://bugs.webkit.org/show_bug.cgi?id=56480
+
+        * fast/text/emphasis-combined-text.html: Added.
+        * platform/mac/fast/text/emphasis-combined-text-expected.checksum: Added.
+        * platform/mac/fast/text/emphasis-combined-text-expected.png: Added.
+        * platform/mac/fast/text/emphasis-combined-text-expected.txt: Added.
+
 2011-03-17  Jian Li  <jianli@chromium.org>
 
         Reviewed by Adam Barth.
diff --git a/LayoutTests/fast/text/emphasis-combined-text.html b/LayoutTests/fast/text/emphasis-combined-text.html
new file mode 100644 (file)
index 0000000..91ebfec
--- /dev/null
@@ -0,0 +1,25 @@
+<meta charset="utf-8">
+<style>
+html {
+    -webkit-writing-mode: vertical-rl;
+}
+
+p {
+    font-family: "hiragino mincho pron";
+    font-size: 48px;
+}
+
+.combine {
+    -webkit-text-combine: horizontal;
+}
+
+</style>
+<p>
+    <span  style="-webkit-text-emphasis: sesame red">文字<span class="combine">900</span>年</span>
+</p>
+<p>
+    <span  style="-webkit-text-emphasis: '@' red">文字<span class="combine">900</span>年</span>
+</p>
+<p>
+    <span  style="-webkit-text-emphasis: '年' red">文字<span class="combine">900</span>年</span>
+</p>
diff --git a/LayoutTests/platform/mac/fast/text/emphasis-combined-text-expected.checksum b/LayoutTests/platform/mac/fast/text/emphasis-combined-text-expected.checksum
new file mode 100644 (file)
index 0000000..8c48ea5
--- /dev/null
@@ -0,0 +1 @@
+ba904f9d02a994a31770d7a54f121042
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/text/emphasis-combined-text-expected.png b/LayoutTests/platform/mac/fast/text/emphasis-combined-text-expected.png
new file mode 100644 (file)
index 0000000..f55909d
Binary files /dev/null and b/LayoutTests/platform/mac/fast/text/emphasis-combined-text-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/text/emphasis-combined-text-expected.txt b/LayoutTests/platform/mac/fast/text/emphasis-combined-text-expected.txt
new file mode 100644 (file)
index 0000000..d78fd71
--- /dev/null
@@ -0,0 +1,35 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 744x584
+      RenderBlock {P} at (0,0) size 84x584
+        RenderInline {SPAN} at (0,0) size 48x194
+          RenderText {#text} at (24,0) size 48x97
+            text run at (24,0) width 97: "\x{6587}\x{5B57}"
+          RenderInline {SPAN} at (0,0) size 48x49
+            RenderCombineText {#text} at (24,96) size 48x49
+              text run at (24,96) width 48: "\x{FFFC}"
+          RenderText {#text} at (24,144) size 48x50
+            text run at (24,144) width 49: "\x{5E74}"
+        RenderText {#text} at (0,0) size 0x0
+      RenderBlock {P} at (132,0) size 84x584
+        RenderInline {SPAN} at (0,0) size 48x194
+          RenderText {#text} at (24,0) size 48x97
+            text run at (24,0) width 97: "\x{6587}\x{5B57}"
+          RenderInline {SPAN} at (0,0) size 48x49
+            RenderCombineText {#text} at (24,96) size 48x49
+              text run at (24,96) width 48: "\x{FFFC}"
+          RenderText {#text} at (24,144) size 48x50
+            text run at (24,144) width 49: "\x{5E74}"
+        RenderText {#text} at (0,0) size 0x0
+      RenderBlock {P} at (264,0) size 84x584
+        RenderInline {SPAN} at (0,0) size 48x194
+          RenderText {#text} at (24,0) size 48x97
+            text run at (24,0) width 97: "\x{6587}\x{5B57}"
+          RenderInline {SPAN} at (0,0) size 48x49
+            RenderCombineText {#text} at (24,96) size 48x49
+              text run at (24,96) width 48: "\x{FFFC}"
+          RenderText {#text} at (24,144) size 48x50
+            text run at (24,144) width 49: "\x{5E74}"
+        RenderText {#text} at (0,0) size 0x0
index 04e6038e424607582ca3c208c03f8f75ad561769..70fdcd8ca4bfbee0fda27c508c402579422cfcb5 100644 (file)
@@ -1,3 +1,17 @@
+2011-03-17  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Beth Dakin.
+
+        <rdar://problem/9052166> Emphasis marks appear over combined text rather than beside it
+        https://bugs.webkit.org/show_bug.cgi?id=56480
+
+        Test: fast/text/emphasis-combined-text.html
+
+        * rendering/InlineTextBox.cpp:
+        (WebCore::rotation): Added this helper.
+        (WebCore::InlineTextBox::paint): Paint a single emphasis mark beside the combined text,
+        centered vertically.
+
 2011-03-17  Jian Li  <jianli@chromium.org>
 
         Reviewed by Adam Barth.
index 3c3e4505379cddceb7f95a168da0aaaf479db59b..04b6c5390a7e1884c2cc5b1e89910d96b25a654b 100644 (file)
@@ -427,6 +427,14 @@ bool InlineTextBox::getEmphasisMarkPosition(RenderStyle* style, TextEmphasisPosi
     return !rubyText || !rubyText->firstLineBox();
 }
 
+enum RotationDirection { Counterclockwise, Clockwise };
+
+static inline AffineTransform rotation(const FloatRect& boxRect, RotationDirection clockwise)
+{
+    return clockwise ? AffineTransform(0, 1, -1, 0, boxRect.x() + boxRect.maxY(), boxRect.maxY() - boxRect.x())
+        : AffineTransform(0, -1, 1, 0, boxRect.x() - boxRect.maxY(), boxRect.x() + boxRect.maxY());
+}
+
 void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
 {
     if (isLineBreak() || !paintInfo.shouldPaintWithinRoot(renderer()) || renderer()->style()->visibility() != VISIBLE ||
@@ -485,26 +493,22 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
     FloatPoint boxOrigin = locationIncludingFlipping();
     boxOrigin.move(tx, ty);    
     FloatRect boxRect(boxOrigin, IntSize(logicalWidth(), logicalHeight()));
-    FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + styleToUse->fontMetrics().ascent());
 
-    RenderCombineText* combinedText = styleToUse->hasTextCombine() ? toRenderCombineText(textRenderer()) : 0;
-    bool shouldRotate = !isHorizontal() && (!combinedText || !combinedText->isCombined());
-    if (shouldRotate) {
-        context->save();
-        context->translate(boxRect.x(), boxRect.maxY());
-        context->rotate(static_cast<float>(deg2rad(90.)));
-        context->translate(-boxRect.x(), -boxRect.maxY());
-    }
-    
-    
+    RenderCombineText* combinedText = styleToUse->hasTextCombine() && toRenderCombineText(textRenderer())->isCombined() ? toRenderCombineText(textRenderer()) : 0;
+
+    bool shouldRotate = !isHorizontal() && !combinedText;
+    if (shouldRotate)
+        context->concatCTM(rotation(boxRect, Clockwise));
+
     // Determine whether or not we have composition underlines to draw.
     bool containsComposition = renderer()->node() && renderer()->frame()->editor()->compositionNode() == renderer()->node();
     bool useCustomUnderlines = containsComposition && renderer()->frame()->editor()->compositionUsesCustomUnderlines();
 
     // Set our font.
-    int d = styleToUse->textDecorationsInEffect();
     const Font& font = styleToUse->font();
 
+    FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().ascent());
+
     if (combinedText)
         combinedText->adjustTextOrigin(textOrigin, boxRect);
 
@@ -653,11 +657,21 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
 
         if (!emphasisMark.isEmpty()) {
             updateGraphicsContext(context, emphasisMarkColor, textStrokeColor, textStrokeWidth, styleToUse->colorSpace());
+
+            static TextRun objectReplacementCharacterTextRun(&objectReplacementCharacter, 1);
+            TextRun& emphasisMarkTextRun = combinedText ? objectReplacementCharacterTextRun : textRun;
+            FloatPoint emphasisMarkTextOrigin = combinedText ? FloatPoint(boxOrigin.x() + boxRect.width() / 2, boxOrigin.y() + font.fontMetrics().ascent()) : textOrigin;
+            if (combinedText)
+                context->concatCTM(rotation(boxRect, Clockwise));
+
             if (!paintSelectedTextSeparately || ePos <= sPos) {
                 // FIXME: Truncate right-to-left text correctly.
-                paintTextWithShadows(context, font, textRun, emphasisMark, emphasisMarkOffset, 0, length, length, textOrigin, boxRect, textShadow, textStrokeWidth > 0, isHorizontal());
+                paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, 0, length, length, emphasisMarkTextOrigin, boxRect, textShadow, textStrokeWidth > 0, isHorizontal());
             } else
-                paintTextWithShadows(context, font, textRun, emphasisMark, emphasisMarkOffset, ePos, sPos, length, textOrigin, boxRect, textShadow, textStrokeWidth > 0, isHorizontal());
+                paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, ePos, sPos, length, emphasisMarkTextOrigin, boxRect, textShadow, textStrokeWidth > 0, isHorizontal());
+
+            if (combinedText)
+                context->concatCTM(rotation(boxRect, Counterclockwise));
         }
 
         if (textStrokeWidth > 0)
@@ -673,16 +687,27 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
         paintTextWithShadows(context, font, textRun, nullAtom, 0, sPos, ePos, length, textOrigin, boxRect, selectionShadow, selectionStrokeWidth > 0, isHorizontal());
         if (!emphasisMark.isEmpty()) {
             updateGraphicsContext(context, selectionEmphasisMarkColor, textStrokeColor, textStrokeWidth, styleToUse->colorSpace());
-            paintTextWithShadows(context, font, textRun, emphasisMark, emphasisMarkOffset, sPos, ePos, length, textOrigin, boxRect, selectionShadow, selectionStrokeWidth > 0, isHorizontal());
+
+            static TextRun objectReplacementCharacterTextRun(&objectReplacementCharacter, 1);
+            TextRun& emphasisMarkTextRun = combinedText ? objectReplacementCharacterTextRun : textRun;
+            FloatPoint emphasisMarkTextOrigin = combinedText ? FloatPoint(boxOrigin.x() + boxRect.width() / 2, boxOrigin.y() + font.fontMetrics().ascent()) : textOrigin;
+            if (combinedText)
+                context->concatCTM(rotation(boxRect, Clockwise));
+
+            paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, sPos, ePos, length, emphasisMarkTextOrigin, boxRect, selectionShadow, selectionStrokeWidth > 0, isHorizontal());
+
+            if (combinedText)
+                context->concatCTM(rotation(boxRect, Counterclockwise));
         }
         if (selectionStrokeWidth > 0)
             context->restore();
     }
 
     // Paint decorations
-    if (d != TDNONE && paintInfo.phase != PaintPhaseSelection) {
+    int textDecorations = styleToUse->textDecorationsInEffect();
+    if (textDecorations != TDNONE && paintInfo.phase != PaintPhaseSelection) {
         updateGraphicsContext(context, textFillColor, textStrokeColor, textStrokeWidth, styleToUse->colorSpace());
-        paintDecoration(context, boxOrigin, d, textShadow);
+        paintDecoration(context, boxOrigin, textDecorations, textShadow);
     }
 
     if (paintInfo.phase == PaintPhaseForeground) {
@@ -715,7 +740,7 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty)
     }
     
     if (shouldRotate)
-        context->restore();
+        context->concatCTM(rotation(boxRect, Counterclockwise));
 }
 
 void InlineTextBox::selectionStartEnd(int& sPos, int& ePos)