text-combine text retains compressed font after adding characters to it
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Mar 2011 16:27:25 +0000 (16:27 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Mar 2011 16:27:25 +0000 (16:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=56448

Reviewed by Simon Fraser.

Source/WebCore:

Test: fast/dynamic/text-combine.html

* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyProperty): Allow styles with text-combine to be shared, since
only the clones on the RenderCombineText will be mutated.
* rendering/RenderCombineText.cpp:
(WebCore::RenderCombineText::styleDidChange): Clone the style, to avoid mutating the parent’s
style.
(WebCore::RenderCombineText::combineText): Start off with the original font; restore it if
the text cannot be combined.
* rendering/RenderCombineText.h:
(WebCore::RenderCombineText::originalFont): Added. Returns the parent’s font.

LayoutTests:

* fast/dynamic/text-combine.html: Added.
* platform/mac/fast/dynamic/text-combine-expected.checksum: Added.
* platform/mac/fast/dynamic/text-combine-expected.png: Added.
* platform/mac/fast/dynamic/text-combine-expected.txt: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/dynamic/text-combine.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/dynamic/text-combine-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/fast/dynamic/text-combine-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/dynamic/text-combine-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSStyleSelector.cpp
Source/WebCore/rendering/RenderCombineText.cpp
Source/WebCore/rendering/RenderCombineText.h

index f82b2da..3e150e6 100644 (file)
@@ -1,3 +1,15 @@
+2011-03-16  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Simon Fraser.
+
+        text-combine text retains compressed font after adding characters to it
+        https://bugs.webkit.org/show_bug.cgi?id=56448
+
+        * fast/dynamic/text-combine.html: Added.
+        * platform/mac/fast/dynamic/text-combine-expected.checksum: Added.
+        * platform/mac/fast/dynamic/text-combine-expected.png: Added.
+        * platform/mac/fast/dynamic/text-combine-expected.txt: Added.
+
 2011-03-16  Adam Roben  <aroben@apple.com>
 
         Disable jquery/effects.html
diff --git a/LayoutTests/fast/dynamic/text-combine.html b/LayoutTests/fast/dynamic/text-combine.html
new file mode 100644 (file)
index 0000000..0f4f20c
--- /dev/null
@@ -0,0 +1,19 @@
+<meta charset="utf8">
+<style>
+    html { -webkit-writing-mode: vertical-rl; }
+    div { font-family: 'hiragino mincho pro'; font-size: 24px; }
+    #combine { -webkit-text-combine: horizontal; }
+</style>
+<p>
+    These two lines should be identical:
+</p>
+<div>
+    希薄化後の1株当り利益が<span id="combine">3.67</span>ドルでした。
+</div>
+<div>
+    希薄化後の1株当り利益が<span>3.667</span>ドルでした。
+</div>
+<script>
+    document.body.offsetTop;
+    document.getElementById("combine").textContent = "3.667";
+</script>
diff --git a/LayoutTests/platform/mac/fast/dynamic/text-combine-expected.checksum b/LayoutTests/platform/mac/fast/dynamic/text-combine-expected.checksum
new file mode 100644 (file)
index 0000000..a68395e
--- /dev/null
@@ -0,0 +1 @@
+28cec0b94e55237d4101f782f8118d5f
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/dynamic/text-combine-expected.png b/LayoutTests/platform/mac/fast/dynamic/text-combine-expected.png
new file mode 100644 (file)
index 0000000..b1e798a
Binary files /dev/null and b/LayoutTests/platform/mac/fast/dynamic/text-combine-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/dynamic/text-combine-expected.txt b/LayoutTests/platform/mac/fast/dynamic/text-combine-expected.txt
new file mode 100644 (file)
index 0000000..945da5f
--- /dev/null
@@ -0,0 +1,24 @@
+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 784x584
+      RenderBlock {P} at (0,0) size 18x584
+        RenderText {#text} at (0,0) size 18x225
+          text run at (0,0) width 225: "These two lines should be identical:"
+      RenderBlock {DIV} at (34,0) size 36x584
+        RenderText {#text} at (6,0) size 24x281
+          text run at (6,0) width 281: "\x{5E0C}\x{8584}\x{5316}\x{5F8C}\x{306E}1\x{682A}\x{5F53}\x{308A}\x{5229}\x{76CA}\x{304C}"
+        RenderInline {SPAN} at (0,0) size 24x65
+          RenderCombineText {#text} at (6,280) size 24x65
+            text run at (6,280) width 65: "3.667"
+        RenderText {#text} at (6,344) size 24x146
+          text run at (6,344) width 146: "\x{30C9}\x{30EB}\x{3067}\x{3057}\x{305F}\x{3002}"
+      RenderBlock {DIV} at (70,0) size 36x584
+        RenderText {#text} at (6,0) size 24x281
+          text run at (6,0) width 281: "\x{5E0C}\x{8584}\x{5316}\x{5F8C}\x{306E}1\x{682A}\x{5F53}\x{308A}\x{5229}\x{76CA}\x{304C}"
+        RenderInline {SPAN} at (0,0) size 24x65
+          RenderText {#text} at (6,280) size 24x65
+            text run at (6,280) width 65: "3.667"
+        RenderText {#text} at (6,344) size 24x146
+          text run at (6,344) width 146: "\x{30C9}\x{30EB}\x{3067}\x{3057}\x{305F}\x{3002}"
index 15d66f2..9664b9b 100644 (file)
@@ -1,3 +1,23 @@
+2011-03-16  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Simon Fraser.
+
+        text-combine text retains compressed font after adding characters to it
+        https://bugs.webkit.org/show_bug.cgi?id=56448
+
+        Test: fast/dynamic/text-combine.html
+
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::applyProperty): Allow styles with text-combine to be shared, since
+        only the clones on the RenderCombineText will be mutated.
+        * rendering/RenderCombineText.cpp:
+        (WebCore::RenderCombineText::styleDidChange): Clone the style, to avoid mutating the parent’s
+        style.
+        (WebCore::RenderCombineText::combineText): Start off with the original font; restore it if
+        the text cannot be combined.
+        * rendering/RenderCombineText.h:
+        (WebCore::RenderCombineText::originalFont): Added. Returns the parent’s font.
+
 2011-03-14  Pavel Podivilov  <podivilov@chromium.org>
 
         Reviewed by Yury Semikhatsky.
index f8c45c6..2a0b926 100644 (file)
@@ -6100,8 +6100,6 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
 
     case CSSPropertyWebkitTextCombine:
         HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(textCombine, TextCombine)
-        if (m_style->hasTextCombine())
-            m_style->setUnique(); // The style could be modified in RenderCombineText depending on text metrics.
         return;
 
     case CSSPropertyWebkitTextEmphasisPosition:
index 250ec9b..37ca1ed 100644 (file)
@@ -37,6 +37,7 @@ RenderCombineText::RenderCombineText(Node* node, PassRefPtr<StringImpl> string)
 
 void RenderCombineText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
 {
+    setStyleInternal(RenderStyle::clone(style()));
     RenderText::styleDidChange(diff, oldStyle);
 
     if (m_isCombined)
@@ -93,12 +94,12 @@ void RenderCombineText::combineText()
         return;
 
     TextRun run = TextRun(String(text()));
-    FontDescription description = style()->font().fontDescription();
+    FontDescription description = originalFont().fontDescription();
     float emWidth = description.computedSize() * textCombineMargin;
     bool shouldUpdateFont = false;
 
     description.setOrientation(Horizontal); // We are going to draw combined text horizontally.
-    m_combinedTextWidth = style()->font().width(run);
+    m_combinedTextWidth = originalFont().width(run);
     m_isCombined = m_combinedTextWidth <= emWidth;
 
     if (m_isCombined)
@@ -122,12 +123,14 @@ void RenderCombineText::combineText()
         }
     }
 
+    if (!m_isCombined)
+        shouldUpdateFont = style()->setFontDescription(originalFont().fontDescription());
+
     if (shouldUpdateFont)
         style()->font().update(style()->font().fontSelector());
 
     if (m_isCombined) {
-        static const UChar newCharacter = objectReplacementCharacter;
-        DEFINE_STATIC_LOCAL(String, objectReplacementCharacterString, (&newCharacter, 1));
+        DEFINE_STATIC_LOCAL(String, objectReplacementCharacterString, (&objectReplacementCharacter, 1));
         RenderText::setTextInternal(objectReplacementCharacterString.impl());
     }
 }
index 9068555..406c3f6 100644 (file)
@@ -34,6 +34,7 @@ public:
     void charactersToRender(int start, const UChar*& characters, int& length) const;
     bool isCombined() const { return m_isCombined; }
     float combinedTextWidth(const Font& font) const { return font.size(); }
+    const Font& originalFont() const { return parent()->style()->font(); }
 
 private:
     virtual bool isCombineText() const { return true; }