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 | |
| 8 | #include "Resources.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 9 | #include "SkTo.h" |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 10 | #include "SkTypeface.h" |
| 11 | #include "gm.h" |
| 12 | |
| 13 | static void excercise_draw_pos_text(SkCanvas* canvas, |
| 14 | const char* text, |
| 15 | SkScalar x, SkScalar y, |
| 16 | const SkPaint& paint) { |
| 17 | size_t textLen = strlen(text); |
| 18 | SkAutoTArray<SkScalar> widths(SkToInt(textLen)); |
| 19 | paint.getTextWidths(text, textLen, &widths[0]); |
| 20 | SkAutoTArray<SkPoint> pos(SkToInt(textLen)); |
| 21 | for (int i = 0; i < SkToInt(textLen); ++i) { |
| 22 | pos[i].set(x, y); |
| 23 | x += widths[i]; |
| 24 | } |
| 25 | canvas->drawPosText(text, textLen, &pos[0], paint); |
| 26 | } |
| 27 | |
| 28 | DEF_SIMPLE_GM(pdf_never_embed, canvas, 512, 512) { |
scroggo | 9a9a7b2 | 2016-05-12 06:22:30 -0700 | [diff] [blame] | 29 | SkPaint p; |
| 30 | p.setTextSize(60); |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 31 | p.setTypeface(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf")); |
scroggo | 9a9a7b2 | 2016-05-12 06:22:30 -0700 | [diff] [blame] | 32 | p.setAntiAlias(true); |
bungeman | 6296da7 | 2016-05-11 12:38:18 -0700 | [diff] [blame] | 33 | |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 34 | if (!p.getTypeface()) { |
| 35 | return; |
| 36 | } |
| 37 | |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 38 | const char text[] = "HELLO, WORLD!"; |
| 39 | |
| 40 | canvas->drawColor(SK_ColorWHITE); |
| 41 | excercise_draw_pos_text(canvas, text, 30, 90, p); |
| 42 | |
| 43 | canvas->save(); |
| 44 | canvas->rotate(45.0f); |
| 45 | p.setColor(0xF0800000); |
| 46 | excercise_draw_pos_text(canvas, text, 30, 45, p); |
| 47 | canvas->restore(); |
| 48 | |
| 49 | canvas->save(); |
| 50 | canvas->scale(1, 4.0); |
| 51 | p.setColor(0xF0008000); |
| 52 | excercise_draw_pos_text(canvas, text, 15, 70, p); |
| 53 | canvas->restore(); |
| 54 | |
| 55 | canvas->scale(1.0, 0.5); |
| 56 | p.setColor(0xF0000080); |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 57 | canvas->drawString(text, 30, 700, p); |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 58 | } |
Hal Canary | 4e83ff1 | 2018-03-09 12:16:42 -0500 | [diff] [blame] | 59 | |
| 60 | |
| 61 | // should draw completely white. |
| 62 | DEF_SIMPLE_GM(pdf_crbug_772685, canvas, 612, 792) { |
| 63 | canvas->clipRect({-1, -1, 613, 793}, false); |
| 64 | canvas->translate(-571, 0); |
| 65 | canvas->scale(0.75, 0.75); |
| 66 | canvas->clipRect({-1, -1, 613, 793}, false); |
| 67 | canvas->translate(0, -816); |
| 68 | canvas->drawRect({0, 0, 1224, 1500}, SkPaint()); |
| 69 | } |
| 70 | |