Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SlugTest.cpp
Go to the documentation of this file.
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
24#include "tests/Test.h"
25#include "tools/ToolUtils.h"
27
28#include <cstdint>
29#include <cstring>
30
31struct GrContextOptions;
32
35 ctxInfo,
37 auto dContext = ctxInfo.directContext();
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
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}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
reporter
uint16_t glyphs[5]
@ kUTF8
uses bytes to represent UTF-8 or ASCII
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
Definition Test.h:434
@ kAntiAlias
may have transparent pixels on glyph edges
T * append()
Definition SkTDArray.h:191
static sk_sp< Slug > ConvertBlob(SkCanvas *canvas, const SkTextBlob &blob, SkPoint origin, const SkPaint &paint)
Definition Slug.cpp:20
VkSurfaceKHR surface
Definition main.cc:49
constexpr char kText[]
Definition glyph_pos.cpp:28
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
sk_sp< SkTypeface > CreatePortableTypeface(const char *name, SkFontStyle style)
static SkImageInfo MakeN32Premul(int width, int height)
SkGlyphID * glyphs
storage for glyph indexes in run
Definition SkTextBlob.h:329