Flutter Engine
The Flutter Engine
Functions
FontationsTest.cpp File Reference
#include "include/core/SkStream.h"
#include "include/core/SkTypeface.h"
#include "include/ports/SkTypeface_fontations.h"
#include "tests/Test.h"
#include "tools/Resources.h"
#include <memory>

Go to the source code of this file.

Functions

 DEF_TEST (Fontations_DoNotMakeFromNull, reporter)
 
 DEF_TEST (Fontations_DoNotMakeFromNonSfnt, reporter)
 
 DEF_TEST (Fontations_MakeFromFont, reporter)
 
 DEF_TEST (Fontations_MakeFromCollection, reporter)
 
 DEF_TEST (Fontations_MakeFromCollectionNonNullIndex, reporter)
 
 DEF_TEST (Fontations_DoNotMakeFromCollection_Invalid_Index, reporter)
 
 DEF_TEST (Fontations_TableData, reporter)
 
 DEF_TEST (Fontations_TableTags, reporter)
 
 DEF_TEST (Fontations_VariationPosition, reporter)
 
 DEF_TEST (Fontations_VariationParameters, reporter)
 
 DEF_TEST (Fontations_VariationParameters_BufferTooSmall, reporter)
 

Function Documentation

◆ DEF_TEST() [1/11]

DEF_TEST ( Fontations_DoNotMakeFromCollection_Invalid_Index  ,
reporter   
)

Definition at line 111 of file FontationsTest.cpp.

111 {
113 args.setCollectionIndex(1000);
114 sk_sp<SkTypeface> probeTypeface(
116 REPORTER_ASSERT(reporter, !probeTypeface);
117}
reporter
Definition: FontMgrTest.cpp:39
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
Definition: Resources.cpp:31
SK_API sk_sp< SkTypeface > SkTypeface_Make_Fontations(std::unique_ptr< SkStreamAsset > fontData, const SkFontArguments &args)
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

◆ DEF_TEST() [2/11]

DEF_TEST ( Fontations_DoNotMakeFromNonSfnt  ,
reporter   
)

Definition at line 82 of file FontationsTest.cpp.

82 {
83 char notAnSfnt[] = "I_AM_NOT_AN_SFNT";
84 std::unique_ptr<SkStreamAsset> notSfntStream =
85 SkMemoryStream::MakeDirect(notAnSfnt, std::size(notAnSfnt));
86 sk_sp<SkTypeface> probeTypeface(
87 SkTypeface_Make_Fontations(std::move(notSfntStream), SkFontArguments()));
88 REPORTER_ASSERT(reporter, !probeTypeface);
89}
static std::unique_ptr< SkMemoryStream > MakeDirect(const void *data, size_t length)
Definition: SkStream.cpp:310
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

◆ DEF_TEST() [3/11]

DEF_TEST ( Fontations_DoNotMakeFromNull  ,
reporter   
)

Definition at line 75 of file FontationsTest.cpp.

75 {
76 std::unique_ptr<SkStreamAsset> nullStream = SkMemoryStream::MakeDirect(nullptr, 0);
77 sk_sp<SkTypeface> probeTypeface(
78 SkTypeface_Make_Fontations(std::move(nullStream), SkFontArguments()));
79 REPORTER_ASSERT(reporter, !probeTypeface);
80}

◆ DEF_TEST() [4/11]

DEF_TEST ( Fontations_MakeFromCollection  ,
reporter   
)

Definition at line 97 of file FontationsTest.cpp.

97 {
98 sk_sp<SkTypeface> probeTypeface(
100 REPORTER_ASSERT(reporter, probeTypeface);
101}

◆ DEF_TEST() [5/11]

DEF_TEST ( Fontations_MakeFromCollectionNonNullIndex  ,
reporter   
)

Definition at line 103 of file FontationsTest.cpp.

103 {
105 args.setCollectionIndex(1);
106 sk_sp<SkTypeface> probeTypeface(
108 REPORTER_ASSERT(reporter, probeTypeface);
109}

◆ DEF_TEST() [6/11]

DEF_TEST ( Fontations_MakeFromFont  ,
reporter   
)

Definition at line 91 of file FontationsTest.cpp.

91 {
92 sk_sp<SkTypeface> probeTypeface(
94 REPORTER_ASSERT(reporter, probeTypeface);
95}

◆ DEF_TEST() [7/11]

DEF_TEST ( Fontations_TableData  ,
reporter   
)

Definition at line 119 of file FontationsTest.cpp.

119 {
120 constexpr size_t kNameTableSize = 11310;
121 constexpr size_t kTestOffset = 1310;
122 constexpr size_t kTestLength = 500;
123 char destBuffer[kNameTableSize] = {0};
124 sk_sp<SkTypeface> testTypeface(
126 SkFourByteTag nameTableTag = SkSetFourByteTag('n', 'a', 'm', 'e');
127 SkFourByteTag nonExistantTag = SkSetFourByteTag('0', 'X', '0', 'X');
128
129 // Getting size without buffer.
131 testTypeface->getTableData(nameTableTag, 0, kNameTableSize, nullptr) ==
132 kNameTableSize);
133 // Reading full table.
135 testTypeface->getTableData(nameTableTag, 0, kNameTableSize, destBuffer) ==
136 kNameTableSize);
137 // Reading restricted length.
139 reporter,
140 testTypeface->getTableData(nameTableTag, 0, kTestLength, destBuffer) == kTestLength);
142 testTypeface->getTableData(
143 nameTableTag, kTestOffset, kTestLength, destBuffer) == kTestLength);
144 // Reading at an offset.
146 reporter,
147 testTypeface->getTableData(nameTableTag, kTestOffset, kNameTableSize, destBuffer) ==
148 kNameTableSize - kTestOffset);
149
150 // Reading from offset past table.
152 testTypeface->getTableData(
153 nameTableTag, kNameTableSize, kNameTableSize, destBuffer) == 0);
155 testTypeface->getTableData(nameTableTag, kNameTableSize, 0, nullptr) == 0);
156 // Reading one byte before end of table.
158 testTypeface->getTableData(
159 nameTableTag, kNameTableSize - 1, kNameTableSize, destBuffer) == 1);
160 // Trying to start reading at an offset past table start.
162 testTypeface->getTableData(nameTableTag, 0, kNameTableSize + 10, destBuffer) ==
163 kNameTableSize);
164 // Restricting length without target buffer.
166 testTypeface->getTableData(nameTableTag, 0, kTestLength, nullptr) ==
167 kTestLength);
168
169 // Trying to access non-existant table.
171 testTypeface->getTableData(nonExistantTag, 0, kNameTableSize, destBuffer) ==
172 0);
174 testTypeface->getTableData(nonExistantTag, 0, 0, nullptr) ==
175 0);
177 testTypeface->getTableData(nonExistantTag, kTestOffset, 0, nullptr) == 0);
178}
uint32_t SkFourByteTag
Definition: SkTypes.h:166
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167

◆ DEF_TEST() [8/11]

DEF_TEST ( Fontations_TableTags  ,
reporter   
)

Definition at line 180 of file FontationsTest.cpp.

180 {
181 constexpr size_t kNumTags = 11;
182 SkFourByteTag tagsBuffer[kNumTags] = {0};
183 sk_sp<SkTypeface> testTypeface(
185 SkFourByteTag firstTag = SkSetFourByteTag('O', 'S', '/', '2');
186 SkFourByteTag lastTag = SkSetFourByteTag('p', 'o', 's', 't');
187
188 REPORTER_ASSERT(reporter, testTypeface->getTableTags(nullptr) == kNumTags);
189
190 REPORTER_ASSERT(reporter, testTypeface->getTableTags(tagsBuffer) == kNumTags);
191 REPORTER_ASSERT(reporter, tagsBuffer[0] == firstTag);
192 REPORTER_ASSERT(reporter, tagsBuffer[kNumTags - 1] == lastTag);
193}

◆ DEF_TEST() [9/11]

DEF_TEST ( Fontations_VariationParameters  ,
reporter   
)

Definition at line 238 of file FontationsTest.cpp.

238 {
239 sk_sp<SkTypeface> variableTypeface(
242 variableTypeface->getVariationDesignParameters(nullptr, 0) == kNumVariableAxes);
243
244 SkFontParameters::Variation::Axis axes[kNumVariableAxes] = {};
246 variableTypeface->getVariationDesignParameters(axes, kNumVariableAxes) ==
247 kNumVariableAxes);
248
249 for (size_t i = 0; i < kNumVariableAxes; ++i) {
250 REPORTER_ASSERT(reporter, axes[i].tag == axisExpectations[i].tag);
251 REPORTER_ASSERT(reporter, axes[i].min == axisExpectations[i].minValue);
252 REPORTER_ASSERT(reporter, axes[i].def == axisExpectations[i].defValue);
253 REPORTER_ASSERT(reporter, axes[i].max == axisExpectations[i].maxValue);
254 }
255}
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

◆ DEF_TEST() [10/11]

DEF_TEST ( Fontations_VariationParameters_BufferTooSmall  ,
reporter   
)

Definition at line 257 of file FontationsTest.cpp.

257 {
258 sk_sp<SkTypeface> variableTypeface(
261 variableTypeface->getVariationDesignParameters(nullptr, 0) == kNumVariableAxes);
262
263 constexpr size_t kArrayTooSmall = 3;
264 SkFontParameters::Variation::Axis axes[kArrayTooSmall] = {};
266 variableTypeface->getVariationDesignParameters(axes, kArrayTooSmall) == -1);
267}

◆ DEF_TEST() [11/11]

DEF_TEST ( Fontations_VariationPosition  ,
reporter   
)

Definition at line 195 of file FontationsTest.cpp.

195 {
196 sk_sp<SkTypeface> variableTypeface(
198 // Everything at default.
199 const int numAxes = variableTypeface->getVariationDesignPosition(nullptr, 0);
200 REPORTER_ASSERT(reporter, numAxes == kNumVariableAxes, "numAxes: %d", numAxes);
201
202 SkFontArguments::VariationPosition::Coordinate kSwpsCoordinateFirst = {SkSetFourByteTag('S', 'W', 'P', 'S'), 25};
203 SkFontArguments::VariationPosition::Coordinate kSwpsCoordinateSecond = {SkSetFourByteTag('S', 'W', 'P', 'S'), 55};
204 SkFontArguments::VariationPosition::Coordinate kSwpeCoordinate = {SkSetFourByteTag('S', 'W', 'P', 'E'), 45};
205 SkFontArguments::VariationPosition::Coordinate kInvalidCoordinate = {SkSetFourByteTag('_', '_', '_', '_'), 0};
206
207 // 'SWPS' and 'SWPE' exist. Second 'SWPS' should override first, invalid tag should be stripped.
209 kSwpsCoordinateFirst, kSwpsCoordinateSecond, kSwpeCoordinate, kInvalidCoordinate};
210
212 clonePosition.coordinates = cloneCoordinates;
213 clonePosition.coordinateCount = 4;
214
215 sk_sp<SkTypeface> cloneTypeface = variableTypeface->makeClone(
216 SkFontArguments().setVariationDesignPosition(clonePosition));
217 const int cloneNumAxes = cloneTypeface->getVariationDesignPosition(nullptr, 0);
218 REPORTER_ASSERT(reporter, cloneNumAxes == kNumVariableAxes, "clonedNumAxes: %d", cloneNumAxes);
219
220 SkFontArguments::VariationPosition::Coordinate retrieveCoordinates[kNumVariableAxes] = {};
221
222 // Error when providing too little space.
223 const int badClonedNumAxes = cloneTypeface->getVariationDesignPosition(retrieveCoordinates, 1);
224 REPORTER_ASSERT(reporter, badClonedNumAxes == -1, "badClonedNumAxes: %d", badClonedNumAxes);
225
226 const int retrievedClonedNumAxes =
227 cloneTypeface->getVariationDesignPosition(retrieveCoordinates, kNumVariableAxes);
228 REPORTER_ASSERT(reporter, retrievedClonedNumAxes == kNumVariableAxes,
229 "retrievedClonedNumAxes: %d", retrievedClonedNumAxes);
231 retrieveCoordinates[0].axis == kSwpsCoordinateSecond.axis &&
232 retrieveCoordinates[0].value == kSwpsCoordinateSecond.value);
234 retrieveCoordinates[1].axis == kSwpeCoordinate.axis &&
235 retrieveCoordinates[1].value == kSwpeCoordinate.value);
236}
int getVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const
Definition: SkTypeface.cpp:289
sk_sp< SkTypeface > makeClone(const SkFontArguments &) const
Definition: SkTypeface.cpp:190