Exemple #1
0
 public HSSFClientAnchor(EscherClientAnchorRecord escherClientAnchorRecord)
 {
     this._escherClientAnchor = escherClientAnchorRecord;
 }
Exemple #2
0
 protected override void CreateEscherAnchor()
 {
     _escherClientAnchor = new EscherClientAnchorRecord();
 }
Exemple #3
0
    /**
     * Create a new ShapeGroup and create an instance of <code>EscherSpgrContainer</code> which represents a group of shapes
     */
    protected EscherContainerRecord CreateSpContainer(bool IsChild) {
        EscherContainerRecord spgr = new EscherContainerRecord();
        spgr.SetRecordId(EscherContainerRecord.SPGR_CONTAINER);
        spgr.SetOptions((short)15);

        //The group itself is a shape, and always appears as the first EscherSpContainer in the group Container.
        EscherContainerRecord spcont = new EscherContainerRecord();
        spcont.SetRecordId(EscherContainerRecord.SP_CONTAINER);
        spcont.SetOptions((short)15);

        EscherSpgrRecord spg = new EscherSpgrRecord();
        spg.SetOptions((short)1);
        spcont.AddChildRecord(spg);

        EscherSpRecord sp = new EscherSpRecord();
        short type = (ShapeTypes.NotPrimitive << 4) + 2;
        sp.SetOptions(type);
        sp.SetFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_GROUP);
        spcont.AddChildRecord(sp);

        EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
        spcont.AddChildRecord(anchor);

        spgr.AddChildRecord(spcont);
        return spgr;
    }
Exemple #4
0
 /// <summary>
 /// Creates a new client anchor and defaults all the anchor positions to 0.
 /// </summary>
 public HSSFClientAnchor()
 {
     //Is this necessary?
     this._escherClientAnchor = new EscherClientAnchorRecord();
 }
Exemple #5
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);
                }
            }
        }
Exemple #6
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!");
        }