Exemplo n.º 1
0
    /**
     * Create a new Table of the given number of rows and columns
     *
     * @param numrows the number of rows
     * @param numcols the number of columns
     */
    public Table(int numrows, int numcols) {
        base();

        if(numrows < 1) throw new ArgumentException("The number of rows must be greater than 1");
        if(numcols < 1) throw new ArgumentException("The number of columns must be greater than 1");

        int x=0, y=0, tblWidth=0, tblHeight=0;
        cells = new TableCell[numrows][numcols];
        for (int i = 0; i < cells.Length; i++) {
            x = 0;
            for (int j = 0; j < cells[i].Length; j++) {
                cells[i][j] = new TableCell(this);
                Rectangle anchor = new Rectangle(x, y, TableCell.DEFAULT_WIDTH, TableCell.DEFAULT_HEIGHT);
                cells[i][j].SetAnchor(anchor);
                x += TableCell.DEFAULT_WIDTH;
            }
            y += TableCell.DEFAULT_HEIGHT;
        }
        tblWidth = x;
        tblHeight = y;
        SetAnchor(new Rectangle(0, 0, tblWidth, tblHeight));

        EscherContainerRecord spCont = (EscherContainerRecord) GetSpContainer().GetChild(0);
        EscherOptRecord opt = new EscherOptRecord();
        opt.SetRecordId((short)0xF122);
        opt.AddEscherProperty(new EscherSimpleProperty((short)0x39F, 1));
        EscherArrayProperty p = new EscherArrayProperty((short)0x43A0, false, null);
        p.SetSizeOfElements(0x0004);
        p.SetNumberOfElementsInArray(numrows);
        p.SetNumberOfElementsInMemory(numrows);
        opt.AddEscherProperty(p);
        List<EscherRecord> lst = spCont.GetChildRecords();
        lst.Add(lst.Count-1, opt);
        spCont.SetChildRecords(lst);
    }
Exemplo n.º 2
0
    /**
     * Set the polygon vertices
     *
     * @param xPoints
     * @param yPoints
     */
    public void SetPoints(float[] xPoints, float[] yPoints)
    {
        float right  = FindBiggest(xPoints);
        float bottom = FindBiggest(yPoints);
        float left   = FindSmallest(xPoints);
        float top    = FindSmallest(yPoints);

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
        opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, (int)((right - left)*POINT_DPI/MASTER_DPI)));
        opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, (int)((bottom - top)*POINT_DPI/MASTER_DPI)));

        for (int i = 0; i < xPoints.Length; i++) {
            xPoints[i] += -left;
            yPoints[i] += -top;
        }

        int numpoints = xPoints.Length;

        EscherArrayProperty verticesProp = new EscherArrayProperty(EscherProperties.GEOMETRY__VERTICES, false, new byte[0] );
        verticesProp.SetNumberOfElementsInArray(numpoints+1);
        verticesProp.SetNumberOfElementsInMemory(numpoints+1);
        verticesProp.SetSizeOfElements(0xFFF0);
        for (int i = 0; i < numpoints; i++)
        {
            byte[] data = new byte[4];
            LittleEndian.Putshort(data, 0, (short)(xPoints[i]*POINT_DPI/MASTER_DPI));
            LittleEndian.Putshort(data, 2, (short)(yPoints[i]*POINT_DPI/MASTER_DPI));
            verticesProp.SetElement(i, data);
        }
        byte[] data = new byte[4];
        LittleEndian.Putshort(data, 0, (short)(xPoints[0]*POINT_DPI/MASTER_DPI));
        LittleEndian.Putshort(data, 2, (short)(yPoints[0]*POINT_DPI/MASTER_DPI));
        verticesProp.SetElement(numpoints, data);
        opt.AddEscherProperty(verticesProp);

        EscherArrayProperty segmentsProp = new EscherArrayProperty(EscherProperties.GEOMETRY__SEGMENTINFO, false, null );
        segmentsProp.SetSizeOfElements(0x0002);
        segmentsProp.SetNumberOfElementsInArray(numpoints * 2 + 4);
        segmentsProp.SetNumberOfElementsInMemory(numpoints * 2 + 4);
        segmentsProp.SetElement(0, new byte[] { (byte)0x00, (byte)0x40 } );
        segmentsProp.SetElement(1, new byte[] { (byte)0x00, (byte)0xAC } );
        for (int i = 0; i < numpoints; i++)
        {
            segmentsProp.SetElement(2 + i * 2, new byte[] { (byte)0x01, (byte)0x00 } );
            segmentsProp.SetElement(3 + i * 2, new byte[] { (byte)0x00, (byte)0xAC } );
        }
        segmentsProp.SetElement(segmentsProp.GetNumberOfElementsInArray() - 2, new byte[] { (byte)0x01, (byte)0x60 } );
        segmentsProp.SetElement(segmentsProp.GetNumberOfElementsInArray() - 1, new byte[] { (byte)0x00, (byte)0x80 } );
        opt.AddEscherProperty(segmentsProp);

        opt.sortProperties();
    }
Exemplo n.º 3
0
    /**
     * 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);
    }