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:
parent
13654b20ce
commit
ea8900e74e
@ -41,13 +41,8 @@ protected:
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStyle(SkPaint::kFill_Style);
|
||||
|
||||
const char text[] = "hambur";
|
||||
|
||||
sk_tool_utils::set_portable_typeface(&paint);
|
||||
paint.setTextSize(256);
|
||||
paint.setAntiAlias(true);
|
||||
SkFont font(sk_tool_utils::create_portable_typeface(), 256);
|
||||
|
||||
// setup up maskfilter
|
||||
const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(50));
|
||||
@ -55,11 +50,8 @@ protected:
|
||||
SkPaint blurPaint(paint);
|
||||
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());
|
||||
const char text[] = "hambur";
|
||||
auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
|
||||
|
||||
SkPaint clearPaint(paint);
|
||||
clearPaint.setColor(SK_ColorWHITE);
|
||||
|
@ -33,18 +33,19 @@ protected:
|
||||
|
||||
void onOnceBeforeDraw() override {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
SkPaint paint;
|
||||
paint.setTextSize(32);
|
||||
paint.setAntiAlias(i > 0);
|
||||
paint.setLCDRenderText(i > 1);
|
||||
paint.setSubpixelText(true);
|
||||
SkFont font;
|
||||
font.setSize(32);
|
||||
font.setEdging(i == 0 ? SkFont::Edging::kAlias :
|
||||
(i == 1 ? SkFont::Edging::kAntiAlias :
|
||||
SkFont::Edging::kSubpixelAntiAlias));
|
||||
font.setSubpixel(true);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* inputCanvas) override {
|
||||
void onDraw(SkCanvas* inputCanvas) override {
|
||||
// set up offscreen rendering with distance field text
|
||||
GrContext* ctx = inputCanvas->getGrContext();
|
||||
SkISize size = this->onISize();
|
||||
|
@ -16,28 +16,21 @@
|
||||
// This test ensures that glyphs whose point size is less than the SkGlyphCache's maxmium, but
|
||||
// who have a large blur, are still handled correctly
|
||||
DEF_SIMPLE_GM(largeglyphblur, canvas, 1920, 600) {
|
||||
const char text[] = "Hamburgefons";
|
||||
const char text[] = "Hamburgefons";
|
||||
|
||||
SkPaint paint;
|
||||
sk_tool_utils::set_portable_typeface(&paint);
|
||||
paint.setTextSize(256);
|
||||
paint.setAntiAlias(true);
|
||||
SkFont font(sk_tool_utils::create_portable_typeface(), 256);
|
||||
auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
|
||||
|
||||
// setup up maskfilter
|
||||
const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(40));
|
||||
// setup up maskfilter
|
||||
const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(40));
|
||||
|
||||
SkPaint blurPaint(paint);
|
||||
blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, kSigma));
|
||||
SkPaint blurPaint;
|
||||
blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, kSigma));
|
||||
|
||||
SkTextBlobBuilder builder;
|
||||
canvas->drawTextBlob(blob, 10, 200, blurPaint);
|
||||
canvas->drawTextBlob(blob, 10, 200, SkPaint());
|
||||
|
||||
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, paint);
|
||||
|
||||
size_t len = strlen(text);
|
||||
canvas->drawText(text, len, 10, 500, blurPaint);
|
||||
canvas->drawText(text, len, 10, 500, paint);
|
||||
size_t len = strlen(text);
|
||||
canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, 10, 500, font, blurPaint);
|
||||
canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, 10, 500, font, SkPaint());
|
||||
}
|
||||
|
@ -32,50 +32,52 @@ protected:
|
||||
|
||||
const char* text = "The quick brown fox jumps over the lazy dog.";
|
||||
|
||||
// make textbloben
|
||||
SkPaint paint;
|
||||
paint.setTextSize(32);
|
||||
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
|
||||
auto typeface = sk_tool_utils::create_portable_typeface("sans-serif", SkFontStyle::Bold());
|
||||
if (!typeface) {
|
||||
typeface = SkTypeface::MakeDefault();
|
||||
}
|
||||
paint.setColor(SK_ColorMAGENTA);
|
||||
paint.setTypeface(sk_make_sp<SkRandomTypeface>(std::move(typeface), paint, false));
|
||||
font.setTypeface(sk_make_sp<SkRandomTypeface>(std::move(typeface), paint, false));
|
||||
|
||||
SkScalar y = 0;
|
||||
SkRect bounds;
|
||||
paint.measureText(text, strlen(text), &bounds);
|
||||
font.measureText(text, strlen(text), kUTF8_SkTextEncoding, &bounds);
|
||||
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;
|
||||
|
||||
// A8
|
||||
const char* bigtext1 = "The quick brown fox";
|
||||
const char* bigtext2 = "jumps over the lazy dog.";
|
||||
paint.setTextSize(160);
|
||||
paint.setSubpixelText(false);
|
||||
paint.setLCDRenderText(false);
|
||||
paint.measureText(bigtext1, strlen(bigtext1), &bounds);
|
||||
font.setSize(160);
|
||||
font.setSubpixel(false);
|
||||
font.setEdging(SkFont::Edging::kAntiAlias);
|
||||
font.measureText(bigtext1, strlen(bigtext1), kUTF8_SkTextEncoding, &bounds);
|
||||
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;
|
||||
|
||||
paint.measureText(bigtext2, strlen(bigtext2), &bounds);
|
||||
font.measureText(bigtext2, strlen(bigtext2), kUTF8_SkTextEncoding, &bounds);
|
||||
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;
|
||||
|
||||
// color emoji
|
||||
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();
|
||||
paint.measureText(emojiText, strlen(emojiText), &bounds);
|
||||
font.measureText(emojiText, strlen(emojiText), kUTF8_SkTextEncoding, &bounds);
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user