Exemplo n.º 1
0
 /// <summary>
 /// Create a new textbox Under this Group.
 /// </summary>
 /// <param name="anchor">the position of the shape.</param>
 /// <returns>the textbox</returns>
 public HSSFTextbox CreateTextbox(HSSFChildAnchor anchor)
 {
     HSSFTextbox shape = new HSSFTextbox(this, anchor);
     shape.Anchor = anchor;
     shapes.Add(shape);
     return shape;
 }
Exemplo n.º 2
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(HSSFTextbox hssfShape, int shapeId)
        {
            HSSFTextbox shape = hssfShape;

            EscherContainerRecord spContainer = new EscherContainerRecord();
            EscherSpRecord sp = new EscherSpRecord();
            EscherOptRecord opt = new EscherOptRecord();
            EscherRecord anchor = new EscherClientAnchorRecord();
            EscherClientDataRecord clientData = new EscherClientDataRecord();
            escherTextbox = new EscherTextboxRecord();

            spContainer.RecordId=EscherContainerRecord.SP_CONTAINER;
            spContainer.Options=(short)0x000F;
            sp.RecordId=EscherSpRecord.RECORD_ID;
            sp.Options=(short)((EscherAggregate.ST_TEXTBOX << 4) | 0x2);

            sp.ShapeId=shapeId;
            sp.Flags=EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
            opt.RecordId=EscherOptRecord.RECORD_ID;
            //        opt.AddEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144 ) );
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTLEFT, shape.MarginLeft));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTRIGHT, shape.MarginRight));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTBOTTOM, shape.MarginBottom));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTTOP, shape.MarginTop));

            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__WRAPTEXT, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__ANCHORTEXT, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000));

            AddStandardOptions(shape, opt);
            HSSFAnchor userAnchor = shape.Anchor;
            //        if (userAnchor.IsHorizontallyFlipped())
            //            sp.Flags(sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ);
            //        if (userAnchor.IsVerticallyFlipped())
            //            sp.Flags(sp.Flags | EscherSpRecord.FLAG_FLIPVERT);
            anchor = CreateAnchor(userAnchor);
            clientData.RecordId=EscherClientDataRecord.RECORD_ID;
            clientData.Options=(short)0x0000;
            escherTextbox.RecordId=EscherTextboxRecord.RECORD_ID;
            escherTextbox.Options=(short)0x0000;

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

            return spContainer;
        }
Exemplo n.º 3
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(HSSFTextbox hssfShape, int shapeId)
        {
            HSSFShape shape = hssfShape;

            ObjRecord obj = new ObjRecord();
            CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
            c.ObjectType = (CommonObjectType)((HSSFSimpleShape)shape).ShapeType;
            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.º 4
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!");
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates the low evel records for a textbox.
 /// </summary>
 /// <param name="hssfShape">The highlevel shape.</param>
 /// <param name="shapeId">The shape id to use for this shape.</param>
 public TextboxShape(HSSFTextbox hssfShape, int shapeId)
 {
     spContainer = CreateSpContainer(hssfShape, shapeId);
     objRecord = CreateObjRecord(hssfShape, shapeId);
     textObjectRecord = CreateTextObjectRecord(hssfShape, shapeId);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Textboxes also have an extra TXO record associated with them that most
        /// other shapes dont have.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private TextObjectRecord CreateTextObjectRecord(HSSFTextbox hssfShape, int shapeId)
        {
            HSSFTextbox shape = hssfShape;

            TextObjectRecord obj = new TextObjectRecord();
            obj.HorizontalTextAlignment=(int)hssfShape.HorizontalAlignment;
            obj.VerticalTextAlignment=(int)hssfShape.VerticalAlignment;
            obj.IsTextLocked=true;
            obj.TextOrientation=TextObjectRecord.TEXT_ORIENTATION_NONE;
            int frLength = (shape.String.NumFormattingRuns + 1) * 8;
            obj.Str=shape.String;

            return obj;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Constructs a textbox Under the patriarch.
 /// </summary>
 /// <param name="anchor">the client anchor describes how this Group is attached
 /// to the sheet.</param>
 /// <returns>the newly Created textbox.</returns>
 public HSSFSimpleShape CreateTextbox(IClientAnchor anchor)
 {
     HSSFTextbox shape = new HSSFTextbox(null, (HSSFAnchor)anchor);
     shape.Anchor = (HSSFAnchor)anchor;
     AddShape(shape);
     return shape;
 }