public void AfterRecordSerialize(int offset, short recordId, int size, EscherRecord record)
 {
     // do nothing
 }
 public MsofbtClientData(EscherRecord record)
     : base(record)
 {
 }
 public MsofbtAlignRule(EscherRecord record)
     : base(record)
 {
 }
Example #4
0
 public MsofbtCLSID(EscherRecord record)
     : base(record)
 {
 }
 public MsofbtCalloutRule(EscherRecord record)
     : base(record)
 {
 }
 public MsofbtConnectorRule(EscherRecord record)
     : base(record)
 {
 }
Example #7
0
        /// <summary>
        /// Creates the lowerlevel escher records for this shape.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private EscherContainerRecord CreateSpContainer(HSSFPolygon hssfShape, int shapeId)
        {
            HSSFShape shape = hssfShape;

            EscherContainerRecord  spContainer = new EscherContainerRecord();
            EscherSpRecord         sp          = new EscherSpRecord();
            EscherOptRecord        opt         = new EscherOptRecord();
            EscherClientDataRecord clientData  = new EscherClientDataRecord();

            spContainer.RecordId = EscherContainerRecord.SP_CONTAINER;
            spContainer.Options  = (short)0x000F;
            sp.RecordId          = EscherSpRecord.RECORD_ID;
            sp.Options           = (short)((EscherAggregate.ST_NOT_PRIMATIVE << 4) | 0x2);
            sp.ShapeId           = shapeId;
            if (hssfShape.Parent == null)
            {
                sp.Flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
            }
            else
            {
                sp.Flags = EscherSpRecord.FLAG_CHILD | EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
            }
            opt.RecordId = EscherOptRecord.RECORD_ID;
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TRANSFORM__ROTATION, false, false, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, false, false, hssfShape.DrawAreaWidth));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, false, false, hssfShape.DrawAreaHeight));
            opt.AddEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX));
            EscherArrayProperty verticesProp = new EscherArrayProperty(EscherProperties.GEOMETRY__VERTICES, false, new byte[0]);

            verticesProp.NumberOfElementsInArray  = (hssfShape.XPoints.Length + 1);
            verticesProp.NumberOfElementsInMemory = (hssfShape.XPoints.Length + 1);
            verticesProp.SizeOfElements           = unchecked ((short)0xFFF0);
            for (int i = 0; i < hssfShape.XPoints.Length; i++)
            {
                byte[] data = new byte[4];
                LittleEndian.PutShort(data, 0, (short)hssfShape.XPoints[i]);
                LittleEndian.PutShort(data, 2, (short)hssfShape.YPoints[i]);
                verticesProp.SetElement(i, data);
            }
            int point = hssfShape.XPoints.Length;

            byte[] data1 = new byte[4];
            LittleEndian.PutShort(data1, 0, (short)hssfShape.XPoints[0]);
            LittleEndian.PutShort(data1, 2, (short)hssfShape.YPoints[0]);
            verticesProp.SetElement(point, data1);
            opt.AddEscherProperty(verticesProp);
            EscherArrayProperty segmentsProp = new EscherArrayProperty(EscherProperties.GEOMETRY__SEGMENTINFO, false, null);

            segmentsProp.SizeOfElements           = (0x0002);
            segmentsProp.NumberOfElementsInArray  = (hssfShape.XPoints.Length * 2 + 4);
            segmentsProp.NumberOfElementsInMemory = (hssfShape.XPoints.Length * 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 < hssfShape.XPoints.Length; 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.NumberOfElementsInArray - 2, new byte[] { (byte)0x01, (byte)0x60 });
            segmentsProp.SetElement(segmentsProp.NumberOfElementsInArray - 1, new byte[] { (byte)0x00, (byte)0x80 });
            opt.AddEscherProperty(segmentsProp);
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__FILLOK, false, false, 0x00010001));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINESTARTARROWHEAD, false, false, 0x0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDARROWHEAD, false, false, 0x0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDCAPSTYLE, false, false, 0x0));

            AddStandardOptions(shape, opt);

            EscherRecord anchor = CreateAnchor(shape.Anchor);

            clientData.RecordId = (EscherClientDataRecord.RECORD_ID);
            clientData.Options  = (short)0x0000;

            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);

            return(spContainer);
        }
Example #8
0
        private void ConvertRecordsToUserModel(EscherContainerRecord shapeContainer, Object model)
        {
            for (IEnumerator it = shapeContainer.ChildRecords.GetEnumerator(); it.MoveNext();)
            {
                EscherRecord r = (EscherRecord)it.Current;
                if (r is EscherSpgrRecord)
                {
                    // This may be overriden by a later EscherClientAnchorRecord
                    EscherSpgrRecord spgr = (EscherSpgrRecord)r;

                    if (model is HSSFShapeGroup)
                    {
                        HSSFShapeGroup g = (HSSFShapeGroup)model;
                        g.SetCoordinates(
                            spgr.RectX1, spgr.RectY1,
                            spgr.RectX2, spgr.RectY2
                            );
                    }
                    else
                    {
                        throw new InvalidOperationException("Got top level anchor but not Processing a Group");
                    }
                }
                else if (r is EscherClientAnchorRecord)
                {
                    EscherClientAnchorRecord car = (EscherClientAnchorRecord)r;

                    if (model is HSSFShape)
                    {
                        HSSFShape g = (HSSFShape)model;
                        g.Anchor.Dx1 = car.Dx1;
                        g.Anchor.Dx2 = car.Dx2;
                        g.Anchor.Dy1 = car.Dy1;
                        g.Anchor.Dy2 = car.Dy2;
                    }
                    else
                    {
                        throw new InvalidOperationException("Got top level anchor but not Processing a Group or shape");
                    }
                }
                else if (r is EscherTextboxRecord)
                {
                    EscherTextboxRecord tbr = (EscherTextboxRecord)r;

                    // Also need to Find the TextObjectRecord too
                    // TODO
                }
                else if (r is EscherSpRecord)
                {
                    // Use flags if needed
                }
                else if (r is EscherOptRecord)
                {
                    // Use properties if needed
                }
                else
                {
                    //Console.Error.WriteLine(r);
                }
            }
        }
 public void AfterRecordSerialize(int offset, short recordId, int size, EscherRecord record)
 {
     // do nothing
 }
 public MsofbtRegroupItems(EscherRecord record)
     : base(record)
 {
 }
 public void BeforeRecordSerialize(int offset, short recordId, EscherRecord record)
 {
     // do nothing
 }
 public MsofbtColorScheme(EscherRecord record)
     : base(record)
 {
 }
 public MsofbtClientRule(EscherRecord record)
     : base(record)
 {
 }
 public MsofbtOleObject(EscherRecord record)
     : base(record)
 {
 }
Example #15
0
        /**
         * Converts the Records into UserModel
         *  objects on the bound HSSFPatriarch
         */
        public void ConvertRecordsToUserModel()
        {
            if (patriarch == null)
            {
                throw new InvalidOperationException("Must call SetPatriarch() first");
            }

            // The top level container ought to have
            //  the DgRecord and the container of one container
            //  per shape Group (patriach overall first)
            EscherContainerRecord topContainer =
                (EscherContainerRecord)GetEscherContainer();

            if (topContainer == null)
            {
                return;
            }
            topContainer = (EscherContainerRecord)
                           topContainer.ChildContainers[0];

            IList tcc = topContainer.ChildContainers;

            if (tcc.Count == 0)
            {
                throw new InvalidOperationException("No child escher containers at the point that should hold the patriach data, and one container per top level shape!");
            }

            // First up, Get the patriach position
            // This Is in the first EscherSpgrRecord, in
            //  the first container, with a EscherSRecord too
            EscherContainerRecord patriachContainer =
                (EscherContainerRecord)tcc[0];
            EscherSpgrRecord spgr = null;

            for (IEnumerator it = patriachContainer.ChildRecords.GetEnumerator(); it.MoveNext();)
            {
                EscherRecord r = (EscherRecord)it.Current;
                if (r is EscherSpgrRecord)
                {
                    spgr = (EscherSpgrRecord)r;
                    break;
                }
            }
            if (spgr != null)
            {
                patriarch.SetCoordinates(
                    spgr.RectX1, spgr.RectY1,
                    spgr.RectX2, spgr.RectY2
                    );
            }

            // Now Process the containers for each Group
            //  and objects
            for (int i = 1; i < tcc.Count; i++)
            {
                EscherContainerRecord shapeContainer =
                    (EscherContainerRecord)tcc[i];
                //Console.Error.WriteLine("\n\n*****\n\n");
                //Console.Error.WriteLine(shapeContainer);

                // Could be a Group, or a base object
                if (shapeContainer.ChildRecords.Count == 1 &&
                    shapeContainer.ChildContainers.Count == 1)
                {
                    // Group
                    HSSFShapeGroup group =
                        new HSSFShapeGroup(null, new HSSFClientAnchor());
                    patriarch.Children.Add(group);

                    EscherContainerRecord groupContainer =
                        (EscherContainerRecord)shapeContainer.GetChild(0);
                    ConvertRecordsToUserModel(groupContainer, group);
                }
                else if (shapeContainer.HasChildOfType(unchecked ((short)0xF00D)))
                {
                    // TextBox
                    HSSFTextbox box =
                        new HSSFTextbox(null, new HSSFClientAnchor());
                    patriarch.Children.Add(box);

                    ConvertRecordsToUserModel(shapeContainer, box);
                }
                else if (shapeContainer.HasChildOfType(unchecked ((short)0xF011)))
                {
                    // Not yet supporting EscherClientDataRecord stuff
                }
                else
                {
                    // Base level
                    ConvertRecordsToUserModel(shapeContainer, patriarch);
                }
            }

            // Now, clear any trace of what records make up
            //  the patriarch
            // Otherwise, everything will go horribly wrong
            //  when we try to Write out again....
            //      clearEscherRecords();
            drawingManager.GetDgg().FileIdClusters = new EscherDggRecord.FileIdCluster[0];

            // TODO: Support Converting our records
            //  back into shapes
            log.Log(POILogger.WARN, "Not Processing objects into Patriarch!");
        }
Example #16
0
        /**
         * Converts the Records into UserModel
         *  objects on the bound HSSFPatriarch
         */
        public void ConvertRecordsToUserModel()
        {
            if (patriarch == null)
            {
                throw new InvalidOperationException("Must call SetPatriarch() first");
            }

            // The top level container ought to have
            //  the DgRecord and the container of one container
            //  per shape Group (patriach overall first)
            EscherContainerRecord topContainer =
                (EscherContainerRecord)GetEscherContainer();

            if (topContainer == null)
            {
                return;
            }
            topContainer = (EscherContainerRecord)
                           topContainer.ChildContainers[0];

            IList <EscherContainerRecord> tcc = topContainer.ChildContainers;

            if (tcc.Count == 0)
            {
                throw new InvalidOperationException("No child escher containers at the point that should hold the patriach data, and one container per top level shape!");
            }

            // First up, Get the patriach position
            // This Is in the first EscherSpgrRecord, in
            //  the first container, with a EscherSRecord too
            EscherContainerRecord patriachContainer =
                (EscherContainerRecord)tcc[0];
            EscherSpgrRecord spgr = null;

            for (IEnumerator it = patriachContainer.ChildRecords.GetEnumerator(); it.MoveNext();)
            {
                EscherRecord r = (EscherRecord)it.Current;
                if (r is EscherSpgrRecord)
                {
                    spgr = (EscherSpgrRecord)r;
                    break;
                }
            }
            if (spgr != null)
            {
                patriarch.SetCoordinates(
                    spgr.RectX1, spgr.RectY1,
                    spgr.RectX2, spgr.RectY2
                    );
            }

            // Now Process the containers for each Group
            //  and objects
            for (int i = 1; i < tcc.Count; i++)
            {
                EscherContainerRecord shapeContainer =
                    (EscherContainerRecord)tcc[i];
                //Console.Error.WriteLine("\n\n*****\n\n");
                //Console.Error.WriteLine(shapeContainer);

                // Could be a Group, or a base object
                if (shapeContainer.RecordId == EscherContainerRecord.SPGR_CONTAINER)
                {
                    if (shapeContainer.ChildRecords.Count > 0)
                    {
                        // Group
                        HSSFShapeGroup group =
                            new HSSFShapeGroup(null, new HSSFClientAnchor());
                        patriarch.Children.Add(group);

                        EscherContainerRecord groupContainer =
                            (EscherContainerRecord)shapeContainer.GetChild(0);
                        ConvertRecordsToUserModel(groupContainer, group);
                    }
                }
                else if (shapeContainer.RecordId == EscherContainerRecord.SP_CONTAINER)
                {
                    EscherSpRecord spRecord = shapeContainer.GetChildById(EscherSpRecord.RECORD_ID);
                    int            type     = spRecord.Options >> 4;

                    switch (type)
                    {
                    case ST_TEXTBOX:
                        // TextBox
                        HSSFTextbox box =
                            new HSSFTextbox(null, new HSSFClientAnchor());
                        patriarch.Children.Add(box);

                        ConvertRecordsToUserModel(shapeContainer, box);
                        break;

                    case ST_PICTUREFRAME:
                        // Duplicated from
                        // org.apache.poi.hslf.model.Picture.getPictureIndex()
                        EscherOptRecord      opt  = (EscherOptRecord)GetEscherChild(shapeContainer, EscherOptRecord.RECORD_ID);
                        EscherSimpleProperty prop = (EscherSimpleProperty)opt.Lookup(EscherProperties.BLIP__BLIPTODISPLAY);
                        if (prop != null)
                        {
                            int pictureIndex = prop.PropertyValue;
                            EscherClientAnchorRecord anchorRecord = (EscherClientAnchorRecord)GetEscherChild(shapeContainer, EscherClientAnchorRecord.RECORD_ID);
                            HSSFClientAnchor         anchor       = new HSSFClientAnchor();
                            anchor.Col1 = anchorRecord.Col1;
                            anchor.Col2 = anchorRecord.Col2;
                            anchor.Dx1  = anchorRecord.Dx1;
                            anchor.Dx2  = anchorRecord.Dx2;
                            anchor.Dy1  = anchorRecord.Dy1;
                            anchor.Dy2  = anchorRecord.Dy2;
                            anchor.Row1 = anchorRecord.Row1;
                            anchor.Row2 = anchorRecord.Row2;
                            HSSFPicture picture = new HSSFPicture(null, anchor);
                            picture.PictureIndex = pictureIndex;
                            patriarch.AddShape(picture);
                        }
                        break;
                    }
                }
                else
                {
                    // Base level
                    ConvertRecordsToUserModel(shapeContainer, patriarch);
                }
            }

            // Now, clear any trace of what records make up
            //  the patriarch
            // Otherwise, everything will go horribly wrong
            //  when we try to Write out again....
            //      clearEscherRecords();
            drawingManager.GetDgg().FileIdClusters = new EscherDggRecord.FileIdCluster[0];

            // TODO: Support Converting our records
            //  back into shapes
            log.Log(POILogger.WARN, "Not Processing objects into Patriarch!");
        }
        /**
         * Clone the current record, via a call to serialise
         *  it, and another to Create a new record from the
         *  bytes.
         * May only be used for classes which don't have
         *  internal counts / ids in them. For those which
         *  do, a full record-aware serialise is needed, which
         *  allocates new ids / counts as needed.
         */
        //public override Record CloneViaReserialise()
        //{
        //    // Do it via a re-serialise
        //    // It's a cheat, but it works...
        //    byte[] b = this.Serialize();
        //    using (var ms = new System.IO.MemoryStream(b))
        //    {
        //        RecordInputStream rinp = new RecordInputStream(ms);
        //        rinp.NextRecord();

        //        Record[] r = RecordFactory.CreateRecord(rinp);
        //        if (r.Length != 1)
        //        {
        //            throw new InvalidOperationException("Re-serialised a record to Clone it, but got " + r.Length + " records back!");
        //        }
        //        return r[0];
        //    }
        //}

        public void AddEscherRecord(int index, EscherRecord element)
        {
            escherRecords.Insert(index, element);
        }
Example #18
0
 public MsofbtOPT(EscherRecord record)
     : base(record)
 {
 }
 public bool AddEscherRecord(EscherRecord element)
 {
     escherRecords.Add(element);
     return(true);
 }
 public MsofbtSelection(EscherRecord record)
     : base(record)
 {
 }
Example #21
0
        /**
         * Collapses the drawing records into an aggregate.
         */
        public static EscherAggregate CreateAggregate(IList records, int locFirstDrawingRecord, DrawingManager2 drawingManager)
        {
            // Keep track of any shape records Created so we can match them back to the object id's.
            // Textbox objects are also treated as shape objects.
            IList shapeRecords = new ArrayList();
            EscherRecordFactory recordFactory = new CustomEscherRecordFactory(ref shapeRecords);

            // Calculate the size of the buffer
            EscherAggregate agg      = new EscherAggregate(drawingManager);
            int             loc      = locFirstDrawingRecord;
            int             dataSize = 0;

            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                dataSize += ((DrawingRecord)records[loc]).Data.Length;
                loc      += 2;
            }

            // Create one big buffer
            byte[] buffer = new byte[dataSize];
            int    offset = 0;

            loc = locFirstDrawingRecord;
            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                DrawingRecord drawingRecord = (DrawingRecord)records[loc];
                Array.Copy(drawingRecord.Data, 0, buffer, offset, drawingRecord.Data.Length);
                offset += drawingRecord.Data.Length;
                loc    += 2;
            }

            // Decode the shapes
            //        agg.escherRecords = new ArrayList();
            int pos = 0;

            while (pos < dataSize)
            {
                EscherRecord r         = recordFactory.CreateRecord(buffer, pos);
                int          bytesRead = r.FillFields(buffer, pos, recordFactory);
                agg.AddEscherRecord(r);
                pos += bytesRead;
            }

            // Associate the object records with the shapes
            loc = locFirstDrawingRecord;
            int shapeIndex = 0;

            agg.shapeToObj = new Hashtable();
            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                Record objRecord = (Record)records[loc + 1];
                agg.shapeToObj[shapeRecords[shapeIndex++]] = objRecord;
                loc += 2;
            }

            return(agg);
        }
 public MsofbtDeletedPspl(EscherRecord record)
     : base(record)
 {
 }
Example #23
0
 void EscherSerializationListener.BeforeRecordSerialize(int Offset, short recordId, EscherRecord record)
 {
 }
 public MsofbtChildAnchor(EscherRecord record)
     : base(record)
 {
 }
Example #25
0
        /**
         * Serializes this aggregate to a byte array.  Since this Is an aggregate
         * record it will effectively Serialize the aggregated records.
         *
         * @param offset    The offset into the start of the array.
         * @param data      The byte array to Serialize to.
         * @return          The number of bytes Serialized.
         */
        public override int Serialize(int offset, byte [] data)
        {
            ConvertUserModelToRecords();

            // Determine buffer size
            IList records = EscherRecords;
            int   size    = GetEscherRecordSize(records);

            byte[] buffer = new byte[size];


            // Serialize escher records into one big data structure and keep note of ending offsets.
            spEndingOffsets = new ArrayList();
            shapes          = new ArrayList();
            int pos = 0;

            for (IEnumerator iterator = records.GetEnumerator(); iterator.MoveNext();)
            {
                EscherRecord e = (EscherRecord)iterator.Current;
                pos += e.Serialize(pos, buffer, new SerializationListener(ref spEndingOffsets, ref shapes));
            }
            // todo: fix this
            shapes.Insert(0, null);
            spEndingOffsets.Insert(0, null);

            // Split escher records into Separate MSODRAWING and OBJ, TXO records.  (We don't break on
            // the first one because it's the patriach).
            pos = offset;
            for (int i = 1; i < shapes.Count; i++)
            {
                int endOffset = (int)spEndingOffsets[i] - 1;
                int startOffset;
                if (i == 1)
                {
                    startOffset = 0;
                }
                else
                {
                    startOffset = (int)spEndingOffsets[i - 1];
                }

                // Create and Write a new MSODRAWING record
                DrawingRecord drawing     = new DrawingRecord();
                byte[]        drawingData = new byte[endOffset - startOffset + 1];
                Array.Copy(buffer, startOffset, drawingData, 0, drawingData.Length);
                drawing.Data = drawingData;
                int temp = drawing.Serialize(pos, data);
                pos += temp;

                // Write the matching OBJ record
                Record obj = (Record)shapeToObj[shapes[i]];
                temp = obj.Serialize(pos, data);
                pos += temp;
            }

            // Write records that need to be Serialized after all drawing Group records
            for (int i = 0; i < tailRec.Count; i++)
            {
                Record rec = (Record)tailRec[i];
                pos += rec.Serialize(pos, data);
            }

            int bytesWritten = pos - offset;

            if (bytesWritten != RecordSize)
            {
                throw new RecordFormatException(bytesWritten + " bytes written but RecordSize reports " + RecordSize);
            }
            return(bytesWritten);
        }
 public void BeforeRecordSerialize(int offset, short recordId, EscherRecord record)
 {
     // do nothing
 }
Example #27
0
 void EscherSerializationListener.AfterRecordSerialize(int Offset, short recordId, int size, EscherRecord record)
 {
     if (recordId == EscherClientDataRecord.RECORD_ID || recordId == EscherTextboxRecord.RECORD_ID)
     {
         spEndingOffsets.Add(Offset);
         shapes.Add(record);
     }
 }
 public MsofbtClientTextbox(EscherRecord record)
     : base(record)
 {
 }
Example #29
0
 /**
  * Associates an escher record to an OBJ record or a TXO record.
  */
 public Object AssoicateShapeToObjRecord(EscherRecord r, Record objRecord)
 {
     return(shapeToObj[r] = objRecord);
 }
 public MsofbtContainer(EscherRecord record)
     : base(record)
 {
 }
 public MsofbtColorMRU(EscherRecord record)
     : base(record)
 {
 }