Make SkGlyphRun use SkFont instead of SkPaint

Change-Id: I5f34857a21deac418eaaeb19c776b2148b7f0737
Reviewed-on: https://skia-review.googlesource.com/c/175460
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2018-12-06 17:11:43 -05:00 committed by Skia Commit-Bot
parent ece772d8c2
commit 95e1760a78
16 changed files with 112 additions and 124 deletions

View File

@ -1205,10 +1205,6 @@ public:
Style style) const; Style style) const;
private: private:
friend class SkGlyphRun;
friend class SkGlyphRunBuilder;
SkPaint(const SkPaint&, const SkFont&);
sk_sp<SkTypeface> fTypeface; sk_sp<SkTypeface> fTypeface;
sk_sp<SkPathEffect> fPathEffect; sk_sp<SkPathEffect> fPathEffect;
sk_sp<SkShader> fShader; sk_sp<SkShader> fShader;

View File

@ -161,7 +161,8 @@ void SkInternalAtlasTextTarget::drawText(const SkGlyphID glyphs[], const SkPoint
auto* grContext = this->context()->internal().grContext(); auto* grContext = this->context()->internal().grContext();
auto atlasTextContext = grContext->contextPriv().drawingManager()->getTextContext(); auto atlasTextContext = grContext->contextPriv().drawingManager()->getTextContext();
SkGlyphRunBuilder builder; SkGlyphRunBuilder builder;
builder.drawGlyphPos(paint, SkSpan<const SkGlyphID>{glyphs, SkTo<size_t>(glyphCnt)}, positions); builder.drawGlyphsWithPositions(paint, SkSpan<const SkGlyphID>{glyphs, SkTo<size_t>(glyphCnt)},
positions);
auto glyphRunList = builder.useGlyphRunList(); auto glyphRunList = builder.useGlyphRunList();
if (!glyphRunList.empty()) { if (!glyphRunList.empty()) {
atlasTextContext->drawGlyphRunList(grContext, this, GrNoClip(), this->ctm(), props, atlasTextContext->drawGlyphRunList(grContext, this, GrNoClip(), this->ctm(), props,

View File

@ -2456,7 +2456,7 @@ void SkCanvas::onDrawTextRSXform(const void* text, size_t len, const SkRSXform x
auto list = fScratchGlyphRunBuilder->useGlyphRunList(); auto list = fScratchGlyphRunBuilder->useGlyphRunList();
if (!list.empty()) { if (!list.empty()) {
auto glyphRun = list[0]; auto glyphRun = list[0];
iter.fDevice->drawGlyphRunRSXform(&glyphRun, xform); iter.fDevice->drawGlyphRunRSXform(&glyphRun, xform, paint);
} }
} }

View File

@ -327,22 +327,22 @@ bool SkBaseDevice::peekPixels(SkPixmap* pmap) {
#include "SkUtils.h" #include "SkUtils.h"
void SkBaseDevice::drawGlyphRunRSXform( void SkBaseDevice::drawGlyphRunRSXform(
SkGlyphRun* run, const SkRSXform* xform) { SkGlyphRun* run, const SkRSXform* xform, const SkPaint& paint) {
const SkMatrix originalCTM = this->ctm(); const SkMatrix originalCTM = this->ctm();
if (!originalCTM.isFinite() || !SkScalarIsFinite(run->paint().getTextSize()) || if (!originalCTM.isFinite() || !SkScalarIsFinite(run->font().getSize()) ||
!SkScalarIsFinite(run->paint().getTextScaleX()) || !SkScalarIsFinite(run->font().getScaleX()) ||
!SkScalarIsFinite(run->paint().getTextSkewX())) { !SkScalarIsFinite(run->font().getSkewX())) {
return; return;
} }
auto perGlyph = [this, &xform, &originalCTM] (const SkGlyphRun& glyphRun) { auto perGlyph = [this, &xform, &originalCTM, &paint] (const SkGlyphRun& glyphRun) {
SkMatrix ctm; SkMatrix ctm;
ctm.setRSXform(*xform++); ctm.setRSXform(*xform++);
// We want to rotate each glyph by the rsxform, but we don't want to rotate "space" // We want to rotate each glyph by the rsxform, but we don't want to rotate "space"
// (i.e. the shader that cares about the ctm) so we have to undo our little ctm trick // (i.e. the shader that cares about the ctm) so we have to undo our little ctm trick
// with a localmatrixshader so that the shader draws as if there was no change to the ctm. // with a localmatrixshader so that the shader draws as if there was no change to the ctm.
SkPaint transformingPaint = glyphRun.paint(); SkPaint transformingPaint{paint};
auto shader = transformingPaint.getShader(); auto shader = transformingPaint.getShader();
if (shader) { if (shader) {
SkMatrix inverse; SkMatrix inverse;
@ -356,8 +356,7 @@ void SkBaseDevice::drawGlyphRunRSXform(
ctm.setConcat(originalCTM, ctm); ctm.setConcat(originalCTM, ctm);
this->setCTM(ctm); this->setCTM(ctm);
SkGlyphRun transformedGlyphRun{glyphRun, transformingPaint}; this->drawGlyphRunList(SkGlyphRunList{glyphRun, transformingPaint});
this->drawGlyphRunList(SkGlyphRunList{transformedGlyphRun});
}; };
run->eachGlyphToGlyphRun(perGlyph); run->eachGlyphToGlyphRun(perGlyph);
this->setCTM(originalCTM); this->setCTM(originalCTM);

View File

@ -235,7 +235,7 @@ protected:
*/ */
virtual void drawDevice(SkBaseDevice*, int x, int y, const SkPaint&) = 0; virtual void drawDevice(SkBaseDevice*, int x, int y, const SkPaint&) = 0;
void drawGlyphRunRSXform(SkGlyphRun* run, const SkRSXform* xform); void drawGlyphRunRSXform(SkGlyphRun* run, const SkRSXform* xform, const SkPaint& paint);
virtual void drawDrawable(SkDrawable*, const SkMatrix*, SkCanvas*); virtual void drawDrawable(SkDrawable*, const SkMatrix*, SkCanvas*);

View File

@ -7,6 +7,7 @@
#include "SkGlyphRun.h" #include "SkGlyphRun.h"
#include "SkFont.h"
#include "SkGlyphCache.h" #include "SkGlyphCache.h"
#include "SkPaint.h" #include "SkPaint.h"
#include "SkPaintPriv.h" #include "SkPaintPriv.h"
@ -28,8 +29,7 @@ static SkTypeface::Encoding convert_encoding(SkTextEncoding encoding) {
} // namespace } // namespace
// -- SkGlyphRun ----------------------------------------------------------------------------------- // -- SkGlyphRun -----------------------------------------------------------------------------------
SkGlyphRun::SkGlyphRun(const SkPaint& basePaint, SkGlyphRun::SkGlyphRun(const SkFont& font,
const SkFont& runFont,
SkSpan<const SkPoint> positions, SkSpan<const SkPoint> positions,
SkSpan<const SkGlyphID> glyphIDs, SkSpan<const SkGlyphID> glyphIDs,
SkSpan<const char> text, SkSpan<const char> text,
@ -38,21 +38,20 @@ SkGlyphRun::SkGlyphRun(const SkPaint& basePaint,
, fGlyphIDs{glyphIDs} , fGlyphIDs{glyphIDs}
, fText{text} , fText{text}
, fClusters{clusters} , fClusters{clusters}
, fRunPaint{basePaint, runFont} {} , fFont{font} {}
SkGlyphRun::SkGlyphRun(const SkGlyphRun& that, const SkPaint& paint) SkGlyphRun::SkGlyphRun(const SkGlyphRun& that, const SkFont& font)
: fPositions{that.fPositions} : fPositions{that.fPositions}
, fGlyphIDs{that.fGlyphIDs} , fGlyphIDs{that.fGlyphIDs}
, fText{that.fText} , fText{that.fText}
, fClusters{that.fClusters} , fClusters{that.fClusters}
, fRunPaint{paint} {} , fFont{font} {}
void SkGlyphRun::eachGlyphToGlyphRun(SkGlyphRun::PerGlyph perGlyph) { void SkGlyphRun::eachGlyphToGlyphRun(SkGlyphRun::PerGlyph perGlyph) {
SkPoint point; SkPoint point;
SkGlyphID glyphID; SkGlyphID glyphID;
SkGlyphRun run{ SkGlyphRun run{
fRunPaint, this->font(),
SkFont::LEGACY_ExtractFromPaint(fRunPaint),
SkSpan<const SkPoint>{&point, 1}, SkSpan<const SkPoint>{&point, 1},
SkSpan<const SkGlyphID>{&glyphID, 1}, SkSpan<const SkGlyphID>{&glyphID, 1},
SkSpan<const char>{}, SkSpan<const char>{},
@ -84,8 +83,8 @@ SkGlyphRunList::SkGlyphRunList(
, fOrigin{origin} , fOrigin{origin}
, fGlyphRuns{glyphRunList} { } , fGlyphRuns{glyphRunList} { }
SkGlyphRunList::SkGlyphRunList(const SkGlyphRun& glyphRun) SkGlyphRunList::SkGlyphRunList(const SkGlyphRun& glyphRun, const SkPaint& paint)
: fOriginalPaint{&glyphRun.paint()} : fOriginalPaint{&paint}
, fOriginalTextBlob{nullptr} , fOriginalTextBlob{nullptr}
, fOrigin{SkPoint::Make(0, 0)} , fOrigin{SkPoint::Make(0, 0)}
, fGlyphRuns{SkSpan<const SkGlyphRun>{&glyphRun, 1}} {} , fGlyphRuns{SkSpan<const SkGlyphRun>{&glyphRun, 1}} {}
@ -97,7 +96,7 @@ uint64_t SkGlyphRunList::uniqueID() const {
bool SkGlyphRunList::anyRunsLCD() const { bool SkGlyphRunList::anyRunsLCD() const {
for (const auto& r : fGlyphRuns) { for (const auto& r : fGlyphRuns) {
if (r.paint().isLCDRenderText()) { if (r.font().getEdging() == SkFont::Edging::kSubpixelAntiAlias) {
return true; return true;
} }
} }
@ -106,7 +105,7 @@ bool SkGlyphRunList::anyRunsLCD() const {
bool SkGlyphRunList::anyRunsSubpixelPositioned() const { bool SkGlyphRunList::anyRunsSubpixelPositioned() const {
for (const auto& r : fGlyphRuns) { for (const auto& r : fGlyphRuns) {
if (r.paint().isSubpixelText()) { if (r.font().isSubpixel()) {
return true; return true;
} }
} }
@ -194,7 +193,6 @@ void SkGlyphRunBuilder::drawTextAtOrigin(
sk_bzero((void *)positions.data(), positions.size_bytes()); sk_bzero((void *)positions.data(), positions.size_bytes());
this->makeGlyphRun( this->makeGlyphRun(
paint,
SkFont::LEGACY_ExtractFromPaint(paint), SkFont::LEGACY_ExtractFromPaint(paint),
glyphIDs, glyphIDs,
positions, positions,
@ -208,7 +206,7 @@ void SkGlyphRunBuilder::drawText(
auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength); auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength);
if (!glyphIDs.empty()) { if (!glyphIDs.empty()) {
this->initialize(glyphIDs.size()); this->initialize(glyphIDs.size());
this->simplifyDrawText(paint, SkFont::LEGACY_ExtractFromPaint(paint), this->simplifyDrawText(SkFont::LEGACY_ExtractFromPaint(paint),
glyphIDs, origin, fPositions); glyphIDs, origin, fPositions);
} }
@ -240,18 +238,18 @@ void SkGlyphRunBuilder::drawTextBlob(const SkPaint& paint, const SkTextBlob& blo
switch (it.positioning()) { switch (it.positioning()) {
case SkTextBlobRunIterator::kDefault_Positioning: { case SkTextBlobRunIterator::kDefault_Positioning: {
this->simplifyDrawText( this->simplifyDrawText(
paint, it.font(), glyphIDs, offset, positions, text, clusters); it.font(), glyphIDs, offset, positions, text, clusters);
} }
break; break;
case SkTextBlobRunIterator::kHorizontal_Positioning: { case SkTextBlobRunIterator::kHorizontal_Positioning: {
auto constY = offset.y(); auto constY = offset.y();
this->simplifyDrawPosTextH( this->simplifyDrawPosTextH(
paint, it.font(), glyphIDs, it.pos(), constY, positions, text, clusters); it.font(), glyphIDs, it.pos(), constY, positions, text, clusters);
} }
break; break;
case SkTextBlobRunIterator::kFull_Positioning: case SkTextBlobRunIterator::kFull_Positioning:
this->simplifyDrawPosText( this->simplifyDrawPosText(
paint, it.font(), glyphIDs, (const SkPoint*)it.pos(), text, clusters); it.font(), glyphIDs, (const SkPoint*)it.pos(), text, clusters);
break; break;
} }
@ -261,11 +259,11 @@ void SkGlyphRunBuilder::drawTextBlob(const SkPaint& paint, const SkTextBlob& blo
this->makeGlyphRunList(paint, &blob, origin); this->makeGlyphRunList(paint, &blob, origin);
} }
void SkGlyphRunBuilder::drawGlyphPos( void SkGlyphRunBuilder::drawGlyphsWithPositions(
const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos) { const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos) {
if (!glyphIDs.empty()) { if (!glyphIDs.empty()) {
this->initialize(glyphIDs.size()); this->initialize(glyphIDs.size());
this->simplifyDrawPosText(paint, SkFont::LEGACY_ExtractFromPaint(paint), glyphIDs, pos); this->simplifyDrawPosText(SkFont::LEGACY_ExtractFromPaint(paint), glyphIDs, pos);
this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0)); this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0));
} }
} }
@ -305,8 +303,7 @@ SkSpan<const SkGlyphID> SkGlyphRunBuilder::textToGlyphIDs(
} }
void SkGlyphRunBuilder::makeGlyphRun( void SkGlyphRunBuilder::makeGlyphRun(
const SkPaint& basePaint, const SkFont& font,
const SkFont& runFont,
SkSpan<const SkGlyphID> glyphIDs, SkSpan<const SkGlyphID> glyphIDs,
SkSpan<const SkPoint> positions, SkSpan<const SkPoint> positions,
SkSpan<const char> text, SkSpan<const char> text,
@ -315,8 +312,7 @@ void SkGlyphRunBuilder::makeGlyphRun(
// Ignore empty runs. // Ignore empty runs.
if (!glyphIDs.empty()) { if (!glyphIDs.empty()) {
fGlyphRunListStorage.emplace_back( fGlyphRunListStorage.emplace_back(
basePaint, font,
runFont,
positions, positions,
glyphIDs, glyphIDs,
text, text,
@ -333,22 +329,17 @@ void SkGlyphRunBuilder::makeGlyphRunList(
} }
void SkGlyphRunBuilder::simplifyDrawText( void SkGlyphRunBuilder::simplifyDrawText(
const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkFont& font, SkSpan<const SkGlyphID> glyphIDs,
SkPoint origin, SkPoint* positions, SkPoint origin, SkPoint* positions,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) { SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
SkASSERT(!glyphIDs.empty()); SkASSERT(!glyphIDs.empty());
auto runSize = glyphIDs.size(); auto runSize = glyphIDs.size();
SkPaint runPaint(paint);
runFont.LEGACY_applyToPaint(&runPaint);
runPaint.setTextEncoding(kGlyphID_SkTextEncoding);
if (!glyphIDs.empty()) { if (!glyphIDs.empty()) {
fScratchAdvances.resize(runSize); fScratchAdvances.resize(runSize);
{ {
const SkFont font = SkFont::LEGACY_ExtractFromPaint(runPaint); auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font);
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font, runPaint);
cache->getAdvances(glyphIDs, fScratchAdvances.data()); cache->getAdvances(glyphIDs, fScratchAdvances.data());
} }
@ -360,8 +351,7 @@ void SkGlyphRunBuilder::simplifyDrawText(
} }
this->makeGlyphRun( this->makeGlyphRun(
paint, font,
runFont,
glyphIDs, glyphIDs,
SkSpan<const SkPoint>{positions, runSize}, SkSpan<const SkPoint>{positions, runSize},
text, text,
@ -370,7 +360,7 @@ void SkGlyphRunBuilder::simplifyDrawText(
} }
void SkGlyphRunBuilder::simplifyDrawPosTextH( void SkGlyphRunBuilder::simplifyDrawPosTextH(
const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkFont& font, SkSpan<const SkGlyphID> glyphIDs,
const SkScalar* xpos, SkScalar constY, SkPoint* positions, const SkScalar* xpos, SkScalar constY, SkPoint* positions,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) { SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
@ -379,18 +369,17 @@ void SkGlyphRunBuilder::simplifyDrawPosTextH(
*posCursor++ = SkPoint::Make(x, constY); *posCursor++ = SkPoint::Make(x, constY);
} }
simplifyDrawPosText(paint, runFont, glyphIDs, positions, text, clusters); simplifyDrawPosText(font, glyphIDs, positions, text, clusters);
} }
void SkGlyphRunBuilder::simplifyDrawPosText( void SkGlyphRunBuilder::simplifyDrawPosText(
const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkFont& font, SkSpan<const SkGlyphID> glyphIDs,
const SkPoint* pos, const SkPoint* pos,
SkSpan<const char> text, SkSpan<const uint32_t> clusters) { SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
auto runSize = glyphIDs.size(); auto runSize = glyphIDs.size();
this->makeGlyphRun( this->makeGlyphRun(
paint, font,
runFont,
glyphIDs, glyphIDs,
SkSpan<const SkPoint>{pos, runSize}, SkSpan<const SkPoint>{pos, runSize},
text, text,

View File

@ -11,25 +11,24 @@
#include <functional> #include <functional>
#include <vector> #include <vector>
#include "SkFont.h"
#include "SkPaint.h" #include "SkPaint.h"
#include "SkPoint.h" #include "SkPoint.h"
#include "SkSpan.h" #include "SkSpan.h"
#include "SkTemplates.h" #include "SkTemplates.h"
#include "SkTypes.h" #include "SkTypes.h"
class SkFont;
class SkGlyph; class SkGlyph;
class SkGlyphRun { class SkGlyphRun {
public: public:
SkGlyphRun() = default; SkGlyphRun() = default;
SkGlyphRun(const SkPaint& basePaint, SkGlyphRun(const SkFont& font,
const SkFont& runFont,
SkSpan<const SkPoint> positions, SkSpan<const SkPoint> positions,
SkSpan<const SkGlyphID> glyphIDs, SkSpan<const SkGlyphID> glyphIDs,
SkSpan<const char> text, SkSpan<const char> text,
SkSpan<const uint32_t> clusters); SkSpan<const uint32_t> clusters);
SkGlyphRun(const SkGlyphRun& glyphRun, const SkPaint& paint); SkGlyphRun(const SkGlyphRun& glyphRun, const SkFont& font);
// A function that turns an SkGlyphRun into an SkGlyphRun for each glyph. // A function that turns an SkGlyphRun into an SkGlyphRun for each glyph.
using PerGlyph = std::function<void (const SkGlyphRun&)>; using PerGlyph = std::function<void (const SkGlyphRun&)>;
@ -40,7 +39,7 @@ public:
size_t runSize() const { return fGlyphIDs.size(); } size_t runSize() const { return fGlyphIDs.size(); }
SkSpan<const SkPoint> positions() const { return fPositions.toConst(); } SkSpan<const SkPoint> positions() const { return fPositions.toConst(); }
SkSpan<const SkGlyphID> glyphsIDs() const { return fGlyphIDs; } SkSpan<const SkGlyphID> glyphsIDs() const { return fGlyphIDs; }
const SkPaint& paint() const { return fRunPaint; } const SkFont& font() const { return fFont; }
SkSpan<const uint32_t> clusters() const { return fClusters; } SkSpan<const uint32_t> clusters() const { return fClusters; }
SkSpan<const char> text() const { return fText; } SkSpan<const char> text() const { return fText; }
@ -54,7 +53,7 @@ private:
// Original clusters from SkTextBlob if present. Will be empty if not present. // Original clusters from SkTextBlob if present. Will be empty if not present.
const SkSpan<const uint32_t> fClusters; const SkSpan<const uint32_t> fClusters;
// Paint for this run modified to have glyph encoding and left alignment. // Paint for this run modified to have glyph encoding and left alignment.
SkPaint fRunPaint; SkFont fFont;
}; };
class SkGlyphRunList { class SkGlyphRunList {
@ -74,7 +73,7 @@ public:
SkPoint origin, SkPoint origin,
SkSpan<const SkGlyphRun> glyphRunList); SkSpan<const SkGlyphRun> glyphRunList);
SkGlyphRunList(const SkGlyphRun& glyphRun); SkGlyphRunList(const SkGlyphRun& glyphRun, const SkPaint& paint);
uint64_t uniqueID() const; uint64_t uniqueID() const;
bool anyRunsLCD() const; bool anyRunsLCD() const;
@ -120,7 +119,7 @@ public:
void drawText( void drawText(
const SkPaint& paint, const void* bytes, size_t byteLength, SkPoint origin); const SkPaint& paint, const void* bytes, size_t byteLength, SkPoint origin);
void drawTextBlob(const SkPaint& paint, const SkTextBlob& blob, SkPoint origin); void drawTextBlob(const SkPaint& paint, const SkTextBlob& blob, SkPoint origin);
void drawGlyphPos( void drawGlyphsWithPositions(
const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos); const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos);
const SkGlyphRunList& useGlyphRunList(); const SkGlyphRunList& useGlyphRunList();
@ -131,8 +130,7 @@ private:
const SkPaint& paint, const void* bytes, size_t byteLength); const SkPaint& paint, const void* bytes, size_t byteLength);
void makeGlyphRun( void makeGlyphRun(
const SkPaint& basePaint, const SkFont& font,
const SkFont& runFont,
SkSpan<const SkGlyphID> glyphIDs, SkSpan<const SkGlyphID> glyphIDs,
SkSpan<const SkPoint> positions, SkSpan<const SkPoint> positions,
SkSpan<const char> text, SkSpan<const char> text,
@ -141,17 +139,17 @@ private:
void makeGlyphRunList(const SkPaint& paint, const SkTextBlob* blob, SkPoint origin); void makeGlyphRunList(const SkPaint& paint, const SkTextBlob* blob, SkPoint origin);
void simplifyDrawText( void simplifyDrawText(
const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkFont& font, SkSpan<const SkGlyphID> glyphIDs,
SkPoint origin, SkPoint* positions, SkPoint origin, SkPoint* positions,
SkSpan<const char> text = SkSpan<const char>{}, SkSpan<const char> text = SkSpan<const char>{},
SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{}); SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{});
void simplifyDrawPosTextH( void simplifyDrawPosTextH(
const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkFont& font, SkSpan<const SkGlyphID> glyphIDs,
const SkScalar* xpos, SkScalar constY, SkPoint* positions, const SkScalar* xpos, SkScalar constY, SkPoint* positions,
SkSpan<const char> text = SkSpan<const char>{}, SkSpan<const char> text = SkSpan<const char>{},
SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{}); SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{});
void simplifyDrawPosText( void simplifyDrawPosText(
const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs, const SkFont& font, SkSpan<const SkGlyphID> glyphIDs,
const SkPoint* pos, const SkPoint* pos,
SkSpan<const char> text = SkSpan<const char>{}, SkSpan<const char> text = SkSpan<const char>{},
SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{}); SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{});

View File

@ -164,11 +164,12 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
for (auto& glyphRun : glyphRunList) { for (auto& glyphRun : glyphRunList) {
// The bitmap blitters can only draw lcd text to a N32 bitmap in srcOver. Otherwise, // The bitmap blitters can only draw lcd text to a N32 bitmap in srcOver. Otherwise,
// convert the lcd text into A8 text. The props communicates this to the scaler. // convert the lcd text into A8 text. The props communicates this to the scaler.
auto& props = (kN32_SkColorType == fColorType && glyphRun.paint().isSrcOver()) auto& props = (kN32_SkColorType == fColorType && glyphRunList.paint().isSrcOver())
? fDeviceProps ? fDeviceProps
: fBitmapFallbackProps; : fBitmapFallbackProps;
const SkPaint& paint = glyphRun.paint(); SkPaint paint{glyphRunList.paint()};
glyphRun.font().LEGACY_applyToPaint(&paint);
auto runSize = glyphRun.runSize(); auto runSize = glyphRun.runSize();
this->ensureBitmapBuffers(runSize); this->ensureBitmapBuffers(runSize);
@ -324,7 +325,7 @@ void SkGlyphRunListPainter::processARGBFallback(
template <typename PerEmptyT, typename PerPathT> template <typename PerEmptyT, typename PerPathT>
void SkGlyphRunListPainter::drawGlyphRunAsPathWithARGBFallback( void SkGlyphRunListPainter::drawGlyphRunAsPathWithARGBFallback(
SkGlyphCacheInterface* pathCache, const SkGlyphRun& glyphRun, SkGlyphCacheInterface* pathCache, const SkGlyphRun& glyphRun,
SkPoint origin, const SkMatrix& viewMatrix, SkScalar textScale, SkPoint origin, const SkPaint& paint, const SkMatrix& viewMatrix, SkScalar textScale,
PerEmptyT&& perEmpty, PerPathT&& perPath, ARGBFallback&& argbFallback) { PerEmptyT&& perEmpty, PerPathT&& perPath, ARGBFallback&& argbFallback) {
fARGBGlyphsIDs.clear(); fARGBGlyphsIDs.clear();
fARGBPositions.clear(); fARGBPositions.clear();
@ -351,8 +352,10 @@ void SkGlyphRunListPainter::drawGlyphRunAsPathWithARGBFallback(
} }
if (!fARGBGlyphsIDs.empty()) { if (!fARGBGlyphsIDs.empty()) {
SkPaint runPaint{paint};
glyphRun.font().LEGACY_applyToPaint(&runPaint);
this->processARGBFallback( this->processARGBFallback(
maxFallbackDimension, glyphRun.paint(), viewMatrix, textScale, maxFallbackDimension, runPaint, viewMatrix, textScale,
std::move(argbFallback)); std::move(argbFallback));
} }
@ -400,7 +403,7 @@ void SkGlyphRunListPainter::drawGlyphRunAsBMPWithPathFallback(
template <typename PerEmptyT, typename PerSDFT, typename PerPathT> template <typename PerEmptyT, typename PerSDFT, typename PerPathT>
void SkGlyphRunListPainter::drawGlyphRunAsSDFWithARGBFallback( void SkGlyphRunListPainter::drawGlyphRunAsSDFWithARGBFallback(
SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun, SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun,
SkPoint origin, const SkMatrix& viewMatrix, SkScalar textScale, SkPoint origin, const SkPaint& paint, const SkMatrix& viewMatrix, SkScalar textScale,
PerEmptyT&& perEmpty, PerSDFT&& perSDF, PerPathT&& perPath, ARGBFallback&& argbFallback) { PerEmptyT&& perEmpty, PerSDFT&& perSDF, PerPathT&& perPath, ARGBFallback&& argbFallback) {
fARGBGlyphsIDs.clear(); fARGBGlyphsIDs.clear();
fARGBPositions.clear(); fARGBPositions.clear();
@ -437,8 +440,10 @@ void SkGlyphRunListPainter::drawGlyphRunAsSDFWithARGBFallback(
} }
if (!fARGBGlyphsIDs.empty()) { if (!fARGBGlyphsIDs.empty()) {
SkPaint runPaint{paint};
glyphRun.font().LEGACY_applyToPaint(&runPaint);
this->processARGBFallback( this->processARGBFallback(
maxFallbackDimension, glyphRun.paint(), viewMatrix, textScale, maxFallbackDimension, runPaint, viewMatrix, textScale,
std::move(argbFallback)); std::move(argbFallback));
} }
} }
@ -704,7 +709,8 @@ void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
glyphRunList.paint().computeLuminanceColor(), viewMatrix, origin.x(), origin.y()); glyphRunList.paint().computeLuminanceColor(), viewMatrix, origin.x(), origin.y());
for (const auto& glyphRun : glyphRunList) { for (const auto& glyphRun : glyphRunList) {
const SkPaint& runPaint = glyphRun.paint(); SkPaint runPaint {glyphRunList.paint()};
glyphRun.font().LEGACY_applyToPaint(&runPaint);
Run* run = this->pushBackRun(); Run* run = this->pushBackRun();
run->setRunFontAntiAlias(runPaint.isAntiAlias()); run->setRunFontAntiAlias(runPaint.isAntiAlias());
@ -753,7 +759,7 @@ void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
glyphCache, filteredColor}; glyphCache, filteredColor};
glyphPainter->drawGlyphRunAsSDFWithARGBFallback( glyphPainter->drawGlyphRunAsSDFWithARGBFallback(
cache.get(), glyphRun, origin, viewMatrix, textScale, cache.get(), glyphRun, origin, runPaint, viewMatrix, textScale,
std::move(perEmpty), std::move(perSDF), std::move(perPath), std::move(perEmpty), std::move(perSDF), std::move(perPath),
std::move(argbFallback)); std::move(argbFallback));
} }
@ -787,7 +793,7 @@ void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
glyphCache, filteredColor}; glyphCache, filteredColor};
glyphPainter->drawGlyphRunAsPathWithARGBFallback( glyphPainter->drawGlyphRunAsPathWithARGBFallback(
pathCache.get(), glyphRun, origin, viewMatrix, textScale, pathCache.get(), glyphRun, origin, runPaint, viewMatrix, textScale,
std::move(perEmpty), std::move(perPath), std::move(argbFallback)); std::move(perEmpty), std::move(perPath), std::move(argbFallback));
} else { } else {
// Ensure the blob is set for bitmaptext // Ensure the blob is set for bitmaptext
@ -875,29 +881,30 @@ std::unique_ptr<GrDrawOp> GrTextContext::createOp_TestingOnly(GrContext* context
// -- SkTextBlobCacheDiffCanvas::TrackLayerDevice -------------------------------------------------- // -- SkTextBlobCacheDiffCanvas::TrackLayerDevice --------------------------------------------------
void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRun( void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRun(
const SkPoint& origin, const SkGlyphRun& glyphRun) { const SkPoint& origin, const SkGlyphRun& glyphRun, const SkPaint& paint) {
TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRun"); TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRun");
const SkPaint& runPaint = glyphRun.paint(); SkPaint runPaint{paint};
glyphRun.font().LEGACY_applyToPaint(&runPaint);
const SkMatrix& runMatrix = this->ctm(); const SkMatrix& runMatrix = this->ctm();
// If the matrix has perspective, we fall back to using distance field text or paths. // If the matrix has perspective, we fall back to using distance field text or paths.
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (this->maybeProcessGlyphRunForDFT(glyphRun, runMatrix, origin)) { if (this->maybeProcessGlyphRunForDFT(glyphRun, runMatrix, origin, runPaint)) {
return; return;
} else } else
#endif #endif
if (SkDraw::ShouldDrawTextAsPaths(runPaint, runMatrix)) { if (SkDraw::ShouldDrawTextAsPaths(runPaint, runMatrix)) {
this->processGlyphRunForPaths(glyphRun, runMatrix, origin); this->processGlyphRunForPaths(glyphRun, runMatrix, origin, runPaint);
} else { } else {
this->processGlyphRunForMask(glyphRun, runMatrix, origin); this->processGlyphRunForMask(glyphRun, runMatrix, origin, runPaint);
} }
} }
void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForMask( void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForMask(
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin) { const SkGlyphRun& glyphRun, const SkMatrix& runMatrix,
SkPoint origin, const SkPaint& runPaint) {
TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRunForMask"); TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRunForMask");
const SkPaint& runPaint = glyphRun.paint();
SkScalerContextEffects effects; SkScalerContextEffects effects;
auto* glyphCacheState = fStrikeServer->getOrCreateCache( auto* glyphCacheState = fStrikeServer->getOrCreateCache(
@ -950,9 +957,9 @@ struct ARGBHelper {
}; };
void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForPaths( void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForPaths(
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin) { const SkGlyphRun& glyphRun, const SkMatrix& runMatrix,
SkPoint origin, const SkPaint& runPaint) {
TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRunForPaths"); TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRunForPaths");
const SkPaint& runPaint = glyphRun.paint();
SkPaint pathPaint{runPaint}; SkPaint pathPaint{runPaint};
SkScalar textScale = pathPaint.setupForAsPaths(); SkScalar textScale = pathPaint.setupForAsPaths();
@ -974,17 +981,16 @@ void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForPaths(
ARGBHelper argbFallback{runMatrix, surfaceProps(), fStrikeServer}; ARGBHelper argbFallback{runMatrix, surfaceProps(), fStrikeServer};
fPainter.drawGlyphRunAsPathWithARGBFallback( fPainter.drawGlyphRunAsPathWithARGBFallback(
glyphCacheState, glyphRun, origin, runMatrix, textScale, glyphCacheState, glyphRun, origin, runPaint, runMatrix, textScale,
std::move(perEmpty), std::move(perPath), std::move(argbFallback)); std::move(perEmpty), std::move(perPath), std::move(argbFallback));
} }
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
bool SkTextBlobCacheDiffCanvas::TrackLayerDevice::maybeProcessGlyphRunForDFT( bool SkTextBlobCacheDiffCanvas::TrackLayerDevice::maybeProcessGlyphRunForDFT(
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin) { const SkGlyphRun& glyphRun, const SkMatrix& runMatrix,
SkPoint origin, const SkPaint& runPaint) {
TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::maybeProcessGlyphRunForDFT"); TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::maybeProcessGlyphRunForDFT");
const SkPaint& runPaint = glyphRun.paint();
GrTextContext::Options options; GrTextContext::Options options;
options.fMinDistanceFieldFontSize = fSettings.fMinDistanceFieldFontSize; options.fMinDistanceFieldFontSize = fSettings.fMinDistanceFieldFontSize;
options.fMaxDistanceFieldFontSize = fSettings.fMaxDistanceFieldFontSize; options.fMaxDistanceFieldFontSize = fSettings.fMaxDistanceFieldFontSize;
@ -1022,7 +1028,7 @@ bool SkTextBlobCacheDiffCanvas::TrackLayerDevice::maybeProcessGlyphRunForDFT(
}; };
fPainter.drawGlyphRunAsSDFWithARGBFallback( fPainter.drawGlyphRunAsSDFWithARGBFallback(
sdfCache, glyphRun, origin, runMatrix, textRatio, sdfCache, glyphRun, origin, runPaint, runMatrix, textRatio,
std::move(perEmpty), std::move(perSDF), std::move(perPath), std::move(perEmpty), std::move(perSDF), std::move(perPath),
std::move(argbFallback)); std::move(argbFallback));

View File

@ -97,13 +97,13 @@ public:
template <typename PerEmptyT, typename PerPath> template <typename PerEmptyT, typename PerPath>
void drawGlyphRunAsPathWithARGBFallback( void drawGlyphRunAsPathWithARGBFallback(
SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun, SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun,
SkPoint origin, const SkMatrix& viewMatrix, SkScalar textScale, SkPoint origin, const SkPaint& paint, const SkMatrix& viewMatrix, SkScalar textScale,
PerEmptyT&& perEmpty, PerPath&& perPath, ARGBFallback&& fallbackARGB); PerEmptyT&& perEmpty, PerPath&& perPath, ARGBFallback&& fallbackARGB);
template <typename PerEmptyT, typename PerSDFT, typename PerPathT> template <typename PerEmptyT, typename PerSDFT, typename PerPathT>
void drawGlyphRunAsSDFWithARGBFallback( void drawGlyphRunAsSDFWithARGBFallback(
SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun, SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun,
SkPoint origin, const SkMatrix& viewMatrix, SkScalar textRatio, SkPoint origin, const SkPaint& paint, const SkMatrix& viewMatrix, SkScalar textRatio,
PerEmptyT&& perEmpty, PerSDFT&& perSDF, PerPathT&& perPath, ARGBFallback&& perFallback); PerEmptyT&& perEmpty, PerSDFT&& perSDF, PerPathT&& perPath, ARGBFallback&& perFallback);
private: private:

View File

@ -213,7 +213,7 @@ SkBaseDevice* SkTextBlobCacheDiffCanvas::TrackLayerDevice::onCreateDevice(
void SkTextBlobCacheDiffCanvas::TrackLayerDevice::drawGlyphRunList( void SkTextBlobCacheDiffCanvas::TrackLayerDevice::drawGlyphRunList(
const SkGlyphRunList& glyphRunList) { const SkGlyphRunList& glyphRunList) {
for (auto& glyphRun : glyphRunList) { for (auto& glyphRun : glyphRunList) {
this->processGlyphRun(glyphRunList.origin(), glyphRun); this->processGlyphRun(glyphRunList.origin(), glyphRun, glyphRunList.paint());
} }
} }

View File

@ -102,17 +102,20 @@ protected:
void drawGlyphRunList(const SkGlyphRunList& glyphRunList) override; void drawGlyphRunList(const SkGlyphRunList& glyphRunList) override;
private: private:
void processGlyphRun(const SkPoint& origin, const SkGlyphRun& glyphRun); void processGlyphRun(const SkPoint& origin, const SkGlyphRun& glyphRun, const SkPaint& paint);
void processGlyphRunForMask( void processGlyphRunForMask(
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin); const SkGlyphRun& glyphRun, const SkMatrix& runMatrix,
SkPoint origin, const SkPaint& paint);
void processGlyphRunForPaths( void processGlyphRunForPaths(
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin); const SkGlyphRun& glyphRun, const SkMatrix& runMatrix,
SkPoint origin, const SkPaint& paint);
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
bool maybeProcessGlyphRunForDFT( bool maybeProcessGlyphRunForDFT(
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin); const SkGlyphRun& glyphRun, const SkMatrix& runMatrix,
SkPoint origin, const SkPaint& paint);
#endif #endif
SkStrikeServer* const fStrikeServer; SkStrikeServer* const fStrikeServer;

View File

@ -179,12 +179,6 @@ private:
SkDEBUGCODE(unsigned fMagic;) SkDEBUGCODE(unsigned fMagic;)
}; };
// (paint->getFlags() & ~kFlagsMask) | fFlags
inline SkPaint::SkPaint(const SkPaint& basePaint, const SkFont& runFont) : SkPaint(basePaint) {
fBitfields.fTextEncoding = (unsigned)kGlyphID_SkTextEncoding;
runFont.LEGACY_applyToPaint(this);
}
/** /**
* Iterate through all of the text runs of the text blob. For example: * Iterate through all of the text runs of the text blob. For example:
* for (SkTextBlobRunIterator it(blob); !it.done(); it.next()) { * for (SkTextBlobRunIterator it(blob); !it.done(); it.next()) {

View File

@ -1031,9 +1031,11 @@ static bool contains(const SkRect& r, SkPoint p) {
r.top() <= p.y() && p.y() <= r.bottom(); r.top() <= p.y() && p.y() <= r.bottom();
} }
void SkPDFDevice::drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset) { void SkPDFDevice::drawGlyphRunAsPath(
SkPaint paint{glyphRun.paint()}; const SkGlyphRun& glyphRun, SkPoint offset, const SkPaint& runPaint) {
SkFont font{SkFont::LEGACY_ExtractFromPaint(paint)}; SkPaint paint{runPaint};
glyphRun.font().LEGACY_applyToPaint(&paint);
SkFont font = glyphRun.font();
SkPath path; SkPath path;
struct Rec { struct Rec {
@ -1055,23 +1057,20 @@ void SkPDFDevice::drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset)
}, &rec); }, &rec);
this->drawPath(path, paint, true); this->drawPath(path, paint, true);
SkFont transparentFont = glyphRun.font();
transparentFont.setEmbolden(false); // Stop Recursion
SkGlyphRun tmpGlyphRun(glyphRun, transparentFont);
SkPaint transparent; SkPaint transparent;
transparent.setTypeface(paint.getTypeface() ? paint.refTypeface()
: SkTypeface::MakeDefault());
transparent.setTextEncoding(kGlyphID_SkTextEncoding);
transparent.setColor(SK_ColorTRANSPARENT); transparent.setColor(SK_ColorTRANSPARENT);
transparent.setTextSize(paint.getTextSize());
transparent.setTextScaleX(paint.getTextScaleX());
transparent.setTextSkewX(paint.getTextSkewX());
SkGlyphRun tmp(glyphRun, transparent);
if (this->ctm().hasPerspective()) { if (this->ctm().hasPerspective()) {
SkMatrix prevCTM = this->ctm(); SkMatrix prevCTM = this->ctm();
this->setCTM(SkMatrix::I()); this->setCTM(SkMatrix::I());
this->internalDrawGlyphRun(tmp, offset); this->internalDrawGlyphRun(tmpGlyphRun, offset, transparent);
this->setCTM(prevCTM); this->setCTM(prevCTM);
} else { } else {
this->internalDrawGlyphRun(tmp, offset); this->internalDrawGlyphRun(tmpGlyphRun, offset, transparent);
} }
} }
@ -1093,11 +1092,13 @@ static bool needs_new_font(SkPDFFont* font, SkGlyphID gid, SkGlyphCache* cache,
return convertedToType3 != bitmapOnly; return convertedToType3 != bitmapOnly;
} }
void SkPDFDevice::internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offset) { void SkPDFDevice::internalDrawGlyphRun(
const SkGlyphRun& glyphRun, SkPoint offset, const SkPaint& runPaint) {
const SkGlyphID* glyphs = glyphRun.glyphsIDs().data(); const SkGlyphID* glyphs = glyphRun.glyphsIDs().data();
uint32_t glyphCount = SkToU32(glyphRun.glyphsIDs().size()); uint32_t glyphCount = SkToU32(glyphRun.glyphsIDs().size());
SkPaint srcPaint{glyphRun.paint()}; SkPaint srcPaint{runPaint};
glyphRun.font().LEGACY_applyToPaint(&srcPaint);
srcPaint.setTextEncoding(kGlyphID_SkTextEncoding); srcPaint.setTextEncoding(kGlyphID_SkTextEncoding);
if (!glyphCount || !glyphs || srcPaint.getTextSize() <= 0 || this->hasEmptyClip()) { if (!glyphCount || !glyphs || srcPaint.getTextSize() <= 0 || this->hasEmptyClip()) {
@ -1109,7 +1110,7 @@ void SkPDFDevice::internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offse
|| this->ctm().hasPerspective() || this->ctm().hasPerspective()
|| SkPaint::kFill_Style != srcPaint.getStyle()) { || SkPaint::kFill_Style != srcPaint.getStyle()) {
// Stroked Text doesn't work well with Type3 fonts. // Stroked Text doesn't work well with Type3 fonts.
this->drawGlyphRunAsPath(glyphRun, offset); this->drawGlyphRunAsPath(glyphRun, offset, runPaint);
return; return;
} }
SkPaint paint(srcPaint); SkPaint paint(srcPaint);
@ -1262,7 +1263,7 @@ void SkPDFDevice::internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offse
void SkPDFDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) { void SkPDFDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) {
for (const SkGlyphRun& glyphRun : glyphRunList) { for (const SkGlyphRun& glyphRun : glyphRunList) {
this->internalDrawGlyphRun(glyphRun, glyphRunList.origin()); this->internalDrawGlyphRun(glyphRun, glyphRunList.origin(), glyphRunList.paint());
} }
} }

View File

@ -224,8 +224,8 @@ private:
bool hasText, bool hasText,
GraphicStateEntry* entry); GraphicStateEntry* entry);
void internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offset); void internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offset, const SkPaint& runPaint);
void drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset); void drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset, const SkPaint& runPaint);
void internalDrawImageRect(SkKeyedImage, void internalDrawImageRect(SkKeyedImage,
const SkRect* src, const SkRect* src,

View File

@ -852,10 +852,9 @@ public:
SVGTextBuilder(SkPoint origin, const SkGlyphRun& glyphRun) SVGTextBuilder(SkPoint origin, const SkGlyphRun& glyphRun)
: fOrigin(origin) : fOrigin(origin)
, fLastCharWasWhitespace(true) { // start off in whitespace mode to strip all leadingspace , fLastCharWasWhitespace(true) { // start off in whitespace mode to strip all leadingspace
const SkFont font = SkFont::LEGACY_ExtractFromPaint(glyphRun.paint());
auto runSize = glyphRun.runSize(); auto runSize = glyphRun.runSize();
SkAutoSTArray<64, SkUnichar> unichars(runSize); SkAutoSTArray<64, SkUnichar> unichars(runSize);
font.glyphsToUnichars(glyphRun.glyphsIDs().data(), runSize, unichars.get()); glyphRun.font().glyphsToUnichars(glyphRun.glyphsIDs().data(), runSize, unichars.get());
auto positions = glyphRun.positions(); auto positions = glyphRun.positions();
for (size_t i = 0; i < runSize; ++i) { for (size_t i = 0; i < runSize; ++i) {
this->appendUnichar(unichars[i], positions[i]); this->appendUnichar(unichars[i], positions[i]);
@ -929,8 +928,10 @@ private:
void SkSVGDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) { void SkSVGDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) {
auto processGlyphRun = [this](SkPoint origin, const SkGlyphRun& glyphRun) { auto processGlyphRun = [this]
const SkPaint& paint = glyphRun.paint(); (SkPoint origin, const SkGlyphRun& glyphRun, const SkPaint& runPaint) {
SkPaint paint{runPaint};
glyphRun.font().LEGACY_applyToPaint(&paint);
AutoElement elem("text", fWriter, fResourceBucket.get(), MxCp(this), paint); AutoElement elem("text", fWriter, fResourceBucket.get(), MxCp(this), paint);
elem.addTextAttributes(paint); elem.addTextAttributes(paint);
@ -941,7 +942,7 @@ void SkSVGDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) {
}; };
for (auto& glyphRun : glyphRunList) { for (auto& glyphRun : glyphRunList) {
processGlyphRun(glyphRunList.origin(), glyphRun); processGlyphRun(glyphRunList.origin(), glyphRun, glyphRunList.paint());
} }
} }

View File

@ -488,7 +488,7 @@ DEF_TEST(SkPDF_Primitives_Color, reporter) {
static SkGlyphRun make_run(size_t len, const SkGlyphID* glyphs, SkPoint* pos, static SkGlyphRun make_run(size_t len, const SkGlyphID* glyphs, SkPoint* pos,
SkPaint paint, const uint32_t* clusters, SkPaint paint, const uint32_t* clusters,
size_t utf8TextByteLength, const char* utf8Text) { size_t utf8TextByteLength, const char* utf8Text) {
return SkGlyphRun(paint, SkFont::LEGACY_ExtractFromPaint(paint), return SkGlyphRun(SkFont::LEGACY_ExtractFromPaint(paint),
SkSpan<const SkPoint>{pos, len}, SkSpan<const SkPoint>{pos, len},
SkSpan<const SkGlyphID>{glyphs, len}, SkSpan<const SkGlyphID>{glyphs, len},
SkSpan<const char>{utf8Text, utf8TextByteLength}, SkSpan<const char>{utf8Text, utf8TextByteLength},