/** * Set the shape path * * @param path */ public void SetPath(GeneralPath path) { Rectangle2D bounds = path.GetBounds2D(); PathIterator it = path.GetPathIterator(new AffineTransform()); List<byte[]> segInfo = new List<byte[]>(); List<Point2D.Double> pntInfo = new List<Point2D.Double>(); bool IsClosed = false; while (!it.IsDone()) { double[] vals = new double[6]; int type = it.currentSegment(vals); switch (type) { case PathIterator.SEG_MOVETO: pntInfo.Add(new Point2D.Double(vals[0], vals[1])); segInfo.Add(SEGMENTINFO_MOVETO); break; case PathIterator.SEG_LINETO: pntInfo.Add(new Point2D.Double(vals[0], vals[1])); segInfo.Add(SEGMENTINFO_LINETO); segInfo.Add(SEGMENTINFO_ESCAPE); break; case PathIterator.SEG_CUBICTO: pntInfo.Add(new Point2D.Double(vals[0], vals[1])); pntInfo.Add(new Point2D.Double(vals[2], vals[3])); pntInfo.Add(new Point2D.Double(vals[4], vals[5])); segInfo.Add(SEGMENTINFO_CUBICTO); segInfo.Add(SEGMENTINFO_ESCAPE2); break; case PathIterator.SEG_QUADTO: //TODO: figure out how to convert SEG_QUADTO into SEG_CUBICTO logger.log(POILogger.WARN, "SEG_QUADTO is not supported"); break; case PathIterator.SEG_CLOSE: pntInfo.Add(pntInfo.Get(0)); segInfo.Add(SEGMENTINFO_LINETO); segInfo.Add(SEGMENTINFO_ESCAPE); segInfo.Add(SEGMENTINFO_LINETO); segInfo.Add(SEGMENTINFO_CLOSE); isClosed = true; break; } it.next(); } if(!isClosed) segInfo.Add(SEGMENTINFO_LINETO); segInfo.Add(new byte[]{0x00, (byte)0x80}); EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4)); EscherArrayProperty verticesProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null); verticesProp.SetNumberOfElementsInArray(pntInfo.Count); verticesProp.SetNumberOfElementsInMemory(pntInfo.Count); verticesProp.SetSizeOfElements(0xFFF0); for (int i = 0; i < pntInfo.Count; i++) { Point2D.Double pnt = pntInfo.Get(i); byte[] data = new byte[4]; LittleEndian.Putshort(data, 0, (short)((pnt.GetX() - bounds.GetX())*MASTER_DPI/POINT_DPI)); LittleEndian.Putshort(data, 2, (short)((pnt.GetY() - bounds.GetY())*MASTER_DPI/POINT_DPI)); verticesProp.SetElement(i, data); } opt.AddEscherProperty(verticesProp); EscherArrayProperty segmentsProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000), false, null); segmentsProp.SetNumberOfElementsInArray(segInfo.Count); segmentsProp.SetNumberOfElementsInMemory(segInfo.Count); segmentsProp.SetSizeOfElements(0x2); for (int i = 0; i < segInfo.Count; i++) { byte[] seg = segInfo.Get(i); segmentsProp.SetElement(i, seg); } opt.AddEscherProperty(segmentsProp); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, (int)(bounds.Width*MASTER_DPI/POINT_DPI))); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, (int)(bounds.Height*MASTER_DPI/POINT_DPI))); opt.sortProperties(); SetAnchor(bounds); }