Flutter Engine
The Flutter Engine
FontTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 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
15#include "src/core/SkFontPriv.h"
19#include "tests/Test.h"
20#include "tools/ToolUtils.h"
22
23#include <cstddef>
24
26 sk_sp<SkRefCntSet> typefaces = sk_make_sp<SkRefCntSet>();
28 wb.setTypefaceRecorder(typefaces);
29
31 size_t size = wb.bytesWritten();
32 SkAutoMalloc storage(size);
33 wb.writeToMemory(storage.get());
34
35 int count = typefaces->count();
36 SkASSERT((!font.getTypeface() && count == 0) ||
37 ( font.getTypeface() && count == 1));
38 if (count) {
39 SkTypeface* typeface;
40 typefaces->copyToArray((SkRefCnt**)&typeface);
41 SkASSERT(typeface == font.getTypeface());
42 }
43
44 SkReadBuffer rb(storage.get(), size);
45 sk_sp<SkTypeface> cloneTypeface = font.refTypeface();
46 if (count) {
47 rb.setTypefaceArray(&cloneTypeface, 1);
48 }
49 SkFont clone;
51 return clone;
52}
53
54enum {
57 kSubpixel = 1 << 2,
59 kEmbolden = 1 << 4,
60 kBaselineSnap = 1 << 5,
61
62 kAllBits = 0x3F,
63};
64
65static void apply_flags(SkFont* font, unsigned flags) {
66 font->setForceAutoHinting(SkToBool(flags & kForceAutoHinting));
67 font->setEmbeddedBitmaps( SkToBool(flags & kEmbeddedBitmaps));
68 font->setSubpixel( SkToBool(flags & kSubpixel));
69 font->setLinearMetrics( SkToBool(flags & kLinearMetrics));
70 font->setEmbolden( SkToBool(flags & kEmbolden));
71 font->setBaselineSnap( SkToBool(flags & kBaselineSnap));
72}
73
74DEF_TEST(Font_flatten, reporter) {
75 const float sizes[] = {0, 0.001f, 1, 10, 10.001f, 100000.01f};
76 const float scales[] = {-5, 0, 1, 5};
77 const float skews[] = {-5, 0, 5};
78 const SkFont::Edging edges[] = {
80 };
81 const SkFontHinting hints[] = {
83 };
84 const unsigned int flags[] = {
87 };
88 const sk_sp<SkTypeface> typefaces[] = {
90 };
91
93 for (float size : sizes) {
94 font.setSize(size);
95 for (float scale : scales) {
96 font.setScaleX(scale);
97 for (float skew : skews) {
98 font.setSkewX(skew);
99 for (auto edge : edges) {
100 font.setEdging(edge);
101 for (auto hint : hints) {
102 font.setHinting(hint);
103 for (auto flag : flags) {
105 for (const sk_sp<SkTypeface>& typeface : typefaces) {
106 font.setTypeface(typeface);
108 REPORTER_ASSERT(reporter, font == clone);
109 }
110 }
111 }
112 }
113 }
114 }
115 }
116}
reporter
Definition: FontMgrTest.cpp:39
int count
Definition: FontMgrTest.cpp:50
DEF_TEST(Font_flatten, reporter)
Definition: FontTest.cpp:74
static SkFont serialize_deserialize(const SkFont &font, skiatest::Reporter *reporter)
Definition: FontTest.cpp:25
static void apply_flags(SkFont *font, unsigned flags)
Definition: FontTest.cpp:65
@ kForceAutoHinting
Definition: FontTest.cpp:55
@ kSubpixel
Definition: FontTest.cpp:57
@ kBaselineSnap
Definition: FontTest.cpp:60
@ kEmbeddedBitmaps
Definition: FontTest.cpp:56
@ kAllBits
Definition: FontTest.cpp:62
@ kLinearMetrics
Definition: FontTest.cpp:58
@ kEmbolden
Definition: FontTest.cpp:59
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkFontHinting
Definition: SkFontTypes.h:18
@ kNone
glyph outlines unchanged
@ kFull
modifies glyph outlines for maximum constrast
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
void * get()
Definition: SkAutoMalloc.h:64
void setTypefaceRecorder(sk_sp< SkRefCntSet >)
static void Flatten(const SkFont &, SkWriteBuffer &buffer)
static bool Unflatten(SkFont *, SkReadBuffer &buffer)
Definition: SkFont.h:35
Edging
Definition: SkFont.h:39
@ kAlias
no transparent pixels on glyph edges
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
int count() const
Definition: SkPtrRecorder.h:45
void setTypefaceArray(sk_sp< SkTypeface > array[], int count)
Definition: SkReadBuffer.h:167
void copyToArray(T *array) const
FlutterSemanticsFlag flag
FlutterSemanticsFlag flags
sk_sp< SkTypeface > SampleUserTypeface()
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
const Scalar scale