start to hide paint measuretext
Bug: skia:
Change-Id: I904453f24735fc397ed59f4bb7ce0530147a6587
Reviewed-on: https://skia-review.googlesource.com/c/174580
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index d5fff5d..7b01545 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -1033,14 +1033,26 @@
void SkPDFDevice::drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset) {
SkPaint paint{glyphRun.paint()};
- paint.setTextEncoding(kGlyphID_SkTextEncoding);
+ SkFont font{SkFont::LEGACY_ExtractFromPaint(paint)};
SkPath path;
- paint.getPosTextPath(glyphRun.glyphsIDs().data(),
- glyphRun.glyphsIDs().size() * sizeof(SkGlyphID),
- glyphRun.positions().data(),
- &path);
- path.offset(offset.x(), offset.y());
+ struct Rec {
+ SkPath* fPath;
+ SkPoint fOffset;
+ const SkPoint* fPos;
+ } rec = {&path, offset, glyphRun.positions().data()};
+
+ font.getPaths(glyphRun.glyphsIDs().data(), glyphRun.glyphsIDs().size(),
+ [](const SkPath* path, const SkMatrix& mx, void* ctx) {
+ Rec* rec = reinterpret_cast<Rec*>(ctx);
+ if (path) {
+ SkMatrix total = mx;
+ total.postTranslate(rec->fPos->fX + rec->fOffset.fX,
+ rec->fPos->fY + rec->fOffset.fY);
+ rec->fPath->addPath(*path, total);
+ }
+ rec->fPos += 1; // move to the next glyph's position
+ }, &rec);
this->drawPath(path, paint, true);
SkPaint transparent;
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index d3f3457..ae9b116 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -123,17 +123,18 @@
}
if (0 == metrics->fStemV || 0 == metrics->fCapHeight) {
- SkPaint tmpPaint;
- tmpPaint.setHinting(kNo_SkFontHinting);
- tmpPaint.setTypeface(sk_ref_sp(typeface));
- tmpPaint.setTextSize(1000); // glyph coordinate system
+ SkFont font;
+ font.setHinting(kNo_SkFontHinting);
+ font.setTypeface(sk_ref_sp(typeface));
+ font.setSize(1000); // glyph coordinate system
if (0 == metrics->fStemV) {
// Figure out a good guess for StemV - Min width of i, I, !, 1.
// This probably isn't very good with an italic font.
int16_t stemV = SHRT_MAX;
for (char c : {'i', 'I', '!', '1'}) {
+ uint16_t g = font.unicharToGlyph(c);
SkRect bounds;
- tmpPaint.measureText(&c, 1, &bounds);
+ font.getBounds(&g, 1, &bounds, nullptr);
stemV = SkTMin(stemV, SkToS16(SkScalarRoundToInt(bounds.width())));
}
metrics->fStemV = stemV;
@@ -142,8 +143,9 @@
// Figure out a good guess for CapHeight: average the height of M and X.
SkScalar capHeight = 0;
for (char c : {'M', 'X'}) {
+ uint16_t g = font.unicharToGlyph(c);
SkRect bounds;
- tmpPaint.measureText(&c, 1, &bounds);
+ font.getBounds(&g, 1, &bounds, nullptr);
capHeight += bounds.height();
}
metrics->fCapHeight = SkToS16(SkScalarRoundToInt(capHeight / 2));
diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp
index d4c0b6b..36eea35 100644
--- a/tests/PaintTest.cpp
+++ b/tests/PaintTest.cpp
@@ -47,12 +47,6 @@
return count * sizeof(SkUnichar);
}
-static SkTypeface::Encoding paint2encoding(const SkPaint& paint) {
- SkTextEncoding enc = paint.getTextEncoding();
- SkASSERT(kGlyphID_SkTextEncoding != enc);
- return (SkTypeface::Encoding)enc;
-}
-
static int find_first_zero(const uint16_t glyphs[], int count) {
for (int i = 0; i < count; ++i) {
if (0 == glyphs[i]) {
@@ -82,9 +76,9 @@
};
SkRandom rand;
- SkPaint paint;
- paint.setTypeface(SkTypeface::MakeDefault());
- SkTypeface* face = paint.getTypeface();
+ SkFont font;
+ font.setTypeface(SkTypeface::MakeDefault());
+ SkTypeface* face = font.getTypeface();
for (int i = 0; i < 1000; ++i) {
// generate some random text
@@ -95,15 +89,14 @@
src[rand.nextU() & 63] = rand.nextU() & 0xFFF;
for (size_t k = 0; k < SK_ARRAY_COUNT(gRec); ++k) {
- paint.setTextEncoding(gRec[k].fEncoding);
-
size_t len = gRec[k].fSeedTextProc(src, dst, NGLYPHS);
uint16_t glyphs0[NGLYPHS], glyphs1[NGLYPHS];
- bool contains = paint.containsText(dst, len);
- int nglyphs = paint.textToGlyphs(dst, len, glyphs0);
- int first = face->charsToGlyphs(dst, paint2encoding(paint), glyphs1, NGLYPHS);
+ bool contains = font.containsText(dst, len, gRec[k].fEncoding);
+ int nglyphs = font.textToGlyphs(dst, len, gRec[k].fEncoding, glyphs0, NGLYPHS);
+ int first = face->charsToGlyphs(dst, (SkTypeface::Encoding)gRec[k].fEncoding,
+ glyphs1, NGLYPHS);
int index = find_first_zero(glyphs1, NGLYPHS);
REPORTER_ASSERT(reporter, NGLYPHS == nglyphs);