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/SkFont.h"
9 #include "include/core/SkFontStyle.h"
10 #include "include/core/SkFontTypes.h"
11 #include "include/core/SkImageInfo.h"
12 #include "include/core/SkPaint.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkSurface.h"
15 #include "include/core/SkTextBlob.h"
16 #include "include/core/SkTypeface.h"
17 #include "include/core/SkTypes.h"
18 #include "include/gpu/GpuTypes.h"
19 #include "include/gpu/ganesh/GrDirectContext.h"
20 #include "include/gpu/ganesh/SkSurfaceGanesh.h"
21 #include "include/private/base/SkTDArray.h"
22 #include "include/private/chromium/Slug.h"
23 #include "tests/CtsEnforcement.h"
24 #include "tests/Test.h"
25 #include "tools/ToolUtils.h"
26 #include "tools/fonts/FontToolUtils.h"
27
28 #include <cstdint>
29 #include <cstring>
30
31 struct GrContextOptions;
32
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(Slug_empty,reporter,ctxInfo,CtsEnforcement::kApiLevel_T)33 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(Slug_empty,
34 reporter,
35 ctxInfo,
36 CtsEnforcement::kApiLevel_T) {
37 auto dContext = ctxInfo.directContext();
38 SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256);
39 auto surface(SkSurfaces::RenderTarget(dContext, skgpu::Budgeted::kNo, info));
40 auto canvas = surface->getCanvas();
41
42 static const char* kText = " ";
43 auto typeface = ToolUtils::CreatePortableTypeface("serif", SkFontStyle());
44 SkFont font(typeface);
45 size_t txtLen = strlen(kText);
46 int glyphCount = font.countText(kText, txtLen, SkTextEncoding::kUTF8);
47
48 SkTDArray<uint16_t> glyphs;
49 glyphs.append(glyphCount);
50 font.textToGlyphs(kText, txtLen, SkTextEncoding::kUTF8, glyphs.begin(), glyphCount);
51
52 SkTextBlobBuilder builder;
53
54 font.setSubpixel(true);
55 font.setEdging(SkFont::Edging::kAntiAlias);
56 font.setTypeface(typeface);
57 font.setSize(16);
58
59 const SkTextBlobBuilder::RunBuffer& buf = builder.allocRun(font, glyphs.size(), 0, 0);
60 memcpy(buf.glyphs, glyphs.begin(), glyphs.size() * sizeof(uint16_t));
61 auto blob = builder.make();
62
63 SkPaint p;
64 p.setAntiAlias(true);
65 sk_sp<sktext::gpu::Slug> slug = sktext::gpu::Slug::ConvertBlob(canvas, *blob, {10, 10}, p);
66 REPORTER_ASSERT(reporter, slug == nullptr);
67 }
68