26#if defined(SK_TYPEFACE_FACTORY_FONTATIONS)
31#include <initializer_list>
36const SkScalar kTextSizes[] = {12, 18, 30, 120};
37const char kTestFontName[] =
"fonts/test_glyphs-glyf_colr_1.ttf";
38const char kTestFontNameVariable[] =
"fonts/test_glyphs-glyf_colr_1_variable.ttf";
49 std::initializer_list<SkFontArguments::VariationPosition::Coordinate>
51 : fTestName(testName), fCodepoints(codepoints), fSkewX(skewX), fRotateDeg(rotateDeg) {
53 fCoordinates = std::make_unique<SkFontArguments::VariationPosition::Coordinate[]>(
54 specifiedVariations.size());
55 for (
size_t i = 0; i < specifiedVariations.size(); ++i) {
56 fCoordinates[i] = std::data(specifiedVariations)[i];
59 fVariationPosition.
coordinates = fCoordinates.get();
104 if (fTestName.
equals(
"sweep_varsweep")) {
117 static_cast<int>(coords.
size())};
130 *errorMsg =
"Did not recognize COLR v1 font format.";
134 canvas->
rotate(fRotateDeg);
135 canvas->
skew(fSkewX, 0);
141 std::vector<SkColor> paint_colors = {
143 auto paint_color_iterator = paint_colors.begin();
144 for (
SkScalar textSize : kTextSizes) {
145 font.setSize(textSize);
146 font.getMetrics(&metrics);
149 paint.setColor(*paint_color_iterator);
152 for (
size_t i = 0; i < fCodepoints.
size(); ++i) {
153 SkScalar glyphAdvance = font.measureText(
166 x += glyphAdvance + glyphAdvance * 0.05f;
168 paint_color_iterator++;
174 using INHERITED =
GM;
181 std::unique_ptr<SkFontArguments::VariationPosition::Coordinate[]> fCoordinates;
190namespace ColrV1TestDefinitions {
191const uint32_t gradient_stops_repeat[] = {0xf0100, 0xf0101, 0xf0102, 0xf0103};
192const uint32_t sweep_varsweep[] = {
193 0xf0200, 0xf0201, 0xf0202, 0xf0203, 0xf0204, 0xf0205, 0xf0206, 0xf0207, 0xf0208,
194 0xf0209, 0xf020a, 0xf020b, 0xf020c, 0xf020d, 0xf020e, 0xf020f, 0xf0210, 0xf0211,
195 0xf0212, 0xf0213, 0xf0214, 0xf0215, 0xf0216, 0xf0217, 0xf0218, 0xf0219, 0xf021a,
196 0xf021b, 0xf021c, 0xf021d, 0xf021e, 0xf021f, 0xf0220, 0xf0221, 0xf0222, 0xf0223,
197 0xf0224, 0xf0225, 0xf0226, 0xf0227, 0xf0228, 0xf0229, 0xf022a, 0xf022b, 0xf022c,
198 0xf022d, 0xf022e, 0xf022f, 0xf0230, 0xf0231, 0xf0232, 0xf0233, 0xf0234, 0xf0235,
199 0xf0236, 0xf0237, 0xf0238, 0xf0239, 0xf023a, 0xf023b, 0xf023c, 0xf023d, 0xf023e,
200 0xf023f, 0xf0240, 0xf0241, 0xf0242, 0xf0243, 0xf0244, 0xf0245, 0xf0246, 0xf0247};
201const uint32_t paint_scale[] = {0xf0300, 0xf0301, 0xf0302, 0xf0303, 0xf0304, 0xf0305};
202const uint32_t extend_mode[] = {
203 0xf0500, 0xf0501, 0xf0502, 0xf0503, 0xf0504, 0xf0505, 0xf0506, 0xf0507, 0xf0508};
204const uint32_t paint_rotate[] = {0xf0600, 0xf0601, 0xf0602, 0xf0603};
205const uint32_t paint_skew[] = {0xf0700, 0xf0701, 0xf0702, 0xf0703, 0xf0704, 0xf0705};
206const uint32_t paint_transform[] = {0xf0800, 0xf0801, 0xf0802, 0xf0803};
207const uint32_t paint_translate[] = {0xf0900, 0xf0901, 0xf0902, 0xf0903, 0xf0904, 0xf0905, 0xf0906};
208const uint32_t composite_mode[] = {0xf0a00, 0xf0a01, 0xf0a02, 0xf0a03, 0xf0a04, 0xf0a05, 0xf0a06,
209 0xf0a07, 0xf0a08, 0xf0a09, 0xf0a0a, 0xf0a0b, 0xf0a0c, 0xf0a0d,
210 0xf0a0e, 0xf0a0f, 0xf0a10, 0xf0a11, 0xf0a12, 0xf0a13, 0xf0a14,
211 0xf0a15, 0xf0a16, 0xf0a17, 0xf0a18, 0xf0a19, 0xf0a1a, 0xf0a1b};
212const uint32_t foreground_color[] = {
213 0xf0b00, 0xf0b01, 0xf0b02, 0xf0b03, 0xf0b04, 0xf0b05, 0xf0b06, 0xf0b07};
214const uint32_t clipbox[] = {0xf0c00, 0xf0c01, 0xf0c02, 0xf0c03, 0xf0c04};
215const uint32_t gradient_p2_skewed[] = {0xf0d00};
216const uint32_t variable_alpha[] = {0xf1000};
217const uint32_t paintcolrglyph_cycle[] = { 0xf1100, 0xf1101, 0xf1200 };
218const uint32_t sweep_coincident[] = { 0xf1300, 0xf1301, 0xf1302, 0xf1303, 0xf1304, 0xf1305,
219 0xf1306, 0xf1307, 0xf1308, 0xf1309, 0xf130a, 0xf130b,
220 0xf130c, 0xf130d, 0xf130e, 0xf130f, 0xf1310, 0xf1311,
221 0xf1312, 0xf1313, 0xf1314, 0xf1315, 0xf1316, 0xf1317};
222const uint32_t paint_glyph_nested[] = { 0xf1400, 0xf1401, 0xf1402, 0xf1403,
223 0xf1404, 0xf1405, 0xf1406, 0xf1407,
224 0xf1408, 0xf1409, 0xf140a, 0xf140b,
225 0xf140c, 0xf140d, 0xf140e, 0xf140f };
231std::unique_ptr<ColrV1GM>
F(
236 std::initializer_list<SkFontArguments::VariationPosition::Coordinate> variations) {
237 return std::make_unique<ColrV1GM>(
name, codepoints, skewX, rotateDeg, variations);
240SkFourByteTag constexpr operator"" _t(
const char* tagName,
size_t size) {
247#define C(TEST_CATEGORY) #TEST_CATEGORY, ColrV1TestDefinitions::TEST_CATEGORY
249DEF_GM(return
F(
C(clipbox), 0.0f, 0.0f, {{
"CLIO"_t, 200.f}}))
250DEF_GM(return
F(
C(composite_mode), 0.0f, 0.0f, {}))
251DEF_GM(return
F(
C(composite_mode), -0.5f, 0.0f, {}))
252DEF_GM(return
F(
C(composite_mode), -0.5f, 20.0f, {}))
253DEF_GM(return
F(
C(composite_mode), 0.0f, 20.0f, {}))
254DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {}))
255DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"COL1"_t, -0.25f}, {
"COL3"_t, 0.25f}}))
256DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"COL1"_t, 0.5f}, {
"COL3"_t, -0.5f}}))
257DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"COL3"_t, 0.5f}}))
258DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"COL3"_t, 1.f}}))
260DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"COL1"_t, -1.5f}}))
262DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"GRR0"_t, -200.f}, {
"GRR1"_t, -300.f}}))
264DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"GRX0"_t, -1000.f}, {
"GRX1"_t, -1000.f}, {
"GRR0"_t, -1000.f}, {
"GRR1"_t, -900.f}}))
266DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"GRX0"_t, 1000.f}, {
"GRX1"_t, -1000.f}, {
"GRR0"_t, -1000.f}, {
"GRR1"_t, 200.f}}))
268DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"GRR0"_t, -50.f}, {
"COL3"_t, -2.f}, {
"COL2"_t, -2.f}, {
"COL1"_t, -0.9f}}))
270DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"GRR0"_t, -50.f}, {
"COL3"_t, -2.f}, {
"COL2"_t, -2.f}, {
"COL1"_t, -1.1f}}))
272DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"COL3"_t, 1.f}, {
"COL2"_t, 1.5f}, {
"COL1"_t, 2.f}}))
274DEF_GM(return
F(
C(extend_mode), -0.5f, 0.0f, {}))
275DEF_GM(return
F(
C(extend_mode), -0.5f, 20.0f, {}))
276DEF_GM(return
F(
C(extend_mode), 0.0f, 20.0f, {}))
277DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"COL2"_t, -0.3f}}))
278DEF_GM(return
F(
C(extend_mode), 0.0f, 0.0f, {{
"GRR0"_t, 430.f}, {
"GRR1"_t, 40.f}}))
279DEF_GM(return
F(
C(foreground_color), 0.0f, 0.0f, {}))
280DEF_GM(return
F(
C(gradient_p2_skewed), 0.0f, 0.0f, {}))
281DEF_GM(return
F(
C(gradient_stops_repeat), 0.0f, 0.0f, {}))
282DEF_GM(return
F(
C(gradient_stops_repeat), -0.5f, 0.0f, {}))
283DEF_GM(return
F(
C(gradient_stops_repeat), -0.5f, 20.0f, {}))
284DEF_GM(return
F(
C(gradient_stops_repeat), 0.0f, 20.0f, {}))
285DEF_GM(return
F(
C(paint_rotate), 0.0f, 0.0f, {}))
286DEF_GM(return
F(
C(paint_rotate), 0.0f, 0.0f, {{
"ROTA"_t, 40.f}}))
287DEF_GM(return
F(
C(paint_rotate), 0.0f, 0.0f, {{
"ROTX"_t, -250.f}, {
"ROTY"_t, -250.f}}))
288DEF_GM(return
F(
C(paint_scale), 0.0f, 0.0f, {}))
289DEF_GM(return
F(
C(paint_scale), 0.0f, 0.0f, {{
"SCOX"_t, 200.f}, {
"SCOY"_t, 200.f}}))
290DEF_GM(return
F(
C(paint_scale), 0.0f, 0.0f, {{
"SCSX"_t, 0.25f}, {
"SCOY"_t, 0.25f}}))
291DEF_GM(return
F(
C(paint_scale), 0.0f, 0.0f, {{
"SCSX"_t, -1.f}, {
"SCOY"_t, -1.f}}))
292DEF_GM(return
F(
C(paint_skew), 0.0f, 0.0f, {}))
293DEF_GM(return
F(
C(paint_skew), 0.0f, 0.0f, {{
"SKXA"_t, 20.f}}))
294DEF_GM(return
F(
C(paint_skew), 0.0f, 0.0f, {{
"SKYA"_t, 20.f}}))
295DEF_GM(return
F(
C(paint_skew), 0.0f, 0.0f, {{
"SKCX"_t, 200.f},{
"SKCY"_t, 200.f}}))
296DEF_GM(return
F(
C(paint_transform), 0.0f, 0.0f, {}))
297DEF_GM(return
F(
C(paint_translate), 0.0f, 0.0f, {}))
298DEF_GM(return
F(
C(paint_translate), 0.0f, 0.0f, {{
"TLDX"_t, 100.f}, {
"TLDY"_t, 100.f}}))
299DEF_GM(return
F(
C(sweep_varsweep), 0.0f, 0.0f, {}))
300DEF_GM(return
F(
C(sweep_varsweep), -0.5f, 0.0f, {}))
301DEF_GM(return
F(
C(sweep_varsweep), -0.5f, 20.0f, {}))
302DEF_GM(return
F(
C(sweep_varsweep), 0.0f, 20.0f, {}))
303DEF_GM(return
F(
C(sweep_varsweep), 0.0f, 0.0f, {{
"SWPS"_t, 0.f}}))
304DEF_GM(return
F(
C(sweep_varsweep), 0.0f, 0.0f, {{
"SWPS"_t, 90.f}}))
305DEF_GM(return
F(
C(sweep_varsweep), 0.0f, 0.0f, {{
"SWPE"_t, -90.f}}))
306DEF_GM(return
F(
C(sweep_varsweep), 0.0f, 0.0f, {{
"SWPE"_t, -45.f}}))
307DEF_GM(return
F(
C(sweep_varsweep), 0.0f, 0.0f, {{
"SWPS"_t, -45.f},{
"SWPE"_t, 45.f}}))
312 {
"SWC2"_t, 0.083333333f},
313 {
"SWC3"_t, 0.083333333f},
314 {
"SWC4"_t, +0.25f}}))
315DEF_GM(return
F(
C(variable_alpha), 0.0f, 0.0f, {}))
316DEF_GM(return
F(
C(variable_alpha), 0.0f, 0.0f, {{
"APH1"_t, -0.7f}}))
317DEF_GM(return
F(
C(variable_alpha), 0.0f, 0.0f, {{
"APH2"_t, -0.7f}, {
"APH3"_t, -0.2f}}))
318DEF_GM(return
F(
C(paintcolrglyph_cycle), 0.0f, 0.0f, {}))
319DEF_GM(return
F(
C(sweep_coincident), 0.0f, 0.0f, {}))
320DEF_GM(return
F(
C(paint_glyph_nested), 0.0f, 0.0f, {}))
constexpr SkColor SK_ColorBLUE
constexpr SkColor SK_ColorRED
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorGREEN
constexpr SkColor SK_ColorWHITE
@ kUTF32
uses four byte words to represent all of Unicode
SK_API SkString static SkString SkStringPrintf()
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
void rotate(SkScalar degrees)
void skew(SkScalar sx, SkScalar sy)
constexpr T * data() const
constexpr size_t size() const
bool equals(const SkString &) const
void append(const char text[])
const char * c_str() const
sk_sp< SkTypeface > makeClone(const SkFontArguments &) const
void onSetControls(const SkMetaData &controls) override
bool onGetControls(SkMetaData *controls) override
ColrV1GM(const char *testName, SkSpan< const uint32_t > codepoints, SkScalar skewX, SkScalar rotateDeg, std::initializer_list< SkFontArguments::VariationPosition::Coordinate > specifiedVariations)
sk_sp< SkTypeface > makeVariedTypeface()
void onOnceBeforeDraw() override
DrawResult onDraw(SkCanvas *canvas, SkString *errorMsg) override
SkISize getISize() override
SkString getName() const override
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const Coordinate * coordinates
SkFontArguments & setVariationDesignPosition(VariationPosition position)
SkScalar fLeading
distance to add between lines, typically positive or zero
SkScalar fAscent
distance to reserve above baseline, typically negative
SkScalar fDescent
distance to reserve below baseline, typically positive
static constexpr SkISize Make(int32_t w, int32_t h)
constexpr int32_t width() const