Flutter Engine
The Flutter Engine
Functions
Text.cpp File Reference
#include <unordered_map>
#include "include/core/SkFontMgr.h"
#include "include/core/SkFontStyle.h"
#include "include/core/SkStream.h"
#include "modules/skottie/include/Skottie.h"
#include "modules/skottie/include/SkottieProperty.h"
#include "modules/skshaper/include/SkShaper_factory.h"
#include "modules/skshaper/utils/FactoryHelpers.h"
#include "tests/Test.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Functions

 DEF_TEST (Skottie_Text_Style, r)
 
 DEF_TEST (Skottie_Text_LayoutError, r)
 
 DEF_TEST (Skottie_Text_FontFamily, r)
 

Function Documentation

◆ DEF_TEST() [1/3]

DEF_TEST ( Skottie_Text_FontFamily  ,
 
)

Definition at line 168 of file Text.cpp.

168 : [{
169 "fFamily": "Arial",
170 "fName": "Arial",
171 "fStyle": "Bold"
172 }]
173 },
174 "layers": [{
175 "ty": 5,
176 "t": {
177 "d": {
178 "k": [{
179 "t": 0,
180 "s": {
181 "f": "Arial",
182 "t": "Foo Bar Baz",
183 "s": 24,
184 "fc": [1,1,1,1],
185 "lh": 70,
186 "ps": [0, 0],
187 "sz": [100, 100],
188 "mf": 70,
189 "rs": 1
190 }
191 }]
192 }
193 }
194 }]
195 })";
196
197 class Logger final : public skottie::Logger {
198 public:
199 const std::vector<SkString>& errors() const { return fErrors; }
200
201 private:
202 void log(Level lvl, const char message[], const char* = nullptr) override {
203 if (lvl == Level::kError) {
204 fErrors.emplace_back(message);
205 }
206 }
207
208 std::vector<SkString> fErrors;
209 };

◆ DEF_TEST() [2/3]

DEF_TEST ( Skottie_Text_LayoutError  ,
 
)

Definition at line 123 of file Text.cpp.

123 {
130
137
141 };
142
143 for (const auto& exp : expected) {
144 const auto* style = fmgr->styleRequestedWhenMatchingFamily(exp.family);
145 REPORTER_ASSERT(r, style);
146 REPORTER_ASSERT(r, style->weight() == exp.weight);
147 REPORTER_ASSERT(r, style->slant () == exp.slant );
148 }
149}
150
151DEF_TEST(Skottie_Text_LayoutError, r) {
152 // Text node properties:
153 // - scale to fit
154 // - box width: 100
155 // - min font size: 70
156 // - string: Foo Bar Baz
157 //
158 // Layout should fail with these unsatisfiable constraints.
159 static constexpr char json[] =
160 R"({
161 "v": "5.2.1",
162 "w": 100,
163 "h": 100,
164 "fr": 10,
165 "ip": 0,
166 "op": 100,
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
@ kExtraBold_Weight
Definition: SkFontStyle.h:27
DEF_TEST(Skottie_Text_Style, r)
Definition: Text.cpp:77

◆ DEF_TEST() [3/3]

DEF_TEST ( Skottie_Text_Style  ,
 
)

Definition at line 77 of file Text.cpp.

77 {
78 static constexpr char json[] =
79 R"({
80 "v": "5.2.1",
81 "w": 100,
82 "h": 100,
83 "fr": 10,
84 "ip": 0,
85 "op": 100,
86 "fonts": {
87 "list": [
88 { "fName" : "f1", "fFamily": "f1", "fStyle" : "Regular" },
89 { "fName" : "f2", "fFamily": "f2", "fStyle" : "Medium" },
90 { "fName" : "f3", "fFamily": "f3", "fStyle" : "Bold" },
91 { "fName" : "f4", "fFamily": "f4", "fStyle" : "Light" },
92 { "fName" : "f5", "fFamily": "f5", "fStyle" : "Extra" },
93 { "fName" : "f6", "fFamily": "f6", "fStyle" : "ExtraBold" },
94
95 { "fName" : "f7" , "fFamily": "f7" , "fStyle" : "Regular Italic" },
96 { "fName" : "f8" , "fFamily": "f8" , "fStyle" : "Medium Italic" },
97 { "fName" : "f9" , "fFamily": "f9" , "fStyle" : "Bold Italic" },
98 { "fName" : "f10", "fFamily": "f10", "fStyle" : "Light Oblique" },
99 { "fName" : "f11", "fFamily": "f11", "fStyle" : "Extra Oblique" },
100 { "fName" : "f12", "fFamily": "f12", "fStyle" : "Extrabold Oblique" },
101
102 { "fName" : "f13", "fFamily": "f13", "fStyle" : "Italic" },
103 { "fName" : "f14", "fFamily": "f14", "fStyle" : "Oblique" },
104 { "fName" : "f15", "fFamily": "f15", "fStyle" : "" }
105 ]
106 }
107 })";
108
109 SkMemoryStream stream(json, strlen(json));
110 auto fmgr = sk_make_sp<RecordMatchFamilyStyleSkFontMgr>();
111
112 auto anim = Animation::Builder()
113 .setFontManager(fmgr)
114 .setTextShapingFactory(SkShapers::BestAvailable())
115 .make(&stream);
116
117 REPORTER_ASSERT(r, anim);
118
119 static constexpr struct {
120 const char* family;
121 SkFontStyle::Weight weight;
sk_sp< Factory > BestAvailable()
DlVertices::Builder Builder