• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gm/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkFont.h"
12 #include "include/core/SkFontTypes.h"
13 #include "include/core/SkPaint.h"
14 #include "include/core/SkScalar.h"
15 #include "include/core/SkString.h"
16 #include "include/core/SkTextBlob.h"
17 #include "include/core/SkTypeface.h"
18 #include "tools/Resources.h"
19 
20 #include <string.h>
21 
excercise_draw_pos_text(SkCanvas * canvas,const char * text,SkScalar x,SkScalar y,const SkFont & font,const SkPaint & paint)22 static void excercise_draw_pos_text(SkCanvas* canvas,
23                                     const char* text,
24                                     SkScalar x, SkScalar y,
25                                     const SkFont& font,
26                                     const SkPaint& paint) {
27     const int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8);
28     SkTextBlobBuilder builder;
29     auto rec = builder.allocRunPos(font, count);
30     font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, rec.glyphs, count);
31     font.getPos(rec.glyphs, count, rec.points());
32     canvas->drawTextBlob(builder.make(), x, y, paint);
33 }
34 
35 DEF_SIMPLE_GM_CAN_FAIL(pdf_never_embed, canvas, errorMsg, 512, 512) {
36     SkPaint p;
37 
38     SkFont font(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"), 60);
39     if (!font.getTypefaceOrDefault()) {
40         *errorMsg = "Could not load fonts/Roboto2-Regular_NoEmbed.ttf. "
41                     "Did you forget to set the resourcePath?";
42         return skiagm::DrawResult::kFail;
43     }
44 
45     const char text[] = "HELLO, WORLD!";
46 
47     canvas->drawColor(SK_ColorWHITE);
48     excercise_draw_pos_text(canvas, text, 30, 90, font, p);
49 
50     canvas->save();
51     canvas->rotate(45.0f);
52     p.setColor(0xF0800000);
53     excercise_draw_pos_text(canvas, text, 30, 45, font, p);
54     canvas->restore();
55 
56     canvas->save();
57     canvas->scale(1, 4.0);
58     p.setColor(0xF0008000);
59     excercise_draw_pos_text(canvas, text, 15, 70, font, p);
60     canvas->restore();
61 
62     canvas->scale(1.0, 0.5);
63     p.setColor(0xF0000080);
64     canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 30, 700, font, p);
65     return skiagm::DrawResult::kOk;
66 }
67 
68 
69 // should draw completely white.
70 DEF_SIMPLE_GM(pdf_crbug_772685, canvas, 612, 792) {
71     canvas->clipRect({-1, -1, 613, 793}, false);
72     canvas->translate(-571, 0);
73     canvas->scale(0.75, 0.75);
74     canvas->clipRect({-1, -1, 613, 793}, false);
75     canvas->translate(0, -816);
76     canvas->drawRect({0, 0, 1224, 1500}, SkPaint());
77 }
78