Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
pdf_never_embed.cpp
Go to the documentation of this file.
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"
11#include "include/core/SkFont.h"
18#include "src/core/SkFontPriv.h"
19#include "tools/Resources.h"
21
22#include <string.h>
23
25 const char* text,
27 const SkFont& font,
28 const SkPaint& paint) {
29 const int count = font.countText(text, strlen(text), SkTextEncoding::kUTF8);
30 SkTextBlobBuilder builder;
31 auto rec = builder.allocRunPos(font, count);
32 font.textToGlyphs(text, strlen(text), SkTextEncoding::kUTF8, rec.glyphs, count);
33 font.getPos(rec.glyphs, count, rec.points());
34 canvas->drawTextBlob(builder.make(), x, y, paint);
35}
36
37DEF_SIMPLE_GM_CAN_FAIL(pdf_never_embed, canvas, errorMsg, 512, 512) {
38 SkPaint p;
39
41 ToolUtils::CreateTypefaceFromResource("fonts/Roboto2-Regular_NoEmbed.ttf");
42 if (!tf) {
44 }
45 SkASSERT(tf);
46 SkFont font(tf, 60);
47
48 const char text[] = "HELLO, WORLD!";
49
50 canvas->drawColor(SK_ColorWHITE);
51 excercise_draw_pos_text(canvas, text, 30, 90, font, p);
52
53 canvas->save();
54 canvas->rotate(45.0f);
55 p.setColor(0xF0800000);
56 excercise_draw_pos_text(canvas, text, 30, 45, font, p);
57 canvas->restore();
58
59 canvas->save();
60 canvas->scale(1, 4.0);
61 p.setColor(0xF0008000);
62 excercise_draw_pos_text(canvas, text, 15, 70, font, p);
63 canvas->restore();
64
65 canvas->scale(1.0, 0.5);
66 p.setColor(0xF0000080);
67 canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 30, 700, font, p);
69}
70
71
72// should draw completely white.
73DEF_SIMPLE_GM(pdf_crbug_772685, canvas, 612, 792) {
74 canvas->clipRect({-1, -1, 613, 793}, false);
75 canvas->translate(-571, 0);
76 canvas->scale(0.75, 0.75);
77 canvas->clipRect({-1, -1, 613, 793}, false);
78 canvas->translate(0, -816);
79 canvas->drawRect({0, 0, 1224, 1500}, SkPaint());
80}
int count
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
const Paint & paint
float SkScalar
Definition extension.cpp:12
#define DEF_SIMPLE_GM_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H)
Definition gm.h:62
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
std::u16string text
double y
double x
sk_sp< SkTypeface > DefaultPortableTypeface()
sk_sp< SkTypeface > CreateTypefaceFromResource(const char *resource, int ttcIndex)
static void excercise_draw_pos_text(SkCanvas *canvas, const char *text, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)