public void appendLine(float x1, float y1) { path.lineTo(x1, y1); }
public void DrawPolyline(int[] xPoints, int[] yPoints, int nPoints) { if(nPoints > 0) { GeneralPath generalpath = new GeneralPath(); generalpath.moveTo(xPoints[0], yPoints[0]); for(int j = 1; j < nPoints; j++) generalpath.lineTo(xPoints[j], yPoints[j]); Draw(generalpath); } }
/** * Gets the freeform path * * @return the freeform path */ public GeneralPath GetPath(){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4)); EscherArrayProperty verticesProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES + 0x4000)); if(verticesProp == null) verticesProp = (EscherArrayProperty)getEscherProperty(opt, EscherProperties.GEOMETRY__VERTICES); EscherArrayProperty segmentsProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000)); if(segmentsProp == null) segmentsProp = (EscherArrayProperty)getEscherProperty(opt, EscherProperties.GEOMETRY__SEGMENTINFO); //sanity check if(verticesProp == null) { logger.log(POILogger.WARN, "Freeform is missing GEOMETRY__VERTICES "); return null; } if(segmentsProp == null) { logger.log(POILogger.WARN, "Freeform is missing GEOMETRY__SEGMENTINFO "); return null; } GeneralPath path = new GeneralPath(); int numPoints = verticesProp.GetNumberOfElementsInArray(); int numSegments = segmentsProp.GetNumberOfElementsInArray(); for (int i = 0, j = 0; i < numSegments && j < numPoints; i++) { byte[] elem = segmentsProp.GetElement(i); if(Arrays.Equals(elem, SEGMENTINFO_MOVETO)){ byte[] p = verticesProp.GetElement(j++); short x = LittleEndian.Getshort(p, 0); short y = LittleEndian.Getshort(p, 2); path.moveTo( ((float)x*POINT_DPI/MASTER_DPI), ((float)y*POINT_DPI/MASTER_DPI)); } else if (Arrays.Equals(elem, SEGMENTINFO_CUBICTO) || Arrays.Equals(elem, SEGMENTINFO_CUBICTO2)){ i++; byte[] p1 = verticesProp.GetElement(j++); short x1 = LittleEndian.Getshort(p1, 0); short y1 = LittleEndian.Getshort(p1, 2); byte[] p2 = verticesProp.GetElement(j++); short x2 = LittleEndian.Getshort(p2, 0); short y2 = LittleEndian.Getshort(p2, 2); byte[] p3 = verticesProp.GetElement(j++); short x3 = LittleEndian.Getshort(p3, 0); short y3 = LittleEndian.Getshort(p3, 2); path.curveTo( ((float)x1*POINT_DPI/MASTER_DPI), ((float)y1*POINT_DPI/MASTER_DPI), ((float)x2*POINT_DPI/MASTER_DPI), ((float)y2*POINT_DPI/MASTER_DPI), ((float)x3*POINT_DPI/MASTER_DPI), ((float)y3*POINT_DPI/MASTER_DPI)); } else if (Arrays.Equals(elem, SEGMENTINFO_LINETO)){ i++; byte[] pnext = segmentsProp.GetElement(i); if(Arrays.Equals(pnext, SEGMENTINFO_ESCAPE)){ if(j + 1 < numPoints){ byte[] p = verticesProp.GetElement(j++); short x = LittleEndian.Getshort(p, 0); short y = LittleEndian.Getshort(p, 2); path.lineTo( ((float)x*POINT_DPI/MASTER_DPI), ((float)y*POINT_DPI/MASTER_DPI)); } } else if (Arrays.Equals(pnext, SEGMENTINFO_CLOSE)){ path.ClosePath(); } } } return path; }
/** * Draws a sequence of connected lines defined by * arrays of <i>x</i> and <i>y</i> coordinates. * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point. * The figure is not closed if the first point * differs from the last point. * @param xPoints an array of <i>x</i> points * @param yPoints an array of <i>y</i> points * @param nPoints the total number of points * @see java.awt.Graphics#drawPolygon(int[], int[], int) * @since JDK1.1 */ public void DrawPolyline(int[] xPoints, int[] yPoints, int nPoints){ if(nPoints > 0){ GeneralPath path = new GeneralPath(); path.moveTo(xPoints[0], yPoints[0]); for(int i=1; i<nPoints; i++) path.lineTo(xPoints[i], yPoints[i]); Draw(path); } }