diff options
author | Hal Canary <halcanary@google.com> | 2019-01-08 14:00:08 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2019-01-09 16:06:13 +0000 |
commit | 4484b8f1e348d2b949d74223acc196b2389dc7b5 (patch) | |
tree | fea2b867095ca8fa92c77d954dc5f241106be516 /samplecode | |
parent | df2d27e0c7d94f13b7bfacdfb0a8263ceb644f66 (diff) | |
download | skqp-4484b8f1e348d2b949d74223acc196b2389dc7b5.tar.gz |
drawText Cleanup, part 4
Change-Id: I2b48b6f507fe567cf44836c8755871c2a2f61ec0
Reviewed-on: https://skia-review.googlesource.com/c/182220
Auto-Submit: Hal Canary <halcanary@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Diffstat (limited to 'samplecode')
-rw-r--r-- | samplecode/SampleAAGeometry.cpp | 2 | ||||
-rw-r--r-- | samplecode/SampleAtlas.cpp | 6 | ||||
-rw-r--r-- | samplecode/SampleCCPRGeometry.cpp | 5 | ||||
-rw-r--r-- | samplecode/SampleClip.cpp | 11 | ||||
-rw-r--r-- | samplecode/SampleFatBits.cpp | 5 | ||||
-rw-r--r-- | samplecode/SampleFilterQuality.cpp | 18 | ||||
-rw-r--r-- | samplecode/SampleFlutterAnimate.cpp | 8 | ||||
-rw-r--r-- | samplecode/SampleIdentityScale.cpp | 5 | ||||
-rw-r--r-- | samplecode/SamplePath.cpp | 7 | ||||
-rw-r--r-- | samplecode/SampleQuadStroker.cpp | 14 | ||||
-rw-r--r-- | samplecode/SampleStrokePath.cpp | 7 | ||||
-rw-r--r-- | samplecode/SampleSubpixelTranslate.cpp | 24 | ||||
-rw-r--r-- | samplecode/SampleTextBox.cpp | 7 | ||||
-rw-r--r-- | samplecode/SampleTiling.cpp | 7 |
14 files changed, 65 insertions, 61 deletions
diff --git a/samplecode/SampleAAGeometry.cpp b/samplecode/SampleAAGeometry.cpp index af3ebf2f08..2722cad0c6 100644 --- a/samplecode/SampleAAGeometry.cpp +++ b/samplecode/SampleAAGeometry.cpp @@ -639,7 +639,7 @@ struct BiControl : public UniControl { if (yPos < fYLo + 10) { yPos = fYLo + 10; } - canvas->drawString(label, fBounds.fLeft + 5, yPos - 5, paints.fValue); + canvas->drawString(label, fBounds.fLeft + 5, yPos - 5, paints.fValueFont, paints.fValue); SkRect fill = { fBounds.fLeft, fYLo, fBounds.fRight, yPos }; canvas->drawRect(fill, paints.fFill); } diff --git a/samplecode/SampleAtlas.cpp b/samplecode/SampleAtlas.cpp index 946c5e5a3c..54642044a7 100644 --- a/samplecode/SampleAtlas.cpp +++ b/samplecode/SampleAtlas.cpp @@ -49,14 +49,16 @@ static sk_sp<SkImage> make_atlas(int atlasSize, int cellSize) { const SkScalar half = cellSize * SK_ScalarHalf; const char* s = "01234567890!@#$%^&*=+<>?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - paint.setTextSize(28); + SkFont font(nullptr, 28); + int i = 0; for (int y = 0; y < atlasSize; y += cellSize) { for (int x = 0; x < atlasSize; x += cellSize) { paint.setColor(rand.nextU()); paint.setAlpha(0xFF); int index = i % strlen(s); - SkTextUtils::Draw(canvas, &s[index], 1, kUTF8_SkTextEncoding, x + half, y + half + half/2, SkFont(), paint, + SkTextUtils::Draw(canvas, &s[index], 1, kUTF8_SkTextEncoding, + x + half, y + half + half/2, font, paint, SkTextUtils::kCenter_Align); i += 1; } diff --git a/samplecode/SampleCCPRGeometry.cpp b/samplecode/SampleCCPRGeometry.cpp index f04d5f711c..9ba67e62c4 100644 --- a/samplecode/SampleCCPRGeometry.cpp +++ b/samplecode/SampleCCPRGeometry.cpp @@ -238,11 +238,10 @@ void CCPRGeometryView::onDrawContent(SkCanvas* canvas) { canvas->drawPoints(SkCanvas::kPoints_PointMode, 1, fPoints + 3, pointsPaint); } + SkFont font(nullptr, 20); SkPaint captionPaint; - captionPaint.setTextSize(20); captionPaint.setColor(SK_ColorWHITE); - captionPaint.setAntiAlias(true); - canvas->drawText(caption.c_str(), caption.size(), 10, 30, captionPaint); + canvas->drawString(caption, 10, 30, font, captionPaint); } void CCPRGeometryView::updateGpuData() { diff --git a/samplecode/SampleClip.cpp b/samplecode/SampleClip.cpp index d872cbff28..c901151ca2 100644 --- a/samplecode/SampleClip.cpp +++ b/samplecode/SampleClip.cpp @@ -9,6 +9,7 @@ #include "SkAAClip.h" #include "SkCanvas.h" #include "SkColorPriv.h" +#include "SkFont.h" #include "SkPaint.h" #include "SkPath.h" #include "SkRandom.h" @@ -20,15 +21,13 @@ constexpr int H = 200; static void show_text(SkCanvas* canvas, bool doAA) { SkRandom rand; SkPaint paint; - paint.setAntiAlias(doAA); - paint.setLCDRenderText(true); - paint.setTextSize(SkIntToScalar(20)); + SkFont font(nullptr, 20); + font.setEdging(doAA ? SkFont::Edging::kSubpixelAntiAlias : SkFont::Edging::kAlias); for (int i = 0; i < 200; ++i) { paint.setColor((SK_A32_MASK << SK_A32_SHIFT) | rand.nextU()); - canvas->drawString("Hamburgefons", - rand.nextSScalar1() * W, rand.nextSScalar1() * H + 20, - paint); + canvas->drawString("Hamburgefons", rand.nextSScalar1() * W, rand.nextSScalar1() * H + 20, + font, paint); } } diff --git a/samplecode/SampleFatBits.cpp b/samplecode/SampleFatBits.cpp index 5e53816ee6..1e988e7683 100644 --- a/samplecode/SampleFatBits.cpp +++ b/samplecode/SampleFatBits.cpp @@ -467,10 +467,9 @@ protected: FatBits::kHair_Style == fFB.getStyle() ? "Hair" : "Stroke", fFB.getUseClip() ? "clip" : "noclip"); SkPaint paint; - paint.setAntiAlias(true); - paint.setTextSize(16); paint.setColor(SK_ColorBLUE); - canvas->drawString(str, 10, 16, paint); + SkFont font(nullptr, 16); + canvas->drawString(str, 10, 16, font, paint); } } diff --git a/samplecode/SampleFilterQuality.cpp b/samplecode/SampleFilterQuality.cpp index a686efbdd2..69ade73d50 100644 --- a/samplecode/SampleFilterQuality.cpp +++ b/samplecode/SampleFilterQuality.cpp @@ -10,6 +10,7 @@ #include "SkAnimTimer.h" #include "SkCanvas.h" #include "SkInterpolator.h" +#include "SkFont.h" #include "SkGradientShader.h" #include "SkData.h" #include "SkPath.h" @@ -274,19 +275,12 @@ protected: const SkScalar textX = fCell.width() * 2 + 30; + SkFont font(nullptr, 36); SkPaint paint; - paint.setAntiAlias(true); - paint.setTextSize(36); - SkString str; - str.appendScalar(fScale); - canvas->drawString(str, textX, 100, paint); - str.reset(); str.appendScalar(fAngle); - canvas->drawString(str, textX, 150, paint); - - str.reset(); str.appendScalar(trans[0]); - canvas->drawString(str, textX, 200, paint); - str.reset(); str.appendScalar(trans[1]); - canvas->drawString(str, textX, 250, paint); + canvas->drawString(SkStringPrintf("%.8g", (float)fScale), textX, 100, font, paint); + canvas->drawString(SkStringPrintf("%.8g", (float)fAngle), textX, 150, font, paint); + canvas->drawString(SkStringPrintf("%.8g", trans[0] ), textX, 200, font, paint); + canvas->drawString(SkStringPrintf("%.8g", trans[1] ), textX, 250, font, paint); } bool onAnimate(const SkAnimTimer& timer) override { diff --git a/samplecode/SampleFlutterAnimate.cpp b/samplecode/SampleFlutterAnimate.cpp index 343b33b191..bffee4a65c 100644 --- a/samplecode/SampleFlutterAnimate.cpp +++ b/samplecode/SampleFlutterAnimate.cpp @@ -8,7 +8,7 @@ #include "Sample.h" #include "SkAnimTimer.h" #include "SkCanvas.h" -#include "SkUTF.h" +#include "SkFont.h" #include "SkColorPriv.h" #include "SkColorFilter.h" #include "SkImage.h" @@ -43,11 +43,9 @@ protected: } void onDrawContent(SkCanvas* canvas) override { + SkFont font(fTypeface, 50); SkPaint paint; - paint.setTypeface(fTypeface); - paint.setAntiAlias(true); paint.setFilterQuality(kMedium_SkFilterQuality); - paint.setTextSize(50); // rough center of each glyph static constexpr auto kMidX = 35; @@ -61,7 +59,7 @@ protected: canvas->translate(fChars[i].fPosition.fX + kMidX, fChars[i].fPosition.fY - kMidY); canvas->rotate(SkRadiansToDegrees(rot)); canvas->translate(-35,+50); - canvas->drawString(fChars[i].fChar, 0, 0, paint); + canvas->drawString(fChars[i].fChar, 0, 0, font, paint); canvas->restore(); } } diff --git a/samplecode/SampleIdentityScale.cpp b/samplecode/SampleIdentityScale.cpp index 217a2cac66..bb3ff54b93 100644 --- a/samplecode/SampleIdentityScale.cpp +++ b/samplecode/SampleIdentityScale.cpp @@ -11,6 +11,7 @@ #include "SkBlurMaskFilter.h" #include "SkCanvas.h" #include "SkColorPriv.h" +#include "SkFont.h" #include "SkPath.h" #include "SkRandom.h" #include "SkStream.h" @@ -42,10 +43,10 @@ protected: void onDrawContent(SkCanvas* canvas) override { + SkFont font(nullptr, 48); SkPaint paint; paint.setAntiAlias(true); - paint.setTextSize(48); paint.setFilterQuality(kHigh_SkFilterQuality); SkTime::DateTime time; @@ -67,7 +68,7 @@ protected: } canvas->drawBitmap( fBM, 100, 100, &paint ); canvas->restore(); - canvas->drawString(text, 100, 400, paint ); + canvas->drawString(text, 100, 400, font, paint); } private: diff --git a/samplecode/SamplePath.cpp b/samplecode/SamplePath.cpp index e09db71a6a..74de7251ca 100644 --- a/samplecode/SamplePath.cpp +++ b/samplecode/SamplePath.cpp @@ -11,6 +11,7 @@ #include "SkCanvas.h" #include "SkGradientShader.h" #include "SkGraphics.h" +#include "SkFont.h" #include "SkPath.h" #include "SkRegion.h" #include "SkShader.h" @@ -720,12 +721,10 @@ protected: this->showFrame(canvas, fPts, 3, paint); this->showFrame(canvas, fQuad, 2, paint); - SkString str; - str.printf("t = %g", fT); paint.setColor(SK_ColorBLACK); paint.setStyle(SkPaint::kFill_Style); - paint.setTextSize(20); - canvas->drawText(str.c_str(), str.size(), 20, 20, paint); + SkFont font(nullptr, 20); + canvas->drawString(SkStringPrintf("t = %g", fT), 20, 20, font, paint); } if (fShowFlatness) { diff --git a/samplecode/SampleQuadStroker.cpp b/samplecode/SampleQuadStroker.cpp index ca19de2550..10e9bbc678 100644 --- a/samplecode/SampleQuadStroker.cpp +++ b/samplecode/SampleQuadStroker.cpp @@ -9,6 +9,7 @@ #include "SkBlendMode.h" #include "SkCanvas.h" #include "SkColor.h" +#include "SkFont.h" #include "SkGeometry.h" #include "SkImageInfo.h" #include "SkMatrix.h" @@ -325,6 +326,7 @@ protected: SkPaint paint, labelP; paint.setColor(color); labelP.setColor(color & 0xff5f9f5f); + SkFont font; SkPoint pos, tan; int index = 0; for (SkScalar dist = 0; dist <= total; dist += delta) { @@ -339,7 +341,7 @@ protected: SkRect dot = SkRect::MakeXYWH(pos.x() - 2, pos.y() - 2, 4, 4); canvas->drawRect(dot, labelP); canvas->drawString(label, - pos.x() - tan.x() * 1.25f, pos.y() - tan.y() * 1.25f, labelP); + pos.x() - tan.x() * 1.25f, pos.y() - tan.y() * 1.25f, font, labelP); } } ++index; @@ -399,7 +401,7 @@ protected: SkString label; label.appendS32(index); canvas->drawString(label, - pos.x() + tan.x() * 1.25f, pos.y() + tan.y() * 1.25f, paint); + pos.x() + tan.x() * 1.25f, pos.y() + tan.y() * 1.25f, SkFont(), paint); } } } @@ -525,11 +527,11 @@ protected: SkString label; label.printf("%0.3g", value); paint.setColor(0xFF000000); - paint.setTextSize(11.0f); paint.setStyle(SkPaint::kFill_Style); - canvas->drawString(label, bounds.fLeft + 5, yPos - 5, paint); - paint.setTextSize(13.0f); - canvas->drawString(name, bounds.fLeft, bounds.bottom() + 11, paint); + SkFont font(nullptr, 11.0f); + canvas->drawString(label, bounds.fLeft + 5, yPos - 5, font, paint); + font.setSize(13.0f); + canvas->drawString(name, bounds.fLeft, bounds.bottom() + 11, font, paint); } void setForGeometry() { diff --git a/samplecode/SampleStrokePath.cpp b/samplecode/SampleStrokePath.cpp index adf5a449d7..3eb6af1cea 100644 --- a/samplecode/SampleStrokePath.cpp +++ b/samplecode/SampleStrokePath.cpp @@ -4,9 +4,12 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ + #include "Sample.h" + #include "SkBlurMask.h" #include "SkCanvas.h" +#include "SkFont.h" #include "SkMaskFilter.h" #include "SkParsePath.h" #include "SkPath.h" @@ -152,7 +155,7 @@ protected: if (true) { canvas->drawColor(SK_ColorBLACK); - paint.setTextSize(24); + SkFont font(nullptr, 24); paint.setColor(SK_ColorWHITE); canvas->translate(10, 30); @@ -168,7 +171,7 @@ protected: if (x) { paint.setMaskFilter(SkMaskFilter::MakeBlur(gStyle[x - 1], sigma)); } - canvas->drawString("Title Bar", x*SkIntToScalar(100), y*SkIntToScalar(30), paint); + canvas->drawString("Title Bar", x * 100.0f, y * 30.0f, font, paint); sigma *= 0.75f; } diff --git a/samplecode/SampleSubpixelTranslate.cpp b/samplecode/SampleSubpixelTranslate.cpp index d394127903..16efda2d2f 100644 --- a/samplecode/SampleSubpixelTranslate.cpp +++ b/samplecode/SampleSubpixelTranslate.cpp @@ -5,12 +5,14 @@ * found in the LICENSE file. */ +#include "Sample.h" + #include "DecodeFile.h" #include "Resources.h" -#include "Sample.h" #include "SkBlurMaskFilter.h" #include "SkCanvas.h" #include "SkColorPriv.h" +#include "SkFont.h" #include "SkRandom.h" #include "SkStream.h" @@ -58,8 +60,8 @@ protected: }; SkPaint paint; - paint.setTextSize(48); - paint.setSubpixelText(true); + SkFont font(nullptr, 48); + font.setSubpixel(true); paint.setAntiAlias(true); for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) { @@ -68,31 +70,39 @@ protected: canvas->drawBitmapRect( fBM, r, &paint ); } - canvas->drawString( "AA Scaled", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fSize + 10), fCurPos.fY + fSize/2, paint ); + canvas->drawString("AA Scaled", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fSize + 10), + fCurPos.fY + fSize/2, font, paint); paint.setAntiAlias(false); + font.setEdging(SkFont::Edging::kAlias); for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) { paint.setFilterQuality(gQualitys[i]); SkRect r = SkRect::MakeXYWH( fCurPos.fX + i * (fSize + 10), fCurPos.fY + fSize + 10, fSize, fSize ); canvas->drawBitmapRect( fBM, r, &paint ); } - canvas->drawString( "Scaled", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fSize + 10), fCurPos.fY + fSize + 10 + fSize/2, paint ); + canvas->drawString("Scaled", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fSize + 10), + fCurPos.fY + fSize + 10 + fSize/2, font, paint); paint.setAntiAlias(true); + font.setEdging(SkFont::Edging::kAntiAlias); for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) { paint.setFilterQuality(gQualitys[i]); canvas->drawBitmap( fBM, fCurPos.fX + i * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10), &paint ); } - canvas->drawString( "AA No Scale", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10) + fSize/2, paint ); + canvas->drawString("AA No Scale", + fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fBM.width() + 10), + fCurPos.fY + 2*(fSize + 10) + fSize/2, font, paint); paint.setAntiAlias(false); + font.setEdging(SkFont::Edging::kAlias); for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) { paint.setFilterQuality(gQualitys[i]); canvas->drawBitmap( fBM, fCurPos.fX + i * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10) + fBM.height() + 10, &paint ); } - canvas->drawString( "No Scale", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10) + fBM.height() + 10 + fSize/2, paint ); + canvas->drawString("No Scale", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fBM.width() + 10), + fCurPos.fY + 2*(fSize + 10) + fBM.height() + 10 + fSize/2, font, paint); fCurPos.fX += fHorizontalVelocity; diff --git a/samplecode/SampleTextBox.cpp b/samplecode/SampleTextBox.cpp index 7931dfc7f9..cb31c4d699 100644 --- a/samplecode/SampleTextBox.cpp +++ b/samplecode/SampleTextBox.cpp @@ -76,14 +76,13 @@ protected: SkScalar margin = 20; SkPaint paint; - paint.setAntiAlias(true); - paint.setLCDRenderText(true); paint.setColor(fg); for (int i = 9; i < 24; i += 2) { SkTextBlobBuilderLineHandler builder; - paint.setTextSize(SkIntToScalar(i)); - SkFont font = SkFont::LEGACY_ExtractFromPaint(paint); + SkFont font(nullptr, SkIntToScalar(i)); + font.setEdging(SkFont::Edging::kSubpixelAntiAlias); + SkPoint end = shaper.shape(&builder, font, gText, strlen(gText), true, { margin, margin }, w - margin); canvas->drawTextBlob(builder.makeBlob(), 0, 0, paint); diff --git a/samplecode/SampleTiling.cpp b/samplecode/SampleTiling.cpp index c2c02d8c79..14e40c4529 100644 --- a/samplecode/SampleTiling.cpp +++ b/samplecode/SampleTiling.cpp @@ -139,11 +139,10 @@ protected: } if (textCanvas) { SkPaint p; - SkString str; - p.setAntiAlias(true); p.setLooper(fLooper); - str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); - textCanvas->drawString(str, x, y + r.height() * 2 / 3, p); + textCanvas->drawString( + SkStringPrintf("%s, %s", gConfigNames[i], gFilterNames[j]), + x, y + r.height() * 2 / 3, SkFont(), p); } y += r.height() * 4 / 3; |