flag to convert to SkTextEncoding

Bug: skia:
Change-Id: I9628bcabc5c6f902b79009e4f21badff3e8cca94
Reviewed-on: https://skia-review.googlesource.com/c/173980
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
diff --git a/gm/coloremoji_blendmodes.cpp b/gm/coloremoji_blendmodes.cpp
index e0f396d..91b17dc 100644
--- a/gm/coloremoji_blendmodes.cpp
+++ b/gm/coloremoji_blendmodes.cpp
@@ -146,7 +146,7 @@
                 SkAutoCanvasRestore arc(canvas, true);
                 canvas->clipRect(r);
                 textP.setBlendMode(gModes[i]);
-                textP.setTextEncoding(SkPaint::kUTF32_TextEncoding);
+                textP.setTextEncoding(kUTF32_SkTextEncoding);
                 const char* text = sk_tool_utils::emoji_sample_text();
                 SkUnichar unichar = SkUTF::NextUTF8(&text, text + strlen(text));
                 SkASSERT(unichar >= 0);
diff --git a/gm/fontmgr.cpp b/gm/fontmgr.cpp
index 0e22588..351b7c7 100644
--- a/gm/fontmgr.cpp
+++ b/gm/fontmgr.cpp
@@ -254,7 +254,7 @@
         {
             int numGlyphs = glyphPaint.getTypeface()->countGlyphs();
             SkRect min = {0, 0, 0, 0};
-            glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+            glyphPaint.setTextEncoding(kGlyphID_SkTextEncoding);
             for (int i = 0; i < numGlyphs; ++i) {
                 SkGlyphID glyphId = i;
                 SkRect cur;
diff --git a/gm/poly2poly.cpp b/gm/poly2poly.cpp
index 6edba54..f298412 100644
--- a/gm/poly2poly.cpp
+++ b/gm/poly2poly.cpp
@@ -235,7 +235,7 @@
         SkPaint paint;
         paint.setAntiAlias(true);
         paint.setTypeface(fEmFace);
-        paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+        paint.setTextEncoding(kGlyphID_SkTextEncoding);
         paint.setStrokeWidth(SkIntToScalar(4));
         paint.setTextSize(SkIntToScalar(40));
 
diff --git a/gm/skbug_5321.cpp b/gm/skbug_5321.cpp
index 740c4f4..be7e756 100644
--- a/gm/skbug_5321.cpp
+++ b/gm/skbug_5321.cpp
@@ -14,7 +14,7 @@
     paint.setStyle(SkPaint::kFill_Style);
     paint.setTextSize(30);
 
-    paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
+    paint.setTextEncoding(kUTF8_SkTextEncoding);
     const char text[] = "x\314\200y";  // utf8(u"x\u0300y")
     SkScalar x = 20, y = 45;
     size_t byteLength = strlen(text);
diff --git a/gm/texteffects.cpp b/gm/texteffects.cpp
index 6c8699e..9841c82 100644
--- a/gm/texteffects.cpp
+++ b/gm/texteffects.cpp
@@ -149,7 +149,7 @@
     SkAutoTArray<SkGlyphID> glyphs(glyphCount);
     blobPaint.textToGlyphs(text, textLen, glyphs.get());
 
-    blobPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    blobPaint.setTextEncoding(kGlyphID_SkTextEncoding);
     const size_t glyphTextBytes = SkTo<uint32_t>(glyphCount) * sizeof(SkGlyphID);
     const int widthCount = blobPaint.getTextWidths(glyphs.get(), glyphTextBytes, nullptr);
     SkAssertResult(widthCount == glyphCount);
diff --git a/gm/typeface.cpp b/gm/typeface.cpp
index a7287ec..5ea0618 100644
--- a/gm/typeface.cpp
+++ b/gm/typeface.cpp
@@ -19,7 +19,7 @@
 
 static void getGlyphPositions(const SkPaint& paint, const uint16_t glyphs[],
                              int count, SkScalar x, SkScalar y, SkPoint pos[]) {
-    SkASSERT(SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding());
+    SkASSERT(kGlyphID_SkTextEncoding == (SkTextEncoding)paint.getTextEncoding());
 
     SkAutoSTMalloc<128, SkScalar> widthStorage(count);
     SkScalar* widths = widthStorage.get();
@@ -65,7 +65,7 @@
     }
 
     SkPaint glyphPaint(paint);
-    glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    glyphPaint.setTextEncoding(kGlyphID_SkTextEncoding);
 
     SkAutoSTMalloc<128, SkPoint> posStorage(glyphCount);
     SkPoint* pos = posStorage.get();
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index dfbc43c..f2cee44 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -1846,7 +1846,7 @@
 
     /** Draws text, with origin at (x, y), using clip, SkMatrix, and SkPaint paint.
 
-        text meaning depends on SkPaint::TextEncoding; by default, text is encoded as
+        text meaning depends on SkTextEncoding; by default, text is encoded as
         UTF-8.
 
         x and y meaning depends on SkPaint::Align and SkPaint vertical text; by default
@@ -1873,8 +1873,8 @@
     /** Draws null terminated string, with origin at (x, y), using clip, SkMatrix, and
         SkPaint paint.
 
-        string meaning depends on SkPaint::TextEncoding; by default, strings are encoded
-        as UTF-8. Other values of SkPaint::TextEncoding are unlikely to produce the desired
+        string meaning depends on SkTextEncoding; by default, strings are encoded
+        as UTF-8. Other values of SkTextEncoding are unlikely to produce the desired
         results, since zero bytes may be embedded in the string.
 
         x and y meaning depends on SkPaint::Align and SkPaint vertical text; by default
@@ -1901,8 +1901,8 @@
     /** Draws null terminated string, with origin at (x, y), using clip, SkMatrix, and
         SkPaint paint.
 
-        string meaning depends on SkPaint::TextEncoding; by default, strings are encoded
-        as UTF-8. Other values of SkPaint::TextEncoding are unlikely to produce the desired
+        string meaning depends on SkTextEncoding; by default, strings are encoded
+        as UTF-8. Other values of SkTextEncoding are unlikely to produce the desired
         results, since zero bytes may be embedded in the string.
 
         x and y meaning depends on SkPaint::Align and SkPaint vertical text; by default
@@ -1925,7 +1925,7 @@
         SkPaint paint. The number of entries in pos array must match the number of glyphs
         described by byteLength of text.
 
-        text meaning depends on SkPaint::TextEncoding; by default, text is encoded as
+        text meaning depends on SkTextEncoding; by default, text is encoded as
         UTF-8. pos elements meaning depends on SkPaint vertical text; by default
         glyph left side bearing and baseline are relative to SkPoint in pos array.
         Text size is affected by SkMatrix and SkPaint text size.
@@ -1949,7 +1949,7 @@
         constY, using clip, SkMatrix, and SkPaint paint. The number of entries in xpos array
         must match the number of glyphs described by byteLength of text.
 
-        text meaning depends on SkPaint::TextEncoding; by default, text is encoded as
+        text meaning depends on SkTextEncoding; by default, text is encoded as
         UTF-8. xpos elements meaning depends on SkPaint vertical text;
         by default each glyph left side bearing is positioned at an xpos element and
         its baseline is positioned at constY. Text size is affected by SkMatrix and
@@ -2002,7 +2002,7 @@
         SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text,
         and SkPaint subpixel text.
 
-        SkPaint::TextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
+        SkTextEncoding must be set to kGlyphID_SkTextEncoding.
 
         Elements of paint: anti-alias, SkBlendMode, color including alpha,
         SkColorFilter, SkPaint dither, SkDrawLooper, SkMaskFilter, SkPathEffect, SkShader, and
@@ -2025,7 +2025,7 @@
         SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text,
         and SkPaint subpixel text.
 
-        SkPaint::TextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
+        SkTextEncoding must be set to kGlyphID_SkTextEncoding.
 
         Elements of paint: SkPathEffect, SkMaskFilter, SkShader, SkColorFilter,
         SkImageFilter, and SkDrawLooper; apply to blob.
diff --git a/include/core/SkFont.h b/include/core/SkFont.h
index a16fc0c..968a866 100644
--- a/include/core/SkFont.h
+++ b/include/core/SkFont.h
@@ -246,7 +246,7 @@
         If maxGlyphCount is not sufficient to store all the glyphs, no glyphs are copied.
         The total glyph count is returned for subsequent buffer reallocation.
 
-        @param text          character storage encoded with SkPaint::TextEncoding
+        @param text          character storage encoded with SkTextEncoding
         @param byteLength    length of character storage in bytes
         @param encoding      one of: kUTF8_SkTextEncoding, kUTF16_SkTextEncoding,
                              kUTF32_SkTextEncoding, kGlyphID_SkTextEncoding
@@ -268,7 +268,7 @@
 
     /** Returns number of glyphs represented by text.
 
-        @param text          character storage encoded with SkPaint::TextEncoding
+        @param text          character storage encoded with SkTextEncoding
         @param byteLength    length of character storage in bytes
         @param encoding      one of: kUTF8_SkTextEncoding, kUTF16_SkTextEncoding,
                              kUTF32_SkTextEncoding, kGlyphID_SkTextEncoding
@@ -317,7 +317,7 @@
         The advance is the normal distance to move before drawing additional text.
         Returns the bounding box of text if bounds is not nullptr.
 
-        @param text        character storage encoded with SkPaint::TextEncoding
+        @param text        character storage encoded with SkTextEncoding
         @param byteLength  length of character storage in bytes
         @param encoding    one of: kUTF8_SkTextEncoding, kUTF16_SkTextEncoding,
                            kUTF32_SkTextEncoding, kGlyphID_SkTextEncoding
diff --git a/include/core/SkFontTypes.h b/include/core/SkFontTypes.h
index 3325146..39250e9 100644
--- a/include/core/SkFontTypes.h
+++ b/include/core/SkFontTypes.h
@@ -12,7 +12,9 @@
 #include "SkTypeface.h"
 
 // TODO: add to clients, and then remove from here.
+#ifndef SK_SUPPORT_LEGACY_TEXTENCODINGENUM
 #define SK_SUPPORT_LEGACY_TEXTENCODINGENUM
+#endif
 
 #ifdef SK_SUPPORT_LEGACY_TEXTENCODINGENUM
 enum SkTextEncoding : uint8_t {
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index 74e706a..7ebb85e 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -875,6 +875,7 @@
     */
     void setTextSkewX(SkScalar skewX);
 
+#ifdef SK_SUPPORT_LEGACY_TEXTENCODINGENUM
     /** \enum SkPaint::TextEncoding
         TextEncoding determines whether text specifies character codes and their encoded
         size, or glyph indices. Characters are encoded as specified by the Unicode standard.
@@ -918,11 +919,17 @@
         @param encoding  one of: kUTF8_TextEncoding, kUTF16_TextEncoding, kUTF32_TextEncoding, or
                          kGlyphID_TextEncoding
     */
-    void setTextEncoding(TextEncoding encoding);
-    // Experimental
-    void setTextEncoding(SkTextEncoding encoding) {
-        this->setTextEncoding((TextEncoding)encoding);
+    void setTextEncoding(TextEncoding encoding) {
+        this->setTextEncoding((SkTextEncoding)encoding);
     }
+#else
+    // Experimental
+    SkTextEncoding getTextEncoding() const {
+        return (SkTextEncoding)fBitfields.fTextEncoding;
+    }
+#endif
+    // Experimental
+    void setTextEncoding(SkTextEncoding encoding);
 
 #ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
 
@@ -982,7 +989,7 @@
 
     /** Converts text into glyph indices.
         Returns the number of glyph indices represented by text.
-        SkPaint::TextEncoding specifies how text represents characters or glyphs.
+        SkTextEncoding specifies how text represents characters or glyphs.
         glyphs may be nullptr, to compute the glyph count.
 
         Does not check text for valid character codes or valid glyph indices.
@@ -990,10 +997,10 @@
         If byteLength equals zero, returns zero.
         If byteLength includes a partial character, the partial character is ignored.
 
-        If SkPaint::TextEncoding is kUTF8_TextEncoding and
+        If SkTextEncoding is kUTF8_SkTextEncoding and
         text contains an invalid UTF-8 sequence, zero is returned.
 
-        @param text        character storage encoded with SkPaint::TextEncoding
+        @param text        character storage encoded with SkTextEncoding
         @param byteLength  length of character storage in bytes
         @param glyphs      storage for glyph indices; may be nullptr
         @return            number of glyphs represented by text of length byteLength
@@ -1005,7 +1012,7 @@
         Returns false if any characters in text are not supported in
         SkTypeface.
 
-        If SkPaint::TextEncoding is kGlyphID_TextEncoding,
+        If SkTextEncoding is kGlyphID_SkTextEncoding,
         returns true if all glyph indices in text are non-zero;
         does not check to see if text contains valid glyph indices for SkTypeface.
 
@@ -1021,7 +1028,7 @@
     /** Converts glyphs into text if possible.
         Glyph values without direct Unicode equivalents are mapped to zero.
         Uses the SkTypeface, but is unaffected
-        by SkPaint::TextEncoding; the text values returned are equivalent to kUTF32_TextEncoding.
+        by SkTextEncoding; the text values returned are equivalent to kUTF32_SkTextEncoding.
 
         Only supported on platforms that use FreeType as the font engine.
 
@@ -1033,10 +1040,10 @@
 
 #ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
     /** Returns the number of glyphs in text.
-        Uses SkPaint::TextEncoding to count the glyphs.
+        Uses SkTextEncoding to count the glyphs.
         Returns the same result as textToGlyphs().
 
-        @param text        character storage encoded with SkPaint::TextEncoding
+        @param text        character storage encoded with SkTextEncoding
         @param byteLength  length of character storage in bytes
         @return            number of glyphs represented by text of length byteLength
     */
@@ -1044,7 +1051,7 @@
 
     /** Returns the advance width of text.
         The advance is the normal distance to move before drawing additional text.
-        Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
+        Uses SkTextEncoding to decode text, SkTypeface to get the font metrics,
         and text size, text scale x, text skew x, stroke width, and
         SkPathEffect to scale the metrics and bounds.
         Returns the bounding box of text if bounds is not nullptr.
@@ -1059,7 +1066,7 @@
 
     /** Returns the advance width of text.
         The advance is the normal distance to move before drawing additional text.
-        Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
+        Uses SkTextEncoding to decode text, SkTypeface to get the font metrics,
         and text size to scale the metrics.
         Does not scale the advance or bounds by fake bold or SkPathEffect.
 
@@ -1076,7 +1083,7 @@
         The text fragment fits if its advance width is less than or equal to maxWidth.
         Measures only while the advance is less than or equal to maxWidth.
         Returns the advance or the text fragment in measuredWidth if it not nullptr.
-        Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
+        Uses SkTextEncoding to decode text, SkTypeface to get the font metrics,
         and text size to scale the metrics.
         Does not scale the advance or bounds by fake bold or SkPathEffect.
 
@@ -1095,7 +1102,7 @@
         Both widths and bounds may be nullptr.
         If widths is not nullptr, widths must be an array of glyph count entries.
         if bounds is not nullptr, bounds must be an array of glyph count entries.
-        Uses SkPaint::TextEncoding to decode text, SkTypeface to get the font metrics,
+        Uses SkTextEncoding to decode text, SkTypeface to get the font metrics,
         and text size to scale the widths and bounds.
         Does not scale the advance by fake bold or SkPathEffect.
         Does include fake bold and SkPathEffect in the bounds.
@@ -1110,7 +1117,7 @@
                       SkRect bounds[] = nullptr) const;
 
     /** Returns the geometry as SkPath equivalent to the drawn text.
-        Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
+        Uses SkTextEncoding to decode text, SkTypeface to get the glyph paths,
         and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
         All of the glyph paths are stored in path.
         Uses x, y, to position path.
@@ -1125,7 +1132,7 @@
                      SkPath* path) const;
 
     /** Returns the geometry as SkPath equivalent to the drawn text.
-        Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
+        Uses SkTextEncoding to decode text, SkTypeface to get the glyph paths,
         and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
         All of the glyph paths are stored in path.
         Uses pos array to position path.
@@ -1149,7 +1156,7 @@
         bounds describes a pair of lines parallel to the text advance.
         The return count is zero or a multiple of two, and is at most twice the number of glyphs in
         the string.
-        Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
+        Uses SkTextEncoding to decode text, SkTypeface to get the glyph paths,
         and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
         Uses x, y to position intervals.
 
@@ -1172,7 +1179,7 @@
         bounds describes a pair of lines parallel to the text advance.
         The return count is zero or a multiple of two, and is at most twice the number of glyphs in
         the string.
-        Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
+        Uses SkTextEncoding to decode text, SkTypeface to get the glyph paths,
         and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
         Uses pos array to position intervals.
 
@@ -1194,7 +1201,7 @@
         bounds describes a pair of lines parallel to the text advance.
         The return count is zero or a multiple of two, and is at most twice the number of glyphs in
         the string.
-        Uses SkPaint::TextEncoding to decode text, SkTypeface to get the glyph paths,
+        Uses SkTextEncoding to decode text, SkTypeface to get the glyph paths,
         and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
         Uses xpos array, constY to position intervals.
 
@@ -1222,7 +1229,7 @@
         and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
         Uses run array to position intervals.
 
-        SkPaint::TextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
+        SkTextEncoding must be set to SkPaint::kGlyphID_TextEncoding.
 
         Pass nullptr for intervals to determine the size of the interval array.
 
diff --git a/include/core/SkTextBlob.h b/include/core/SkTextBlob.h
index 5c07d43..31d3f17 100644
--- a/include/core/SkTextBlob.h
+++ b/include/core/SkTextBlob.h
@@ -61,9 +61,9 @@
         @return            SkTextBlob constructed from one run
     */
     static sk_sp<SkTextBlob> MakeFromText(const void* text, size_t byteLength, const SkFont& font,
-                                      SkPaint::TextEncoding encoding = SkPaint::kUTF8_TextEncoding);
+                                      SkTextEncoding encoding = kUTF8_SkTextEncoding);
 
-    /** Creates SkTextBlob with a single run. string meaning depends on SkPaint::TextEncoding;
+    /** Creates SkTextBlob with a single run. string meaning depends on SkTextEncoding;
         by default, string is encoded as UTF-8.
 
         font contains attributes used to define the run text.
@@ -73,7 +73,7 @@
         @return        SkTextBlob constructed from one run
     */
     static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkFont& font,
-                                    SkPaint::TextEncoding encoding = SkPaint::kUTF8_TextEncoding) {
+                                    SkTextEncoding encoding = kUTF8_SkTextEncoding) {
         if (!string) {
             return nullptr;
         }
diff --git a/modules/skottie/src/SkottieAdapter.cpp b/modules/skottie/src/SkottieAdapter.cpp
index d449856..30c4ed5 100644
--- a/modules/skottie/src/SkottieAdapter.cpp
+++ b/modules/skottie/src/SkottieAdapter.cpp
@@ -215,7 +215,7 @@
     font.setHinting(kNo_SkFontHinting);
     font.setSubpixelText(true);
     font.setAntiAlias(true);
-    font.setTextEncoding(SkPaint::kUTF8_TextEncoding);
+    font.setTextEncoding(kUTF8_SkTextEncoding);
 
     const auto align_fract = [](SkTextUtils::Align align) {
         switch (align) {
diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp
index 5eb7ade..50239d6 100644
--- a/samplecode/SampleAll.cpp
+++ b/samplecode/SampleAll.cpp
@@ -257,7 +257,7 @@
         canvas->drawText(utf8, sizeof(utf8) - 1, x, y, paint);
 
         canvas->translate(0, SkIntToScalar(60));
-        paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
+        paint.setTextEncoding(kUTF8_SkTextEncoding);
         canvas->restore();
     }
 
diff --git a/samplecode/SampleChineseFling.cpp b/samplecode/SampleChineseFling.cpp
index 769cc1e..b8110f3 100644
--- a/samplecode/SampleChineseFling.cpp
+++ b/samplecode/SampleChineseFling.cpp
@@ -27,7 +27,7 @@
   paint->setColor(0xDE000000);
   paint->setTypeface(typeface);
   paint->setTextSize(kTextSize);
-  paint->setTextEncoding(SkPaint::kUTF32_TextEncoding);
+  paint->setTextEncoding(kUTF32_SkTextEncoding);
 }
 
 static sk_sp<SkTypeface> chinese_typeface() {
@@ -167,7 +167,7 @@
         paint.setColor(0xDE000000);
         paint.setTypeface(fTypeface);
         paint.setTextSize(11);
-        paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
+        paint.setTextEncoding(kUTF32_SkTextEncoding);
 
         if (afterFirstFrame) {
 #if SK_SUPPORT_GPU
@@ -220,7 +220,7 @@
         paint.setColor(0xDE000000);
         paint.setTypeface(fTypeface);
         paint.setTextSize(11);
-        paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
+        paint.setTextEncoding(kUTF32_SkTextEncoding);
 
         paint.getFontMetrics(&fMetrics);
 
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index f3fc02f..4bb6fcc 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -175,8 +175,8 @@
     return static_cast<SkPaint::Join>(R(SkPaint::kDefault_Join+1));
 }
 
-static SkPaint::TextEncoding make_paint_text_encoding() {
-    return static_cast<SkPaint::TextEncoding>(R(SkPaint::kGlyphID_TextEncoding+1));
+static SkTextEncoding make_paint_text_encoding() {
+    return static_cast<SkTextEncoding>(R((int)kGlyphID_SkTextEncoding+1));
 }
 
 static SkBlurStyle make_blur_style() {
diff --git a/samplecode/SampleFontCache.cpp b/samplecode/SampleFontCache.cpp
index 2ba4b08..f5952c4 100644
--- a/samplecode/SampleFontCache.cpp
+++ b/samplecode/SampleFontCache.cpp
@@ -17,7 +17,7 @@
     SkRandom rand;
 
     paint.setAntiAlias(true);
-    paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
+    paint.setTextEncoding(kUTF16_SkTextEncoding);
     for (int j = 0; j < SK_ARRAY_COUNT(text); j++)
         text[j] = (uint16_t)((rand.nextU() & 0xFF) + 32);
 
@@ -36,7 +36,7 @@
     SkRandom rand;
 
     paint.setAntiAlias(true);
-    paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
+    paint.setTextEncoding(kUTF16_SkTextEncoding);
     for (int j = 0; j < SK_ARRAY_COUNT(text); j++)
         text[j] = (uint16_t)((rand.nextU() & 0xFF) + 32);
 
diff --git a/src/atlastext/SkAtlasTextTarget.cpp b/src/atlastext/SkAtlasTextTarget.cpp
index a61d647..68b19ed 100644
--- a/src/atlastext/SkAtlasTextTarget.cpp
+++ b/src/atlastext/SkAtlasTextTarget.cpp
@@ -151,7 +151,7 @@
     paint.setTypeface(font.refTypeface());
     paint.setTextSize(font.size());
     paint.setStyle(SkPaint::kFill_Style);
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    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.
diff --git a/src/core/SkFindAndPlaceGlyph.h b/src/core/SkFindAndPlaceGlyph.h
index 76fd9ba..8aa3da9 100644
--- a/src/core/SkFindAndPlaceGlyph.h
+++ b/src/core/SkFindAndPlaceGlyph.h
@@ -37,7 +37,7 @@
     // This routine handles all of them using inline polymorphic variable (no heap allocation).
     template<typename ProcessOneGlyph>
     static void ProcessPosText(
-        SkPaint::TextEncoding, const char text[], size_t byteLength,
+        SkTextEncoding, const char text[], size_t byteLength,
         SkPoint offset, const SkMatrix& matrix, const SkScalar pos[], int scalarsPerPosition,
         SkGlyphCache* cache, ProcessOneGlyph&& processOneGlyph);
 
@@ -205,15 +205,15 @@
     };
 
     static GlyphFinderInterface* getGlyphFinder(
-        SkArenaAlloc* arena, SkPaint::TextEncoding encoding, SkGlyphCache* cache) {
+        SkArenaAlloc* arena, SkTextEncoding encoding, SkGlyphCache* cache) {
         switch(encoding) {
-            case SkPaint::kUTF8_TextEncoding:
+            case kUTF8_SkTextEncoding:
                 return arena->make<Utf8GlyphFinder>(cache);
-            case SkPaint::kUTF16_TextEncoding:
+            case kUTF16_SkTextEncoding:
                 return arena->make<Utf16GlyphFinder>(cache);
-            case SkPaint::kUTF32_TextEncoding:
+            case kUTF32_SkTextEncoding:
                 return arena->make<Utf32GlyphFinder>(cache);
-            case SkPaint::kGlyphID_TextEncoding:
+            case kGlyphID_SkTextEncoding:
                 return arena->make<GlyphIdGlyphFinder>(cache);
         }
         SK_ABORT("Should not get here.");
@@ -428,7 +428,7 @@
 
 template<typename ProcessOneGlyph>
 inline void SkFindAndPlaceGlyph::ProcessPosText(
-    SkPaint::TextEncoding textEncoding, const char text[], size_t byteLength,
+    SkTextEncoding textEncoding, const char text[], size_t byteLength,
     SkPoint offset, const SkMatrix& matrix, const SkScalar pos[], int scalarsPerPosition,
     SkGlyphCache* cache, ProcessOneGlyph&& processOneGlyph) {
 
@@ -436,7 +436,7 @@
     uint32_t mtype = matrix.getType();
 
     // Specialized code for handling the most common case for blink.
-    if (textEncoding == SkPaint::kGlyphID_TextEncoding
+    if (textEncoding == kGlyphID_SkTextEncoding
         && axisAlignment == kX_SkAxisAlignment
         && cache->isSubpixel()
         && mtype <= SkMatrix::kTranslate_Mask)
diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp
index 5415719..1e487e3 100644
--- a/src/core/SkGlyphRun.cpp
+++ b/src/core/SkGlyphRun.cpp
@@ -17,11 +17,11 @@
 #include "SkUtils.h"
 
 namespace {
-static SkTypeface::Encoding convert_encoding(SkPaint::TextEncoding encoding) {
+static SkTypeface::Encoding convert_encoding(SkTextEncoding encoding) {
     switch (encoding) {
-        case  SkPaint::kUTF8_TextEncoding: return SkTypeface::kUTF8_Encoding;
-        case SkPaint::kUTF16_TextEncoding: return SkTypeface::kUTF16_Encoding;
-        case SkPaint::kUTF32_TextEncoding: return SkTypeface::kUTF32_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;
     }
 }
@@ -309,8 +309,8 @@
 
 SkSpan<const SkGlyphID> SkGlyphRunBuilder::textToGlyphIDs(
         const SkPaint& paint, const void* bytes, size_t byteLength) {
-    auto encoding = paint.getTextEncoding();
-    if (encoding != SkPaint::kGlyphID_TextEncoding) {
+    SkTextEncoding encoding = (SkTextEncoding)paint.getTextEncoding();
+    if (encoding != kGlyphID_SkTextEncoding) {
         auto tfEncoding = convert_encoding(encoding);
         int utfSize = SkUTFN_CountUnichars(tfEncoding, bytes, byteLength);
         if (utfSize > 0) {
diff --git a/src/core/SkOverdrawCanvas.cpp b/src/core/SkOverdrawCanvas.cpp
index 9c1f38f..0d3596e 100644
--- a/src/core/SkOverdrawCanvas.cpp
+++ b/src/core/SkOverdrawCanvas.cpp
@@ -75,7 +75,8 @@
     auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
                                 SkFont::LEGACY_ExtractFromPaint(paint), paint, props,
                                 SkScalerContextFlags::kNone, this->getTotalMatrix());
-    SkFindAndPlaceGlyph::ProcessPosText(paint.getTextEncoding(), (const char*) text, byteLength,
+    SkFindAndPlaceGlyph::ProcessPosText((SkTextEncoding)paint.getTextEncoding(),
+                                        (const char*)text, byteLength,
                                         SkPoint::Make(0, 0), SkMatrix(), (const SkScalar*) pos, 2,
                                         cache.get(), processBounds);
 }
@@ -109,17 +110,17 @@
                                          const SkPaint& paint) {
     const char* stop = (const char*)text + byteLength;
     CountTextProc proc = nullptr;
-    switch (paint.getTextEncoding()) {
-        case SkPaint::kUTF8_TextEncoding:
+    switch ((SkTextEncoding)paint.getTextEncoding()) {
+        case kUTF8_SkTextEncoding:
             proc = count_utf8;
             break;
-        case SkPaint::kUTF16_TextEncoding:
+        case kUTF16_SkTextEncoding:
             proc = count_utf16;
             break;
-        case SkPaint::kUTF32_TextEncoding:
+        case kUTF32_SkTextEncoding:
             proc = return_4;
             break;
-        case SkPaint::kGlyphID_TextEncoding:
+        case kGlyphID_SkTextEncoding:
             proc = return_2;
             break;
     }
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index e7ed230..2b39c38 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -58,7 +58,7 @@
     fBitfields.fCapType      = kDefault_Cap;
     fBitfields.fJoinType     = kDefault_Join;
     fBitfields.fStyle        = kFill_Style;
-    fBitfields.fTextEncoding = kUTF8_TextEncoding;
+    fBitfields.fTextEncoding = static_cast<unsigned>(kUTF8_SkTextEncoding);
     fBitfields.fHinting      = static_cast<unsigned>(SkPaintDefaults_Hinting);
 }
 
@@ -326,9 +326,9 @@
     fTextSkewX = skewX;
 }
 
-void SkPaint::setTextEncoding(TextEncoding encoding) {
-    if ((unsigned)encoding <= kGlyphID_TextEncoding) {
-        fBitfields.fTextEncoding = encoding;
+void SkPaint::setTextEncoding(SkTextEncoding encoding) {
+    if ((unsigned)encoding <= (unsigned)kGlyphID_SkTextEncoding) {
+        fBitfields.fTextEncoding = (unsigned)encoding;
     } else {
 #ifdef SK_REPORT_API_RANGE_CHECK
         SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding);
@@ -445,7 +445,7 @@
     buffer.writeUInt(pack_paint_flags(paint.getFlags(), static_cast<unsigned>(paint.getHinting()),
                                       paint.getFilterQuality(), flatFlags));
     buffer.writeUInt(pack_4(paint.getStrokeCap(), paint.getStrokeJoin(),
-                            (paint.getStyle() << 4) | paint.getTextEncoding(),
+                            (paint.getStyle() << 4) | (unsigned)paint.getTextEncoding(),
                             paint.fBlendMode));
 
     buffer.writeTypeface(tf);
@@ -483,7 +483,7 @@
     paint->setStrokeCap(safe.checkLE((tmp >> 24) & 0xFF, SkPaint::kLast_Cap));
     paint->setStrokeJoin(safe.checkLE((tmp >> 16) & 0xFF, SkPaint::kLast_Join));
     paint->setStyle(safe.checkLE((tmp >> 12) & 0xF, SkPaint::kStrokeAndFill_Style));
-    paint->setTextEncoding(safe.checkLE((tmp >> 8) & 0xF, SkPaint::kGlyphID_TextEncoding));
+    paint->setTextEncoding(safe.checkLE((tmp >> 8) & 0xF, kGlyphID_SkTextEncoding));
     paint->setBlendMode(safe.checkLE(tmp & 0xFF, SkBlendMode::kLastMode));
 
     if (flatFlags & kHasTypeface_FlatFlag) {
diff --git a/src/core/SkPaintPriv.cpp b/src/core/SkPaintPriv.cpp
index 8718cf1..12e49bb 100644
--- a/src/core/SkPaintPriv.cpp
+++ b/src/core/SkPaintPriv.cpp
@@ -90,12 +90,12 @@
         || !p.getShader() || !as_SB(p.getShader())->isConstant();
 }
 
-int SkPaintPriv::ValidCountText(const void* text, size_t length, SkPaint::TextEncoding encoding) {
+int SkPaintPriv::ValidCountText(const void* text, size_t length, SkTextEncoding encoding) {
     switch (encoding) {
-        case SkPaint::kUTF8_TextEncoding: return SkUTF::CountUTF8((const char*)text, length);
-        case SkPaint::kUTF16_TextEncoding: return SkUTF::CountUTF16((const uint16_t*)text, length);
-        case SkPaint::kUTF32_TextEncoding: return SkUTF::CountUTF32((const int32_t*)text, length);
-        case SkPaint::kGlyphID_TextEncoding:
+        case kUTF8_SkTextEncoding: return SkUTF::CountUTF8((const char*)text, length);
+        case kUTF16_SkTextEncoding: return SkUTF::CountUTF16((const uint16_t*)text, length);
+        case kUTF32_SkTextEncoding: return SkUTF::CountUTF32((const int32_t*)text, length);
+        case kGlyphID_SkTextEncoding:
             if (!SkIsAlign2(intptr_t(text)) || !SkIsAlign2(length)) {
                 return -1;
             }
diff --git a/src/core/SkPaintPriv.h b/src/core/SkPaintPriv.h
index 9181e35..d3a0c35 100644
--- a/src/core/SkPaintPriv.h
+++ b/src/core/SkPaintPriv.h
@@ -69,7 +69,7 @@
     static bool ShouldDither(const SkPaint&, SkColorType);
 
     // returns -1 if buffer is invalid for specified encoding
-    static int ValidCountText(const void* text, size_t length, SkPaint::TextEncoding);
+    static int ValidCountText(const void* text, size_t length, SkTextEncoding);
 
     static SkTypeface* GetTypefaceOrDefault(const SkPaint& paint) {
         return paint.getTypeface() ? paint.getTypeface() : SkTypeface::GetDefaultTypeface();
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index 260ea90..c204b5d 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -77,7 +77,8 @@
                 if (fByteLength == 0) {
                     fCount = 0;
                 } else {
-                    fCount = SkPaintPriv::ValidCountText(fText, fByteLength, paint->getTextEncoding());
+                    fCount = SkPaintPriv::ValidCountText(fText, fByteLength,
+                                                         (SkTextEncoding)paint->getTextEncoding());
                     reader->validate(fCount > 0);
                 }
             }
diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp
index eadb07c..4fa9f69 100644
--- a/src/core/SkTextBlob.cpp
+++ b/src/core/SkTextBlob.cpp
@@ -31,7 +31,7 @@
         , fFlags(paint.getFlags() & kFlagsMask) { }
 
 void SkRunFont::applyToPaint(SkPaint* paint) const {
-    paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    paint->setTextEncoding(kGlyphID_SkTextEncoding);
     paint->setTypeface(fTypeface);
     paint->setTextSize(fSize);
     paint->setTextScaleX(fScaleX);
@@ -478,7 +478,9 @@
                                       SkTextBlob::GlyphPositioning positioning,
                                       int count, int textSize, SkPoint offset,
                                       const SkRect* bounds) {
-    if (count <= 0 || textSize < 0 || font.getTextEncoding() != SkPaint::kGlyphID_TextEncoding) {
+    if (count <= 0 || textSize < 0 ||
+        (SkTextEncoding)font.getTextEncoding() != kGlyphID_SkTextEncoding)
+    {
         fCurrentRunBuffer = { nullptr, nullptr, nullptr, nullptr };
         return;
     }
@@ -530,7 +532,7 @@
                                                                 const SkRect* bounds) {
     SkPaint legacyPaint;
     font.LEGACY_applyToPaint(&legacyPaint);
-    legacyPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    legacyPaint.setTextEncoding(kGlyphID_SkTextEncoding);
 
     return this->allocRunText(legacyPaint, count, x, y, 0, SkString(), bounds);
 }
@@ -540,7 +542,7 @@
                                                                     const SkRect* bounds) {
     SkPaint legacyPaint;
     font.LEGACY_applyToPaint(&legacyPaint);
-    legacyPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    legacyPaint.setTextEncoding(kGlyphID_SkTextEncoding);
 
     return this->allocRunTextPosH(legacyPaint, count, y, 0, SkString(), bounds);
 }
@@ -549,7 +551,7 @@
                                                                    const SkRect* bounds) {
     SkPaint legacyPaint;
     font.LEGACY_applyToPaint(&legacyPaint);
-    legacyPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    legacyPaint.setTextEncoding(kGlyphID_SkTextEncoding);
 
     return this->allocRunTextPos(legacyPaint, count, 0, SkString(), bounds);
 }
@@ -756,7 +758,7 @@
 }
 
 sk_sp<SkTextBlob> SkTextBlob::MakeFromText(const void* text, size_t byteLength, const SkFont& font,
-                                           SkPaint::TextEncoding encoding) {
+                                           SkTextEncoding encoding) {
     SkPaint legacyPaint;
     font.LEGACY_applyToPaint(&legacyPaint);
     legacyPaint.setTextEncoding(encoding);
diff --git a/src/core/SkTextBlobPriv.h b/src/core/SkTextBlobPriv.h
index 149e652..582c301 100644
--- a/src/core/SkTextBlobPriv.h
+++ b/src/core/SkTextBlobPriv.h
@@ -237,7 +237,7 @@
         , fMiterLimit{basePaint.fMiterLimit}
         , fBlendMode{basePaint.fBlendMode}
         , fBitfieldsUInt{(basePaint.fBitfieldsUInt & ~SkRunFont::kFlagsMask) | runFont.fFlags} {
-    fBitfields.fTextEncoding = kGlyphID_TextEncoding;
+    fBitfields.fTextEncoding = (unsigned)kGlyphID_SkTextEncoding;
     fBitfields.fHinting = runFont.fHinting;
 }
 
diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp
index ce22a66..c9c60cc 100644
--- a/src/effects/SkLayerDrawLooper.cpp
+++ b/src/effects/SkLayerDrawLooper.cpp
@@ -79,7 +79,7 @@
                     sk_srgb_singleton());
 
     BitFlags bits = info.fPaintBits;
-    SkPaint::TextEncoding encoding = dst->getTextEncoding();
+    SkTextEncoding encoding = (SkTextEncoding)dst->getTextEncoding();
 
     if (0 == bits) {
         return;
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 41503af..d5fff5d 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -1033,9 +1033,8 @@
 
 void SkPDFDevice::drawGlyphRunAsPath(const SkGlyphRun& glyphRun, SkPoint offset) {
     SkPaint paint{glyphRun.paint()};
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    paint.setTextEncoding(kGlyphID_SkTextEncoding);
     SkPath path;
-    SkASSERT(paint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding);
 
     paint.getPosTextPath(glyphRun.glyphsIDs().data(),
                          glyphRun.glyphsIDs().size() * sizeof(SkGlyphID),
@@ -1047,7 +1046,7 @@
     SkPaint transparent;
     transparent.setTypeface(paint.getTypeface() ? paint.refTypeface()
                                                 : SkTypeface::MakeDefault());
-    transparent.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    transparent.setTextEncoding(kGlyphID_SkTextEncoding);
     transparent.setColor(SK_ColorTRANSPARENT);
     transparent.setTextSize(paint.getTextSize());
     transparent.setTextScaleX(paint.getTextScaleX());
@@ -1087,7 +1086,7 @@
     const SkGlyphID* glyphs = glyphRun.glyphsIDs().data();
     uint32_t glyphCount = SkToU32(glyphRun.glyphsIDs().size());
     SkPaint srcPaint{glyphRun.paint()};
-    srcPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    srcPaint.setTextEncoding(kGlyphID_SkTextEncoding);
 
     if (!glyphCount || !glyphs || srcPaint.getTextSize() <= 0 || this->hasEmptyClip()) {
         return;
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 6e3425e..b6cb6c4 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -399,7 +399,7 @@
 
             SkPaint paint;
             paint.setTypeface(face);
-            paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
+            paint.setTextEncoding(kUTF32_SkTextEncoding);
 
             uint16_t glyphID;
             paint.textToGlyphs(&character, sizeof(character), &glyphID);
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 074493c..4ff6c6e 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -869,7 +869,7 @@
 }
 
 static int lpaint_getTextEncoding(lua_State* L) {
-    SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getTextEncoding());
+    SkLua(L).pushU32((unsigned)get_obj<SkPaint>(L, 1)->getTextEncoding());
     return 1;
 }
 
diff --git a/src/utils/SkLuaCanvas.cpp b/src/utils/SkLuaCanvas.cpp
index a9b3c0e..7f279ca 100644
--- a/src/utils/SkLuaCanvas.cpp
+++ b/src/utils/SkLuaCanvas.cpp
@@ -37,7 +37,12 @@
         lua_settop(L, -1);
     }
 
-    void pushEncodedText(SkPaint::TextEncoding, const void*, size_t);
+#ifdef SK_SUPPORT_LEGACY_TEXTENCODINGENUM
+    void pushEncodedText(SkPaint::TextEncoding enc, const void* text, size_t length) {
+        this->pushEncodedText((SkTextEncoding)enc, text, length);
+    }
+#endif
+    void pushEncodedText(SkTextEncoding, const void*, size_t);
 
 private:
     typedef SkLua INHERITED;
@@ -48,20 +53,19 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-void AutoCallLua::pushEncodedText(SkPaint::TextEncoding enc, const void* text,
-                                  size_t length) {
+void AutoCallLua::pushEncodedText(SkTextEncoding enc, const void* text, size_t length) {
     switch (enc) {
-        case SkPaint::kUTF8_TextEncoding:
+        case kUTF8_SkTextEncoding:
             this->pushString((const char*)text, length, "text");
             break;
-        case SkPaint::kUTF16_TextEncoding:
+        case kUTF16_SkTextEncoding:
             this->pushString(SkStringFromUTF16((const uint16_t*)text, length), "text");
             break;
-        case SkPaint::kGlyphID_TextEncoding:
+        case kGlyphID_SkTextEncoding:
             this->pushArrayU16((const uint16_t*)text, SkToInt(length >> 1),
                                "glyphs");
             break;
-        case SkPaint::kUTF32_TextEncoding:
+        case kUTF32_SkTextEncoding:
             break;
     }
 }
diff --git a/src/utils/SkTextUtils.cpp b/src/utils/SkTextUtils.cpp
index cc1b48e..f33058e 100644
--- a/src/utils/SkTextUtils.cpp
+++ b/src/utils/SkTextUtils.cpp
@@ -18,11 +18,11 @@
     SkAutoSTArray<32, uint16_t> glyphStorage;
     const uint16_t* glyphs;
 
-    if (paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding) {
+    if ((SkTextEncoding)paint.getTextEncoding() != kGlyphID_SkTextEncoding) {
         glyphStorage.reset(count);
         paint.textToGlyphs(text, size, glyphStorage.get());
         glyphs = glyphStorage.get();
-        paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+        paint.setTextEncoding(kGlyphID_SkTextEncoding);
     } else {
         glyphs = static_cast<const uint16_t*>(text);
     }
diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp
index b067c4f..63e7ca6 100644
--- a/src/xps/SkXPSDevice.cpp
+++ b/src/xps/SkXPSDevice.cpp
@@ -1975,11 +1975,11 @@
     return S_OK;
 }
 
-static int num_glyph_guess(SkPaint::TextEncoding encoding, const void* text, size_t byteLength) {
-    static_assert((int)SkTypeface::kUTF8_Encoding  == (int)SkPaint::kUTF8_TextEncoding,  "");
-    static_assert((int)SkTypeface::kUTF16_Encoding == (int)SkPaint::kUTF16_TextEncoding, "");
-    static_assert((int)SkTypeface::kUTF32_Encoding == (int)SkPaint::kUTF32_TextEncoding, "");
-    if (encoding == SkPaint::kGlyphID_TextEncoding) {
+static int num_glyph_guess(SkTextEncoding encoding, const void* text, size_t byteLength) {
+    static_assert((int)SkTypeface::kUTF8_Encoding  == (int)kUTF8_SkTextEncoding,  "");
+    static_assert((int)SkTypeface::kUTF16_Encoding == (int)kUTF16_SkTextEncoding, "");
+    static_assert((int)SkTypeface::kUTF32_Encoding == (int)kUTF32_SkTextEncoding, "");
+    if (encoding == kGlyphID_SkTextEncoding) {
         return SkToInt(byteLength / 2);
     }
     return SkUTFN_CountUnichars((SkTypeface::Encoding)encoding, text, byteLength);
diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp
index 39ebcc7..e4da0a0 100644
--- a/tests/FontHostTest.cpp
+++ b/tests/FontHostTest.cpp
@@ -96,7 +96,7 @@
 
         SkPaint paint;
         paint.setTypeface(face);
-        paint.setTextEncoding((SkPaint::TextEncoding)test.typefaceEncoding);
+        paint.setTextEncoding((SkTextEncoding)test.typefaceEncoding);
         paint.textToGlyphs(test.chars, test.charsByteLength, paintGlyphIds);
 
         face->charsToGlyphs(test.chars, test.typefaceEncoding, faceGlyphIds, test.charCount);
@@ -159,7 +159,7 @@
     uint16_t g;
     SkPaint paint;
     paint.setTypeface(MakeResourceAsTypeface("fonts/SpiderSymbol.ttf"));
-    paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
+    paint.setTextEncoding(kUTF32_SkTextEncoding);
     paint.textToGlyphs(&c, 4, &g);
 
     if (!paint.getTypeface()) {
diff --git a/tests/GlyphRunTest.cpp b/tests/GlyphRunTest.cpp
index f92b113..da368df 100644
--- a/tests/GlyphRunTest.cpp
+++ b/tests/GlyphRunTest.cpp
@@ -46,7 +46,7 @@
     uint16_t count = SK_ARRAY_COUNT(glyphs);
 
     SkPaint paint;
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    paint.setTextEncoding(kGlyphID_SkTextEncoding);
 
     SkGlyphRunBuilder builder;
     builder.drawText(paint, glyphs, count, SkPoint::Make(0, 0));
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index 23aebb9..91e64e0 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -164,7 +164,7 @@
     sk_sp<SkDocument> doc(SkPDF::MakeDocument(&outStream));
     SkCanvas* canvas = doc->beginPage(100.0f, 100.0f);
     SkPaint paint;
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    paint.setTextEncoding(kGlyphID_SkTextEncoding);
 
     uint16_t glyphID = 65000;
     canvas->drawText(&glyphID, 2, 0, 0, paint);
@@ -497,7 +497,7 @@
 
 DEF_TEST(SkPDF_Clusterator, reporter) {
     SkPaint paint;
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    paint.setTextEncoding(kGlyphID_SkTextEncoding);
     {
         constexpr unsigned len = 11;
         const uint32_t clusters[len] = { 3, 2, 2, 1, 0, 4, 4, 7, 6, 6, 5 };
diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp
index 15c0aed..e33f91d 100644
--- a/tests/PaintTest.cpp
+++ b/tests/PaintTest.cpp
@@ -48,8 +48,8 @@
 }
 
 static SkTypeface::Encoding paint2encoding(const SkPaint& paint) {
-    SkPaint::TextEncoding enc = paint.getTextEncoding();
-    SkASSERT(SkPaint::kGlyphID_TextEncoding != enc);
+    SkTextEncoding enc = (SkTextEncoding)paint.getTextEncoding();
+    SkASSERT(kGlyphID_SkTextEncoding != enc);
     return (SkTypeface::Encoding)enc;
 }
 
@@ -74,11 +74,11 @@
 
     static const struct {
         size_t (*fSeedTextProc)(const SkUnichar[], void* dst, int count);
-        SkPaint::TextEncoding   fEncoding;
+        SkTextEncoding   fEncoding;
     } gRec[] = {
-        { uni_to_utf8,  SkPaint::kUTF8_TextEncoding },
-        { uni_to_utf16, SkPaint::kUTF16_TextEncoding },
-        { uni_to_utf32, SkPaint::kUTF32_TextEncoding },
+        { uni_to_utf8,  kUTF8_SkTextEncoding },
+        { uni_to_utf16, kUTF16_SkTextEncoding },
+        { uni_to_utf32, kUTF32_SkTextEncoding },
     };
 
     SkRandom rand;
@@ -225,11 +225,11 @@
         SkPaint::kRound_Join,
         SkPaint::kBevel_Join,
     };
-    const SkPaint::TextEncoding encodings[] = {
-        SkPaint::kUTF8_TextEncoding,
-        SkPaint::kUTF16_TextEncoding,
-        SkPaint::kUTF32_TextEncoding,
-        SkPaint::kGlyphID_TextEncoding,
+    const SkTextEncoding encodings[] = {
+        kUTF8_SkTextEncoding,
+        kUTF16_SkTextEncoding,
+        kUTF32_SkTextEncoding,
+        kGlyphID_SkTextEncoding,
     };
     const SkPaint::Style styles[] = {
         SkPaint::kFill_Style,
@@ -370,7 +370,7 @@
     uint16_t* glyphs = glyphStorage.get();
 
     (void)paint.textToGlyphs(text, strlen(text), glyphs);
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    paint.setTextEncoding(kGlyphID_SkTextEncoding);
 
     SkAutoTArray<SkScalar> widthStorage(count * 2);
     SkScalar* widths = widthStorage.get();
diff --git a/tests/SkLiteDLTest.cpp b/tests/SkLiteDLTest.cpp
index 4dfce09..657fd03 100644
--- a/tests/SkLiteDLTest.cpp
+++ b/tests/SkLiteDLTest.cpp
@@ -73,7 +73,7 @@
     canvas.reset(&dl, {0,0,100,100});
 
     SkPaint paint;
-    paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
+    paint.setTextEncoding(kUTF8_SkTextEncoding);
 
     // These values don't really matter... we just need 5 valid transforms.
     SkRSXform xforms[] = {
diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp
index 249cd1b..09e4bb1 100644
--- a/tests/TextBlobTest.cpp
+++ b/tests/TextBlobTest.cpp
@@ -327,7 +327,7 @@
     int glyphCount = paint.textToGlyphs(text1, strlen(text1), nullptr);
     SkAutoTMalloc<uint16_t> glyphs(glyphCount);
     (void)paint.textToGlyphs(text1, strlen(text1), glyphs.get());
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    paint.setTextEncoding(kGlyphID_SkTextEncoding);
 
     auto run = SkTextBlobBuilderPriv::AllocRunText(&textBlobBuilder,
             paint, glyphCount, 0, 0, SkToInt(strlen(text2)), SkString(), nullptr);
@@ -441,7 +441,7 @@
 
 DEF_TEST(TextBlob_MakeAsDrawText, reporter) {
     const char text[] = "Hello";
-    auto blob = SkTextBlob::MakeFromString(text, SkFont(), SkPaint::kUTF8_TextEncoding);
+    auto blob = SkTextBlob::MakeFromString(text, SkFont(), kUTF8_SkTextEncoding);
 
     int runs = 0;
     for(SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) {
diff --git a/tests/UnicodeTest.cpp b/tests/UnicodeTest.cpp
index 43a8e6c..62174e9 100644
--- a/tests/UnicodeTest.cpp
+++ b/tests/UnicodeTest.cpp
@@ -31,13 +31,13 @@
 
     SkPaint paint;
 
-    paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
+    paint.setTextEncoding(kUTF8_SkTextEncoding);
     int count8  = paint.textToGlyphs(text8,  len8,  glyphs8);
 
-    paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
+    paint.setTextEncoding(kUTF16_SkTextEncoding);
     int count16 = paint.textToGlyphs(text16, len16, glyphs16);
 
-    paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
+    paint.setTextEncoding(kUTF32_SkTextEncoding);
     int count32 = paint.textToGlyphs(text32, len32, glyphs32);
 
     REPORTER_ASSERT(reporter, (int)len8 == count8);
diff --git a/tools/fonts/SkTestSVGTypeface.cpp b/tools/fonts/SkTestSVGTypeface.cpp
index 4b0d5a0..2dd7058 100644
--- a/tools/fonts/SkTestSVGTypeface.cpp
+++ b/tools/fonts/SkTestSVGTypeface.cpp
@@ -629,7 +629,7 @@
 
     SkPaint paint;
     paint.setTypeface(sk_ref_sp(const_cast<SkTestSVGTypeface*>(this)));
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    paint.setTextEncoding(kGlyphID_SkTextEncoding);
 
     out->writeText("  <CBDT>\n");
     out->writeText("    <header version=\"2.0\"/>\n");
@@ -797,7 +797,7 @@
 
     SkPaint paint;
     paint.setTypeface(sk_ref_sp(const_cast<SkTestSVGTypeface*>(this)));
-    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+    paint.setTextEncoding(kGlyphID_SkTextEncoding);
 
     out->writeText("  <glyf>\n");
     for (int i = 0; i < fGlyphCount; ++i) {