Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
30 SkFontPriv::Flatten(font, wb);
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
92 SkFont font;
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) {
104 apply_flags(&font, flag);
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
int count
@ 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
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
#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 DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
void * get()
void setTypefaceRecorder(sk_sp< SkRefCntSet >)
static void Flatten(const SkFont &, SkWriteBuffer &buffer)
static bool Unflatten(SkFont *, SkReadBuffer &buffer)
Edging
Definition SkFont.h:39
@ kAlias
no transparent pixels on glyph edges
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
void setTypefaceArray(sk_sp< SkTypeface > array[], int count)
FlutterSemanticsFlag flag
FlutterSemanticsFlag flags
sk_sp< SkTypeface > SampleUserTypeface()
const Scalar scale