1 /*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
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
127 }
128 }
129
130 private static Vector<Curve> pathToCurves(PathIterator pi) {
131 Vector<Curve> curves = new Vector<>();
132 int windingRule = pi.getWindingRule();
133 // coords array is big enough for holding:
134 // coordinates returned from currentSegment (6)
135 // OR
136 // two subdivided quadratic curves (2+4+4=10)
137 // AND
138 // 0-1 horizontal splitting parameters
139 // OR
140 // 2 parametric equation derivative coefficients
141 // OR
142 // three subdivided cubic curves (2+6+6+6=20)
143 // AND
144 // 0-2 horizontal splitting parameters
145 // OR
146 // 3 parametric equation derivative coefficients
147 double coords[] = new double[23];
148 double movx = 0, movy = 0;
149 double curx = 0, cury = 0;
150 double newx, newy;
151 while (!pi.isDone()) {
152 switch (pi.currentSegment(coords)) {
153 case PathIterator.SEG_MOVETO:
154 Curve.insertLine(curves, curx, cury, movx, movy);
155 curx = movx = coords[0];
156 cury = movy = coords[1];
157 Curve.insertMove(curves, movx, movy);
158 break;
159 case PathIterator.SEG_LINETO:
160 newx = coords[0];
161 newy = coords[1];
162 Curve.insertLine(curves, curx, cury, newx, newy);
163 curx = newx;
164 cury = newy;
165 break;
166 case PathIterator.SEG_QUADTO:
167 newx = coords[2];
685 public void next() {
686 if (prevcurve != null) {
687 prevcurve = null;
688 } else {
689 prevcurve = thiscurve;
690 index++;
691 if (index < curves.size()) {
692 thiscurve = curves.get(index);
693 if (thiscurve.getOrder() != 0 &&
694 prevcurve.getX1() == thiscurve.getX0() &&
695 prevcurve.getY1() == thiscurve.getY0())
696 {
697 prevcurve = null;
698 }
699 } else {
700 thiscurve = null;
701 }
702 }
703 }
704
705 public int currentSegment(float coords[]) {
706 double dcoords[] = new double[6];
707 int segtype = currentSegment(dcoords);
708 int numpoints = (segtype == SEG_CLOSE ? 0
709 : (segtype == SEG_QUADTO ? 2
710 : (segtype == SEG_CUBICTO ? 3
711 : 1)));
712 for (int i = 0; i < numpoints * 2; i++) {
713 coords[i] = (float) dcoords[i];
714 }
715 return segtype;
716 }
717
718 public int currentSegment(double coords[]) {
719 int segtype;
720 int numpoints;
721 if (prevcurve != null) {
722 // Need to finish off junction between curves
723 if (thiscurve == null || thiscurve.getOrder() == 0) {
724 return SEG_CLOSE;
725 }
726 coords[0] = thiscurve.getX0();
727 coords[1] = thiscurve.getY0();
728 segtype = SEG_LINETO;
729 numpoints = 1;
730 } else if (thiscurve == null) {
731 throw new NoSuchElementException("area iterator out of bounds");
732 } else {
733 segtype = thiscurve.getSegment(coords);
734 numpoints = thiscurve.getOrder();
735 if (numpoints == 0) {
736 numpoints = 1;
737 }
738 }
|
1 /*
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
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
127 }
128 }
129
130 private static Vector<Curve> pathToCurves(PathIterator pi) {
131 Vector<Curve> curves = new Vector<>();
132 int windingRule = pi.getWindingRule();
133 // coords array is big enough for holding:
134 // coordinates returned from currentSegment (6)
135 // OR
136 // two subdivided quadratic curves (2+4+4=10)
137 // AND
138 // 0-1 horizontal splitting parameters
139 // OR
140 // 2 parametric equation derivative coefficients
141 // OR
142 // three subdivided cubic curves (2+6+6+6=20)
143 // AND
144 // 0-2 horizontal splitting parameters
145 // OR
146 // 3 parametric equation derivative coefficients
147 double[] coords = new double[23];
148 double movx = 0, movy = 0;
149 double curx = 0, cury = 0;
150 double newx, newy;
151 while (!pi.isDone()) {
152 switch (pi.currentSegment(coords)) {
153 case PathIterator.SEG_MOVETO:
154 Curve.insertLine(curves, curx, cury, movx, movy);
155 curx = movx = coords[0];
156 cury = movy = coords[1];
157 Curve.insertMove(curves, movx, movy);
158 break;
159 case PathIterator.SEG_LINETO:
160 newx = coords[0];
161 newy = coords[1];
162 Curve.insertLine(curves, curx, cury, newx, newy);
163 curx = newx;
164 cury = newy;
165 break;
166 case PathIterator.SEG_QUADTO:
167 newx = coords[2];
685 public void next() {
686 if (prevcurve != null) {
687 prevcurve = null;
688 } else {
689 prevcurve = thiscurve;
690 index++;
691 if (index < curves.size()) {
692 thiscurve = curves.get(index);
693 if (thiscurve.getOrder() != 0 &&
694 prevcurve.getX1() == thiscurve.getX0() &&
695 prevcurve.getY1() == thiscurve.getY0())
696 {
697 prevcurve = null;
698 }
699 } else {
700 thiscurve = null;
701 }
702 }
703 }
704
705 public int currentSegment(float[] coords) {
706 double[] dcoords = new double[6];
707 int segtype = currentSegment(dcoords);
708 int numpoints = (segtype == SEG_CLOSE ? 0
709 : (segtype == SEG_QUADTO ? 2
710 : (segtype == SEG_CUBICTO ? 3
711 : 1)));
712 for (int i = 0; i < numpoints * 2; i++) {
713 coords[i] = (float) dcoords[i];
714 }
715 return segtype;
716 }
717
718 public int currentSegment(double[] coords) {
719 int segtype;
720 int numpoints;
721 if (prevcurve != null) {
722 // Need to finish off junction between curves
723 if (thiscurve == null || thiscurve.getOrder() == 0) {
724 return SEG_CLOSE;
725 }
726 coords[0] = thiscurve.getX0();
727 coords[1] = thiscurve.getY0();
728 segtype = SEG_LINETO;
729 numpoints = 1;
730 } else if (thiscurve == null) {
731 throw new NoSuchElementException("area iterator out of bounds");
732 } else {
733 segtype = thiscurve.getSegment(coords);
734 numpoints = thiscurve.getOrder();
735 if (numpoints == 0) {
736 numpoints = 1;
737 }
738 }
|