diff --git a/gm/shadermaskfilter.cpp b/gm/shadermaskfilter.cpp index 83c95f41b4..f306018c6a 100644 --- a/gm/shadermaskfilter.cpp +++ b/gm/shadermaskfilter.cpp @@ -13,6 +13,7 @@ #include "SkMaskFilter.h" #include "SkPictureRecorder.h" #include "SkShaderMaskFilter.h" +#include "SkTextUtils.h" static void draw_masked_image(SkCanvas* canvas, const SkImage* image, SkScalar x, SkScalar y, const SkImage* mask, sk_sp outer, SkBlendMode mode) { @@ -108,7 +109,6 @@ DEF_SIMPLE_GM(combinemaskfilter, canvas, 560, 510) { SkPaint labelP; labelP.setAntiAlias(true); labelP.setTextSize(20); - labelP.setTextAlign(SkPaint::kCenter_Align); const SkRect r2 = r.makeOutset(1.5f, 1.5f); SkPaint strokePaint; @@ -139,7 +139,8 @@ DEF_SIMPLE_GM(combinemaskfilter, canvas, 560, 510) { canvas->translate(10, 10 + 20); canvas->save(); for (int i = 0; i < 5; ++i) { - canvas->drawText(gCoverageName[i], strlen(gCoverageName[i]), r.width()*0.5f, -10, labelP); + SkTextUtils::DrawString(canvas, gCoverageName[i], r.width()*0.5f, -10, labelP, + SkPaint::kCenter_Align); SkCoverageMode cmode = static_cast(i); canvas->save(); diff --git a/gm/surface.cpp b/gm/surface.cpp index 30a7844742..dad3814660 100644 --- a/gm/surface.cpp +++ b/gm/surface.cpp @@ -10,6 +10,7 @@ #include "SkGradientShader.h" #include "SkSurface.h" #include "SkSurfaceProps.h" +#include "SkTextUtils.h" #define W 200 #define H 100 @@ -44,9 +45,8 @@ static void test_draw(SkCanvas* canvas, const char label[]) { paint.setColor(SK_ColorWHITE); paint.setTextSize(32); - paint.setTextAlign(SkPaint::kCenter_Align); sk_tool_utils::set_portable_typeface(&paint); - canvas->drawString(label, W / 2, H * 3 / 4, paint); + SkTextUtils::DrawString(canvas, label, W / 2, H * 3 / 4, paint, SkPaint::kCenter_Align); } class SurfacePropsGM : public skiagm::GM { diff --git a/samplecode/SampleAAGeometry.cpp b/samplecode/SampleAAGeometry.cpp index 5746e2df6f..abca6dbcc3 100644 --- a/samplecode/SampleAAGeometry.cpp +++ b/samplecode/SampleAAGeometry.cpp @@ -16,6 +16,7 @@ // #include "SkPathStroker.h" #include "SkPointPriv.h" #include "SkString.h" +#include "SkTextUtils.h" #if 0 void SkStrokeSegment::dump() const { @@ -502,7 +503,6 @@ struct ButtonPaints { fStates[2].setColor(0xFFcf0000); fLabel.setAntiAlias(true); fLabel.setTextSize(25.0f); - fLabel.setTextAlign(SkPaint::kCenter_Align); fLabel.setStyle(SkPaint::kFill_Style); } }; @@ -542,7 +542,8 @@ struct Button { return; } canvas->drawRect(fBounds, paints.fStates[fState]); - canvas->drawText(&fLabel, 1, fBounds.centerX(), fBounds.fBottom - 5, paints.fLabel); + SkTextUtils::DrawText(canvas, &fLabel, 1, fBounds.centerX(), fBounds.fBottom - 5, + paints.fLabel, SkPaint::kCenter_Align); } void toggle() { @@ -864,7 +865,6 @@ public: fLegendLeftPaint.setAntiAlias(true); fLegendLeftPaint.setTextSize(13); fLegendRightPaint = fLegendLeftPaint; - fLegendRightPaint.setTextAlign(SkPaint::kRight_Align); construct_path(fPath); fFillButton.fVisible = fSkeletonButton.fVisible = fFilterButton.fVisible = fBisectButton.fVisible = fJoinButton.fVisible = fInOutButton.fVisible = true; @@ -1811,12 +1811,12 @@ void AAGeometryView::draw_legend(SkCanvas* canvas) { SkScalar bottomOffset = this->height() - 10; for (int index = kKeyCommandCount - 1; index >= 0; --index) { bottomOffset -= 15; - canvas->drawString(kKeyCommandList[index].fDescriptionL, + SkTextUtils::DrawString(canvas, kKeyCommandList[index].fDescriptionL, this->width() - 160, bottomOffset, fLegendLeftPaint); - canvas->drawString(kKeyCommandList[index].fDescriptionR, + SkTextUtils::DrawString(canvas, kKeyCommandList[index].fDescriptionR, this->width() - 20, bottomOffset, - fLegendRightPaint); + fLegendRightPaint, SkPaint::kRight_Align); } } diff --git a/samplecode/SampleArc.cpp b/samplecode/SampleArc.cpp index ed1f8dfb76..acf0cf7b8b 100644 --- a/samplecode/SampleArc.cpp +++ b/samplecode/SampleArc.cpp @@ -20,6 +20,7 @@ #include "SkRegion.h" #include "SkShader.h" #include "SkString.h" +#include "SkTextUtils.h" #include "SkUTF.h" #include "Sk1DPathEffect.h" @@ -116,17 +117,14 @@ protected: static void DrawLabel(SkCanvas* canvas, const SkRect& rect, SkScalar start, SkScalar sweep) { SkPaint paint; - paint.setAntiAlias(true); - paint.setTextAlign(SkPaint::kCenter_Align); SkString str; - str.appendScalar(start); str.append(", "); str.appendScalar(sweep); - canvas->drawString(str, rect.centerX(), - rect.fBottom + paint.getTextSize() * 5/4, paint); + SkTextUtils::DrawString(canvas, str, rect.centerX(), + rect.fBottom + paint.getTextSize() * 5/4, paint, SkPaint::kCenter_Align); } static void DrawArcs(SkCanvas* canvas) { diff --git a/samplecode/SampleAtlas.cpp b/samplecode/SampleAtlas.cpp index a6ab820fe7..28508cd155 100644 --- a/samplecode/SampleAtlas.cpp +++ b/samplecode/SampleAtlas.cpp @@ -13,6 +13,7 @@ #include "SkRandom.h" #include "SkRSXform.h" #include "SkSurface.h" +#include "SkTextUtils.h" typedef void (*DrawAtlasProc)(SkCanvas*, SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int, const SkRect*, const SkPaint*); @@ -50,14 +51,14 @@ static sk_sp make_atlas(int atlasSize, int cellSize) { const SkScalar half = cellSize * SK_ScalarHalf; const char* s = "01234567890!@#$%^&*=+<>?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; paint.setTextSize(28); - paint.setTextAlign(SkPaint::kCenter_Align); 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); - canvas->drawText(&s[index], 1, x + half, y + half + half/2, paint); + SkTextUtils::DrawText(canvas, &s[index], 1, x + half, y + half + half/2, paint, + SkPaint::kCenter_Align); i += 1; } } diff --git a/samplecode/SampleFilter2.cpp b/samplecode/SampleFilter2.cpp index 06b542efb7..c68b69cae5 100644 --- a/samplecode/SampleFilter2.cpp +++ b/samplecode/SampleFilter2.cpp @@ -16,6 +16,7 @@ #include "SkRegion.h" #include "SkShader.h" #include "SkString.h" +#include "SkTextUtils.h" #include "SkTime.h" #include "SkUTF.h" @@ -82,14 +83,13 @@ protected: if (i == 0) { SkPaint p; p.setAntiAlias(true); - p.setTextAlign(SkPaint::kCenter_Align); p.setTextSize(SkIntToScalar(18)); SkString s("dither="); s.appendS32(paint.isDither()); s.append(" filter="); s.appendS32(paint.getFilterQuality() != kNone_SkFilterQuality); - canvas->drawString(s, x + W/2, - y - p.getTextSize(), p); + SkTextUtils::DrawString(canvas, s, x + W/2, y - p.getTextSize(), p, + SkPaint::kCenter_Align); } if (k+j == 2) { SkPaint p; @@ -98,8 +98,7 @@ protected: SkString s; s.append(" depth="); s.appendS32(fBitmaps[i].colorType() == kRGB_565_SkColorType ? 16 : 32); - canvas->drawString(s, x + W + SkIntToScalar(4), - y + H/2, p); + SkTextUtils::DrawString(canvas, s, x + W + SkIntToScalar(4), y + H/2, p); } } } diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp index af10bd51e5..da558cc42c 100644 --- a/samplecode/SampleFilterFuzz.cpp +++ b/samplecode/SampleFilterFuzz.cpp @@ -159,10 +159,6 @@ static SkBlendMode make_xfermode() { return static_cast(R((int)SkBlendMode::kLastMode+1)); } -static SkPaint::Align make_paint_align() { - return static_cast(R(SkPaint::kRight_Align+1)); -} - static SkPaint::Hinting make_paint_hinting() { return static_cast(R(SkPaint::kFull_Hinting+1)); } @@ -522,7 +518,6 @@ static SkPaint make_paint() { paint.setImageFilter(make_image_filter()); sk_sp data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool())); - paint.setTextAlign(make_paint_align()); paint.setTextSize(make_scalar()); paint.setTextScaleX(make_scalar()); paint.setTextSkewX(make_scalar()); diff --git a/samplecode/SamplePolyToPoly.cpp b/samplecode/SamplePolyToPoly.cpp index 71086147ee..13baafa779 100644 --- a/samplecode/SamplePolyToPoly.cpp +++ b/samplecode/SamplePolyToPoly.cpp @@ -10,6 +10,7 @@ #include "SkPath.h" #include "SkRandom.h" #include "SkString.h" +#include "SkTextUtils.h" #include "SkTime.h" class PolyToPolyView : public Sample { @@ -103,9 +104,7 @@ protected: float y = D/2 - (fm.fAscent + fm.fDescent)/2; SkString str; str.appendS32(count); - canvas->drawString(str, - x, y, - *paint); + SkTextUtils::DrawString(canvas, str, x, y, *paint, SkPaint::kCenter_Align); canvas->restore(); } @@ -115,7 +114,6 @@ protected: paint.setAntiAlias(true); paint.setStrokeWidth(SkIntToScalar(4)); paint.setTextSize(SkIntToScalar(40)); - paint.setTextAlign(SkPaint::kCenter_Align); canvas->save(); canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); diff --git a/samplecode/SampleQuadStroker.cpp b/samplecode/SampleQuadStroker.cpp index e7823a2c32..ce524521f5 100644 --- a/samplecode/SampleQuadStroker.cpp +++ b/samplecode/SampleQuadStroker.cpp @@ -27,6 +27,7 @@ #include "SkSurface.h" #include "SkTArray.h" #include "SkTemplates.h" +#include "SkTextUtils.h" #include "SkTypes.h" #include "sk_tool_utils.h" @@ -504,10 +505,9 @@ protected: canvas->drawRect(button.fBounds, paint); paint.setTextSize(25.0f); paint.setColor(button.fEnabled ? 0xFF3F0000 : 0x6F3F0000); - paint.setTextAlign(SkPaint::kCenter_Align); paint.setStyle(SkPaint::kFill_Style); - canvas->drawText(&button.fLabel, 1, button.fBounds.centerX(), button.fBounds.fBottom - 5, - paint); + SkTextUtils::DrawText(canvas, &button.fLabel, 1, button.fBounds.centerX(), button.fBounds.fBottom - 5, + paint, SkPaint::kCenter_Align); } void draw_control(SkCanvas* canvas, const SkRect& bounds, SkScalar value, diff --git a/samplecode/SampleTiling.cpp b/samplecode/SampleTiling.cpp index 71cb428c2c..b2a5460711 100644 --- a/samplecode/SampleTiling.cpp +++ b/samplecode/SampleTiling.cpp @@ -17,6 +17,7 @@ #include "SkColorPriv.h" #include "SkColorFilter.h" #include "SkPicture.h" +#include "SkTextUtils.h" #include "SkTypeface.h" // effects @@ -110,8 +111,8 @@ protected: p.setLooper(fLooper); str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); - p.setTextAlign(SkPaint::kCenter_Align); - textCanvas->drawString(str, x + r.width()/2, y, p); + SkTextUtils::DrawString(textCanvas, str, x + r.width()/2, y, p, + SkPaint::kCenter_Align); x += r.width() * 4 / 3; } diff --git a/samplecode/SampleXfer.cpp b/samplecode/SampleXfer.cpp index d0ba35ea8b..f87d60cefa 100644 --- a/samplecode/SampleXfer.cpp +++ b/samplecode/SampleXfer.cpp @@ -15,6 +15,7 @@ #include "SkRSXform.h" #include "SkString.h" #include "SkSurface.h" +#include "SkTextUtils.h" #include "SkGradientShader.h" const SkBlendMode gModes[] = { @@ -52,9 +53,9 @@ public: paint.setColor(0xFFFFFFFF); paint.setTextSize(16); - paint.setTextAlign(SkPaint::kCenter_Align); paint.setLCDRenderText(true); - canvas->drawString(fLabel, fRect.centerX(), fRect.fTop + 0.68f * fRect.height(), paint); + SkTextUtils::DrawString(canvas, fLabel, fRect.centerX(), fRect.fTop + 0.68f * fRect.height(), + paint, SkPaint::kCenter_Align); } bool hitTest(SkScalar x, SkScalar y) { diff --git a/samplecode/SampleXfermodesBlur.cpp b/samplecode/SampleXfermodesBlur.cpp index 8819840fbf..ae8d6d57c6 100644 --- a/samplecode/SampleXfermodesBlur.cpp +++ b/samplecode/SampleXfermodesBlur.cpp @@ -19,6 +19,7 @@ #include "SkUTF.h" #include "SkColorPriv.h" #include "SkColorFilter.h" +#include "SkTextUtils.h" #include "SkTime.h" #include "SkTypeface.h" @@ -131,7 +132,6 @@ protected: SkPaint labelP; labelP.setAntiAlias(true); labelP.setLCDRenderText(true); - labelP.setTextAlign(SkPaint::kCenter_Align); setNamedTypeface(&labelP, "Menlo Regular"); const int W = 5; @@ -158,8 +158,8 @@ protected: canvas->drawRect(r, p); const char* label = SkBlendMode_Name(gModes[i]); - canvas->drawString(label, - x + w/2, y - labelP.getTextSize()/2, labelP); + SkTextUtils::DrawString(canvas, label, x + w/2, y - labelP.getTextSize()/2, labelP, + SkPaint::kCenter_Align); x += w + SkIntToScalar(10); if ((i % W) == W - 1) { x = x0; diff --git a/tests/GlyphRunTest.cpp b/tests/GlyphRunTest.cpp index 2e99c47078..877686dcfc 100644 --- a/tests/GlyphRunTest.cpp +++ b/tests/GlyphRunTest.cpp @@ -61,7 +61,6 @@ DEF_TEST(GlyphRunBlob, reporter) { SkPaint font; font.setTypeface(tf); font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - font.setTextAlign(SkPaint::kLeft_Align); font.setStyle(SkPaint::kFill_Style); font.setHinting(SkPaint::kNormal_Hinting); font.setTextSize(1u); diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp index a5f79ae675..10be8f9913 100644 --- a/tests/PaintTest.cpp +++ b/tests/PaintTest.cpp @@ -144,7 +144,6 @@ DEF_TEST(Paint_copy, reporter) { SkPaint paint; // set a few member variables paint.setStyle(SkPaint::kStrokeAndFill_Style); - paint.setTextAlign(SkPaint::kLeft_Align); paint.setStrokeWidth(SkIntToScalar(2)); // set a few pointers SkLayerDrawLooper::Builder looperBuilder; diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp index 347cd47de1..0bdbe8b095 100644 --- a/tests/SkRemoteGlyphCacheTest.cpp +++ b/tests/SkRemoteGlyphCacheTest.cpp @@ -69,7 +69,6 @@ sk_sp buildTextBlob(sk_sp tf, int glyphCount) { SkPaint font; font.setTypeface(tf); font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - font.setTextAlign(SkPaint::kLeft_Align); font.setStyle(SkPaint::kFill_Style); font.setHinting(SkPaint::kNormal_Hinting); font.setTextSize(1u); @@ -432,7 +431,6 @@ sk_sp make_blob_causing_fallback( paint.setSubpixelText(true); paint.setTextSize(96); paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - paint.setTextAlign(SkPaint::kLeft_Align); paint.setStyle(SkPaint::kFill_Style); paint.setHinting(SkPaint::kNormal_Hinting);