Fix typeface GMs to draw or skip
Before this change the typeface_styling GM would draw an empty canvas if the default SkFontMgr could not load a 'ttf' font. Instead of drawing nothing, attempt to draw an 'A' in the default available font. Before this change the typeface_rendering GMs would draw an empty canvas if the default SkFontMgr could not load a 'ttf' font. Instea of drawing nothing, skip the test instead. Change-Id: I15b3c5aae7ac0d2e8f0291456a84291768b009a0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/438276 Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
6a42e7e479
commit
8477dd24c8
147
gm/typeface.cpp
147
gm/typeface.cpp
@ -359,86 +359,95 @@ static void draw_typeface_rendering_gm(SkCanvas* canvas, sk_sp<SkTypeface> face,
|
||||
}
|
||||
}
|
||||
|
||||
DEF_SIMPLE_GM(typefacerendering, canvas, 640, 840) {
|
||||
if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/hintgasp.ttf")) {
|
||||
draw_typeface_rendering_gm(canvas, face, face->unicharToGlyph('A'));
|
||||
|
||||
// Should draw nothing and not do anything undefined.
|
||||
draw_typeface_rendering_gm(canvas, face, 0xFFFF);
|
||||
DEF_SIMPLE_GM_CAN_FAIL(typefacerendering, canvas, errMsg, 640, 840) {
|
||||
sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/hintgasp.ttf");
|
||||
if (!face) {
|
||||
return skiagm::DrawResult::kSkip;
|
||||
}
|
||||
}
|
||||
draw_typeface_rendering_gm(canvas, face, face->unicharToGlyph('A'));
|
||||
|
||||
#include "include/effects/SkStrokeAndFillPathEffect.h"
|
||||
|
||||
// Exercise different paint styles and embolden, and compare with strokeandfill patheffect
|
||||
DEF_SIMPLE_GM(typeface_styling, canvas, 710, 360) {
|
||||
if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto-Regular.ttf")) {
|
||||
|
||||
uint16_t glyphs[1] = { face->unicharToGlyph('A') };
|
||||
SkPoint pos[1] = { {0, 0} };
|
||||
|
||||
SkFont font;
|
||||
font.setTypeface(face);
|
||||
font.setSize(100);
|
||||
font.setEdging(SkFont::Edging::kAntiAlias);
|
||||
|
||||
auto draw = [&](SkPaint::Style style, float width, sk_sp<SkPathEffect> pe) {
|
||||
// Draws 3 rows:
|
||||
// 1. normal
|
||||
// 2. emboldened
|
||||
// 3. normal(white) on top of emboldened (to show the delta)
|
||||
|
||||
SkPaint paint;
|
||||
paint.setStyle(style);
|
||||
paint.setStrokeWidth(width);
|
||||
paint.setPathEffect(pe);
|
||||
|
||||
font.setEmbolden(true);
|
||||
canvas->drawGlyphs(1, glyphs, pos, {20, 120*2}, font, paint);
|
||||
canvas->drawGlyphs(1, glyphs, pos, {20, 120*3}, font, paint);
|
||||
|
||||
font.setEmbolden(false);
|
||||
canvas->drawGlyphs(1, glyphs, pos, {20, 120*1}, font, paint);
|
||||
paint.setColor(SK_ColorYELLOW);
|
||||
canvas->drawGlyphs(1, glyphs, pos, {20, 120*3}, font, paint);
|
||||
};
|
||||
|
||||
const struct {
|
||||
SkPaint::Style style;
|
||||
float width;
|
||||
bool usePE;
|
||||
} recs[] = {
|
||||
{ SkPaint::kFill_Style, 0, false },
|
||||
{ SkPaint::kStroke_Style, 0, false },
|
||||
{ SkPaint::kStroke_Style, 3, false },
|
||||
{ SkPaint::kStrokeAndFill_Style, 0, false },
|
||||
{ SkPaint::kStrokeAndFill_Style, 3, false },
|
||||
{ SkPaint::kStroke_Style, 0, true },
|
||||
{ SkPaint::kStroke_Style, 3, true },
|
||||
};
|
||||
|
||||
canvas->translate(0, -20);
|
||||
auto pe = SkStrokeAndFillPathEffect::Make();
|
||||
for (auto r : recs) {
|
||||
draw(r.style, r.width, r.usePE ? pe : nullptr);
|
||||
canvas->translate(100, 0);
|
||||
}
|
||||
}
|
||||
// Should draw nothing and not do anything undefined.
|
||||
draw_typeface_rendering_gm(canvas, face, 0xFFFF);
|
||||
return skiagm::DrawResult::kOk;
|
||||
}
|
||||
|
||||
// Type1 fonts don't currently work in Skia on Windows.
|
||||
#ifndef SK_BUILD_FOR_WIN
|
||||
|
||||
DEF_SIMPLE_GM(typefacerendering_pfa, canvas, 640, 840) {
|
||||
if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto2-Regular.pfa")) {
|
||||
draw_typeface_rendering_gm(canvas, face, face->unicharToGlyph('O'));
|
||||
DEF_SIMPLE_GM_CAN_FAIL(typefacerendering_pfa, canvas, errMsg, 640, 840) {
|
||||
sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto2-Regular.pfa");
|
||||
if (!face) {
|
||||
return skiagm::DrawResult::kSkip;
|
||||
}
|
||||
draw_typeface_rendering_gm(canvas, face, face->unicharToGlyph('O'));
|
||||
return skiagm::DrawResult::kOk;
|
||||
}
|
||||
|
||||
DEF_SIMPLE_GM(typefacerendering_pfb, canvas, 640, 840) {
|
||||
if (sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto2-Regular.pfb")) {
|
||||
draw_typeface_rendering_gm(canvas, face, face->unicharToGlyph('O'));
|
||||
DEF_SIMPLE_GM_CAN_FAIL(typefacerendering_pfb, canvas, errMsg, 640, 840) {
|
||||
sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto2-Regular.pfb");
|
||||
if (!face) {
|
||||
return skiagm::DrawResult::kSkip;
|
||||
}
|
||||
draw_typeface_rendering_gm(canvas, face, face->unicharToGlyph('O'));
|
||||
return skiagm::DrawResult::kOk;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "include/effects/SkStrokeAndFillPathEffect.h"
|
||||
|
||||
// Exercise different paint styles and embolden, and compare with strokeandfill patheffect
|
||||
DEF_SIMPLE_GM(typeface_styling, canvas, 710, 360) {
|
||||
sk_sp<SkTypeface> face = MakeResourceAsTypeface("fonts/Roboto-Regular.ttf");
|
||||
SkFont font;
|
||||
font.setTypeface(face);
|
||||
font.setSize(100);
|
||||
font.setEdging(SkFont::Edging::kAntiAlias);
|
||||
|
||||
uint16_t glyphs[1] = { font.unicharToGlyph('A') };
|
||||
SkPoint pos[1] = { {0, 0} };
|
||||
|
||||
auto draw = [&](SkPaint::Style style, float width, sk_sp<SkPathEffect> pe) {
|
||||
// Draws 3 rows:
|
||||
// 1. normal
|
||||
// 2. emboldened
|
||||
// 3. normal(white) on top of emboldened (to show the delta)
|
||||
|
||||
SkPaint paint;
|
||||
paint.setStyle(style);
|
||||
paint.setStrokeWidth(width);
|
||||
paint.setPathEffect(pe);
|
||||
|
||||
font.setEmbolden(true);
|
||||
canvas->drawGlyphs(1, glyphs, pos, {20, 120*2}, font, paint);
|
||||
canvas->drawGlyphs(1, glyphs, pos, {20, 120*3}, font, paint);
|
||||
|
||||
font.setEmbolden(false);
|
||||
canvas->drawGlyphs(1, glyphs, pos, {20, 120*1}, font, paint);
|
||||
paint.setColor(SK_ColorYELLOW);
|
||||
canvas->drawGlyphs(1, glyphs, pos, {20, 120*3}, font, paint);
|
||||
};
|
||||
|
||||
const struct {
|
||||
SkPaint::Style style;
|
||||
float width;
|
||||
bool usePE;
|
||||
} recs[] = {
|
||||
{ SkPaint::kFill_Style, 0, false },
|
||||
{ SkPaint::kStroke_Style, 0, false },
|
||||
{ SkPaint::kStroke_Style, 3, false },
|
||||
{ SkPaint::kStrokeAndFill_Style, 0, false },
|
||||
{ SkPaint::kStrokeAndFill_Style, 3, false },
|
||||
{ SkPaint::kStroke_Style, 0, true },
|
||||
{ SkPaint::kStroke_Style, 3, true },
|
||||
};
|
||||
|
||||
canvas->translate(0, -20);
|
||||
auto pe = SkStrokeAndFillPathEffect::Make();
|
||||
for (auto r : recs) {
|
||||
draw(r.style, r.width, r.usePE ? pe : nullptr);
|
||||
canvas->translate(100, 0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user