change textutils to require font param
Bug: skia:
Change-Id: I8ba252e3fc5c0970fd9d83f73c32b68f3c68452e
Reviewed-on: https://skia-review.googlesource.com/c/180771
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Mike Reed <reed@google.com>
diff --git a/samplecode/SampleAAGeometry.cpp b/samplecode/SampleAAGeometry.cpp
index 397ba5f..9208ad1 100644
--- a/samplecode/SampleAAGeometry.cpp
+++ b/samplecode/SampleAAGeometry.cpp
@@ -491,7 +491,7 @@
static const int kMaxStateCount = 3;
SkPaint fDisabled;
SkPaint fStates[kMaxStateCount];
- SkPaint fLabel;
+ SkFont fLabelFont;
ButtonPaints() {
fStates[0].setAntiAlias(true);
@@ -501,9 +501,7 @@
fStates[1].setStrokeWidth(3);
fStates[2] = fStates[1];
fStates[2].setColor(0xFFcf0000);
- fLabel.setAntiAlias(true);
- fLabel.setTextSize(25.0f);
- fLabel.setStyle(SkPaint::kFill_Style);
+ fLabelFont.setSize(25.0f);
}
};
@@ -542,8 +540,8 @@
return;
}
canvas->drawRect(fBounds, paints.fStates[fState]);
- SkTextUtils::DrawText(canvas, &fLabel, 1, fBounds.centerX(), fBounds.fBottom - 5,
- paints.fLabel, SkTextUtils::kCenter_Align);
+ SkTextUtils::Draw(canvas, &fLabel, 1, kUTF8_SkTextEncoding, fBounds.centerX(), fBounds.fBottom - 5,
+ paints.fLabelFont, SkPaint(), SkTextUtils::kCenter_Align);
}
void toggle() {
@@ -791,8 +789,8 @@
SkPaint fActivePaint;
SkPaint fComplexPaint;
SkPaint fCoveragePaint;
- SkPaint fLegendLeftPaint;
- SkPaint fLegendRightPaint;
+ SkFont fLegendLeftFont;
+ SkFont fLegendRightFont;
SkPaint fPointPaint;
SkPaint fSkeletonPaint;
SkPaint fLightSkeletonPaint;
@@ -866,9 +864,8 @@
fActivePaint.setStrokeWidth(5);
fComplexPaint = fActivePaint;
fComplexPaint.setColor(SK_ColorBLUE);
- fLegendLeftPaint.setAntiAlias(true);
- fLegendLeftPaint.setTextSize(13);
- fLegendRightPaint = fLegendLeftPaint;
+ fLegendLeftFont.setSize(13);
+ fLegendRightFont = fLegendLeftFont;
construct_path(fPath);
fFillButton.fVisible = fSkeletonButton.fVisible = fFilterButton.fVisible
= fBisectButton.fVisible = fJoinButton.fVisible = fInOutButton.fVisible = true;
@@ -1815,12 +1812,11 @@
SkScalar bottomOffset = this->height() - 10;
for (int index = kKeyCommandCount - 1; index >= 0; --index) {
bottomOffset -= 15;
- SkTextUtils::DrawString(canvas, kKeyCommandList[index].fDescriptionL,
- this->width() - 160, bottomOffset,
- fLegendLeftPaint);
+ SkTextUtils::DrawString(canvas, kKeyCommandList[index].fDescriptionL, this->width() - 160, bottomOffset,
+ fLegendLeftFont, SkPaint());
SkTextUtils::DrawString(canvas, kKeyCommandList[index].fDescriptionR,
this->width() - 20, bottomOffset,
- fLegendRightPaint, SkTextUtils::kRight_Align);
+ fLegendRightFont, SkPaint(), SkTextUtils::kRight_Align);
}
}
diff --git a/samplecode/SampleArc.cpp b/samplecode/SampleArc.cpp
index 4e11301..58e4057 100644
--- a/samplecode/SampleArc.cpp
+++ b/samplecode/SampleArc.cpp
@@ -104,15 +104,13 @@
}
static void DrawLabel(SkCanvas* canvas, const SkRect& rect, SkScalar start, SkScalar sweep) {
- SkPaint paint;
- paint.setAntiAlias(true);
-
+ SkFont font;
SkString str;
str.appendScalar(start);
str.append(", ");
str.appendScalar(sweep);
- SkTextUtils::DrawString(canvas, str, rect.centerX(),
- rect.fBottom + paint.getTextSize() * 5/4, paint,
+ SkTextUtils::DrawString(canvas, str.c_str(), rect.centerX(),
+ rect.fBottom + font.getSize() * 5/4, font, SkPaint(),
SkTextUtils::kCenter_Align);
}
diff --git a/samplecode/SampleAtlas.cpp b/samplecode/SampleAtlas.cpp
index 652ef14..946c5e5 100644
--- a/samplecode/SampleAtlas.cpp
+++ b/samplecode/SampleAtlas.cpp
@@ -45,7 +45,6 @@
SkCanvas* canvas = surface->getCanvas();
SkPaint paint;
- paint.setAntiAlias(true);
SkRandom rand;
const SkScalar half = cellSize * SK_ScalarHalf;
@@ -57,8 +56,8 @@
paint.setColor(rand.nextU());
paint.setAlpha(0xFF);
int index = i % strlen(s);
- SkTextUtils::DrawText(canvas, &s[index], 1, x + half, y + half + half/2, paint,
- SkTextUtils::kCenter_Align);
+ SkTextUtils::Draw(canvas, &s[index], 1, kUTF8_SkTextEncoding, x + half, y + half + half/2, SkFont(), paint,
+ SkTextUtils::kCenter_Align);
i += 1;
}
}
diff --git a/samplecode/SampleFilter2.cpp b/samplecode/SampleFilter2.cpp
index e4a43ca..7a7acf0 100644
--- a/samplecode/SampleFilter2.cpp
+++ b/samplecode/SampleFilter2.cpp
@@ -80,25 +80,21 @@
x = SkScalarRoundToScalar(x);
y = SkScalarRoundToScalar(y);
canvas->drawBitmap(fBitmaps[i], x, y, &paint);
+ SkFont font;
+ font.setSize(SkIntToScalar(18));
if (i == 0) {
- SkPaint p;
- p.setAntiAlias(true);
- p.setTextSize(SkIntToScalar(18));
SkString s("dither=");
s.appendS32(paint.isDither());
s.append(" filter=");
s.appendS32(paint.getFilterQuality() != kNone_SkFilterQuality);
- SkTextUtils::DrawString(canvas, s, x + W/2, y - p.getTextSize(), p,
+ SkTextUtils::DrawString(canvas, s.c_str(), x + W/2, y - font.getSize(), font, SkPaint(),
SkTextUtils::kCenter_Align);
}
if (k+j == 2) {
- SkPaint p;
- p.setAntiAlias(true);
- p.setTextSize(SkIntToScalar(18));
SkString s;
s.append(" depth=");
s.appendS32(fBitmaps[i].colorType() == kRGB_565_SkColorType ? 16 : 32);
- SkTextUtils::DrawString(canvas, s, x + W + SkIntToScalar(4), y + H/2, p);
+ SkTextUtils::DrawString(canvas, s.c_str(), x + W + SkIntToScalar(4), y + H/2, font, SkPaint());
}
}
}
diff --git a/samplecode/SampleQuadStroker.cpp b/samplecode/SampleQuadStroker.cpp
index 270fdc4..ca19de2 100644
--- a/samplecode/SampleQuadStroker.cpp
+++ b/samplecode/SampleQuadStroker.cpp
@@ -503,11 +503,13 @@
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(button.fEnabled ? 0xFF3F0000 : 0x6F3F0000);
canvas->drawRect(button.fBounds, paint);
- paint.setTextSize(25.0f);
paint.setColor(button.fEnabled ? 0xFF3F0000 : 0x6F3F0000);
paint.setStyle(SkPaint::kFill_Style);
- SkTextUtils::DrawText(canvas, &button.fLabel, 1, button.fBounds.centerX(), button.fBounds.fBottom - 5,
- paint, SkTextUtils::kCenter_Align);
+ SkFont font;
+ font.setSize(25.0f);
+ SkTextUtils::Draw(canvas, &button.fLabel, 1, kUTF8_SkTextEncoding,
+ button.fBounds.centerX(), button.fBounds.fBottom - 5,
+ font, paint, SkTextUtils::kCenter_Align);
}
void draw_control(SkCanvas* canvas, const SkRect& bounds, SkScalar value,
diff --git a/samplecode/SampleTiling.cpp b/samplecode/SampleTiling.cpp
index fc4a5fd..c2c02d8 100644
--- a/samplecode/SampleTiling.cpp
+++ b/samplecode/SampleTiling.cpp
@@ -106,12 +106,11 @@
for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) {
SkPaint p;
SkString str;
- p.setAntiAlias(true);
p.setDither(true);
p.setLooper(fLooper);
str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]);
- SkTextUtils::DrawString(textCanvas, str, x + r.width()/2, y, p,
+ SkTextUtils::DrawString(textCanvas, str.c_str(), x + r.width()/2, y, SkFont(), p,
SkTextUtils::kCenter_Align);
x += r.width() * 4 / 3;
diff --git a/samplecode/SampleXfer.cpp b/samplecode/SampleXfer.cpp
index 6832e8d..bc6b911 100644
--- a/samplecode/SampleXfer.cpp
+++ b/samplecode/SampleXfer.cpp
@@ -52,10 +52,11 @@
canvas->drawRoundRect(fRect, 8, 8, paint);
paint.setColor(0xFFFFFFFF);
- paint.setTextSize(16);
- paint.setLCDRenderText(true);
- SkTextUtils::DrawString(canvas, fLabel, fRect.centerX(), fRect.fTop + 0.68f * fRect.height(),
- paint, SkTextUtils::kCenter_Align);
+ SkFont font;
+ font.setSize(16);
+ font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
+ SkTextUtils::DrawString(canvas, fLabel.c_str(), fRect.centerX(), fRect.fTop + 0.68f * fRect.height(),
+ font, paint, SkTextUtils::kCenter_Align);
}
bool hitTest(SkScalar x, SkScalar y) {
diff --git a/samplecode/SampleXfermodesBlur.cpp b/samplecode/SampleXfermodesBlur.cpp
index 0eeab5b..75ad9d1 100644
--- a/samplecode/SampleXfermodesBlur.cpp
+++ b/samplecode/SampleXfermodesBlur.cpp
@@ -10,6 +10,7 @@
#include "SkBlurMask.h"
#include "SkCanvas.h"
#include "SkCornerPathEffect.h"
+#include "SkFont.h"
#include "SkGradientShader.h"
#include "SkGraphics.h"
#include "SkPath.h"
@@ -27,8 +28,8 @@
#include "SkColorPriv.h"
#include "SkBlurMaskFilter.h"
-static void setNamedTypeface(SkPaint* paint, const char name[]) {
- paint->setTypeface(SkTypeface::MakeFromName(name, SkFontStyle()));
+static void setNamedTypeface(SkFont* font, const char name[]) {
+ font->setTypeface(SkTypeface::MakeFromName(name, SkFontStyle()));
}
static uint16_t gBG[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
@@ -83,29 +84,6 @@
virtual void onDrawContent(SkCanvas* canvas) {
canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
- if (false) {
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setTextSize(50);
- paint.setTypeface(SkTypeface::MakeFromName("Arial Unicode MS", SkFontStyle()));
- char buffer[10];
- size_t len = SkUTF::ToUTF8(0x8500, buffer);
- canvas->drawText(buffer, len, 40, 40, paint);
- return;
- }
- if (false) {
- SkPaint paint;
- paint.setAntiAlias(true);
-
- SkRect r0 = { 0, 0, 10.5f, 20 };
- SkRect r1 = { 10.5f, 10, 20, 30 };
- paint.setColor(SK_ColorRED);
- canvas->drawRect(r0, paint);
- paint.setColor(SK_ColorBLUE);
- canvas->drawRect(r1, paint);
- return;
- }
-
const SkBlendMode gModes[] = {
SkBlendMode::kClear,
SkBlendMode::kSrc,
@@ -129,10 +107,9 @@
auto s = SkShader::MakeBitmapShader(fBG, SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode, &m);
- SkPaint labelP;
- labelP.setAntiAlias(true);
- labelP.setLCDRenderText(true);
- setNamedTypeface(&labelP, "Menlo Regular");
+ SkFont font;
+ font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
+ setNamedTypeface(&font, "Menlo Regular");
const int W = 5;
@@ -158,7 +135,7 @@
canvas->drawRect(r, p);
const char* label = SkBlendMode_Name(gModes[i]);
- SkTextUtils::DrawString(canvas, label, x + w/2, y - labelP.getTextSize()/2, labelP,
+ SkTextUtils::DrawString(canvas, label, x + w/2, y - font.getSize()/2, font, SkPaint(),
SkTextUtils::kCenter_Align);
x += w + SkIntToScalar(10);
if ((i % W) == W - 1) {