1 /* 2 * Copyright (c) 2009, 2016, 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 23 * questions. 24 */ 25 26 package com.sun.prism.impl.shape; 27 28 import com.sun.javafx.geom.Path2D; 29 import com.sun.javafx.geom.PathConsumer2D; 30 import com.sun.javafx.geom.RectBounds; 31 import com.sun.javafx.geom.Shape; 32 import com.sun.javafx.geom.transform.BaseTransform; 33 import com.sun.prism.BasicStroke; 34 import com.sun.prism.impl.PrismSettings; 35 import com.sun.prism.impl.PrismSettings.RasterizerType; 36 37 public class ShapeUtil { 38 39 private static final ShapeRasterizer shapeRasterizer; 40 static { 41 switch (PrismSettings.rasterizerSpec) { 42 case JavaPisces: 43 shapeRasterizer = new OpenPiscesRasterizer(); 44 break; 45 case NativePisces: 46 shapeRasterizer = new NativePiscesRasterizer(); 47 break; 48 case FloatMarlin: 49 shapeRasterizer = new MarlinRasterizer(); 50 break; 51 default: 52 case DoubleMarlin: 53 shapeRasterizer = new DMarlinRasterizer(); 54 break; 55 } 56 } 57 58 public static MaskData rasterizeShape(Shape shape, 59 BasicStroke stroke, 60 RectBounds xformBounds, 61 BaseTransform xform, 62 boolean close, boolean antialiasedShape) 63 { 64 return shapeRasterizer.getMaskData(shape, stroke, xformBounds, xform, close, antialiasedShape); 65 } 66 67 public static Shape createCenteredStrokedShape(Shape s, BasicStroke stroke) 68 { 69 if (PrismSettings.rasterizerSpec == RasterizerType.DoubleMarlin) { 70 return DMarlinRasterizer.createCenteredStrokedShape(s, stroke); 71 } 72 if (PrismSettings.rasterizerSpec == RasterizerType.FloatMarlin) { 73 return MarlinRasterizer.createCenteredStrokedShape(s, stroke); 74 } 75 // JavaPisces fallback: 76 return createCenteredStrokedShapeOpenPisces(s, stroke); 77 } 78 79 private static Shape createCenteredStrokedShapeOpenPisces(Shape s, BasicStroke stroke) 80 { 81 final float lw = (stroke.getType() == BasicStroke.TYPE_CENTERED) ? 82 stroke.getLineWidth() : stroke.getLineWidth() * 2.0f; 83 84 final Path2D p2d = new Path2D(Path2D.WIND_NON_ZERO); 85 86 PathConsumer2D pc2d = 87 new com.sun.openpisces.Stroker(p2d, lw, stroke.getEndCap(), 88 stroke.getLineJoin(), 89 stroke.getMiterLimit()); 90 91 if (stroke.isDashed()) { 92 pc2d = new com.sun.openpisces.Dasher(pc2d, stroke.getDashArray(), 93 stroke.getDashPhase()); 94 } 95 com.sun.prism.impl.shape.OpenPiscesPrismUtils.feedConsumer( 96 s.getPathIterator(null), pc2d); 97 98 return p2d; 99 } 100 101 /** 102 * Private constructor to prevent instantiation. 103 */ 104 private ShapeUtil() { 105 } 106 }