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.prism; 27 28 import com.sun.javafx.geom.Area; 29 import com.sun.javafx.geom.GeneralShapePair; 30 import com.sun.javafx.geom.Path2D; 31 import com.sun.javafx.geom.PathConsumer2D; 32 import com.sun.javafx.geom.PathIterator; 33 import com.sun.javafx.geom.RoundRectangle2D; 34 import com.sun.javafx.geom.Shape; 35 import com.sun.javafx.geom.ShapePair; 36 import com.sun.javafx.geom.transform.BaseTransform; 37 import com.sun.openpisces.Dasher; 38 import com.sun.openpisces.Stroker; 39 import com.sun.prism.impl.shape.OpenPiscesPrismUtils; 40 41 public final class BasicStroke { 42 public static final int CAP_BUTT = Stroker.CAP_BUTT; 43 public static final int CAP_ROUND = Stroker.CAP_ROUND; 44 public static final int CAP_SQUARE = Stroker.CAP_SQUARE; 45 46 public static final int JOIN_BEVEL = Stroker.JOIN_BEVEL; 47 public static final int JOIN_MITER = Stroker.JOIN_MITER; 48 public static final int JOIN_ROUND = Stroker.JOIN_ROUND; 49 50 public static final int TYPE_CENTERED = 0; 51 public static final int TYPE_INNER = 1; 52 public static final int TYPE_OUTER = 2; 53 54 float width; 55 int type; 56 int cap; 57 int join; 58 float miterLimit; 59 float dash[]; 60 float dashPhase; 61 62 public BasicStroke() { 63 set(TYPE_CENTERED, 1.0f, CAP_SQUARE, JOIN_MITER, 10f); 64 } 65 66 public BasicStroke(float width, int cap, int join, float miterLimit) { 67 set(TYPE_CENTERED, width, cap, join, miterLimit); 68 } 662 oy = -oy; 663 } 664 665 computeMiter((x0 - pdx) + pox, (y0 - pdy) + poy, x0 + pox, y0 + poy, 666 (x0 + dx) + ox, (y0 + dy) + oy, x0 + ox, y0 + oy, 667 tmpMiter, 0); 668 float lenSq = (tmpMiter[0] - x0) * (tmpMiter[0] - x0) + (tmpMiter[1] - y0) * (tmpMiter[1] - y0); 669 670 float miterLimitWidth = miterLimit * w; 671 if (lenSq < miterLimitWidth * miterLimitWidth) { 672 accumulateOrdered(tmpMiter[0], tmpMiter[1], tmpMiter[0], tmpMiter[1], bbox); 673 } 674 } 675 676 677 private void accumulateBevel(float x0, float y0, float pox, float poy, float ox, float oy, float[] bbox) { 678 accumulate(x0 + pox, y0 + poy, x0 - pox, y0 - poy, bbox); 679 accumulate(x0 + ox, y0 + oy, x0 - ox, y0 - oy, bbox); 680 } 681 682 public Shape createCenteredStrokedShape(Shape s) { 683 Path2D p2d = new Path2D(Path2D.WIND_NON_ZERO); 684 float lw = (type == TYPE_CENTERED) ? width : width * 2.0f; 685 PathConsumer2D pc2d = 686 new Stroker(p2d, lw, cap, join, miterLimit); 687 if (dash != null) { 688 pc2d = new Dasher(pc2d, dash, dashPhase); 689 } 690 OpenPiscesPrismUtils.feedConsumer(s.getPathIterator(null), pc2d); 691 return p2d; 692 } 693 694 static final float SQRT_2 = (float) Math.sqrt(2); 695 696 Shape strokeRoundRectangle(RoundRectangle2D rr) { 697 if (rr.width < 0 || rr.height < 0) { 698 return new Path2D(); 699 } 700 if (isDashed()) { 701 return null; 702 } 703 int j; 704 float aw = rr.arcWidth; 705 float ah = rr.arcHeight; 706 if (aw <= 0f || ah <= 0f) { 707 aw = ah = 0f; 708 if (type == TYPE_INNER) { 709 j = JOIN_MITER; 710 } else { 711 j = this.join; | 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.prism; 27 28 import com.sun.javafx.geom.Area; 29 import com.sun.javafx.geom.GeneralShapePair; 30 import com.sun.javafx.geom.Path2D; 31 import com.sun.javafx.geom.PathIterator; 32 import com.sun.javafx.geom.RoundRectangle2D; 33 import com.sun.javafx.geom.Shape; 34 import com.sun.javafx.geom.ShapePair; 35 import com.sun.javafx.geom.transform.BaseTransform; 36 import com.sun.prism.impl.shape.ShapeUtil; 37 38 public final class BasicStroke { 39 40 /** Constant value for end cap style. */ 41 public static final int CAP_BUTT = 0; 42 /** Constant value for end cap style. */ 43 public static final int CAP_ROUND = 1; 44 /** Constant value for end cap style. */ 45 public static final int CAP_SQUARE = 2; 46 47 /** Constant value for join style. */ 48 public static final int JOIN_MITER = 0; 49 /** Constant value for join style. */ 50 public static final int JOIN_ROUND = 1; 51 /** Constant value for join style. */ 52 public static final int JOIN_BEVEL = 2; 53 54 public static final int TYPE_CENTERED = 0; 55 public static final int TYPE_INNER = 1; 56 public static final int TYPE_OUTER = 2; 57 58 float width; 59 int type; 60 int cap; 61 int join; 62 float miterLimit; 63 float dash[]; 64 float dashPhase; 65 66 public BasicStroke() { 67 set(TYPE_CENTERED, 1.0f, CAP_SQUARE, JOIN_MITER, 10f); 68 } 69 70 public BasicStroke(float width, int cap, int join, float miterLimit) { 71 set(TYPE_CENTERED, width, cap, join, miterLimit); 72 } 666 oy = -oy; 667 } 668 669 computeMiter((x0 - pdx) + pox, (y0 - pdy) + poy, x0 + pox, y0 + poy, 670 (x0 + dx) + ox, (y0 + dy) + oy, x0 + ox, y0 + oy, 671 tmpMiter, 0); 672 float lenSq = (tmpMiter[0] - x0) * (tmpMiter[0] - x0) + (tmpMiter[1] - y0) * (tmpMiter[1] - y0); 673 674 float miterLimitWidth = miterLimit * w; 675 if (lenSq < miterLimitWidth * miterLimitWidth) { 676 accumulateOrdered(tmpMiter[0], tmpMiter[1], tmpMiter[0], tmpMiter[1], bbox); 677 } 678 } 679 680 681 private void accumulateBevel(float x0, float y0, float pox, float poy, float ox, float oy, float[] bbox) { 682 accumulate(x0 + pox, y0 + poy, x0 - pox, y0 - poy, bbox); 683 accumulate(x0 + ox, y0 + oy, x0 - ox, y0 - oy, bbox); 684 } 685 686 public Shape createCenteredStrokedShape(final Shape s) { 687 return ShapeUtil.createCenteredStrokedShape(s, this); 688 } 689 690 static final float SQRT_2 = (float) Math.sqrt(2); 691 692 Shape strokeRoundRectangle(RoundRectangle2D rr) { 693 if (rr.width < 0 || rr.height < 0) { 694 return new Path2D(); 695 } 696 if (isDashed()) { 697 return null; 698 } 699 int j; 700 float aw = rr.arcWidth; 701 float ah = rr.arcHeight; 702 if (aw <= 0f || ah <= 0f) { 703 aw = ah = 0f; 704 if (type == TYPE_INNER) { 705 j = JOIN_MITER; 706 } else { 707 j = this.join; |