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