use drawString with font
Bug: skia: Change-Id: If193ce2abad59124d24478f24f2bc2fd85ac0d16 Reviewed-on: https://skia-review.googlesource.com/c/181408 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com> Auto-Submit: Mike Reed <reed@google.com>
This commit is contained in:
parent
a47eb45536
commit
c4745d6e51
@ -95,17 +95,15 @@ protected:
|
||||
|
||||
void drawOverlay(SkCanvas* canvas) {
|
||||
canvas->translate(10, 0);
|
||||
SkPaint textPaint;
|
||||
sk_tool_utils::set_portable_typeface(&textPaint);
|
||||
textPaint.setAntiAlias(true);
|
||||
SkFont font(sk_tool_utils::create_portable_typeface());
|
||||
canvas->save();
|
||||
for (int i = 0; i < kNumBlurs; ++i) {
|
||||
canvas->drawString(kBlurFlags[i].fName, 100, 0, textPaint);
|
||||
canvas->drawString(kBlurFlags[i].fName, 100, 0, font, SkPaint());
|
||||
canvas->translate(SkIntToScalar(130), 0);
|
||||
}
|
||||
canvas->restore();
|
||||
for (auto scale : kMatrixScales) {
|
||||
canvas->drawString(scale.fName, 0, 50, textPaint);
|
||||
canvas->drawString(scale.fName, 0, 50, font, SkPaint());
|
||||
canvas->translate(0, SkIntToScalar(150));
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "gm.h"
|
||||
#include "SkColor.h"
|
||||
#include "SkFont.h"
|
||||
#include "SkMaskFilter.h"
|
||||
|
||||
// GM to check the behavior from chrome bug:745290
|
||||
@ -18,11 +19,11 @@ DEF_SIMPLE_GM(blurSmallRadii, canvas, 100, 100) {
|
||||
paint.setColor(SK_ColorBLACK);
|
||||
paint.setAntiAlias(true);
|
||||
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma));
|
||||
canvas->drawString("Guest", 20, 10, paint);
|
||||
canvas->drawString("Guest", 20, 10, SkFont(), paint);
|
||||
|
||||
paint.setMaskFilter(nullptr);
|
||||
paint.setColor(SK_ColorWHITE);
|
||||
canvas->drawString("Guest", 20, 10, paint);
|
||||
canvas->drawString("Guest", 20, 10, SkFont(), paint);
|
||||
canvas->translate(0, 20);
|
||||
}
|
||||
}
|
||||
|
@ -83,18 +83,18 @@ static SkBitmap make_text(SkImageInfo info) {
|
||||
canvas.drawColor(SK_ColorWHITE);
|
||||
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setSubpixelText(true);
|
||||
paint.setTextSize(textSize);
|
||||
SkFont font;
|
||||
font.setSubpixel(true);
|
||||
font.setSize(textSize);
|
||||
|
||||
sk_tool_utils::set_portable_typeface(&paint, "serif", SkFontStyle());
|
||||
canvas.drawString("Hamburgefons", textSize/2, 1.2f*textSize, paint);
|
||||
sk_tool_utils::set_portable_typeface(&paint, "serif", SkFontStyle::Bold());
|
||||
canvas.drawString("Hamburgefons", textSize/2, 2.4f*textSize, paint);
|
||||
sk_tool_utils::set_portable_typeface(&paint, "serif", SkFontStyle::Italic());
|
||||
canvas.drawString("Hamburgefons", textSize/2, 3.6f*textSize, paint);
|
||||
sk_tool_utils::set_portable_typeface(&paint, "serif", SkFontStyle::BoldItalic());
|
||||
canvas.drawString("Hamburgefons", textSize/2, 4.8f*textSize, paint);
|
||||
font.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkFontStyle()));
|
||||
canvas.drawString("Hamburgefons", textSize/2, 1.2f*textSize, font, paint);
|
||||
font.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Bold()));
|
||||
canvas.drawString("Hamburgefons", textSize/2, 2.4f*textSize, font, paint);
|
||||
font.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()));
|
||||
canvas.drawString("Hamburgefons", textSize/2, 3.6f*textSize, font, paint);
|
||||
font.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkFontStyle::BoldItalic()));
|
||||
canvas.drawString("Hamburgefons", textSize/2, 4.8f*textSize, font, paint);
|
||||
|
||||
return bm;
|
||||
}
|
||||
|
@ -128,16 +128,12 @@ protected:
|
||||
quadColors[i] = gColors[i];
|
||||
}
|
||||
|
||||
SkPaint textP;
|
||||
textP.setTextSize(SkIntToScalar(kTextPad));
|
||||
textP.setAntiAlias(true);
|
||||
sk_tool_utils::set_portable_typeface(&textP, nullptr);
|
||||
SkFont font(sk_tool_utils::create_portable_typeface(), kTextPad);
|
||||
|
||||
for (int i = 0; i < numModes; ++i) {
|
||||
const char* label = SkBlendMode_Name(gModes[i]);
|
||||
canvas->drawString(label,
|
||||
i*(target.width()+kPad)+kPad, SkIntToScalar(kTextPad),
|
||||
textP);
|
||||
canvas->drawString(label, i*(target.width()+kPad)+kPad, SkIntToScalar(kTextPad),
|
||||
font, paint);
|
||||
}
|
||||
|
||||
for (int i = 0; i < numModes; ++i) {
|
||||
|
@ -170,13 +170,13 @@ protected:
|
||||
SkPaint blackPaint;
|
||||
SkScalar titleHeight = SK_Scalar1 * 24;
|
||||
blackPaint.setColor(SK_ColorBLACK);
|
||||
blackPaint.setTextSize(titleHeight);
|
||||
blackPaint.setAntiAlias(true);
|
||||
sk_tool_utils::set_portable_typeface(&blackPaint);
|
||||
|
||||
SkFont font(sk_tool_utils::create_portable_typeface(), titleHeight);
|
||||
|
||||
SkString title;
|
||||
title.printf("Bitmap size: %d x %d", gBmpSize, gBmpSize);
|
||||
canvas->drawString(title, 0,
|
||||
titleHeight, blackPaint);
|
||||
canvas->drawString(title, 0, titleHeight, font, blackPaint);
|
||||
|
||||
canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight);
|
||||
int rowCount = 0;
|
||||
@ -191,12 +191,9 @@ protected:
|
||||
label.appendf("%d x %d", w, h);
|
||||
blackPaint.setAntiAlias(true);
|
||||
blackPaint.setStyle(SkPaint::kFill_Style);
|
||||
blackPaint.setTextSize(SK_Scalar1 * 10);
|
||||
SkScalar baseline = dstRect.height() +
|
||||
blackPaint.getTextSize() + SK_Scalar1 * 3;
|
||||
canvas->drawString(label,
|
||||
0, baseline,
|
||||
blackPaint);
|
||||
font.setSize(SK_Scalar1 * 10);
|
||||
SkScalar baseline = dstRect.height() + font.getSize() + SK_Scalar1 * 3;
|
||||
canvas->drawString(label, 0, baseline, font, blackPaint);
|
||||
blackPaint.setStyle(SkPaint::kStroke_Style);
|
||||
blackPaint.setStrokeWidth(SK_Scalar1);
|
||||
blackPaint.setAntiAlias(false);
|
||||
|
@ -37,13 +37,13 @@ protected:
|
||||
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
sk_tool_utils::set_portable_typeface(&paint);
|
||||
paint.setTextSize(SkIntToScalar(72));
|
||||
paint.setLooper(fLooper);
|
||||
|
||||
SkFont font(sk_tool_utils::create_portable_typeface(), 72);
|
||||
|
||||
canvas->drawCircle(50, 50, 30, paint);
|
||||
canvas->drawRect({ 150, 50, 200, 100 }, paint);
|
||||
canvas->drawString("Looper", 230, 100, paint);
|
||||
canvas->drawString("Looper", 230, 100, font, paint);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "gm.h"
|
||||
#include "SkFont.h"
|
||||
#include "SkGradientShader.h"
|
||||
|
||||
// NOTE: The positions define hardstops for the red and green borders. For the repeating degenerate
|
||||
@ -33,13 +34,8 @@ typedef sk_sp<SkShader> (*GradientFactory)(SkShader::TileMode tm);
|
||||
static void draw_tile_header(SkCanvas* canvas) {
|
||||
canvas->save();
|
||||
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorBLACK);
|
||||
paint.setTextSize(12.0f);
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
for (int i = 0; i < TILE_MODE_CT; ++i) {
|
||||
canvas->drawString(TILE_NAMES[i], 0, 0, paint);
|
||||
canvas->drawString(TILE_NAMES[i], 0, 0, SkFont(), SkPaint());
|
||||
canvas->translate(TILE_SIZE + TILE_GAP, 0);
|
||||
}
|
||||
|
||||
|
@ -2539,9 +2539,11 @@ void SkCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
|
||||
LOOPER_END
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_DRAWSTRING
|
||||
void SkCanvas::drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint) {
|
||||
this->drawText(string.c_str(), string.size(), x, y, paint);
|
||||
}
|
||||
#endif
|
||||
|
||||
// These call the (virtual) onDraw... method
|
||||
void SkCanvas::drawSimpleText(const void* text, size_t byteLength, SkTextEncoding encoding,
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "Test.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <SkFont.h>
|
||||
|
||||
static const SkColor bgColor = SK_ColorWHITE;
|
||||
|
||||
@ -118,12 +119,12 @@ DEF_TEST(DrawText_weirdCoordinates, r) {
|
||||
SkScalar oddballs[] = { 0.0f, (float)INFINITY, (float)NAN, 34359738368.0f };
|
||||
|
||||
for (auto x : oddballs) {
|
||||
canvas->drawString("a", +x, 0.0f, SkPaint());
|
||||
canvas->drawString("a", -x, 0.0f, SkPaint());
|
||||
canvas->drawString("a", +x, 0.0f, SkFont(), SkPaint());
|
||||
canvas->drawString("a", -x, 0.0f, SkFont(), SkPaint());
|
||||
}
|
||||
for (auto y : oddballs) {
|
||||
canvas->drawString("a", 0.0f, +y, SkPaint());
|
||||
canvas->drawString("a", 0.0f, -y, SkPaint());
|
||||
canvas->drawString("a", 0.0f, +y, SkFont(), SkPaint());
|
||||
canvas->drawString("a", 0.0f, -y, SkFont(), SkPaint());
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,9 +134,8 @@ DEF_TEST(DrawText_weirdMatricies, r) {
|
||||
auto surface = SkSurface::MakeRasterN32Premul(100,100);
|
||||
auto canvas = surface->getCanvas();
|
||||
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setLCDRenderText(true);
|
||||
SkFont font;
|
||||
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
||||
|
||||
struct {
|
||||
SkScalar textSize;
|
||||
@ -156,11 +156,11 @@ DEF_TEST(DrawText_weirdMatricies, r) {
|
||||
};
|
||||
|
||||
for (const auto& testCase : testCases) {
|
||||
paint.setTextSize(testCase.textSize);
|
||||
font.setSize(testCase.textSize);
|
||||
const SkScalar(&m)[9] = testCase.matrix;
|
||||
SkMatrix mat;
|
||||
mat.setAll(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
|
||||
canvas->setMatrix(mat);
|
||||
canvas->drawString("Hamburgefons", 10, 10, paint);
|
||||
canvas->drawString("Hamburgefons", 10, 10, font, SkPaint());
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ DEF_TEST(SkPDF_document_skbug_4734, r) {
|
||||
canvas->translate(20.0f, 10.0f);
|
||||
canvas->rotate(30.0f);
|
||||
const char text[] = "HELLO";
|
||||
canvas->drawString(text, 0, 0, SkPaint());
|
||||
canvas->drawString(text, 0, 0, SkFont(), SkPaint());
|
||||
}
|
||||
|
||||
static bool contains(const uint8_t* result, size_t size, const char expectation[]) {
|
||||
|
@ -558,9 +558,8 @@ static void test_gen_id(skiatest::Reporter* reporter) {
|
||||
static void test_typeface(skiatest::Reporter* reporter) {
|
||||
SkPictureRecorder recorder;
|
||||
SkCanvas* canvas = recorder.beginRecording(10, 10);
|
||||
SkPaint paint;
|
||||
paint.setTypeface(SkTypeface::MakeFromName("Arial", SkFontStyle::Italic()));
|
||||
canvas->drawString("Q", 0, 10, paint);
|
||||
SkFont font(SkTypeface::MakeFromName("Arial", SkFontStyle::Italic()));
|
||||
canvas->drawString("Q", 0, 10, font, SkPaint());
|
||||
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
|
||||
SkDynamicMemoryWStream stream;
|
||||
picture->serialize(&stream);
|
||||
|
Loading…
Reference in New Issue
Block a user