コード例 #1
0
        private void InsertMasterStylePlaceholders(ShapeTreeMapping stm)
        {
            SlideAtom slideAtom = this.Slide.FirstChildWithType <SlideAtom>();

            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);

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

                                if (placeholder != null)
                                {
                                    if (placeholder.PlacementId != PlaceholderEnum.MasterFooter)
                                    {
                                        stm.Apply(shapecontainer, "", "", "");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void WriteSlide(SlideMapping sMapping)
        {
            Slide slide = sMapping.Slide;

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

            SlideAtom slideAtom = slide.FirstChildWithType <SlideAtom>();

            _writer.WriteAttributeString("id", slide.PersistAtom.SlideId.ToString());
            _writer.WriteAttributeString("r", "id", OpenXmlNamespaces.Relationships, sMapping.targetPart.RelIdToString);

            _writer.WriteEndElement();
        }
コード例 #3
0
        /// <summary>
        /// Get the id of our real main master.
        ///
        /// This need not be the id of our immediate master as it can be a title master.
        /// </summary>
        /// <param name="slideAtom">SlideAtom of slide to find main master id for</param>
        /// <returns>Id of main master</returns>
        private uint GetMainMasterId(SlideAtom slideAtom)
        {
            var masterSlide = this._ctx.Ppt.FindMasterRecordById(slideAtom.MasterId);

            // Is our immediate master a title master?
            if (!(masterSlide is MainMaster))
            {
                // Then our main master is the title master's master
                var titleSlideAtom = masterSlide.FirstChildWithType <SlideAtom>();
                return(titleSlideAtom.MasterId);
            }

            return(slideAtom.MasterId);
        }
コード例 #4
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();
        }
コード例 #5
0
        private void checkHeaderFooter(ShapeTreeMapping stm)
        {
            SlideAtom slideAtom = this.Slide.FirstChildWithType <SlideAtom>();

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

            if (headersfooters != null)
            {
                foreach (CStringAtom 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 slideNumber = false;
            bool date        = false;
            bool userDate    = false;

            if (!(_ctx.Ppt.DocumentRecord.FirstChildWithType <DocumentAtom>().OmitTitlePlace&& this.Slide.FirstChildWithType <SlideAtom>().Layout.Geom == SlideLayoutType.TitleSlide))
            {
                foreach (SlideHeadersFootersContainer c in this._ctx.Ppt.DocumentRecord.AllChildrenWithType <SlideHeadersFootersContainer>())
                {
                    switch (c.Instance)
                    {
                    case 0: //PerSlideHeadersFootersContainer
                        break;

                    case 3: //SlideHeadersFootersContainer
                        foreach (HeadersFootersAtom a in c.AllChildrenWithType <HeadersFootersAtom>())
                        {
                            if (a.fHasFooter)
                            {
                                footer = true;
                            }
                            if (a.fHasSlideNumber)
                            {
                                slideNumber = true;
                            }
                            if (a.fHasDate)
                            {
                                date = true;
                            }
                            if (a.fHasUserDate)
                            {
                                userDate = true;
                            }

                            //if (a.fHasHeader) header = true;
                        }

                        if (footer && footertext.Length == 0 && c.FirstChildWithType <CStringAtom>() != null)
                        {
                            footertext = c.FirstChildWithType <CStringAtom>().Text;
                        }
                        break;

                    case 4: //NotesHeadersFootersContainer
                        break;
                    }
                }
            }

            //if (footertext.Length == 0) footer = false;

            if (slideNumber)
            {
                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);

                                if (rec.TypeCode == 3011)
                                {
                                    OEPlaceHolderAtom 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);

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

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

            if (footer)
            {
                foreach (Slide master in this._ctx.Ppt.TitleMasterRecords)
                {
                    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);

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

                                    if (placeholder != null)
                                    {
                                        if (placeholder.PlacementId == PlaceholderEnum.MasterFooter)
                                        {
                                            bool doit = footertext.Length > 0;
                                            if (!doit)
                                            {
                                                foreach (ShapeOptions so in shapecontainer.AllChildrenWithType <ShapeOptions>())
                                                {
                                                    if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.FillStyleBooleanProperties))
                                                    {
                                                        FillStyleBooleanProperties 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)
                    {
                        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)
                                        {
                                            if (footertext.Length == 0 & shapecontainer.AllChildrenWithType <ClientTextbox>().Count > 0)
                                            {
                                                footertext = readFooterFromClientTextBox(shapecontainer.FirstChildWithType <ClientTextbox>());
                                            }

                                            bool doit = footertext.Length > 0;
                                            if (!doit)
                                            {
                                                foreach (ShapeOptions so in shapecontainer.AllChildrenWithType <ShapeOptions>())
                                                {
                                                    if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.FillStyleBooleanProperties))
                                                    {
                                                        FillStyleBooleanProperties props = new FillStyleBooleanProperties(so.OptionsByID[ShapeOptions.PropertyId.FillStyleBooleanProperties].op);
                                                        if (props.fFilled && props.fUsefFilled)
                                                        {
                                                            doit = true;
                                                        }
                                                    }
                                                }
                                            }
                                            if (doit)
                                            {
                                                stm.Apply(shapecontainer, footertext, "", "");
                                            }
                                            footer = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
        public void writeSolidFill(RegularContainer slide, CharacterRun run, ref string lastColor)
        {
            _writer.WriteStartElement("a", "solidFill", OpenXmlNamespaces.DrawingML);

            if (run.Color.IsSchemeColor) //TODO: to be fully implemented
            {
                //_writer.WriteStartElement("a", "schemeClr", OpenXmlNamespaces.DrawingML);

                if (slide == null)
                {
                    ////TODO: what shall be used in this case (happens for default text style in presentation.xml)
                    //_writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML);
                    //_writer.WriteAttributeString("val", "000000");
                    //_writer.WriteEndElement();

                    _writer.WriteStartElement("a", "schemeClr", OpenXmlNamespaces.DrawingML);
                    switch (run.Color.Index)
                    {
                    case 0x00:
                        _writer.WriteAttributeString("val", "bg1");     //background
                        break;

                    case 0x01:
                        _writer.WriteAttributeString("val", "tx1");     //text
                        break;

                    case 0x02:
                        _writer.WriteAttributeString("val", "dk1");     //shadow
                        break;

                    case 0x03:
                        _writer.WriteAttributeString("val", "tx1");     //title text
                        break;

                    case 0x04:
                        _writer.WriteAttributeString("val", "bg2");     //fill
                        break;

                    case 0x05:
                        _writer.WriteAttributeString("val", "accent1");     //accent1
                        break;

                    case 0x06:
                        _writer.WriteAttributeString("val", "accent2");     //accent2
                        break;

                    case 0x07:
                        _writer.WriteAttributeString("val", "accent3");     //accent3
                        break;

                    case 0xFE:     //sRGB
                        lastColor = run.Color.Red.ToString("X").PadLeft(2, '0') + run.Color.Green.ToString("X").PadLeft(2, '0') + run.Color.Blue.ToString("X").PadLeft(2, '0');
                        _writer.WriteAttributeString("val", lastColor);
                        break;

                    case 0xFF:     //undefined
                        break;
                    }
                    _writer.WriteEndElement();
                }
                else
                {
                    ColorSchemeAtom        MasterScheme = null;
                    SlideAtom              ato          = slide.FirstChildWithType <SlideAtom>();
                    List <ColorSchemeAtom> colors;
                    if (ato != null && Tools.Utils.BitmaskToBool(ato.Flags, 0x1 << 1) && ato.MasterId != 0)
                    {
                        colors = _ctx.Ppt.FindMasterRecordById(ato.MasterId).AllChildrenWithType <ColorSchemeAtom>();
                    }
                    else
                    {
                        colors = slide.AllChildrenWithType <ColorSchemeAtom>();
                    }
                    foreach (ColorSchemeAtom color in colors)
                    {
                        if (color.Instance == 1)
                        {
                            MasterScheme = color;
                        }
                    }

                    _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML);
                    switch (run.Color.Index)
                    {
                    case 0x00:     //background
                        lastColor = new RGBColor(MasterScheme.Background, RGBColor.ByteOrder.RedFirst).SixDigitHexCode;
                        _writer.WriteAttributeString("val", lastColor);
                        break;

                    case 0x01:     //text
                        lastColor = new RGBColor(MasterScheme.TextAndLines, RGBColor.ByteOrder.RedFirst).SixDigitHexCode;
                        _writer.WriteAttributeString("val", lastColor);
                        break;

                    case 0x02:     //shadow
                        lastColor = new RGBColor(MasterScheme.Shadows, RGBColor.ByteOrder.RedFirst).SixDigitHexCode;
                        _writer.WriteAttributeString("val", lastColor);
                        break;

                    case 0x03:     //title
                        lastColor = new RGBColor(MasterScheme.TitleText, RGBColor.ByteOrder.RedFirst).SixDigitHexCode;
                        _writer.WriteAttributeString("val", lastColor);
                        break;

                    case 0x04:     //fill
                        lastColor = new RGBColor(MasterScheme.Fills, RGBColor.ByteOrder.RedFirst).SixDigitHexCode;
                        _writer.WriteAttributeString("val", lastColor);
                        break;

                    case 0x05:     //accent1
                        lastColor = new RGBColor(MasterScheme.Accent, RGBColor.ByteOrder.RedFirst).SixDigitHexCode;
                        _writer.WriteAttributeString("val", lastColor);
                        break;

                    case 0x06:     //accent2
                        lastColor = new RGBColor(MasterScheme.AccentAndHyperlink, RGBColor.ByteOrder.RedFirst).SixDigitHexCode;
                        _writer.WriteAttributeString("val", lastColor);
                        break;

                    case 0x07:     //accent3
                        lastColor = new RGBColor(MasterScheme.AccentAndFollowedHyperlink, RGBColor.ByteOrder.RedFirst).SixDigitHexCode;
                        _writer.WriteAttributeString("val", lastColor);
                        break;

                    case 0xFE:     //sRGB
                        lastColor = run.Color.Red.ToString("X").PadLeft(2, '0') + run.Color.Green.ToString("X").PadLeft(2, '0') + run.Color.Blue.ToString("X").PadLeft(2, '0');
                        _writer.WriteAttributeString("val", lastColor);
                        break;

                    case 0xFF:     //undefined
                        break;
                    }
                    _writer.WriteEndElement();
                    //_writer.WriteEndElement();
                }
            }
            else
            {
                _writer.WriteStartElement("a", "srgbClr", OpenXmlNamespaces.DrawingML);
                lastColor = run.Color.Red.ToString("X").PadLeft(2, '0') + run.Color.Green.ToString("X").PadLeft(2, '0') + run.Color.Blue.ToString("X").PadLeft(2, '0');
                _writer.WriteAttributeString("val", lastColor);
                _writer.WriteEndElement();
            }
            _writer.WriteEndElement();
        }