Changeset 75400 in webkit


Ignore:
Timestamp:
Jan 10, 2011 11:58:05 AM (13 years ago)
Author:
evan@chromium.org
Message:

2011-01-10 Evan Martin <evan@chromium.org>

Reviewed by Tony Chang.

[chromium] simplify complex glyph positioning code
https://bugs.webkit.org/show_bug.cgi?id=52159

Before, we had roughly same code duplicated for RTL and LTR.
Now, use the same code for both directions by being careful about
flipping signs where appropriate.

  • platform/graphics/chromium/ComplexTextControllerLinux.cpp: (WebCore::ComplexTextController::shapeGlyphs): (WebCore::ComplexTextController::setGlyphXPositions):
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r75397 r75400  
     12011-01-10  Evan Martin  <evan@chromium.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        [chromium] simplify complex glyph positioning code
     6        https://bugs.webkit.org/show_bug.cgi?id=52159
     7
     8        Before, we had roughly same code duplicated for RTL and LTR.
     9        Now, use the same code for both directions by being careful about
     10        flipping signs where appropriate.
     11
     12        * platform/graphics/chromium/ComplexTextControllerLinux.cpp:
     13        (WebCore::ComplexTextController::shapeGlyphs):
     14        (WebCore::ComplexTextController::setGlyphXPositions):
     15
    1162011-01-10  Alejandro G. Castro  <alex@igalia.com>
    217
  • trunk/Source/WebCore/platform/graphics/chromium/ComplexTextControllerLinux.cpp

    r75108 r75400  
    274274    // HB_ShapeItem() resets m_item.num_glyphs. If the previous call to
    275275    // HB_ShapeItem() used less space than was available, the capacity of
    276     // the array may be larger than the current value of m_item.num_glyphs. 
     276    // the array may be larger than the current value of m_item.num_glyphs.
    277277    // So, we need to reset the num_glyphs to the capacity of the array.
    278278    m_item.num_glyphs = m_glyphsArrayCapacity;
     
    292292void ComplexTextController::setGlyphXPositions(bool isRTL)
    293293{
     294    const double rtlFlip = isRTL ? -1 : 1;
    294295    double position = 0;
    295     // logClustersIndex indexes logClusters for the first (or last when
    296     // RTL) codepoint of the current glyph.  Each time we advance a glyph,
    297     // we skip over all the codepoints that contributed to the current
    298     // glyph.
     296
     297    // logClustersIndex indexes logClusters for the first codepoint of the current glyph.
     298    // Each time we advance a glyph, we skip over all the codepoints that contributed to the current glyph.
    299299    int logClustersIndex = 0;
    300300
     301    // Iterate through the glyphs in logical order, flipping for RTL where necessary.
     302    // In RTL mode all variables are positive except m_xPositions, which starts from m_offsetX and runs negative.
     303    // It is fixed up in a second pass below.
     304    for (size_t i = 0; i < m_item.num_glyphs; ++i) {
     305        while (static_cast<unsigned>(logClustersIndex) < m_item.item.length && logClusters()[logClustersIndex] < i)
     306            logClustersIndex++;
     307
     308        // If the current glyph is just after a space, add in the word spacing.
     309        position += determineWordBreakSpacing(logClustersIndex);
     310
     311        m_glyphs16[i] = m_item.glyphs[i];
     312        double offsetX = truncateFixedPointToInteger(m_item.offsets[i].x);
     313        double advance = truncateFixedPointToInteger(m_item.advances[i]);
     314        if (isRTL)
     315            offsetX -= advance;
     316
     317        m_xPositions[i] = m_offsetX + (position * rtlFlip) + offsetX;
     318
     319        if (m_currentFontData->isZeroWidthSpaceGlyph(m_glyphs16[i]))
     320            continue;
     321
     322        // At the end of each cluster, add in the letter spacing.
     323        if (i + 1 == m_item.num_glyphs || m_item.attributes[i + 1].clusterStart)
     324            position += m_letterSpacing;
     325
     326        position += advance;
     327    }
     328    const double width = position;
     329
     330    // Now that we've computed the total width, do another pass to fix positioning for RTL.
    301331    if (isRTL) {
    302         logClustersIndex = m_item.num_glyphs - 1;
    303 
    304         // Glyphs are stored in logical order, but for layout purposes we
    305         // always go left to right.
    306         for (int i = m_item.num_glyphs - 1; i >= 0; --i) {
    307             if (!m_currentFontData->isZeroWidthSpaceGlyph(m_glyphs16[i])) {
    308                 // Whitespace must be laid out in logical order, so when inserting
    309                 // spaces in RTL (but iterating in LTR order) we must insert spaces
    310                 // _before_ the next glyph.
    311                 if (static_cast<unsigned>(i + 1) >= m_item.num_glyphs || m_item.attributes[i + 1].clusterStart)
    312                     position += m_letterSpacing;
    313 
    314                 position += determineWordBreakSpacing(logClustersIndex);
    315             }
    316 
    317             m_glyphs16[i] = m_item.glyphs[i];
    318             double offsetX = truncateFixedPointToInteger(m_item.offsets[i].x);
    319             m_xPositions[i] = m_offsetX + position + offsetX;
    320 
    321             while (logClustersIndex > 0 && logClusters()[logClustersIndex] == i)
    322                 logClustersIndex--;
    323 
    324             if (!m_currentFontData->isZeroWidthSpaceGlyph(m_glyphs16[i]))
    325                 position += truncateFixedPointToInteger(m_item.advances[i]);
    326         }
    327     } else {
    328         for (size_t i = 0; i < m_item.num_glyphs; ++i) {
    329             m_glyphs16[i] = m_item.glyphs[i];
    330             double offsetX = truncateFixedPointToInteger(m_item.offsets[i].x);
    331             m_xPositions[i] = m_offsetX + position + offsetX;
    332 
    333             if (m_currentFontData->isZeroWidthSpaceGlyph(m_glyphs16[i]))
    334                 continue;
    335 
    336             double advance = truncateFixedPointToInteger(m_item.advances[i]);
    337 
    338             advance += determineWordBreakSpacing(logClustersIndex);
    339 
    340             if (m_item.attributes[i].clusterStart)
    341                 advance += m_letterSpacing;
    342 
    343             while (static_cast<unsigned>(logClustersIndex) < m_item.item.length && logClusters()[logClustersIndex] == i)
    344                 logClustersIndex++;
    345 
    346             position += advance;
    347         }
    348     }
    349     m_pixelWidth = std::max(position, 0.0);
     332        for (size_t i = 0; i < m_item.num_glyphs; ++i)
     333            m_xPositions[i] += width;
     334    }
     335
     336    m_pixelWidth = std::max(width, 0.0);
    350337    m_offsetX += m_pixelWidth;
    351338}
Note: See TracChangeset for help on using the changeset viewer.