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>
This commit is contained in:
Hal Canary 2019-01-08 14:00:08 -05:00 committed by Skia Commit-Bot
parent df2d27e0c7
commit 4484b8f1e3
14 changed files with 65 additions and 61 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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