diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index 3379260fc5..736541784d 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -47,7 +47,7 @@ class SkMaskFilter; class SkPath; class SkPathEffect; struct SkPoint; -class SkRunFont; +class SkFont; class SkShader; class SkSurfaceProps; class SkTextBlob; @@ -1279,7 +1279,7 @@ public: private: friend class SkGlyphRun; friend class SkGlyphRunBuilder; - SkPaint(const SkPaint&, const SkRunFont&); + SkPaint(const SkPaint&, const SkFont&); sk_sp fTypeface; sk_sp fPathEffect; diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp index 84497566f2..383837cfb9 100644 --- a/src/core/SkGlyphRun.cpp +++ b/src/core/SkGlyphRun.cpp @@ -29,7 +29,7 @@ static SkTypeface::Encoding convert_encoding(SkTextEncoding encoding) { // -- SkGlyphRun ----------------------------------------------------------------------------------- SkGlyphRun::SkGlyphRun(const SkPaint& basePaint, - const SkRunFont& runFont, + const SkFont& runFont, SkSpan positions, SkSpan glyphIDs, SkSpan text, @@ -52,7 +52,7 @@ void SkGlyphRun::eachGlyphToGlyphRun(SkGlyphRun::PerGlyph perGlyph) { SkGlyphID glyphID; SkGlyphRun run{ fRunPaint, - SkRunFont{fRunPaint}, + SkFont::LEGACY_ExtractFromPaint(fRunPaint), SkSpan{&point, 1}, SkSpan{&glyphID, 1}, SkSpan{}, @@ -195,7 +195,7 @@ void SkGlyphRunBuilder::drawTextAtOrigin( this->makeGlyphRun( paint, - SkRunFont{paint}, + SkFont::LEGACY_ExtractFromPaint(paint), glyphIDs, positions, SkSpan{}, @@ -208,7 +208,8 @@ void SkGlyphRunBuilder::drawText( auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength); if (!glyphIDs.empty()) { this->initialize(glyphIDs.size()); - this->simplifyDrawText(paint, SkRunFont{paint}, glyphIDs, origin, fPositions); + this->simplifyDrawText(paint, SkFont::LEGACY_ExtractFromPaint(paint), + glyphIDs, origin, fPositions); } this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0)); @@ -221,7 +222,7 @@ void SkGlyphRunBuilder::drawPosTextH(const SkPaint& paint, const void* bytes, if (!glyphIDs.empty()) { this->initialize(glyphIDs.size()); this->simplifyDrawPosTextH( - paint, SkRunFont{paint}, glyphIDs, xpos, constY, fPositions); + paint, SkFont::LEGACY_ExtractFromPaint(paint), glyphIDs, xpos, constY, fPositions); } this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0)); @@ -232,7 +233,7 @@ void SkGlyphRunBuilder::drawPosText(const SkPaint& paint, const void* bytes, auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength); if (!glyphIDs.empty()) { this->initialize(glyphIDs.size()); - this->simplifyDrawPosText(paint, SkRunFont{paint}, glyphIDs, pos); + this->simplifyDrawPosText(paint, SkFont::LEGACY_ExtractFromPaint(paint), glyphIDs, pos); } this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0)); @@ -263,18 +264,18 @@ void SkGlyphRunBuilder::drawTextBlob(const SkPaint& paint, const SkTextBlob& blo switch (it.positioning()) { case SkTextBlobRunIterator::kDefault_Positioning: { this->simplifyDrawText( - paint, it.runFont(), glyphIDs, offset, positions, text, clusters); + paint, it.font(), glyphIDs, offset, positions, text, clusters); } break; case SkTextBlobRunIterator::kHorizontal_Positioning: { auto constY = offset.y(); this->simplifyDrawPosTextH( - paint, it.runFont(), glyphIDs, it.pos(), constY, positions, text, clusters); + paint, it.font(), glyphIDs, it.pos(), constY, positions, text, clusters); } break; case SkTextBlobRunIterator::kFull_Positioning: this->simplifyDrawPosText( - paint, it.runFont(), glyphIDs, (const SkPoint*)it.pos(), text, clusters); + paint, it.font(), glyphIDs, (const SkPoint*)it.pos(), text, clusters); break; } @@ -288,7 +289,7 @@ void SkGlyphRunBuilder::drawGlyphPos( const SkPaint& paint, SkSpan glyphIDs, const SkPoint* pos) { if (!glyphIDs.empty()) { this->initialize(glyphIDs.size()); - this->simplifyDrawPosText(paint, SkRunFont{paint}, glyphIDs, pos); + this->simplifyDrawPosText(paint, SkFont::LEGACY_ExtractFromPaint(paint), glyphIDs, pos); this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0)); } } @@ -329,7 +330,7 @@ SkSpan SkGlyphRunBuilder::textToGlyphIDs( void SkGlyphRunBuilder::makeGlyphRun( const SkPaint& basePaint, - const SkRunFont& runFont, + const SkFont& runFont, SkSpan glyphIDs, SkSpan positions, SkSpan text, @@ -356,14 +357,16 @@ void SkGlyphRunBuilder::makeGlyphRunList( } void SkGlyphRunBuilder::simplifyDrawText( - const SkPaint& paint, const SkRunFont& runFont, SkSpan glyphIDs, + const SkPaint& paint, const SkFont& runFont, SkSpan glyphIDs, SkPoint origin, SkPoint* positions, SkSpan text, SkSpan clusters) { SkASSERT(!glyphIDs.empty()); auto runSize = glyphIDs.size(); - SkPaint runPaint{paint, runFont}; + SkPaint runPaint(paint); + runFont.LEGACY_applyToPaint(&runPaint); + runPaint.setTextEncoding(kGlyphID_SkTextEncoding); if (!glyphIDs.empty()) { fScratchAdvances.resize(runSize); @@ -391,7 +394,7 @@ void SkGlyphRunBuilder::simplifyDrawText( } void SkGlyphRunBuilder::simplifyDrawPosTextH( - const SkPaint& paint, const SkRunFont& runFont, SkSpan glyphIDs, + const SkPaint& paint, const SkFont& runFont, SkSpan glyphIDs, const SkScalar* xpos, SkScalar constY, SkPoint* positions, SkSpan text, SkSpan clusters) { @@ -404,7 +407,7 @@ void SkGlyphRunBuilder::simplifyDrawPosTextH( } void SkGlyphRunBuilder::simplifyDrawPosText( - const SkPaint& paint, const SkRunFont& runFont, SkSpan glyphIDs, + const SkPaint& paint, const SkFont& runFont, SkSpan glyphIDs, const SkPoint* pos, SkSpan text, SkSpan clusters) { auto runSize = glyphIDs.size(); diff --git a/src/core/SkGlyphRun.h b/src/core/SkGlyphRun.h index 703b1d025e..b91c480260 100644 --- a/src/core/SkGlyphRun.h +++ b/src/core/SkGlyphRun.h @@ -17,14 +17,14 @@ #include "SkTemplates.h" #include "SkTypes.h" +class SkFont; class SkGlyph; -class SkRunFont; class SkGlyphRun { public: SkGlyphRun() = default; SkGlyphRun(const SkPaint& basePaint, - const SkRunFont& runFont, + const SkFont& runFont, SkSpan positions, SkSpan glyphIDs, SkSpan text, @@ -137,7 +137,7 @@ private: void makeGlyphRun( const SkPaint& basePaint, - const SkRunFont& runFont, + const SkFont& runFont, SkSpan glyphIDs, SkSpan positions, SkSpan text, @@ -146,17 +146,17 @@ private: void makeGlyphRunList(const SkPaint& paint, const SkTextBlob* blob, SkPoint origin); void simplifyDrawText( - const SkPaint& paint, const SkRunFont& runFont, SkSpan glyphIDs, + const SkPaint& paint, const SkFont& runFont, SkSpan glyphIDs, SkPoint origin, SkPoint* positions, SkSpan text = SkSpan{}, SkSpan clusters = SkSpan{}); void simplifyDrawPosTextH( - const SkPaint& paint, const SkRunFont& runFont, SkSpan glyphIDs, + const SkPaint& paint, const SkFont& runFont, SkSpan glyphIDs, const SkScalar* xpos, SkScalar constY, SkPoint* positions, SkSpan text = SkSpan{}, SkSpan clusters = SkSpan{}); void simplifyDrawPosText( - const SkPaint& paint, const SkRunFont& runFont, SkSpan glyphIDs, + const SkPaint& paint, const SkFont& runFont, SkSpan glyphIDs, const SkPoint* pos, SkSpan text = SkSpan{}, SkSpan clusters = SkSpan{}); diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp index ab2d582c93..2e6b42782e 100644 --- a/src/core/SkTextBlob.cpp +++ b/src/core/SkTextBlob.cpp @@ -23,13 +23,6 @@ #include "text/GrTextBlobCache.h" #endif -SkRunFont::SkRunFont(const SkPaint& paint) : SkFont(SkFont::LEGACY_ExtractFromPaint(paint)) {} - -void SkRunFont::applyToPaint(SkPaint* paint) const { - this->LEGACY_applyToPaint(paint); - paint->setTextEncoding(kGlyphID_SkTextEncoding); -} - namespace { struct RunFontStorageEquivalent { SkScalar fSize, fScaleX; @@ -37,7 +30,7 @@ struct RunFontStorageEquivalent { SkScalar fSkewX; uint32_t fFlags; }; -static_assert(sizeof(SkRunFont) == sizeof(RunFontStorageEquivalent), "runfont_should_stay_packed"); +static_assert(sizeof(SkFont) == sizeof(RunFontStorageEquivalent), "runfont_should_stay_packed"); } size_t SkTextBlob::RunRecord::StorageSize(uint32_t glyphCount, uint32_t textSize, @@ -74,7 +67,7 @@ const SkTextBlob::RunRecord* SkTextBlob::RunRecord::Next(const RunRecord* run) { namespace { struct RunRecordStorageEquivalent { - SkRunFont fFont; + SkFont fFont; SkPoint fOffset; uint32_t fCount; uint32_t fFlags; @@ -235,7 +228,8 @@ SkTextBlobRunIterator::GlyphPositioning SkTextBlobRunIterator::positioning() con void SkTextBlobRunIterator::applyFontToPaint(SkPaint* paint) const { SkASSERT(!this->done()); - fCurrentRun->font().applyToPaint(paint); + fCurrentRun->font().LEGACY_applyToPaint(paint); + paint->setTextEncoding(kGlyphID_SkTextEncoding); } bool SkTextBlobRunIterator::isLCD() const { @@ -262,7 +256,8 @@ SkTextBlobBuilder::~SkTextBlobBuilder() { SkRect SkTextBlobBuilder::TightRunBounds(const SkTextBlob::RunRecord& run) { SkRect bounds; SkPaint paint; - run.font().applyToPaint(&paint); + run.font().LEGACY_applyToPaint(&paint); + paint.setTextEncoding(kGlyphID_SkTextEncoding); if (SkTextBlob::kDefault_Positioning == run.positioning()) { paint.measureText(run.glyphBuffer(), run.glyphCount() * sizeof(uint16_t), &bounds); diff --git a/src/core/SkTextBlobPriv.h b/src/core/SkTextBlobPriv.h index 3710afbfe5..2bd9178d4c 100644 --- a/src/core/SkTextBlobPriv.h +++ b/src/core/SkTextBlobPriv.h @@ -59,21 +59,6 @@ public: } }; -// TODO(fmalita): replace with SkFont. -class SkRunFont : public SkFont { -public: - SkRunFont(const SkFont& font) : SkFont(font) {} - SkRunFont(const SkPaint& paint); - - void applyToPaint(SkPaint* paint) const; - - bool operator==(const SkRunFont& other) const { return SkFont::operator==(other); } - - bool operator!=(const SkRunFont& other) const { - return !(*this == other); - } -}; - // // Textblob data is laid out into externally-managed storage as follows: // @@ -120,7 +105,7 @@ public: return fOffset; } - const SkRunFont& font() const { + const SkFont& font() const { return fFont; } @@ -186,7 +171,7 @@ private: return fFlags & kExtended_Flag; } - SkRunFont fFont; + SkFont fFont; uint32_t fCount; SkPoint fOffset; uint32_t fFlags; @@ -195,9 +180,9 @@ private: }; // (paint->getFlags() & ~kFlagsMask) | fFlags -inline SkPaint::SkPaint(const SkPaint& basePaint, const SkRunFont& runFont) : SkPaint(basePaint) { +inline SkPaint::SkPaint(const SkPaint& basePaint, const SkFont& runFont) : SkPaint(basePaint) { fBitfields.fTextEncoding = (unsigned)kGlyphID_SkTextEncoding; - runFont.applyToPaint(this); + runFont.LEGACY_applyToPaint(this); } /** @@ -241,10 +226,6 @@ public: SkASSERT(!this->done()); return fCurrentRun->font(); } - const SkRunFont& runFont() const { - SkASSERT(!this->done()); - return fCurrentRun->font(); - } void applyFontToPaint(SkPaint*) const; GlyphPositioning positioning() const; uint32_t* clusters() const { diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp index 91e64e0c40..cd70d36b52 100644 --- a/tests/PDFPrimitivesTest.cpp +++ b/tests/PDFPrimitivesTest.cpp @@ -488,7 +488,7 @@ DEF_TEST(SkPDF_Primitives_Color, reporter) { static SkGlyphRun make_run(size_t len, const SkGlyphID* glyphs, SkPoint* pos, SkPaint paint, const uint32_t* clusters, size_t utf8TextByteLength, const char* utf8Text) { - return SkGlyphRun(paint, SkRunFont{paint}, + return SkGlyphRun(paint, SkFont::LEGACY_ExtractFromPaint(paint), SkSpan{pos, len}, SkSpan{glyphs, len}, SkSpan{utf8Text, utf8TextByteLength},