blob: ae63432c08544d7d8ae3e759a7828dcc14a4f821 [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"
9#include "SkTypeface.h"
10#include "gm.h"
11
12static void excercise_draw_pos_text(SkCanvas* canvas,
13 const char* text,
14 SkScalar x, SkScalar y,
15 const SkPaint& paint) {
16 size_t textLen = strlen(text);
17 SkAutoTArray<SkScalar> widths(SkToInt(textLen));
18 paint.getTextWidths(text, textLen, &widths[0]);
19 SkAutoTArray<SkPoint> pos(SkToInt(textLen));
20 for (int i = 0; i < SkToInt(textLen); ++i) {
21 pos[i].set(x, y);
22 x += widths[i];
23 }
24 canvas->drawPosText(text, textLen, &pos[0], paint);
25}
26
27DEF_SIMPLE_GM(pdf_never_embed, canvas, 512, 512) {
scroggo9a9a7b22016-05-12 06:22:30 -070028 SkPaint p;
29 p.setTextSize(60);
bungeman13b9c952016-05-12 10:09:30 -070030 p.setTypeface(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"));
scroggo9a9a7b22016-05-12 06:22:30 -070031 p.setAntiAlias(true);
bungeman6296da72016-05-11 12:38:18 -070032
bungeman13b9c952016-05-12 10:09:30 -070033 if (!p.getTypeface()) {
34 return;
35 }
36
halcanary66a82f32015-10-12 13:05:04 -070037 const char text[] = "HELLO, WORLD!";
38
39 canvas->drawColor(SK_ColorWHITE);
40 excercise_draw_pos_text(canvas, text, 30, 90, p);
41
42 canvas->save();
43 canvas->rotate(45.0f);
44 p.setColor(0xF0800000);
45 excercise_draw_pos_text(canvas, text, 30, 45, p);
46 canvas->restore();
47
48 canvas->save();
49 canvas->scale(1, 4.0);
50 p.setColor(0xF0008000);
51 excercise_draw_pos_text(canvas, text, 15, 70, p);
52 canvas->restore();
53
54 canvas->scale(1.0, 0.5);
55 p.setColor(0xF0000080);
Cary Clark2a475ea2017-04-28 15:35:12 -040056 canvas->drawString(text, 30, 700, p);
halcanary66a82f32015-10-12 13:05:04 -070057}