[chromium] Font::drawComplexText can not draw a segment of text run
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Nov 2011 05:25:01 +0000 (05:25 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Nov 2011 05:25:01 +0000 (05:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72095

Patch by Robin Cao <robin.cao@torchmobile.com.cn> on 2011-11-17
Reviewed by Adam Barth.

Source/WebCore:

drawComplexText() should respect the 'from' and 'to' arguments.
Drawing the whole text run may result in text overlapping.

Test: platform/chromium-linux/fast/text/international/draw-complex-text-from-to.html

* platform/graphics/chromium/ComplexTextControllerLinux.cpp:
(WebCore::ComplexTextController::glyphsForRange):
* platform/graphics/chromium/ComplexTextControllerLinux.h:
* platform/graphics/chromium/FontLinux.cpp:
(WebCore::Font::drawComplexText):

LayoutTests:

* platform/chromium-linux/fast/text/international/draw-complex-text-from-to-expected.png: Added.
* platform/chromium-linux/fast/text/international/draw-complex-text-from-to-expected.txt: Added.
* platform/chromium-linux/fast/text/international/draw-complex-text-from-to.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/platform/chromium-linux/fast/text/international/draw-complex-text-from-to-expected.png [new file with mode: 0644]
LayoutTests/platform/chromium-linux/fast/text/international/draw-complex-text-from-to-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium-linux/fast/text/international/draw-complex-text-from-to.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/ComplexTextControllerLinux.cpp
Source/WebCore/platform/graphics/chromium/ComplexTextControllerLinux.h
Source/WebCore/platform/graphics/chromium/FontLinux.cpp

index 0514f9caf8fad70cbbad35f848e8cd1ae1237d95..ef49a7d5188e89a49ad4ea2f41fed1a5e404a279 100755 (executable)
@@ -1,3 +1,14 @@
+2011-11-17  Robin Cao  <robin.cao@torchmobile.com.cn>
+
+        [chromium] Font::drawComplexText can not draw a segment of text run
+        https://bugs.webkit.org/show_bug.cgi?id=72095
+
+        Reviewed by Adam Barth.
+
+        * platform/chromium-linux/fast/text/international/draw-complex-text-from-to-expected.png: Added.
+        * platform/chromium-linux/fast/text/international/draw-complex-text-from-to-expected.txt: Added.
+        * platform/chromium-linux/fast/text/international/draw-complex-text-from-to.html: Added.
+
 2011-11-17  Peter Kasting  <pkasting@google.com>
 
         [chromium] Fix broken expectation.
diff --git a/LayoutTests/platform/chromium-linux/fast/text/international/draw-complex-text-from-to-expected.png b/LayoutTests/platform/chromium-linux/fast/text/international/draw-complex-text-from-to-expected.png
new file mode 100644 (file)
index 0000000..13b8839
Binary files /dev/null and b/LayoutTests/platform/chromium-linux/fast/text/international/draw-complex-text-from-to-expected.png differ
diff --git a/LayoutTests/platform/chromium-linux/fast/text/international/draw-complex-text-from-to-expected.txt b/LayoutTests/platform/chromium-linux/fast/text/international/draw-complex-text-from-to-expected.txt
new file mode 100644 (file)
index 0000000..cc482a0
--- /dev/null
@@ -0,0 +1,3 @@
+The text and ellipsis should not overlap.
+
+هذا هو الاختبار
diff --git a/LayoutTests/platform/chromium-linux/fast/text/international/draw-complex-text-from-to.html b/LayoutTests/platform/chromium-linux/fast/text/international/draw-complex-text-from-to.html
new file mode 100644 (file)
index 0000000..e5300e6
--- /dev/null
@@ -0,0 +1,18 @@
+<style>
+  div {
+    font-size:36pt;
+    width:100px;
+    white-space:nowrap;
+    overflow:hidden;
+    text-overflow:ellipsis;
+    direction:rtl;
+  }
+</style>
+ <script>
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText(true);
+</script>
+
+<p>The text and ellipsis should not overlap.</p>
+<div>&#1607;&#1584;&#1575; &#1607;&#1608; &#1575;&#1604;&#1575;&#1582;&#1578;&#1576;&#1575;&#1585;</div>
+
index 133b5bb09d8bd6121af792722a7839a7a0c76477..c8484277b16307a5c5c30ef2f4af1bc3f34454c0 100644 (file)
@@ -1,3 +1,21 @@
+2011-11-17  Robin Cao  <robin.cao@torchmobile.com.cn>
+
+        [chromium] Font::drawComplexText can not draw a segment of text run
+        https://bugs.webkit.org/show_bug.cgi?id=72095
+
+        Reviewed by Adam Barth.
+
+        drawComplexText() should respect the 'from' and 'to' arguments.
+        Drawing the whole text run may result in text overlapping.
+
+        Test: platform/chromium-linux/fast/text/international/draw-complex-text-from-to.html
+
+        * platform/graphics/chromium/ComplexTextControllerLinux.cpp:
+        (WebCore::ComplexTextController::glyphsForRange):
+        * platform/graphics/chromium/ComplexTextControllerLinux.h:
+        * platform/graphics/chromium/FontLinux.cpp:
+        (WebCore::Font::drawComplexText):
+
 2011-11-17  Adam Barth  <abarth@webkit.org>
 
         Unique SecurityOrigins shouldn't remember their old schemes and hosts
index bbad3fd8f76fdf2a828cda5802ca2cdc34f0c52a..00087c2330901fea6a3e7f16c4d3f0f77defa347 100644 (file)
@@ -545,4 +545,27 @@ FloatRect ComplexTextController::selectionRect(const FloatPoint& point, int heig
     return FloatRect(point.x() + toX, point.y(), fromX - toX, height);
 }
 
+void ComplexTextController::glyphsForRange(int from, int to, int& fromGlyph, int& glyphLength)
+{
+    // Character offsets within the current run. THESE MAY NOT BE IN RANGE and may
+    // be negative, etc. The code below handles this.
+    int fromChar = from - m_item.item.pos;
+    int toChar = to - m_item.item.pos;
+
+    // See if there are any characters in the current run.
+    if (!numCodePoints() || fromChar >= static_cast<int>(numCodePoints()) || toChar <= 0) {
+        fromGlyph = -1;
+        glyphLength = 0;
+        return;
+    }
+
+    // Compute the starting glyph within this span. |from| and |to| are
+    // global offsets that may intersect arbitrarily with our local run.
+    fromGlyph = m_item.log_clusters[fromChar < 0 ? 0 : fromChar];
+    if (toChar >= static_cast<int>(numCodePoints()))
+        glyphLength = length() - fromGlyph;
+    else
+        glyphLength = m_item.log_clusters[toChar] - fromGlyph;
+}
+
 } // namespace WebCore
index e1ed3d8dd2208d259c0473b2750d4dff7b40c48b..1d3ec95eee1374e15d39e821b0c99bd33da01365 100644 (file)
@@ -93,6 +93,9 @@ public:
     bool rtl() const { return m_run.rtl(); }
     const uint16_t* glyphs() const { return m_glyphs16; }
 
+    // Return the start index and length of glyphs for the range [from, to) in the current script run.
+    void glyphsForRange(int from, int to, int& fromGlyph, int& glyphLength);
+
     // Return the length of the array returned by |glyphs|
     const unsigned length() const { return m_item.num_glyphs; }
 
index 10471a616cd28f9d2c886ba88c432313363179da..92655d823aea989175a62c46609b793c77818051 100644 (file)
@@ -201,16 +201,22 @@ void Font::drawComplexText(GraphicsContext* gc, const TextRun& run,
         controller.setupForRTL();
 
     while (controller.nextScriptRun()) {
+        // Check if there is any glyph found in the current script run.
+        int fromGlyph, glyphLength;
+        controller.glyphsForRange(from, to, fromGlyph, glyphLength);
+        if (fromGlyph < 0 || glyphLength <= 0)
+            continue;
+
         if (fill) {
             controller.fontPlatformDataForScriptRun()->setupPaint(&fillPaint);
             adjustTextRenderMode(&fillPaint, gc->platformContext());
-            canvas->drawPosText(controller.glyphs(), controller.length() << 1, controller.positions(), fillPaint);
+            canvas->drawPosText(controller.glyphs() + fromGlyph, glyphLength << 1, controller.positions() + fromGlyph, fillPaint);
         }
 
         if (stroke) {
             controller.fontPlatformDataForScriptRun()->setupPaint(&strokePaint);
             adjustTextRenderMode(&strokePaint, gc->platformContext());
-            canvas->drawPosText(controller.glyphs(), controller.length() << 1, controller.positions(), strokePaint);
+            canvas->drawPosText(controller.glyphs() + fromGlyph, glyphLength << 1, controller.positions() + fromGlyph, strokePaint);
         }
     }
 }