8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.marlin;
27
28
29 import com.sun.javafx.geom.transform.BaseTransform;
30
31 public final class DTransformingPathConsumer2D {
32
33 DTransformingPathConsumer2D() {
34 // used by DRendererContext
35 }
36
37 // recycled DPathConsumer2D instances from deltaTransformConsumer()
38 private final DeltaScaleFilter dt_DeltaScaleFilter = new DeltaScaleFilter();
39 private final DeltaTransformFilter dt_DeltaTransformFilter = new DeltaTransformFilter();
40
41 public DPathConsumer2D deltaTransformConsumer(DPathConsumer2D out,
42 BaseTransform at)
43 {
44 if (at == null) {
45 return out;
46 }
47 double mxx = at.getMxx();
48 double mxy = at.getMxy();
49 double myx = at.getMyx();
50 double myy = at.getMyy();
51
52 if (mxy == 0.0d && myx == 0.0d) {
53 if (mxx == 1.0d && myy == 1.0d) {
54 return out;
55 } else {
56 return dt_DeltaScaleFilter.init(out, mxx, myy);
57 }
58 } else {
59 return dt_DeltaTransformFilter.init(out, mxx, mxy, myx, myy);
60 }
74 double mxy = at.getMxy();
75 double myx = at.getMyx();
76 double myy = at.getMyy();
77
78 if (mxy == 0.0d && myx == 0.0d) {
79 if (mxx == 1.0d && myy == 1.0d) {
80 return out;
81 } else {
82 return iv_DeltaScaleFilter.init(out, 1.0d/mxx, 1.0d/myy);
83 }
84 } else {
85 double det = mxx * myy - mxy * myx;
86 return iv_DeltaTransformFilter.init(out,
87 myy / det,
88 -mxy / det,
89 -myx / det,
90 mxx / det);
91 }
92 }
93
94
95 static final class DeltaScaleFilter implements DPathConsumer2D {
96 private DPathConsumer2D out;
97 private double sx, sy;
98
99 DeltaScaleFilter() {}
100
101 DeltaScaleFilter init(DPathConsumer2D out,
102 double mxx, double myy)
103 {
104 this.out = out;
105 sx = mxx;
106 sy = myy;
107 return this; // fluent API
108 }
109
110 @Override
111 public void moveTo(double x0, double y0) {
112 out.moveTo(x0 * sx, y0 * sy);
113 }
114
190 public void curveTo(double x1, double y1,
191 double x2, double y2,
192 double x3, double y3)
193 {
194 out.curveTo(x1 * mxx + y1 * mxy,
195 x1 * myx + y1 * myy,
196 x2 * mxx + y2 * mxy,
197 x2 * myx + y2 * myy,
198 x3 * mxx + y3 * mxy,
199 x3 * myx + y3 * myy);
200 }
201
202 @Override
203 public void closePath() {
204 out.closePath();
205 }
206
207 @Override
208 public void pathDone() {
209 out.pathDone();
210 }
211 }
212 }
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.marlin;
27
28 import com.sun.javafx.geom.Path2D;
29 import com.sun.javafx.geom.transform.BaseTransform;
30
31 public final class DTransformingPathConsumer2D {
32
33 DTransformingPathConsumer2D() {
34 // used by DRendererContext
35 }
36
37 // recycled DPathConsumer2D instance from wrapPath2d()
38 private final Path2DWrapper wp_Path2DWrapper = new Path2DWrapper();
39
40 // recycled DPathConsumer2D instances from deltaTransformConsumer()
41 private final DeltaScaleFilter dt_DeltaScaleFilter = new DeltaScaleFilter();
42 private final DeltaTransformFilter dt_DeltaTransformFilter = new DeltaTransformFilter();
43
44 public DPathConsumer2D wrapPath2d(Path2D p2d)
45 {
46 return wp_Path2DWrapper.init(p2d);
47 }
48
49 public DPathConsumer2D deltaTransformConsumer(DPathConsumer2D out,
50 BaseTransform at)
51 {
52 if (at == null) {
53 return out;
54 }
55 double mxx = at.getMxx();
56 double mxy = at.getMxy();
57 double myx = at.getMyx();
58 double myy = at.getMyy();
59
60 if (mxy == 0.0d && myx == 0.0d) {
61 if (mxx == 1.0d && myy == 1.0d) {
62 return out;
63 } else {
64 return dt_DeltaScaleFilter.init(out, mxx, myy);
65 }
66 } else {
67 return dt_DeltaTransformFilter.init(out, mxx, mxy, myx, myy);
68 }
82 double mxy = at.getMxy();
83 double myx = at.getMyx();
84 double myy = at.getMyy();
85
86 if (mxy == 0.0d && myx == 0.0d) {
87 if (mxx == 1.0d && myy == 1.0d) {
88 return out;
89 } else {
90 return iv_DeltaScaleFilter.init(out, 1.0d/mxx, 1.0d/myy);
91 }
92 } else {
93 double det = mxx * myy - mxy * myx;
94 return iv_DeltaTransformFilter.init(out,
95 myy / det,
96 -mxy / det,
97 -myx / det,
98 mxx / det);
99 }
100 }
101
102 static final class DeltaScaleFilter implements DPathConsumer2D {
103 private DPathConsumer2D out;
104 private double sx, sy;
105
106 DeltaScaleFilter() {}
107
108 DeltaScaleFilter init(DPathConsumer2D out,
109 double mxx, double myy)
110 {
111 this.out = out;
112 sx = mxx;
113 sy = myy;
114 return this; // fluent API
115 }
116
117 @Override
118 public void moveTo(double x0, double y0) {
119 out.moveTo(x0 * sx, y0 * sy);
120 }
121
197 public void curveTo(double x1, double y1,
198 double x2, double y2,
199 double x3, double y3)
200 {
201 out.curveTo(x1 * mxx + y1 * mxy,
202 x1 * myx + y1 * myy,
203 x2 * mxx + y2 * mxy,
204 x2 * myx + y2 * myy,
205 x3 * mxx + y3 * mxy,
206 x3 * myx + y3 * myy);
207 }
208
209 @Override
210 public void closePath() {
211 out.closePath();
212 }
213
214 @Override
215 public void pathDone() {
216 out.pathDone();
217 }
218 }
219 static final class Path2DWrapper implements DPathConsumer2D {
220 private Path2D p2d;
221
222 Path2DWrapper() {}
223
224 Path2DWrapper init(Path2D p2d) {
225 this.p2d = p2d;
226 return this;
227 }
228
229 @Override
230 public void moveTo(double x0, double y0) {
231 p2d.moveTo((float)x0, (float)y0);
232 }
233
234 @Override
235 public void lineTo(double x1, double y1) {
236 p2d.lineTo((float)x1, (float)y1);
237 }
238
239 @Override
240 public void closePath() {
241 p2d.closePath();
242 }
243
244 @Override
245 public void pathDone() {}
246
247 @Override
248 public void curveTo(double x1, double y1,
249 double x2, double y2,
250 double x3, double y3)
251 {
252 p2d.curveTo((float)x1, (float)y1, (float)x2, (float)y2,
253 (float)x3, (float)y3);
254 }
255
256 @Override
257 public void quadTo(double x1, double y1, double x2, double y2) {
258 p2d.quadTo((float)x1, (float)y1, (float)x2, (float)y2);
259 }
260 }
261 }
|