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" |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 9 | #include "SkTextBlob.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 10 | #include "SkTo.h" |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 11 | #include "SkTypeface.h" |
| 12 | #include "gm.h" |
| 13 | |
| 14 | static void excercise_draw_pos_text(SkCanvas* canvas, |
| 15 | const char* text, |
| 16 | SkScalar x, SkScalar y, |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 17 | const SkFont& font, |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 18 | const SkPaint& paint) { |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 19 | const int count = font.countText(text, strlen(text), kUTF8_SkTextEncoding); |
| 20 | SkTextBlobBuilder builder; |
| 21 | auto rec = builder.allocRunPos(font, count); |
| 22 | font.textToGlyphs(text, strlen(text), kUTF8_SkTextEncoding, rec.glyphs, count); |
Mike Reed | 22451cc | 2019-01-01 15:40:28 -0500 | [diff] [blame^] | 23 | font.getPos(rec.glyphs, count, rec.points()); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 24 | canvas->drawTextBlob(builder.make(), x, y, paint); |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | DEF_SIMPLE_GM(pdf_never_embed, canvas, 512, 512) { |
scroggo | 9a9a7b2 | 2016-05-12 06:22:30 -0700 | [diff] [blame] | 28 | SkPaint p; |
bungeman | 6296da7 | 2016-05-11 12:38:18 -0700 | [diff] [blame] | 29 | |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 30 | SkFont font(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"), 60); |
| 31 | if (!font.getTypeface()) { |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 32 | return; |
| 33 | } |
| 34 | |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 35 | const char text[] = "HELLO, WORLD!"; |
| 36 | |
| 37 | canvas->drawColor(SK_ColorWHITE); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 38 | excercise_draw_pos_text(canvas, text, 30, 90, font, p); |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 39 | |
| 40 | canvas->save(); |
| 41 | canvas->rotate(45.0f); |
| 42 | p.setColor(0xF0800000); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 43 | excercise_draw_pos_text(canvas, text, 30, 45, font, p); |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 44 | canvas->restore(); |
| 45 | |
| 46 | canvas->save(); |
| 47 | canvas->scale(1, 4.0); |
| 48 | p.setColor(0xF0008000); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 49 | excercise_draw_pos_text(canvas, text, 15, 70, font, p); |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 50 | canvas->restore(); |
| 51 | |
| 52 | canvas->scale(1.0, 0.5); |
| 53 | p.setColor(0xF0000080); |
Mike Reed | 088b74e | 2018-12-24 14:52:46 -0500 | [diff] [blame] | 54 | canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 30, 700, font, p); |
halcanary | 66a82f3 | 2015-10-12 13:05:04 -0700 | [diff] [blame] | 55 | } |
Hal Canary | 4e83ff1 | 2018-03-09 12:16:42 -0500 | [diff] [blame] | 56 | |
| 57 | |
| 58 | // should draw completely white. |
| 59 | DEF_SIMPLE_GM(pdf_crbug_772685, canvas, 612, 792) { |
| 60 | canvas->clipRect({-1, -1, 613, 793}, false); |
| 61 | canvas->translate(-571, 0); |
| 62 | canvas->scale(0.75, 0.75); |
| 63 | canvas->clipRect({-1, -1, 613, 793}, false); |
| 64 | canvas->translate(0, -816); |
| 65 | canvas->drawRect({0, 0, 1224, 1500}, SkPaint()); |
| 66 | } |