start removing legacy paint calls
Bug: skia: Change-Id: I2a5c98c65e587015beb0ed6f6d5bcf5a3a1b69a2 Reviewed-on: https://skia-review.googlesource.com/c/177066 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
This commit is contained in:
parent
eae1d10f5d
commit
34c9b6d63e
@ -208,14 +208,10 @@ TextAdapter::TextAdapter(sk_sp<sksg::Group> root)
|
||||
}
|
||||
|
||||
sk_sp<SkTextBlob> TextAdapter::makeBlob() const {
|
||||
// TODO: convert to SkFont (missing getFontSpacing, measureText).
|
||||
SkPaint font;
|
||||
font.setTypeface(fText.fTypeface);
|
||||
font.setTextSize(fText.fTextSize);
|
||||
SkFont font(fText.fTypeface, fText.fTextSize);
|
||||
font.setHinting(kNo_SkFontHinting);
|
||||
font.setSubpixelText(true);
|
||||
font.setAntiAlias(true);
|
||||
font.setTextEncoding(kUTF8_SkTextEncoding);
|
||||
font.setSubpixel(true);
|
||||
font.setEdging(SkFont::Edging::kAntiAlias);
|
||||
|
||||
const auto align_fract = [](SkTextUtils::Align align) {
|
||||
switch (align) {
|
||||
@ -226,8 +222,7 @@ sk_sp<SkTextBlob> TextAdapter::makeBlob() const {
|
||||
return 0.0f; // go home, msvc...
|
||||
}(fText.fAlign);
|
||||
|
||||
const auto line_spacing = font.getFontSpacing();
|
||||
const auto blob_font = SkFont::LEGACY_ExtractFromPaint(font);
|
||||
const auto line_spacing = font.getSpacing();
|
||||
float y_off = 0;
|
||||
SkSTArray<256, SkGlyphID, true> line_glyph_buffer;
|
||||
SkTextBlobBuilder builder;
|
||||
@ -235,14 +230,15 @@ sk_sp<SkTextBlob> TextAdapter::makeBlob() const {
|
||||
const auto& push_line = [&](const char* start, const char* end) {
|
||||
if (end > start) {
|
||||
const auto len = SkToSizeT(end - start);
|
||||
line_glyph_buffer.reset(font.textToGlyphs(start, len, nullptr));
|
||||
SkAssertResult(font.textToGlyphs(start, len, line_glyph_buffer.data())
|
||||
line_glyph_buffer.reset(font.countText(start, len, kUTF8_SkTextEncoding));
|
||||
SkAssertResult(font.textToGlyphs(start, len, kUTF8_SkTextEncoding, line_glyph_buffer.data(),
|
||||
line_glyph_buffer.count())
|
||||
== line_glyph_buffer.count());
|
||||
|
||||
const auto x_off = align_fract != 0
|
||||
? align_fract * font.measureText(start, len)
|
||||
? align_fract * font.measureText(start, len, kUTF8_SkTextEncoding)
|
||||
: 0;
|
||||
const auto& buf = builder.allocRun(blob_font, line_glyph_buffer.count(), x_off, y_off);
|
||||
const auto& buf = builder.allocRun(font, line_glyph_buffer.count(), x_off, y_off);
|
||||
if (!buf.glyphs) {
|
||||
return;
|
||||
}
|
||||
|
@ -587,7 +587,7 @@ void SkLiteDL::drawImageSet(const SkCanvas::ImageSetEntry set[], int count,
|
||||
|
||||
void SkLiteDL::drawTextRSXform(const void* text, size_t bytes,
|
||||
const SkRSXform xforms[], const SkRect* cull, const SkPaint& paint) {
|
||||
int n = paint.countText(text, bytes);
|
||||
int n = SkFont::LEGACY_ExtractFromPaint(paint).countText(text, bytes, paint.getTextEncoding());
|
||||
void* pod = this->push<DrawTextRSXform>(bytes+n*sizeof(SkRSXform), bytes, n, cull, paint);
|
||||
copy_v(pod, xforms,n, (const char*)text,bytes);
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ SkScalar SkPaint::MaxCacheSize2(SkScalar maxLimit) {
|
||||
#include "SkGlyphCache.h"
|
||||
#include "SkUtils.h"
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
|
||||
int SkPaint::countText(const void* text, size_t length) const {
|
||||
return SkFont::LEGACY_ExtractFromPaint(*this).countText(text, length, this->getTextEncoding());
|
||||
}
|
||||
@ -75,6 +76,7 @@ bool SkPaint::containsText(const void* text, size_t length) const {
|
||||
return SkFont::LEGACY_ExtractFromPaint(*this).containsText(text, length,
|
||||
this->getTextEncoding());
|
||||
}
|
||||
#endif
|
||||
|
||||
void SkPaint::glyphsToUnichars(const uint16_t glyphs[], int count, SkUnichar textData[]) const {
|
||||
SkFont::LEGACY_ExtractFromPaint(*this).glyphsToUnichars(glyphs, count, textData);
|
||||
@ -297,6 +299,7 @@ SkScalar SkPaint::measure_text(SkGlyphCache* cache,
|
||||
return x;
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
|
||||
SkScalar SkPaint::measureText(const void* textData, size_t length, SkRect* bounds) const {
|
||||
const char* text = (const char*)textData;
|
||||
SkASSERT(text != nullptr || length == 0);
|
||||
@ -330,20 +333,10 @@ SkScalar SkPaint::measureText(const void* textData, size_t length, SkRect* bound
|
||||
return width;
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PAINT_BREAKTEXT
|
||||
size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth,
|
||||
SkScalar* measuredWidth) const {
|
||||
return SkFont::LEGACY_ExtractFromPaint(*this).breakText(textD, length,
|
||||
this->getTextEncoding(), maxWidth, measuredWidth);
|
||||
}
|
||||
#endif
|
||||
|
||||
SkScalar SkPaint::getFontMetrics(SkFontMetrics* metrics) const {
|
||||
return SkFont::LEGACY_ExtractFromPaint(*this).getMetrics(metrics);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int SkPaint::getTextWidths(const void* text, size_t len, SkScalar widths[], SkRect bounds[]) const {
|
||||
const SkFont font = SkFont::LEGACY_ExtractFromPaint(*this);
|
||||
SkAutoToGlyphs gly(font, text, len, this->getTextEncoding());
|
||||
@ -351,8 +344,19 @@ int SkPaint::getTextWidths(const void* text, size_t len, SkScalar widths[], SkRe
|
||||
return gly.count();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PAINT_BREAKTEXT
|
||||
size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth,
|
||||
SkScalar* measuredWidth) const {
|
||||
return SkFont::LEGACY_ExtractFromPaint(*this).breakText(textD, length,
|
||||
this->getTextEncoding(), maxWidth, measuredWidth);
|
||||
}
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
|
||||
#include "SkDraw.h"
|
||||
|
||||
struct PathPosRec {
|
||||
@ -390,6 +394,7 @@ void SkPaint::getPosTextPath(const void* text, size_t length,
|
||||
PathPosRec rec = { path, pos };
|
||||
font.getPaths(gly.glyphs(), gly.count(), PathPosProc, &rec);
|
||||
}
|
||||
#endif
|
||||
|
||||
int SkPaint::getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2],
|
||||
SkScalar* intervals) const {
|
||||
|
@ -564,7 +564,7 @@ void SkPictureRecord::onDrawImageSet(const SkCanvas::ImageSetEntry set[], int co
|
||||
void SkPictureRecord::onDrawTextRSXform(const void* text, size_t byteLength,
|
||||
const SkRSXform xform[], const SkRect* cull,
|
||||
const SkPaint& paint) {
|
||||
const int count = paint.countText(text, byteLength);
|
||||
const int count = SkFont::LEGACY_ExtractFromPaint(paint).countText(text, byteLength, paint.getTextEncoding());
|
||||
// [op + paint-index + count + flags + length] + [text] + [xform] + cull
|
||||
size_t size = 5 * kUInt32Size + SkAlign4(byteLength) + count * sizeof(SkRSXform);
|
||||
uint32_t flags = 0;
|
||||
|
@ -268,7 +268,7 @@ void SkRecorder::onDrawTextRSXform(const void* text, size_t byteLength, const Sk
|
||||
paint,
|
||||
this->copy((const char*)text, byteLength),
|
||||
byteLength,
|
||||
this->copy(xform, paint.countText(text, byteLength)),
|
||||
this->copy(xform, SkFont::LEGACY_ExtractFromPaint(paint).countText(text, byteLength, paint.getTextEncoding())),
|
||||
this->copy(cull));
|
||||
}
|
||||
|
||||
|
@ -6,48 +6,21 @@
|
||||
*/
|
||||
|
||||
#include "SkTextUtils.h"
|
||||
#include "SkTextBlob.h"
|
||||
|
||||
void SkTextUtils::DrawText(SkCanvas* canvas, const void* text, size_t size, SkScalar x, SkScalar y,
|
||||
const SkPaint& origPaint, Align align) {
|
||||
int count = origPaint.countText(text, size);
|
||||
if (!count) {
|
||||
return;
|
||||
}
|
||||
const SkPaint& paint, Align align) {
|
||||
|
||||
SkPaint paint(origPaint);
|
||||
SkAutoSTArray<32, uint16_t> glyphStorage;
|
||||
const uint16_t* glyphs;
|
||||
|
||||
if (paint.getTextEncoding() != kGlyphID_SkTextEncoding) {
|
||||
glyphStorage.reset(count);
|
||||
paint.textToGlyphs(text, size, glyphStorage.get());
|
||||
glyphs = glyphStorage.get();
|
||||
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
} else {
|
||||
glyphs = static_cast<const uint16_t*>(text);
|
||||
}
|
||||
|
||||
SkAutoSTArray<32, SkScalar> widthStorage(count);
|
||||
SkScalar* widths = widthStorage.get();
|
||||
paint.getTextWidths(glyphs, count * sizeof(uint16_t), widths);
|
||||
SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
|
||||
|
||||
if (align != kLeft_Align) {
|
||||
SkScalar offset = 0;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
offset += widths[i];
|
||||
}
|
||||
SkScalar width = font.measureText(text, size, paint.getTextEncoding());
|
||||
if (align == kCenter_Align) {
|
||||
offset *= 0.5f;
|
||||
width *= 0.5f;
|
||||
}
|
||||
x -= offset;
|
||||
x -= width;
|
||||
}
|
||||
|
||||
// Turn widths into h-positions
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkScalar w = widths[i];
|
||||
widths[i] = x;
|
||||
x += w;
|
||||
}
|
||||
canvas->drawPosTextH(glyphs, count * sizeof(uint16_t), widths, y, paint);
|
||||
canvas->drawTextBlob(SkTextBlob::MakeFromText(text, size, font, paint.getTextEncoding()), x, y, paint);
|
||||
}
|
||||
|
||||
|
@ -2059,7 +2059,7 @@ SkDrawTextRSXformCommand::SkDrawTextRSXformCommand(const void* text, size_t byte
|
||||
const SkPaint& paint)
|
||||
: INHERITED(kDrawTextRSXform_OpType)
|
||||
, fText(SkData::MakeWithCopy(text, byteLength))
|
||||
, fXform(xform, paint.countText(text, byteLength))
|
||||
, fXform(xform, SkFont::LEGACY_ExtractFromPaint(paint).countText(text, byteLength, paint.getTextEncoding()))
|
||||
, fCull(cull)
|
||||
, fPaint(paint) {}
|
||||
|
||||
|
@ -628,13 +628,13 @@ void SkTestSVGTypeface::exportTtxCbdt(SkWStream* out) const {
|
||||
int strikeSizes[3] = { 16, 64, 128 };
|
||||
|
||||
SkPaint paint;
|
||||
paint.setTypeface(sk_ref_sp(const_cast<SkTestSVGTypeface*>(this)));
|
||||
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
SkFont font;
|
||||
font.setTypeface(sk_ref_sp(const_cast<SkTestSVGTypeface*>(this)));
|
||||
|
||||
out->writeText(" <CBDT>\n");
|
||||
out->writeText(" <header version=\"2.0\"/>\n");
|
||||
for (size_t strikeIndex = 0; strikeIndex < SK_ARRAY_COUNT(strikeSizes); ++strikeIndex) {
|
||||
paint.setTextSize(strikeSizes[strikeIndex]);
|
||||
font.setSize(strikeSizes[strikeIndex]);
|
||||
out->writeText(" <strikedata index=\"");
|
||||
out->writeDecAsText(strikeIndex);
|
||||
out->writeText("\">\n");
|
||||
@ -642,7 +642,7 @@ void SkTestSVGTypeface::exportTtxCbdt(SkWStream* out) const {
|
||||
SkGlyphID gid = i;
|
||||
SkScalar advance;
|
||||
SkRect bounds;
|
||||
paint.getTextWidths(&gid, sizeof(gid), &advance, &bounds);
|
||||
font.getWidthsBounds(&gid, 1, &advance, &bounds, nullptr);
|
||||
SkIRect ibounds = bounds.roundOut();
|
||||
if (ibounds.isEmpty()) {
|
||||
continue;
|
||||
@ -654,7 +654,8 @@ void SkTestSVGTypeface::exportTtxCbdt(SkWStream* out) const {
|
||||
canvas->clear(0);
|
||||
SkPixmap pix;
|
||||
surface->peekPixels(&pix);
|
||||
canvas->drawText(&gid, sizeof(gid), -bounds.fLeft, -bounds.fTop, paint);
|
||||
canvas->drawSimpleText(&gid, sizeof(gid), kGlyphID_SkTextEncoding,
|
||||
-bounds.fLeft, -bounds.fTop, font, paint);
|
||||
canvas->flush();
|
||||
sk_sp<SkImage> image = surface->makeImageSnapshot();
|
||||
sk_sp<SkData> data = image->encodeToData(SkEncodedImageFormat::kPNG, 100);
|
||||
@ -701,8 +702,8 @@ void SkTestSVGTypeface::exportTtxCbdt(SkWStream* out) const {
|
||||
out->writeText(" <CBLC>\n");
|
||||
out->writeText(" <header version=\"2.0\"/>\n");
|
||||
for (size_t strikeIndex = 0; strikeIndex < SK_ARRAY_COUNT(strikeSizes); ++strikeIndex) {
|
||||
paint.setTextSize(strikeSizes[strikeIndex]);
|
||||
paint.getFontMetrics(&fm);
|
||||
font.setSize(strikeSizes[strikeIndex]);
|
||||
font.getMetrics(&fm);
|
||||
out->writeText(" <strike index=\"");
|
||||
out->writeDecAsText(strikeIndex);
|
||||
out->writeText("\">\n");
|
||||
@ -763,7 +764,7 @@ void SkTestSVGTypeface::exportTtxCbdt(SkWStream* out) const {
|
||||
for (int i = 0; i < fGlyphCount; ++i) {
|
||||
SkGlyphID gid = i;
|
||||
SkRect bounds;
|
||||
paint.getTextWidths(&gid, sizeof(gid), nullptr, &bounds);
|
||||
font.getBounds(&gid, 1, &bounds, nullptr);
|
||||
if (bounds.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@ -796,8 +797,8 @@ void SkTestSVGTypeface::exportTtxSbix(SkWStream* out) const {
|
||||
this->exportTtxCommon(out, "sbix");
|
||||
|
||||
SkPaint paint;
|
||||
paint.setTypeface(sk_ref_sp(const_cast<SkTestSVGTypeface*>(this)));
|
||||
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
SkFont font;
|
||||
font.setTypeface(sk_ref_sp(const_cast<SkTestSVGTypeface*>(this)));
|
||||
|
||||
out->writeText(" <glyf>\n");
|
||||
for (int i = 0; i < fGlyphCount; ++i) {
|
||||
@ -847,7 +848,7 @@ void SkTestSVGTypeface::exportTtxSbix(SkWStream* out) const {
|
||||
out->writeText(" <version value=\"1\"/>\n");
|
||||
out->writeText(" <flags value=\"00000000 00000001\"/>\n");
|
||||
for (size_t strikeIndex = 0; strikeIndex < SK_ARRAY_COUNT(strikeSizes); ++strikeIndex) {
|
||||
paint.setTextSize(strikeSizes[strikeIndex]);
|
||||
font.setSize(strikeSizes[strikeIndex]);
|
||||
out->writeText(" <strike>\n");
|
||||
out->writeText(" <ppem value=\"");
|
||||
out->writeDecAsText(strikeSizes[strikeIndex]);
|
||||
@ -857,7 +858,7 @@ void SkTestSVGTypeface::exportTtxSbix(SkWStream* out) const {
|
||||
SkGlyphID gid = i;
|
||||
SkScalar advance;
|
||||
SkRect bounds;
|
||||
paint.getTextWidths(&gid, sizeof(gid), &advance, &bounds);
|
||||
font.getWidthsBounds(&gid, 1, &advance, &bounds, nullptr);
|
||||
SkIRect ibounds = bounds.roundOut();
|
||||
if (ibounds.isEmpty()) {
|
||||
continue;
|
||||
@ -869,7 +870,8 @@ void SkTestSVGTypeface::exportTtxSbix(SkWStream* out) const {
|
||||
canvas->clear(0);
|
||||
SkPixmap pix;
|
||||
surface->peekPixels(&pix);
|
||||
canvas->drawText(&gid, sizeof(gid), -bounds.fLeft, -bounds.fTop, paint);
|
||||
canvas->drawSimpleText(&gid, sizeof(gid), kGlyphID_SkTextEncoding,
|
||||
-bounds.fLeft, -bounds.fTop, font, paint);
|
||||
canvas->flush();
|
||||
sk_sp<SkImage> image = surface->makeImageSnapshot();
|
||||
sk_sp<SkData> data = image->encodeToData(SkEncodedImageFormat::kPNG, 100);
|
||||
|
Loading…
Reference in New Issue
Block a user