示例#1
0
        override public void Apply(RegularContainer pmaster)
        {
            Slide master = (Slide)pmaster;

            TraceLogger.DebugInternal("MasterMapping.Apply");
            UInt32 masterId = master.PersistAtom.SlideId;

            _ctx.RegisterMasterMapping(masterId, this);

            this.Master        = master;
            this.MasterId      = master.PersistAtom.SlideId;
            this.LayoutManager = _ctx.GetOrCreateLayoutManagerByMasterId(this.MasterId);

            // Add PPT2007 roundtrip slide layouts
            List <RoundTripContentMasterInfo12> rtSlideLayouts = this.Master.AllChildrenWithType <RoundTripContentMasterInfo12>();

            foreach (RoundTripContentMasterInfo12 slideLayout in rtSlideLayouts)
            {
                SlideLayoutPart layoutPart = this.LayoutManager.AddLayoutPartWithInstanceId(slideLayout.Instance);
                XmlNode         e          = slideLayout.XmlDocumentElement;

                XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
                nsm.AddNamespace("a", OpenXmlNamespaces.DrawingML);

                //for the moment remove blips that reference pictures
                foreach (XmlNode bublip in  e.SelectNodes("//a:buBlip", nsm))
                {
                    bublip.ParentNode.RemoveChild(bublip);
                }

                Tools.Utils.replaceOutdatedNamespaces(ref e);
                e.WriteTo(layoutPart.XmlWriter);
                layoutPart.XmlWriter.Flush();
            }
        }
示例#2
0
        override public void Apply(RegularContainer slide)
        {
            this.Slide = (Slide)slide;
            TraceLogger.DebugInternal("SlideMapping.Apply");

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

            SlideLayoutPart            layoutPart = null;
            RoundTripContentMasterId12 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
            {
                MainMaster m = (MainMaster)_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
            _writer.WriteStartDocument();
            _writer.WriteStartElement("p", "sld", OpenXmlNamespaces.PresentationML);

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


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

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

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

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

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

                    SlideAtom 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)
                    {
                        _writer.WriteStartElement("p", "bg", OpenXmlNamespaces.PresentationML);
                        _writer.WriteStartElement("p", "bgPr", OpenXmlNamespaces.PresentationML);
                        FillStyleBooleanProperties p = new FillStyleBooleanProperties(so.OptionsByID[ShapeOptions.PropertyId.FillStyleBooleanProperties].op);
                        if (p.fUsefFilled & p.fFilled) //  so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillType))
                        {
                            new FillMapping(_ctx, _writer, this).Apply(so);
                        }
                        _writer.WriteElementString("a", "effectLst", OpenXmlNamespaces.DrawingML, "");
                        _writer.WriteEndElement(); //p:bgPr
                        _writer.WriteEndElement(); //p:bg
                    }
                }
            }


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

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

            checkHeaderFooter(shapeTreeMapping);

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

            // TODO: Write clrMapOvr

            if (slide.FirstChildWithType <SlideShowSlideInfoAtom>() != null)
            {
                new SlideTransitionMapping(_ctx, _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(_ctx, _writer).Apply(slide.FirstChildWithType <ProgTags>().FirstChildWithType <ProgBinaryTag>().FirstChildWithType <ProgBinaryTagDataBlob>(), this, shapeTreeMapping.animinfos, shapeTreeMapping);
                    }
                }
            }


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

            _writer.Flush();
        }