Changeset 222086 in webkit


Ignore:
Timestamp:
Sep 15, 2017 6:42:34 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

[Harfbuzz] Fix incorrect font rendering when selecting texts in pages which specifies text-rendering: optimizeLegibility
https://bugs.webkit.org/show_bug.cgi?id=148220

Reviewed by Michael Catanzaro.

Add support for shaping a range of characters and return the advance to the first glyph in the range.

Covered by existing tests.

  • platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:

(WebCore::FontCascade::getGlyphsAndAdvancesForComplexText const): Pass "from" and "to" parameters to
HarfBuzzShaper::shape and return the x position of the selection rect.

  • platform/graphics/harfbuzz/HarfBuzzShaper.cpp:

(WebCore::HarfBuzzShaper::shape): Forward "from" and "to" parameters to fillGlyphBuffer().
(WebCore::HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun): Only add glyphs for the given character range.
(WebCore::HarfBuzzShaper::fillGlyphBuffer): Only consider runs in the given character range.

  • platform/graphics/harfbuzz/HarfBuzzShaper.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r222085 r222086  
     12017-09-15  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [Harfbuzz] Fix incorrect font rendering when selecting texts in pages which specifies text-rendering: optimizeLegibility
     4        https://bugs.webkit.org/show_bug.cgi?id=148220
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add support for shaping a range of characters and return the advance to the first glyph in the range.
     9
     10        Covered by existing tests.
     11
     12        * platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:
     13        (WebCore::FontCascade::getGlyphsAndAdvancesForComplexText const): Pass "from" and "to" parameters to
     14        HarfBuzzShaper::shape and return the x position of the selection rect.
     15        * platform/graphics/harfbuzz/HarfBuzzShaper.cpp:
     16        (WebCore::HarfBuzzShaper::shape): Forward "from" and "to" parameters to fillGlyphBuffer().
     17        (WebCore::HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun): Only add glyphs for the given character range.
     18        (WebCore::HarfBuzzShaper::fillGlyphBuffer): Only consider runs in the given character range.
     19        * platform/graphics/harfbuzz/HarfBuzzShaper.h:
     20
    1212017-09-15  Zan Dobersek  <zdobersek@igalia.com>
    222
  • trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp

    r221974 r222086  
    4141namespace WebCore {
    4242
    43 float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, unsigned, unsigned, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot /* forTextEmphasis */) const
     43float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, unsigned from, unsigned to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot /* forTextEmphasis */) const
    4444{
    4545    HarfBuzzShaper shaper(this, run);
    46     if (!shaper.shape(&glyphBuffer)) {
     46    if (!shaper.shape(&glyphBuffer, from, to)) {
    4747        LOG_ERROR("Shaper couldn't shape glyphBuffer.");
    4848        return 0;
    4949    }
    5050
    51     // FIXME: Mac returns an initial advance here.
    52     return 0;
     51    if (glyphBuffer.isEmpty())
     52        return 0;
     53
     54    return shaper.selectionRect({ }, 0, from, to).x();
    5355}
    5456
  • trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp

    r222020 r222086  
    337337}
    338338
    339 bool HarfBuzzShaper::shape(GlyphBuffer* glyphBuffer)
     339bool HarfBuzzShaper::shape(GlyphBuffer* glyphBuffer, std::optional<unsigned> from, std::optional<unsigned> to)
    340340{
    341341    if (!collectHarfBuzzRuns())
     
    349349    m_totalWidth = roundf(m_totalWidth);
    350350
    351     if (glyphBuffer && !fillGlyphBuffer(glyphBuffer))
     351    if (glyphBuffer && !fillGlyphBuffer(glyphBuffer, from.value_or(0), to.value_or(m_run.length())))
    352352        return false;
    353353
     
    530530}
    531531
    532 void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, HarfBuzzRun* currentRun, FloatPoint& firstOffsetOfNextRun)
     532void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, unsigned from, unsigned to, HarfBuzzRun* currentRun, const FloatPoint& firstOffsetOfNextRun)
    533533{
    534534    FloatPoint* offsets = currentRun->offsets();
     
    540540    for (unsigned i = 0; i < numGlyphs; ++i) {
    541541        uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToCharacterIndexes[i];
    542         FloatPoint& currentOffset = offsets[i];
    543         FloatPoint& nextOffset = (i == numGlyphs - 1) ? firstOffsetOfNextRun : offsets[i + 1];
     542        if (currentCharacterIndex < from)
     543            continue;
     544        if (currentCharacterIndex >= to)
     545            break;
     546        const FloatPoint& currentOffset = offsets[i];
     547        const FloatPoint& nextOffset = (i == numGlyphs - 1) ? firstOffsetOfNextRun : offsets[i + 1];
    544548        float glyphAdvanceX = advances[i] + nextOffset.x() - currentOffset.x();
    545549        float glyphAdvanceY = nextOffset.y() - currentOffset.y();
     
    556560}
    557561
    558 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer)
     562bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer, unsigned from, unsigned to)
    559563{
    560564    unsigned numRuns = m_harfBuzzRuns.size();
     
    563567        for (int runIndex = numRuns - 1; runIndex >= 0; --runIndex) {
    564568            HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get();
    565             FloatPoint firstOffsetOfNextRun = !runIndex ? FloatPoint() : m_harfBuzzRuns[runIndex - 1]->offsets()[0];
    566             fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun, firstOffsetOfNextRun);
     569            auto runStartIndex = currentRun->startIndex();
     570            auto runEndIndex = std::max<unsigned>(0, runStartIndex + currentRun->numCharacters() - 1);
     571            if ((from >= runStartIndex && from <= runEndIndex) || (to >= runStartIndex && to <= runEndIndex)
     572                || (from < runEndIndex && to > runStartIndex)) {
     573                FloatPoint firstOffsetOfNextRun = !runIndex ? FloatPoint() : m_harfBuzzRuns[runIndex - 1]->offsets()[0];
     574                fillGlyphBufferFromHarfBuzzRun(glyphBuffer, from, to, currentRun, firstOffsetOfNextRun);
     575            }
    567576        }
    568577    } else {
     
    570579        for (unsigned runIndex = 0; runIndex < numRuns; ++runIndex) {
    571580            HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get();
    572             FloatPoint firstOffsetOfNextRun = runIndex == numRuns - 1 ? FloatPoint() : m_harfBuzzRuns[runIndex + 1]->offsets()[0];
    573             fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun, firstOffsetOfNextRun);
     581            auto runStartIndex = currentRun->startIndex();
     582            auto runEndIndex = std::max<unsigned>(0, runStartIndex + currentRun->numCharacters() - 1);
     583            if ((from >= runStartIndex && from <= runEndIndex) || (to >= runStartIndex && to <= runEndIndex)
     584                || (from < runStartIndex && to > runEndIndex)) {
     585                FloatPoint firstOffsetOfNextRun = runIndex == numRuns - 1 ? FloatPoint() : m_harfBuzzRuns[runIndex + 1]->offsets()[0];
     586                fillGlyphBufferFromHarfBuzzRun(glyphBuffer, from, to, currentRun, firstOffsetOfNextRun);
     587            }
    574588        }
    575589    }
  • trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.h

    r221974 r222086  
    5555    virtual ~HarfBuzzShaper();
    5656
    57     bool shape(GlyphBuffer* = 0);
     57    bool shape(GlyphBuffer* = nullptr, std::optional<unsigned> from = std::nullopt, std::optional<unsigned> to = std::nullopt);
    5858    FloatPoint adjustStartPoint(const FloatPoint&);
    5959    float totalWidth() { return m_totalWidth; }
     
    114114    bool collectHarfBuzzRuns();
    115115    bool shapeHarfBuzzRuns(bool shouldSetDirection);
    116     bool fillGlyphBuffer(GlyphBuffer*);
    117     void fillGlyphBufferFromHarfBuzzRun(GlyphBuffer*, HarfBuzzRun*, FloatPoint& firstOffsetOfNextRun);
     116    bool fillGlyphBuffer(GlyphBuffer*, unsigned from, unsigned to);
     117    void fillGlyphBufferFromHarfBuzzRun(GlyphBuffer*, unsigned from, unsigned to, HarfBuzzRun*, const FloatPoint& firstOffsetOfNextRun);
    118118    void setGlyphPositionsForHarfBuzzRun(HarfBuzzRun*, hb_buffer_t*);
    119119
Note: See TracChangeset for help on using the changeset viewer.