Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
Text.cpp File Reference
#include <vector>
#include "include/utils/SkNoDrawCanvas.h"
#include "modules/skshaper/utils/FactoryHelpers.h"
#include "modules/svg/src/SkSVGTextPriv.h"
#include "tests/Test.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Functions

 DEF_TEST (Svg_Text_PosProvider, r)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( Svg_Text_PosProvider  ,
 
)

Definition at line 16 of file Text.cpp.

16 {
17 const auto L = [](float x) { return SkSVGLength(x); };
19
20 static const struct PosTestDesc {
21 size_t offseta;
22 std::vector<SkSVGLength> xa, ya;
23
24 size_t offsetb;
25 std::vector<SkSVGLength> xb, yb;
26
27 std::vector<SkPoint> expected;
28 } gTests[] = {
29 {
30 0, {}, {},
31 0, {}, {},
32
33 { {N,N} }
34 },
35
36 {
37 0, { L(1) }, {},
38 0, { }, {},
39
40 { {1,N}, {N,N} }
41 },
42 {
43 0, { }, {},
44 0, { L(10) }, {},
45
46 { {10,N}, {N,N} }
47 },
48 {
49 0, { L( 1) }, {},
50 0, { L(10) }, {},
51
52 { {10,N}, {N,N} }
53 },
54 {
55 0, { L( 1), L(2) }, {},
56 0, { L(10) }, {},
57
58 { {10,N}, {2,N}, {N,N} }
59 },
60 {
61 0, { L(1), L( 2) }, {},
62 1, { L(20) }, {},
63
64 { {1,N}, {20,N}, {N,N} }
65 },
66 {
67 0, { L(1), L( 2), L(3) }, {},
68 1, { L(20) }, {},
69
70 { {1,N}, {20,N}, {3,N}, {N,N} }
71 },
72 {
73 0, { L(1), L(2), L( 3) }, {},
74 2, { L(30) }, {},
75
76 { {1,N}, {2,N}, {30,N}, {N,N} }
77 },
78 {
79 0, { L(1) }, {},
80 2, { L(30) }, {},
81
82 { {1,N}, {N,N}, {30,N}, {N,N} }
83 },
84
85
86 {
87 0, {}, { L(4) },
88 0, {}, { },
89
90 { {N,4}, {N,N} }
91 },
92 {
93 0, {}, { },
94 0, {}, { L(40) },
95
96 { {N,40}, {N,N} }
97 },
98 {
99 0, {}, { L( 4) },
100 0, {}, { L(40) },
101
102 { {N,40}, {N,N} }
103 },
104 {
105 0, {}, { L( 4), L(5) },
106 0, {}, { L(40) },
107
108 { {N,40}, {N,5}, {N,N} }
109 },
110 {
111 0, {}, { L(4), L( 5) },
112 1, {}, { L(50) },
113
114 { {N,4}, {N,50}, {N,N} }
115 },
116 {
117 0, {}, { L(4), L( 5), L(6) },
118 1, {}, { L(50) },
119
120 { {N,4}, {N,50}, {N,6}, {N,N} }
121 },
122 {
123 0, {}, { L(4), L(5), L( 6) },
124 2, {}, { L(60) },
125
126 { {N,4}, {N,5}, {N,60}, {N,N} }
127 },
128 {
129 0, {}, { L(4) },
130 2, {}, { L(60) },
131
132 { {N,4}, {N,N}, {N,60}, {N,N} }
133 },
134
135 {
136 0, { L( 1), L(2)}, { L( 4) },
137 0, { L(10) }, { L(40), L(50) },
138
139 { {10,40}, {2,50}, {N,N} }
140 },
141 {
142 0, { L(1), L( 2), L(3) }, { L(4), L( 5) },
143 1, { L(20) }, { L(50), L(60) },
144
145 { {1,4}, {20,50}, {3,60}, {N,N} }
146 },
147 };
148
150 [](const SkSVGRenderContext&, const sk_sp<SkTextBlob>&, const SkPaint*, const SkPaint*) {};
151
152 auto test = [&](const PosTestDesc& tst) {
153 auto a = SkSVGText::Make();
154 auto b = SkSVGTSpan::Make();
155 a->appendChild(b);
156
157 a->setX(tst.xa);
158 a->setY(tst.ya);
159 b->setX(tst.xb);
160 b->setY(tst.yb);
161
162 const SkSVGIDMapper mapper;
163 const SkSVGLengthContext lctx({0,0});
164 const SkSVGPresentationContext pctx;
165 SkNoDrawCanvas canvas(0, 0);
169 const SkSVGRenderContext ctx(&canvas,
170 fmgr,
171 rp,
172 mapper,
173 lctx,
174 pctx,
175 {nullptr, nullptr},
176 shaping);
177
178 SkSVGTextContext tctx(ctx, mock_cb);
179 SkSVGTextContext::ScopedPosResolver pa(*a, lctx, &tctx, tst.offseta);
180 SkSVGTextContext::ScopedPosResolver pb(*b, lctx, &tctx, tst.offsetb);
181
182 for (size_t i = 0; i < tst.expected.size(); ++i) {
183 const auto& exp = tst.expected[i];
184 auto pos = i >= tst.offsetb ? pb.resolve(i) : pa.resolve(i);
185
188 }
189 };
190
191 for (const auto& tst : gTests) {
192 test(tst);
193 }
194}
static const TestCase gTests[]
#define test(name)
SkPoint pos
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define N
Definition beziers.cpp:19
static sk_sp< SkSVGTSpan > Make()
Definition SkSVGText.h:80
std::function< void(const SkSVGRenderContext &, const sk_sp< SkTextBlob > &, const SkPaint *, const SkPaint *)> ShapedTextCallback
static sk_sp< SkSVGText > Make()
Definition SkSVGText.h:65
static bool b
struct MyStruct a[10]
double x
sk_sp< Factory > BestAvailable()
sk_sp< SkFontMgr > TestFontMgr()
float fX
x-axis value
float fY
y-axis value