Example #1
0
        private void checkHeaderFooter(ShapeTreeMapping stm)
        {
            var slideAtom = this.Note.FirstChildWithType <NotesAtom>();

            string footertext     = "";
            string headertext     = "";
            string userdatetext   = "";
            var    headersfooters = this.Note.FirstChildWithType <SlideHeadersFootersContainer>();

            if (headersfooters != null)
            {
                foreach (var text in headersfooters.AllChildrenWithType <CStringAtom>())
                {
                    switch (text.Instance)
                    {
                    case 0:
                        userdatetext = text.Text;
                        break;

                    case 1:
                        headertext = text.Text;
                        break;

                    case 2:
                        footertext = text.Text;
                        break;
                    }
                }
                //CStringAtom text = headersfooters.FirstChildWithType<CStringAtom>();
                //if (text != null)
                //{
                //    footertext = text.Text;
                //}
            }

            bool footer = false;
            //bool header = false;
            bool slideNumber = false;

            //bool date = false;
            //bool userDate = false;

            foreach (var c in this._ctx.Ppt.DocumentRecord.AllChildrenWithType <SlideHeadersFootersContainer>())
            {
                switch (c.Instance)
                {
                case 0:     //PerSlideHeadersFootersContainer
                    break;

                case 3:     //SlideHeadersFootersContainer
                    break;

                case 4:     //NotesHeadersFootersContainer
                    foreach (var a in c.AllChildrenWithType <HeadersFootersAtom>())
                    {
                        if (a.fHasFooter)
                        {
                            footer = true;
                        }
                        //if (a.fHasHeader) header = true;
                        if (a.fHasSlideNumber)
                        {
                            slideNumber = true;
                        }
                        //if (a.fHasDate) date = true;
                        //if (a.fHasUserDate) userDate = true;
                    }
                    break;
                }
            }

            var master = this._ctx.Ppt.NotesMasterRecords[0];

            if (slideNumber)
            {
                //foreach (Slide master in this._ctx.Ppt.MainMasterRecords)
                //{
                //if (master.PersistAtom.SlideId == slideAtom.MasterId)
                //{
                var shapes = master.AllChildrenWithType <PPDrawing>()[0].AllChildrenWithType <OfficeDrawing.DrawingContainer>()[0].AllChildrenWithType <OfficeDrawing.GroupContainer>()[0].AllChildrenWithType <OfficeDrawing.ShapeContainer>();
                foreach (var shapecontainer in shapes)
                {
                    foreach (var data in shapecontainer.AllChildrenWithType <OfficeDrawing.ClientData>())
                    {
                        var ms  = new System.IO.MemoryStream(data.bytes);
                        var rec = OfficeDrawing.Record.ReadRecord(ms);

                        if (rec.TypeCode == 3011)
                        {
                            var placeholder = (OEPlaceHolderAtom)rec;

                            if (placeholder != null)
                            {
                                if (placeholder.PlacementId == PlaceholderEnum.MasterSlideNumber)
                                {
                                    stm.Apply(shapecontainer, "", "", "");
                                }
                            }
                        }
                    }
                }

                //}
                //}
            }

            //if (date)
            //{
            //if (!(userDate & userdatetext.Length == 0))
            //    {
            //    foreach (Slide master in this._ctx.Ppt.MainMasterRecords)
            //    {
            //        if (master.PersistAtom.SlideId == slideAtom.MasterId)
            //        {
            //            List<OfficeDrawing.ShapeContainer> shapes = master.AllChildrenWithType<PPDrawing>()[0].AllChildrenWithType<OfficeDrawing.DrawingContainer>()[0].AllChildrenWithType<OfficeDrawing.GroupContainer>()[0].AllChildrenWithType<OfficeDrawing.ShapeContainer>();
            //            foreach (OfficeDrawing.ShapeContainer shapecontainer in shapes)
            //            {
            //                foreach (OfficeDrawing.ClientData data in shapecontainer.AllChildrenWithType<OfficeDrawing.ClientData>())
            //                {
            //                    System.IO.MemoryStream ms = new System.IO.MemoryStream(data.bytes);
            //                    OfficeDrawing.Record rec = OfficeDrawing.Record.ReadRecord(ms, 0);

            //                    if (rec.TypeCode == 3011)
            //                    {
            //                        OEPlaceHolderAtom placeholder = (OEPlaceHolderAtom)rec;

            //                        if (placeholder != null)
            //                        {
            //                            if (placeholder.PlacementId == PlaceholderEnum.MasterDate)
            //                            {
            //                                stm.Apply(shapecontainer, "");
            //                            }
            //                        }
            //                    }
            //                }
            //            }

            //        }
            //    }
            //  }
            //}

            //if (header)
            //{
            //    string s = "";
            //}

            // if (footer)
            // //foreach (Note master in this._ctx.Ppt.NotesMasterRecords)
            // {
            //     List<OfficeDrawing.ShapeContainer> shapes = master.AllChildrenWithType<PPDrawing>()[0].AllChildrenWithType<OfficeDrawing.DrawingContainer>()[0].AllChildrenWithType<OfficeDrawing.GroupContainer>()[0].AllChildrenWithType<OfficeDrawing.ShapeContainer>();
            //     foreach (OfficeDrawing.ShapeContainer shapecontainer in shapes)
            //     {
            //         foreach (OfficeDrawing.ClientData data in shapecontainer.AllChildrenWithType<OfficeDrawing.ClientData>())
            //         {
            //             System.IO.MemoryStream ms = new System.IO.MemoryStream(data.bytes);
            //             OfficeDrawing.Record rec = OfficeDrawing.Record.ReadRecord(ms);

            //             if (rec.TypeCode == 3011)
            //             {
            //                 OEPlaceHolderAtom placeholder = (OEPlaceHolderAtom)rec;

            //                 if (placeholder != null)
            //                 {
            //                     if (placeholder.PlacementId == PlaceholderEnum.MasterFooter)
            //                     {
            //                         stm.Apply(shapecontainer, footertext, "", "");
            //                         footer = false;
            //                     }
            //                 }
            //             }
            //         }
            //     }
            //}

            if (footer)
            //foreach (Slide master in this._ctx.Ppt.TitleMasterRecords)
            {
                //if (master.PersistAtom.SlideId == slideAtom.MasterId)
                //{
                var shapes = master.AllChildrenWithType <PPDrawing>()[0].AllChildrenWithType <OfficeDrawing.DrawingContainer>()[0].AllChildrenWithType <OfficeDrawing.GroupContainer>()[0].AllChildrenWithType <OfficeDrawing.ShapeContainer>();
                foreach (var shapecontainer in shapes)
                {
                    foreach (var data in shapecontainer.AllChildrenWithType <OfficeDrawing.ClientData>())
                    {
                        var ms  = new System.IO.MemoryStream(data.bytes);
                        var rec = OfficeDrawing.Record.ReadRecord(ms);

                        if (rec.TypeCode == 3011)
                        {
                            var placeholder = (OEPlaceHolderAtom)rec;

                            if (placeholder != null)
                            {
                                if (placeholder.PlacementId == PlaceholderEnum.MasterFooter)
                                {
                                    bool doit = footertext.Length > 0;
                                    if (!doit)
                                    {
                                        foreach (var so in shapecontainer.AllChildrenWithType <ShapeOptions>())
                                        {
                                            if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.FillStyleBooleanProperties))
                                            {
                                                var props = new FillStyleBooleanProperties(so.OptionsByID[ShapeOptions.PropertyId.FillStyleBooleanProperties].op);
                                                if (props.fFilled && props.fUsefFilled)
                                                {
                                                    doit = true;
                                                }
                                            }
                                        }
                                    }
                                    if (doit)
                                    {
                                        stm.Apply(shapecontainer, footertext, "", "");
                                    }
                                    footer = false;
                                }
                            }
                        }
                    }
                }

                //}
            }

            if (footer)
            //foreach (Slide master in this._ctx.Ppt.MainMasterRecords)
            {
                //if (master.PersistAtom.SlideId == slideAtom.MasterId)
                //{
                var shapes = master.AllChildrenWithType <PPDrawing>()[0].AllChildrenWithType <OfficeDrawing.DrawingContainer>()[0].AllChildrenWithType <OfficeDrawing.GroupContainer>()[0].AllChildrenWithType <OfficeDrawing.ShapeContainer>();
                foreach (var shapecontainer in shapes)
                {
                    foreach (var data in shapecontainer.AllChildrenWithType <OfficeDrawing.ClientData>())
                    {
                        var ms  = new System.IO.MemoryStream(data.bytes);
                        var rec = OfficeDrawing.Record.ReadRecord(ms);

                        if (rec.TypeCode == 3011)
                        {
                            var placeholder = (OEPlaceHolderAtom)rec;

                            if (placeholder != null)
                            {
                                if (placeholder.PlacementId == PlaceholderEnum.MasterFooter)
                                {
                                    if (footertext.Length == 0 & shapecontainer.AllChildrenWithType <ClientTextbox>().Count > 0)
                                    {
                                        footertext = new SlideMapping(this._ctx).readFooterFromClientTextBox(shapecontainer.FirstChildWithType <ClientTextbox>());
                                    }

                                    bool doit = footertext.Length > 0;
                                    if (!doit)
                                    {
                                        foreach (var so in shapecontainer.AllChildrenWithType <ShapeOptions>())
                                        {
                                            if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.FillStyleBooleanProperties))
                                            {
                                                var props = new FillStyleBooleanProperties(so.OptionsByID[ShapeOptions.PropertyId.FillStyleBooleanProperties].op);
                                                if (props.fFilled && props.fUsefFilled)
                                                {
                                                    doit = true;
                                                }
                                            }
                                        }
                                    }
                                    if (doit)
                                    {
                                        stm.Apply(shapecontainer, footertext, "", "");
                                    }
                                    footer = false;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        override public void Apply(RegularContainer slide)
        {
            this.Slide = (Slide)slide;
            TraceLogger.DebugInternal("SlideMapping.Apply");

            // Associate slide with slide layout
            var  slideAtom     = slide.FirstChildWithType <SlideAtom>();
            uint mainMasterId  = GetMainMasterId(slideAtom);
            var  layoutManager = this._ctx.GetOrCreateLayoutManagerByMasterId(mainMasterId);

            SlideLayoutPart layoutPart = null;
            var             masterInfo = slide.FirstChildWithType <RoundTripContentMasterId12>();

            // PPT2007 OOXML-Layout
            if (masterInfo != null)
            {
                layoutPart = layoutManager.GetLayoutPartByInstanceId(masterInfo.ContentMasterInstanceId);
            }
            // Pre-PPT2007 Title master layout
            else if (mainMasterId != slideAtom.MasterId)
            {
                layoutPart = layoutManager.GetOrCreateLayoutPartForTitleMasterId(slideAtom.MasterId);
            }
            // Pre-PPT2007 SSlideLayoutAtom primitive SlideLayoutType layout
            else
            {
                var m = (MainMaster)this._ctx.Ppt.FindMasterRecordById(slideAtom.MasterId);
                if (m.Layouts.Count == 1 && slideAtom.Layout.Geom == SlideLayoutType.Blank)
                {
                    foreach (string layout in m.Layouts.Values)
                    {
                        string output = Tools.Utils.replaceOutdatedNamespaces(layout);
                        layoutPart = layoutManager.GetOrCreateLayoutPartByCode(output);
                    }
                }
                else
                {
                    layoutPart = layoutManager.GetOrCreateLayoutPartByLayoutType(slideAtom.Layout.Geom, slideAtom.Layout.PlaceholderTypes);
                }
            }

            this.targetPart.ReferencePart(layoutPart);

            // Start the document
            this._writer.WriteStartDocument();
            this._writer.WriteStartElement("p", "sld", OpenXmlNamespaces.PresentationML);

            // Force declaration of these namespaces at document start
            this._writer.WriteAttributeString("xmlns", "a", null, OpenXmlNamespaces.DrawingML);
            // Force declaration of these namespaces at document start
            this._writer.WriteAttributeString("xmlns", "r", null, OpenXmlNamespaces.Relationships);


            if (Tools.Utils.BitmaskToBool(slideAtom.Flags, 0x1 << 0) == false)
            {
                this._writer.WriteAttributeString("showMasterSp", "0");
            }

            // TODO: Write slide data of master slide
            this._writer.WriteStartElement("p", "cSld", OpenXmlNamespaces.PresentationML);

            var sc = slide.FirstChildWithType <PPDrawing>().FirstChildWithType <DrawingContainer>().FirstChildWithType <ShapeContainer>();

            if (sc != null)
            {
                var sh = sc.FirstChildWithType <Shape>();
                var so = sc.FirstChildWithType <ShapeOptions>();

                if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.FillStyleBooleanProperties))
                {
                    bool ignore = false;
                    if (sc.AllChildrenWithType <ShapeOptions>().Count > 1)
                    {
                        var so2 = sc.AllChildrenWithType <ShapeOptions>()[1];
                        if (so2.OptionsByID.ContainsKey(ShapeOptions.PropertyId.FillStyleBooleanProperties))
                        {
                            var p2 = new FillStyleBooleanProperties(so2.OptionsByID[ShapeOptions.PropertyId.FillStyleBooleanProperties].op);
                            if (!p2.fUsefFilled || !p2.fFilled)
                            {
                                ignore = true;
                            }
                        }
                    }

                    var sa = slide.FirstChildWithType <SlideAtom>();
                    if (Tools.Utils.BitmaskToBool(sa.Flags, 0x1 << 2))
                    {
                        ignore = true;                                                //this means the slide gets its background from the master
                    }
                    if (!ignore)
                    {
                        this._writer.WriteStartElement("p", "bg", OpenXmlNamespaces.PresentationML);
                        this._writer.WriteStartElement("p", "bgPr", OpenXmlNamespaces.PresentationML);
                        var p = new FillStyleBooleanProperties(so.OptionsByID[ShapeOptions.PropertyId.FillStyleBooleanProperties].op);
                        if (p.fUsefFilled & p.fFilled) //  so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillType))
                        {
                            new FillMapping(this._ctx, this._writer, this).Apply(so);
                        }
                        this._writer.WriteElementString("a", "effectLst", OpenXmlNamespaces.DrawingML, "");
                        this._writer.WriteEndElement(); //p:bgPr
                        this._writer.WriteEndElement(); //p:bg
                    }
                }
            }


            this._writer.WriteStartElement("p", "spTree", OpenXmlNamespaces.PresentationML);

            this.shapeTreeMapping = new ShapeTreeMapping(this._ctx, this._writer);
            this.shapeTreeMapping.parentSlideMapping = this;
            this.shapeTreeMapping.Apply(slide.FirstChildWithType <PPDrawing>());

            checkHeaderFooter(this.shapeTreeMapping);

            this._writer.WriteEndElement(); //spTree
            this._writer.WriteEndElement(); //cSld

            // TODO: Write clrMapOvr

            if (slide.FirstChildWithType <SlideShowSlideInfoAtom>() != null)
            {
                new SlideTransitionMapping(this._ctx, this._writer).Apply(slide.FirstChildWithType <SlideShowSlideInfoAtom>());
            }

            if (slide.FirstChildWithType <ProgTags>() != null)
            {
                if (slide.FirstChildWithType <ProgTags>().FirstChildWithType <ProgBinaryTag>() != null)
                {
                    if (slide.FirstChildWithType <ProgTags>().FirstChildWithType <ProgBinaryTag>().FirstChildWithType <ProgBinaryTagDataBlob>() != null)
                    {
                        new AnimationMapping(this._ctx, this._writer).Apply(slide.FirstChildWithType <ProgTags>().FirstChildWithType <ProgBinaryTag>().FirstChildWithType <ProgBinaryTagDataBlob>(), this, this.shapeTreeMapping.animinfos, this.shapeTreeMapping);
                    }
                }
            }


            // End the document
            this._writer.WriteEndElement(); //sld
            this._writer.WriteEndDocument();

            this._writer.Flush();
        }