pass a font to GlyphRunBuilder
- avoid using legacy paint->font converter - call out that drawText exists just for testing - simplify drawText to assume UTF8 Bug: skia: Change-Id: Ide14d8581d4744827d2282e7983cc5e19070b21e Reviewed-on: https://skia-review.googlesource.com/c/180641 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Herb Derby <herb@google.com>
This commit is contained in:
parent
35ac038ce0
commit
191e64b6c6
@ -8,6 +8,7 @@
|
||||
#ifndef SkAtlasTextFont_DEFINED
|
||||
#define SkAtlasTextFont_DEFINED
|
||||
|
||||
#include "SkFont.h"
|
||||
#include "SkRefCnt.h"
|
||||
#include "SkTypeface.h"
|
||||
|
||||
@ -24,6 +25,8 @@ public:
|
||||
|
||||
SkScalar size() const { return fSize; }
|
||||
|
||||
SkFont makeFont() const { return SkFont(fTypeface, fSize); }
|
||||
|
||||
private:
|
||||
SkAtlasTextFont(sk_sp<SkTypeface> typeface, SkScalar size)
|
||||
: fTypeface(std::move(typeface)), fSize(size) {}
|
||||
|
@ -148,10 +148,6 @@ void SkInternalAtlasTextTarget::drawText(const SkGlyphID glyphs[], const SkPoint
|
||||
const SkAtlasTextFont& font) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTypeface(font.refTypeface());
|
||||
paint.setTextSize(font.size());
|
||||
paint.setStyle(SkPaint::kFill_Style);
|
||||
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
|
||||
// The atlas text context does munging of the paint color. We store the client's color here
|
||||
// and then overwrite the generated op's color when addDrawOp() is called.
|
||||
@ -161,7 +157,8 @@ void SkInternalAtlasTextTarget::drawText(const SkGlyphID glyphs[], const SkPoint
|
||||
auto* grContext = this->context()->internal().grContext();
|
||||
auto atlasTextContext = grContext->contextPriv().drawingManager()->getTextContext();
|
||||
SkGlyphRunBuilder builder;
|
||||
builder.drawGlyphsWithPositions(paint, SkSpan<const SkGlyphID>{glyphs, SkTo<size_t>(glyphCnt)},
|
||||
builder.drawGlyphsWithPositions(paint, font.makeFont(),
|
||||
SkSpan<const SkGlyphID>{glyphs, SkTo<size_t>(glyphCnt)},
|
||||
positions);
|
||||
auto glyphRunList = builder.useGlyphRunList();
|
||||
if (!glyphRunList.empty()) {
|
||||
|
@ -18,17 +18,6 @@
|
||||
#include "SkTo.h"
|
||||
#include "SkUtils.h"
|
||||
|
||||
namespace {
|
||||
static SkTypeface::Encoding convert_encoding(SkTextEncoding encoding) {
|
||||
switch (encoding) {
|
||||
case kUTF8_SkTextEncoding: return SkTypeface::kUTF8_Encoding;
|
||||
case kUTF16_SkTextEncoding: return SkTypeface::kUTF16_Encoding;
|
||||
case kUTF32_SkTextEncoding: return SkTypeface::kUTF32_Encoding;
|
||||
default: return SkTypeface::kUTF32_Encoding;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// -- SkGlyphRun -----------------------------------------------------------------------------------
|
||||
SkGlyphRun::SkGlyphRun(const SkFont& font,
|
||||
SkSpan<const SkPoint> positions,
|
||||
@ -162,9 +151,9 @@ SkSpan<const SkGlyphID> SkGlyphIDSet::uniquifyGlyphIDs(
|
||||
}
|
||||
|
||||
// -- SkGlyphRunBuilder ----------------------------------------------------------------------------
|
||||
void SkGlyphRunBuilder::drawText(
|
||||
const SkPaint& paint, const void* bytes, size_t byteLength, SkPoint origin) {
|
||||
auto glyphIDs = textToGlyphIDs(paint, bytes, byteLength);
|
||||
void SkGlyphRunBuilder::drawTextUTF8(const SkPaint& paint, const SkFont& font, const void* bytes,
|
||||
size_t byteLength, SkPoint origin) {
|
||||
auto glyphIDs = textToGlyphIDs(font, bytes, byteLength, kUTF8_SkTextEncoding);
|
||||
if (!glyphIDs.empty()) {
|
||||
this->initialize(glyphIDs.size());
|
||||
this->simplifyDrawText(SkFont::LEGACY_ExtractFromPaint(paint),
|
||||
@ -236,11 +225,11 @@ void SkGlyphRunBuilder::drawTextBlob(const SkPaint& paint, const SkTextBlob& blo
|
||||
}
|
||||
}
|
||||
|
||||
void SkGlyphRunBuilder::drawGlyphsWithPositions(
|
||||
const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos) {
|
||||
void SkGlyphRunBuilder::drawGlyphsWithPositions(const SkPaint& paint, const SkFont& font,
|
||||
SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos) {
|
||||
if (!glyphIDs.empty()) {
|
||||
this->initialize(glyphIDs.size());
|
||||
this->simplifyDrawPosText(SkFont::LEGACY_ExtractFromPaint(paint), glyphIDs, pos);
|
||||
this->simplifyDrawPosText(font, glyphIDs, pos);
|
||||
this->makeGlyphRunList(paint, nullptr, SkPoint::Make(0, 0));
|
||||
}
|
||||
}
|
||||
@ -260,16 +249,12 @@ void SkGlyphRunBuilder::initialize(size_t totalRunSize) {
|
||||
}
|
||||
|
||||
SkSpan<const SkGlyphID> SkGlyphRunBuilder::textToGlyphIDs(
|
||||
const SkPaint& paint, const void* bytes, size_t byteLength) {
|
||||
SkTextEncoding encoding = paint.getTextEncoding();
|
||||
const SkFont& font, const void* bytes, size_t byteLength, SkTextEncoding encoding) {
|
||||
if (encoding != kGlyphID_SkTextEncoding) {
|
||||
auto tfEncoding = convert_encoding(encoding);
|
||||
int utfSize = SkUTFN_CountUnichars(tfEncoding, bytes, byteLength);
|
||||
if (utfSize > 0) {
|
||||
size_t runSize = SkTo<size_t>(utfSize);
|
||||
fScratchGlyphIDs.resize(runSize);
|
||||
auto typeface = SkPaintPriv::GetTypefaceOrDefault(paint);
|
||||
typeface->charsToGlyphs(bytes, tfEncoding, fScratchGlyphIDs.data(), runSize);
|
||||
int count = font.countText(bytes, byteLength, encoding);
|
||||
if (count > 0) {
|
||||
fScratchGlyphIDs.resize(count);
|
||||
font.textToGlyphs(bytes, byteLength, encoding, fScratchGlyphIDs.data(), count);
|
||||
return SkSpan<const SkGlyphID>{fScratchGlyphIDs};
|
||||
} else {
|
||||
return SkSpan<const SkGlyphID>();
|
||||
|
@ -112,11 +112,11 @@ private:
|
||||
|
||||
class SkGlyphRunBuilder {
|
||||
public:
|
||||
void drawText(
|
||||
const SkPaint& paint, const void* bytes, size_t byteLength, SkPoint origin);
|
||||
void drawTextBlob(const SkPaint& paint, const SkTextBlob& blob, SkPoint origin, SkBaseDevice*);
|
||||
void drawTextUTF8(
|
||||
const SkPaint& paint, const SkFont&, const void* bytes, size_t byteLength, SkPoint origin);
|
||||
void drawGlyphsWithPositions(
|
||||
const SkPaint& paint, SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos);
|
||||
const SkPaint&, const SkFont&, SkSpan<const SkGlyphID> glyphIDs, const SkPoint* pos);
|
||||
void drawTextBlob(const SkPaint& paint, const SkTextBlob& blob, SkPoint origin, SkBaseDevice*);
|
||||
|
||||
const SkGlyphRunList& useGlyphRunList();
|
||||
|
||||
@ -128,7 +128,7 @@ public:
|
||||
private:
|
||||
void initialize(size_t totalRunSize);
|
||||
SkSpan<const SkGlyphID> textToGlyphIDs(
|
||||
const SkPaint& paint, const void* bytes, size_t byteLength);
|
||||
const SkFont& font, const void* bytes, size_t byteLength, SkTextEncoding);
|
||||
|
||||
void makeGlyphRun(
|
||||
const SkFont& font,
|
||||
|
@ -865,6 +865,7 @@ std::unique_ptr<GrDrawOp> GrTextContext::createOp_TestingOnly(GrContext* context
|
||||
GrTextContext* textContext,
|
||||
GrRenderTargetContext* rtc,
|
||||
const SkPaint& skPaint,
|
||||
const SkFont& font,
|
||||
const SkMatrix& viewMatrix,
|
||||
const char* text,
|
||||
int x,
|
||||
@ -880,7 +881,7 @@ std::unique_ptr<GrDrawOp> GrTextContext::createOp_TestingOnly(GrContext* context
|
||||
|
||||
auto origin = SkPoint::Make(x, y);
|
||||
SkGlyphRunBuilder builder;
|
||||
builder.drawText(skPaint, text, textLen, origin);
|
||||
builder.drawTextUTF8(skPaint, font, text, textLen, origin);
|
||||
|
||||
auto glyphRunList = builder.useGlyphRunList();
|
||||
sk_sp<GrTextBlob> blob;
|
||||
|
@ -226,9 +226,14 @@ GR_DRAW_OP_TEST_DEFINE(GrAtlasTextOp) {
|
||||
|
||||
SkPaint skPaint;
|
||||
skPaint.setColor(random->nextU());
|
||||
skPaint.setLCDRenderText(random->nextBool());
|
||||
skPaint.setAntiAlias(skPaint.isLCDRenderText() ? true : random->nextBool());
|
||||
skPaint.setSubpixelText(random->nextBool());
|
||||
|
||||
SkFont font;
|
||||
if (random->nextBool()) {
|
||||
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
||||
} else {
|
||||
font.setEdging(random->nextBool() ? SkFont::Edging::kAntiAlias : SkFont::Edging::kAlias);
|
||||
}
|
||||
font.setSubpixel(random->nextBool());
|
||||
|
||||
const char* text = "The quick brown fox jumps over the lazy dog.";
|
||||
|
||||
@ -240,7 +245,7 @@ GR_DRAW_OP_TEST_DEFINE(GrAtlasTextOp) {
|
||||
int yInt = (random->nextU() % kMaxTrans) * yPos;
|
||||
|
||||
return gTextContext->createOp_TestingOnly(context, gTextContext.get(), rtc.get(),
|
||||
skPaint, viewMatrix, text, xInt, yInt);
|
||||
skPaint, font, viewMatrix, text, xInt, yInt);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
std::unique_ptr<GrDrawOp> createOp_TestingOnly(GrContext*,
|
||||
GrTextContext*,
|
||||
GrRenderTargetContext*,
|
||||
const SkPaint&,
|
||||
const SkPaint&, const SkFont&,
|
||||
const SkMatrix& viewMatrix,
|
||||
const char* text,
|
||||
int x,
|
||||
|
@ -199,14 +199,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrAtlasTextOpPreparation, reporter, ctxInfo)
|
||||
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorRED);
|
||||
paint.setLCDRenderText(false);
|
||||
paint.setAntiAlias(false);
|
||||
paint.setSubpixelText(false);
|
||||
|
||||
SkFont font;
|
||||
font.setEdging(SkFont::Edging::kAlias);
|
||||
|
||||
const char* text = "a";
|
||||
|
||||
std::unique_ptr<GrDrawOp> op = textContext->createOp_TestingOnly(
|
||||
context, textContext, rtc.get(), paint, SkMatrix::I(), text, 16, 16);
|
||||
context, textContext, rtc.get(), paint, font, SkMatrix::I(), text, 16, 16);
|
||||
op->finalize(*context->contextPriv().caps(), nullptr);
|
||||
|
||||
TestingUploadTarget uploadTarget;
|
||||
|
@ -41,17 +41,6 @@ DEF_TEST(GlyphRunGlyphIDSetBasic, reporter) {
|
||||
}
|
||||
}
|
||||
|
||||
DEF_TEST(GlyphRunBasic, reporter) {
|
||||
SkGlyphID glyphs[] = {100, 3, 240, 3, 234, 111, 3, 4, 10, 11};
|
||||
uint16_t count = SK_ARRAY_COUNT(glyphs);
|
||||
|
||||
SkPaint paint;
|
||||
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
|
||||
SkGlyphRunBuilder builder;
|
||||
builder.drawText(paint, glyphs, count, SkPoint::Make(0, 0));
|
||||
}
|
||||
|
||||
#if 0 // should we revitalize this by consing up a device for drawTextBlob() ?
|
||||
DEF_TEST(GlyphRunBlob, reporter) {
|
||||
constexpr uint16_t count = 5;
|
||||
|
Loading…
Reference in New Issue
Block a user