diff --git a/gm/typeface.cpp b/gm/typeface.cpp index 9be01d4dd3..752f938e06 100644 --- a/gm/typeface.cpp +++ b/gm/typeface.cpp @@ -359,86 +359,95 @@ static void draw_typeface_rendering_gm(SkCanvas* canvas, sk_sp face, } } -DEF_SIMPLE_GM(typefacerendering, canvas, 640, 840) { - if (sk_sp 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 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 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 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 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 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 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 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 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 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); + } +}