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"
9 #include "SkTextBlob.h"
10 #include "SkTo.h"
11 #include "SkTypeface.h"
12 #include "gm.h"
13
excercise_draw_pos_text(SkCanvas * canvas,const char * text,SkScalar x,SkScalar y,const SkFont & font,const SkPaint & paint)14 static void excercise_draw_pos_text(SkCanvas* canvas,
15 const char* text,
16 SkScalar x, SkScalar y,
17 const SkFont& font,
18 const SkPaint& paint) {
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);
23 font.getPos(rec.glyphs, count, rec.points());
24 canvas->drawTextBlob(builder.make(), x, y, paint);
25 }
26
27 DEF_SIMPLE_GM(pdf_never_embed, canvas, 512, 512) {
28 SkPaint p;
29
30 SkFont font(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"), 60);
31 if (!font.getTypefaceOrDefault()) {
32 return;
33 }
34
35 const char text[] = "HELLO, WORLD!";
36
37 canvas->drawColor(SK_ColorWHITE);
38 excercise_draw_pos_text(canvas, text, 30, 90, font, p);
39
40 canvas->save();
41 canvas->rotate(45.0f);
42 p.setColor(0xF0800000);
43 excercise_draw_pos_text(canvas, text, 30, 45, font, p);
44 canvas->restore();
45
46 canvas->save();
47 canvas->scale(1, 4.0);
48 p.setColor(0xF0008000);
49 excercise_draw_pos_text(canvas, text, 15, 70, font, p);
50 canvas->restore();
51
52 canvas->scale(1.0, 0.5);
53 p.setColor(0xF0000080);
54 canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 30, 700, font, p);
55 }
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 }
67