From 51e15a69ce5bef01ff0d0b5ae3d72c1b2ad3f799 Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Tue, 7 May 2019 15:38:46 -0400 Subject: [PATCH] Use SkTextEncoding enum instead of macros. Change-Id: I4b6259590fa0693ee0522b4999a1c0fe250b173d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212504 Reviewed-by: Mike Reed Commit-Queue: Ben Wagner --- bench/BlendmodeBench.cpp | 2 +- bench/CmapBench.cpp | 2 +- bench/DisplacementBench.cpp | 2 +- bench/FontCacheBench.cpp | 2 +- bench/MergeBench.cpp | 2 +- bench/TextBlobBench.cpp | 4 ++-- docs/examples/Canvas_drawTextBlob.cpp | 2 +- docs/examples/Font_breakText.cpp | 2 +- docs/examples/Paint_containsText.cpp | 2 +- docs/examples/Paint_getTextEncoding.cpp | 10 ++++---- docs/examples/Paint_textToGlyphs.cpp | 2 +- docs/examples/TextBlobBuilder_make.cpp | 2 +- docs/examples/TextBlob_bounds.cpp | 2 +- docs/examples/TextBlob_uniqueID.cpp | 2 +- docs/examples/Text_Encoding.cpp | 6 ++--- example/HelloWorld.cpp | 2 +- fuzz/FuzzCanvas.cpp | 8 +++---- gm/all_bitmap_configs.cpp | 6 ++--- gm/annotated_text.cpp | 4 ++-- gm/arithmode.cpp | 2 +- gm/bigtext.cpp | 6 ++--- gm/bitmapcopy.cpp | 6 ++--- gm/coloremoji.cpp | 14 ++++++----- gm/coloremoji_blendmodes.cpp | 8 +++---- gm/complexclip.cpp | 10 ++++---- gm/constcolorprocessor.cpp | 4 ++-- gm/convexpolyclip.cpp | 8 +++---- gm/dftext.cpp | 24 +++++++++---------- gm/drawatlas.cpp | 8 +++---- gm/flippity.cpp | 4 ++-- gm/fontcache.cpp | 2 +- gm/fontmgr.cpp | 4 ++-- gm/fontscaler.cpp | 2 +- gm/fontscalerdistortable.cpp | 2 +- gm/gamma.cpp | 2 +- gm/getpostextpath.cpp | 8 +++---- gm/glyph_pos.cpp | 7 +++--- gm/gm.cpp | 2 +- gm/highcontrastfilter.cpp | 4 ++-- gm/largeglyphblur.cpp | 4 ++-- gm/lumafilter.cpp | 4 ++-- gm/mac_aa_explorer.cpp | 2 +- gm/mixedtextblobs.cpp | 6 ++--- gm/pdf_never_embed.cpp | 6 ++--- gm/pictureimagegenerator.cpp | 8 +++---- gm/poly2poly.cpp | 2 +- gm/postercircle.cpp | 2 +- gm/scaledemoji.cpp | 2 +- gm/scaledemoji_rendering.cpp | 2 +- gm/shadertext3.cpp | 2 +- gm/skbug_257.cpp | 10 ++++---- gm/skbug_5321.cpp | 6 ++--- gm/stroketext.cpp | 4 ++-- gm/textblob.cpp | 4 ++-- gm/textblobblockreordering.cpp | 2 +- gm/textblobcolortrans.cpp | 4 ++-- gm/textbloblooper.cpp | 4 ++-- gm/textblobmixedsizes.cpp | 10 ++++---- gm/textblobrandomfont.cpp | 8 +++---- gm/textblobshader.cpp | 4 ++-- gm/textblobtransforms.cpp | 4 ++-- gm/texteffects.cpp | 14 +++++------ gm/typeface.cpp | 20 ++++++++-------- gm/variedtext.cpp | 4 ++-- gm/wacky_yuv_formats.cpp | 6 ++--- include/core/SkCanvas.h | 8 +++---- include/core/SkFont.h | 22 ++++++++--------- include/core/SkTextBlob.h | 10 ++++---- include/utils/SkTextUtils.h | 2 +- modules/particles/src/SkParticleAffector.cpp | 2 +- modules/sksg/src/SkSGText.cpp | 2 +- modules/skshaper/src/SkShaper_harfbuzz.cpp | 2 +- samplecode/SampleAAGeometry.cpp | 2 +- samplecode/SampleAnimatedImage.cpp | 4 ++-- samplecode/SampleAnimatedText.cpp | 2 +- samplecode/SampleAtlas.cpp | 2 +- samplecode/SampleBitmapRect.cpp | 4 ++-- samplecode/SampleChineseFling.cpp | 4 ++-- samplecode/SampleComplexClip.cpp | 10 ++++---- samplecode/SampleCusp.cpp | 2 +- samplecode/SampleFontCache.cpp | 4 ++-- samplecode/SampleGlyphTransform.cpp | 4 ++-- samplecode/SampleLCD.cpp | 4 ++-- samplecode/SampleQuadStroker.cpp | 4 ++-- samplecode/SampleRegion.cpp | 15 ++++++------ samplecode/SampleTextEffects.cpp | 2 +- site/user/api/SkCanvas_Reference.md | 4 ++-- site/user/api/SkFont_Reference.md | 16 ++++++------- site/user/api/SkPaint_Reference.md | 12 +++++----- site/user/api/SkTextBlob_Reference.md | 16 ++++++------- site/user/api/catalog.htm | 20 ++++++++-------- site/user/api/undocumented.md | 8 +++---- src/core/SkFont.cpp | 8 +++---- src/core/SkFontPriv.h | 2 +- src/core/SkGlyphRun.cpp | 4 ++-- src/core/SkTextBlob.cpp | 2 +- src/utils/SkLua.cpp | 4 ++-- src/utils/SkLuaCanvas.cpp | 8 +++---- src/xps/SkXPSDevice.cpp | 8 +++---- tests/FontHostTest.cpp | 7 +++--- tests/FontMgrTest.cpp | 4 ++-- tests/PDFPrimitivesTest.cpp | 2 +- tests/PaintTest.cpp | 6 ++--- tests/PathTest.cpp | 2 +- tests/SVGDeviceTest.cpp | 2 +- tests/TextBlobTest.cpp | 14 +++++------ tests/UnicodeTest.cpp | 8 +++---- tools/ToolUtils.cpp | 4 ++-- tools/fiddle/documumentation_examples_map.txt | 4 ++-- tools/fonts/TestSVGTypeface.cpp | 4 ++-- tools/sk_app/CommandSet.cpp | 8 +++---- 111 files changed, 314 insertions(+), 309 deletions(-) diff --git a/bench/BlendmodeBench.cpp b/bench/BlendmodeBench.cpp index f51ecce968..5fb7a7bf1f 100644 --- a/bench/BlendmodeBench.cpp +++ b/bench/BlendmodeBench.cpp @@ -40,7 +40,7 @@ protected: font.setSize(random.nextRangeScalar(12, 96)); SkScalar x = random.nextRangeScalar(0, (SkScalar)size.fWidth), y = random.nextRangeScalar(0, (SkScalar)size.fHeight); - auto blob = SkTextBlob::MakeFromText(text, len, font, kUTF8_SkTextEncoding); + auto blob = SkTextBlob::MakeFromText(text, len, font, SkTextEncoding::kUTF8); for (int j = 0; j < 1000; ++j) { canvas->drawTextBlob(blob, x, y, paint); } diff --git a/bench/CmapBench.cpp b/bench/CmapBench.cpp index 53d5cefd91..7988165e68 100644 --- a/bench/CmapBench.cpp +++ b/bench/CmapBench.cpp @@ -34,7 +34,7 @@ static void textToGlyphs_proc(const Rec& r) { SkASSERT(r.fCount <= NGLYPHS); for (int i = 0; i < r.fLoops; ++i) { - r.fFont.textToGlyphs(r.fText, r.fCount*4, kUTF32_SkTextEncoding, glyphs, NGLYPHS); + r.fFont.textToGlyphs(r.fText, r.fCount*4, SkTextEncoding::kUTF32, glyphs, NGLYPHS); } } diff --git a/bench/DisplacementBench.cpp b/bench/DisplacementBench.cpp index b0749fec9b..906a04b672 100644 --- a/bench/DisplacementBench.cpp +++ b/bench/DisplacementBench.cpp @@ -41,7 +41,7 @@ protected: SkFont font; font.setSize(SkIntToScalar(96)); - canvas.drawSimpleText("g", 1, kUTF8_SkTextEncoding, SkIntToScalar(15), SkIntToScalar(55), font, paint); + canvas.drawSimpleText("g", 1, SkTextEncoding::kUTF8, SkIntToScalar(15), SkIntToScalar(55), font, paint); } void makeCheckerboard() { diff --git a/bench/FontCacheBench.cpp b/bench/FontCacheBench.cpp index 75d421e26a..72a4d539f9 100644 --- a/bench/FontCacheBench.cpp +++ b/bench/FontCacheBench.cpp @@ -43,7 +43,7 @@ protected: while (*array != gUniqueGlyphIDs_Sentinel) { int count = count_glyphs(array); for (int i = 0; i < loops; ++i) { - (void)font.measureText(array, count * sizeof(uint16_t), kGlyphID_SkTextEncoding); + (void)font.measureText(array, count * sizeof(uint16_t), SkTextEncoding::kGlyphID); } array += count + 1; // skip the sentinel } diff --git a/bench/MergeBench.cpp b/bench/MergeBench.cpp index 70688141f0..27d22dd2a6 100644 --- a/bench/MergeBench.cpp +++ b/bench/MergeBench.cpp @@ -24,7 +24,7 @@ static sk_sp make_bitmap() { paint.setColor(0xFF884422); SkFont font; font.setSize(SkIntToScalar(96)); - surface->getCanvas()->drawSimpleText("g", 1, kUTF8_SkTextEncoding, 15, 55, font, paint); + surface->getCanvas()->drawSimpleText("g", 1, SkTextEncoding::kUTF8, 15, 55, font, paint); return surface->makeImageSnapshot(); } diff --git a/bench/TextBlobBench.cpp b/bench/TextBlobBench.cpp index 73e69605ae..70ad449112 100644 --- a/bench/TextBlobBench.cpp +++ b/bench/TextBlobBench.cpp @@ -33,10 +33,10 @@ public: // This text seems representative in both length and letter frequency. const char* text = "Keep your sentences short, but not overly so."; - fGlyphs.setCount(fFont.countText(text, strlen(text), kUTF8_SkTextEncoding)); + fGlyphs.setCount(fFont.countText(text, strlen(text), SkTextEncoding::kUTF8)); fXPos.setCount(fGlyphs.count()); - fFont.textToGlyphs(text, strlen(text), kUTF8_SkTextEncoding, fGlyphs.begin(), fGlyphs.count()); + fFont.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, fGlyphs.begin(), fGlyphs.count()); fFont.getXPos(&fGlyphs[0], fGlyphs.count(), fXPos.begin()); } diff --git a/docs/examples/Canvas_drawTextBlob.cpp b/docs/examples/Canvas_drawTextBlob.cpp index bd974b07b7..9fcab6a136 100644 --- a/docs/examples/Canvas_drawTextBlob.cpp +++ b/docs/examples/Canvas_drawTextBlob.cpp @@ -11,7 +11,7 @@ void draw(SkCanvas* canvas) { uint16_t glyphs[len]; SkPaint paint; paint.textToGlyphs(bunny, len, glyphs); - paint.setTextEncoding(kGlyphID_SkTextEncoding); + paint.setTextEncoding(SkTextEncoding::kGlyphID); SkFont font; int runs[] = { 3, 1, 3 }; SkPoint textPos = { 20, 100 }; diff --git a/docs/examples/Font_breakText.cpp b/docs/examples/Font_breakText.cpp index d5ad4f48bf..ddfef719eb 100644 --- a/docs/examples/Font_breakText.cpp +++ b/docs/examples/Font_breakText.cpp @@ -14,7 +14,7 @@ void draw(SkCanvas* canvas) { SkScalar measuredWidth; SkFont font; font.setSize(50); - int partialBytes = font.breakText(str, count, kUTF8_SkTextEncoding, + int partialBytes = font.breakText(str, count, SkTextEncoding::kUTF8, 100, &measuredWidth); canvas->drawText(str, partialBytes, 25, 100, paint); canvas->drawLine(25, 60, 25 + 100, 60, paint); diff --git a/docs/examples/Paint_containsText.cpp b/docs/examples/Paint_containsText.cpp index b7d8bf031f..4c4407652b 100644 --- a/docs/examples/Paint_containsText.cpp +++ b/docs/examples/Paint_containsText.cpp @@ -9,7 +9,7 @@ void draw(SkCanvas* canvas) { const uint16_t goodGlyph = 511; const uint16_t zeroGlyph = 0; const uint16_t badGlyph = 65535; // larger than glyph count in font - paint.setTextEncoding(kGlyphID_SkTextEncoding); + paint.setTextEncoding(SkTextEncoding::kGlyphID); SkDebugf("0x%04x %c= has glyph\n", goodGlyph, paint.containsText(&goodGlyph, 2) ? '=' : '!'); SkDebugf("0x%04x %c= has glyph\n", zeroGlyph, diff --git a/docs/examples/Paint_getTextEncoding.cpp b/docs/examples/Paint_getTextEncoding.cpp index f2b48fb619..294a31e908 100644 --- a/docs/examples/Paint_getTextEncoding.cpp +++ b/docs/examples/Paint_getTextEncoding.cpp @@ -6,11 +6,11 @@ REG_FIDDLE(Paint_getTextEncoding, 256, 256, true, 0) { void draw(SkCanvas* canvas) { SkPaint paint; - SkDebugf("kUTF8_SkTextEncoding %c= text encoding\n", - kUTF8_SkTextEncoding == paint.getTextEncoding() ? '=' : '!'); - paint.setTextEncoding(kGlyphID_SkTextEncoding); - SkDebugf("kGlyphID_SkTextEncoding %c= text encoding\n", - kGlyphID_SkTextEncoding == paint.getTextEncoding() ? '=' : '!'); + SkDebugf("SkTextEncoding::kUTF8 %c= text encoding\n", + SkTextEncoding::kUTF8 == paint.getTextEncoding() ? '=' : '!'); + paint.setTextEncoding(SkTextEncoding::kGlyphID); + SkDebugf("SkTextEncoding::kGlyphID %c= text encoding\n", + SkTextEncoding::kGlyphID == paint.getTextEncoding() ? '=' : '!'); } } // END FIDDLE #endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_textToGlyphs.cpp b/docs/examples/Paint_textToGlyphs.cpp index 861d9f3b8a..a1f213ca10 100644 --- a/docs/examples/Paint_textToGlyphs.cpp +++ b/docs/examples/Paint_textToGlyphs.cpp @@ -11,7 +11,7 @@ void draw(SkCanvas* canvas) { int count = paint.textToGlyphs(utf8, sizeof(utf8), nullptr); glyphs.resize(count); (void) paint.textToGlyphs(utf8, sizeof(utf8), &glyphs.front()); - paint.setTextEncoding(kGlyphID_SkTextEncoding); + paint.setTextEncoding(SkTextEncoding::kGlyphID); paint.setTextSize(32); canvas->drawText(&glyphs.front(), glyphs.size() * sizeof(SkGlyphID), 10, 40, paint); } diff --git a/docs/examples/TextBlobBuilder_make.cpp b/docs/examples/TextBlobBuilder_make.cpp index 60c9081add..984f6c9b8b 100644 --- a/docs/examples/TextBlobBuilder_make.cpp +++ b/docs/examples/TextBlobBuilder_make.cpp @@ -9,7 +9,7 @@ void draw(SkCanvas* canvas) { sk_sp blob = builder.make(); SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal"); SkPaint paint; - paint.setTextEncoding(kGlyphID_SkTextEncoding); + paint.setTextEncoding(SkTextEncoding::kGlyphID); SkFont font; paint.textToGlyphs("x", 1, builder.allocRun(font, 1, 20, 20).glyphs); blob = builder.make(); diff --git a/docs/examples/TextBlob_bounds.cpp b/docs/examples/TextBlob_bounds.cpp index 3588fe5c28..d63edf43d5 100644 --- a/docs/examples/TextBlob_bounds.cpp +++ b/docs/examples/TextBlob_bounds.cpp @@ -11,7 +11,7 @@ void draw(SkCanvas* canvas) { uint16_t glyphs[len]; SkPaint paint; paint.textToGlyphs(bunny, len, glyphs); - paint.setTextEncoding(kGlyphID_SkTextEncoding); + paint.setTextEncoding(SkTextEncoding::kGlyphID); SkFont font; int runs[] = { 3, 1, 3 }; SkPoint textPos = { 20, 50 }; diff --git a/docs/examples/TextBlob_uniqueID.cpp b/docs/examples/TextBlob_uniqueID.cpp index d9152ecd43..01bc97c27a 100644 --- a/docs/examples/TextBlob_uniqueID.cpp +++ b/docs/examples/TextBlob_uniqueID.cpp @@ -12,7 +12,7 @@ void draw(SkCanvas* canvas) { uint16_t glyphs[len]; SkPaint paint; paint.textToGlyphs(bunny, len, glyphs); - paint.setTextEncoding(kGlyphID_SkTextEncoding); + paint.setTextEncoding(SkTextEncoding::kGlyphID); paint.setTextScaleX(0.5); SkFont font; font.setScaleX(0.5); diff --git a/docs/examples/Text_Encoding.cpp b/docs/examples/Text_Encoding.cpp index 930c7d4c6d..483c3f2e32 100644 --- a/docs/examples/Text_Encoding.cpp +++ b/docs/examples/Text_Encoding.cpp @@ -11,13 +11,13 @@ void draw(SkCanvas* canvas) { const uint32_t hello32[] = { 'H', 'e', 'l', 'l', 'o', 0x263A }; paint.setTextSize(24); canvas->drawText(hello8, sizeof(hello8) - 1, 10, 30, paint); - paint.setTextEncoding(kUTF16_SkTextEncoding); + paint.setTextEncoding(SkTextEncoding::kUTF16); canvas->drawText(hello16, sizeof(hello16), 10, 60, paint); - paint.setTextEncoding(kUTF32_SkTextEncoding); + paint.setTextEncoding(SkTextEncoding::kUTF32); canvas->drawText(hello32, sizeof(hello32), 10, 90, paint); uint16_t glyphs[SK_ARRAY_COUNT(hello32)]; paint.textToGlyphs(hello32, sizeof(hello32), glyphs); - paint.setTextEncoding(kGlyphID_SkTextEncoding); + paint.setTextEncoding(SkTextEncoding::kGlyphID); canvas->drawText(glyphs, sizeof(glyphs), 10, 120, paint); } } // END FIDDLE diff --git a/example/HelloWorld.cpp b/example/HelloWorld.cpp index eed4b689e3..9fff44ee33 100644 --- a/example/HelloWorld.cpp +++ b/example/HelloWorld.cpp @@ -99,7 +99,7 @@ void HelloWorld::onPaint(SkSurface* surface) { canvas->rotate(fRotationAngle); // Draw the text - canvas->drawSimpleText(message, strlen(message), kUTF8_SkTextEncoding, 0, 0, font, paint); + canvas->drawSimpleText(message, strlen(message), SkTextEncoding::kUTF8, 0, 0, font, paint); canvas->restore(); } diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp index fcf043fc05..36eb6f3ae1 100644 --- a/fuzz/FuzzCanvas.cpp +++ b/fuzz/FuzzCanvas.cpp @@ -900,7 +900,7 @@ constexpr int kMaxGlyphCount = 30; static SkTDArray make_fuzz_text(Fuzz* fuzz, const SkFont& font, SkTextEncoding encoding) { SkTDArray array; - if (kGlyphID_SkTextEncoding == encoding) { + if (SkTextEncoding::kGlyphID == encoding) { int glyphRange = font.getTypefaceOrDefault()->countGlyphs(); if (glyphRange == 0) { // Some fuzzing environments have no fonts, so empty array is the best @@ -941,7 +941,7 @@ static SkTDArray make_fuzz_text(Fuzz* fuzz, const SkFont& font, SkTextE } } switch (encoding) { - case kUTF8_SkTextEncoding: { + case SkTextEncoding::kUTF8: { size_t utf8len = 0; for (int j = 0; j < length; ++j) { utf8len += SkUTF::ToUTF8(buffer[j], nullptr); @@ -951,7 +951,7 @@ static SkTDArray make_fuzz_text(Fuzz* fuzz, const SkFont& font, SkTextE ptr += SkUTF::ToUTF8(buffer[j], ptr); } } break; - case kUTF16_SkTextEncoding: { + case SkTextEncoding::kUTF16: { size_t utf16len = 0; for (int j = 0; j < length; ++j) { utf16len += SkUTF::ToUTF16(buffer[j]); @@ -961,7 +961,7 @@ static SkTDArray make_fuzz_text(Fuzz* fuzz, const SkFont& font, SkTextE ptr += SkUTF::ToUTF16(buffer[j], ptr); } } break; - case kUTF32_SkTextEncoding: + case SkTextEncoding::kUTF32: memcpy(array.append(length * sizeof(SkUnichar)), buffer, length * sizeof(SkUnichar)); break; default: diff --git a/gm/all_bitmap_configs.cpp b/gm/all_bitmap_configs.cpp index 7f3496aa8b..5a8387ed53 100644 --- a/gm/all_bitmap_configs.cpp +++ b/gm/all_bitmap_configs.cpp @@ -74,8 +74,8 @@ static SkBitmap make_bitmap(SkColorType ct) { static void draw_center_letter(char c, const SkFont& font, SkColor color, SkScalar x, SkScalar y, SkCanvas* canvas) { SkRect bounds; - font.measureText(&c, 1, kUTF8_SkTextEncoding, &bounds); - canvas->drawSimpleText(&c, 1, kUTF8_SkTextEncoding, + font.measureText(&c, 1, SkTextEncoding::kUTF8, &bounds); + canvas->drawSimpleText(&c, 1, SkTextEncoding::kUTF8, x - bounds.centerX(), y - bounds.centerY(), font, SkPaint(SkColor4f::FromColor(color))); } @@ -122,7 +122,7 @@ static void draw(SkCanvas* canvas, const char text[]) { SkASSERT(src.colorType() == colorType); canvas->drawBitmap(src, 0.0f, 0.0f); - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 0.0f, 12.0f, font, p); + canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 0.0f, 12.0f, font, p); } DEF_SIMPLE_GM(all_bitmap_configs, canvas, SCALE, 6 * SCALE) { diff --git a/gm/annotated_text.cpp b/gm/annotated_text.cpp index 86da9a0113..5d21d158a7 100644 --- a/gm/annotated_text.cpp +++ b/gm/annotated_text.cpp @@ -24,14 +24,14 @@ static void draw_url_annotated_text_with_box( SkScalar x, SkScalar y, const SkFont& font, const char* url) { size_t byteLength = strlen(static_cast(text)); SkRect bounds; - (void)font.measureText(text, byteLength, kUTF8_SkTextEncoding, &bounds); + (void)font.measureText(text, byteLength, SkTextEncoding::kUTF8, &bounds); bounds.offset(x, y); sk_sp urlData(SkData::MakeWithCString(url)); SkAnnotateRectWithURL(canvas, bounds, urlData.get()); SkPaint shade; shade.setColor(0x80346180); canvas->drawRect(bounds, shade); - canvas->drawSimpleText(text, byteLength, kUTF8_SkTextEncoding, x, y, font, SkPaint()); + canvas->drawSimpleText(text, byteLength, SkTextEncoding::kUTF8, x, y, font, SkPaint()); } DEF_SIMPLE_GM(annotated_text, canvas, 512, 512) { diff --git a/gm/arithmode.cpp b/gm/arithmode.cpp index 32d3b98b7c..37c7a597b0 100644 --- a/gm/arithmode.cpp +++ b/gm/arithmode.cpp @@ -74,7 +74,7 @@ static void show_k_text(SkCanvas* canvas, SkScalar x, SkScalar y, const SkScalar for (int i = 0; i < 4; ++i) { SkString str; str.appendScalar(k[i]); - SkScalar width = font.measureText(str.c_str(), str.size(), kUTF8_SkTextEncoding); + SkScalar width = font.measureText(str.c_str(), str.size(), SkTextEncoding::kUTF8); canvas->drawString(str, x, y + font.getSize(), font, paint); x += width + SkIntToScalar(10); } diff --git a/gm/bigtext.cpp b/gm/bigtext.cpp index 9ace77d0ff..e491d10add 100644 --- a/gm/bigtext.cpp +++ b/gm/bigtext.cpp @@ -43,17 +43,17 @@ protected: SkFont font(ToolUtils::create_portable_typeface(), 1500); SkRect r; - (void)font.measureText("/", 1, kUTF8_SkTextEncoding, &r); + (void)font.measureText("/", 1, SkTextEncoding::kUTF8, &r); SkPoint pos = { this->width()/2 - r.centerX(), this->height()/2 - r.centerY() }; paint.setColor(SK_ColorRED); - canvas->drawSimpleText("/", 1, kUTF8_SkTextEncoding, pos.fX, pos.fY, font, paint); + canvas->drawSimpleText("/", 1, SkTextEncoding::kUTF8, pos.fX, pos.fY, font, paint); paint.setColor(SK_ColorBLUE); - canvas->drawSimpleText("\\", 1, kUTF8_SkTextEncoding, pos.fX, pos.fY, font, paint); + canvas->drawSimpleText("\\", 1, SkTextEncoding::kUTF8, pos.fX, pos.fY, font, paint); } private: diff --git a/gm/bitmapcopy.cpp b/gm/bitmapcopy.cpp index 8ad5808fe7..778dc9c9cd 100644 --- a/gm/bitmapcopy.cpp +++ b/gm/bitmapcopy.cpp @@ -111,7 +111,7 @@ protected: } for (unsigned i = 0; i < NUM_CONFIGS; i++) { const char* name = color_type_name(src.colorType()); - SkScalar textWidth = font.measureText(name, strlen(name), kUTF8_SkTextEncoding); + SkScalar textWidth = font.measureText(name, strlen(name), SkTextEncoding::kUTF8); if (textWidth > width) { width = textWidth; } @@ -124,10 +124,10 @@ protected: canvas->save(); // Draw destination config name const char* name = color_type_name(fDst[i].colorType()); - SkScalar textWidth = font.measureText(name, strlen(name), kUTF8_SkTextEncoding); + SkScalar textWidth = font.measureText(name, strlen(name), SkTextEncoding::kUTF8); SkScalar x = (width - textWidth) / SkScalar(2); SkScalar y = font.getSpacing() / SkScalar(2); - canvas->drawSimpleText(name, strlen(name), kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(name, strlen(name), SkTextEncoding::kUTF8, x, y, font, paint); // Draw destination bitmap canvas->translate(0, vertOffset); diff --git a/gm/coloremoji.cpp b/gm/coloremoji.cpp index f02353cfbb..ef93000660 100644 --- a/gm/coloremoji.cpp +++ b/gm/coloremoji.cpp @@ -92,7 +92,8 @@ protected: canvas->drawColor(SK_ColorGRAY); SkFont font(emojiFont.typeface); - const char* text = emojiFont.text; + char const * const text = emojiFont.text; + size_t textLen = strlen(text); // draw text at different point sizes constexpr SkScalar textSizes[] = { 10, 30, 50, }; @@ -104,7 +105,8 @@ protected: font.setSize(textSize); font.getMetrics(&metrics); y += -metrics.fAscent; - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 10, y, font, SkPaint()); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, + 10, y, font, SkPaint()); y += metrics.fDescent + metrics.fLeading; } } @@ -141,7 +143,7 @@ protected: shaderFont.setSize(30); shaderFont.getMetrics(&metrics); y += -metrics.fAscent; - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 380, y, + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 380, y, shaderFont, shaderPaint); y += metrics.fDescent + metrics.fLeading; } @@ -155,7 +157,7 @@ protected: // compute the bounds of the text SkRect bounds; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, textLen, SkTextEncoding::kUTF8, &bounds); const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf; const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf; @@ -181,10 +183,10 @@ protected: canvas->save(); canvas->drawRect(clipRect, clipHairline); paint.setAlpha(0x20); - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 0, 0, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint); canvas->clipRect(clipRect); paint.setAlphaf(1.0f); - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 0, 0, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint); canvas->restore(); canvas->translate(0, SkIntToScalar(25)); } diff --git a/gm/coloremoji_blendmodes.cpp b/gm/coloremoji_blendmodes.cpp index f0f44f5f4e..09d52cf153 100644 --- a/gm/coloremoji_blendmodes.cpp +++ b/gm/coloremoji_blendmodes.cpp @@ -147,13 +147,13 @@ protected: const char* text = ToolUtils::emoji_sample_text(); SkUnichar unichar = SkUTF::NextUTF8(&text, text + strlen(text)); SkASSERT(unichar >= 0); - canvas->drawSimpleText(&unichar, 4, kUTF32_SkTextEncoding, x+ w/10.f, y + 7.f*h/8.f, - textFont, textP); + canvas->drawSimpleText(&unichar, 4, SkTextEncoding::kUTF32, + x+ w/10.f, y + 7.f*h/8.f, textFont, textP); } #if 1 const char* label = SkBlendMode_Name(gModes[i]); - SkTextUtils::DrawString(canvas, label, x + w/2, y - labelFont.getSize()/2, labelFont, SkPaint(), - SkTextUtils::kCenter_Align); + SkTextUtils::DrawString(canvas, label, x + w/2, y - labelFont.getSize()/2, + labelFont, SkPaint(), SkTextUtils::kCenter_Align); #endif x += w + SkIntToScalar(10); if ((i % W) == W - 1) { diff --git a/gm/complexclip.cpp b/gm/complexclip.cpp index 64922b664c..3e53783004 100644 --- a/gm/complexclip.cpp +++ b/gm/complexclip.cpp @@ -152,15 +152,15 @@ protected: SkScalar txtX = 45; paint.setColor(gClipAColor); const char* aTxt = doInvA ? "InvA " : "A "; - canvas->drawSimpleText(aTxt, strlen(aTxt), kUTF8_SkTextEncoding, txtX, 220, font, paint); - txtX += font.measureText(aTxt, strlen(aTxt), kUTF8_SkTextEncoding); + canvas->drawSimpleText(aTxt, strlen(aTxt), SkTextEncoding::kUTF8, txtX, 220, font, paint); + txtX += font.measureText(aTxt, strlen(aTxt), SkTextEncoding::kUTF8); paint.setColor(SK_ColorBLACK); - canvas->drawSimpleText(gOps[op].fName, strlen(gOps[op].fName), kUTF8_SkTextEncoding, txtX, 220, + canvas->drawSimpleText(gOps[op].fName, strlen(gOps[op].fName), SkTextEncoding::kUTF8, txtX, 220, font, paint); - txtX += font.measureText(gOps[op].fName, strlen(gOps[op].fName), kUTF8_SkTextEncoding); + txtX += font.measureText(gOps[op].fName, strlen(gOps[op].fName), SkTextEncoding::kUTF8); paint.setColor(gClipBColor); const char* bTxt = doInvB ? "InvB " : "B "; - canvas->drawSimpleText(bTxt, strlen(bTxt), kUTF8_SkTextEncoding, txtX, 220, font, paint); + canvas->drawSimpleText(bTxt, strlen(bTxt), SkTextEncoding::kUTF8, txtX, 220, font, paint); canvas->translate(250,0); } diff --git a/gm/constcolorprocessor.cpp b/gm/constcolorprocessor.cpp index 93ef95aa83..fe4e0355eb 100644 --- a/gm/constcolorprocessor.cpp +++ b/gm/constcolorprocessor.cpp @@ -145,7 +145,7 @@ protected: SkRect inputLabelBounds; // get the bounds of the text in order to position it labelFont.measureText(inputLabel.c_str(), inputLabel.size(), - kUTF8_SkTextEncoding, &inputLabelBounds); + SkTextEncoding::kUTF8, &inputLabelBounds); canvas->drawString(inputLabel, renderRect.fRight + kPad, -inputLabelBounds.fTop, labelFont, labelPaint); // update the bounds to reflect the offset we used to draw it. @@ -153,7 +153,7 @@ protected: SkRect procLabelBounds; labelFont.measureText(procLabel.c_str(), procLabel.size(), - kUTF8_SkTextEncoding, &procLabelBounds); + SkTextEncoding::kUTF8, &procLabelBounds); canvas->drawString(procLabel, renderRect.fRight + kPad, inputLabelBounds.fBottom + 2.f - procLabelBounds.fTop, labelFont, labelPaint); diff --git a/gm/convexpolyclip.cpp b/gm/convexpolyclip.cpp index 08c5160064..31dc1d4697 100644 --- a/gm/convexpolyclip.cpp +++ b/gm/convexpolyclip.cpp @@ -79,12 +79,12 @@ static SkBitmap make_bmp(int w, int h) { paint.setColor(SK_ColorLTGRAY); constexpr char kTxt[] = "Skia"; SkPoint texPos = { wScalar / 17, hScalar / 2 + font.getSize() / 2.5f }; - canvas.drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, kUTF8_SkTextEncoding, + canvas.drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8, texPos.fX, texPos.fY, font, paint); paint.setColor(SK_ColorBLACK); paint.setStyle(SkPaint::kStroke_Style); paint.setStrokeWidth(SK_Scalar1); - canvas.drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, kUTF8_SkTextEncoding, + canvas.drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8, texPos.fX, texPos.fY, font, paint); return bmp; } @@ -166,7 +166,7 @@ protected: constexpr char kTxt[] = "Clip Me!"; SkFont font(ToolUtils::create_portable_typeface(), 23); - SkScalar textW = font.measureText(kTxt, SK_ARRAY_COUNT(kTxt)-1, kUTF8_SkTextEncoding); + SkScalar textW = font.measureText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8); SkPaint txtPaint; txtPaint.setColor(SK_ColorDKGRAY); @@ -217,7 +217,7 @@ protected: canvas->drawPath(closedClipPath, clipOutlinePaint); clip->setOnCanvas(canvas, kIntersect_SkClipOp, SkToBool(aa)); canvas->scale(1.f, 1.8f); - canvas->drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, kUTF8_SkTextEncoding, + canvas->drawSimpleText(kTxt, SK_ARRAY_COUNT(kTxt)-1, SkTextEncoding::kUTF8, 0, 1.5f * font.getSize(), font, txtPaint); canvas->restore(); x += textW + 2 * kMargin; diff --git a/gm/dftext.cpp b/gm/dftext.cpp index 199d9ee8a3..a342c38b24 100644 --- a/gm/dftext.cpp +++ b/gm/dftext.cpp @@ -90,7 +90,7 @@ protected: canvas->translate(x, y); canvas->scale(scales[i], scales[i]); font.setSize(textSizes[i]); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, 0, 0, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint); y += font.getMetrics(nullptr)*scales[i]; } @@ -104,7 +104,7 @@ protected: canvas->rotate(SkIntToScalar(i * 5), rotX, rotY); for (int ps = 6; ps <= 32; ps += 3) { font.setSize(SkIntToScalar(ps)); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, rotX, rotY, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, rotX, rotY, font, paint); rotY += font.getMetrics(nullptr); } } @@ -120,7 +120,7 @@ protected: SkScalar scaleFactor = SkScalarInvert(scales[arraySize - i - 1]); canvas->scale(scaleFactor, scaleFactor); font.setSize(textSizes[i]); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, 0, 0, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint); y += font.getMetrics(nullptr)*scaleFactor; } @@ -131,13 +131,13 @@ protected: canvas->scale(2.0f, 2.0f); SkAutoTArray glyphs(SkToInt(textLen)); - int count = font.textToGlyphs(text, textLen, kUTF8_SkTextEncoding, glyphs.get(), textLen); + int count = font.textToGlyphs(text, textLen, SkTextEncoding::kUTF8, glyphs.get(), textLen); SkAutoTArray pos(count); font.setSize(textSizes[0]); font.getPos(glyphs.get(), count, pos.get(), {340, 75}); auto blob = SkTextBlob::MakeFromPosText(glyphs.get(), count * sizeof(SkGlyphID), - pos.get(), font, kGlyphID_SkTextEncoding); + pos.get(), font, SkTextEncoding::kGlyphID); canvas->drawTextBlob(blob, 0, 0, paint); } @@ -160,7 +160,7 @@ protected: for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) { paint.setColor(fg[i]); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, paint); y += font.getMetrics(nullptr); } @@ -174,7 +174,7 @@ protected: for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) { paint.setColor(fg[i]); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, paint); y += font.getMetrics(nullptr); } @@ -184,14 +184,14 @@ protected: SkAutoCanvasRestore acr(canvas, true); canvas->skew(0.0f, 0.151515f); font.setSize(SkIntToScalar(32)); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, 745, 70, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 745, 70, font, paint); } { font.setEdging(SkFont::Edging::kSubpixelAntiAlias); SkAutoCanvasRestore acr(canvas, true); canvas->skew(0.5f, 0.0f); font.setSize(SkIntToScalar(32)); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, 580, 125, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 580, 125, font, paint); } // check perspective @@ -205,7 +205,7 @@ protected: canvas->concat(persp); canvas->translate(1100, -295); font.setSize(37.5f); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, 0, 0, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint); } { font.setSubpixel(false); @@ -219,7 +219,7 @@ protected: canvas->translate(1075, -245); canvas->scale(375, 375); font.setSize(0.1f); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, 0, 0, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint); } // check color emoji @@ -228,7 +228,7 @@ protected: emoiFont.setSubpixel(true); emoiFont.setTypeface(fEmojiTypeface); emoiFont.setSize(SkIntToScalar(19)); - canvas->drawSimpleText(fEmojiText, strlen(fEmojiText), kUTF8_SkTextEncoding, 670, 90, emoiFont, paint); + canvas->drawSimpleText(fEmojiText, strlen(fEmojiText), SkTextEncoding::kUTF8, 670, 90, emoiFont, paint); } // render offscreen buffer diff --git a/gm/drawatlas.cpp b/gm/drawatlas.cpp index 3042472b6d..132fd5b8c2 100644 --- a/gm/drawatlas.cpp +++ b/gm/drawatlas.cpp @@ -132,7 +132,7 @@ static void draw_text_on_path(SkCanvas* canvas, const void* text, size_t length, float baseline_offset) { SkPathMeasure meas(path, false); - int count = font.countText(text, length, kUTF8_SkTextEncoding); + int count = font.countText(text, length, SkTextEncoding::kUTF8); size_t size = count * (sizeof(SkRSXform) + sizeof(SkScalar)); SkAutoSMalloc<512> storage(size); SkRSXform* xform = (SkRSXform*)storage.get(); @@ -145,7 +145,7 @@ static void draw_text_on_path(SkCanvas* canvas, const void* text, size_t length, const SkRect bounds = path.getBounds().makeOutset(max, max); SkAutoTArray glyphs(count); - font.textToGlyphs(text, length, kUTF8_SkTextEncoding, glyphs.get(), count); + font.textToGlyphs(text, length, SkTextEncoding::kUTF8, glyphs.get(), count); font.getWidths(glyphs.get(), count, widths); for (int i = 0; i < count; ++i) { @@ -166,7 +166,7 @@ static void draw_text_on_path(SkCanvas* canvas, const void* text, size_t length, } canvas->drawTextBlob(SkTextBlob::MakeFromRSXform(glyphs.get(), count * sizeof(SkGlyphID), - &xform[0], font, kGlyphID_SkTextEncoding), + &xform[0], font, SkTextEncoding::kGlyphID), 0, 0, paint); if (true) { @@ -202,7 +202,7 @@ static void drawTextPath(SkCanvas* canvas, bool doStroke) { SkScalar x = 0; for (int i = 0; i < N; ++i) { pos[i].set(x, 0); - x += font.measureText(&text0[i], 1, kUTF8_SkTextEncoding, nullptr, &paint); + x += font.measureText(&text0[i], 1, SkTextEncoding::kUTF8, nullptr, &paint); } SkPath path; diff --git a/gm/flippity.cpp b/gm/flippity.cpp index 8718da605d..24c7879bd7 100644 --- a/gm/flippity.cpp +++ b/gm/flippity.cpp @@ -90,7 +90,7 @@ static sk_sp make_text_image(GrContext* context, const char* text, SkCo font.setSize(32); SkRect bounds; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); const SkMatrix mat = SkMatrix::MakeRectToRect(bounds, SkRect::MakeWH(kLabelSize, kLabelSize), SkMatrix::kFill_ScaleToFit); @@ -101,7 +101,7 @@ static sk_sp make_text_image(GrContext* context, const char* text, SkCo canvas->clear(SK_ColorWHITE); canvas->concat(mat); - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 0, 0, font, paint); + canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 0, 0, font, paint); sk_sp image = surf->makeImageSnapshot(); diff --git a/gm/fontcache.cpp b/gm/fontcache.cpp index fb0bad2a1f..cd78e82ce9 100644 --- a/gm/fontcache.cpp +++ b/gm/fontcache.cpp @@ -32,7 +32,7 @@ static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x, SkScalar y, const SkFont& font) { SkPaint paint; canvas->drawString(text, x, y, font, paint); - return x + font.measureText(text.c_str(), text.size(), kUTF8_SkTextEncoding); + return x + font.measureText(text.c_str(), text.size(), SkTextEncoding::kUTF8); } class FontCacheGM : public skiagm::GpuGM { diff --git a/gm/fontmgr.cpp b/gm/fontmgr.cpp index e86c2c6813..9290825e1d 100644 --- a/gm/fontmgr.cpp +++ b/gm/fontmgr.cpp @@ -36,7 +36,7 @@ static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x, SkScalar y, const SkFont& font) { canvas->drawString(text, x, y, font, SkPaint()); - return x + font.measureText(text.c_str(), text.size(), kUTF8_SkTextEncoding); + return x + font.measureText(text.c_str(), text.size(), SkTextEncoding::kUTF8); } static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x, @@ -309,7 +309,7 @@ public: SkPaint::Style style = path.isEmpty() ? SkPaint::kFill_Style : SkPaint::kStroke_Style; SkPaint glyphPaint; glyphPaint.setStyle(style); - canvas->drawSimpleText(&str[i], sizeof(str[0]), kGlyphID_SkTextEncoding, x, y, font, glyphPaint); + canvas->drawSimpleText(&str[i], sizeof(str[0]), SkTextEncoding::kGlyphID, x, y, font, glyphPaint); if (labelBounds) { SkString glyphStr; diff --git a/gm/fontscaler.cpp b/gm/fontscaler.cpp index 27505dba46..3cdbbddfef 100644 --- a/gm/fontscaler.cpp +++ b/gm/fontscaler.cpp @@ -67,7 +67,7 @@ protected: for (int ps = 6; ps <= 22; ps++) { font.setSize(SkIntToScalar(ps)); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, x, y, font, SkPaint()); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, SkPaint()); y += font.getMetrics(nullptr); } } diff --git a/gm/fontscalerdistortable.cpp b/gm/fontscalerdistortable.cpp index 50c21183f3..609b75a6c5 100644 --- a/gm/fontscalerdistortable.cpp +++ b/gm/fontscalerdistortable.cpp @@ -96,7 +96,7 @@ protected: for (int ps = 6; ps <= 22; ps++) { font.setSize(SkIntToScalar(ps)); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, paint); y += font.getMetrics(nullptr); } } diff --git a/gm/gamma.cpp b/gm/gamma.cpp index 400c1c00db..97ad2d96c8 100644 --- a/gm/gamma.cpp +++ b/gm/gamma.cpp @@ -80,7 +80,7 @@ DEF_SIMPLE_GM(gamma, canvas, 850, 200) { }; auto drawString = [&](const char str[], SkScalar x, SkScalar y) { - canvas->drawSimpleText(str, strlen(str), kUTF8_SkTextEncoding, x, y, font, textPaint); + canvas->drawSimpleText(str, strlen(str), SkTextEncoding::kUTF8, x, y, font, textPaint); }; auto nextRect = [&](const char* label, const char* label2) { diff --git a/gm/getpostextpath.cpp b/gm/getpostextpath.cpp index fbce39887b..bf3343f74f 100644 --- a/gm/getpostextpath.cpp +++ b/gm/getpostextpath.cpp @@ -45,12 +45,12 @@ DEF_SIMPLE_GM(getpostextpath, canvas, 480, 780) { canvas->translate(SkIntToScalar(10), SkIntToScalar(64)); - canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, 0, 0, font, paint); - ToolUtils::get_text_path(font, text, len, kUTF8_SkTextEncoding, &path, nullptr); + canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, 0, 0, font, paint); + ToolUtils::get_text_path(font, text, len, SkTextEncoding::kUTF8, &path, nullptr); strokePath(canvas, path); path.reset(); - SkAutoToGlyphs atg(font, text, len, kUTF8_SkTextEncoding); + SkAutoToGlyphs atg(font, text, len, SkTextEncoding::kUTF8); const int count = atg.count(); SkAutoTArray pos(count); SkAutoTArray widths(count); @@ -67,6 +67,6 @@ DEF_SIMPLE_GM(getpostextpath, canvas, 480, 780) { canvas->translate(0, SkIntToScalar(64)); canvas->drawTextBlob(SkTextBlob::MakeFromPosText(text, len, &pos[0], font), 0, 0, paint); - ToolUtils::get_text_path(font, text, len, kUTF8_SkTextEncoding, &path, &pos[0]); + ToolUtils::get_text_path(font, text, len, SkTextEncoding::kUTF8, &path, &pos[0]); strokePath(canvas, path); } diff --git a/gm/glyph_pos.cpp b/gm/glyph_pos.cpp index e2f191f431..10ab21383c 100644 --- a/gm/glyph_pos.cpp +++ b/gm/glyph_pos.cpp @@ -104,7 +104,7 @@ static void drawTestCase(SkCanvas* canvas, SkRect bounds; if (drawRef) { - SkScalar advance = font.measureText(kText, sizeof(kText) - 1, kUTF8_SkTextEncoding, + SkScalar advance = font.measureText(kText, sizeof(kText) - 1, SkTextEncoding::kUTF8, &bounds, &paint); paint.setStrokeWidth(0.0f); @@ -123,12 +123,13 @@ static void drawTestCase(SkCanvas* canvas, paint.setColor(SK_ColorBLACK); paint.setStrokeWidth(strokeWidth); paint.setStyle(strokeStyle); - canvas->drawSimpleText(kText, sizeof(kText) - 1, kUTF8_SkTextEncoding, 0.0f, 0.0f, font, paint); + canvas->drawSimpleText(kText, sizeof(kText) - 1, SkTextEncoding::kUTF8, + 0.0f, 0.0f, font, paint); if (drawRef) { const size_t len = sizeof(kText) - 1; SkGlyphID glyphs[len]; - const int count = font.textToGlyphs(kText, len, kUTF8_SkTextEncoding, glyphs, len); + const int count = font.textToGlyphs(kText, len, SkTextEncoding::kUTF8, glyphs, len); SkScalar widths[len]; // len is conservative. we really only need 'count' font.getWidthsBounds(glyphs, count, widths, nullptr, &paint); diff --git a/gm/gm.cpp b/gm/gm.cpp index 04a3d6667f..27a719cdf8 100644 --- a/gm/gm.cpp +++ b/gm/gm.cpp @@ -42,7 +42,7 @@ static void draw_failure_message(SkCanvas* canvas, const char format[], ...) { canvas->drawColor(SkColorSetRGB(200,0,0)); SkFont font; SkRect bounds; - font.measureText(failureMsg.c_str(), failureMsg.size(), kUTF8_SkTextEncoding, &bounds); + font.measureText(failureMsg.c_str(), failureMsg.size(), SkTextEncoding::kUTF8, &bounds); SkPaint textPaint(SkColors::kWhite); canvas->drawString(failureMsg, kOffset, bounds.height() + kOffset, font, textPaint); } diff --git a/gm/highcontrastfilter.cpp b/gm/highcontrastfilter.cpp index e56ae1c45e..dc5a0390a5 100644 --- a/gm/highcontrastfilter.cpp +++ b/gm/highcontrastfilter.cpp @@ -55,8 +55,8 @@ static void draw_label(SkCanvas* canvas, const SkHighContrastConfig& config) { size_t len = strlen(labelBuffer); - SkScalar width = font.measureText(labelBuffer, len, kUTF8_SkTextEncoding); - canvas->drawSimpleText(labelBuffer, len, kUTF8_SkTextEncoding, 0.5f - width / 2, 0.16f, font, SkPaint()); + SkScalar width = font.measureText(labelBuffer, len, SkTextEncoding::kUTF8); + canvas->drawSimpleText(labelBuffer, len, SkTextEncoding::kUTF8, 0.5f - width / 2, 0.16f, font, SkPaint()); } static void draw_scene(SkCanvas* canvas, const SkHighContrastConfig& config) { diff --git a/gm/largeglyphblur.cpp b/gm/largeglyphblur.cpp index 5e18dbb3ff..2c106ec322 100644 --- a/gm/largeglyphblur.cpp +++ b/gm/largeglyphblur.cpp @@ -38,6 +38,6 @@ DEF_SIMPLE_GM(largeglyphblur, canvas, 1920, 600) { canvas->drawTextBlob(blob, 10, 200, SkPaint()); size_t len = strlen(text); - canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, 10, 500, font, blurPaint); - canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, 10, 500, font, SkPaint()); + canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, 10, 500, font, blurPaint); + canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, 10, 500, font, SkPaint()); } diff --git a/gm/lumafilter.cpp b/gm/lumafilter.cpp index b35208fbc1..3c360be56c 100644 --- a/gm/lumafilter.cpp +++ b/gm/lumafilter.cpp @@ -41,8 +41,8 @@ static void draw_label(SkCanvas* canvas, const char* label, size_t len = strlen(label); - SkScalar width = font.measureText(label, len, kUTF8_SkTextEncoding); - canvas->drawSimpleText(label, len, kUTF8_SkTextEncoding, offset.x() - width / 2, offset.y(), + SkScalar width = font.measureText(label, len, SkTextEncoding::kUTF8); + canvas->drawSimpleText(label, len, SkTextEncoding::kUTF8, offset.x() - width / 2, offset.y(), font, SkPaint()); } diff --git a/gm/mac_aa_explorer.cpp b/gm/mac_aa_explorer.cpp index 37adb8d94e..85de227e3d 100644 --- a/gm/mac_aa_explorer.cpp +++ b/gm/mac_aa_explorer.cpp @@ -169,7 +169,7 @@ DEF_SIMPLE_GM(macaa_colors, canvas, 800, 500) { font.setHinting(h); y += font.getSpacing() + 2; - canvas->drawSimpleText(str, len, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(str, len, SkTextEncoding::kUTF8, x, y, font, paint); } } y += 8; diff --git a/gm/mixedtextblobs.cpp b/gm/mixedtextblobs.cpp index 2bacd23f67..ab784128dc 100644 --- a/gm/mixedtextblobs.cpp +++ b/gm/mixedtextblobs.cpp @@ -61,7 +61,7 @@ protected: const char* text = "O"; SkRect bounds; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); SkScalar yOffset = bounds.height(); ToolUtils::add_to_text_blob(&builder, text, font, 10, yOffset); @@ -79,7 +79,7 @@ protected: font.setEdging(SkFont::Edging::kSubpixelAntiAlias); font.setSubpixel(true); text = "LCD!!!!!"; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); ToolUtils::add_to_text_blob(&builder, text, font, @@ -91,7 +91,7 @@ protected: font.setEdging(SkFont::Edging::kAlias); font.setSubpixel(false); font.setTypeface(fEmojiTypeface); - font.measureText(fEmojiText, strlen(fEmojiText), kUTF8_SkTextEncoding, &bounds); + font.measureText(fEmojiText, strlen(fEmojiText), SkTextEncoding::kUTF8, &bounds); ToolUtils::add_to_text_blob(&builder, fEmojiText, font, xOffset, yOffset); } diff --git a/gm/pdf_never_embed.cpp b/gm/pdf_never_embed.cpp index 0b6ccd7beb..3b96ae4a86 100644 --- a/gm/pdf_never_embed.cpp +++ b/gm/pdf_never_embed.cpp @@ -24,10 +24,10 @@ static void excercise_draw_pos_text(SkCanvas* canvas, SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint) { - const int count = font.countText(text, strlen(text), kUTF8_SkTextEncoding); + const int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8); SkTextBlobBuilder builder; auto rec = builder.allocRunPos(font, count); - font.textToGlyphs(text, strlen(text), kUTF8_SkTextEncoding, rec.glyphs, count); + font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, rec.glyphs, count); font.getPos(rec.glyphs, count, rec.points()); canvas->drawTextBlob(builder.make(), x, y, paint); } @@ -61,7 +61,7 @@ DEF_SIMPLE_GM_CAN_FAIL(pdf_never_embed, canvas, errorMsg, 512, 512) { canvas->scale(1.0, 0.5); p.setColor(0xF0000080); - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 30, 700, font, p); + canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 30, 700, font, p); return skiagm::DrawResult::kOk; } diff --git a/gm/pictureimagegenerator.cpp b/gm/pictureimagegenerator.cpp index 2fe7ca2c68..758b5f51aa 100644 --- a/gm/pictureimagegenerator.cpp +++ b/gm/pictureimagegenerator.cpp @@ -53,14 +53,14 @@ static void draw_vector_logo(SkCanvas* canvas, const SkRect& viewBox) { SkPath path; SkRect iBox, skiBox, skiaBox; - SkTextUtils::GetPath("SKI", 3, kUTF8_SkTextEncoding, 0, 0, font, &path); + SkTextUtils::GetPath("SKI", 3, SkTextEncoding::kUTF8, 0, 0, font, &path); TightBounds(path, &skiBox); - SkTextUtils::GetPath("I", 1, kUTF8_SkTextEncoding, 0, 0, font, &path); + SkTextUtils::GetPath("I", 1, SkTextEncoding::kUTF8, 0, 0, font, &path); TightBounds(path, &iBox); iBox.offsetTo(skiBox.fRight - iBox.width(), iBox.fTop); const size_t textLen = strlen(kSkiaStr); - SkTextUtils::GetPath(kSkiaStr, textLen, kUTF8_SkTextEncoding, 0, 0, font, &path); + SkTextUtils::GetPath(kSkiaStr, textLen, SkTextEncoding::kUTF8, 0, 0, font, &path); TightBounds(path, &skiaBox); skiaBox.outset(0, 2 * iBox.width() * (kVerticalSpacing + 1)); @@ -112,7 +112,7 @@ static void draw_vector_logo(SkCanvas* canvas, const SkRect& viewBox) { SkASSERT(SK_ARRAY_COUNT(pos2) == SK_ARRAY_COUNT(colors2)); paint.setShader(SkGradientShader::MakeLinear(pts2, colors2, pos2, SK_ARRAY_COUNT(pos2), SkTileMode::kClamp)); - canvas->drawSimpleText(kSkiaStr, textLen, kUTF8_SkTextEncoding, 0, 0, font, paint); + canvas->drawSimpleText(kSkiaStr, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint); } // This GM exercises SkPictureImageGenerator features diff --git a/gm/poly2poly.cpp b/gm/poly2poly.cpp index 63d71ca95b..141a602410 100644 --- a/gm/poly2poly.cpp +++ b/gm/poly2poly.cpp @@ -67,7 +67,7 @@ protected: SkScalar x = D/2; SkScalar y = D/2 - (fm.fAscent + fm.fDescent)/2; uint16_t glyphID = 3; // X - SkTextUtils::Draw(canvas, &glyphID, sizeof(glyphID), kGlyphID_SkTextEncoding, x, y, + SkTextUtils::Draw(canvas, &glyphID, sizeof(glyphID), SkTextEncoding::kGlyphID, x, y, font, *paint, SkTextUtils::kCenter_Align); canvas->restore(); } diff --git a/gm/postercircle.cpp b/gm/postercircle.cpp index 52f3ce6be3..3c692210f1 100644 --- a/gm/postercircle.cpp +++ b/gm/postercircle.cpp @@ -73,7 +73,7 @@ protected: SkString label; label.printf("%d", i); SkRect labelBounds; - font.measureText(label.c_str(), label.size(), kUTF8_SkTextEncoding, &labelBounds); + font.measureText(label.c_str(), label.size(), SkTextEncoding::kUTF8, &labelBounds); SkScalar labelX = 0.5f * kPosterSize - 0.5f * labelBounds.width(); SkScalar labelY = 0.5f * kPosterSize + 0.5f * labelBounds.height(); diff --git a/gm/scaledemoji.cpp b/gm/scaledemoji.cpp index fb42ac92fd..9ef5627fb3 100644 --- a/gm/scaledemoji.cpp +++ b/gm/scaledemoji.cpp @@ -76,7 +76,7 @@ protected: font.setSize(textSize); font.getMetrics(&metrics); y += -metrics.fAscent; - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 10, y, font, paint); + canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 10, y, font, paint); y += metrics.fDescent + metrics.fLeading; } diff --git a/gm/scaledemoji_rendering.cpp b/gm/scaledemoji_rendering.cpp index b41204d2ec..dd645bd38b 100644 --- a/gm/scaledemoji_rendering.cpp +++ b/gm/scaledemoji_rendering.cpp @@ -65,7 +65,7 @@ protected: font.setSubpixel(true); y += -metrics.fAscent; - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, + canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 10, y, font, paint); y += metrics.fDescent + metrics.fLeading; } diff --git a/gm/shadertext3.cpp b/gm/shadertext3.cpp index 22252edb29..6f33581e89 100644 --- a/gm/shadertext3.cpp +++ b/gm/shadertext3.cpp @@ -122,7 +122,7 @@ protected: constexpr char kText[] = "B"; canvas->drawString(kText, 0, 0, font, fillPaint); canvas->drawString(kText, 0, 0, font, outlinePaint); - SkScalar w = font.measureText(kText, strlen(kText), kUTF8_SkTextEncoding); + SkScalar w = font.measureText(kText, strlen(kText), SkTextEncoding::kUTF8); canvas->translate(w + 10.f, 0.f); ++i; if (!(i % 2)) { diff --git a/gm/skbug_257.cpp b/gm/skbug_257.cpp index d5654f81ce..ad3a93a634 100644 --- a/gm/skbug_257.cpp +++ b/gm/skbug_257.cpp @@ -44,10 +44,10 @@ static void exercise_draw_pos_text(SkCanvas* canvas, const char* text, SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint) { - const int count = font.countText(text, strlen(text), kUTF8_SkTextEncoding); + const int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8); SkTextBlobBuilder builder; auto rec = builder.allocRunPos(font, count); - font.textToGlyphs(text, strlen(text), kUTF8_SkTextEncoding, rec.glyphs, count); + font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, rec.glyphs, count); font.getPos(rec.glyphs, count, rec.points(), {x, y}); canvas->drawTextBlob(builder.make(), 0, 0, paint); } @@ -56,10 +56,10 @@ static void exercise_draw_pos_text_h(SkCanvas* canvas, const char* text, SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint) { - const int count = font.countText(text, strlen(text), kUTF8_SkTextEncoding); + const int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8); SkTextBlobBuilder builder; auto rec = builder.allocRunPosH(font, count, 0); - font.textToGlyphs(text, strlen(text), kUTF8_SkTextEncoding, rec.glyphs, count); + font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, rec.glyphs, count); font.getXPos(rec.glyphs, count, rec.pos); canvas->drawTextBlob(builder.make(), x, y, paint); } @@ -71,7 +71,7 @@ static void test_text(SkCanvas* canvas, SkScalar size, SkPaint type; type.setColor(color); const char text[] = "HELLO WORLD"; - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 32, size / 2 + Y, + canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 32, size / 2 + Y, font, type); SkScalar lineSpacing = font.getSpacing(); exercise_draw_pos_text(canvas, text, 32, size / 2 + Y + lineSpacing, font, type); diff --git a/gm/skbug_5321.cpp b/gm/skbug_5321.cpp index 3ad71af20e..e389cbc03b 100644 --- a/gm/skbug_5321.cpp +++ b/gm/skbug_5321.cpp @@ -26,14 +26,14 @@ DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128) { SkScalar x = 20, y = 45; size_t byteLength = strlen(text); - canvas->drawSimpleText(text, byteLength, kUTF8_SkTextEncoding, x, y, font, SkPaint()); + canvas->drawSimpleText(text, byteLength, SkTextEncoding::kUTF8, x, y, font, SkPaint()); y += font.getMetrics(nullptr); - int glyph_count = font.countText(text, byteLength, kUTF8_SkTextEncoding); + int glyph_count = font.countText(text, byteLength, SkTextEncoding::kUTF8); SkTextBlobBuilder builder; auto rec = builder.allocRunPosH(font, glyph_count, y); - font.textToGlyphs(text, byteLength, kUTF8_SkTextEncoding, rec.glyphs, glyph_count); + font.textToGlyphs(text, byteLength, SkTextEncoding::kUTF8, rec.glyphs, glyph_count); font.getWidths(rec.glyphs, glyph_count, rec.pos); for (int i = 0; i < glyph_count; ++i) { diff --git a/gm/stroketext.cpp b/gm/stroketext.cpp index abcfe37afd..4ca103ff7f 100644 --- a/gm/stroketext.cpp +++ b/gm/stroketext.cpp @@ -44,7 +44,7 @@ static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint, const SkFo if (strokeWidth > 0) { p.setStyle(SkPaint::kFill_Style); - canvas->drawSimpleText("P", 1, kUTF8_SkTextEncoding, loc.fX, loc.fY - 225, font, p); + canvas->drawSimpleText("P", 1, SkTextEncoding::kUTF8, loc.fX, loc.fY - 225, font, p); canvas->drawTextBlob(SkTextBlob::MakeFromPosText("P", 1, &loc, font), 0, 0, p); } @@ -52,7 +52,7 @@ static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint, const SkFo p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(strokeWidth); - canvas->drawSimpleText("P", 1, kUTF8_SkTextEncoding, loc.fX, loc.fY - 225, font, p); + canvas->drawSimpleText("P", 1, SkTextEncoding::kUTF8, loc.fX, loc.fY - 225, font, p); canvas->drawTextBlob(SkTextBlob::MakeFromPosText("P", 1, &loc, font), 0, 0, p); } diff --git a/gm/textblob.cpp b/gm/textblob.cpp index 5356aa68e4..b79e5799a9 100644 --- a/gm/textblob.cpp +++ b/gm/textblob.cpp @@ -89,10 +89,10 @@ protected: fTypeface = ToolUtils::create_portable_typeface("serif", SkFontStyle()); SkFont font(fTypeface); size_t txtLen = strlen(fText); - int glyphCount = font.countText(fText, txtLen, kUTF8_SkTextEncoding); + int glyphCount = font.countText(fText, txtLen, SkTextEncoding::kUTF8); fGlyphs.append(glyphCount); - font.textToGlyphs(fText, txtLen, kUTF8_SkTextEncoding, fGlyphs.begin(), glyphCount); + font.textToGlyphs(fText, txtLen, SkTextEncoding::kUTF8, fGlyphs.begin(), glyphCount); } SkString onShortName() override { diff --git a/gm/textblobblockreordering.cpp b/gm/textblobblockreordering.cpp index 692789a8b8..f7b3c4f24c 100644 --- a/gm/textblobblockreordering.cpp +++ b/gm/textblobblockreordering.cpp @@ -41,7 +41,7 @@ protected: const char* text = "AB"; SkRect bounds; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); SkScalar yOffset = bounds.height(); ToolUtils::add_to_text_blob(&builder, text, font, 0, yOffset - 30); diff --git a/gm/textblobcolortrans.cpp b/gm/textblobcolortrans.cpp index 4d0d2690d1..b41dd238bd 100644 --- a/gm/textblobcolortrans.cpp +++ b/gm/textblobcolortrans.cpp @@ -42,7 +42,7 @@ protected: const char* text = "AB"; SkRect bounds; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); SkScalar yOffset = bounds.height(); ToolUtils::add_to_text_blob(&builder, text, font, 0, yOffset - 30); @@ -50,7 +50,7 @@ protected: // A8 font.setSize(28); text = "The quick brown fox jumps over the lazy dog."; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); ToolUtils::add_to_text_blob(&builder, text, font, 0, yOffset - 8); // build diff --git a/gm/textbloblooper.cpp b/gm/textbloblooper.cpp index b67cc21334..7adc1c172e 100644 --- a/gm/textbloblooper.cpp +++ b/gm/textbloblooper.cpp @@ -52,8 +52,8 @@ static void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const SkTDArray glyphs; size_t len = strlen(text); - glyphs.append(font.countText(text, len, kUTF8_SkTextEncoding)); - font.textToGlyphs(text, len, kUTF8_SkTextEncoding, glyphs.begin(), glyphs.count()); + glyphs.append(font.countText(text, len, SkTextEncoding::kUTF8)); + font.textToGlyphs(text, len, SkTextEncoding::kUTF8, glyphs.begin(), glyphs.count()); const SkScalar advanceX = font.getSize() * 0.85f; const SkScalar advanceY = font.getSize() * 1.5f; diff --git a/gm/textblobmixedsizes.cpp b/gm/textblobmixedsizes.cpp index 2986682915..973c345fbd 100644 --- a/gm/textblobmixedsizes.cpp +++ b/gm/textblobmixedsizes.cpp @@ -55,35 +55,35 @@ protected: // large SkRect bounds; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); SkScalar yOffset = bounds.height(); font.setSize(162); ToolUtils::add_to_text_blob(&builder, text, font, 0, yOffset); // Medium - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); yOffset += bounds.height(); font.setSize(72); ToolUtils::add_to_text_blob(&builder, text, font, 0, yOffset); // Small - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); yOffset += bounds.height(); font.setSize(32); ToolUtils::add_to_text_blob(&builder, text, font, 0, yOffset); // micro (will fall out of distance field text even if distance field text is enabled) - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); yOffset += bounds.height(); font.setSize(14); ToolUtils::add_to_text_blob(&builder, text, font, 0, yOffset); // Zero size. - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); yOffset += bounds.height(); font.setSize(0); diff --git a/gm/textblobrandomfont.cpp b/gm/textblobrandomfont.cpp index 43ecae3189..0160a3eb4c 100644 --- a/gm/textblobrandomfont.cpp +++ b/gm/textblobrandomfont.cpp @@ -63,7 +63,7 @@ protected: SkScalar y = 0; SkRect bounds; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); y -= bounds.fTop; ToolUtils::add_to_text_blob(&builder, text, font, 0, y); y += bounds.fBottom; @@ -74,12 +74,12 @@ protected: font.setSize(160); font.setSubpixel(false); font.setEdging(SkFont::Edging::kAntiAlias); - font.measureText(bigtext1, strlen(bigtext1), kUTF8_SkTextEncoding, &bounds); + font.measureText(bigtext1, strlen(bigtext1), SkTextEncoding::kUTF8, &bounds); y -= bounds.fTop; ToolUtils::add_to_text_blob(&builder, bigtext1, font, 0, y); y += bounds.fBottom; - font.measureText(bigtext2, strlen(bigtext2), kUTF8_SkTextEncoding, &bounds); + font.measureText(bigtext2, strlen(bigtext2), SkTextEncoding::kUTF8, &bounds); y -= bounds.fTop; ToolUtils::add_to_text_blob(&builder, bigtext2, font, 0, y); y += bounds.fBottom; @@ -88,7 +88,7 @@ protected: if (sk_sp origEmoji = ToolUtils::emoji_typeface()) { font.setTypeface(sk_make_sp(origEmoji, paint, false)); const char* emojiText = ToolUtils::emoji_sample_text(); - font.measureText(emojiText, strlen(emojiText), kUTF8_SkTextEncoding, &bounds); + font.measureText(emojiText, strlen(emojiText), SkTextEncoding::kUTF8, &bounds); y -= bounds.fTop; ToolUtils::add_to_text_blob(&builder, emojiText, font, 0, y); y += bounds.fBottom; diff --git a/gm/textblobshader.cpp b/gm/textblobshader.cpp index 933a92b429..bc5ade6706 100644 --- a/gm/textblobshader.cpp +++ b/gm/textblobshader.cpp @@ -39,8 +39,8 @@ private: SkFont font(ToolUtils::create_portable_typeface()); const char* txt = "Blobber"; size_t txtLen = strlen(txt); - fGlyphs.append(font.countText(txt, txtLen, kUTF8_SkTextEncoding)); - font.textToGlyphs(txt, txtLen, kUTF8_SkTextEncoding, fGlyphs.begin(), fGlyphs.count()); + fGlyphs.append(font.countText(txt, txtLen, SkTextEncoding::kUTF8)); + font.textToGlyphs(txt, txtLen, SkTextEncoding::kUTF8, fGlyphs.begin(), fGlyphs.count()); } SkFont font; diff --git a/gm/textblobtransforms.cpp b/gm/textblobtransforms.cpp index 2c45819afe..d9ea8b46e9 100644 --- a/gm/textblobtransforms.cpp +++ b/gm/textblobtransforms.cpp @@ -38,7 +38,7 @@ protected: const char* text = "A"; SkRect bounds; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); ToolUtils::add_to_text_blob(&builder, text, font, 0, 0); // Medium @@ -47,7 +47,7 @@ protected: text = "B"; ToolUtils::add_to_text_blob(&builder, text, font, xOffset, 0); - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); SkScalar yOffset = bounds.height(); // Small diff --git a/gm/texteffects.cpp b/gm/texteffects.cpp index 6c82c2d616..ed11db183e 100644 --- a/gm/texteffects.cpp +++ b/gm/texteffects.cpp @@ -51,9 +51,9 @@ namespace { sk_sp MakeFancyBlob(const SkPaint& paint, const SkFont& font, const char* text) { const size_t textLen = strlen(text); - const int glyphCount = font.countText(text, textLen, kUTF8_SkTextEncoding); + const int glyphCount = font.countText(text, textLen, SkTextEncoding::kUTF8); SkAutoTArray glyphs(glyphCount); - font.textToGlyphs(text, textLen, kUTF8_SkTextEncoding, glyphs.get(), glyphCount); + font.textToGlyphs(text, textLen, SkTextEncoding::kUTF8, glyphs.get(), glyphCount); SkAutoTArray widths(glyphCount); font.getWidths(glyphs.get(), glyphCount, widths.get()); @@ -150,7 +150,7 @@ DEF_SIMPLE_GM(fancyblobunderline, canvas, 1480, 1380) { static sk_sp make_text(const SkFont& font, const SkGlyphID glyphs[], int count) { return SkTextBlob::MakeFromText(glyphs, count * sizeof(SkGlyphID), font, - kGlyphID_SkTextEncoding); + SkTextEncoding::kGlyphID); } static sk_sp make_posh(const SkFont& font, const SkGlyphID glyphs[], int count, @@ -161,7 +161,7 @@ static sk_sp make_posh(const SkFont& font, const SkGlyphID glyphs[], xpos[i] += spacing * i; } return SkTextBlob::MakeFromPosTextH(glyphs, count * sizeof(SkGlyphID), xpos.get(), 0, font, - kGlyphID_SkTextEncoding); + SkTextEncoding::kGlyphID); } static sk_sp make_pos(const SkFont& font, const SkGlyphID glyphs[], int count, @@ -172,7 +172,7 @@ static sk_sp make_pos(const SkFont& font, const SkGlyphID glyphs[], pos[i].fX += spacing * i; } return SkTextBlob::MakeFromPosText(glyphs, count * sizeof(SkGlyphID), pos.get(), font, - kGlyphID_SkTextEncoding); + SkTextEncoding::kGlyphID); } // widen the gaps with a margin (on each side of the gap), elimnating segments that go away @@ -241,9 +241,9 @@ DEF_SIMPLE_GM(textblob_intercepts, canvas, 940, 800) { font.setTypeface(ToolUtils::create_portable_typeface()); font.setSize(100); font.setEdging(SkFont::Edging::kAntiAlias); - const int count = font.countText(text, length, kUTF8_SkTextEncoding); + const int count = font.countText(text, length, SkTextEncoding::kUTF8); SkAutoTArray glyphs(count); - font.textToGlyphs(text, length, kUTF8_SkTextEncoding, glyphs.get(), count); + font.textToGlyphs(text, length, SkTextEncoding::kUTF8, glyphs.get(), count); auto b0 = make_text(font, glyphs.get(), count); diff --git a/gm/typeface.cpp b/gm/typeface.cpp index a34fbb29f5..4e58632e4d 100644 --- a/gm/typeface.cpp +++ b/gm/typeface.cpp @@ -54,13 +54,13 @@ static void drawKernText(SkCanvas* canvas, const void* text, size_t len, SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint) { SkTypeface* face = font.getTypefaceOrDefault(); if (!face) { - canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x, y, font, paint); return; } SkAutoSTMalloc<128, uint16_t> glyphStorage(len); uint16_t* glyphs = glyphStorage.get(); - int glyphCount = font.textToGlyphs(text, len, kUTF8_SkTextEncoding, glyphs, len); + int glyphCount = font.textToGlyphs(text, len, SkTextEncoding::kUTF8, glyphs, len); if (glyphCount < 1) { return; } @@ -68,7 +68,7 @@ static void drawKernText(SkCanvas* canvas, const void* text, size_t len, SkAutoSTMalloc<128, int32_t> adjustmentStorage(glyphCount - 1); int32_t* adjustments = adjustmentStorage.get(); if (!face->getKerningPairAdjustments(glyphs, glyphCount, adjustments)) { - canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x, y, font, paint); return; } @@ -137,7 +137,7 @@ protected: SkPaint paint; for (int i = 0; i < gStylesCount; i++) { font.setTypeface(fFaces[i]); - canvas->drawSimpleText(text, textLen, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, paint); if (fApplyKerning) { drawKernText(canvas, text, textLen, x + 240, y, font, paint); } @@ -245,12 +245,12 @@ static void draw_typeface_rendering_gm(SkCanvas* canvas, sk_sp face, canvas->rotate(2, x + subpixel.offset.x(), y + subpixel.offset.y()); } - canvas->drawSimpleText(&character, 1, kUTF8_SkTextEncoding, + canvas->drawSimpleText(&character, 1, SkTextEncoding::kUTF8, x + subpixel.offset.x(), y + subpixel.offset.y(), font, paint); SkScalar dx = SkScalarCeilToScalar( - font.measureText(&character, 1, kUTF8_SkTextEncoding)) + 5; + font.measureText(&character, 1, SkTextEncoding::kUTF8)) + 5; x += dx; xMax = SkTMax(x, xMax); } @@ -295,10 +295,10 @@ static void draw_typeface_rendering_gm(SkCanvas* canvas, sk_sp face, for (const StyleTests& style : styleTypes) { paint.setStyle(style.style); paint.setStrokeWidth(style.strokeWidth); - canvas->drawSimpleText(&character, 1, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(&character, 1, SkTextEncoding::kUTF8, x, y, font, paint); SkScalar dx = SkScalarCeilToScalar(font.measureText(&character, 1, - kUTF8_SkTextEncoding)) + 5; + SkTextEncoding::kUTF8)) + 5; x += dx; } } @@ -345,10 +345,10 @@ static void draw_typeface_rendering_gm(SkCanvas* canvas, sk_sp face, } for (const MaskTests& mask : maskTypes) { paint.setMaskFilter(SkMaskFilter::MakeBlur(mask.style, mask.sigma)); - canvas->drawSimpleText(&character, 1, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(&character, 1, SkTextEncoding::kUTF8, x, y, font, paint); SkScalar dx = SkScalarCeilToScalar(font.measureText(&character, 1, - kUTF8_SkTextEncoding)) + 5; + SkTextEncoding::kUTF8)) + 5; x += dx; } paint.setMaskFilter(nullptr); diff --git a/gm/variedtext.cpp b/gm/variedtext.cpp index 67388e05ba..37c6ac485e 100644 --- a/gm/variedtext.cpp +++ b/gm/variedtext.cpp @@ -94,7 +94,7 @@ protected: fFont.setTypeface(fTypefaces[fTypefaceIndices[i]]); fFont.setSize(fPtSizes[i]); - fFont.measureText(fStrings[i].c_str(), fStrings[i].size(), kUTF8_SkTextEncoding, &r); + fFont.measureText(fStrings[i].c_str(), fStrings[i].size(), SkTextEncoding::kUTF8, &r); // safeRect is set of x,y positions where we can draw the string without hitting // the GM's border. SkRect safeRect = SkRect::MakeLTRB(-r.fLeft, -r.fTop, w - r.fRight, h - r.fBottom); @@ -125,7 +125,7 @@ protected: canvas->save(); canvas->clipRect(fClipRects[i]); canvas->translate(fPositions[i].fX, fPositions[i].fY); - canvas->drawSimpleText(fStrings[i].c_str(), fStrings[i].size(), kUTF8_SkTextEncoding, + canvas->drawSimpleText(fStrings[i].c_str(), fStrings[i].size(), SkTextEncoding::kUTF8, 0, 0, fFont, fPaint); canvas->restore(); } diff --git a/gm/wacky_yuv_formats.cpp b/gm/wacky_yuv_formats.cpp index e5c679b25e..379c8171b6 100644 --- a/gm/wacky_yuv_formats.cpp +++ b/gm/wacky_yuv_formats.cpp @@ -740,14 +740,14 @@ static void draw_col_label(SkCanvas* canvas, int x, int yuvColorSpace, bool opaq SkString colLabel; colLabel.printf("%s", kYUVColorSpaceNames[yuvColorSpace]); - font.measureText(colLabel.c_str(), colLabel.size(), kUTF8_SkTextEncoding, &textRect); + font.measureText(colLabel.c_str(), colLabel.size(), SkTextEncoding::kUTF8, &textRect); int y = textRect.height(); SkTextUtils::DrawString(canvas, colLabel.c_str(), x, y, font, paint, SkTextUtils::kCenter_Align); colLabel.printf("%s", opaque ? "Opaque" : "Transparent"); - font.measureText(colLabel.c_str(), colLabel.size(), kUTF8_SkTextEncoding, &textRect); + font.measureText(colLabel.c_str(), colLabel.size(), SkTextEncoding::kUTF8, &textRect); y += textRect.height(); SkTextUtils::DrawString(canvas, colLabel.c_str(), x, y, font, paint, SkTextUtils::kCenter_Align); @@ -765,7 +765,7 @@ static void draw_row_label(SkCanvas* canvas, int y, int yuvFormat) { SkString rowLabel; rowLabel.printf("%s", kYUVFormatNames[yuvFormat]); - font.measureText(rowLabel.c_str(), rowLabel.size(), kUTF8_SkTextEncoding, &textRect); + font.measureText(rowLabel.c_str(), rowLabel.size(), SkTextEncoding::kUTF8, &textRect); y += kTileWidthHeight/2 + textRect.height()/2; canvas->drawString(rowLabel, 0, y, font, paint); diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 4706c59934..8129b025b5 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -1948,7 +1948,7 @@ public: */ void drawString(const char str[], SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint) { - this->drawSimpleText(str, strlen(str), kUTF8_SkTextEncoding, x, y, font, paint); + this->drawSimpleText(str, strlen(str), SkTextEncoding::kUTF8, x, y, font, paint); } /** Draws SkString, with origin at (x, y), using clip, SkMatrix, SkFont font, @@ -1977,7 +1977,7 @@ public: */ void drawString(const SkString& str, SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint) { - this->drawSimpleText(str.c_str(), str.size(), kUTF8_SkTextEncoding, x, y, font, paint); + this->drawSimpleText(str.c_str(), str.size(), SkTextEncoding::kUTF8, x, y, font, paint); } /** Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint. @@ -1988,7 +1988,7 @@ public: SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text, and SkPaint subpixel text. - SkTextEncoding must be set to kGlyphID_SkTextEncoding. + SkTextEncoding must be set to SkTextEncoding::kGlyphID. Elements of paint: anti-alias, SkBlendMode, color including alpha, SkColorFilter, SkPaint dither, SkDrawLooper, SkMaskFilter, SkPathEffect, SkShader, and @@ -2011,7 +2011,7 @@ public: SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text, and SkPaint subpixel text. - SkTextEncoding must be set to kGlyphID_SkTextEncoding. + SkTextEncoding must be set to SkTextEncoding::kGlyphID. 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 eabb8aa63d..f002af2614 100644 --- a/include/core/SkFont.h +++ b/include/core/SkFont.h @@ -272,7 +272,7 @@ public: If byteLength equals zero, returns zero. If byteLength includes a partial character, the partial character is ignored. - If encoding is kUTF8_SkTextEncoding and text contains an invalid UTF-8 sequence, + If encoding is SkTextEncoding::kUTF8 and text contains an invalid UTF-8 sequence, zero is returned. When encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or @@ -286,8 +286,8 @@ public: @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 + @param encoding one of: SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, + SkTextEncoding::kUTF32, SkTextEncoding::kGlyphID @param glyphs storage for glyph indices; may be nullptr @param maxGlyphCount storage capacity @return number of glyphs represented by text of length byteLength @@ -308,14 +308,14 @@ public: /** Returns number of glyphs represented by text. - If encoding is kUTF8_SkTextEncoding, kUTF16_SkTextEncoding, or - kUTF32_SkTextEncoding; then each Unicode codepoint is mapped to a + If encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or + SkTextEncoding::kUTF32; then each Unicode codepoint is mapped to a single glyph. @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 + @param encoding one of: SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, + SkTextEncoding::kUTF32, SkTextEncoding::kGlyphID @return number of glyphs represented by text of length byteLength */ int countText(const void* text, size_t byteLength, SkTextEncoding encoding) const { @@ -328,8 +328,8 @@ public: @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 + @param encoding one of: SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, + SkTextEncoding::kUTF32, SkTextEncoding::kGlyphID @param bounds returns bounding box relative to (0, 0) if not nullptr @return number of glyphs represented by text of length byteLength */ @@ -345,8 +345,8 @@ public: @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 + @param encoding one of: SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, + SkTextEncoding::kUTF32, SkTextEncoding::kGlyphID @param bounds returns bounding box relative to (0, 0) if not nullptr @param paint optional; may be nullptr @return number of glyphs represented by text of length byteLength diff --git a/include/core/SkTextBlob.h b/include/core/SkTextBlob.h index b73835b7c6..2c120d9d7c 100644 --- a/include/core/SkTextBlob.h +++ b/include/core/SkTextBlob.h @@ -77,7 +77,7 @@ public: @return SkTextBlob constructed from one run */ static sk_sp MakeFromText(const void* text, size_t byteLength, const SkFont& font, - SkTextEncoding encoding = kUTF8_SkTextEncoding); + SkTextEncoding encoding = SkTextEncoding::kUTF8); /** Creates SkTextBlob with a single run. string meaning depends on SkTextEncoding; by default, string is encoded as UTF-8. @@ -97,7 +97,7 @@ public: @return SkTextBlob constructed from one run */ static sk_sp MakeFromString(const char* string, const SkFont& font, - SkTextEncoding encoding = kUTF8_SkTextEncoding) { + SkTextEncoding encoding = SkTextEncoding::kUTF8) { if (!string) { return nullptr; } @@ -118,7 +118,7 @@ public: */ static sk_sp MakeFromPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkFont& font, - SkTextEncoding encoding = kUTF8_SkTextEncoding); + SkTextEncoding encoding = SkTextEncoding::kUTF8); /** Returns a textblob built from a single run of text with positions. This is equivalent to using SkTextBlobBuilder and calling allocRunPos(). @@ -133,11 +133,11 @@ public: */ static sk_sp MakeFromPosText(const void* text, size_t byteLength, const SkPoint pos[], const SkFont& font, - SkTextEncoding encoding = kUTF8_SkTextEncoding); + SkTextEncoding encoding = SkTextEncoding::kUTF8); static sk_sp MakeFromRSXform(const void* text, size_t byteLength, const SkRSXform xform[], const SkFont& font, - SkTextEncoding encoding = kUTF8_SkTextEncoding); + SkTextEncoding encoding = SkTextEncoding::kUTF8); /** Writes data to allow later reconstruction of SkTextBlob. memory points to storage to receive the encoded data, and memory_size describes the size of storage. diff --git a/include/utils/SkTextUtils.h b/include/utils/SkTextUtils.h index 9bff22abfc..6cd3771e3d 100644 --- a/include/utils/SkTextUtils.h +++ b/include/utils/SkTextUtils.h @@ -28,7 +28,7 @@ public: static void DrawString(SkCanvas* canvas, const char text[], SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint, Align align = kLeft_Align) { - Draw(canvas, text, strlen(text), kUTF8_SkTextEncoding, x, y, font, paint, align); + Draw(canvas, text, strlen(text), SkTextEncoding::kUTF8, x, y, font, paint, align); } static void GetPath(const void* text, size_t length, SkTextEncoding, SkScalar x, SkScalar y, diff --git a/modules/particles/src/SkParticleAffector.cpp b/modules/particles/src/SkParticleAffector.cpp index 80094ff239..e34306fca3 100644 --- a/modules/particles/src/SkParticleAffector.cpp +++ b/modules/particles/src/SkParticleAffector.cpp @@ -356,7 +356,7 @@ private: // Use the font manager's default font SkFont font(nullptr, fFontSize); SkPath path; - SkTextUtils::GetPath(fText.c_str(), fText.size(), kUTF8_SkTextEncoding, 0, 0, font, &path); + SkTextUtils::GetPath(fText.c_str(), fText.size(), SkTextEncoding::kUTF8, 0, 0, font, &path); SkContourMeasureIter iter(path, false); while (auto contour = iter.next()) { fContours.push_back(contour); diff --git a/modules/sksg/src/SkSGText.cpp b/modules/sksg/src/SkSGText.cpp index 2147640d27..e72f8d89f2 100644 --- a/modules/sksg/src/SkSGText.cpp +++ b/modules/sksg/src/SkSGText.cpp @@ -57,7 +57,7 @@ SkRect Text::onRevalidate(InvalidationController*, const SkMatrix&) { // 1) SkTextBlob has some trouble computing accurate bounds with alignment. // 2) SkPaint::Align is slated for deprecation. - fBlob = SkTextBlob::MakeFromText(fText.c_str(), fText.size(), font, kUTF8_SkTextEncoding); + fBlob = SkTextBlob::MakeFromText(fText.c_str(), fText.size(), font, SkTextEncoding::kUTF8); if (!fBlob) { return SkRect::MakeEmpty(); } diff --git a/modules/skshaper/src/SkShaper_harfbuzz.cpp b/modules/skshaper/src/SkShaper_harfbuzz.cpp index 9423732f5e..9cc1bb948b 100644 --- a/modules/skshaper/src/SkShaper_harfbuzz.cpp +++ b/modules/skshaper/src/SkShaper_harfbuzz.cpp @@ -125,7 +125,7 @@ unsigned skhb_nominal_glyphs(hb_font_t *hb_font, void *font_data, unicodes = SkTAddOffset(unicodes, unicode_stride); } SkAutoSTMalloc<256, SkGlyphID> glyph(count); - font.textToGlyphs(unicode.get(), count * sizeof(SkUnichar), kUTF32_SkTextEncoding, + font.textToGlyphs(unicode.get(), count * sizeof(SkUnichar), SkTextEncoding::kUTF32, glyph.get(), count); // Copy the results back to the sparse array. diff --git a/samplecode/SampleAAGeometry.cpp b/samplecode/SampleAAGeometry.cpp index 225d9bcde6..144141b949 100644 --- a/samplecode/SampleAAGeometry.cpp +++ b/samplecode/SampleAAGeometry.cpp @@ -540,7 +540,7 @@ struct Button { return; } canvas->drawRect(fBounds, paints.fStates[fState]); - SkTextUtils::Draw(canvas, &fLabel, 1, kUTF8_SkTextEncoding, fBounds.centerX(), fBounds.fBottom - 5, + SkTextUtils::Draw(canvas, &fLabel, 1, SkTextEncoding::kUTF8, fBounds.centerX(), fBounds.fBottom - 5, paints.fLabelFont, SkPaint(), SkTextUtils::kCenter_Align); } diff --git a/samplecode/SampleAnimatedImage.cpp b/samplecode/SampleAnimatedImage.cpp index d60325952a..eabce6b38d 100644 --- a/samplecode/SampleAnimatedImage.cpp +++ b/samplecode/SampleAnimatedImage.cpp @@ -38,10 +38,10 @@ protected: kPauseKey, kResetKey); const char* text = str.c_str(); SkRect bounds; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); fYOffset = bounds.height(); - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 5, fYOffset, font, SkPaint()); + canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 5, fYOffset, font, SkPaint()); fYOffset *= 2; } diff --git a/samplecode/SampleAnimatedText.cpp b/samplecode/SampleAnimatedText.cpp index 079eafca91..696be8db08 100644 --- a/samplecode/SampleAnimatedText.cpp +++ b/samplecode/SampleAnimatedText.cpp @@ -27,7 +27,7 @@ static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkSc const SkFont& font, const SkPaint& paint) { SkFont f(font); f.setSubpixel(true); - canvas->drawSimpleText(text, length, kUTF8_SkTextEncoding, x, y, f, paint); + canvas->drawSimpleText(text, length, SkTextEncoding::kUTF8, x, y, f, paint); } // This sample demonstrates the cache behavior of bitmap vs. distance field text diff --git a/samplecode/SampleAtlas.cpp b/samplecode/SampleAtlas.cpp index 22c8861eec..4ea32b3c99 100644 --- a/samplecode/SampleAtlas.cpp +++ b/samplecode/SampleAtlas.cpp @@ -57,7 +57,7 @@ static sk_sp make_atlas(int atlasSize, int cellSize) { paint.setColor(rand.nextU()); paint.setAlpha(0xFF); int index = i % strlen(s); - SkTextUtils::Draw(canvas, &s[index], 1, kUTF8_SkTextEncoding, + SkTextUtils::Draw(canvas, &s[index], 1, SkTextEncoding::kUTF8, x + half, y + half + half/2, font, paint, SkTextUtils::kCenter_Align); i += 1; diff --git a/samplecode/SampleBitmapRect.cpp b/samplecode/SampleBitmapRect.cpp index 2bc2ba0788..abbbc38b52 100644 --- a/samplecode/SampleBitmapRect.cpp +++ b/samplecode/SampleBitmapRect.cpp @@ -161,14 +161,14 @@ static void make_big_bitmap(SkBitmap* bm) { SkFont font; font.setSize(SkIntToScalar(BIG_H)); - const int BIG_W = SkScalarRoundToInt(font.measureText(gText, strlen(gText), kUTF8_SkTextEncoding)); + const int BIG_W = SkScalarRoundToInt(font.measureText(gText, strlen(gText), SkTextEncoding::kUTF8)); bm->allocN32Pixels(BIG_W, BIG_H); bm->eraseColor(SK_ColorWHITE); SkCanvas canvas(*bm); - canvas.drawSimpleText(gText, strlen(gText), kUTF8_SkTextEncoding, 0, font.getSize()*4/5, font, SkPaint()); + canvas.drawSimpleText(gText, strlen(gText), SkTextEncoding::kUTF8, 0, font.getSize()*4/5, font, SkPaint()); } class BitmapRectView2 : public Sample { diff --git a/samplecode/SampleChineseFling.cpp b/samplecode/SampleChineseFling.cpp index 1c2d7d343b..e9631f26a8 100644 --- a/samplecode/SampleChineseFling.cpp +++ b/samplecode/SampleChineseFling.cpp @@ -95,7 +95,7 @@ private: ToolUtils::add_to_text_blob_w_len(&builder, (const char*)glyphs, kWordLength * 4, - kUTF32_SkTextEncoding, + SkTextEncoding::kUTF32, font, 0, 0); @@ -224,7 +224,7 @@ private: ToolUtils::add_to_text_blob_w_len(&builder, (const char*)glyphs, currentLineLength * 4, - kUTF32_SkTextEncoding, + SkTextEncoding::kUTF32, font, 0, y); diff --git a/samplecode/SampleComplexClip.cpp b/samplecode/SampleComplexClip.cpp index 59065cbbf7..a898c37a05 100644 --- a/samplecode/SampleComplexClip.cpp +++ b/samplecode/SampleComplexClip.cpp @@ -129,14 +129,14 @@ protected: SkScalar txtX = SkIntToScalar(55); paint.setColor(colorA); const char* aTxt = invA ? "InverseA " : "A "; - canvas->drawSimpleText(aTxt, strlen(aTxt), kUTF8_SkTextEncoding, txtX, SkIntToScalar(220), font, paint); - txtX += font.measureText(aTxt, strlen(aTxt), kUTF8_SkTextEncoding); + canvas->drawSimpleText(aTxt, strlen(aTxt), SkTextEncoding::kUTF8, txtX, SkIntToScalar(220), font, paint); + txtX += font.measureText(aTxt, strlen(aTxt), SkTextEncoding::kUTF8); paint.setColor(SK_ColorBLACK); - canvas->drawSimpleText(gOps[op].fName, strlen(gOps[op].fName), kUTF8_SkTextEncoding, + canvas->drawSimpleText(gOps[op].fName, strlen(gOps[op].fName), SkTextEncoding::kUTF8, txtX, 220, font, paint); - txtX += font.measureText(gOps[op].fName, strlen(gOps[op].fName), kUTF8_SkTextEncoding); + txtX += font.measureText(gOps[op].fName, strlen(gOps[op].fName), SkTextEncoding::kUTF8); paint.setColor(colorB); - canvas->drawSimpleText("B", 1, kUTF8_SkTextEncoding, txtX, 220, font, paint); + canvas->drawSimpleText("B", 1, SkTextEncoding::kUTF8, txtX, 220, font, paint); canvas->translate(SkIntToScalar(250),0); } diff --git a/samplecode/SampleCusp.cpp b/samplecode/SampleCusp.cpp index b287bbda6b..59e5a62b61 100644 --- a/samplecode/SampleCusp.cpp +++ b/samplecode/SampleCusp.cpp @@ -167,7 +167,7 @@ protected: canvas->drawPath(path, p); // draw time to make it easier to guess when the bad cubic was drawn std::string timeStr = std::to_string((float) (curTime - start) / 1000.f); - canvas->drawSimpleText(timeStr.c_str(), timeStr.size(), kUTF8_SkTextEncoding, 20, 20, SkFont(), SkPaint()); + canvas->drawSimpleText(timeStr.c_str(), timeStr.size(), SkTextEncoding::kUTF8, 20, 20, SkFont(), SkPaint()); SkDebugf(""); } diff --git a/samplecode/SampleFontCache.cpp b/samplecode/SampleFontCache.cpp index d9f4f046ce..75d35b8d4d 100644 --- a/samplecode/SampleFontCache.cpp +++ b/samplecode/SampleFontCache.cpp @@ -17,7 +17,7 @@ static void call_measure() { SkRandom rand; paint.setAntiAlias(true); - paint.setTextEncoding(kUTF16_SkTextEncoding); + paint.setTextEncoding(SkTextEncoding::kUTF16); for (int j = 0; j < SK_ARRAY_COUNT(text); j++) text[j] = (uint16_t)((rand.nextU() & 0xFF) + 32); @@ -36,7 +36,7 @@ static void call_draw(SkCanvas* canvas) { SkRandom rand; paint.setAntiAlias(true); - paint.setTextEncoding(kUTF16_SkTextEncoding); + paint.setTextEncoding(SkTextEncoding::kUTF16); for (int j = 0; j < SK_ARRAY_COUNT(text); j++) text[j] = (uint16_t)((rand.nextU() & 0xFF) + 32); diff --git a/samplecode/SampleGlyphTransform.cpp b/samplecode/SampleGlyphTransform.cpp index 35058e0eaf..c81939b546 100644 --- a/samplecode/SampleGlyphTransform.cpp +++ b/samplecode/SampleGlyphTransform.cpp @@ -55,8 +55,8 @@ protected: // d3 by default anchors text around the middle SkRect bounds; - font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds); - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, -bounds.centerX(), -bounds.centerY(), + font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); + canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, -bounds.centerX(), -bounds.centerY(), font, paint); } diff --git a/samplecode/SampleLCD.cpp b/samplecode/SampleLCD.cpp index 22452285a8..979dcb7ee8 100644 --- a/samplecode/SampleLCD.cpp +++ b/samplecode/SampleLCD.cpp @@ -46,9 +46,9 @@ protected: textSize += delta; font.setEdging(SkFont::Edging::kAntiAlias); - canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, x0, y, font, paint); + canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x0, y, font, paint); font.setEdging(SkFont::Edging::kSubpixelAntiAlias); - canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, x1, y, font, paint); + canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x1, y, font, paint); y += font.getSpacing(); } diff --git a/samplecode/SampleQuadStroker.cpp b/samplecode/SampleQuadStroker.cpp index c4e08bcbda..702628540b 100644 --- a/samplecode/SampleQuadStroker.cpp +++ b/samplecode/SampleQuadStroker.cpp @@ -509,7 +509,7 @@ protected: paint.setStyle(SkPaint::kFill_Style); SkFont font; font.setSize(25.0f); - SkTextUtils::Draw(canvas, &button.fLabel, 1, kUTF8_SkTextEncoding, + SkTextUtils::Draw(canvas, &button.fLabel, 1, SkTextEncoding::kUTF8, button.fBounds.centerX(), button.fBounds.fBottom - 5, font, paint, SkTextUtils::kCenter_Align); } @@ -682,7 +682,7 @@ protected: path.reset(); SkFont font; font.setSize(fTextSize); - SkTextUtils::GetPath(fText.c_str(), fText.size(), kUTF8_SkTextEncoding, + SkTextUtils::GetPath(fText.c_str(), fText.size(), SkTextEncoding::kUTF8, 0, fTextSize, font, &path); setForText(); draw_stroke(canvas, path, width * fWidthScale / fTextSize, fTextSize, true); diff --git a/samplecode/SampleRegion.cpp b/samplecode/SampleRegion.cpp index b0cf062091..4bd601de87 100644 --- a/samplecode/SampleRegion.cpp +++ b/samplecode/SampleRegion.cpp @@ -61,14 +61,14 @@ static void drawFadingText(SkCanvas* canvas, SkFontMetrics fm; font.getMetrics(&fm); - bounds.set(x, y + fm.fTop, x + font.measureText(text, len, kUTF8_SkTextEncoding), y + fm.fBottom); + bounds.set(x, y + fm.fTop, x + font.measureText(text, len, SkTextEncoding::kUTF8), y + fm.fBottom); // may need to outset bounds a little, to account for hinting and/or // antialiasing bounds.inset(-SkIntToScalar(2), -SkIntToScalar(2)); canvas->saveLayer(&bounds, nullptr); - canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(text, len, SkTextEncoding::kUTF8, x, y, font, paint); const SkPoint pts[] = { { bounds.fLeft, y }, @@ -100,17 +100,18 @@ static void test_text(SkCanvas* canvas) { SkScalar x = 20; SkScalar y = 20; - canvas->drawSimpleText(str, len, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(str, len, SkTextEncoding::kUTF8, x, y, font, paint); y += 20; - const SkPoint pts[] = { { x, y }, { x + font.measureText(str, len, kUTF8_SkTextEncoding), y } }; + const SkPoint pts[] = { { x , y }, + { x + font.measureText(str, len, SkTextEncoding::kUTF8), y } }; const SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 }; const SkScalar pos[] = { 0, 0.9f, 1 }; paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, SK_ARRAY_COUNT(colors), SkTileMode::kClamp)); - canvas->drawSimpleText(str, len, kUTF8_SkTextEncoding, x, y, font, paint); + canvas->drawSimpleText(str, len, SkTextEncoding::kUTF8, x, y, font, paint); y += 20; paint.setShader(nullptr); @@ -189,7 +190,7 @@ protected: paint.setColor(hilite ? SK_ColorRED : 0x40FF0000); SkFont font; font.setSize(SkIntToScalar(20)); - canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, loc.fX, loc.fY, font, paint); + canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, loc.fX, loc.fY, font, paint); } void drawPredicates(SkCanvas* canvas, const SkPoint pts[]) { @@ -316,7 +317,7 @@ protected: canvas->translate(0, SkIntToScalar(200)); for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); op++) { - canvas->drawSimpleText(gOps[op].fName, strlen(gOps[op].fName), kUTF8_SkTextEncoding, + canvas->drawSimpleText(gOps[op].fName, strlen(gOps[op].fName), SkTextEncoding::kUTF8, SkIntToScalar(75), SkIntToScalar(50), font, SkPaint()); this->drawRgnOped(canvas, gOps[op].fOp, gOps[op].fColor); diff --git a/samplecode/SampleTextEffects.cpp b/samplecode/SampleTextEffects.cpp index 4893936c55..a5b6453726 100644 --- a/samplecode/SampleTextEffects.cpp +++ b/samplecode/SampleTextEffects.cpp @@ -135,7 +135,7 @@ protected: SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); SkPath path, dstPath; - SkTextUtils::GetPath(s.c_str(), s.size(), kUTF8_SkTextEncoding, x, y, font, &path); + SkTextUtils::GetPath(s.c_str(), s.size(), SkTextEncoding::kUTF8, x, y, font, &path); pe->filterPath(&dstPath, path, &rec, nullptr); SkPaint paint; diff --git a/site/user/api/SkCanvas_Reference.md b/site/user/api/SkCanvas_Reference.md index 206a3ce900..e661f08715 100644 --- a/site/user/api/SkCanvas_Reference.md +++ b/site/user/api/SkCanvas_Reference.md @@ -5225,7 +5225,7 @@ Draws Text_Blob b and Font_Subpixel . -Paint_Text_Encoding must be set to kGlyphID_SkTextEncoding. +Paint_Text_Encoding must be set to SkTextEncoding::kGlyphID. Elements of paint: Anti_Alias, Blend_Mode, Color including Color_Alpha, Color_Filter, Paint_Dither, Draw_Looper, Mask_Filter, Path_Effect, Shader, and @@ -5273,7 +5273,7 @@ Draws Text_Blob Font_Subpixel . -Paint_Text_Encoding must be set to kGlyphID_SkTextEncoding. +Paint_Text_Encoding must be set to SkTextEncoding::kGlyphID. Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter, Image_Filter, and Draw_Looper; apply to blob. diff --git a/site/user/api/SkFont_Reference.md b/site/user/api/SkFont_Reference.md index fb55705dfa..3c02881cab 100644 --- a/site/user/api/SkFont_Reference.md +++ b/site/user/api/SkFont_Reference.md @@ -948,7 +948,7 @@ Does not check text for valid character If byteLength equals zero, returns zero. If byteLength includes a partial character, the partial character is ignored. -If encoding is kUTF8_SkTextEncoding and text contains an invalid UTF-8 sequence, +If encoding is SkTextEncoding::kUTF8 and text contains an invalid UTF-8 sequence, zero is returned. If maxGlyphCount is not sufficient to store all the glyphs, no glyphs are copied. @@ -963,11 +963,11 @@ The total glyph count is returned for subsequen length of character storage in bytes encoding - one of: kUTF8_SkTextEncoding, kUTF16_SkTextEncoding, + one of: SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, -kUTF32_SkTextEncoding, kGlyphID_SkTextEncoding +SkTextEncoding::kUTF32, SkTextEncoding::kGlyphID ### Parameters @@ -1039,11 +1039,11 @@ Returns number of glyphs represented by length of character storage in bytes encoding - one of: kUTF8_SkTextEncoding, kUTF16_SkTextEncoding, + one of: SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, -kUTF32_SkTextEncoding, kGlyphID_SkTextEncoding +SkTextEncoding::kUTF32, SkTextEncoding::kGlyphID ### Return Value @@ -1069,7 +1069,7 @@ Returns true if all text corresponds to Returns false if any characters in text are not supported in SkTypeface. -If SkTextEncoding is kGlyphID_SkTextEncoding, +If SkTextEncoding is SkTextEncoding::kGlyphID, returns true if all glyph indices in text are non-zero; does not check to see if text contains valid glyph indices for SkTypeface. @@ -1172,11 +1172,11 @@ Returns the bounding box of text if length of character storage in bytes encoding - one of: kUTF8_SkTextEncoding, kUTF16_SkTextEncoding, + one of: SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, -kUTF32_SkTextEncoding, kGlyphID_SkTextEncoding +SkTextEncoding::kUTF32, SkTextEncoding::kGlyphID ### Parameters diff --git a/site/user/api/SkPaint_Reference.md b/site/user/api/SkPaint_Reference.md index 76fccba90a..b6169b4e3f 100644 --- a/site/user/api/SkPaint_Reference.md +++ b/site/user/api/SkPaint_Reference.md @@ -219,7 +219,7 @@ Constructs Paint with default values. | Path_Effect | nullptr | | Shader | nullptr | | Style | kFill_Style | -| Text_Encoding | kUTF8_SkTextEncoding | +| Text_Encoding | SkTextEncoding::kUTF8 | | Typeface | nullptr | | Stroke_Cap | kButt_Cap | | Stroke_Join | kMiter_Join | @@ -3552,8 +3552,8 @@ the text encoding #### Example Output ~~~~ -kUTF8_SkTextEncoding == text encoding -kGlyphID_SkTextEncoding == text encoding +SkTextEncoding::kUTF8 == text encoding +SkTextEncoding::kGlyphID == text encoding ~~~~ @@ -3680,7 +3680,7 @@ Does not check text for valid character If byteLength equals zero, returns zero. If byteLength includes a partial character, the partial character is ignored. -If SkTextEncoding is kUTF8_SkTextEncoding and +If SkTextEncoding is SkTextEncoding::kUTF8 and text contains an invalid UTF-8 sequence, zero is returned. ### Parameters @@ -3754,7 +3754,7 @@ Returns true if all text corresponds to Returns false if any characters in text are not supported in SkTypeface. -If SkTextEncoding is kGlyphID_SkTextEncoding, +If SkTextEncoding is SkTextEncoding::kGlyphID, returns true if all glyph indices in text are non-zero; does not check to see if text contains valid glyph indices for SkTypeface. @@ -3816,7 +3816,7 @@ void glyphsToUnichars(const glyphs into text if possible. Glyph values without direct Unicode equivalents are mapped to zero. Uses the SkTypeface, but is unaffected -by SkTextEncoding; the text values returned are equivalent to kUTF32_SkTextEncoding. +by SkTextEncoding; the text values returned are equivalent to SkTextEncoding::kUTF32. Only supported on platforms that use FreeType as the font engine. diff --git a/site/user/api/SkTextBlob_Reference.md b/site/user/api/SkTextBlob_Reference.md index dee6ea0b2f..4e49078ead 100644 --- a/site/user/api/SkTextBlob_Reference.md +++ b/site/user/api/SkTextBlob_Reference.md @@ -14,9 +14,9 @@ class SkTextBlob final : public getIntercepts(const SkScalar bounds[2], SkScalar intervals[], const SkPaint* paint = nullptr) const; static sk_sp<SkTextBlob> MakeFromText(const void* text, size_t byteLength, const SkFont& font, - SkTextEncoding encoding = kUTF8_SkTextEncoding); + SkTextEncoding encoding = SkTextEncoding::kUTF8); static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkFont& font, - SkTextEncoding encoding = kUTF8_SkTextEncoding); + SkTextEncoding encoding = SkTextEncoding::kUTF8); size_t serialize(const SkSerialProcs& procs, void* memory, size_t memory_size) const; sk_sp<SkData> serialize(const SkSerialProcs& procs) const; static sk_sp<SkTextBlob> Deserialize(const void* data, size_t size, @@ -125,7 +125,7 @@ number of intersections; may be zero
 static sk_sp<SkTextBlob> MakeFromText(const void* text, size_t byteLength, const SkFont& font,
-                                      SkTextEncoding encoding = kUTF8_SkTextEncoding)
+                                      SkTextEncoding encoding = SkTextEncoding::kUTF8)
 
Creates Text_Blob with a single run. text meaning depends on Text_Encoding; @@ -149,8 +149,8 @@ and Font_Subpixel text size, typeface, text scale, and so on, used to draw encoding - one of: kUTF8_SkTextEncoding, kUTF16_SkTextEncoding, -kUTF32_SkTextEncoding, kGlyphID_SkTextEncoding + one of: SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, +SkTextEncoding::kUTF32, SkTextEncoding::kGlyphID @@ -173,7 +173,7 @@ and Font_Subpixel
 static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkFont& font,
-                                        SkTextEncoding encoding = kUTF8_SkTextEncoding)
+                                        SkTextEncoding encoding = SkTextEncoding::kUTF8)
 
Creates Text_Blob with a single run. string meaning depends on Text_Encoding; @@ -194,8 +194,8 @@ and Font_Subpixel text size, typeface, text scale, and so on, used to draw encoding - one of: kUTF8_SkTextEncoding, kUTF16_SkTextEncoding, -kUTF32_SkTextEncoding, kGlyphID_SkTextEncoding + one of: SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, +SkTextEncoding::kUTF32, SkTextEncoding::kGlyphID diff --git a/site/user/api/catalog.htm b/site/user/api/catalog.htm index b578bb918a..2f001a8cd9 100644 --- a/site/user/api/catalog.htm +++ b/site/user/api/catalog.htm @@ -1401,7 +1401,7 @@ "stdout": "[ 1.0000 0.0000 3.0000][ 0.0000 2.0000 4.0000][ 0.0000 0.0000 1.0000]\\n" }, "SkPaint_containsText": { - "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n const uint16_t goodGlyph = 511;\n const uint16_t zeroGlyph = 0;\n const uint16_t badGlyph = 65535; // larger than glyph count in font\n paint.setTextEncoding(kGlyphID_SkTextEncoding);\n SkDebugf(\"0x%04x %c= has glyph\\n\", goodGlyph,\n paint.containsText(&goodGlyph, 2) ? '=' : '!');\n SkDebugf(\"0x%04x %c= has glyph\\n\", zeroGlyph,\n paint.containsText(&zeroGlyph, 2) ? '=' : '!');\n SkDebugf(\"0x%04x %c= has glyph\\n\", badGlyph,\n paint.containsText(&badGlyph, 2) ? '=' : '!');\n}", + "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n const uint16_t goodGlyph = 511;\n const uint16_t zeroGlyph = 0;\n const uint16_t badGlyph = 65535; // larger than glyph count in font\n paint.setTextEncoding(SkTextEncoding::kGlyphID);\n SkDebugf(\"0x%04x %c= has glyph\\n\", goodGlyph,\n paint.containsText(&goodGlyph, 2) ? '=' : '!');\n SkDebugf(\"0x%04x %c= has glyph\\n\", zeroGlyph,\n paint.containsText(&zeroGlyph, 2) ? '=' : '!');\n SkDebugf(\"0x%04x %c= has glyph\\n\", badGlyph,\n paint.containsText(&badGlyph, 2) ? '=' : '!');\n}", "hash": "6a68cb3c8b81a5976c81ee004f559247", "file": "SkPaint_Reference", "name": "SkPaint::containsText", @@ -1576,11 +1576,11 @@ "stdout": "SkPaint::kFill_Style == paint.getStyle()\\n" }, "SkPaint_getTextEncoding": { - "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n SkDebugf(\"kUTF8_SkTextEncoding %c= text encoding\\n\",\n kUTF8_SkTextEncoding == paint.getTextEncoding() ? '=' : '!');\n paint.setTextEncoding(kGlyphID_SkTextEncoding);\n SkDebugf(\"kGlyphID_SkTextEncoding %c= text encoding\\n\",\n kGlyphID_SkTextEncoding == paint.getTextEncoding() ? '=' : '!');\n}", + "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n SkDebugf(\"SkTextEncoding::kUTF8 %c= text encoding\\n\",\n SkTextEncoding::kUTF8 == paint.getTextEncoding() ? '=' : '!');\n paint.setTextEncoding(SkTextEncoding::kGlyphID);\n SkDebugf(\"SkTextEncoding::kGlyphID %c= text encoding\\n\",\n SkTextEncoding::kGlyphID == paint.getTextEncoding() ? '=' : '!');\n}", "hash": "0d21e968e9a4c78c902ae3ef494941a0", "file": "SkPaint_Reference", "name": "SkPaint::getTextEncoding", - "stdout": "kUTF8_SkTextEncoding == text encoding\\nkGlyphID_SkTextEncoding == text encoding\\n" + "stdout": "SkTextEncoding::kUTF8 == text encoding\\nSkTextEncoding::kGlyphID == text encoding\\n" }, "SkPaint_getTextScaleX": { "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n SkDebugf(\"1 %c= default text scale x\\n\", 1 == paint.getTextScaleX() ? '=' : '!');\n}", @@ -3564,7 +3564,7 @@ "stdout": "blob equals nullptr" }, "SkTextBlobBuilder_make": { - "code": "void draw(SkCanvas* canvas) {\n SkTextBlobBuilder builder;\n sk_sp blob = builder.make();\n SkDebugf(\"blob \" \"%s\" \" nullptr\\n\", blob == nullptr ? \"equals\" : \"does not equal\");\n SkPaint paint;\n paint.setTextEncoding(kGlyphID_SkTextEncoding);\n SkFont font;\n paint.textToGlyphs(\"x\", 1, builder.allocRun(font, 1, 20, 20).glyphs);\n blob = builder.make();\n SkDebugf(\"blob \" \"%s\" \" nullptr\\n\", blob == nullptr ? \"equals\" : \"does not equal\");\n blob = builder.make();\n SkDebugf(\"blob \" \"%s\" \" nullptr\\n\", blob == nullptr ? \"equals\" : \"does not equal\");\n}", + "code": "void draw(SkCanvas* canvas) {\n SkTextBlobBuilder builder;\n sk_sp blob = builder.make();\n SkDebugf(\"blob \" \"%s\" \" nullptr\\n\", blob == nullptr ? \"equals\" : \"does not equal\");\n SkPaint paint;\n paint.setTextEncoding(SkTextEncoding::kGlyphID);\n SkFont font;\n paint.textToGlyphs(\"x\", 1, builder.allocRun(font, 1, 20, 20).glyphs);\n blob = builder.make();\n SkDebugf(\"blob \" \"%s\" \" nullptr\\n\", blob == nullptr ? \"equals\" : \"does not equal\");\n blob = builder.make();\n SkDebugf(\"blob \" \"%s\" \" nullptr\\n\", blob == nullptr ? \"equals\" : \"does not equal\");\n}", "hash": "34c37c0212cc0aef670d96945d08fe24", "file": "SkTextBlobBuilder_Reference", "name": "SkTextBlobBuilder::make()", @@ -4245,7 +4245,7 @@ "name": "Stroke_Width" }, "Paint_Text_Encoding": { - "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n const char hello8[] = \"Hello\" \"\\xE2\" \"\\x98\" \"\\xBA\";\n const uint16_t hello16[] = { 'H', 'e', 'l', 'l', 'o', 0x263A };\n const uint32_t hello32[] = { 'H', 'e', 'l', 'l', 'o', 0x263A };\n paint.setTextSize(24);\n canvas->drawText(hello8, sizeof(hello8) - 1, 10, 30, paint);\n paint.setTextEncoding(kUTF16_SkTextEncoding);\n canvas->drawText(hello16, sizeof(hello16), 10, 60, paint);\n paint.setTextEncoding(kUTF32_SkTextEncoding);\n canvas->drawText(hello32, sizeof(hello32), 10, 90, paint);\n uint16_t glyphs[SK_ARRAY_COUNT(hello32)];\n paint.textToGlyphs(hello32, sizeof(hello32), glyphs);\n paint.setTextEncoding(kGlyphID_SkTextEncoding);\n canvas->drawText(glyphs, sizeof(glyphs), 10, 120, paint);\n}\n", + "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n const char hello8[] = \"Hello\" \"\\xE2\" \"\\x98\" \"\\xBA\";\n const uint16_t hello16[] = { 'H', 'e', 'l', 'l', 'o', 0x263A };\n const uint32_t hello32[] = { 'H', 'e', 'l', 'l', 'o', 0x263A };\n paint.setTextSize(24);\n canvas->drawText(hello8, sizeof(hello8) - 1, 10, 30, paint);\n paint.setTextEncoding(SkTextEncoding::kUTF16);\n canvas->drawText(hello16, sizeof(hello16), 10, 60, paint);\n paint.setTextEncoding(SkTextEncoding::kUTF32);\n canvas->drawText(hello32, sizeof(hello32), 10, 90, paint);\n uint16_t glyphs[SK_ARRAY_COUNT(hello32)];\n paint.textToGlyphs(hello32, sizeof(hello32), glyphs);\n paint.setTextEncoding(SkTextEncoding::kGlyphID);\n canvas->drawText(glyphs, sizeof(glyphs), 10, 120, paint);\n}\n", "width": 256, "height": 128, "hash": "767fa4e7b6300e16a419f9881f0f9d3d", @@ -5237,7 +5237,7 @@ "name": "SkCanvas::drawText" }, "SkCanvas_drawTextBlob": { - "code": "void draw(SkCanvas* canvas) {\n SkTextBlobBuilder textBlobBuilder;\n const char bunny[] = \"/(^x^)\\\\\";\n const int len = sizeof(bunny) - 1;\n uint16_t glyphs[len];\n SkPaint paint;\n paint.textToGlyphs(bunny, len, glyphs);\n paint.setTextEncoding(kGlyphID_SkTextEncoding);\n SkFont font;\n int runs[] = { 3, 1, 3 };\n SkPoint textPos = { 20, 100 };\n int glyphIndex = 0;\n for (auto runLen : runs) {\n font.setSize(1 == runLen ? 20 : 50);\n const SkTextBlobBuilder::RunBuffer& run =\n textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY);\n memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);\n paint.setTextSize(1 == runLen ? 20 : 50);\n textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);\n glyphIndex += runLen;\n }\n sk_sp blob = textBlobBuilder.make();\n paint.reset();\n canvas->drawTextBlob(blob.get(), 0, 0, paint);\n}\n", + "code": "void draw(SkCanvas* canvas) {\n SkTextBlobBuilder textBlobBuilder;\n const char bunny[] = \"/(^x^)\\\\\";\n const int len = sizeof(bunny) - 1;\n uint16_t glyphs[len];\n SkPaint paint;\n paint.textToGlyphs(bunny, len, glyphs);\n paint.setTextEncoding(SkTextEncoding::kGlyphID);\n SkFont font;\n int runs[] = { 3, 1, 3 };\n SkPoint textPos = { 20, 100 };\n int glyphIndex = 0;\n for (auto runLen : runs) {\n font.setSize(1 == runLen ? 20 : 50);\n const SkTextBlobBuilder::RunBuffer& run =\n textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY);\n memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);\n paint.setTextSize(1 == runLen ? 20 : 50);\n textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);\n glyphIndex += runLen;\n }\n sk_sp blob = textBlobBuilder.make();\n paint.reset();\n canvas->drawTextBlob(blob.get(), 0, 0, paint);\n}\n", "width": 256, "height": 120, "hash": "005502b502c1282cb8d306d6c8d998fb", @@ -7437,7 +7437,7 @@ "name": "SkPaint::getTextWidths" }, "SkPaint_glyphsToUnichars": { - "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n const char hello[] = \"Hello!\";\n const int count = sizeof(hello) - 1;\n SkGlyphID glyphs[count];\n if (count != paint.textToGlyphs(hello, count, glyphs)) {\n return;\n }\n SkUnichar unichars[count];\n paint.glyphsToUnichars(glyphs, count, unichars);\n paint.setTextEncoding(kUTF32_SkTextEncoding);\n canvas->drawText(unichars, sizeof(unichars), 10, 30, paint);\n}\n", + "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n const char hello[] = \"Hello!\";\n const int count = sizeof(hello) - 1;\n SkGlyphID glyphs[count];\n if (count != paint.textToGlyphs(hello, count, glyphs)) {\n return;\n }\n SkUnichar unichars[count];\n paint.glyphsToUnichars(glyphs, count, unichars);\n paint.setTextEncoding(SkTextEncoding::kUTF32);\n canvas->drawText(unichars, sizeof(unichars), 10, 30, paint);\n}\n", "width": 256, "height": 64, "hash": "79c550ec6c34054ab60fbcd1b81adc03", @@ -7541,7 +7541,7 @@ "name": "SkPaint::setTypeface" }, "SkPaint_textToGlyphs": { - "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 };\n std::vector glyphs;\n int count = paint.textToGlyphs(utf8, sizeof(utf8), nullptr);\n glyphs.resize(count);\n (void) paint.textToGlyphs(utf8, sizeof(utf8), &glyphs.front());\n paint.setTextEncoding(kGlyphID_SkTextEncoding);\n paint.setTextSize(32);\n canvas->drawText(&glyphs.front(), glyphs.size() * sizeof(SkGlyphID), 10, 40, paint);\n}\n", + "code": "void draw(SkCanvas* canvas) {\n SkPaint paint;\n const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 };\n std::vector glyphs;\n int count = paint.textToGlyphs(utf8, sizeof(utf8), nullptr);\n glyphs.resize(count);\n (void) paint.textToGlyphs(utf8, sizeof(utf8), &glyphs.front());\n paint.setTextEncoding(SkTextEncoding::kGlyphID);\n paint.setTextSize(32);\n canvas->drawText(&glyphs.front(), glyphs.size() * sizeof(SkGlyphID), 10, 40, paint);\n}\n", "width": 256, "height": 64, "hash": "d11136d8a74f63009da2a7f550710823", @@ -9333,7 +9333,7 @@ "name": "SkTextBlob::MakeFromText" }, "SkTextBlob_bounds": { - "code": "void draw(SkCanvas* canvas) {\n SkTextBlobBuilder textBlobBuilder;\n const char bunny[] = \"/(^x^)\\\\\";\n const int len = sizeof(bunny) - 1;\n uint16_t glyphs[len];\n SkPaint paint;\n paint.textToGlyphs(bunny, len, glyphs);\n paint.setTextEncoding(kGlyphID_SkTextEncoding);\n SkFont font;\n int runs[] = { 3, 1, 3 };\n SkPoint textPos = { 20, 50 };\n int glyphIndex = 0;\n for (auto runLen : runs) {\n font.setSize(1 == runLen ? 20 : 50);\n paint.setTextSize(1 == runLen ? 20 : 50);\n const SkTextBlobBuilder::RunBuffer& run =\n textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY);\n memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);\n textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);\n glyphIndex += runLen;\n }\n sk_sp blob = textBlobBuilder.make();\n canvas->drawTextBlob(blob.get(), 0, 0, paint);\n paint.setStyle(SkPaint::kStroke_Style);\n canvas->drawRect(blob->bounds(), paint);\n}", + "code": "void draw(SkCanvas* canvas) {\n SkTextBlobBuilder textBlobBuilder;\n const char bunny[] = \"/(^x^)\\\\\";\n const int len = sizeof(bunny) - 1;\n uint16_t glyphs[len];\n SkPaint paint;\n paint.textToGlyphs(bunny, len, glyphs);\n paint.setTextEncoding(SkTextEncoding::kGlyphID);\n SkFont font;\n int runs[] = { 3, 1, 3 };\n SkPoint textPos = { 20, 50 };\n int glyphIndex = 0;\n for (auto runLen : runs) {\n font.setSize(1 == runLen ? 20 : 50);\n paint.setTextSize(1 == runLen ? 20 : 50);\n const SkTextBlobBuilder::RunBuffer& run =\n textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY);\n memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);\n textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);\n glyphIndex += runLen;\n }\n sk_sp blob = textBlobBuilder.make();\n canvas->drawTextBlob(blob.get(), 0, 0, paint);\n paint.setStyle(SkPaint::kStroke_Style);\n canvas->drawRect(blob->bounds(), paint);\n}", "width": 256, "height": 70, "hash": "fb8b2502bbe52d2029aecdf569dd9fdb", @@ -9357,7 +9357,7 @@ "name": "SkTextBlob::serialize_2" }, "SkTextBlob_uniqueID": { - "code": "void draw(SkCanvas* canvas) {\n for (int index = 0; index < 2; ++index) {\n SkTextBlobBuilder textBlobBuilder;\n const char bunny[] = \"/(^x^)\\\\\";\n const int len = sizeof(bunny) - 1;\n uint16_t glyphs[len];\n SkPaint paint;\n paint.textToGlyphs(bunny, len, glyphs);\n paint.setTextEncoding(kGlyphID_SkTextEncoding);\n paint.setTextScaleX(0.5);\n SkFont font;\n font.setScaleX(0.5);\n int runs[] = { 3, 1, 3 };\n SkPoint textPos = { 20, 50 };\n int glyphIndex = 0;\n for (auto runLen : runs) {\n font.setSize(1 == runLen ? 20 : 50);\n paint.setTextSize(1 == runLen ? 20 : 50);\n const SkTextBlobBuilder::RunBuffer& run =\n textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY);\n memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);\n textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);\n glyphIndex += runLen;\n }\n sk_sp blob = textBlobBuilder.make();\n paint.reset();\n canvas->drawTextBlob(blob.get(), 0, 0, paint);\n std::string id = \"unique ID:\" + std::to_string(blob->uniqueID());\n canvas->drawString(id.c_str(), 30, blob->bounds().fBottom + 15, paint);\n canvas->translate(blob->bounds().fRight + 10, 0);\n }\n}", + "code": "void draw(SkCanvas* canvas) {\n for (int index = 0; index < 2; ++index) {\n SkTextBlobBuilder textBlobBuilder;\n const char bunny[] = \"/(^x^)\\\\\";\n const int len = sizeof(bunny) - 1;\n uint16_t glyphs[len];\n SkPaint paint;\n paint.textToGlyphs(bunny, len, glyphs);\n paint.setTextEncoding(SkTextEncoding::kGlyphID);\n paint.setTextScaleX(0.5);\n SkFont font;\n font.setScaleX(0.5);\n int runs[] = { 3, 1, 3 };\n SkPoint textPos = { 20, 50 };\n int glyphIndex = 0;\n for (auto runLen : runs) {\n font.setSize(1 == runLen ? 20 : 50);\n paint.setTextSize(1 == runLen ? 20 : 50);\n const SkTextBlobBuilder::RunBuffer& run =\n textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY);\n memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);\n textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);\n glyphIndex += runLen;\n }\n sk_sp blob = textBlobBuilder.make();\n paint.reset();\n canvas->drawTextBlob(blob.get(), 0, 0, paint);\n std::string id = \"unique ID:\" + std::to_string(blob->uniqueID());\n canvas->drawString(id.c_str(), 30, blob->bounds().fBottom + 15, paint);\n canvas->translate(blob->bounds().fRight + 10, 0);\n }\n}", "width": 256, "height": 256, "hash": "6e12cceca981ddabc0fc18c380543f34", diff --git a/site/user/api/undocumented.md b/site/user/api/undocumented.md index 08b8b4618a..7ff6351df4 100644 --- a/site/user/api/undocumented.md +++ b/site/user/api/undocumented.md @@ -227,25 +227,25 @@ void draw(S Value Description - kUTF8_SkTextEncoding + SkTextEncoding::kUTF8 0 - kUTF16_SkTextEncoding + SkTextEncoding::kUTF16 1 - kUTF32_SkTextEncoding + SkTextEncoding::kUTF32 2 - kGlyphID_SkTextEncoding + SkTextEncoding::kGlyphID 3 diff --git a/src/core/SkFont.cpp b/src/core/SkFont.cpp index 48685da7a9..e26c7a2bd1 100644 --- a/src/core/SkFont.cpp +++ b/src/core/SkFont.cpp @@ -479,13 +479,13 @@ SkRect SkFontPriv::GetFontBounds(const SkFont& font) { int SkFontPriv::CountTextElements(const void* text, size_t byteLength, SkTextEncoding encoding) { switch (encoding) { - case kUTF8_SkTextEncoding: + case SkTextEncoding::kUTF8: return SkUTF::CountUTF8(reinterpret_cast(text), byteLength); - case kUTF16_SkTextEncoding: + case SkTextEncoding::kUTF16: return SkUTF::CountUTF16(reinterpret_cast(text), byteLength); - case kUTF32_SkTextEncoding: + case SkTextEncoding::kUTF32: return byteLength >> 2; - case kGlyphID_SkTextEncoding: + case SkTextEncoding::kGlyphID: return byteLength >> 1; } SkASSERT(false); diff --git a/src/core/SkFontPriv.h b/src/core/SkFontPriv.h index 2e83f706fd..ee98859489 100644 --- a/src/core/SkFontPriv.h +++ b/src/core/SkFontPriv.h @@ -85,7 +85,7 @@ public: class SkAutoToGlyphs { public: SkAutoToGlyphs(const SkFont& font, const void* text, size_t length, SkTextEncoding encoding) { - if (encoding == kGlyphID_SkTextEncoding || length == 0) { + if (encoding == SkTextEncoding::kGlyphID || length == 0) { fGlyphs = reinterpret_cast(text); fCount = length >> 1; } else { diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp index 65a12055a8..7712059ffb 100644 --- a/src/core/SkGlyphRun.cpp +++ b/src/core/SkGlyphRun.cpp @@ -162,7 +162,7 @@ SkSpan SkGlyphIDSet::uniquifyGlyphIDs( // -- SkGlyphRunBuilder ---------------------------------------------------------------------------- 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); + auto glyphIDs = textToGlyphIDs(font, bytes, byteLength, SkTextEncoding::kUTF8); if (!glyphIDs.empty()) { this->initialize(glyphIDs.size()); this->simplifyDrawText(font, glyphIDs, origin, fPositions); @@ -258,7 +258,7 @@ void SkGlyphRunBuilder::initialize(size_t totalRunSize) { SkSpan SkGlyphRunBuilder::textToGlyphIDs( const SkFont& font, const void* bytes, size_t byteLength, SkTextEncoding encoding) { - if (encoding != kGlyphID_SkTextEncoding) { + if (encoding != SkTextEncoding::kGlyphID) { int count = font.countText(bytes, byteLength, encoding); if (count > 0) { fScratchGlyphIDs.resize(count); diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp index 1ab3179352..d9d9c5f952 100644 --- a/src/core/SkTextBlob.cpp +++ b/src/core/SkTextBlob.cpp @@ -262,7 +262,7 @@ SkRect SkTextBlobBuilder::TightRunBounds(const SkTextBlob::RunRecord& run) { if (SkTextBlob::kDefault_Positioning == run.positioning()) { font.measureText(run.glyphBuffer(), run.glyphCount() * sizeof(uint16_t), - kGlyphID_SkTextEncoding, &bounds); + SkTextEncoding::kGlyphID, &bounds); return bounds.makeOffset(run.offset().x(), run.offset().y()); } diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp index 997ea5fef1..bca0c724b0 100644 --- a/src/utils/SkLua.cpp +++ b/src/utils/SkLua.cpp @@ -563,7 +563,7 @@ static int lcanvas_drawText(lua_State* L) { size_t len; const char* text = lua_tolstring(L, 2, &len); get_ref(L, 1)->drawSimpleText( - text, len, kUTF8_SkTextEncoding, + text, len, SkTextEncoding::kUTF8, lua2scalar(L, 3), lua2scalar(L, 4), SkFont::LEGACY_ExtractFromPaint(*get_obj(L, 5)), *get_obj(L, 5)); @@ -977,7 +977,7 @@ static int lfont_measureText(lua_State* L) { if (lua_isstring(L, 2)) { size_t len; const char* text = lua_tolstring(L, 2, &len); - SkLua(L).pushScalar(get_obj(L, 1)->measureText(text, len, kUTF8_SkTextEncoding)); + SkLua(L).pushScalar(get_obj(L, 1)->measureText(text, len, SkTextEncoding::kUTF8)); return 1; } return 0; diff --git a/src/utils/SkLuaCanvas.cpp b/src/utils/SkLuaCanvas.cpp index 9c6d512b16..f756ee6c6e 100644 --- a/src/utils/SkLuaCanvas.cpp +++ b/src/utils/SkLuaCanvas.cpp @@ -50,17 +50,17 @@ private: void AutoCallLua::pushEncodedText(SkTextEncoding enc, const void* text, size_t length) { switch (enc) { - case kUTF8_SkTextEncoding: + case SkTextEncoding::kUTF8: this->pushString((const char*)text, length, "text"); break; - case kUTF16_SkTextEncoding: + case SkTextEncoding::kUTF16: this->pushString(SkStringFromUTF16((const uint16_t*)text, length), "text"); break; - case kGlyphID_SkTextEncoding: + case SkTextEncoding::kGlyphID: this->pushArrayU16((const uint16_t*)text, SkToInt(length >> 1), "glyphs"); break; - case kUTF32_SkTextEncoding: + case SkTextEncoding::kUTF32: break; } } diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp index 6f1d16dbb3..cd619b3e11 100644 --- a/src/xps/SkXPSDevice.cpp +++ b/src/xps/SkXPSDevice.cpp @@ -1905,10 +1905,10 @@ HRESULT SkXPSDevice::AddGlyphs(IXpsOMObjectFactory* xpsFactory, } 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) { + static_assert((int)SkTypeface::kUTF8_Encoding == (int)SkTextEncoding::kUTF8, ""); + static_assert((int)SkTypeface::kUTF16_Encoding == (int)SkTextEncoding::kUTF16, ""); + static_assert((int)SkTypeface::kUTF32_Encoding == (int)SkTextEncoding::kUTF32, ""); + if (encoding == SkTextEncoding::kGlyphID) { return SkToInt(byteLength / 2); } return SkUTFN_CountUnichars((SkTypeface::Encoding)encoding, text, byteLength); diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp index eb4c48abea..b16a73c9cc 100644 --- a/tests/FontHostTest.cpp +++ b/tests/FontHostTest.cpp @@ -229,7 +229,8 @@ static void test_advances(skiatest::Reporter* reporter) { }; SkFont font; - char txt[] = "long.text.with.lots.of.dots."; + char const * const txt = "long.text.with.lots.of.dots."; + size_t textLen = strlen(txt); for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) { font.setTypeface(SkTypeface::MakeFromName(faces[i], SkFontStyle())); @@ -247,10 +248,10 @@ static void test_advances(skiatest::Reporter* reporter) { // For no hinting and light hinting this should take the // optimized generateAdvance path. - SkScalar width1 = font.measureText(txt, strlen(txt), kUTF8_SkTextEncoding); + SkScalar width1 = font.measureText(txt, textLen, SkTextEncoding::kUTF8); // Requesting the bounds forces a generateMetrics call. - SkScalar width2 = font.measureText(txt, strlen(txt), kUTF8_SkTextEncoding, &bounds); + SkScalar width2 = font.measureText(txt, textLen, SkTextEncoding::kUTF8, &bounds); // SkDebugf("Font: %s, generateAdvance: %f, generateMetrics: %f\n", // faces[i], SkScalarToFloat(width1), SkScalarToFloat(width2)); diff --git a/tests/FontMgrTest.cpp b/tests/FontMgrTest.cpp index 7f956eadbb..471fb921da 100644 --- a/tests/FontMgrTest.cpp +++ b/tests/FontMgrTest.cpp @@ -30,11 +30,11 @@ static void test_font(skiatest::Reporter* reporter) { sk_bzero(glyphs, sizeof(glyphs)); // Check that no glyphs are copied with insufficient storage. - int count = font.textToGlyphs("Hello", 5, kUTF8_SkTextEncoding, glyphs, 2); + int count = font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, 2); REPORTER_ASSERT(reporter, 5 == count); for (const auto glyph : glyphs) { REPORTER_ASSERT(reporter, glyph == 0); } - SkAssertResult(font.textToGlyphs("Hello", 5, kUTF8_SkTextEncoding, glyphs, + SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, SK_ARRAY_COUNT(glyphs)) == count); for (int i = 0; i < count; ++i) { diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp index 53a369a1b5..549e4b8d31 100644 --- a/tests/PDFPrimitivesTest.cpp +++ b/tests/PDFPrimitivesTest.cpp @@ -87,7 +87,7 @@ static void test_issue1083() { SkCanvas* canvas = doc->beginPage(100.0f, 100.0f); uint16_t glyphID = 65000; - canvas->drawSimpleText(&glyphID, 2, kGlyphID_SkTextEncoding, 0, 0, SkFont(), SkPaint()); + canvas->drawSimpleText(&glyphID, 2, SkTextEncoding::kGlyphID, 0, 0, SkFont(), SkPaint()); doc->close(); } diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp index d2559d4192..6bb4819e6d 100644 --- a/tests/PaintTest.cpp +++ b/tests/PaintTest.cpp @@ -169,7 +169,7 @@ DEF_TEST(Paint_regression_measureText, reporter) { r.setLTRB(SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN, SK_ScalarNaN); // test that the rect was reset - font.measureText("", 0, kUTF8_SkTextEncoding, &r); + font.measureText("", 0, SkTextEncoding::kUTF8, &r); REPORTER_ASSERT(reporter, r.isEmpty()); } @@ -247,10 +247,10 @@ DEF_TEST(Paint_nothingToDraw, r) { DEF_TEST(Font_getpos, r) { SkFont font; const char text[] = "Hamburgefons!@#!#23425,./;'[]"; - int count = font.countText(text, strlen(text), kUTF8_SkTextEncoding); + int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8); SkAutoTArray glyphStorage(count); uint16_t* glyphs = glyphStorage.get(); - (void)font.textToGlyphs(text, strlen(text), kUTF8_SkTextEncoding, glyphs, count); + (void)font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, glyphs, count); SkAutoTArray widthStorage(count); SkAutoTArray xposStorage(count); diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp index beaafd0a3b..e761ec0207 100644 --- a/tests/PathTest.cpp +++ b/tests/PathTest.cpp @@ -5427,7 +5427,7 @@ DEF_TEST(path_last_move_to_index, r) { SkGlyphID glyphs[len]; SkFont font; - font.textToGlyphs(text, len, kUTF8_SkTextEncoding, glyphs, len); + font.textToGlyphs(text, len, SkTextEncoding::kUTF8, glyphs, len); SkPath copyPath; SkFont().getPaths(glyphs, len, [](const SkPath* src, const SkMatrix& mx, void* ctx) { diff --git a/tests/SVGDeviceTest.cpp b/tests/SVGDeviceTest.cpp index e9e58e7432..1deec3d113 100644 --- a/tests/SVGDeviceTest.cpp +++ b/tests/SVGDeviceTest.cpp @@ -127,7 +127,7 @@ void test_whitespace_pos(skiatest::Reporter* reporter, { auto svgCanvas = MakeDOMCanvas(&dom); - svgCanvas->drawSimpleText(txt, len, kUTF8_SkTextEncoding, offset.x(), offset.y(), + svgCanvas->drawSimpleText(txt, len, SkTextEncoding::kUTF8, offset.x(), offset.y(), font, paint); } check_text_node(reporter, dom, dom.finishParsing(), offset, 2, expected); diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp index 9b5b78b45a..6314097453 100644 --- a/tests/TextBlobTest.cpp +++ b/tests/TextBlobTest.cpp @@ -159,10 +159,10 @@ public: const char* txt = "BOOO"; const size_t txtLen = strlen(txt); - const int glyphCount = font.countText(txt, txtLen, kUTF8_SkTextEncoding); + const int glyphCount = font.countText(txt, txtLen, SkTextEncoding::kUTF8); const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(font, glyphCount); - font.textToGlyphs(txt, txtLen, kUTF8_SkTextEncoding, buffer.glyphs, glyphCount); + font.textToGlyphs(txt, txtLen, SkTextEncoding::kUTF8, buffer.glyphs, glyphCount); memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2); sk_sp blob(builder.make()); @@ -319,9 +319,9 @@ DEF_TEST(TextBlob_extended, reporter) { const char text1[] = "Foo"; const char text2[] = "Bar"; - int glyphCount = font.countText(text1, strlen(text1), kUTF8_SkTextEncoding); + int glyphCount = font.countText(text1, strlen(text1), SkTextEncoding::kUTF8); SkAutoTMalloc glyphs(glyphCount); - (void)font.textToGlyphs(text1, strlen(text1), kUTF8_SkTextEncoding, glyphs.get(), glyphCount); + (void)font.textToGlyphs(text1, strlen(text1), SkTextEncoding::kUTF8, glyphs.get(), glyphCount); auto run = SkTextBlobBuilderPriv::AllocRunText(&textBlobBuilder, font, glyphCount, 0, 0, SkToInt(strlen(text2)), SkString(), nullptr); @@ -362,11 +362,11 @@ static void add_run(SkTextBlobBuilder* builder, const char text[], SkScalar x, S font.setSize(16); font.setTypeface(tf); - int glyphCount = font.countText(text, strlen(text), kUTF8_SkTextEncoding); + int glyphCount = font.countText(text, strlen(text), SkTextEncoding::kUTF8); SkTextBlobBuilder::RunBuffer buffer = builder->allocRun(font, glyphCount, x, y); - (void)font.textToGlyphs(text, strlen(text), kUTF8_SkTextEncoding, buffer.glyphs, glyphCount); + (void)font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, buffer.glyphs, glyphCount); } static sk_sp render(const SkTextBlob* blob) { @@ -435,7 +435,7 @@ DEF_TEST(TextBlob_serialize, reporter) { DEF_TEST(TextBlob_MakeAsDrawText, reporter) { const char text[] = "Hello"; - auto blob = SkTextBlob::MakeFromString(text, SkFont(), kUTF8_SkTextEncoding); + auto blob = SkTextBlob::MakeFromString(text, SkFont(), SkTextEncoding::kUTF8); int runs = 0; for(SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) { diff --git a/tests/UnicodeTest.cpp b/tests/UnicodeTest.cpp index c67c278d56..1328fdcb87 100644 --- a/tests/UnicodeTest.cpp +++ b/tests/UnicodeTest.cpp @@ -32,9 +32,9 @@ DEF_TEST(Unicode_textencodings, reporter) { SkFont font; - int count8 = font.textToGlyphs(text8, len8, kUTF8_SkTextEncoding, glyphs8, SK_ARRAY_COUNT(glyphs8)); - int count16 = font.textToGlyphs(text16, len16, kUTF16_SkTextEncoding, glyphs16, SK_ARRAY_COUNT(glyphs16)); - int count32 = font.textToGlyphs(text32, len32, kUTF32_SkTextEncoding, glyphs32, SK_ARRAY_COUNT(glyphs32)); + int count8 = font.textToGlyphs(text8, len8, SkTextEncoding::kUTF8, glyphs8, SK_ARRAY_COUNT(glyphs8)); + int count16 = font.textToGlyphs(text16, len16, SkTextEncoding::kUTF16, glyphs16, SK_ARRAY_COUNT(glyphs16)); + int count32 = font.textToGlyphs(text32, len32, SkTextEncoding::kUTF32, glyphs32, SK_ARRAY_COUNT(glyphs32)); REPORTER_ASSERT(reporter, (int)len8 == count8); REPORTER_ASSERT(reporter, (int)len8 == count16); @@ -57,7 +57,7 @@ DEF_TEST(glyphs_to_unichars, reporter) { uni[i + 26] = i + 'a'; } uint16_t glyphs[N]; - font.textToGlyphs(uni, sizeof(uni), kUTF32_SkTextEncoding, glyphs, N); + font.textToGlyphs(uni, sizeof(uni), SkTextEncoding::kUTF32, glyphs, N); SkUnichar uni2[N]; SkFontPriv::GlyphsToUnichars(font, glyphs, N, uni2); diff --git a/tools/ToolUtils.cpp b/tools/ToolUtils.cpp index b161e24cfb..ab4e81d9ce 100644 --- a/tools/ToolUtils.cpp +++ b/tools/ToolUtils.cpp @@ -137,7 +137,7 @@ create_string_bitmap(int w, int h, SkColor c, int x, int y, int textSize, const canvas.clear(0x00000000); canvas.drawSimpleText(str, strlen(str), - kUTF8_SkTextEncoding, + SkTextEncoding::kUTF8, SkIntToScalar(x), SkIntToScalar(y), font, @@ -168,7 +168,7 @@ void add_to_text_blob(SkTextBlobBuilder* builder, const SkFont& font, SkScalar x, SkScalar y) { - add_to_text_blob_w_len(builder, text, strlen(text), kUTF8_SkTextEncoding, font, x, y); + add_to_text_blob_w_len(builder, text, strlen(text), SkTextEncoding::kUTF8, font, x, y); } void get_text_path(const SkFont& font, diff --git a/tools/fiddle/documumentation_examples_map.txt b/tools/fiddle/documumentation_examples_map.txt index af49342533..fc22d344e9 100644 --- a/tools/fiddle/documumentation_examples_map.txt +++ b/tools/fiddle/documumentation_examples_map.txt @@ -4059,11 +4059,11 @@ static sk_sp Deserialize(const void* data, size_t size, const SkDese [TextBlob_MakeFromString] SkTextBlob -static sk_sp MakeFromString(const char* string, const SkFont& font, SkTextEncoding encoding = kUTF8_SkTextEncoding); +static sk_sp MakeFromString(const char* string, const SkFont& font, SkTextEncoding encoding = SkTextEncoding::kUTF8); [TextBlob_MakeFromText] SkTextBlob -static sk_sp MakeFromText(const void* text, size_t byteLength, const SkFont& font, SkTextEncoding encoding = kUTF8_SkTextEncoding); +static sk_sp MakeFromText(const void* text, size_t byteLength, const SkFont& font, SkTextEncoding encoding = SkTextEncoding::kUTF8); [TextBlob_bounds] SkTextBlob diff --git a/tools/fonts/TestSVGTypeface.cpp b/tools/fonts/TestSVGTypeface.cpp index de4e1dc7c2..e6fe156be3 100644 --- a/tools/fonts/TestSVGTypeface.cpp +++ b/tools/fonts/TestSVGTypeface.cpp @@ -759,7 +759,7 @@ void TestSVGTypeface::exportTtxCbdt(SkWStream* out, SkSpan strikeSizes surface->peekPixels(&pix); canvas->drawSimpleText(&gid, sizeof(gid), - kGlyphID_SkTextEncoding, + SkTextEncoding::kGlyphID, -bounds.fLeft, -bounds.fTop, font, @@ -981,7 +981,7 @@ void TestSVGTypeface::exportTtxSbix(SkWStream* out, SkSpan strikeSizes surface->peekPixels(&pix); canvas->drawSimpleText(&gid, sizeof(gid), - kGlyphID_SkTextEncoding, + SkTextEncoding::kGlyphID, -bounds.fLeft, -bounds.fTop, font, diff --git a/tools/sk_app/CommandSet.cpp b/tools/sk_app/CommandSet.cpp index 04c5aa8595..984c8d989b 100644 --- a/tools/sk_app/CommandSet.cpp +++ b/tools/sk_app/CommandSet.cpp @@ -128,9 +128,9 @@ void CommandSet::drawHelp(SkCanvas* canvas) { for (Command& cmd : fCommands) { keyWidth = SkMaxScalar(keyWidth, font.measureText(cmd.fKeyName.c_str(), cmd.fKeyName.size(), - kUTF8_SkTextEncoding)); + SkTextEncoding::kUTF8)); } - keyWidth += font.measureText(" ", 1, kUTF8_SkTextEncoding); + keyWidth += font.measureText(" ", 1, SkTextEncoding::kUTF8); // If we're grouping by category, we'll be adding text height on every new group (including the // first), so no need to do that here. Otherwise, skip down so the first line is where we want. @@ -144,13 +144,13 @@ void CommandSet::drawHelp(SkCanvas* canvas) { if (kGrouped_HelpMode == fHelpMode && lastGroup != cmd.fGroup) { // Group change. Advance and print header: y += font.getSize(); - canvas->drawSimpleText(cmd.fGroup.c_str(), cmd.fGroup.size(), kUTF8_SkTextEncoding, + canvas->drawSimpleText(cmd.fGroup.c_str(), cmd.fGroup.size(), SkTextEncoding::kUTF8, x, y, groupFont, groupPaint); y += groupFont.getSize() + 2; lastGroup = cmd.fGroup; } - canvas->drawSimpleText(cmd.fKeyName.c_str(), cmd.fKeyName.size(), kUTF8_SkTextEncoding, + canvas->drawSimpleText(cmd.fKeyName.c_str(), cmd.fKeyName.size(), SkTextEncoding::kUTF8, x, y, font, paint); SkString text = SkStringPrintf(": %s", cmd.fDescription.c_str()); canvas->drawString(text, x + keyWidth, y, font, paint);