Exemplo n.º 1
0
        public static Record CreateSubRecord(RecordInputStream in1)
        {
            Record r = null;

            /* This must surely be an earlier hack?? Delete when confident
            short adjustedSize = size;
            if ( size < 0 )
            {
                adjustedSize = 0;
            }
            else if ( offset + size > data.Length )
            {
                adjustedSize = (short) ( data.Length - offset );
                if ( adjustedSize > 4 )
                {
                    adjustedSize -= 4;
                }
            }
    */
            switch (in1.Sid)
            {
                case CommonObjectDataSubRecord.sid:
                    r = new CommonObjectDataSubRecord(in1);
                    break;
                case EmbeddedObjectRefSubRecord.sid:
                    r = new EmbeddedObjectRefSubRecord(in1);
                    break;
                case GroupMarkerSubRecord.sid:
                    r = new GroupMarkerSubRecord(in1);
                    break;
                case EndSubRecord.sid:
                    r = new EndSubRecord(in1);
                    break;
                case NoteStructureSubRecord.sid:
                    r = new NoteStructureSubRecord(in1);
                    break;
                default:
                    r = new UnknownRecord(in1);
                    break;
            }
            return r;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the lowerlevel OBJ records for this shape.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private ObjRecord CreateObjRecord(HSSFShape hssfShape, int shapeId)
        {
            HSSFShape shape = hssfShape;

            ObjRecord obj = new ObjRecord();
            CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();

            c.ObjectType  = (CommonObjectType)((HSSFSimpleShape)shape).ShapeType;
            c.ObjectId    = shapeId;
            c.IsLocked    = true;
            c.IsPrintable = true;
            c.IsAutoFill  = true;
            c.IsAutoline  = true;
            EndSubRecord e = new EndSubRecord();

            obj.AddSubRecord(c);
            obj.AddSubRecord(e);

            return(obj);
        }
Exemplo n.º 3
0
        protected override ObjRecord CreateObjRecord()
        {
            ObjRecord obj = new ObjRecord();
            CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();

            c.ObjectType  = CommonObjectType.COMBO_BOX;
            c.IsLocked    = (true);
            c.IsPrintable = (false);
            c.IsAutoFill  = (true);
            c.IsAutoline  = (false);
            FtCblsSubRecord  f = new FtCblsSubRecord();
            LbsDataSubRecord l = LbsDataSubRecord.CreateAutoFilterInstance();
            EndSubRecord     e = new EndSubRecord();

            obj.AddSubRecord(c);
            obj.AddSubRecord(f);
            obj.AddSubRecord(l);
            obj.AddSubRecord(e);
            return(obj);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the lowerlevel OBJ records for this shape.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private ObjRecord CreateObjRecord(HSSFShape hssfShape, int shapeId)
        {
            HSSFShape shape = hssfShape;

            ObjRecord obj = new ObjRecord();
            CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();

            c.ObjectType  = (CommonObjectType)OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING;
            c.ObjectId    = GetCmoObjectId(shapeId);
            c.IsLocked    = true;
            c.IsPrintable = true;
            c.IsAutoFill  = true;
            c.IsAutoline  = true;
            EndSubRecord e = new EndSubRecord();

            obj.AddSubRecord(c);
            obj.AddSubRecord(e);

            return(obj);
        }
Exemplo n.º 5
0
        /**
         * No NullPointerException should appear
         */
        public void TestDefaultSettingsWithEmptyContainer()
        {
            EscherContainerRecord Container = new EscherContainerRecord();
            EscherOptRecord       opt       = new EscherOptRecord();

            opt.RecordId = (EscherOptRecord.RECORD_ID);
            Container.AddChildRecord(opt);
            ObjRecord obj = new ObjRecord();
            CommonObjectDataSubRecord cod = new CommonObjectDataSubRecord();

            cod.ObjectType = (CommonObjectType)(HSSFSimpleShape.OBJECT_TYPE_PICTURE);
            obj.AddSubRecord(cod);
            HSSFPicture picture = new HSSFPicture(Container, obj);

            Assert.AreEqual(picture.LineWidth, HSSFShape.LINEWIDTH_DEFAULT);
            Assert.AreEqual(picture.FillColor, HSSFShape.FILL__FILLCOLOR_DEFAULT);
            Assert.AreEqual(picture.LineStyle, HSSFShape.LINESTYLE_DEFAULT);
            Assert.AreEqual(picture.LineStyleColor, HSSFShape.LINESTYLE__COLOR_DEFAULT);
            Assert.AreEqual(picture.IsNoFill, HSSFShape.NO_FILL_DEFAULT);
            Assert.AreEqual(picture.PictureIndex, -1);//not Set yet
        }
Exemplo n.º 6
0
        public void TestStore()
        {
            CommonObjectDataSubRecord record = new CommonObjectDataSubRecord();

            record.ObjectType  = (CommonObjectType.LIST_BOX);
            record.ObjectId    = ((short)1);
            record.Option      = ((short)1);
            record.IsLocked    = (true);
            record.IsPrintable = (false);
            record.IsAutoFill  = (false);
            record.IsAutoline  = (false);
            record.Reserved1   = ((int)24593);
            record.Reserved2   = ((int)218103808);
            record.Reserved3   = ((int)294);

            byte[] recordBytes = record.Serialize();
            Assert.AreEqual(recordBytes.Length - 4, data.Length);
            for (int i = 0; i < data.Length; i++)
            {
                Assert.AreEqual(data[i], recordBytes[i + 4], "At offset " + i);
            }
        }
Exemplo n.º 7
0
        /**
         * Creates the low level OBJ record for this shape.
         */
        private ObjRecord CreateObjRecord(HSSFSimpleShape shape, int shapeId)
        {
            ObjRecord obj = new ObjRecord();
            CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();

            c.ObjectType  = CommonObjectType.COMBO_BOX;
            c.ObjectId    = (short)shapeId;
            c.IsLocked    = (true);
            c.IsPrintable = false;
            c.IsAutoFill  = true;
            c.IsAutoline  = false;

            LbsDataSubRecord l = LbsDataSubRecord.CreateAutoFilterInstance();

            EndSubRecord e = new EndSubRecord();

            obj.AddSubRecord(c);
            obj.AddSubRecord(l);
            obj.AddSubRecord(e);

            return(obj);
        }
Exemplo n.º 8
0
        public void TestShapeId()
        {
            HSSFWorkbook  wb        = new HSSFWorkbook();
            HSSFSheet     sh        = wb.CreateSheet() as HSSFSheet;
            HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch;

            HSSFComment comment = patriarch.CreateCellComment(new HSSFClientAnchor()) as HSSFComment;

            comment.ShapeId = 2024;

            Assert.AreEqual(comment.ShapeId, 2024);

            CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord)comment.GetObjRecord().SubRecords[0];

            Assert.AreEqual(2024, cod.ObjectId);
            EscherSpRecord spRecord = (EscherSpRecord)comment.GetEscherContainer().GetChild(0);

            Assert.AreEqual(2024, spRecord.ShapeId);
            Assert.AreEqual(2024, comment.ShapeId);
            Assert.AreEqual(2024, comment.NoteRecord.ShapeId);

            wb.Close();
        }
Exemplo n.º 9
0
        /**
         * Adds a new OLE Package Shape
         *
         * @param anchor       the client anchor describes how this picture is
         *                     attached to the sheet.
         * @param storageId    the storageId returned by {@Link HSSFWorkbook.AddOlePackage}
         * @param pictureIndex the index of the picture (used as preview image) in the
         *                     workbook collection of pictures.
         *
         * @return newly Created shape
         */
        public HSSFObjectData CreateObjectData(HSSFClientAnchor anchor, int storageId, int pictureIndex)
        {
            ObjRecord obj = new ObjRecord();

            CommonObjectDataSubRecord ftCmo = new CommonObjectDataSubRecord();

            ftCmo.ObjectType = (/*setter*/ CommonObjectType.Picture);
            // ftCmo.ObjectId=(/*setter*/oleShape.ShapeId); ... will be Set by onCreate(...)
            ftCmo.IsLocked    = (/*setter*/ true);
            ftCmo.IsPrintable = (/*setter*/ true);
            ftCmo.IsAutoFill  = (/*setter*/ true);
            ftCmo.IsAutoline  = (/*setter*/ true);
            ftCmo.Reserved1   = (/*setter*/ 0);
            ftCmo.Reserved2   = (/*setter*/ 0);
            ftCmo.Reserved3   = (/*setter*/ 0);
            obj.AddSubRecord(ftCmo);

            // FtCf (pictFormat)
            FtCfSubRecord   ftCf     = new FtCfSubRecord();
            HSSFPictureData pictData = Sheet.Workbook.GetAllPictures()[(pictureIndex - 1)] as HSSFPictureData;

            switch ((PictureType)pictData.Format)
            {
            case PictureType.WMF:
            case PictureType.EMF:
                // this needs patch #49658 to be applied to actually work
                ftCf.Flags = (/*setter*/ FtCfSubRecord.METAFILE_BIT);
                break;

            case PictureType.DIB:
            case PictureType.PNG:
            case PictureType.JPEG:
            case PictureType.PICT:
                ftCf.Flags = (/*setter*/ FtCfSubRecord.BITMAP_BIT);
                break;
            }
            obj.AddSubRecord(ftCf);
            // FtPioGrbit (pictFlags)
            FtPioGrbitSubRecord ftPioGrbit = new FtPioGrbitSubRecord();

            ftPioGrbit.SetFlagByBit(FtPioGrbitSubRecord.AUTO_PICT_BIT, true);
            obj.AddSubRecord(ftPioGrbit);

            EmbeddedObjectRefSubRecord ftPictFmla = new EmbeddedObjectRefSubRecord();

            ftPictFmla.SetUnknownFormulaData(new byte[] { 2, 0, 0, 0, 0 });
            ftPictFmla.OLEClassName = (/*setter*/ "Paket");
            ftPictFmla.SetStorageId(storageId);

            obj.AddSubRecord(ftPictFmla);
            obj.AddSubRecord(new EndSubRecord());

            String         entryName = "MBD" + HexDump.ToHex(storageId);
            DirectoryEntry oleRoot;

            try
            {
                DirectoryNode dn = (_sheet.Workbook as HSSFWorkbook).RootDirectory;
                if (dn == null)
                {
                    throw new FileNotFoundException();
                }
                oleRoot = (DirectoryEntry)dn.GetEntry(entryName);
            }
            catch (FileNotFoundException e)
            {
                throw new InvalidOperationException("trying to add ole shape without actually Adding data first - use HSSFWorkbook.AddOlePackage first", e);
            }

            // create picture shape, which need to be minimal modified for oleshapes
            HSSFPicture shape = new HSSFPicture(null, anchor);

            shape.PictureIndex = (/*setter*/ pictureIndex);
            EscherContainerRecord spContainer = shape.GetEscherContainer();
            EscherSpRecord        spRecord    = spContainer.GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord;

            spRecord.Flags = (/*setter*/ spRecord.Flags | EscherSpRecord.FLAG_OLESHAPE);

            HSSFObjectData oleShape = new HSSFObjectData(spContainer, obj, oleRoot);

            AddShape(oleShape);
            OnCreate(oleShape);


            return(oleShape);
        }
Exemplo n.º 10
0
        /**
         * build shape tree from escher container
         * @param container root escher container from which escher records must be taken
         * @param agg - EscherAggregate
         * @param out - shape container to which shapes must be added
         * @param root - node to create HSSFObjectData shapes
         */

        public static void CreateShapeTree(EscherContainerRecord container, EscherAggregate agg,
                                           HSSFShapeContainer out1, DirectoryNode root)
        {
            if (container.RecordId == EscherContainerRecord.SPGR_CONTAINER)
            {
                ObjRecord obj = null;
                EscherClientDataRecord clientData = (EscherClientDataRecord)((EscherContainerRecord)container.GetChild(0)).GetChildById(EscherClientDataRecord.RECORD_ID);
                if (null != clientData)
                {
                    obj = (ObjRecord)agg.GetShapeToObjMapping()[clientData];
                }
                HSSFShapeGroup group = new HSSFShapeGroup(container, obj);
                IList <EscherContainerRecord> children = container.ChildContainers;
                // skip the first child record, it is group descriptor
                for (int i = 0; i < children.Count; i++)
                {
                    EscherContainerRecord spContainer = children[(i)];
                    if (i != 0)
                    {
                        CreateShapeTree(spContainer, agg, group, root);
                    }
                }
                out1.AddShape(group);
            }
            else if (container.RecordId == EscherContainerRecord.SP_CONTAINER)
            {
                Dictionary <EscherRecord, Record.Record> shapeToObj = agg.GetShapeToObjMapping();
                ObjRecord        objRecord = null;
                TextObjectRecord txtRecord = null;

                foreach (EscherRecord record in container.ChildRecords)
                {
                    switch (record.RecordId)
                    {
                    case EscherClientDataRecord.RECORD_ID:
                        objRecord = (ObjRecord)shapeToObj[(record)];
                        break;

                    case EscherTextboxRecord.RECORD_ID:
                        txtRecord = (TextObjectRecord)shapeToObj[(record)];
                        break;
                    }
                }
                if (IsEmbeddedObject(objRecord))
                {
                    HSSFObjectData objectData = new HSSFObjectData(container, objRecord, root);
                    out1.AddShape(objectData);
                    return;
                }
                CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord)objRecord.SubRecords[0];
                HSSFShape shape;
                switch (cmo.ObjectType)
                {
                case CommonObjectType.Picture:
                    shape = new HSSFPicture(container, objRecord);
                    break;

                case CommonObjectType.Rectangle:
                    shape = new HSSFSimpleShape(container, objRecord, txtRecord);
                    break;

                case CommonObjectType.Line:
                    shape = new HSSFSimpleShape(container, objRecord);
                    break;

                case CommonObjectType.ComboBox:
                    shape = new HSSFCombobox(container, objRecord);
                    break;

                case CommonObjectType.MicrosoftOfficeDrawing:
                    EscherOptRecord optRecord = (EscherOptRecord)container.GetChildById(EscherOptRecord.RECORD_ID);
                    EscherProperty  property  = optRecord.Lookup(EscherProperties.GEOMETRY__VERTICES);
                    if (null != property)
                    {
                        shape = new HSSFPolygon(container, objRecord, txtRecord);
                    }
                    else
                    {
                        shape = new HSSFSimpleShape(container, objRecord, txtRecord);
                    }
                    break;

                case CommonObjectType.Text:
                    shape = new HSSFTextbox(container, objRecord, txtRecord);
                    break;

                case CommonObjectType.Comment:
                    shape = new HSSFComment(container, objRecord, txtRecord, agg.GetNoteRecordByObj(objRecord));
                    break;

                default:
                    shape = new HSSFSimpleShape(container, objRecord, txtRecord);
                    break;
                }
                out1.AddShape(shape);
            }
        }