33 |
33 |
34 TransformingPathConsumer2D() { |
34 TransformingPathConsumer2D() { |
35 // used by RendererContext |
35 // used by RendererContext |
36 } |
36 } |
37 |
37 |
38 // recycled PathConsumer2D instance from transformConsumer() |
38 // recycled PathConsumer2D instance from wrapPath2d() |
39 private final Path2DWrapper wp_Path2DWrapper = new Path2DWrapper(); |
39 private final Path2DWrapper wp_Path2DWrapper = new Path2DWrapper(); |
40 |
40 |
41 PathConsumer2D wrapPath2d(Path2D.Float p2d) |
41 PathConsumer2D wrapPath2d(Path2D.Float p2d) |
42 { |
42 { |
43 return wp_Path2DWrapper.init(p2d); |
43 return wp_Path2DWrapper.init(p2d); |
44 } |
|
45 |
|
46 // recycled PathConsumer2D instances from transformConsumer() |
|
47 private final TranslateFilter tx_TranslateFilter = new TranslateFilter(); |
|
48 private final DeltaScaleFilter tx_DeltaScaleFilter = new DeltaScaleFilter(); |
|
49 private final ScaleFilter tx_ScaleFilter = new ScaleFilter(); |
|
50 private final DeltaTransformFilter tx_DeltaTransformFilter = new DeltaTransformFilter(); |
|
51 private final TransformFilter tx_TransformFilter = new TransformFilter(); |
|
52 |
|
53 PathConsumer2D transformConsumer(PathConsumer2D out, |
|
54 AffineTransform at) |
|
55 { |
|
56 if (at == null) { |
|
57 return out; |
|
58 } |
|
59 float mxx = (float) at.getScaleX(); |
|
60 float mxy = (float) at.getShearX(); |
|
61 float mxt = (float) at.getTranslateX(); |
|
62 float myx = (float) at.getShearY(); |
|
63 float myy = (float) at.getScaleY(); |
|
64 float myt = (float) at.getTranslateY(); |
|
65 if (mxy == 0f && myx == 0f) { |
|
66 if (mxx == 1f && myy == 1f) { |
|
67 if (mxt == 0f && myt == 0f) { |
|
68 return out; |
|
69 } else { |
|
70 return tx_TranslateFilter.init(out, mxt, myt); |
|
71 } |
|
72 } else { |
|
73 if (mxt == 0f && myt == 0f) { |
|
74 return tx_DeltaScaleFilter.init(out, mxx, myy); |
|
75 } else { |
|
76 return tx_ScaleFilter.init(out, mxx, myy, mxt, myt); |
|
77 } |
|
78 } |
|
79 } else if (mxt == 0f && myt == 0f) { |
|
80 return tx_DeltaTransformFilter.init(out, mxx, mxy, myx, myy); |
|
81 } else { |
|
82 return tx_TransformFilter.init(out, mxx, mxy, mxt, myx, myy, myt); |
|
83 } |
|
84 } |
44 } |
85 |
45 |
86 // recycled PathConsumer2D instances from deltaTransformConsumer() |
46 // recycled PathConsumer2D instances from deltaTransformConsumer() |
87 private final DeltaScaleFilter dt_DeltaScaleFilter = new DeltaScaleFilter(); |
47 private final DeltaScaleFilter dt_DeltaScaleFilter = new DeltaScaleFilter(); |
88 private final DeltaTransformFilter dt_DeltaTransformFilter = new DeltaTransformFilter(); |
48 private final DeltaTransformFilter dt_DeltaTransformFilter = new DeltaTransformFilter(); |
136 -myx / det, |
98 -myx / det, |
137 mxx / det); |
99 mxx / det); |
138 } |
100 } |
139 } |
101 } |
140 |
102 |
141 static final class TranslateFilter implements PathConsumer2D { |
|
142 private PathConsumer2D out; |
|
143 private float tx, ty; |
|
144 |
|
145 TranslateFilter() {} |
|
146 |
|
147 TranslateFilter init(PathConsumer2D out, |
|
148 float tx, float ty) |
|
149 { |
|
150 this.out = out; |
|
151 this.tx = tx; |
|
152 this.ty = ty; |
|
153 return this; // fluent API |
|
154 } |
|
155 |
|
156 @Override |
|
157 public void moveTo(float x0, float y0) { |
|
158 out.moveTo(x0 + tx, y0 + ty); |
|
159 } |
|
160 |
|
161 @Override |
|
162 public void lineTo(float x1, float y1) { |
|
163 out.lineTo(x1 + tx, y1 + ty); |
|
164 } |
|
165 |
|
166 @Override |
|
167 public void quadTo(float x1, float y1, |
|
168 float x2, float y2) |
|
169 { |
|
170 out.quadTo(x1 + tx, y1 + ty, |
|
171 x2 + tx, y2 + ty); |
|
172 } |
|
173 |
|
174 @Override |
|
175 public void curveTo(float x1, float y1, |
|
176 float x2, float y2, |
|
177 float x3, float y3) |
|
178 { |
|
179 out.curveTo(x1 + tx, y1 + ty, |
|
180 x2 + tx, y2 + ty, |
|
181 x3 + tx, y3 + ty); |
|
182 } |
|
183 |
|
184 @Override |
|
185 public void closePath() { |
|
186 out.closePath(); |
|
187 } |
|
188 |
|
189 @Override |
|
190 public void pathDone() { |
|
191 out.pathDone(); |
|
192 } |
|
193 |
|
194 @Override |
|
195 public long getNativeConsumer() { |
|
196 return 0; |
|
197 } |
|
198 } |
|
199 |
|
200 static final class ScaleFilter implements PathConsumer2D { |
|
201 private PathConsumer2D out; |
|
202 private float sx, sy, tx, ty; |
|
203 |
|
204 ScaleFilter() {} |
|
205 |
|
206 ScaleFilter init(PathConsumer2D out, |
|
207 float sx, float sy, |
|
208 float tx, float ty) |
|
209 { |
|
210 this.out = out; |
|
211 this.sx = sx; |
|
212 this.sy = sy; |
|
213 this.tx = tx; |
|
214 this.ty = ty; |
|
215 return this; // fluent API |
|
216 } |
|
217 |
|
218 @Override |
|
219 public void moveTo(float x0, float y0) { |
|
220 out.moveTo(x0 * sx + tx, y0 * sy + ty); |
|
221 } |
|
222 |
|
223 @Override |
|
224 public void lineTo(float x1, float y1) { |
|
225 out.lineTo(x1 * sx + tx, y1 * sy + ty); |
|
226 } |
|
227 |
|
228 @Override |
|
229 public void quadTo(float x1, float y1, |
|
230 float x2, float y2) |
|
231 { |
|
232 out.quadTo(x1 * sx + tx, y1 * sy + ty, |
|
233 x2 * sx + tx, y2 * sy + ty); |
|
234 } |
|
235 |
|
236 @Override |
|
237 public void curveTo(float x1, float y1, |
|
238 float x2, float y2, |
|
239 float x3, float y3) |
|
240 { |
|
241 out.curveTo(x1 * sx + tx, y1 * sy + ty, |
|
242 x2 * sx + tx, y2 * sy + ty, |
|
243 x3 * sx + tx, y3 * sy + ty); |
|
244 } |
|
245 |
|
246 @Override |
|
247 public void closePath() { |
|
248 out.closePath(); |
|
249 } |
|
250 |
|
251 @Override |
|
252 public void pathDone() { |
|
253 out.pathDone(); |
|
254 } |
|
255 |
|
256 @Override |
|
257 public long getNativeConsumer() { |
|
258 return 0; |
|
259 } |
|
260 } |
|
261 |
|
262 static final class TransformFilter implements PathConsumer2D { |
|
263 private PathConsumer2D out; |
|
264 private float mxx, mxy, mxt, myx, myy, myt; |
|
265 |
|
266 TransformFilter() {} |
|
267 |
|
268 TransformFilter init(PathConsumer2D out, |
|
269 float mxx, float mxy, float mxt, |
|
270 float myx, float myy, float myt) |
|
271 { |
|
272 this.out = out; |
|
273 this.mxx = mxx; |
|
274 this.mxy = mxy; |
|
275 this.mxt = mxt; |
|
276 this.myx = myx; |
|
277 this.myy = myy; |
|
278 this.myt = myt; |
|
279 return this; // fluent API |
|
280 } |
|
281 |
|
282 @Override |
|
283 public void moveTo(float x0, float y0) { |
|
284 out.moveTo(x0 * mxx + y0 * mxy + mxt, |
|
285 x0 * myx + y0 * myy + myt); |
|
286 } |
|
287 |
|
288 @Override |
|
289 public void lineTo(float x1, float y1) { |
|
290 out.lineTo(x1 * mxx + y1 * mxy + mxt, |
|
291 x1 * myx + y1 * myy + myt); |
|
292 } |
|
293 |
|
294 @Override |
|
295 public void quadTo(float x1, float y1, |
|
296 float x2, float y2) |
|
297 { |
|
298 out.quadTo(x1 * mxx + y1 * mxy + mxt, |
|
299 x1 * myx + y1 * myy + myt, |
|
300 x2 * mxx + y2 * mxy + mxt, |
|
301 x2 * myx + y2 * myy + myt); |
|
302 } |
|
303 |
|
304 @Override |
|
305 public void curveTo(float x1, float y1, |
|
306 float x2, float y2, |
|
307 float x3, float y3) |
|
308 { |
|
309 out.curveTo(x1 * mxx + y1 * mxy + mxt, |
|
310 x1 * myx + y1 * myy + myt, |
|
311 x2 * mxx + y2 * mxy + mxt, |
|
312 x2 * myx + y2 * myy + myt, |
|
313 x3 * mxx + y3 * mxy + mxt, |
|
314 x3 * myx + y3 * myy + myt); |
|
315 } |
|
316 |
|
317 @Override |
|
318 public void closePath() { |
|
319 out.closePath(); |
|
320 } |
|
321 |
|
322 @Override |
|
323 public void pathDone() { |
|
324 out.pathDone(); |
|
325 } |
|
326 |
|
327 @Override |
|
328 public long getNativeConsumer() { |
|
329 return 0; |
|
330 } |
|
331 } |
|
332 |
103 |
333 static final class DeltaScaleFilter implements PathConsumer2D { |
104 static final class DeltaScaleFilter implements PathConsumer2D { |
334 private PathConsumer2D out; |
105 private PathConsumer2D out; |
335 private float sx, sy; |
106 private float sx, sy; |
336 |
107 |