Title: [123991] trunk/Source/WebCore
Revision
123991
Author
[email protected]
Date
2012-07-29 18:46:58 -0700 (Sun, 29 Jul 2012)

Log Message

[Chromium] HarfBuzzShaper can't handle segmented text run
https://bugs.webkit.org/show_bug.cgi?id=92445

Reviewed by Tony Chang.

Pass the range to be displayed to HarfBuzzShaper. The shaper calculates positions and advances of each glyph
regardless of the range, but only add glyphs which are in the range.

No new tests. platform/chromium-linux/fast/text/international/draw-complex-text-from-to.html should
work as expected once we move to use harfbuzz-ng on linux. Note that the current expectation will need to be rebaselined
because the old hb shaper (ComplexTextController) mishandles the range. |to| should be exclusive. I'll rebaseline
the expectation later.

* platform/graphics/harfbuzz/FontHarfBuzz.cpp:
(WebCore::Font::drawComplexText): Call shaper.setDrawRange().
* platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp:
(WebCore::HarfBuzzShaper::HarfBuzzShaper):
(WebCore::HarfBuzzShaper::setDrawRange): Added.
(WebCore):
(WebCore::HarfBuzzShaper::shouldDrawCharacterAt): Added.
(WebCore::HarfBuzzShaper::shapeHarfBuzzRuns): Added variables that hold pending advances.
(WebCore::HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun): Add only glyphs which are in the given range to glyphBuffer.
* platform/graphics/harfbuzz/ng/HarfBuzzShaper.h:
(HarfBuzzShaper):
* platform/graphics/mac/FontComplexTextMac.cpp:
(WebCore::Font::drawComplexText): Call shaper.setDrawRange().

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (123990 => 123991)


--- trunk/Source/WebCore/ChangeLog	2012-07-30 00:44:08 UTC (rev 123990)
+++ trunk/Source/WebCore/ChangeLog	2012-07-30 01:46:58 UTC (rev 123991)
@@ -1,3 +1,32 @@
+2012-07-29  Kenichi Ishibashi  <[email protected]>
+
+        [Chromium] HarfBuzzShaper can't handle segmented text run
+        https://bugs.webkit.org/show_bug.cgi?id=92445
+
+        Reviewed by Tony Chang.
+
+        Pass the range to be displayed to HarfBuzzShaper. The shaper calculates positions and advances of each glyph
+        regardless of the range, but only add glyphs which are in the range.
+
+        No new tests. platform/chromium-linux/fast/text/international/draw-complex-text-from-to.html should
+        work as expected once we move to use harfbuzz-ng on linux. Note that the current expectation will need to be rebaselined
+        because the old hb shaper (ComplexTextController) mishandles the range. |to| should be exclusive. I'll rebaseline
+        the expectation later.
+
+        * platform/graphics/harfbuzz/FontHarfBuzz.cpp:
+        (WebCore::Font::drawComplexText): Call shaper.setDrawRange().
+        * platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp:
+        (WebCore::HarfBuzzShaper::HarfBuzzShaper):
+        (WebCore::HarfBuzzShaper::setDrawRange): Added.
+        (WebCore):
+        (WebCore::HarfBuzzShaper::shouldDrawCharacterAt): Added.
+        (WebCore::HarfBuzzShaper::shapeHarfBuzzRuns): Added variables that hold pending advances.
+        (WebCore::HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun): Add only glyphs which are in the given range to glyphBuffer.
+        * platform/graphics/harfbuzz/ng/HarfBuzzShaper.h:
+        (HarfBuzzShaper):
+        * platform/graphics/mac/FontComplexTextMac.cpp:
+        (WebCore::Font::drawComplexText): Call shaper.setDrawRange().
+
 2012-07-29  Dan Bernstein  <[email protected]>
 
         Hit testing in the gap between pages returns incorrect results in flipped blocks writing modes

Modified: trunk/Source/WebCore/platform/graphics/harfbuzz/FontHarfBuzz.cpp (123990 => 123991)


--- trunk/Source/WebCore/platform/graphics/harfbuzz/FontHarfBuzz.cpp	2012-07-30 00:44:08 UTC (rev 123990)
+++ trunk/Source/WebCore/platform/graphics/harfbuzz/FontHarfBuzz.cpp	2012-07-30 01:46:58 UTC (rev 123991)
@@ -185,6 +185,7 @@
 #if USE(HARFBUZZ_NG)
     GlyphBuffer glyphBuffer;
     HarfBuzzShaper shaper(this, run);
+    shaper.setDrawRange(from, to);
     if (!shaper.shape(&glyphBuffer))
         return;
     FloatPoint adjustedPoint = shaper.adjustStartPoint(point);

Modified: trunk/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp (123990 => 123991)


--- trunk/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp	2012-07-30 00:44:08 UTC (rev 123990)
+++ trunk/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp	2012-07-30 01:46:58 UTC (rev 123991)
@@ -167,6 +167,8 @@
 
 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run)
     : HarfBuzzShaperBase(font, run)
+    , m_fromIndex(0)
+    , m_toIndex(m_run.length())
 {
     m_normalizedBuffer = adoptArrayPtr(new UChar[m_run.length() + 1]);
     m_normalizedBufferLength = m_run.length();
@@ -179,6 +181,19 @@
 {
 }
 
+void HarfBuzzShaper::setDrawRange(int from, int to)
+{
+    ASSERT(from >= 0);
+    ASSERT(to <= m_run.length());
+    m_fromIndex = from;
+    m_toIndex = to;
+}
+
+bool HarfBuzzShaper::shouldDrawCharacterAt(int index)
+{
+    return m_fromIndex <= index && index < m_toIndex;
+}
+
 void HarfBuzzShaper::setFontFeatures()
 {
     FontFeatureSettings* settings = m_font->fontDescription().featureSettings();
@@ -254,6 +269,9 @@
 bool HarfBuzzShaper::shapeHarfBuzzRuns(GlyphBuffer* glyphBuffer)
 {
     HarfBuzzScopedPtr<hb_buffer_t> harfbuzzBuffer(hb_buffer_create(), hb_buffer_destroy);
+    float pendingGlyphAdvanceX = 0;
+    float pendingGlyphAdvanceY = 0;
+
     hb_buffer_set_unicode_funcs(harfbuzzBuffer.get(), hb_icu_get_unicode_funcs());
     if (m_run.directionalOverride())
         hb_buffer_set_direction(harfbuzzBuffer.get(), m_run.rtl() ? HB_DIRECTION_RTL : HB_DIRECTION_LTR);
@@ -279,7 +297,7 @@
         hb_shape(harfbuzzFont.get(), harfbuzzBuffer.get(), m_features.isEmpty() ? 0 : m_features.data(), m_features.size());
 
         currentRun->applyShapeResult(harfbuzzBuffer.get());
-        setGlyphPositionsForHarfBuzzRun(currentRun, i, harfbuzzBuffer.get(), glyphBuffer);
+        setGlyphPositionsForHarfBuzzRun(currentRun, i, harfbuzzBuffer.get(), glyphBuffer, pendingGlyphAdvanceX, pendingGlyphAdvanceY);
 
         hb_buffer_reset(harfbuzzBuffer.get());
         if (m_run.directionalOverride())
@@ -288,7 +306,7 @@
     return true;
 }
 
-void HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun(HarfBuzzRun* currentRun, unsigned runIndexInVisualOrder, hb_buffer_t* harfbuzzBuffer, GlyphBuffer* glyphBuffer)
+void HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun(HarfBuzzRun* currentRun, unsigned runIndexInVisualOrder, hb_buffer_t* harfbuzzBuffer, GlyphBuffer* glyphBuffer, float& pendingGlyphAdvanceX, float& pendingGlyphAdvanceY)
 {
     const SimpleFontData* currentFontData = currentRun->fontData();
     hb_glyph_info_t* glyphInfos = hb_buffer_get_glyph_infos(harfbuzzBuffer, 0);
@@ -317,7 +335,7 @@
 
         if (currentFontData->isZeroWidthSpaceGlyph(glyph)) {
             currentRun->setGlyphAndAdvance(i, glyph, 0);
-            if (glyphBuffer)
+            if (glyphBuffer && shouldDrawCharacterAt(currentCharacterIndex))
                 glyphBuffer->add(glyph, currentFontData, createGlyphBufferAdvance(0, 0));
             continue;
         }
@@ -330,7 +348,16 @@
                 m_startOffset.set(offsetX, offsetY);
             float glyphAdvanceX = advance + nextOffsetX - offsetX;
             float glyphAdvanceY = nextOffsetY - offsetY;
-            glyphBuffer->add(glyph, currentFontData, createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY));
+            if (shouldDrawCharacterAt(currentCharacterIndex)) {
+                glyphAdvanceX += pendingGlyphAdvanceX;
+                glyphAdvanceY += pendingGlyphAdvanceY;
+                pendingGlyphAdvanceX = 0;
+                pendingGlyphAdvanceY = 0;
+                glyphBuffer->add(glyph, currentFontData, createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY));
+            } else {
+                pendingGlyphAdvanceX += glyphAdvanceX;
+                pendingGlyphAdvanceY += glyphAdvanceY;
+            }
         }
 
         totalAdvance += advance;

Modified: trunk/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.h (123990 => 123991)


--- trunk/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.h	2012-07-30 00:44:08 UTC (rev 123990)
+++ trunk/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.h	2012-07-30 01:46:58 UTC (rev 123991)
@@ -51,6 +51,7 @@
     HarfBuzzShaper(const Font*, const TextRun&);
     virtual ~HarfBuzzShaper();
 
+    void setDrawRange(int from, int to);
     bool shape(GlyphBuffer* = 0);
     FloatPoint adjustStartPoint(const FloatPoint&);
     float totalWidth() { return m_totalWidth; }
@@ -96,11 +97,12 @@
         float m_width;
     };
 
+    bool shouldDrawCharacterAt(int index);
     void setFontFeatures();
 
     bool collectHarfBuzzRuns();
     bool shapeHarfBuzzRuns(GlyphBuffer*);
-    void setGlyphPositionsForHarfBuzzRun(HarfBuzzRun*, unsigned runIndexInVisualOrder, hb_buffer_t*, GlyphBuffer*);
+    void setGlyphPositionsForHarfBuzzRun(HarfBuzzRun*, unsigned runIndexInVisualOrder, hb_buffer_t*, GlyphBuffer*, float& pendingGlyphAdvanceX, float& pendingGlyphAdvanceY);
 
     GlyphBufferAdvance createGlyphBufferAdvance(float, float);
 
@@ -109,6 +111,9 @@
 
     FloatPoint m_startOffset;
 
+    int m_fromIndex;
+    int m_toIndex;
+
     float m_totalWidth;
 };
 

Modified: trunk/Source/WebCore/platform/graphics/mac/FontComplexTextMac.cpp (123990 => 123991)


--- trunk/Source/WebCore/platform/graphics/mac/FontComplexTextMac.cpp	2012-07-30 00:44:08 UTC (rev 123990)
+++ trunk/Source/WebCore/platform/graphics/mac/FontComplexTextMac.cpp	2012-07-30 01:46:58 UTC (rev 123991)
@@ -105,6 +105,7 @@
     if (preferHarfBuzz(this)) {
         GlyphBuffer glyphBuffer;
         HarfBuzzShaper shaper(this, run);
+        shaper.setDrawRange(from, to);
         if (shaper.shape(&glyphBuffer)) {
             drawGlyphBuffer(context, run, glyphBuffer, point);
             return;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to