blob: adaf78b450bda75d746bffab5f77201c47204677 [file] [log] [blame]
halcanary66a82f32015-10-12 13:05:04 -07001/*
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 Canaryc640d0d2018-06-13 09:59:02 -04009#include "SkTo.h"
halcanary66a82f32015-10-12 13:05:04 -070010#include "SkTypeface.h"
11#include "gm.h"
12
13static 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
28DEF_SIMPLE_GM(pdf_never_embed, canvas, 512, 512) {
scroggo9a9a7b22016-05-12 06:22:30 -070029 SkPaint p;
30 p.setTextSize(60);
bungeman13b9c952016-05-12 10:09:30 -070031 p.setTypeface(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"));
scroggo9a9a7b22016-05-12 06:22:30 -070032 p.setAntiAlias(true);
bungeman6296da72016-05-11 12:38:18 -070033
bungeman13b9c952016-05-12 10:09:30 -070034 if (!p.getTypeface()) {
35 return;
36 }
37
halcanary66a82f32015-10-12 13:05:04 -070038 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 Clark2a475ea2017-04-28 15:35:12 -040057 canvas->drawString(text, 30, 700, p);
halcanary66a82f32015-10-12 13:05:04 -070058}
Hal Canary4e83ff12018-03-09 12:16:42 -050059
60
61// should draw completely white.
62DEF_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