use fonts when making blobs

Bug: skia:
Change-Id: Id2d9cb3180f9f137fb26a1a9379c6ce22b8ad5e6
Reviewed-on: https://skia-review.googlesource.com/c/179981
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:
Mike Reed 2018-12-22 17:37:30 -05:00 committed by Skia Commit-Bot
parent 13654b20ce
commit ea8900e74e
4 changed files with 42 additions and 54 deletions

View File

@ -41,13 +41,8 @@ protected:
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
SkPaint paint; SkPaint paint;
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setStyle(SkPaint::kFill_Style);
const char text[] = "hambur"; SkFont font(sk_tool_utils::create_portable_typeface(), 256);
sk_tool_utils::set_portable_typeface(&paint);
paint.setTextSize(256);
paint.setAntiAlias(true);
// setup up maskfilter // setup up maskfilter
const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(50)); const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(50));
@ -55,11 +50,8 @@ protected:
SkPaint blurPaint(paint); SkPaint blurPaint(paint);
blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, kSigma)); blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, kSigma));
SkTextBlobBuilder builder; const char text[] = "hambur";
auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
sk_sp<SkTextBlob> blob(builder.make());
SkPaint clearPaint(paint); SkPaint clearPaint(paint);
clearPaint.setColor(SK_ColorWHITE); clearPaint.setColor(SK_ColorWHITE);

View File

@ -33,18 +33,19 @@ protected:
void onOnceBeforeDraw() override { void onOnceBeforeDraw() override {
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
SkPaint paint; SkFont font;
paint.setTextSize(32); font.setSize(32);
paint.setAntiAlias(i > 0); font.setEdging(i == 0 ? SkFont::Edging::kAlias :
paint.setLCDRenderText(i > 1); (i == 1 ? SkFont::Edging::kAntiAlias :
paint.setSubpixelText(true); SkFont::Edging::kSubpixelAntiAlias));
font.setSubpixel(true);
SkTextBlobBuilder builder; SkTextBlobBuilder builder;
sk_tool_utils::add_to_text_blob(&builder, "SkiaText", paint, 0, 0); sk_tool_utils::add_to_text_blob(&builder, "SkiaText", font, 0, 0);
fBlobs.emplace_back(builder.make()); fBlobs.emplace_back(builder.make());
} }
} }
virtual void onDraw(SkCanvas* inputCanvas) override { void onDraw(SkCanvas* inputCanvas) override {
// set up offscreen rendering with distance field text // set up offscreen rendering with distance field text
GrContext* ctx = inputCanvas->getGrContext(); GrContext* ctx = inputCanvas->getGrContext();
SkISize size = this->onISize(); SkISize size = this->onISize();

View File

@ -18,26 +18,19 @@
DEF_SIMPLE_GM(largeglyphblur, canvas, 1920, 600) { DEF_SIMPLE_GM(largeglyphblur, canvas, 1920, 600) {
const char text[] = "Hamburgefons"; const char text[] = "Hamburgefons";
SkPaint paint; SkFont font(sk_tool_utils::create_portable_typeface(), 256);
sk_tool_utils::set_portable_typeface(&paint); auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
paint.setTextSize(256);
paint.setAntiAlias(true);
// setup up maskfilter // setup up maskfilter
const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(40)); const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(40));
SkPaint blurPaint(paint); SkPaint blurPaint;
blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, kSigma)); blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, kSigma));
SkTextBlobBuilder builder;
sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
sk_sp<SkTextBlob> blob(builder.make());
canvas->drawTextBlob(blob, 10, 200, blurPaint); canvas->drawTextBlob(blob, 10, 200, blurPaint);
canvas->drawTextBlob(blob, 10, 200, paint); canvas->drawTextBlob(blob, 10, 200, SkPaint());
size_t len = strlen(text); size_t len = strlen(text);
canvas->drawText(text, len, 10, 500, blurPaint); canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, 10, 500, font, blurPaint);
canvas->drawText(text, len, 10, 500, paint); canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, 10, 500, font, SkPaint());
} }

View File

@ -32,50 +32,52 @@ protected:
const char* text = "The quick brown fox jumps over the lazy dog."; const char* text = "The quick brown fox jumps over the lazy dog.";
// make textbloben
SkPaint paint; SkPaint paint;
paint.setTextSize(32);
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setLCDRenderText(true); paint.setColor(SK_ColorMAGENTA);
// make textbloben
SkFont font;
font.setSize(32);
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
// Setup our random scaler context // Setup our random scaler context
auto typeface = sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle::Bold()); auto typeface = sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle::Bold());
if (!typeface) { if (!typeface) {
typeface = SkTypeface::MakeDefault(); typeface = SkTypeface::MakeDefault();
} }
paint.setColor(SK_ColorMAGENTA); font.setTypeface(sk_make_sp<SkRandomTypeface>(std::move(typeface), paint, false));
paint.setTypeface(sk_make_sp<SkRandomTypeface>(std::move(typeface), paint, false));
SkScalar y = 0; SkScalar y = 0;
SkRect bounds; SkRect bounds;
paint.measureText(text, strlen(text), &bounds); font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds);
y -= bounds.fTop; y -= bounds.fTop;
sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, y); sk_tool_utils::add_to_text_blob(&builder, text, font, 0, y);
y += bounds.fBottom; y += bounds.fBottom;
// A8 // A8
const char* bigtext1 = "The quick brown fox"; const char* bigtext1 = "The quick brown fox";
const char* bigtext2 = "jumps over the lazy dog."; const char* bigtext2 = "jumps over the lazy dog.";
paint.setTextSize(160); font.setSize(160);
paint.setSubpixelText(false); font.setSubpixel(false);
paint.setLCDRenderText(false); font.setEdging(SkFont::Edging::kAntiAlias);
paint.measureText(bigtext1, strlen(bigtext1), &bounds); font.measureText(bigtext1, strlen(bigtext1), kUTF8_SkTextEncoding, &bounds);
y -= bounds.fTop; y -= bounds.fTop;
sk_tool_utils::add_to_text_blob(&builder, bigtext1, paint, 0, y); sk_tool_utils::add_to_text_blob(&builder, bigtext1, font, 0, y);
y += bounds.fBottom; y += bounds.fBottom;
paint.measureText(bigtext2, strlen(bigtext2), &bounds); font.measureText(bigtext2, strlen(bigtext2), kUTF8_SkTextEncoding, &bounds);
y -= bounds.fTop; y -= bounds.fTop;
sk_tool_utils::add_to_text_blob(&builder, bigtext2, paint, 0, y); sk_tool_utils::add_to_text_blob(&builder, bigtext2, font, 0, y);
y += bounds.fBottom; y += bounds.fBottom;
// color emoji // color emoji
if (sk_sp<SkTypeface> origEmoji = sk_tool_utils::emoji_typeface()) { if (sk_sp<SkTypeface> origEmoji = sk_tool_utils::emoji_typeface()) {
paint.setTypeface(sk_make_sp<SkRandomTypeface>(origEmoji, paint, false)); font.setTypeface(sk_make_sp<SkRandomTypeface>(origEmoji, paint, false));
const char* emojiText = sk_tool_utils::emoji_sample_text(); const char* emojiText = sk_tool_utils::emoji_sample_text();
paint.measureText(emojiText, strlen(emojiText), &bounds); font.measureText(emojiText, strlen(emojiText), kUTF8_SkTextEncoding, &bounds);
y -= bounds.fTop; y -= bounds.fTop;
sk_tool_utils::add_to_text_blob(&builder, emojiText, paint, 0, y); sk_tool_utils::add_to_text_blob(&builder, emojiText, font, 0, y);
y += bounds.fBottom; y += bounds.fBottom;
} }