Path: blob/master/src/java.desktop/share/classes/sun/java2d/pipe/PixelToShapeConverter.java
41159 views
/*1* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.pipe;2627import java.awt.Rectangle;28import java.awt.Shape;29import java.awt.geom.Arc2D;30import java.awt.geom.Ellipse2D;31import java.awt.geom.Line2D;32import java.awt.geom.RoundRectangle2D;33import java.awt.geom.GeneralPath;34import sun.java2d.SunGraphics2D;3536/**37* This class converts calls to the basic pixel rendering methods38* into calls to a generic Shape rendering pipeline.39*/40public class PixelToShapeConverter41implements PixelDrawPipe, PixelFillPipe42{43ShapeDrawPipe outpipe;4445public PixelToShapeConverter(ShapeDrawPipe pipe) {46outpipe = pipe;47}4849public void drawLine(SunGraphics2D sg,50int x1, int y1, int x2, int y2) {51outpipe.draw(sg, new Line2D.Float(x1, y1, x2, y2));52}5354public void drawRect(SunGraphics2D sg,55int x, int y, int w, int h) {56outpipe.draw(sg, new Rectangle(x, y, w, h));57}5859public void fillRect(SunGraphics2D sg,60int x, int y, int w, int h) {61outpipe.fill(sg, new Rectangle(x, y, w, h));62}6364public void drawRoundRect(SunGraphics2D sg,65int x, int y, int w, int h,66int aW, int aH) {67outpipe.draw(sg, new RoundRectangle2D.Float(x, y, w, h, aW, aH));68}6970public void fillRoundRect(SunGraphics2D sg,71int x, int y, int w, int h,72int aW, int aH) {73outpipe.fill(sg, new RoundRectangle2D.Float(x, y, w, h, aW, aH));74}7576public void drawOval(SunGraphics2D sg,77int x, int y, int w, int h) {78outpipe.draw(sg, new Ellipse2D.Float(x, y, w, h));79}8081public void fillOval(SunGraphics2D sg,82int x, int y, int w, int h) {83outpipe.fill(sg, new Ellipse2D.Float(x, y, w, h));84}8586public void drawArc(SunGraphics2D sg,87int x, int y, int w, int h,88int start, int extent) {89outpipe.draw(sg, new Arc2D.Float(x, y, w, h,90start, extent, Arc2D.OPEN));91}9293public void fillArc(SunGraphics2D sg,94int x, int y, int w, int h,95int start, int extent) {96outpipe.fill(sg, new Arc2D.Float(x, y, w, h,97start, extent, Arc2D.PIE));98}99100private Shape makePoly(int[] xPoints, int[] yPoints,101int nPoints, boolean close) {102GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD);103if (nPoints > 0) {104gp.moveTo(xPoints[0], yPoints[0]);105for (int i = 1; i < nPoints; i++) {106gp.lineTo(xPoints[i], yPoints[i]);107}108if (close) {109gp.closePath();110}111}112return gp;113}114115public void drawPolyline(SunGraphics2D sg,116int[] xPoints, int[] yPoints,117int nPoints) {118outpipe.draw(sg, makePoly(xPoints, yPoints, nPoints, false));119}120121public void drawPolygon(SunGraphics2D sg,122int[] xPoints, int[] yPoints,123int nPoints) {124outpipe.draw(sg, makePoly(xPoints, yPoints, nPoints, true));125}126127public void fillPolygon(SunGraphics2D sg,128int[] xPoints, int[] yPoints,129int nPoints) {130outpipe.fill(sg, makePoly(xPoints, yPoints, nPoints, true));131}132}133134135