use utils for deprecated TextAlign

Bug: skia:8493
Change-Id: Ie7162d6e9099ce6499f05024205bd39fdd944c2b
Reviewed-on: https://skia-review.googlesource.com/c/165300
Auto-Submit: Mike Reed <reed@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Mike Reed 2018-10-26 07:28:30 -04:00 committed by Skia Commit-Bot
parent 6ddca5f0c6
commit a697df98d7
15 changed files with 35 additions and 45 deletions

View File

@ -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<SkMaskFilter> 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<SkCoverageMode>(i);
canvas->save();

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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<SkImage> 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;
}
}

View File

@ -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);
}
}
}

View File

@ -159,10 +159,6 @@ static SkBlendMode make_xfermode() {
return static_cast<SkBlendMode>(R((int)SkBlendMode::kLastMode+1));
}
static SkPaint::Align make_paint_align() {
return static_cast<SkPaint::Align>(R(SkPaint::kRight_Align+1));
}
static SkPaint::Hinting make_paint_hinting() {
return static_cast<SkPaint::Hinting>(R(SkPaint::kFull_Hinting+1));
}
@ -522,7 +518,6 @@ static SkPaint make_paint() {
paint.setImageFilter(make_image_filter());
sk_sp<SkData> 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());

View File

@ -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));

View File

@ -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,

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -69,7 +69,6 @@ sk_sp<SkTextBlob> buildTextBlob(sk_sp<SkTypeface> 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<SkTextBlob> 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);