huangcm
2024-12-18 9d29be7f7249789d6ffd0440067187a9f040c2cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
 
#include "Resources.h"
#include "SkTextBlob.h"
#include "SkTo.h"
#include "SkTypeface.h"
#include "gm.h"
 
static void excercise_draw_pos_text(SkCanvas* canvas,
                                    const char* text,
                                    SkScalar x, SkScalar y,
                                    const SkFont& font,
                                    const SkPaint& paint) {
    const int count = font.countText(text, strlen(text), kUTF8_SkTextEncoding);
    SkTextBlobBuilder builder;
    auto rec = builder.allocRunPos(font, count);
    font.textToGlyphs(text, strlen(text), kUTF8_SkTextEncoding, rec.glyphs, count);
    font.getPos(rec.glyphs, count, rec.points());
    canvas->drawTextBlob(builder.make(), x, y, paint);
}
 
DEF_SIMPLE_GM(pdf_never_embed, canvas, 512, 512) {
    SkPaint p;
 
    SkFont font(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"), 60);
    if (!font.getTypefaceOrDefault()) {
        return;
    }
 
    const char text[] = "HELLO, WORLD!";
 
    canvas->drawColor(SK_ColorWHITE);
    excercise_draw_pos_text(canvas, text, 30, 90, font, p);
 
    canvas->save();
    canvas->rotate(45.0f);
    p.setColor(0xF0800000);
    excercise_draw_pos_text(canvas, text, 30, 45, font, p);
    canvas->restore();
 
    canvas->save();
    canvas->scale(1, 4.0);
    p.setColor(0xF0008000);
    excercise_draw_pos_text(canvas, text, 15, 70, font, p);
    canvas->restore();
 
    canvas->scale(1.0, 0.5);
    p.setColor(0xF0000080);
    canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 30, 700, font, p);
}
 
 
// should draw completely white.
DEF_SIMPLE_GM(pdf_crbug_772685, canvas, 612, 792) {
    canvas->clipRect({-1, -1, 613, 793}, false);
    canvas->translate(-571, 0);
    canvas->scale(0.75, 0.75);
    canvas->clipRect({-1, -1, 613, 793}, false);
    canvas->translate(0, -816);
    canvas->drawRect({0, 0, 1224, 1500}, SkPaint());
}