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:
parent
ece772d8c2
commit
95e1760a78
@ -1205,10 +1205,6 @@ public:
|
||||
Style style) const;
|
||||
|
||||
private:
|
||||
friend class SkGlyphRun;
|
||||
friend class SkGlyphRunBuilder;
|
||||
SkPaint(const SkPaint&, const SkFont&);
|
||||
|
||||
sk_sp<SkTypeface> fTypeface;
|
||||
sk_sp<SkPathEffect> fPathEffect;
|
||||
sk_sp<SkShader> fShader;
|
||||
|
@ -161,7 +161,8 @@ void SkInternalAtlasTextTarget::drawText(const SkGlyphID glyphs[], const SkPoint
|
||||
auto* grContext = this->context()->internal().grContext();
|
||||
auto atlasTextContext = grContext->contextPriv().drawingManager()->getTextContext();
|
||||
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();
|
||||
if (!glyphRunList.empty()) {
|
||||
atlasTextContext->drawGlyphRunList(grContext, this, GrNoClip(), this->ctm(), props,
|
||||
|
@ -2456,7 +2456,7 @@ void SkCanvas::onDrawTextRSXform(const void* text, size_t len, const SkRSXform x
|
||||
auto list = fScratchGlyphRunBuilder->useGlyphRunList();
|
||||
if (!list.empty()) {
|
||||
auto glyphRun = list[0];
|
||||
iter.fDevice->drawGlyphRunRSXform(&glyphRun, xform);
|
||||
iter.fDevice->drawGlyphRunRSXform(&glyphRun, xform, paint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -327,22 +327,22 @@ bool SkBaseDevice::peekPixels(SkPixmap* pmap) {
|
||||
#include "SkUtils.h"
|
||||
|
||||
void SkBaseDevice::drawGlyphRunRSXform(
|
||||
SkGlyphRun* run, const SkRSXform* xform) {
|
||||
SkGlyphRun* run, const SkRSXform* xform, const SkPaint& paint) {
|
||||
const SkMatrix originalCTM = this->ctm();
|
||||
if (!originalCTM.isFinite() || !SkScalarIsFinite(run->paint().getTextSize()) ||
|
||||
!SkScalarIsFinite(run->paint().getTextScaleX()) ||
|
||||
!SkScalarIsFinite(run->paint().getTextSkewX())) {
|
||||
if (!originalCTM.isFinite() || !SkScalarIsFinite(run->font().getSize()) ||
|
||||
!SkScalarIsFinite(run->font().getScaleX()) ||
|
||||
!SkScalarIsFinite(run->font().getSkewX())) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto perGlyph = [this, &xform, &originalCTM] (const SkGlyphRun& glyphRun) {
|
||||
auto perGlyph = [this, &xform, &originalCTM, &paint] (const SkGlyphRun& glyphRun) {
|
||||
SkMatrix ctm;
|
||||
ctm.setRSXform(*xform++);
|
||||
|
||||
// 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
|
||||
// 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();
|
||||
if (shader) {
|
||||
SkMatrix inverse;
|
||||
@ -356,8 +356,7 @@ void SkBaseDevice::drawGlyphRunRSXform(
|
||||
ctm.setConcat(originalCTM, ctm);
|
||||
this->setCTM(ctm);
|
||||
|
||||
SkGlyphRun transformedGlyphRun{glyphRun, transformingPaint};
|
||||
this->drawGlyphRunList(SkGlyphRunList{transformedGlyphRun});
|
||||
this->drawGlyphRunList(SkGlyphRunList{glyphRun, transformingPaint});
|
||||
};
|
||||
run->eachGlyphToGlyphRun(perGlyph);
|
||||
this->setCTM(originalCTM);
|
||||
|
@ -235,7 +235,7 @@ protected:
|
||||
*/
|
||||
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*);
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "SkGlyphRun.h"
|
||||
|
||||
#include "SkFont.h"
|
||||
#include "SkGlyphCache.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkPaintPriv.h"
|
||||
@ -28,8 +29,7 @@ static SkTypeface::Encoding convert_encoding(SkTextEncoding encoding) {
|
||||
} // namespace
|
||||
|
||||
// -- SkGlyphRun -----------------------------------------------------------------------------------
|
||||
SkGlyphRun::SkGlyphRun(const SkPaint& basePaint,
|
||||
const SkFont& runFont,
|
||||
SkGlyphRun::SkGlyphRun(const SkFont& font,
|
||||
SkSpan<const SkPoint> positions,
|
||||
SkSpan<const SkGlyphID> glyphIDs,
|
||||
SkSpan<const char> text,
|
||||
@ -38,21 +38,20 @@ SkGlyphRun::SkGlyphRun(const SkPaint& basePaint,
|
||||
, fGlyphIDs{glyphIDs}
|
||||
, fText{text}
|
||||
, 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}
|
||||
, fGlyphIDs{that.fGlyphIDs}
|
||||
, fText{that.fText}
|
||||
, fClusters{that.fClusters}
|
||||
, fRunPaint{paint} {}
|
||||
, fFont{font} {}
|
||||
|
||||
void SkGlyphRun::eachGlyphToGlyphRun(SkGlyphRun::PerGlyph perGlyph) {
|
||||
SkPoint point;
|
||||
SkGlyphID glyphID;
|
||||
SkGlyphRun run{
|
||||
fRunPaint,
|
||||
SkFont::LEGACY_ExtractFromPaint(fRunPaint),
|
||||
this->font(),
|
||||
SkSpan<const SkPoint>{&point, 1},
|
||||
SkSpan<const SkGlyphID>{&glyphID, 1},
|
||||
SkSpan<const char>{},
|
||||
@ -84,8 +83,8 @@ SkGlyphRunList::SkGlyphRunList(
|
||||
, fOrigin{origin}
|
||||
, fGlyphRuns{glyphRunList} { }
|
||||
|
||||
SkGlyphRunList::SkGlyphRunList(const SkGlyphRun& glyphRun)
|
||||
: fOriginalPaint{&glyphRun.paint()}
|
||||
SkGlyphRunList::SkGlyphRunList(const SkGlyphRun& glyphRun, const SkPaint& paint)
|
||||
: fOriginalPaint{&paint}
|
||||
, fOriginalTextBlob{nullptr}
|
||||
, fOrigin{SkPoint::Make(0, 0)}
|
||||
, fGlyphRuns{SkSpan<const SkGlyphRun>{&glyphRun, 1}} {}
|
||||
@ -97,7 +96,7 @@ uint64_t SkGlyphRunList::uniqueID() const {
|
||||
|
||||
bool SkGlyphRunList::anyRunsLCD() const {
|
||||
for (const auto& r : fGlyphRuns) {
|
||||
if (r.paint().isLCDRenderText()) {
|
||||
if (r.font().getEdging() == SkFont::Edging::kSubpixelAntiAlias) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -106,7 +105,7 @@ bool SkGlyphRunList::anyRunsLCD() const {
|
||||
|
||||
bool SkGlyphRunList::anyRunsSubpixelPositioned() const {
|
||||
for (const auto& r : fGlyphRuns) {
|
||||
if (r.paint().isSubpixelText()) {
|
||||
if (r.font().isSubpixel()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -194,7 +193,6 @@ void SkGlyphRunBuilder::drawTextAtOrigin(
|
||||
sk_bzero((void *)positions.data(), positions.size_bytes());
|
||||
|
||||
this->makeGlyphRun(
|
||||
paint,
|
||||
SkFont::LEGACY_ExtractFromPaint(paint),
|
||||
glyphIDs,
|
||||
positions,
|
||||
@ -208,7 +206,7 @@ void SkGlyphRunBuilder::drawText(
|
||||
auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength);
|
||||
if (!glyphIDs.empty()) {
|
||||
this->initialize(glyphIDs.size());
|
||||
this->simplifyDrawText(paint, SkFont::LEGACY_ExtractFromPaint(paint),
|
||||
this->simplifyDrawText(SkFont::LEGACY_ExtractFromPaint(paint),
|
||||
glyphIDs, origin, fPositions);
|
||||
}
|
||||
|
||||
@ -240,18 +238,18 @@ void SkGlyphRunBuilder::drawTextBlob(const SkPaint& paint, const SkTextBlob& blo
|
||||
switch (it.positioning()) {
|
||||
case SkTextBlobRunIterator::kDefault_Positioning: {
|
||||
this->simplifyDrawText(
|
||||
paint, it.font(), glyphIDs, offset, positions, text, clusters);
|
||||
it.font(), glyphIDs, offset, positions, text, clusters);
|
||||
}
|
||||
break;
|
||||
case SkTextBlobRunIterator::kHorizontal_Positioning: {
|
||||
auto constY = offset.y();
|
||||
this->simplifyDrawPosTextH(
|
||||
paint, it.font(), glyphIDs, it.pos(), constY, positions, text, clusters);
|
||||
it.font(), glyphIDs, it.pos(), constY, positions, text, clusters);
|
||||
}
|
||||
break;
|
||||
case SkTextBlobRunIterator::kFull_Positioning:
|
||||
this->simplifyDrawPosText(
|
||||
paint, it.font(), glyphIDs, (const SkPoint*)it.pos(), text, clusters);
|
||||
it.font(), glyphIDs, (const SkPoint*)it.pos(), text, clusters);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -261,11 +259,11 @@ void SkGlyphRunBuilder::drawTextBlob(const SkPaint& paint, const SkTextBlob& blo
|
||||
this->makeGlyphRunList(paint, &blob, origin);
|
||||
}
|
||||
|
||||
void SkGlyphRunBuilder::drawGlyphPos(
|
||||
void SkGlyphRunBuilder::drawGlyphsWithPositions(
|
||||
const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos) {
|
||||
if (!glyphIDs.empty()) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
@ -305,8 +303,7 @@ SkSpan<const SkGlyphID> SkGlyphRunBuilder::textToGlyphIDs(
|
||||
}
|
||||
|
||||
void SkGlyphRunBuilder::makeGlyphRun(
|
||||
const SkPaint& basePaint,
|
||||
const SkFont& runFont,
|
||||
const SkFont& font,
|
||||
SkSpan<const SkGlyphID> glyphIDs,
|
||||
SkSpan<const SkPoint> positions,
|
||||
SkSpan<const char> text,
|
||||
@ -315,8 +312,7 @@ void SkGlyphRunBuilder::makeGlyphRun(
|
||||
// Ignore empty runs.
|
||||
if (!glyphIDs.empty()) {
|
||||
fGlyphRunListStorage.emplace_back(
|
||||
basePaint,
|
||||
runFont,
|
||||
font,
|
||||
positions,
|
||||
glyphIDs,
|
||||
text,
|
||||
@ -333,22 +329,17 @@ void SkGlyphRunBuilder::makeGlyphRunList(
|
||||
}
|
||||
|
||||
void SkGlyphRunBuilder::simplifyDrawText(
|
||||
const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
|
||||
const SkFont& font, SkSpan<const SkGlyphID> glyphIDs,
|
||||
SkPoint origin, SkPoint* positions,
|
||||
SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
|
||||
SkASSERT(!glyphIDs.empty());
|
||||
|
||||
auto runSize = glyphIDs.size();
|
||||
|
||||
SkPaint runPaint(paint);
|
||||
runFont.LEGACY_applyToPaint(&runPaint);
|
||||
runPaint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
|
||||
if (!glyphIDs.empty()) {
|
||||
fScratchAdvances.resize(runSize);
|
||||
{
|
||||
const SkFont font = SkFont::LEGACY_ExtractFromPaint(runPaint);
|
||||
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font, runPaint);
|
||||
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font);
|
||||
cache->getAdvances(glyphIDs, fScratchAdvances.data());
|
||||
}
|
||||
|
||||
@ -360,8 +351,7 @@ void SkGlyphRunBuilder::simplifyDrawText(
|
||||
}
|
||||
|
||||
this->makeGlyphRun(
|
||||
paint,
|
||||
runFont,
|
||||
font,
|
||||
glyphIDs,
|
||||
SkSpan<const SkPoint>{positions, runSize},
|
||||
text,
|
||||
@ -370,7 +360,7 @@ void SkGlyphRunBuilder::simplifyDrawText(
|
||||
}
|
||||
|
||||
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,
|
||||
SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
|
||||
|
||||
@ -379,18 +369,17 @@ void SkGlyphRunBuilder::simplifyDrawPosTextH(
|
||||
*posCursor++ = SkPoint::Make(x, constY);
|
||||
}
|
||||
|
||||
simplifyDrawPosText(paint, runFont, glyphIDs, positions, text, clusters);
|
||||
simplifyDrawPosText(font, glyphIDs, positions, text, clusters);
|
||||
}
|
||||
|
||||
void SkGlyphRunBuilder::simplifyDrawPosText(
|
||||
const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
|
||||
const SkFont& font, SkSpan<const SkGlyphID> glyphIDs,
|
||||
const SkPoint* pos,
|
||||
SkSpan<const char> text, SkSpan<const uint32_t> clusters) {
|
||||
auto runSize = glyphIDs.size();
|
||||
|
||||
this->makeGlyphRun(
|
||||
paint,
|
||||
runFont,
|
||||
font,
|
||||
glyphIDs,
|
||||
SkSpan<const SkPoint>{pos, runSize},
|
||||
text,
|
||||
|
@ -11,25 +11,24 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "SkFont.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkPoint.h"
|
||||
#include "SkSpan.h"
|
||||
#include "SkTemplates.h"
|
||||
#include "SkTypes.h"
|
||||
|
||||
class SkFont;
|
||||
class SkGlyph;
|
||||
|
||||
class SkGlyphRun {
|
||||
public:
|
||||
SkGlyphRun() = default;
|
||||
SkGlyphRun(const SkPaint& basePaint,
|
||||
const SkFont& runFont,
|
||||
SkGlyphRun(const SkFont& font,
|
||||
SkSpan<const SkPoint> positions,
|
||||
SkSpan<const SkGlyphID> glyphIDs,
|
||||
SkSpan<const char> text,
|
||||
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.
|
||||
using PerGlyph = std::function<void (const SkGlyphRun&)>;
|
||||
@ -40,7 +39,7 @@ public:
|
||||
size_t runSize() const { return fGlyphIDs.size(); }
|
||||
SkSpan<const SkPoint> positions() const { return fPositions.toConst(); }
|
||||
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 char> text() const { return fText; }
|
||||
|
||||
@ -54,7 +53,7 @@ private:
|
||||
// Original clusters from SkTextBlob if present. Will be empty if not present.
|
||||
const SkSpan<const uint32_t> fClusters;
|
||||
// Paint for this run modified to have glyph encoding and left alignment.
|
||||
SkPaint fRunPaint;
|
||||
SkFont fFont;
|
||||
};
|
||||
|
||||
class SkGlyphRunList {
|
||||
@ -74,7 +73,7 @@ public:
|
||||
SkPoint origin,
|
||||
SkSpan<const SkGlyphRun> glyphRunList);
|
||||
|
||||
SkGlyphRunList(const SkGlyphRun& glyphRun);
|
||||
SkGlyphRunList(const SkGlyphRun& glyphRun, const SkPaint& paint);
|
||||
|
||||
uint64_t uniqueID() const;
|
||||
bool anyRunsLCD() const;
|
||||
@ -120,7 +119,7 @@ public:
|
||||
void drawText(
|
||||
const SkPaint& paint, const void* bytes, size_t byteLength, 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 SkGlyphRunList& useGlyphRunList();
|
||||
@ -131,8 +130,7 @@ private:
|
||||
const SkPaint& paint, const void* bytes, size_t byteLength);
|
||||
|
||||
void makeGlyphRun(
|
||||
const SkPaint& basePaint,
|
||||
const SkFont& runFont,
|
||||
const SkFont& font,
|
||||
SkSpan<const SkGlyphID> glyphIDs,
|
||||
SkSpan<const SkPoint> positions,
|
||||
SkSpan<const char> text,
|
||||
@ -141,17 +139,17 @@ private:
|
||||
void makeGlyphRunList(const SkPaint& paint, const SkTextBlob* blob, SkPoint origin);
|
||||
|
||||
void simplifyDrawText(
|
||||
const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
|
||||
const SkFont& font, SkSpan<const SkGlyphID> glyphIDs,
|
||||
SkPoint origin, SkPoint* positions,
|
||||
SkSpan<const char> text = SkSpan<const char>{},
|
||||
SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{});
|
||||
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,
|
||||
SkSpan<const char> text = SkSpan<const char>{},
|
||||
SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{});
|
||||
void simplifyDrawPosText(
|
||||
const SkPaint& paint, const SkFont& runFont, SkSpan<const SkGlyphID> glyphIDs,
|
||||
const SkFont& font, SkSpan<const SkGlyphID> glyphIDs,
|
||||
const SkPoint* pos,
|
||||
SkSpan<const char> text = SkSpan<const char>{},
|
||||
SkSpan<const uint32_t> clusters = SkSpan<const uint32_t>{});
|
||||
|
@ -164,11 +164,12 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
|
||||
for (auto& glyphRun : glyphRunList) {
|
||||
// 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.
|
||||
auto& props = (kN32_SkColorType == fColorType && glyphRun.paint().isSrcOver())
|
||||
auto& props = (kN32_SkColorType == fColorType && glyphRunList.paint().isSrcOver())
|
||||
? fDeviceProps
|
||||
: fBitmapFallbackProps;
|
||||
|
||||
const SkPaint& paint = glyphRun.paint();
|
||||
SkPaint paint{glyphRunList.paint()};
|
||||
glyphRun.font().LEGACY_applyToPaint(&paint);
|
||||
auto runSize = glyphRun.runSize();
|
||||
this->ensureBitmapBuffers(runSize);
|
||||
|
||||
@ -324,7 +325,7 @@ void SkGlyphRunListPainter::processARGBFallback(
|
||||
template <typename PerEmptyT, typename PerPathT>
|
||||
void SkGlyphRunListPainter::drawGlyphRunAsPathWithARGBFallback(
|
||||
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) {
|
||||
fARGBGlyphsIDs.clear();
|
||||
fARGBPositions.clear();
|
||||
@ -351,8 +352,10 @@ void SkGlyphRunListPainter::drawGlyphRunAsPathWithARGBFallback(
|
||||
}
|
||||
|
||||
if (!fARGBGlyphsIDs.empty()) {
|
||||
SkPaint runPaint{paint};
|
||||
glyphRun.font().LEGACY_applyToPaint(&runPaint);
|
||||
this->processARGBFallback(
|
||||
maxFallbackDimension, glyphRun.paint(), viewMatrix, textScale,
|
||||
maxFallbackDimension, runPaint, viewMatrix, textScale,
|
||||
std::move(argbFallback));
|
||||
|
||||
}
|
||||
@ -400,7 +403,7 @@ void SkGlyphRunListPainter::drawGlyphRunAsBMPWithPathFallback(
|
||||
template <typename PerEmptyT, typename PerSDFT, typename PerPathT>
|
||||
void SkGlyphRunListPainter::drawGlyphRunAsSDFWithARGBFallback(
|
||||
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) {
|
||||
fARGBGlyphsIDs.clear();
|
||||
fARGBPositions.clear();
|
||||
@ -437,8 +440,10 @@ void SkGlyphRunListPainter::drawGlyphRunAsSDFWithARGBFallback(
|
||||
}
|
||||
|
||||
if (!fARGBGlyphsIDs.empty()) {
|
||||
SkPaint runPaint{paint};
|
||||
glyphRun.font().LEGACY_applyToPaint(&runPaint);
|
||||
this->processARGBFallback(
|
||||
maxFallbackDimension, glyphRun.paint(), viewMatrix, textScale,
|
||||
maxFallbackDimension, runPaint, viewMatrix, textScale,
|
||||
std::move(argbFallback));
|
||||
}
|
||||
}
|
||||
@ -704,7 +709,8 @@ void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
|
||||
glyphRunList.paint().computeLuminanceColor(), viewMatrix, origin.x(), origin.y());
|
||||
|
||||
for (const auto& glyphRun : glyphRunList) {
|
||||
const SkPaint& runPaint = glyphRun.paint();
|
||||
SkPaint runPaint {glyphRunList.paint()};
|
||||
glyphRun.font().LEGACY_applyToPaint(&runPaint);
|
||||
Run* run = this->pushBackRun();
|
||||
|
||||
run->setRunFontAntiAlias(runPaint.isAntiAlias());
|
||||
@ -753,7 +759,7 @@ void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
|
||||
glyphCache, filteredColor};
|
||||
|
||||
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(argbFallback));
|
||||
}
|
||||
@ -787,7 +793,7 @@ void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
|
||||
glyphCache, filteredColor};
|
||||
|
||||
glyphPainter->drawGlyphRunAsPathWithARGBFallback(
|
||||
pathCache.get(), glyphRun, origin, viewMatrix, textScale,
|
||||
pathCache.get(), glyphRun, origin, runPaint, viewMatrix, textScale,
|
||||
std::move(perEmpty), std::move(perPath), std::move(argbFallback));
|
||||
} else {
|
||||
// Ensure the blob is set for bitmaptext
|
||||
@ -875,29 +881,30 @@ std::unique_ptr<GrDrawOp> GrTextContext::createOp_TestingOnly(GrContext* context
|
||||
// -- SkTextBlobCacheDiffCanvas::TrackLayerDevice --------------------------------------------------
|
||||
|
||||
void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRun(
|
||||
const SkPoint& origin, const SkGlyphRun& glyphRun) {
|
||||
const SkPoint& origin, const SkGlyphRun& glyphRun, const SkPaint& paint) {
|
||||
TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRun");
|
||||
|
||||
const SkPaint& runPaint = glyphRun.paint();
|
||||
SkPaint runPaint{paint};
|
||||
glyphRun.font().LEGACY_applyToPaint(&runPaint);
|
||||
const SkMatrix& runMatrix = this->ctm();
|
||||
|
||||
// If the matrix has perspective, we fall back to using distance field text or paths.
|
||||
#if SK_SUPPORT_GPU
|
||||
if (this->maybeProcessGlyphRunForDFT(glyphRun, runMatrix, origin)) {
|
||||
if (this->maybeProcessGlyphRunForDFT(glyphRun, runMatrix, origin, runPaint)) {
|
||||
return;
|
||||
} else
|
||||
#endif
|
||||
if (SkDraw::ShouldDrawTextAsPaths(runPaint, runMatrix)) {
|
||||
this->processGlyphRunForPaths(glyphRun, runMatrix, origin);
|
||||
this->processGlyphRunForPaths(glyphRun, runMatrix, origin, runPaint);
|
||||
} else {
|
||||
this->processGlyphRunForMask(glyphRun, runMatrix, origin);
|
||||
this->processGlyphRunForMask(glyphRun, runMatrix, origin, runPaint);
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
const SkPaint& runPaint = glyphRun.paint();
|
||||
|
||||
SkScalerContextEffects effects;
|
||||
auto* glyphCacheState = fStrikeServer->getOrCreateCache(
|
||||
@ -950,9 +957,9 @@ struct ARGBHelper {
|
||||
};
|
||||
|
||||
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");
|
||||
const SkPaint& runPaint = glyphRun.paint();
|
||||
SkPaint pathPaint{runPaint};
|
||||
|
||||
SkScalar textScale = pathPaint.setupForAsPaths();
|
||||
@ -974,17 +981,16 @@ void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForPaths(
|
||||
ARGBHelper argbFallback{runMatrix, surfaceProps(), fStrikeServer};
|
||||
|
||||
fPainter.drawGlyphRunAsPathWithARGBFallback(
|
||||
glyphCacheState, glyphRun, origin, runMatrix, textScale,
|
||||
glyphCacheState, glyphRun, origin, runPaint, runMatrix, textScale,
|
||||
std::move(perEmpty), std::move(perPath), std::move(argbFallback));
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
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");
|
||||
|
||||
const SkPaint& runPaint = glyphRun.paint();
|
||||
|
||||
GrTextContext::Options options;
|
||||
options.fMinDistanceFieldFontSize = fSettings.fMinDistanceFieldFontSize;
|
||||
options.fMaxDistanceFieldFontSize = fSettings.fMaxDistanceFieldFontSize;
|
||||
@ -1022,7 +1028,7 @@ bool SkTextBlobCacheDiffCanvas::TrackLayerDevice::maybeProcessGlyphRunForDFT(
|
||||
};
|
||||
|
||||
fPainter.drawGlyphRunAsSDFWithARGBFallback(
|
||||
sdfCache, glyphRun, origin, runMatrix, textRatio,
|
||||
sdfCache, glyphRun, origin, runPaint, runMatrix, textRatio,
|
||||
std::move(perEmpty), std::move(perSDF), std::move(perPath),
|
||||
std::move(argbFallback));
|
||||
|
||||
|
@ -97,13 +97,13 @@ public:
|
||||
template <typename PerEmptyT, typename PerPath>
|
||||
void drawGlyphRunAsPathWithARGBFallback(
|
||||
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);
|
||||
|
||||
template <typename PerEmptyT, typename PerSDFT, typename PerPathT>
|
||||
void drawGlyphRunAsSDFWithARGBFallback(
|
||||
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);
|
||||
|
||||
private:
|
||||
|
@ -213,7 +213,7 @@ SkBaseDevice* SkTextBlobCacheDiffCanvas::TrackLayerDevice::onCreateDevice(
|
||||
void SkTextBlobCacheDiffCanvas::TrackLayerDevice::drawGlyphRunList(
|
||||
const SkGlyphRunList& glyphRunList) {
|
||||
for (auto& glyphRun : glyphRunList) {
|
||||
this->processGlyphRun(glyphRunList.origin(), glyphRun);
|
||||
this->processGlyphRun(glyphRunList.origin(), glyphRun, glyphRunList.paint());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,17 +102,20 @@ protected:
|
||||
void drawGlyphRunList(const SkGlyphRunList& glyphRunList) override;
|
||||
|
||||
private:
|
||||
void processGlyphRun(const SkPoint& origin, const SkGlyphRun& glyphRun);
|
||||
void processGlyphRun(const SkPoint& origin, const SkGlyphRun& glyphRun, const SkPaint& paint);
|
||||
|
||||
void processGlyphRunForMask(
|
||||
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin);
|
||||
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix,
|
||||
SkPoint origin, const SkPaint& paint);
|
||||
|
||||
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
|
||||
bool maybeProcessGlyphRunForDFT(
|
||||
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix, SkPoint origin);
|
||||
const SkGlyphRun& glyphRun, const SkMatrix& runMatrix,
|
||||
SkPoint origin, const SkPaint& paint);
|
||||
#endif
|
||||
|
||||
SkStrikeServer* const fStrikeServer;
|
||||
|
@ -179,12 +179,6 @@ private:
|
||||
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:
|
||||
* for (SkTextBlobRunIterator it(blob); !it.done(); it.next()) {
|
||||
|
@ -1031,9 +1031,11 @@ static bool contains(const SkRect& r, SkPoint p) {
|
||||
r.top() <= p.y() && p.y() <= r.bottom();
|
||||
}
|
||||
|
||||
void SkPDFDevice::drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset) {
|
||||
SkPaint paint{glyphRun.paint()};
|
||||
SkFont font{SkFont::LEGACY_ExtractFromPaint(paint)};
|
||||
void SkPDFDevice::drawGlyphRunAsPath(
|
||||
const SkGlyphRun& glyphRun, SkPoint offset, const SkPaint& runPaint) {
|
||||
SkPaint paint{runPaint};
|
||||
glyphRun.font().LEGACY_applyToPaint(&paint);
|
||||
SkFont font = glyphRun.font();
|
||||
SkPath path;
|
||||
|
||||
struct Rec {
|
||||
@ -1055,23 +1057,20 @@ void SkPDFDevice::drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset)
|
||||
}, &rec);
|
||||
this->drawPath(path, paint, true);
|
||||
|
||||
SkFont transparentFont = glyphRun.font();
|
||||
transparentFont.setEmbolden(false); // Stop Recursion
|
||||
SkGlyphRun tmpGlyphRun(glyphRun, transparentFont);
|
||||
|
||||
SkPaint transparent;
|
||||
transparent.setTypeface(paint.getTypeface() ? paint.refTypeface()
|
||||
: SkTypeface::MakeDefault());
|
||||
transparent.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
transparent.setColor(SK_ColorTRANSPARENT);
|
||||
transparent.setTextSize(paint.getTextSize());
|
||||
transparent.setTextScaleX(paint.getTextScaleX());
|
||||
transparent.setTextSkewX(paint.getTextSkewX());
|
||||
SkGlyphRun tmp(glyphRun, transparent);
|
||||
|
||||
if (this->ctm().hasPerspective()) {
|
||||
SkMatrix prevCTM = this->ctm();
|
||||
this->setCTM(SkMatrix::I());
|
||||
this->internalDrawGlyphRun(tmp, offset);
|
||||
this->internalDrawGlyphRun(tmpGlyphRun, offset, transparent);
|
||||
this->setCTM(prevCTM);
|
||||
} 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;
|
||||
}
|
||||
|
||||
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();
|
||||
uint32_t glyphCount = SkToU32(glyphRun.glyphsIDs().size());
|
||||
SkPaint srcPaint{glyphRun.paint()};
|
||||
SkPaint srcPaint{runPaint};
|
||||
glyphRun.font().LEGACY_applyToPaint(&srcPaint);
|
||||
srcPaint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
|
||||
if (!glyphCount || !glyphs || srcPaint.getTextSize() <= 0 || this->hasEmptyClip()) {
|
||||
@ -1109,7 +1110,7 @@ void SkPDFDevice::internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offse
|
||||
|| this->ctm().hasPerspective()
|
||||
|| SkPaint::kFill_Style != srcPaint.getStyle()) {
|
||||
// Stroked Text doesn't work well with Type3 fonts.
|
||||
this->drawGlyphRunAsPath(glyphRun, offset);
|
||||
this->drawGlyphRunAsPath(glyphRun, offset, runPaint);
|
||||
return;
|
||||
}
|
||||
SkPaint paint(srcPaint);
|
||||
@ -1262,7 +1263,7 @@ void SkPDFDevice::internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offse
|
||||
|
||||
void SkPDFDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) {
|
||||
for (const SkGlyphRun& glyphRun : glyphRunList) {
|
||||
this->internalDrawGlyphRun(glyphRun, glyphRunList.origin());
|
||||
this->internalDrawGlyphRun(glyphRun, glyphRunList.origin(), glyphRunList.paint());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,8 +224,8 @@ private:
|
||||
bool hasText,
|
||||
GraphicStateEntry* entry);
|
||||
|
||||
void internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offset);
|
||||
void drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset);
|
||||
void internalDrawGlyphRun(const SkGlyphRun& glyphRun, SkPoint offset, const SkPaint& runPaint);
|
||||
void drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset, const SkPaint& runPaint);
|
||||
|
||||
void internalDrawImageRect(SkKeyedImage,
|
||||
const SkRect* src,
|
||||
|
@ -852,10 +852,9 @@ public:
|
||||
SVGTextBuilder(SkPoint origin, const SkGlyphRun& glyphRun)
|
||||
: fOrigin(origin)
|
||||
, fLastCharWasWhitespace(true) { // start off in whitespace mode to strip all leadingspace
|
||||
const SkFont font = SkFont::LEGACY_ExtractFromPaint(glyphRun.paint());
|
||||
auto runSize = glyphRun.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();
|
||||
for (size_t i = 0; i < runSize; ++i) {
|
||||
this->appendUnichar(unichars[i], positions[i]);
|
||||
@ -929,8 +928,10 @@ private:
|
||||
|
||||
void SkSVGDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) {
|
||||
|
||||
auto processGlyphRun = [this](SkPoint origin, const SkGlyphRun& glyphRun) {
|
||||
const SkPaint& paint = glyphRun.paint();
|
||||
auto processGlyphRun = [this]
|
||||
(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);
|
||||
elem.addTextAttributes(paint);
|
||||
|
||||
@ -941,7 +942,7 @@ void SkSVGDevice::drawGlyphRunList(const SkGlyphRunList& glyphRunList) {
|
||||
};
|
||||
|
||||
for (auto& glyphRun : glyphRunList) {
|
||||
processGlyphRun(glyphRunList.origin(), glyphRun);
|
||||
processGlyphRun(glyphRunList.origin(), glyphRun, glyphRunList.paint());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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, SkFont::LEGACY_ExtractFromPaint(paint),
|
||||
return SkGlyphRun(SkFont::LEGACY_ExtractFromPaint(paint),
|
||||
SkSpan<const SkPoint>{pos, len},
|
||||
SkSpan<const SkGlyphID>{glyphs, len},
|
||||
SkSpan<const char>{utf8Text, utf8TextByteLength},
|
||||
|
Loading…
Reference in New Issue
Block a user