blob: 583ff3e1eddb374d06a4fdecee4efa08111df8ed [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"
Mike Reed088b74e2018-12-24 14:52:46 -05009#include "SkTextBlob.h"
Hal Canaryc640d0d2018-06-13 09:59:02 -040010#include "SkTo.h"
halcanary66a82f32015-10-12 13:05:04 -070011#include "SkTypeface.h"
12#include "gm.h"
13
14static void excercise_draw_pos_text(SkCanvas* canvas,
15 const char* text,
16 SkScalar x, SkScalar y,
Mike Reed088b74e2018-12-24 14:52:46 -050017 const SkFont& font,
halcanary66a82f32015-10-12 13:05:04 -070018 const SkPaint& paint) {
Mike Reed088b74e2018-12-24 14:52:46 -050019 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);
Mike Reed22451cc2019-01-01 15:40:28 -050023 font.getPos(rec.glyphs, count, rec.points());
Mike Reed088b74e2018-12-24 14:52:46 -050024 canvas->drawTextBlob(builder.make(), x, y, paint);
halcanary66a82f32015-10-12 13:05:04 -070025}
26
27DEF_SIMPLE_GM(pdf_never_embed, canvas, 512, 512) {
scroggo9a9a7b22016-05-12 06:22:30 -070028 SkPaint p;
bungeman6296da72016-05-11 12:38:18 -070029
Mike Reed088b74e2018-12-24 14:52:46 -050030 SkFont font(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"), 60);
31 if (!font.getTypeface()) {
bungeman13b9c952016-05-12 10:09:30 -070032 return;
33 }
34
halcanary66a82f32015-10-12 13:05:04 -070035 const char text[] = "HELLO, WORLD!";
36
37 canvas->drawColor(SK_ColorWHITE);
Mike Reed088b74e2018-12-24 14:52:46 -050038 excercise_draw_pos_text(canvas, text, 30, 90, font, p);
halcanary66a82f32015-10-12 13:05:04 -070039
40 canvas->save();
41 canvas->rotate(45.0f);
42 p.setColor(0xF0800000);
Mike Reed088b74e2018-12-24 14:52:46 -050043 excercise_draw_pos_text(canvas, text, 30, 45, font, p);
halcanary66a82f32015-10-12 13:05:04 -070044 canvas->restore();
45
46 canvas->save();
47 canvas->scale(1, 4.0);
48 p.setColor(0xF0008000);
Mike Reed088b74e2018-12-24 14:52:46 -050049 excercise_draw_pos_text(canvas, text, 15, 70, font, p);
halcanary66a82f32015-10-12 13:05:04 -070050 canvas->restore();
51
52 canvas->scale(1.0, 0.5);
53 p.setColor(0xF0000080);
Mike Reed088b74e2018-12-24 14:52:46 -050054 canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 30, 700, font, p);
halcanary66a82f32015-10-12 13:05:04 -070055}
Hal Canary4e83ff12018-03-09 12:16:42 -050056
57
58// should draw completely white.
59DEF_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}