MCPcopy Create free account
hub / github.com/Tencent/tgfx / TileModeCode

Function TileModeCode

src/pdf/PDFGradientShader.cpp:109–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109void TileModeCode(TileMode mode, const std::shared_ptr<MemoryWriteStream>& result) {
110 if (mode == TileMode::Repeat) {
111 result->writeText("dup truncate sub\n"); // Get the fractional part.
112 result->writeText("dup 0 le {1 add} if\n"); // Map (-1,0) => (0,1)
113 return;
114 }
115
116 if (mode == TileMode::Mirror) {
117 // In Preview 11.0 (1033.3) `a n mod r eq` (with a and n both integers, r integer or real)
118 // early aborts the function when false would be put on the stack.
119 // Work around this by re-writing `t 2 mod 1 eq` as `t 2 mod 0 gt`.
120
121 // Map t mod 2 into [0, 1, 1, 0].
122 // Code Stack t
123 result->writeText(
124 "abs " // +t
125 "dup " // +t.s +t.s
126 "truncate " // +t.s +t
127 "dup " // +t.s +t +t
128 "cvi " // +t.s +t +T
129 "2 mod " // +t.s +t (+T mod 2)
130 /*"1 eq "*/
131 "0 gt " // +t.s +t true|false
132 "3 1 roll " // true|false +t.s +t
133 "sub " // true|false 0.s
134 "exch " // 0.s true|false
135 "{1 exch sub} if\n"); // 1 - 0.s|0.s
136 }
137}
138
139/**
140 * Assumes t - startOffset is on the stack and does a linear interpolation on t between startOffset

Callers 3

LinearCodeFunction · 0.85
RadialCodeFunction · 0.85
TwoPointConicalCodeFunction · 0.85

Calls 1

writeTextMethod · 0.80

Tested by

no test coverage detected