Changeset 129175 in webkit


Ignore:
Timestamp:
Sep 20, 2012 4:16:16 PM (12 years ago)
Author:
bashi@chromium.org
Message:

[Chromium] Improve glyph selection of HarfBuzzShaper
https://bugs.webkit.org/show_bug.cgi?id=97164

Reviewed by Tony Chang.

Source/WebCore:

Take into account clusters for selection.

Test: fast/text/international/hebrew-selection.html

  • platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp:

(WebCore::HarfBuzzShaper::HarfBuzzRun::applyShapeResult): Removed m_logClusters.
m_logCluster is no longer used.
(WebCore::HarfBuzzShaper::HarfBuzzRun::characterIndexForXPosition):

  • If targetX is in the left side of the first cluster, return the leftmost character index.
  • If targetX is in the right side of the last cluster, return the rightmost character index.
  • If targetX is between the right side of the cluster N and the left side of the cluster N+1, then:
    • return N+1 for LTR.
    • return N for RTL.

(WebCore::HarfBuzzShaper::HarfBuzzRun::xPositionForOffset):
Find the cluster of index in question, then:

  • return the left side boundary of the cluster for LTR.
  • return the right side boundary of the cluster for RTL.
  • platform/graphics/harfbuzz/ng/HarfBuzzShaper.h:

(HarfBuzzRun):

LayoutTests:

Added a test for complex text selection.

  • fast/text/international/hebrew-selection-expected.html: Added.
  • fast/text/international/hebrew-selection.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r129171 r129175  
     12012-09-20  Kenichi Ishibashi  <bashi@chromium.org>
     2
     3        [Chromium] Improve glyph selection of HarfBuzzShaper
     4        https://bugs.webkit.org/show_bug.cgi?id=97164
     5
     6        Reviewed by Tony Chang.
     7
     8        Added a test for complex text selection.
     9
     10        * fast/text/international/hebrew-selection-expected.html: Added.
     11        * fast/text/international/hebrew-selection.html: Added.
     12
    1132012-09-20  Dirk Pranke  <dpranke@chromium.org>
    214
  • trunk/LayoutTests/platform/chromium/TestExpectations

    r129171 r129175  
    35593559webkit.org/b/97179 http/tests/css/link-css-disabled-value-with-slow-loading-sheet.html [ Failure Pass ]
    35603560
    3561 
     3561# The test should pass after harfbuzz transition.
     3562webkit.org/b/97164 [ Linux ] fast/text/international/hebrew-selection.html [ Failure ]
     3563
  • trunk/Source/WebCore/ChangeLog

    r129174 r129175  
     12012-09-20  Kenichi Ishibashi  <bashi@chromium.org>
     2
     3        [Chromium] Improve glyph selection of HarfBuzzShaper
     4        https://bugs.webkit.org/show_bug.cgi?id=97164
     5
     6        Reviewed by Tony Chang.
     7
     8        Take into account clusters for selection.
     9
     10        Test: fast/text/international/hebrew-selection.html
     11
     12        * platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp:
     13        (WebCore::HarfBuzzShaper::HarfBuzzRun::applyShapeResult): Removed m_logClusters.
     14        m_logCluster is no longer used.
     15        (WebCore::HarfBuzzShaper::HarfBuzzRun::characterIndexForXPosition):
     16        - If targetX is in the left side of the first cluster, return the leftmost character index.
     17        - If targetX is in the right side of the last cluster, return the rightmost character index.
     18        - If targetX is between the right side of the cluster N and the left side of the cluster N+1, then:
     19          - return N+1 for LTR.
     20          - return N for RTL.
     21        (WebCore::HarfBuzzShaper::HarfBuzzRun::xPositionForOffset):
     22        Find the cluster of index in question, then:
     23        - return the left side boundary of the cluster for LTR.
     24        - return the right side boundary of the cluster for RTL.
     25        * platform/graphics/harfbuzz/ng/HarfBuzzShaper.h:
     26        (HarfBuzzRun):
     27
    1282012-09-20  Tony Chang  <tony@chromium.org>
    229
  • trunk/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp

    r129074 r129175  
    8787    m_advances.resize(m_numGlyphs);
    8888    m_glyphToCharacterIndexes.resize(m_numGlyphs);
    89     m_logClusters.resize(m_numCharacters);
    9089    m_offsets.resize(m_numGlyphs);
    9190
     
    9392    for (unsigned i = 0; i < m_numGlyphs; ++i)
    9493        m_glyphToCharacterIndexes[i] = infos[i].cluster;
    95 
    96     // Fill logical clusters
    97     unsigned index = 0;
    98     while (index < m_numGlyphs) {
    99         unsigned nextIndex = index + 1;
    100         while (nextIndex < m_numGlyphs && infos[index].cluster == infos[nextIndex].cluster)
    101             ++nextIndex;
    102         if (rtl()) {
    103             int nextCluster = nextIndex < m_numGlyphs ? infos[nextIndex].cluster : -1;
    104             for (int j = infos[index].cluster; j > nextCluster; --j)
    105                 m_logClusters[j] = index;
    106         } else {
    107             unsigned nextCluster = nextIndex < m_numGlyphs ? infos[nextIndex].cluster : m_numCharacters;
    108             for (unsigned j = infos[index].cluster; j < nextCluster; ++j)
    109                 m_logClusters[j] = index;
    110         }
    111         index = nextIndex;
    112     }
    11394}
    11495
     
    124105    ASSERT(targetX <= m_width);
    125106    float currentX = 0;
    126     float prevAdvance = 0;
    127     for (unsigned i = 0; i < m_numGlyphs; ++i) {
    128         float currentAdvance = m_advances[i] / 2.0;
     107    float currentAdvance = m_advances[0];
     108    unsigned glyphIndex = 0;
     109
     110    // Sum up advances that belong to a character.
     111    while (glyphIndex < m_numGlyphs - 1 && m_glyphToCharacterIndexes[glyphIndex] == m_glyphToCharacterIndexes[glyphIndex + 1])
     112        currentAdvance += m_advances[++glyphIndex];
     113    currentAdvance = currentAdvance / 2.0;
     114    if (targetX <= currentAdvance)
     115        return rtl() ? m_numCharacters : 0;
     116
     117    ++glyphIndex;
     118    while (glyphIndex < m_numGlyphs) {
     119        unsigned prevCharacterIndex = m_glyphToCharacterIndexes[glyphIndex - 1];
     120        float prevAdvance = currentAdvance;
     121        currentAdvance = m_advances[glyphIndex];
     122        while (glyphIndex < m_numGlyphs - 1 && m_glyphToCharacterIndexes[glyphIndex] == m_glyphToCharacterIndexes[glyphIndex + 1])
     123            currentAdvance += m_advances[++glyphIndex];
     124        currentAdvance = currentAdvance / 2.0;
    129125        float nextX = currentX + prevAdvance + currentAdvance;
    130126        if (currentX <= targetX && targetX <= nextX)
    131             return m_glyphToCharacterIndexes[i] + (rtl() ? 1 : 0);
     127            return rtl() ? prevCharacterIndex : m_glyphToCharacterIndexes[glyphIndex];
    132128        currentX = nextX;
    133129        prevAdvance = currentAdvance;
     130        ++glyphIndex;
    134131    }
    135132
     
    140137{
    141138    ASSERT(offset < m_numCharacters);
    142     unsigned glyphIndex = m_logClusters[offset];
    143     ASSERT(glyphIndex <= m_numGlyphs);
     139    unsigned glyphIndex = 0;
    144140    float position = 0;
    145     for (unsigned i = 0; i < glyphIndex; ++i)
    146         position += m_advances[i];
    147     if (rtl())
     141    if (rtl()) {
     142        while (glyphIndex < m_numGlyphs && m_glyphToCharacterIndexes[glyphIndex] > offset) {
     143            position += m_advances[glyphIndex];
     144            ++glyphIndex;
     145        }
     146        // For RTL, we need to return the right side boundary of the character.
     147        // Add advance of glyphs which are part of the character.
     148        while (glyphIndex < m_numGlyphs - 1 && m_glyphToCharacterIndexes[glyphIndex] == m_glyphToCharacterIndexes[glyphIndex + 1]) {
     149            position += m_advances[glyphIndex];
     150            ++glyphIndex;
     151        }
    148152        position += m_advances[glyphIndex];
     153    } else {
     154        while (glyphIndex < m_numGlyphs && m_glyphToCharacterIndexes[glyphIndex] < offset) {
     155            position += m_advances[glyphIndex];
     156            ++glyphIndex;
     157        }
     158    }
    149159    return position;
    150160}
     
    158168        int nextPosition = position;
    159169        U16_NEXT(source, nextPosition, length, character);
    160         // Don't normalize tabs as they are not treated as spaces for word-end
     170        // Don't normalize tabs as they are not treated as spaces for word-end.
    161171        if (Font::treatAsSpace(character) && character != '\t')
    162172            character = ' ';
  • trunk/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.h

    r129074 r129175  
    9595        Vector<uint16_t, 256> m_glyphs;
    9696        Vector<float, 256> m_advances;
    97         Vector<uint16_t, 256> m_logClusters;
    9897        Vector<uint16_t, 256> m_glyphToCharacterIndexes;
    9998        Vector<FloatPoint, 256> m_offsets;
Note: See TracChangeset for help on using the changeset viewer.