1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "gm/gm.h" 9 #include "include/core/SkCanvas.h" 10 #include "include/core/SkColor.h" 11 #include "include/core/SkData.h" 12 #include "include/core/SkFont.h" 13 #include "include/core/SkFontTypes.h" 14 #include "include/core/SkPaint.h" 15 #include "include/core/SkPoint.h" 16 #include "include/core/SkRect.h" 17 #include "include/core/SkSize.h" 18 #include "include/core/SkString.h" 19 #include "include/core/SkTypeface.h" 20 #include "tools/Resources.h" 21 #include "tools/ToolUtils.h" 22 #include "tools/fonts/FontToolUtils.h" 23 24 /** 25 * Skia may draw from outlines when the size is very large, so we exercise that 26 * here. 27 */ 28 29 class BigTextGM : public skiagm::GM { 30 public: BigTextGM()31 BigTextGM() {} 32 33 protected: getName() const34 SkString getName() const override { return SkString("bigtext"); } 35 getISize()36 SkISize getISize() override { return SkISize::Make(640, 480); } 37 onDraw(SkCanvas * canvas)38 void onDraw(SkCanvas* canvas) override { 39 SkPaint paint; 40 paint.setAntiAlias(true); 41 SkFont font(ToolUtils::DefaultPortableTypeface(), 1500); 42 43 SkRect r; 44 (void)font.measureText("/", 1, SkTextEncoding::kUTF8, &r); 45 SkPoint pos = { 46 this->width()/2 - r.centerX(), 47 this->height()/2 - r.centerY() 48 }; 49 50 paint.setColor(SK_ColorRED); 51 canvas->drawSimpleText("/", 1, SkTextEncoding::kUTF8, pos.fX, pos.fY, font, paint); 52 53 paint.setColor(SK_ColorBLUE); 54 canvas->drawSimpleText("\\", 1, SkTextEncoding::kUTF8, pos.fX, pos.fY, font, paint); 55 } 56 57 private: 58 using INHERITED = skiagm::GM; 59 }; 60 61 DEF_GM(return new BigTextGM;) 62 63 // Exercise the case where the glyph is sufficiently large that we should just draw with a path, 64 // but the DirectWrite scaler context failed to calculate the bounds and reported empty bounds. 65 // With empty bounds the glyph was discarded instead of rendered from path. See crbug.com/1370488 66 DEF_SIMPLE_GM(bigtext_crbug_1370488, canvas, 512, 512) { 67 auto typeface = ToolUtils::CreateTypefaceFromResource("fonts/SpiderSymbol.ttf"); 68 const char* text = "\xEF\x80\xA1"; 69 if (!typeface) { 70 typeface = ToolUtils::DefaultPortableTypeface(); 71 text = "H"; 72 } 73 74 SkFont font(typeface, 12.f); 75 canvas->translate(-1800.f, 1800.f); 76 canvas->scale(437.5f, 437.5f); 77 SkPaint paint; 78 paint.setAntiAlias(true); 79 canvas->drawString(text, 0.f, 0.f, font, paint); 80 } 81