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_CAN_FAIL(pdf_never_embed, canvas, errorMsg, 512, 512) {
28 SkPaint p;
29
30 SkFont font(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"), 60);
31 if (!font.getTypefaceOrDefault()) {
32 *errorMsg = "Could not load fonts/Roboto2-Regular_NoEmbed.ttf. "
33 "Did you forget to set the resourcePath?";
34 return skiagm::DrawResult::kFail;
35 }
36
37 const char text[] = "HELLO, WORLD!";
38
39 canvas->drawColor(SK_ColorWHITE);
40 excercise_draw_pos_text(canvas, text, 30, 90, font, p);
41
42 canvas->save();
43 canvas->rotate(45.0f);
44 p.setColor(0xF0800000);
45 excercise_draw_pos_text(canvas, text, 30, 45, font, 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, font, p);
52 canvas->restore();
53
54 canvas->scale(1.0, 0.5);
55 p.setColor(0xF0000080);
56 canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 30, 700, font, p);
57 return skiagm::DrawResult::kOk;
58 }
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