text-combine needs to center text within the vertical space using glyph bounds
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Oct 2014 01:00:36 +0000 (01:00 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Oct 2014 01:00:36 +0000 (01:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138056
<rdar://problem/15403667>

Reviewed by Dean Jackson.

Source/WebCore:

Added fast/text/tatechuyoko.html

* rendering/RenderCombineText.cpp:
(WebCore::RenderCombineText::RenderCombineText):
(WebCore::RenderCombineText::adjustTextOrigin):
(WebCore::RenderCombineText::combineText):
* rendering/RenderCombineText.h:

LayoutTests:

* fast/text/tatechuyoko.html: Added.
* platform/mac/fast/text/tatechuyoko-expected.png: Added.
* platform/mac/fast/text/tatechuyoko-expected.txt: Added.

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

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

index e06c51e..67edfa6 100644 (file)
@@ -1,3 +1,15 @@
+2014-10-24  David Hyatt  <hyatt@apple.com>
+
+        text-combine needs to center text within the vertical space using glyph bounds
+        https://bugs.webkit.org/show_bug.cgi?id=138056
+        <rdar://problem/15403667>
+
+        Reviewed by Dean Jackson.
+
+        * fast/text/tatechuyoko.html: Added.
+        * platform/mac/fast/text/tatechuyoko-expected.png: Added.
+        * platform/mac/fast/text/tatechuyoko-expected.txt: Added.
+
 2014-10-27  Alexey Proskuryakov  <ap@apple.com>
 
         http/tests/cookies/third-party-cookie-relaxing.html is flaky on bots
diff --git a/LayoutTests/fast/text/tatechuyoko.html b/LayoutTests/fast/text/tatechuyoko.html
new file mode 100644 (file)
index 0000000..eb5f25f
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ibooks="http://apple.com/ibooks/html-extensions" xmlns:epub="http://www.idpf.org/2007/ops">\r
+<head>\r
+<title>Text-Combine</title>\r
+<style>\r
+.text-combine{\r
+-webkit-text-combine: horizontal;\r
+}\r
+.vertical{\r
+-webkit-writing-mode:vertical-rl;\r
+}\r
+</style>\r
+</head>\r
+<body>\r
+<p>「向見論治道書,其間欲仿井田之意<span class="text-combine">12</span>,而科條州郡財賦之類,此固為治之具。然施之當有次第。今日先務,恐當啟迪主心</p>\r
+<p class="vertical">「向見論治道書,其間欲仿井田之意<span class="text-combine">12</span>,而科條州郡財賦之類,此固為治之具。然施之當有次第。今日先務,恐當啟迪主心</p>\r
+\r
+</body>\r
+</html>\r
+\r
diff --git a/LayoutTests/platform/mac/fast/text/tatechuyoko-expected.png b/LayoutTests/platform/mac/fast/text/tatechuyoko-expected.png
new file mode 100644 (file)
index 0000000..d3f6e05
Binary files /dev/null and b/LayoutTests/platform/mac/fast/text/tatechuyoko-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/text/tatechuyoko-expected.txt b/LayoutTests/platform/mac/fast/text/tatechuyoko-expected.txt
new file mode 100644 (file)
index 0000000..58b8739
--- /dev/null
@@ -0,0 +1,23 @@
+layer at (0,0) size 785x668
+  RenderView at (0,0) size 785x600
+layer at (0,0) size 785x668
+  RenderBlock {HTML} at (0,0) size 785x668
+    RenderBody {BODY} at (8,16) size 769x644
+      RenderBlock {P} at (0,0) size 769x44
+        RenderText {#text} at (0,3) size 256x18
+          text run at (0,3) width 256: "\x{300C}\x{5411}\x{898B}\x{8AD6}\x{6CBB}\x{9053}\x{66F8}\x{FF0C}\x{5176}\x{9593}\x{6B32}\x{4EFF}\x{4E95}\x{7530}\x{4E4B}\x{610F}"
+        RenderInline {SPAN} at (0,0) size 16x18
+          RenderCombineText {#text} at (256,3) size 16x18
+            text run at (256,3) width 16: "12"
+        RenderText {#text} at (272,3) size 768x40
+          text run at (272,3) width 496: "\x{FF0C}\x{800C}\x{79D1}\x{689D}\x{5DDE}\x{90E1}\x{8CA1}\x{8CE6}\x{4E4B}\x{985E}\x{FF0C}\x{6B64}\x{56FA}\x{70BA}\x{6CBB}\x{4E4B}\x{5177}\x{3002}\x{7136}\x{65BD}\x{4E4B}\x{7576}\x{6709}\x{6B21}\x{7B2C}\x{3002}\x{4ECA}\x{65E5}\x{5148}\x{52D9}\x{FF0C}"
+          text run at (0,25) width 96: "\x{6050}\x{7576}\x{555F}\x{8FEA}\x{4E3B}\x{5FC3}"
+      RenderBlock {P} at (16,60) size 44x584
+        RenderText {#text} at (2,0) size 18x256
+          text run at (2,0) width 256: "\x{300C}\x{5411}\x{898B}\x{8AD6}\x{6CBB}\x{9053}\x{66F8}\x{FF0C}\x{5176}\x{9593}\x{6B32}\x{4EFF}\x{4E95}\x{7530}\x{4E4B}\x{610F}"
+        RenderInline {SPAN} at (0,0) size 18x16
+          RenderCombineText {#text} at (2,256) size 18x16
+            text run at (2,256) width 16: "\x{FFFC}"
+        RenderText {#text} at (2,272) size 40x560
+          text run at (2,272) width 288: "\x{FF0C}\x{800C}\x{79D1}\x{689D}\x{5DDE}\x{90E1}\x{8CA1}\x{8CE6}\x{4E4B}\x{985E}\x{FF0C}\x{6B64}\x{56FA}\x{70BA}\x{6CBB}\x{4E4B}\x{5177}\x{3002}"
+          text run at (24,0) width 304: "\x{7136}\x{65BD}\x{4E4B}\x{7576}\x{6709}\x{6B21}\x{7B2C}\x{3002}\x{4ECA}\x{65E5}\x{5148}\x{52D9}\x{FF0C}\x{6050}\x{7576}\x{555F}\x{8FEA}\x{4E3B}\x{5FC3}"
index 5c8f8b0..3693745 100644 (file)
@@ -1,3 +1,19 @@
+2014-10-24  David Hyatt  <hyatt@apple.com>
+
+        text-combine needs to center text within the vertical space using glyph bounds
+        https://bugs.webkit.org/show_bug.cgi?id=138056
+        <rdar://problem/15403667>
+
+        Reviewed by Dean Jackson.
+
+        Added fast/text/tatechuyoko.html
+
+        * rendering/RenderCombineText.cpp:
+        (WebCore::RenderCombineText::RenderCombineText):
+        (WebCore::RenderCombineText::adjustTextOrigin):
+        (WebCore::RenderCombineText::combineText):
+        * rendering/RenderCombineText.h:
+
 2014-10-27  Benjamin Poulain  <benjamin@webkit.org>
 
         Cleanup after r175213: fastGetAttribute().isNull() should be fastHasAttribute()
index 3f013db..59aa5c8 100644 (file)
@@ -30,7 +30,6 @@ const float textCombineMargin = 1.15f; // Allow em + 15% margin
 
 RenderCombineText::RenderCombineText(Text& textNode, PassRefPtr<StringImpl> string)
     : RenderText(textNode, string)
-    , m_combinedTextWidth(0)
     , m_isCombined(false)
     , m_needsFontUpdate(false)
 {
@@ -69,7 +68,7 @@ float RenderCombineText::width(unsigned from, unsigned length, const Font& font,
 void RenderCombineText::adjustTextOrigin(FloatPoint& textOrigin, const FloatRect& boxRect) const
 {
     if (m_isCombined)
-        textOrigin.move(boxRect.height() / 2 - ceilf(m_combinedTextWidth) / 2, style().font().pixelSize());
+        textOrigin.move(boxRect.height() / 2 - ceilf(m_combinedTextSize.width()) / 2, boxRect.width() + (boxRect.width() - m_combinedTextSize.height()) / 2);
 }
 
 void RenderCombineText::getStringToRender(int start, String& string, int& length) const
@@ -97,15 +96,18 @@ void RenderCombineText::combineText()
     if (style().isHorizontalWritingMode())
         return;
 
-    TextRun run = RenderBlock::constructTextRun(this, originalFont(), this, style());
     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 = originalFont().width(run);
-    m_isCombined = m_combinedTextWidth <= emWidth;
-
+    
+    GlyphOverflow glyphOverflow;
+    glyphOverflow.computeBounds = true;
+    
+    float combinedTextWidth = width(0, textLength(), originalFont(), 0, nullptr, &glyphOverflow);
+    m_isCombined = combinedTextWidth <= emWidth;
+    
     FontSelector* fontSelector = style().font().fontSelector();
 
     if (m_isCombined)
@@ -117,9 +119,10 @@ void RenderCombineText::combineText()
             description.setWidthVariant(widthVariants[i]);
             Font compressedFont = Font(description, style().font().letterSpacing(), style().font().wordSpacing());
             compressedFont.update(fontSelector);
-            float runWidth = compressedFont.width(run);
+            
+            float runWidth = RenderText::width(0, textLength(), compressedFont, 0, nullptr, &glyphOverflow);
             if (runWidth <= emWidth) {
-                m_combinedTextWidth = runWidth;
+                combinedTextWidth = runWidth;
                 m_isCombined = true;
 
                 // Replace my font with the new one.
@@ -138,6 +141,7 @@ void RenderCombineText::combineText()
     if (m_isCombined) {
         DEPRECATED_DEFINE_STATIC_LOCAL(String, objectReplacementCharacterString, (&objectReplacementCharacter, 1));
         RenderText::setRenderedText(objectReplacementCharacterString.impl());
+        m_combinedTextSize = FloatSize(combinedTextWidth, glyphOverflow.bottom + glyphOverflow.top);
     }
 }
 
index 01be4d6..11b2855 100644 (file)
@@ -52,7 +52,7 @@ private:
     virtual void setRenderedText(const String&) override;
 
     RefPtr<RenderStyle> m_combineFontStyle;
-    float m_combinedTextWidth;
+    FloatSize m_combinedTextSize;
     bool m_isCombined : 1;
     bool m_needsFontUpdate : 1;
 };