halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkFont.h" |
| 12 | #include "include/core/SkFontTypes.h" |
| 13 | #include "include/core/SkPaint.h" |
| 14 | #include "include/core/SkScalar.h" |
| 15 | #include "include/core/SkString.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/core/SkTextBlob.h" |
| 17 | #include "include/core/SkTypeface.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "tools/Resources.h" |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 19 | |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 20 | #include <string.h> |
| 21 | |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 22 | static void excercise_draw_pos_text(SkCanvas* canvas, |
| 23 | const char* text, |
| 24 | SkScalar x, SkScalar y, |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 25 | const SkFont& font, |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 26 | const SkPaint& paint) { |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 27 | const int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 28 | SkTextBlobBuilder builder; |
| 29 | auto rec = builder.allocRunPos(font, count); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 30 | font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, rec.glyphs, count); |
Mike Reed | 22451cc | 2019-01-01 15:40:28 -0500 | [diff] [blame] | 31 | font.getPos(rec.glyphs, count, rec.points()); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 32 | canvas->drawTextBlob(builder.make(), x, y, paint); |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 35 | DEF_SIMPLE_GM_CAN_FAIL(pdf_never_embed, canvas, errorMsg, 512, 512) { |
scroggo | 9a9a7b2 | 2016-05-12 06:22:30 -0700 | [diff] [blame] | 36 | SkPaint p; |
bungeman | 6296da7 | 2016-05-11 12:38:18 -0700 | [diff] [blame] | 37 | |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 38 | SkFont font(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"), 60); |
Herb Derby | 087fad7 | 2019-01-22 14:45:16 -0500 | [diff] [blame] | 39 | if (!font.getTypefaceOrDefault()) { |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 40 | *errorMsg = "Could not load fonts/Roboto2-Regular_NoEmbed.ttf. " |
| 41 | "Did you forget to set the resourcePath?"; |
| 42 | return skiagm::DrawResult::kFail; |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 43 | } |
| 44 | |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 45 | const char text[] = "HELLO, WORLD!"; |
| 46 | |
| 47 | canvas->drawColor(SK_ColorWHITE); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 48 | excercise_draw_pos_text(canvas, text, 30, 90, font, p); |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 49 | |
| 50 | canvas->save(); |
| 51 | canvas->rotate(45.0f); |
| 52 | p.setColor(0xF0800000); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 53 | excercise_draw_pos_text(canvas, text, 30, 45, font, p); |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 54 | canvas->restore(); |
| 55 | |
| 56 | canvas->save(); |
| 57 | canvas->scale(1, 4.0); |
| 58 | p.setColor(0xF0008000); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 59 | excercise_draw_pos_text(canvas, text, 15, 70, font, p); |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 60 | canvas->restore(); |
| 61 | |
| 62 | canvas->scale(1.0, 0.5); |
| 63 | p.setColor(0xF0000080); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 64 | canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 30, 700, font, p); |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 65 | return skiagm::DrawResult::kOk; |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 66 | } |
Hal Canary | 4e83ff1 | 2018-03-09 12:16:42 -0500 | [diff] [blame] | 67 | |
| 68 | |
| 69 | // should draw completely white. |
| 70 | DEF_SIMPLE_GM(pdf_crbug_772685, canvas, 612, 792) { |
| 71 | canvas->clipRect({-1, -1, 613, 793}, false); |
| 72 | canvas->translate(-571, 0); |
| 73 | canvas->scale(0.75, 0.75); |
| 74 | canvas->clipRect({-1, -1, 613, 793}, false); |
| 75 | canvas->translate(0, -816); |
| 76 | canvas->drawRect({0, 0, 1224, 1500}, SkPaint()); |
| 77 | } |