diff options
Diffstat (limited to 'Source/WebCore/platform/graphics/harfbuzz')
6 files changed, 134 insertions, 123 deletions
diff --git a/Source/WebCore/platform/graphics/harfbuzz/ComplexTextControllerHarfBuzz.cpp b/Source/WebCore/platform/graphics/harfbuzz/ComplexTextControllerHarfBuzz.cpp new file mode 100644 index 000000000..e97f9c204 --- /dev/null +++ b/Source/WebCore/platform/graphics/harfbuzz/ComplexTextControllerHarfBuzz.cpp @@ -0,0 +1,36 @@ +/* +* Copyright (C) 2017 Apple Inc. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "config.h" +#include "ComplexTextController.h" + +namespace WebCore { + +void ComplexTextController::collectComplexTextRunsForCharacters(const UChar*, unsigned, unsigned, const Font*) +{ + // FIXME: Implement this. + ASSERT_NOT_REACHED(); +} + +} diff --git a/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFace.cpp b/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFace.cpp index efc94f3f9..f03cace8e 100644 --- a/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFace.cpp +++ b/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFace.cpp @@ -32,8 +32,8 @@ #include "HarfBuzzFace.h" #include "FontPlatformData.h" -#include "hb-ot.h" -#include "hb.h" +#include <hb-ot.h> +#include <hb.h> namespace WebCore { @@ -74,7 +74,7 @@ typedef HashMap<uint64_t, RefPtr<FaceCacheEntry>, WTF::IntHash<uint64_t>, WTF::U static HarfBuzzFaceCache* harfBuzzFaceCache() { - DEFINE_STATIC_LOCAL(HarfBuzzFaceCache, s_harfBuzzFaceCache, ()); + DEPRECATED_DEFINE_STATIC_LOCAL(HarfBuzzFaceCache, s_harfBuzzFaceCache, ()); return &s_harfBuzzFaceCache; } diff --git a/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFace.h b/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFace.h index 8066528b5..63179fe81 100644 --- a/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFace.h +++ b/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFace.h @@ -36,7 +36,6 @@ #include <wtf/HashMap.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> -#include <wtf/RefPtr.h> namespace WebCore { diff --git a/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFaceCairo.cpp b/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFaceCairo.cpp index 9ddf36a7e..61486ca0e 100644 --- a/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFaceCairo.cpp +++ b/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFaceCairo.cpp @@ -32,10 +32,11 @@ #include "config.h" #include "HarfBuzzFace.h" +#include "CairoUtilities.h" +#include "Font.h" #include "FontPlatformData.h" #include "GlyphBuffer.h" #include "HarfBuzzShaper.h" -#include "SimpleFontData.h" #include "TextEncoding.h" #include <cairo-ft.h> #include <cairo.h> @@ -44,6 +45,7 @@ #include FT_TRUETYPE_TABLES_H #include <hb.h> #include <wtf/text/CString.h> +#include <wtf/text/StringView.h> namespace WebCore { @@ -56,21 +58,6 @@ struct HarfBuzzFontData { cairo_scaled_font_t* m_cairoScaledFont; }; -class CairoFtFaceLocker { -public: - CairoFtFaceLocker(cairo_scaled_font_t* cairoScaledFont) : m_scaledFont(cairoScaledFont) { }; - FT_Face lock() - { - return cairo_ft_scaled_font_lock_face(m_scaledFont); - }; - ~CairoFtFaceLocker() - { - cairo_ft_scaled_font_unlock_face(m_scaledFont); - } -private: - cairo_scaled_font_t* m_scaledFont; -}; - static hb_position_t floatToHarfBuzzPosition(float value) { return static_cast<hb_position_t>(value * (1 << 16)); @@ -113,7 +100,7 @@ static hb_bool_t harfBuzzGetGlyph(hb_font_t*, void* fontData, hb_codepoint_t uni cairo_glyph_t* glyphs = 0; int numGlyphs = 0; UChar ch = unicode; - CString utf8Codepoint = UTF8Encoding().encode(&ch, 1, QuestionMarksForUnencodables); + CString utf8Codepoint = UTF8Encoding().encode(StringView(&ch, 1), QuestionMarksForUnencodables); if (cairo_scaled_font_text_to_glyphs(scaledFont, 0, 0, utf8Codepoint.data(), utf8Codepoint.length(), &glyphs, &numGlyphs, 0, 0, 0) != CAIRO_STATUS_SUCCESS) return false; if (!numGlyphs) @@ -177,9 +164,9 @@ static hb_blob_t* harfBuzzCairoGetTable(hb_face_t*, hb_tag_t tag, void* userData return 0; CairoFtFaceLocker cairoFtFaceLocker(scaledFont); - FT_Face ftFont = cairoFtFaceLocker.lock(); + FT_Face ftFont = cairoFtFaceLocker.ftFace(); if (!ftFont) - return 0; + return nullptr; FT_ULong tableSize = 0; FT_Error error = FT_Load_Sfnt_Table(ftFont, tag, 0, 0, &tableSize); diff --git a/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp b/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp index d4985c7a2..9e6f44867 100644 --- a/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp +++ b/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp @@ -31,17 +31,15 @@ #include "config.h" #include "HarfBuzzShaper.h" -#include "Font.h" +#include "FontCascade.h" #include "HarfBuzzFace.h" #include "SurrogatePairAwareTextIterator.h" -#include "TextRun.h" -#include "hb-icu.h" +#include <hb-icu.h> #include <unicode/normlzr.h> #include <unicode/uchar.h> #include <wtf/MathExtras.h> #include <wtf/StdLibExtras.h> -#include <wtf/Vector.h> -#include <wtf/unicode/Unicode.h> +#include <wtf/text/StringView.h> namespace WebCore { @@ -73,7 +71,7 @@ static inline float harfBuzzPositionToFloat(hb_position_t value) return static_cast<float>(value) / (1 << 16); } -HarfBuzzShaper::HarfBuzzRun::HarfBuzzRun(const SimpleFontData* fontData, unsigned startIndex, unsigned numCharacters, TextDirection direction, hb_script_t script) +HarfBuzzShaper::HarfBuzzRun::HarfBuzzRun(const Font* fontData, unsigned startIndex, unsigned numCharacters, TextDirection direction, hb_script_t script) : m_fontData(fontData) , m_startIndex(startIndex) , m_numCharacters(numCharacters) @@ -85,6 +83,11 @@ HarfBuzzShaper::HarfBuzzRun::HarfBuzzRun(const SimpleFontData* fontData, unsigne void HarfBuzzShaper::HarfBuzzRun::applyShapeResult(hb_buffer_t* harfBuzzBuffer) { m_numGlyphs = hb_buffer_get_length(harfBuzzBuffer); + if (!m_numGlyphs) { + // HarfBuzzShaper::fillGlyphBuffer gets offsets()[0] + m_offsets.resize(1); + return; + } m_glyphs.resize(m_numGlyphs); m_advances.resize(m_numGlyphs); m_glyphToCharacterIndexes.resize(m_numGlyphs); @@ -98,7 +101,7 @@ void HarfBuzzShaper::HarfBuzzRun::setGlyphAndPositions(unsigned index, uint16_t m_offsets[index] = FloatPoint(offsetX, offsetY); } -int HarfBuzzShaper::HarfBuzzRun::characterIndexForXPosition(float targetX) +unsigned HarfBuzzShaper::HarfBuzzRun::characterIndexForXPosition(float targetX) { ASSERT(targetX <= m_width); float currentX = 0; @@ -157,9 +160,9 @@ float HarfBuzzShaper::HarfBuzzRun::xPositionForOffset(unsigned offset) return position; } -static void normalizeCharacters(const TextRun& run, UChar* destination, int length) +static void normalizeCharacters(const TextRun& run, UChar* destination, unsigned length) { - int position = 0; + unsigned position = 0; bool error = false; const UChar* source; String stringFor8BitRun; @@ -171,12 +174,12 @@ static void normalizeCharacters(const TextRun& run, UChar* destination, int leng while (position < length) { UChar32 character; - int nextPosition = position; + unsigned nextPosition = position; U16_NEXT(source, nextPosition, length, character); // Don't normalize tabs as they are not treated as spaces for word-end. - if (Font::treatAsSpace(character) && character != '\t') + if (FontCascade::treatAsSpace(character) && character != '\t') character = ' '; - else if (Font::treatAsZeroWidthSpaceInComplexScript(character)) + else if (FontCascade::treatAsZeroWidthSpaceInComplexScript(character)) character = zeroWidthSpace; U16_APPEND(destination, position, length, character, error); ASSERT_UNUSED(error, !error); @@ -184,7 +187,7 @@ static void normalizeCharacters(const TextRun& run, UChar* destination, int leng } } -HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run) +HarfBuzzShaper::HarfBuzzShaper(const FontCascade* font, const TextRun& run) : m_font(font) , m_normalizedBufferLength(0) , m_run(run) @@ -193,8 +196,6 @@ HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run) , m_padPerWordBreak(0) , m_padError(0) , m_letterSpacing(font->letterSpacing()) - , m_fromIndex(0) - , m_toIndex(m_run.length()) { m_normalizedBuffer = std::make_unique<UChar[]>(m_run.length() + 1); m_normalizedBufferLength = m_run.length(); @@ -207,19 +208,19 @@ HarfBuzzShaper::~HarfBuzzShaper() { } -static void normalizeSpacesAndMirrorChars(const UChar* source, UChar* destination, int length, HarfBuzzShaper::NormalizeMode normalizeMode) +static void normalizeSpacesAndMirrorChars(const UChar* source, UChar* destination, unsigned length, HarfBuzzShaper::NormalizeMode normalizeMode) { - int position = 0; + unsigned position = 0; bool error = false; // Iterate characters in source and mirror character if needed. while (position < length) { UChar32 character; - int nextPosition = position; + unsigned nextPosition = position; U16_NEXT(source, nextPosition, length, character); // Don't normalize tabs as they are not treated as spaces for word-end - if (Font::treatAsSpace(character) && character != '\t') + if (FontCascade::treatAsSpace(character) && character != '\t') character = ' '; - else if (Font::treatAsZeroWidthSpace(character)) + else if (FontCascade::treatAsZeroWidthSpace(character)) character = zeroWidthSpace; else if (normalizeMode == HarfBuzzShaper::NormalizeMirrorChars) character = u_charMirror(character); @@ -257,7 +258,7 @@ void HarfBuzzShaper::setNormalizedBuffer(NormalizeMode normalizeMode) } else runCharacters = m_run.characters16(); - for (int i = 0; i < m_run.length(); ++i) { + for (unsigned i = 0; i < m_run.length(); ++i) { UChar ch = runCharacters[i]; if (::ublock_getCode(ch) == UBLOCK_COMBINING_DIACRITICAL_MARKS) { icu::Normalizer::normalize(icu::UnicodeString(runCharacters, @@ -329,18 +330,9 @@ void HarfBuzzShaper::setPadding(int padding) m_padPerWordBreak = 0; } - -void HarfBuzzShaper::setDrawRange(int from, int to) -{ - ASSERT_WITH_SECURITY_IMPLICATION(from >= 0); - ASSERT_WITH_SECURITY_IMPLICATION(to <= m_run.length()); - m_fromIndex = from; - m_toIndex = to; -} - void HarfBuzzShaper::setFontFeatures() { - const FontDescription& description = m_font->fontDescription(); + const auto& description = m_font->fontDescription(); if (description.orientation() == Vertical) { static hb_feature_t vert = { HarfBuzzFace::vertTag, 1, 0, static_cast<unsigned>(-1) }; static hb_feature_t vrt2 = { HarfBuzzFace::vrt2Tag, 1, 0, static_cast<unsigned>(-1) }; @@ -350,30 +342,28 @@ void HarfBuzzShaper::setFontFeatures() hb_feature_t kerning = { HarfBuzzFace::kernTag, 0, 0, static_cast<unsigned>(-1) }; switch (description.kerning()) { - case FontDescription::NormalKerning: + case Kerning::Normal: kerning.value = 1; m_features.append(kerning); break; - case FontDescription::NoneKerning: + case Kerning::NoShift: kerning.value = 0; m_features.append(kerning); break; - case FontDescription::AutoKerning: + case Kerning::Auto: break; default: ASSERT_NOT_REACHED(); } - FontFeatureSettings* settings = description.featureSettings(); - if (!settings) - return; + const FontFeatureSettings& settings = description.featureSettings(); - unsigned numFeatures = settings->size(); + unsigned numFeatures = settings.size(); for (unsigned i = 0; i < numFeatures; ++i) { hb_feature_t feature; - const UChar* tag = settings->at(i).tag().characters(); + auto& tag = settings[i].tag(); feature.tag = HB_TAG(tag[0], tag[1], tag[2], tag[3]); - feature.value = settings->at(i).value(); + feature.value = settings[i].value(); feature.start = 0; feature.end = static_cast<unsigned>(-1); m_features.append(feature); @@ -413,7 +403,7 @@ bool HarfBuzzShaper::collectHarfBuzzRuns() if (!iterator.consume(character, clusterLength)) return false; - const SimpleFontData* nextFontData = m_font->glyphDataForCharacter(character, false).fontData; + const Font* nextFontData = m_font->glyphDataForCharacter(character, false).font; UErrorCode errorCode = U_ZERO_ERROR; UScriptCode nextScript = uscript_getScript(character, &errorCode); if (U_FAILURE(errorCode)) @@ -421,19 +411,21 @@ bool HarfBuzzShaper::collectHarfBuzzRuns() do { const UChar* currentCharacterPosition = iterator.characters(); - const SimpleFontData* currentFontData = nextFontData; + const Font* currentFontData = nextFontData; + if (!currentFontData) + currentFontData = &m_font->primaryFont(); UScriptCode currentScript = nextScript; for (iterator.advance(clusterLength); iterator.consume(character, clusterLength); iterator.advance(clusterLength)) { - if (Font::treatAsZeroWidthSpace(character)) + if (FontCascade::treatAsZeroWidthSpace(character)) continue; if (U_GET_GC_MASK(character) & U_GC_M_MASK) { - int markLength = clusterLength; + unsigned markLength = clusterLength; const UChar* markCharactersEnd = iterator.characters() + clusterLength; while (markCharactersEnd < normalizedBufferEnd) { UChar32 nextCharacter; - int nextCharacterLength = 0; + unsigned nextCharacterLength = 0; U16_NEXT(markCharactersEnd, nextCharacterLength, normalizedBufferEnd - markCharactersEnd, nextCharacter); if (!(U_GET_GC_MASK(nextCharacter) & U_GC_M_MASK)) break; @@ -445,9 +437,9 @@ bool HarfBuzzShaper::collectHarfBuzzRuns() clusterLength = markLength; continue; } - nextFontData = m_font->glyphDataForCharacter(character, false).fontData; + nextFontData = m_font->glyphDataForCharacter(character, false).font; } else - nextFontData = m_font->glyphDataForCharacter(character, false).fontData; + nextFontData = m_font->glyphDataForCharacter(character, false).font; nextScript = uscript_getScript(character, &errorCode); if (U_FAILURE(errorCode)) @@ -458,11 +450,11 @@ bool HarfBuzzShaper::collectHarfBuzzRuns() nextScript = currentScript; currentCharacterPosition = iterator.characters(); } - unsigned numCharactersOfCurrentRun = iterator.currentCharacter() - startIndexOfCurrentRun; + unsigned numCharactersOfCurrentRun = iterator.currentIndex() - startIndexOfCurrentRun; hb_script_t script = hb_icu_script_to_script(currentScript); - m_harfBuzzRuns.append(HarfBuzzRun::create(currentFontData, startIndexOfCurrentRun, numCharactersOfCurrentRun, m_run.direction(), script)); + m_harfBuzzRuns.append(std::make_unique<HarfBuzzRun>(currentFontData, startIndexOfCurrentRun, numCharactersOfCurrentRun, m_run.direction(), script)); currentFontData = nextFontData; - startIndexOfCurrentRun = iterator.currentCharacter(); + startIndexOfCurrentRun = iterator.currentIndex(); } while (iterator.consume(character, clusterLength)); return !m_harfBuzzRuns.isEmpty(); @@ -477,9 +469,7 @@ bool HarfBuzzShaper::shapeHarfBuzzRuns(bool shouldSetDirection) for (unsigned i = 0; i < m_harfBuzzRuns.size(); ++i) { unsigned runIndex = m_run.rtl() ? m_harfBuzzRuns.size() - i - 1 : i; HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); - const SimpleFontData* currentFontData = currentRun->fontData(); - if (currentFontData->isSVGFont()) - return false; + const Font* currentFontData = currentRun->fontData(); hb_buffer_set_script(harfBuzzBuffer.get(), currentRun->script()); if (shouldSetDirection) @@ -494,9 +484,10 @@ bool HarfBuzzShaper::shapeHarfBuzzRuns(bool shouldSetDirection) hb_buffer_add_utf16(harfBuzzBuffer.get(), &preContext, 1, 1, 0); if (m_font->isSmallCaps() && u_islower(m_normalizedBuffer[currentRun->startIndex()])) { - String upperText = String(m_normalizedBuffer.get() + currentRun->startIndex(), currentRun->numCharacters()).upper(); - currentFontData = m_font->glyphDataForCharacter(upperText[0], false, SmallCapsVariant).fontData; - hb_buffer_add_utf16(harfBuzzBuffer.get(), reinterpret_cast<const uint16_t*>(upperText.characters()), currentRun->numCharacters(), 0, currentRun->numCharacters()); + String upperText = String(m_normalizedBuffer.get() + currentRun->startIndex(), currentRun->numCharacters()).convertToUppercaseWithoutLocale(); + currentFontData = m_font->glyphDataForCharacter(upperText[0], false, SmallCapsVariant).font; + const UChar* characters = StringView(upperText).upconvertedCharacters(); + hb_buffer_add_utf16(harfBuzzBuffer.get(), reinterpret_cast<const uint16_t*>(characters), currentRun->numCharacters(), 0, currentRun->numCharacters()); } else hb_buffer_add_utf16(harfBuzzBuffer.get(), reinterpret_cast<const uint16_t*>(m_normalizedBuffer.get() + currentRun->startIndex()), currentRun->numCharacters(), 0, currentRun->numCharacters()); @@ -523,7 +514,7 @@ bool HarfBuzzShaper::shapeHarfBuzzRuns(bool shouldSetDirection) void HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun(HarfBuzzRun* currentRun, hb_buffer_t* harfBuzzBuffer) { - const SimpleFontData* currentFontData = currentRun->fontData(); + const Font* currentFontData = currentRun->fontData(); hb_glyph_info_t* glyphInfos = hb_buffer_get_glyph_infos(harfBuzzBuffer, 0); hb_glyph_position_t* glyphPositions = hb_buffer_get_glyph_positions(harfBuzzBuffer, 0); @@ -545,7 +536,7 @@ void HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun(HarfBuzzRun* currentRun, hb glyphToCharacterIndexes[i] = glyphInfos[i].cluster; - if (isClusterEnd && !Font::treatAsZeroWidthSpace(m_normalizedBuffer[currentCharacterIndex])) + if (isClusterEnd && !FontCascade::treatAsZeroWidthSpace(m_normalizedBuffer[currentCharacterIndex])) spacing += m_letterSpacing; if (isClusterEnd && isWordEnd(currentCharacterIndex)) @@ -587,15 +578,13 @@ void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, Ha float glyphAdvanceX = advances[i] + nextOffset.x() - currentOffset.x(); float glyphAdvanceY = nextOffset.y() - currentOffset.y(); if (m_run.rtl()) { - if (currentCharacterIndex > m_toIndex) + if (currentCharacterIndex > m_run.length()) m_startOffset.move(glyphAdvanceX, glyphAdvanceY); - else if (currentCharacterIndex >= m_fromIndex) - glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY)); + else + glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY), currentCharacterIndex); } else { - if (currentCharacterIndex < m_fromIndex) - m_startOffset.move(glyphAdvanceX, glyphAdvanceY); - else if (currentCharacterIndex < m_toIndex) - glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY)); + if (currentCharacterIndex < m_run.length()) + glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY), currentCharacterIndex); } } } @@ -655,7 +644,7 @@ int HarfBuzzShaper::offsetForPosition(float targetX) return charactersSoFar; } -FloatRect HarfBuzzShaper::selectionRect(const FloatPoint& point, int height, int from, int to) +FloatRect HarfBuzzShaper::selectionRect(const FloatPoint& point, int height, unsigned from, unsigned to) { float currentX = 0; float fromX = 0; @@ -663,23 +652,34 @@ FloatRect HarfBuzzShaper::selectionRect(const FloatPoint& point, int height, int bool foundFromX = false; bool foundToX = false; + std::optional<unsigned> fromIndex = from; + std::optional<unsigned> toIndex = to; + if (m_run.rtl()) currentX = m_totalWidth; for (unsigned i = 0; i < m_harfBuzzRuns.size(); ++i) { if (m_run.rtl()) currentX -= m_harfBuzzRuns[i]->width(); - int numCharacters = m_harfBuzzRuns[i]->numCharacters(); - if (!foundFromX && from >= 0 && from < numCharacters) { - fromX = m_harfBuzzRuns[i]->xPositionForOffset(from) + currentX; + unsigned numCharacters = m_harfBuzzRuns[i]->numCharacters(); + if (!foundFromX && fromIndex.value() < numCharacters) { + fromX = m_harfBuzzRuns[i]->xPositionForOffset(fromIndex.value()) + currentX; foundFromX = true; - } else - from -= numCharacters; + } else { + if (fromIndex && fromIndex.value() >= numCharacters) + fromIndex.value() -= numCharacters; + else + fromIndex = std::nullopt; + } - if (!foundToX && to >= 0 && to < numCharacters) { - toX = m_harfBuzzRuns[i]->xPositionForOffset(to) + currentX; + if (!foundToX && toIndex.value() < numCharacters) { + toX = m_harfBuzzRuns[i]->xPositionForOffset(toIndex.value()) + currentX; foundToX = true; - } else - to -= numCharacters; + } else { + if (toIndex && toIndex.value() >= numCharacters) + toIndex.value() -= numCharacters; + else + toIndex = std::nullopt; + } if (foundFromX && foundToX) break; diff --git a/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.h b/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.h index 5747e4304..593c87cd2 100644 --- a/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.h +++ b/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.h @@ -37,15 +37,13 @@ #include "hb.h" #include <memory> #include <wtf/HashSet.h> -#include <wtf/OwnPtr.h> -#include <wtf/PassOwnPtr.h> #include <wtf/Vector.h> #include <wtf/unicode/CharacterNames.h> namespace WebCore { class Font; -class SimpleFontData; +class FontCascade; class HarfBuzzShaper { public: @@ -54,49 +52,43 @@ public: NormalizeMirrorChars }; - HarfBuzzShaper(const Font*, const TextRun&); + HarfBuzzShaper(const FontCascade*, const TextRun&); virtual ~HarfBuzzShaper(); - void setDrawRange(int from, int to); bool shape(GlyphBuffer* = 0); FloatPoint adjustStartPoint(const FloatPoint&); float totalWidth() { return m_totalWidth; } int offsetForPosition(float targetX); - FloatRect selectionRect(const FloatPoint&, int height, int from, int to); + FloatRect selectionRect(const FloatPoint&, int height, unsigned from, unsigned to); private: class HarfBuzzRun { public: - static PassOwnPtr<HarfBuzzRun> create(const SimpleFontData* fontData, unsigned startIndex, unsigned numCharacters, TextDirection direction, hb_script_t script) - { - return adoptPtr(new HarfBuzzRun(fontData, startIndex, numCharacters, direction, script)); - } + HarfBuzzRun(const Font*, unsigned startIndex, unsigned numCharacters, TextDirection, hb_script_t); void applyShapeResult(hb_buffer_t*); void setGlyphAndPositions(unsigned index, uint16_t glyphId, float advance, float offsetX, float offsetY); void setWidth(float width) { m_width = width; } - int characterIndexForXPosition(float targetX); + unsigned characterIndexForXPosition(float targetX); float xPositionForOffset(unsigned offset); - const SimpleFontData* fontData() { return m_fontData; } + const Font* fontData() { return m_fontData; } unsigned startIndex() const { return m_startIndex; } unsigned numCharacters() const { return m_numCharacters; } unsigned numGlyphs() const { return m_numGlyphs; } - uint16_t* glyphs() { return &m_glyphs[0]; } - float* advances() { return &m_advances[0]; } - FloatPoint* offsets() { return &m_offsets[0]; } - uint16_t* glyphToCharacterIndexes() { return &m_glyphToCharacterIndexes[0]; } + uint16_t* glyphs() { return m_glyphs.data(); } + float* advances() { return m_advances.data(); } + FloatPoint* offsets() { return m_offsets.data(); } + uint16_t* glyphToCharacterIndexes() { return m_glyphToCharacterIndexes.data(); } float width() { return m_width; } bool rtl() { return m_direction == RTL; } hb_script_t script() { return m_script; } private: - HarfBuzzRun(const SimpleFontData*, unsigned startIndex, unsigned numCharacters, TextDirection, hb_script_t); - - const SimpleFontData* m_fontData; + const Font* m_fontData; unsigned m_startIndex; - size_t m_numCharacters; + unsigned m_numCharacters; unsigned m_numGlyphs; TextDirection m_direction; hb_script_t m_script; @@ -128,7 +120,7 @@ private: GlyphBufferAdvance createGlyphBufferAdvance(float, float); - const Font* m_font; + const FontCascade* m_font; std::unique_ptr<UChar[]> m_normalizedBuffer; unsigned m_normalizedBufferLength; const TextRun& m_run; @@ -140,13 +132,10 @@ private: int m_letterSpacing; // Pixels to be added after each glyph. Vector<hb_feature_t, 4> m_features; - Vector<OwnPtr<HarfBuzzRun>, 16> m_harfBuzzRuns; + Vector<std::unique_ptr<HarfBuzzRun>, 16> m_harfBuzzRuns; FloatPoint m_startOffset; - int m_fromIndex; - int m_toIndex; - float m_totalWidth; }; |