예제 #1
0
 void EscherSerializationListener.AfterRecordSerialize(int offset, short recordId, int size, EscherRecord record)
 {
     if (recordId == EscherClientDataRecord.RECORD_ID || recordId == EscherTextboxRecord.RECORD_ID)
     {
         spEndingOffsets.Add(offset);
     }
 }
예제 #2
0
        public EscherRecordTreeNode(EscherRecord record)
        {
            this.Record = record;
            this.Text = record.GetType().Name;
            if(record.ChildRecords.Count>0)
                this.ImageKey = "Folder";
            else
                this.ImageKey = "Binary";

            if (record is AbstractEscherOptRecord)
            {
                AbstractEscherOptRecord rec = ((AbstractEscherOptRecord)record);
                foreach (EscherProperty ep in rec.EscherProperties )
                {
                    EscherPropertyTreeNode cnode = new EscherPropertyTreeNode(ep);
                    this.Nodes.Add(cnode);
                }
            }
            else
            {
                GetChildren(this);
            }
        }
예제 #3
0
 public SerializationListener(IList<int> spEndingOffsets, IList<EscherRecord> records, EscherRecord e)
 {
     this.spEndingOffsets = spEndingOffsets;
     this.records = records;
     this.record = e;
 }
예제 #4
0
 /// <summary>
 /// Remove echerRecord and associated to it Obj or TextObj record
 /// </summary>
 /// <param name="rec">clientData or textbox record to be removed</param>
 public void RemoveShapeToObjRecord(EscherRecord rec)
 {
     shapeToObj.Remove(rec);
 }
예제 #5
0
 public bool RemoveChildRecord(EscherRecord toBeRemoved)
 {
     return(_childRecords.Remove(toBeRemoved));
 }
        /**
 * 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);
        }
예제 #7
0
 private void GetSheetImageIds(EscherRecord parent, List<int> usedIds)
 {
     foreach (EscherRecord child in parent.ChildRecords)
     {
         if (child is EscherOptRecord)
         {
             EscherOptRecord picOpts = (EscherOptRecord)child;
             foreach (EscherProperty eprop in picOpts.EscherProperties)
             {
                 if (eprop.PropertyNumber == EscherProperties.BLIP__BLIPTODISPLAY)
                 {
                     //This is the picture ID property
                     int pictureId = ((EscherSimpleProperty) eprop).PropertyValue;
                     if (!usedIds.Contains(pictureId))
                     {
                         usedIds.Add(pictureId);
                     }
                     break;
                 }
             }
         }
         if (child.ChildRecords.Count > 0)
         {
             foreach (EscherRecord grandKid in child.ChildRecords)
             {
                 GetSheetImageIds(grandKid, usedIds);
             }
         }
     }
 }
예제 #8
0
 public bool RemoveChildRecord(EscherRecord toBeRemoved)
 {
     return childRecords.Remove(toBeRemoved);
 }
예제 #9
0
 public void BeforeRecordSerialize(int offset, short recordId, EscherRecord record)
 {
     // do nothing
 }
예제 #10
0
        /// <summary>
        /// Generates an escher record including the any children contained under that record.
        /// An exception is thrown if the record could not be generated.
        /// </summary>
        /// <param name="data">The byte array containing the records</param>
        /// <param name="offset">The starting offset into the byte array</param>
        /// <returns>The generated escher record</returns>
        public virtual EscherRecord CreateRecord(byte[] data, int offset)
        {
            short options  = LittleEndian.GetShort(data, offset);
            short recordId = LittleEndian.GetShort(data, offset + 2);

            // int remainingBytes = LittleEndian.getInt( data, offset + 4 );
            // Options of 0x000F means container record
            // However, EscherTextboxRecord are containers of records for the
            //  host application, not of other Escher records, so treat them
            //  differently
            if (IsContainer(options, recordId))
            {
                EscherContainerRecord r = new EscherContainerRecord();
                r.RecordId = recordId;
                r.Options  = options;
                return(r);
            }
            if (recordId >= EscherBlipRecord.RECORD_ID_START && recordId <= EscherBlipRecord.RECORD_ID_END)
            {
                EscherBlipRecord r;
                if (recordId == EscherBitmapBlip.RECORD_ID_DIB ||
                    recordId == EscherBitmapBlip.RECORD_ID_JPEG ||
                    recordId == EscherBitmapBlip.RECORD_ID_PNG)
                {
                    r = new EscherBitmapBlip();
                }
                //ZIP
                //else if (recordId == EscherMetafileBlip.RECORD_ID_EMF ||
                //        recordId == EscherMetafileBlip.RECORD_ID_WMF ||
                //        recordId == EscherMetafileBlip.RECORD_ID_PICT)
                //{
                //    r = new EscherMetafileBlip();
                //}
                else
                {
                    r = new EscherBlipRecord();
                }
                r.RecordId = recordId;
                r.Options  = options;
                return(r);
            }

            //ConstructorInfo recordConstructor = (ConstructorInfo) recordsMap[header.RecordId];
            ConstructorInfo recordConstructor = null;

            if (recordsMap.ContainsKey(recordId))
            {
                recordConstructor = recordsMap[recordId];
            }

            EscherRecord escherRecord = null;

            if (recordConstructor == null)
            {
                return(new UnknownEscherRecord());
            }

            try
            {
                escherRecord = (EscherRecord)recordConstructor.Invoke(new object[] { });
                //escherRecord = (EscherRecord)Activator.CreateInstance(recordConstructor);
            }
            catch (Exception)
            {
                return(new UnknownEscherRecord());
            }
            escherRecord.RecordId = recordId;
            escherRecord.Options  = options;
            return(escherRecord);
        }
예제 #11
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 void BeforeRecordSerialize(int offset, short recordId, EscherRecord record)
 {
     // do nothing
 }
 public void AfterRecordSerialize(int offset, short recordId, int size, EscherRecord record)
 {
     // do nothing
 }
예제 #14
0
 /// <summary>
 /// Adds the child record.
 /// </summary>
 /// <param name="childRecord">The child record.</param>
 public void AddChildRecord(EscherRecord childRecord)
 {
     ChildRecords.Add(childRecord);
 }
예제 #15
0
 /// <summary>
 /// Adds the child record.
 /// </summary>
 /// <param name="record">The record.</param>
 public void AddChildRecord(EscherRecord record)
 {
     this.childRecords.Add(record);
 }
예제 #16
0
 public RecordSizeListener(IList<int> spEndingOffsets, EscherRecord e)
 {
     this.spEndingOffsets = spEndingOffsets;
     this.record = e;
 }
예제 #17
0
        void EscherSerializationListener.BeforeRecordSerialize(int offset, short recordId, EscherRecord record)
        {

        }
예제 #18
0
 public void AfterRecordSerialize(int offset, short recordId, int size, EscherRecord record)
 {
     // do nothing
 }
예제 #19
0
        /// <summary>
        /// Generates an escher record including the any children contained under that record.
        /// An exception is thrown if the record could not be generated.
        /// </summary>
        /// <param name="data">The byte array containing the records</param>
        /// <param name="offset">The starting offset into the byte array</param>
        /// <returns>The generated escher record</returns>
        public virtual EscherRecord CreateRecord(byte[] data, int offset)
        {
            EscherRecord.EscherRecordHeader header = EscherRecord.EscherRecordHeader.ReadHeader(data, offset);

            // Options of 0x000F means container record
            // However, EscherTextboxRecord are containers of records for the
            //  host application, not of other Escher records, so treat them
            //  differently
            if ((header.Options & (short)0x000F) == (short)0x000F &&
                header.RecordId != EscherTextboxRecord.RECORD_ID)
            {
                EscherContainerRecord r = new EscherContainerRecord();
                r.RecordId = header.RecordId;
                r.Options  = header.Options;
                return(r);
            }
            else if (header.RecordId >= EscherBlipRecord.RECORD_ID_START && header.RecordId <= EscherBlipRecord.RECORD_ID_END)
            {
                EscherBlipRecord r;
                if (header.RecordId == EscherBitmapBlip.RECORD_ID_DIB ||
                    header.RecordId == EscherBitmapBlip.RECORD_ID_JPEG ||
                    header.RecordId == EscherBitmapBlip.RECORD_ID_PNG)
                {
                    r = new EscherBitmapBlip();
                }
                else if (header.RecordId == EscherMetafileBlip.RECORD_ID_EMF ||
                         header.RecordId == EscherMetafileBlip.RECORD_ID_WMF ||
                         header.RecordId == EscherMetafileBlip.RECORD_ID_PICT)
                {
                    r = new EscherMetafileBlip();
                }
                else
                {
                    r = new EscherBlipRecord();
                }
                r.RecordId = header.RecordId;
                r.Options  = header.Options;
                return(r);
            }
            else
            {
                //ConstructorInfo recordConstructor = (ConstructorInfo) recordsMap[header.RecordId];
                Type         record       = (Type)recordsMap[header.RecordId];
                EscherRecord escherRecord = null;
                //if ( recordConstructor != null )
                if (record != null)
                {
                    try
                    {
                        escherRecord          = (EscherRecord)Activator.CreateInstance(record);
                        escherRecord.RecordId = header.RecordId;
                        escherRecord.Options  = header.Options;
                    }
                    catch (Exception)
                    {
                        escherRecord = null;
                    }
                }
                return(escherRecord == null ? new UnknownEscherRecord() : escherRecord);
            }
        }
 /// <summary>
 /// Adds the child record.
 /// </summary>
 /// <param name="childRecord">The child record.</param>
 public void AddChildRecord(EscherRecord childRecord)
 {
     ChildRecords.Add(childRecord);
 }
예제 #21
0
 /// <summary>
 /// Adds the child record.
 /// </summary>
 /// <param name="record">The record.</param>
 public void AddChildRecord(EscherRecord record)
 {
     this.childRecords.Add(record);
 }
 public int AddEscherRecord(EscherRecord element)
 {
     return escherRecords.Add(element);
 }
예제 #23
0
 private void ApplyEscherRemap(EscherRecord parent, Dictionary<int,int> mappings)
 {
     foreach (EscherRecord child in parent.ChildRecords)
     {
         if (child is EscherOptRecord)
         {
             EscherOptRecord picOpts = (EscherOptRecord)child;
             foreach (EscherProperty eprop in picOpts.EscherProperties)
             {
                 if (eprop.PropertyNumber == EscherProperties.BLIP__BLIPTODISPLAY)
                 {
                     //This is the picture ID property
                     int pictureId = ((EscherSimpleProperty)eprop).PropertyValue;
                     if (mappings.ContainsKey(pictureId))
                     {
                         ((EscherSimpleProperty) eprop).PropertyValue = mappings[pictureId];
                     }
                     break;
                 }
             }
         }
         if (child.ChildRecords.Count > 0)
         {
             foreach (EscherRecord grandKid in child.ChildRecords)
             {
                 ApplyEscherRemap(grandKid, mappings);
             }
         }
     }
 }
예제 #24
0
        //private void ConvertShapes(HSSFShapeContainer parent, EscherContainerRecord escherParent, Hashtable shapeToObj)
        //{
        //    if (escherParent == null) throw new ArgumentException("Parent record required");

        //    IList<HSSFShape> shapes = parent.Children;
        //    for (IEnumerator iterator = shapes.GetEnumerator(); iterator.MoveNext(); )
        //    {
        //        HSSFShape shape = (HSSFShape)iterator.Current;
        //        if (shape is HSSFShapeGroup)
        //        {
        //            ConvertGroup((HSSFShapeGroup)shape, escherParent, shapeToObj);
        //        }
        //        else
        //        {
        //            AbstractShape shapeModel = AbstractShape.CreateShape(
        //                    shape,
        //                    drawingManager.AllocateShapeId(drawingGroupId));
        //            shapeToObj[FindClientData(shapeModel.SpContainer)]=shapeModel.ObjRecord;
        //            if (shapeModel is TextboxShape)
        //            {
        //                EscherRecord escherTextbox = ((TextboxShape)shapeModel).EscherTextbox;
        //                shapeToObj[escherTextbox]=((TextboxShape)shapeModel).TextObjectRecord;
        //                //                    escherParent.AddChildRecord(escherTextbox);

        //                if (shapeModel is CommentShape)
        //                {
        //                    CommentShape comment = (CommentShape)shapeModel;
        //                    tailRec.Add(comment.NoteRecord.ShapeId,comment.NoteRecord);
        //                }
        //            }
        //            escherParent.AddChildRecord(shapeModel.SpContainer);
        //        }
        //    }
        //    //        drawingManager.newCluster( (short)1 );
        //    //        drawingManager.newCluster( (short)2 );

        //}

        //private void ConvertGroup(HSSFShapeGroup shape, EscherContainerRecord escherParent, Hashtable shapeToObj)
        //{
        //    EscherContainerRecord spgrContainer = new EscherContainerRecord();
        //    EscherContainerRecord spContainer = new EscherContainerRecord();
        //    EscherSpgrRecord spgr = new EscherSpgrRecord();
        //    EscherSpRecord sp = new EscherSpRecord();
        //    EscherOptRecord opt = new EscherOptRecord();
        //    EscherRecord anchor;
        //    EscherClientDataRecord clientData = new EscherClientDataRecord();

        //    spgrContainer.RecordId = EscherContainerRecord.SPGR_CONTAINER;
        //    spgrContainer.Options = (short)0x000F;
        //    spContainer.RecordId = EscherContainerRecord.SP_CONTAINER;
        //    spContainer.Options = (short)0x000F;
        //    spgr.RecordId = EscherSpgrRecord.RECORD_ID;
        //    spgr.Options = (short)0x0001;
        //    spgr.RectX1 = shape.X1;
        //    spgr.RectY1 = shape.Y1;
        //    spgr.RectX2 = shape.X2;
        //    spgr.RectY2 = shape.Y2;
        //    sp.RecordId = EscherSpRecord.RECORD_ID;
        //    sp.Options = (short)0x0002;
        //    int shapeId = drawingManager.AllocateShapeId(drawingGroupId);
        //    sp.ShapeId = shapeId;
        //    if (shape.Anchor is HSSFClientAnchor)
        //        sp.Flags = EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR;
        //    else
        //        sp.Flags = EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_CHILD;
        //    opt.RecordId = EscherOptRecord.RECORD_ID;
        //    opt.Options = (short)0x0023;
        //    opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00040004));
        //    opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000));

        //    anchor = ConvertAnchor.CreateAnchor(shape.Anchor);
        //    //        clientAnchor.Col1( ( (HSSFClientAnchor) shape.Anchor ).Col1 );
        //    //        clientAnchor.Row1( (short) ( (HSSFClientAnchor) shape.Anchor ).Row1 );
        //    //        clientAnchor.Dx1( (short) shape.Anchor.Dx1 );
        //    //        clientAnchor.Dy1( (short) shape.Anchor.Dy1 );
        //    //        clientAnchor.Col2( ( (HSSFClientAnchor) shape.Anchor ).Col2 );
        //    //        clientAnchor.Row2( (short) ( (HSSFClientAnchor) shape.Anchor ).Row2 );
        //    //        clientAnchor.Dx2( (short) shape.Anchor.Dx2 );
        //    //        clientAnchor.Dy2( (short) shape.Anchor.Dy2 );
        //    clientData.RecordId = (EscherClientDataRecord.RECORD_ID);
        //    clientData.Options = ((short)0x0000);

        //    spgrContainer.AddChildRecord(spContainer);
        //    spContainer.AddChildRecord(spgr);
        //    spContainer.AddChildRecord(sp);
        //    spContainer.AddChildRecord(opt);
        //    spContainer.AddChildRecord(anchor);
        //    spContainer.AddChildRecord(clientData);

        //    ObjRecord obj = new ObjRecord();
        //    CommonObjectDataSubRecord cmo = new CommonObjectDataSubRecord();
        //    cmo.ObjectType = CommonObjectType.GROUP;
        //    cmo.ObjectId = shapeId;
        //    cmo.IsLocked = true;
        //    cmo.IsPrintable = true;
        //    cmo.IsAutoFill = true;
        //    cmo.IsAutoline = true;
        //    GroupMarkerSubRecord gmo = new GroupMarkerSubRecord();
        //    EndSubRecord end = new EndSubRecord();
        //    obj.AddSubRecord(cmo);
        //    obj.AddSubRecord(gmo);
        //    obj.AddSubRecord(end);
        //    shapeToObj[clientData] = obj;

        //    escherParent.AddChildRecord(spgrContainer);

        //    ConvertShapes(shape, spgrContainer, shapeToObj);

        //}

        //private EscherRecord FindClientData(EscherContainerRecord spContainer)
        //{
        //    for (IEnumerator iterator = spContainer.ChildRecords.GetEnumerator(); iterator.MoveNext(); )
        //    {
        //        EscherRecord r = (EscherRecord)iterator.Current;
        //        if (r.RecordId == EscherClientDataRecord.RECORD_ID)
        //            return r;
        //    }
        //    throw new ArgumentException("Can not Find client data record");
        //}

        //private void ConvertPatriarch(HSSFPatriarch patriarch)
        //{
        //    EscherContainerRecord dgContainer = new EscherContainerRecord();
        //    EscherDgRecord dg;
        //    EscherContainerRecord spgrContainer = new EscherContainerRecord();
        //    EscherContainerRecord spContainer1 = new EscherContainerRecord();
        //    EscherSpgrRecord spgr = new EscherSpgrRecord();
        //    EscherSpRecord sp1 = new EscherSpRecord();

        //    dgContainer.RecordId=EscherContainerRecord.DG_CONTAINER;
        //    dgContainer.Options=(short)0x000F;
        //    dg = drawingManager.CreateDgRecord();
        //    drawingGroupId = dg.DrawingGroupId;
        //    //        dg.Options( (short) ( drawingId << 4 ) );
        //    //        dg.NumShapes( GetNumberOfShapes( patriarch ) );
        //    //        dg.LastMSOSPID( 0 );  // populated after all shape id's are assigned.
        //    spgrContainer.RecordId=EscherContainerRecord.SPGR_CONTAINER;
        //    spgrContainer.Options=(short)0x000F;
        //    spContainer1.RecordId=EscherContainerRecord.SP_CONTAINER;
        //    spContainer1.Options=(short)0x000F;
        //    spgr.RecordId=EscherSpgrRecord.RECORD_ID;
        //    spgr.Options=(short)0x0001;    // version
        //    spgr.RectX1=patriarch.X1;
        //    spgr.RectY1=patriarch.Y1;
        //    spgr.RectX2=patriarch.X2;
        //    spgr.RectY2=patriarch.Y2;
        //    sp1.RecordId=EscherSpRecord.RECORD_ID;
        //    sp1.Options=(short)0x0002;
        //    sp1.ShapeId=drawingManager.AllocateShapeId(dg.DrawingGroupId);
        //    sp1.Flags=EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_PATRIARCH;

        //    dgContainer.AddChildRecord(dg);
        //    dgContainer.AddChildRecord(spgrContainer);
        //    spgrContainer.AddChildRecord(spContainer1);
        //    spContainer1.AddChildRecord(spgr);
        //    spContainer1.AddChildRecord(sp1);

        //    AddEscherRecord(dgContainer);
        //}

        //private static short GetSid(IList records, int loc)
        //{
        //    return ((Record)records[loc]).Sid;
        //}
        /// <summary>
        /// Associates an escher record to an OBJ record or a TXO record.
        /// </summary>
        /// <param name="r">ClientData or Textbox record</param>
        /// <param name="objRecord">Obj or TextObj record</param>
        public void AssociateShapeToObjRecord(EscherRecord r, Record objRecord)
        {
            if(!shapeToObj.ContainsKey(r))
                shapeToObj.Add(r, objRecord);
            else
                shapeToObj[r]= objRecord;
        }
예제 #25
0
 public bool AddEscherRecord(EscherRecord element)
 {
     escherRecords.Add(element);
     return true;
 }
예제 #26
0
 public void AddChildBefore(EscherRecord record, int insertBeforeRecordId)
 {
     for (int i = 0; i < _childRecords.Count; i++)
     {
         EscherRecord rec = _childRecords[(i)];
         if (rec.RecordId == insertBeforeRecordId)
         {
             _childRecords.Insert(i++, record);
             // TODO - keep looping? Do we expect multiple matches?
         }
     }
 }