Use SkFont in textblobs

Bug: skia:2664
Change-Id: I43fd6471a66320787890f620c072974ca974b236
Reviewed-on: https://skia-review.googlesource.com/c/172640
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp
index 4b9f347..77b39ec 100644
--- a/tests/SkRemoteGlyphCacheTest.cpp
+++ b/tests/SkRemoteGlyphCacheTest.cpp
@@ -436,30 +436,27 @@
 
 sk_sp<SkTextBlob> make_blob_causing_fallback(
         sk_sp<SkTypeface> targetTf, const SkTypeface* glyphTf, skiatest::Reporter* reporter) {
-    SkPaint paint;
-    paint.setSubpixelText(true);
-    paint.setTextSize(96);
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
-    paint.setStyle(SkPaint::kFill_Style);
-    paint.setHinting(kNormal_SkFontHinting);
+    SkFont font;
+    font.setSubpixel(true);
+    font.setSize(96);
+    font.setHinting(kNormal_SkFontHinting);
+    font.setTypeface(targetTf);
 
-    paint.setTypeface(targetTf);
-
-    REPORTER_ASSERT(reporter, !SkDraw::ShouldDrawTextAsPaths(paint, SkMatrix::I()));
+    REPORTER_ASSERT(reporter, !SkDraw::ShouldDrawTextAsPaths(font, SkPaint(), SkMatrix::I()));
 
     char s[] = "Skia";
     int runSize = strlen(s);
 
     SkTextBlobBuilder builder;
     SkRect bounds = SkRect::MakeIWH(100, 100);
-    const auto& runBuffer = builder.allocRunPosH(paint, runSize, 10, &bounds);
+    const auto& runBuffer = builder.allocRunPosH(font, runSize, 10, &bounds);
     SkASSERT(runBuffer.utf8text == nullptr);
     SkASSERT(runBuffer.clusters == nullptr);
 
     glyphTf->charsToGlyphs(s, SkTypeface::kUTF8_Encoding, runBuffer.glyphs, runSize);
 
     SkRect glyphBounds;
-    paint.measureText(runBuffer.glyphs, 2, &glyphBounds);
+    font.getWidths(runBuffer.glyphs, 1, nullptr, &glyphBounds);
 
     REPORTER_ASSERT(reporter, glyphBounds.width() > SkGlyphCacheCommon::kSkSideTooBigForAtlas);
 
diff --git a/tests/TextBlobCacheTest.cpp b/tests/TextBlobCacheTest.cpp
index 5f63622..4a1d49c 100644
--- a/tests/TextBlobCacheTest.cpp
+++ b/tests/TextBlobCacheTest.cpp
@@ -83,9 +83,8 @@
     // generate textblobs
     SkTArray<sk_sp<SkTextBlob>> blobs;
     for (int i = 0; i < count; i++) {
-        SkPaint paint;
-        paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
-        paint.setTextSize(48); // draw big glyphs to really stress the atlas
+        SkFont font;
+        font.setSize(48); // draw big glyphs to really stress the atlas
 
         SkString familyName;
         fm->getFamilyName(i, &familyName);
@@ -97,22 +96,27 @@
             // We use a typeface which randomy returns unexpected mask formats to fuzz
             sk_sp<SkTypeface> orig(set->createTypeface(j));
             if (normal) {
-                paint.setTypeface(orig);
+                font.setTypeface(orig);
             } else {
-                paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, true));
+                font.setTypeface(sk_make_sp<SkRandomTypeface>(orig, SkPaint(), true));
             }
 
             SkTextBlobBuilder builder;
             for (int aa = 0; aa < 2; aa++) {
                 for (int subpixel = 0; subpixel < 2; subpixel++) {
                     for (int lcd = 0; lcd < 2; lcd++) {
-                        paint.setAntiAlias(SkToBool(aa));
-                        paint.setSubpixelText(SkToBool(subpixel));
-                        paint.setLCDRenderText(SkToBool(lcd));
-                        if (!SkToBool(lcd)) {
-                            paint.setTextSize(160);
+                        font.setEdging(SkFont::Edging::kAlias);
+                        if (aa) {
+                            font.setEdging(SkFont::Edging::kAntiAlias);
+                            if (lcd) {
+                                font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
+                            }
                         }
-                        const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(paint,
+                        font.setSubpixel(SkToBool(subpixel));
+                        if (!SkToBool(lcd)) {
+                            font.setSize(160);
+                        }
+                        const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(font,
                                                                                    maxTotalText,
                                                                                    0, 0,
                                                                                    nullptr);
diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp
index 94c7fa5..249cd1b 100644
--- a/tests/TextBlobTest.cpp
+++ b/tests/TextBlobTest.cpp
@@ -362,19 +362,17 @@
 
 static void add_run(SkTextBlobBuilder* builder, const char text[], SkScalar x, SkScalar y,
                     sk_sp<SkTypeface> tf) {
-    SkPaint paint;
-    paint.setAntiAlias(true);
-    paint.setSubpixelText(true);
-    paint.setTextSize(16);
-    paint.setTypeface(tf);
+    SkFont font;
+    font.setEdging(SkFont::Edging::kAntiAlias);
+    font.setSubpixel(true);
+    font.setSize(16);
+    font.setTypeface(tf);
 
-    int glyphCount = paint.textToGlyphs(text, strlen(text), nullptr);
+    int glyphCount = font.countText(text, strlen(text), kUTF8_SkTextEncoding);
 
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
-    SkTextBlobBuilder::RunBuffer buffer = builder->allocRun(paint, glyphCount, x, y);
+    SkTextBlobBuilder::RunBuffer buffer = builder->allocRun(font, glyphCount, x, y);
 
-    paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
-    (void)paint.textToGlyphs(text, strlen(text), buffer.glyphs);
+    (void)font.textToGlyphs(text, strlen(text), kUTF8_SkTextEncoding, buffer.glyphs, glyphCount);
 }
 
 static sk_sp<SkImage> render(const SkTextBlob* blob) {