1 /*
2 * Copyright 2021 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 "include/core/SkTextBlob.h"
9 #include "include/private/chromium/GrSlug.h"
10 #include "src/gpu/GrDirectContextPriv.h"
11 #include "tests/Test.h"
12 #include "tools/ToolUtils.h"
13
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrSlug_empty,reporter,ctxInfo)14 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrSlug_empty, reporter, ctxInfo) {
15 auto dContext = ctxInfo.directContext();
16 SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256);
17 auto surface(SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info));
18 auto canvas = surface->getCanvas();
19
20 static const char* kText = " ";
21 auto typeface = ToolUtils::create_portable_typeface("serif", SkFontStyle());
22 SkFont font(typeface);
23 size_t txtLen = strlen(kText);
24 int glyphCount = font.countText(kText, txtLen, SkTextEncoding::kUTF8);
25
26 SkTDArray<uint16_t> glyphs;
27 glyphs.append(glyphCount);
28 font.textToGlyphs(kText, txtLen, SkTextEncoding::kUTF8, glyphs.begin(), glyphCount);
29
30 SkTextBlobBuilder builder;
31
32 font.setSubpixel(true);
33 font.setEdging(SkFont::Edging::kAntiAlias);
34 font.setTypeface(typeface);
35 font.setSize(16);
36
37 const SkTextBlobBuilder::RunBuffer& buf = builder.allocRun(font, glyphs.count(), 0, 0);
38 memcpy(buf.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t));
39 auto blob = builder.make();
40
41 SkPaint p;
42 p.setAntiAlias(true);
43 sk_sp<GrSlug> slug = GrSlug::ConvertBlob(canvas, *blob, {10, 10}, p);
44 REPORTER_ASSERT(reporter, slug == nullptr);
45 }
46
47