diff --git a/DEPS b/DEPS index 80f6508fa4..56b421e935 100644 --- a/DEPS +++ b/DEPS @@ -12,7 +12,7 @@ }, { "url": "${PAG_GROUP}/tgfx.git", - "commit": "ab0937d87b579ebbe74028e6f8068da351a68d53", + "commit": "2d4c22ab50fe738d221025c1b68812e7b8d6f232", "dir": "third_party/tgfx" }, { diff --git a/src/platform/web/NativeTextShaper.cpp b/src/platform/web/NativeTextShaper.cpp index a24df8d89a..6706f4250e 100644 --- a/src/platform/web/NativeTextShaper.cpp +++ b/src/platform/web/NativeTextShaper.cpp @@ -116,7 +116,7 @@ PositionedGlyphs NativeTextShaper::Shape(const std::string& text, continue; } auto str = text.substr(infos[i].cluster, length); - auto glyphID = typeface->getGlyphID(str); + auto glyphID = typeface ? typeface->getGlyphID(str) : 0; if (glyphID == 0) { for (const auto& faceHolder : fallbackTypefaces) { auto face = faceHolder->getTypeface(); diff --git a/src/rendering/caches/TextAtlas.cpp b/src/rendering/caches/TextAtlas.cpp index c3941d48e9..1b770e3480 100644 --- a/src/rendering/caches/TextAtlas.cpp +++ b/src/rendering/caches/TextAtlas.cpp @@ -145,7 +145,8 @@ static AtlasTextRun CreateTextRun(const GlyphHandle& glyph) { static void ComputeStyleKey(tgfx::BytesKey* styleKey, const GlyphHandle& glyph) { styleKey->write(static_cast(glyph->getStyle())); styleKey->write(glyph->getStrokeWidth()); - styleKey->write(glyph->getFont().getTypeface()->uniqueID()); + auto typeface = glyph->getFont().getTypeface(); + styleKey->write(typeface ? typeface->uniqueID() : 0); } struct Page { diff --git a/src/rendering/caches/TextBlock.cpp b/src/rendering/caches/TextBlock.cpp index 165ceb5ddb..8d63a1b084 100644 --- a/src/rendering/caches/TextBlock.cpp +++ b/src/rendering/caches/TextBlock.cpp @@ -59,7 +59,7 @@ TextBlock::TextBlock(ID assetID, std::vector> lines, fl for (const auto& line : this->lines()) { for (const auto& tempGlyph : line) { auto glyph = tempGlyph->makeHorizontalGlyph(); - auto hasColor = glyph->getFont().getTypeface()->hasColor(); + auto hasColor = glyph->getFont().hasColor(); auto style = glyph->getStyle(); if (hasColor && (style == TextStyle::Stroke || style == TextStyle::StrokeAndFill)) { glyph->setStrokeWidth(0); diff --git a/src/rendering/caches/TextContentCache.cpp b/src/rendering/caches/TextContentCache.cpp index d6281973c5..2dfcaf429c 100644 --- a/src/rendering/caches/TextContentCache.cpp +++ b/src/rendering/caches/TextContentCache.cpp @@ -137,8 +137,7 @@ std::pair, std::vector> GetGlyphs( for (auto& line : glyphLines) { for (auto& glyph : line) { simpleGlyphs.push_back(glyph); - auto typeface = glyph->getFont().getTypeface(); - if (typeface->hasColor()) { + if (glyph->getFont().hasColor()) { colorGlyphs.push_back(glyph); } } diff --git a/src/rendering/graphics/Glyph.cpp b/src/rendering/graphics/Glyph.cpp index e05efc825a..a98e9954f4 100644 --- a/src/rendering/graphics/Glyph.cpp +++ b/src/rendering/graphics/Glyph.cpp @@ -112,7 +112,8 @@ void Glyph::computeStyleKey(tgfx::BytesKey* styleKey) const { static_cast(textStyle)}; styleKey->write(strokeValues); styleKey->write(strokeWidth); - styleKey->write(getFont().getTypeface()->uniqueID()); + auto typeface = getFont().getTypeface(); + styleKey->write(typeface ? typeface->uniqueID() : 0); } bool Glyph::isVisible() const { @@ -129,7 +130,7 @@ tgfx::Matrix Glyph::getTotalMatrix() const { } void Glyph::computeAtlasKey(tgfx::BytesKey* bytesKey, TextStyle style) const { - bytesKey->write(static_cast(getFont().getTypeface()->hasColor())); + bytesKey->write(static_cast(getFont().hasColor())); bytesKey->write(static_cast(getGlyphID())); bytesKey->write(static_cast(style)); } diff --git a/src/rendering/graphics/Text.cpp b/src/rendering/graphics/Text.cpp index 2f80decccc..ac553e3e39 100644 --- a/src/rendering/graphics/Text.cpp +++ b/src/rendering/graphics/Text.cpp @@ -328,7 +328,7 @@ void Text::draw(Canvas* canvas, const TextAtlas* textAtlas) const { } parameters.matrices.emplace_back(matrix); parameters.rects.emplace_back(locator.location); - if (glyph->getFont().getTypeface()->hasColor()) { + if (glyph->getFont().hasColor()) { auto alpha = canvas->getAlpha(); canvas->setAlpha(alpha * glyph->getAlpha()); Draw(canvas, textAtlas, parameters); diff --git a/src/rendering/utils/shaper/TextShaperHarfbuzz.cpp b/src/rendering/utils/shaper/TextShaperHarfbuzz.cpp index f65fc8fcb7..d9f23b283b 100644 --- a/src/rendering/utils/shaper/TextShaperHarfbuzz.cpp +++ b/src/rendering/utils/shaper/TextShaperHarfbuzz.cpp @@ -45,7 +45,10 @@ hb_blob_t* HBGetTable(hb_face_t*, hb_tag_t tag, void* userData) { [](void* ctx) { delete reinterpret_cast*>(ctx); }); } -std::shared_ptr CreateHBFace(const std::shared_ptr& typeface) { +std::shared_ptr CreateHBFace(std::shared_ptr typeface) { + if (typeface == nullptr) { + return nullptr; + } std::shared_ptr hbFace; auto data = typeface->getBytes(); if (data && !data->empty()) { @@ -142,7 +145,10 @@ static HBLockedFontCache GetHBFontCache() { return {HBFontLRU, HBFontCache, HBFontCacheMutex}; } -static std::shared_ptr CreateHBFont(const std::shared_ptr& typeface) { +static std::shared_ptr CreateHBFont(std::shared_ptr typeface) { + if (typeface == nullptr) { + return nullptr; + } auto cache = GetHBFontCache(); auto hbFont = cache.find(typeface->uniqueID()); if (hbFont == nullptr) { @@ -157,7 +163,7 @@ static std::shared_ptr CreateHBFont(const std::shared_ptr> Shape( - const std::string& text, const std::shared_ptr& typeface) { + const std::string& text, std::shared_ptr typeface) { auto hbFont = CreateHBFont(typeface); if (hbFont == nullptr) { return {}; diff --git a/src/rendering/utils/shaper/TextShaperPrimitive.cpp b/src/rendering/utils/shaper/TextShaperPrimitive.cpp index c767dd014c..2d44f304ce 100644 --- a/src/rendering/utils/shaper/TextShaperPrimitive.cpp +++ b/src/rendering/utils/shaper/TextShaperPrimitive.cpp @@ -32,8 +32,7 @@ PositionedGlyphs TextShaperPrimitive::Shape(const std::string& text, tgfx::UTF::NextUTF8(&textStart, textStop); auto length = textStart - oldPosition; auto str = std::string(oldPosition, length); - auto glyphID = typeface->getGlyphID(str); - bool found = false; + auto glyphID = typeface ? typeface->getGlyphID(str) : 0; if (glyphID == 0) { for (const auto& faceHolder : fallbackTypefaces) { auto face = faceHolder->getTypeface(); @@ -43,13 +42,9 @@ PositionedGlyphs TextShaperPrimitive::Shape(const std::string& text, glyphID = face->getGlyphID(str); if (glyphID != 0) { glyphs.emplace_back(std::move(face), glyphID, oldPosition - text.data()); - found = true; break; } } - if (!found) { - glyphs.emplace_back(typeface, glyphID, oldPosition - text.data()); - } } else { glyphs.emplace_back(typeface, glyphID, oldPosition - text.data()); } diff --git a/test/baseline/version.json b/test/baseline/version.json index 6f165b6ec4..3724b31d30 100644 --- a/test/baseline/version.json +++ b/test/baseline/version.json @@ -8451,7 +8451,7 @@ "NormalEmoji": "4b7f3114", "PositionAnimator": "7f7435d6f", "RangeSelectorTriangleHighLow": "5c3b8bc5", - "SmallFontSizeScale": "4b7f3114", + "SmallFontSizeScale": "b2fcd22b", "SmallFontSizeScale_LowResolution": "088c7e93", "TextLayerScaleAnimationWithMipmap": "3bd38676", "TextPathBox": "7f7435d6f",