blob: 3b96ae4a868392fe0a31389e8abafd8ce6f05aa0 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/core/SkTextBlob.h"
17#include "include/core/SkTypeface.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "tools/Resources.h"
halcanary66a82f32015-10-12 13:05:04 -070019
Ben Wagner7fde8e12019-05-01 17:28:53 -040020#include <string.h>
21
halcanary66a82f32015-10-12 13:05:04 -070022static void excercise_draw_pos_text(SkCanvas* canvas,
23 const char* text,
24 SkScalar x, SkScalar y,
Mike Reed088b74e2018-12-24 14:52:46 -050025 const SkFont& font,
halcanary66a82f32015-10-12 13:05:04 -070026 const SkPaint& paint) {
Ben Wagner51e15a62019-05-07 15:38:46 -040027 const int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8);
Mike Reed088b74e2018-12-24 14:52:46 -050028 SkTextBlobBuilder builder;
29 auto rec = builder.allocRunPos(font, count);
Ben Wagner51e15a62019-05-07 15:38:46 -040030 font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, rec.glyphs, count);
Mike Reed22451cc2019-01-01 15:40:28 -050031 font.getPos(rec.glyphs, count, rec.points());
Mike Reed088b74e2018-12-24 14:52:46 -050032 canvas->drawTextBlob(builder.make(), x, y, paint);
halcanary66a82f32015-10-12 13:05:04 -070033}
34
Chris Dalton50e24d72019-02-07 16:20:09 -070035DEF_SIMPLE_GM_CAN_FAIL(pdf_never_embed, canvas, errorMsg, 512, 512) {
scroggo9a9a7b22016-05-12 06:22:30 -070036 SkPaint p;
bungeman6296da72016-05-11 12:38:18 -070037
Mike Reed088b74e2018-12-24 14:52:46 -050038 SkFont font(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"), 60);
Herb Derby087fad72019-01-22 14:45:16 -050039 if (!font.getTypefaceOrDefault()) {
Chris Dalton50e24d72019-02-07 16:20:09 -070040 *errorMsg = "Could not load fonts/Roboto2-Regular_NoEmbed.ttf. "
41 "Did you forget to set the resourcePath?";
42 return skiagm::DrawResult::kFail;
bungeman13b9c952016-05-12 10:09:30 -070043 }
44
halcanary66a82f32015-10-12 13:05:04 -070045 const char text[] = "HELLO, WORLD!";
46
47 canvas->drawColor(SK_ColorWHITE);
Mike Reed088b74e2018-12-24 14:52:46 -050048 excercise_draw_pos_text(canvas, text, 30, 90, font, p);
halcanary66a82f32015-10-12 13:05:04 -070049
50 canvas->save();
51 canvas->rotate(45.0f);
52 p.setColor(0xF0800000);
Mike Reed088b74e2018-12-24 14:52:46 -050053 excercise_draw_pos_text(canvas, text, 30, 45, font, p);
halcanary66a82f32015-10-12 13:05:04 -070054 canvas->restore();
55
56 canvas->save();
57 canvas->scale(1, 4.0);
58 p.setColor(0xF0008000);
Mike Reed088b74e2018-12-24 14:52:46 -050059 excercise_draw_pos_text(canvas, text, 15, 70, font, p);
halcanary66a82f32015-10-12 13:05:04 -070060 canvas->restore();
61
62 canvas->scale(1.0, 0.5);
63 p.setColor(0xF0000080);
Ben Wagner51e15a62019-05-07 15:38:46 -040064 canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 30, 700, font, p);
Chris Dalton50e24d72019-02-07 16:20:09 -070065 return skiagm::DrawResult::kOk;
halcanary66a82f32015-10-12 13:05:04 -070066}
Hal Canary4e83ff12018-03-09 12:16:42 -050067
68
69// should draw completely white.
70DEF_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}