public ColorBase GetFillColorSlideMaster(pp.FillFormat fill, P.CommonSlideData commonSlide, OpenXmlPart openXmlPart) { if (commonSlide.Background != null && commonSlide.Background.BackgroundProperties != null) { switch (fill.Type) { case MsoFillType.msoFillMixed: return(new SolidColor() { Name = Brushes.Transparent.ToString() }); case MsoFillType.msoFillSolid: return(GetSolidColor(fill.ForeColor)); case MsoFillType.msoFillPatterned: return(GetPatternColor(fill.Pattern, fill.BackColor, fill.ForeColor)); case MsoFillType.msoFillGradient: if (fill.GradientStyle == MsoGradientStyle.msoGradientDiagonalDown || fill.GradientStyle == MsoGradientStyle.msoGradientDiagonalUp || fill.GradientStyle == MsoGradientStyle.msoGradientVertical) { return(GetLinearColor(fill.GradientStops, fill.GradientStyle, fill.GradientAngle)); } else { return(GetRadialColor(fill.GradientStops, fill.GradientStyle)); } case MsoFillType.msoFillTextured: case MsoFillType.msoFillPicture: foreach (var item in commonSlide.Background.BackgroundProperties) { if (item is DocumentFormat.OpenXml.Drawing.BlipFill blipFill) { return(GetImageColor(fill, openXmlPart, blipFill)); } } break; } } else { switch (fill.Type) { case MsoFillType.msoFillMixed: return(new SolidColor() { Name = Brushes.Transparent.ToString() }); case MsoFillType.msoFillSolid: return(GetSolidColor(fill.ForeColor)); case MsoFillType.msoFillPatterned: return(GetPatternColor(fill.Pattern, fill.BackColor, fill.ForeColor)); case MsoFillType.msoFillGradient: if (fill.GradientStyle == MsoGradientStyle.msoGradientDiagonalDown || fill.GradientStyle == MsoGradientStyle.msoGradientDiagonalUp || fill.GradientStyle == MsoGradientStyle.msoGradientVertical) { return(GetLinearColor(fill.GradientStops, fill.GradientStyle, fill.GradientAngle)); } else { return(GetRadialColor(fill.GradientStops, fill.GradientStyle)); } case MsoFillType.msoFillPicture: break; } } return(null); }
/// <summary> /// Lấy màu Image Slide /// </summary> /// <param name="slide"></param> /// <param name="openXmlPart"></param> /// <param name="blipFill"></param> /// <returns></returns> private ImageColor GetImageColor(pp.FillFormat fill, OpenXmlPart openXmlPart, BlipFill blipFill) { ImagePart part = null; IEnumerable <DocumentFormat.OpenXml.Presentation.Picture> lstPic = null; if (openXmlPart is SlidePart slidePart) { lstPic = slidePart.Slide.Descendants <DocumentFormat.OpenXml.Presentation.Picture>().Select(p => p); if (lstPic != null) { string rID = blipFill.Blip.Embed.Value; part = (ImagePart)slidePart.GetPartById(rID); } } else if (openXmlPart is SlideMasterPart slideMasterPart) { lstPic = slideMasterPart.SlideMaster.Descendants <DocumentFormat.OpenXml.Presentation.Picture>().Select(p => p); if (lstPic != null) { string rID = blipFill.Blip.Embed.Value; part = (ImagePart)slideMasterPart.GetPartById(rID); } } else if (openXmlPart is SlideLayoutPart slideLayoutPart) { lstPic = slideLayoutPart.SlideLayout.Descendants <DocumentFormat.OpenXml.Presentation.Picture>().Select(p => p); if (lstPic != null) { string rID = blipFill.Blip.Embed.Value; part = (ImagePart)slideLayoutPart.GetPartById(rID); } } if (lstPic != null && part != null) { string pathImage = System.IO.Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, ObjectElementsHelper.RandomString(13) + System.IO.Path.GetExtension(part.Uri.ToString())); Utils.CopyStream(part.GetStream(), pathImage); ImageColor imageColor = new ImageColor(); imageColor.Source = new Core.Model.Image(pathImage); imageColor.Opacity = 1 - fill.Transparency; imageColor.OffsetX = fill.TextureOffsetX; imageColor.OffsetY = fill.TextureOffsetY; imageColor.IsTiled = fill.TextureTile == MsoTriState.msoTrue; imageColor.Alignment = ConvertImageAligment(fill.TextureAlignment); imageColor.ScaleX = fill.TextureHorizontalScale; imageColor.ScaleY = fill.TextureVerticalScale; imageColor.RotateWidthShape = fill.RotateWithObject == MsoTriState.msoTrue; foreach (var item in blipFill) { if (item is Stretch stretch) { if (stretch.FillRectangle.Top != null) { imageColor.OffsetTop = stretch.FillRectangle.Top / 100000; } if (stretch.FillRectangle.Left != null) { imageColor.OffsetLeft = stretch.FillRectangle.Left / 100000; } if (stretch.FillRectangle.Right != null) { imageColor.OffsetRight = stretch.FillRectangle.Right / 100000; } if (stretch.FillRectangle.Bottom != null) { imageColor.OffsetBottom = stretch.FillRectangle.Bottom / 100000; } } } return(imageColor); } return(null); }
/// <summary> /// lấy màu background Slide /// </summary> /// <param name="slide"></param> /// <param name="slideTag"></param> /// <param name="openXmlPart"></param> /// <returns></returns> public ColorBase GetFillColor(pp.FillFormat fill, P.Background background, OpenXmlPart openXmlPart) { if (background == null || background.BackgroundProperties == null) { switch (fill.Type) { case MsoFillType.msoFillMixed: return(new SolidColor() { Name = Brushes.Transparent.ToString() }); case MsoFillType.msoFillSolid: return(GetSolidColor(fill.ForeColor)); case MsoFillType.msoFillPatterned: return(GetPatternColor(fill.Pattern, fill.BackColor, fill.ForeColor)); case MsoFillType.msoFillGradient: if (fill.GradientStyle == MsoGradientStyle.msoGradientDiagonalDown || fill.GradientStyle == MsoGradientStyle.msoGradientDiagonalUp || fill.GradientStyle == MsoGradientStyle.msoGradientHorizontal || fill.GradientStyle == MsoGradientStyle.msoGradientVertical) { return(GetLinearColor(fill.GradientStops, fill.GradientStyle, fill.GradientAngle)); } else { return(GetRadialColor(fill.GradientStops, fill.GradientStyle)); } case MsoFillType.msoFillPicture: break; } } else { foreach (var item in background.BackgroundProperties) { if (item is NoFill noFill) { return(new SolidColor() { Name = Brushes.Transparent.ToString() }); } if (item is SolidFill solidFill) { return(GetSolidColor(fill.ForeColor)); } if (item is PatternFill patternFill) { return(GetPatternColor(fill.Pattern, fill.BackColor, fill.ForeColor)); } if (item is GradientFill gradientFill) { if (fill.GradientStyle == MsoGradientStyle.msoGradientDiagonalDown || fill.GradientStyle == MsoGradientStyle.msoGradientDiagonalUp || fill.GradientStyle == MsoGradientStyle.msoGradientHorizontal || fill.GradientStyle == MsoGradientStyle.msoGradientVertical) { return(GetLinearColor(fill.GradientStops, fill.GradientStyle, fill.GradientAngle)); } else { return(GetRadialColor(fill.GradientStops, fill.GradientStyle)); } } if (item is BlipFill blipFill) { return(GetImageColor(fill, openXmlPart, blipFill)); } } } return(null); }