Changeset 222086 in webkit
- Timestamp:
- Sep 15, 2017 6:42:34 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r222085 r222086 1 2017-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 1 21 2017-09-15 Zan Dobersek <zdobersek@igalia.com> 2 22 -
trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp
r221974 r222086 41 41 namespace WebCore { 42 42 43 float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, unsigned , unsigned, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot /* forTextEmphasis */) const43 float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, unsigned from, unsigned to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot /* forTextEmphasis */) const 44 44 { 45 45 HarfBuzzShaper shaper(this, run); 46 if (!shaper.shape(&glyphBuffer )) {46 if (!shaper.shape(&glyphBuffer, from, to)) { 47 47 LOG_ERROR("Shaper couldn't shape glyphBuffer."); 48 48 return 0; 49 49 } 50 50 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(); 53 55 } 54 56 -
trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp
r222020 r222086 337 337 } 338 338 339 bool HarfBuzzShaper::shape(GlyphBuffer* glyphBuffer )339 bool HarfBuzzShaper::shape(GlyphBuffer* glyphBuffer, std::optional<unsigned> from, std::optional<unsigned> to) 340 340 { 341 341 if (!collectHarfBuzzRuns()) … … 349 349 m_totalWidth = roundf(m_totalWidth); 350 350 351 if (glyphBuffer && !fillGlyphBuffer(glyphBuffer ))351 if (glyphBuffer && !fillGlyphBuffer(glyphBuffer, from.value_or(0), to.value_or(m_run.length()))) 352 352 return false; 353 353 … … 530 530 } 531 531 532 void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, HarfBuzzRun* currentRun,FloatPoint& firstOffsetOfNextRun)532 void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, unsigned from, unsigned to, HarfBuzzRun* currentRun, const FloatPoint& firstOffsetOfNextRun) 533 533 { 534 534 FloatPoint* offsets = currentRun->offsets(); … … 540 540 for (unsigned i = 0; i < numGlyphs; ++i) { 541 541 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]; 544 548 float glyphAdvanceX = advances[i] + nextOffset.x() - currentOffset.x(); 545 549 float glyphAdvanceY = nextOffset.y() - currentOffset.y(); … … 556 560 } 557 561 558 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer )562 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer, unsigned from, unsigned to) 559 563 { 560 564 unsigned numRuns = m_harfBuzzRuns.size(); … … 563 567 for (int runIndex = numRuns - 1; runIndex >= 0; --runIndex) { 564 568 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 } 567 576 } 568 577 } else { … … 570 579 for (unsigned runIndex = 0; runIndex < numRuns; ++runIndex) { 571 580 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 } 574 588 } 575 589 } -
trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.h
r221974 r222086 55 55 virtual ~HarfBuzzShaper(); 56 56 57 bool shape(GlyphBuffer* = 0);57 bool shape(GlyphBuffer* = nullptr, std::optional<unsigned> from = std::nullopt, std::optional<unsigned> to = std::nullopt); 58 58 FloatPoint adjustStartPoint(const FloatPoint&); 59 59 float totalWidth() { return m_totalWidth; } … … 114 114 bool collectHarfBuzzRuns(); 115 115 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); 118 118 void setGlyphPositionsForHarfBuzzRun(HarfBuzzRun*, hb_buffer_t*); 119 119
Note: See TracChangeset
for help on using the changeset viewer.