public static void LoadBlankTheme() { foreach (ETheme item in (Application.Current as IAppGlobal).ThemesCollection) { if (item.ThemeName == "BlankTheme") { Global.BeginInit(); ETheme _cloneTheme = new ETheme(); _cloneTheme = item.Clone() as ETheme; _cloneTheme.Name = item.Name; _cloneTheme.TagName = "This Presenter"; _cloneTheme.ThemeName = item.ThemeName; _cloneTheme.ID = ObjectElementsHelper.RandomString(10); _cloneTheme.Colors = (Application.Current as IAppGlobal).OfficeColors[1]; _cloneTheme.SelectedFont = (Application.Current as IAppGlobal).OfficeFonts[1]; (Application.Current as IAppGlobal).LocalThemesCollection.Add(_cloneTheme); (Application.Current as IAppGlobal).DocumentControl.SelectedTheme = _cloneTheme; (Application.Current as IAppGlobal).DocumentControl.SelectedColors = _cloneTheme.Colors; (Application.Current as IAppGlobal).DocumentControl.SelectedFont = _cloneTheme.SelectedFont; (Application.Current as IAppGlobal).SelectedTheme.SelectedFont = _cloneTheme.SelectedFont; DesignTabControlViewModel.ThemeDesign.SelectedIndex = 0; Global.EndInit(); } } }
//#region Commands public static List <ETheme> GetThemesCollection() { List <ETheme> _result = new List <ETheme>(); foreach (string fileName in Directory.GetFiles("Themes/")) { //Task.Factory.StartNew(() => //{ // EThemes eThemes = new EThemes(); // eThemes = themesData.Open(fileName); // eThemes.Name = Path.GetFileNameWithoutExtension(fileName); // eThemes.TagName = "Office"; // eThemes.ThumbnailIcon = new BitmapImage(new Uri(eThemes.MainTheme.Thumbnail.Path)); // foreach (ETheme item in eThemes.Variants) // { // item.ThumbnailBitmap = new BitmapImage(new Uri(item.Thumbnail.Path)); // } // _result.Add(eThemes); //}); ETheme eTheme = new ETheme(); eTheme = themesData.FirstLoad(fileName); eTheme.Name = Path.GetFileNameWithoutExtension(fileName); eTheme.ID = ObjectElementsHelper.RandomString(10); eTheme.TagName = "Office"; eTheme.ThemeName = Path.GetFileNameWithoutExtension(fileName); eTheme.FilePath = fileName; _result.Add(eTheme); } return(_result); }
/// <summary> /// Lấy chủ đề /// </summary> /// <param name="design"></param> /// <param name="count"></param> /// <returns></returns> public ETheme GetETheme(pp.Design design, int count) { ETheme etheme = new ETheme(); etheme.Name = design.Name; etheme.ID = ObjectElementsHelper.RandomString(10); etheme.ThemeName = design.Name; EColorManagment eColorManagment = new EColorManagment(); eColorManagment = GetEColorManagment(design.SlideMaster.Theme.ThemeColorScheme); etheme.Colors = eColorManagment; etheme.SelectedFont = GetFontTheme(design.SlideMaster.Theme.ThemeFontScheme); ESlideMaster eSlideMaster = new ESlideMaster(); eSlideMaster.ThemesName = etheme.Name; eSlideMaster.Name = etheme.Name; eSlideMaster.MainLayer = new PageLayer(); SlideMasterPart slideMasterPart = GetSlideMasterPart(count); eSlideMaster.MainLayer.Background = GetFillColorSlideMaster(design.SlideMaster.Background.Fill, slideMasterPart.SlideMaster?.CommonSlideData, slideMasterPart); eSlideMaster.ID = ObjectElementsHelper.RandomString(12); foreach (pp.Shape shape in design.SlideMaster.Shapes) { eSlideMaster.MainLayer.Children.Add(GetShape(shape, shape.Type, design.SlideMaster.TimeLine, slideMasterPart)); } SetIsBackgroundShape(eSlideMaster.MainLayer); int countLayoutMaster = 0; foreach (pp.CustomLayout layout in design.SlideMaster.CustomLayouts) { SlideLayoutPart slideLayoutPart = GetSlideLayoutPart(countLayoutMaster++, slideMasterPart); ELayoutMaster eLayoutMaster = new ELayoutMaster(); eLayoutMaster.ID = ObjectElementsHelper.RandomString(13); eLayoutMaster.MainLayer = new PageLayer(); eLayoutMaster.MainLayer.Background = GetFillColorSlideMaster(layout.Background.Fill, slideLayoutPart.SlideLayout?.CommonSlideData, slideLayoutPart); if (eLayoutMaster.MainLayer.Background == null) { eLayoutMaster.MainLayer.Background = eSlideMaster.MainLayer.Background; } foreach (pp.Shape shape in layout.Shapes) { eLayoutMaster.MainLayer.Children.Add(GetShape(shape, shape.Type, design.SlideMaster.TimeLine, slideLayoutPart)); } SetIsBackgroundShape(eLayoutMaster.MainLayer); eLayoutMaster.SlideName = layout.Name; eLayoutMaster.LayoutName = layout.Name; eLayoutMaster.IsHideBackground = layout.DisplayMasterShapes != MsoTriState.msoTrue; eSlideMaster.LayoutMasters.Add(eLayoutMaster); } etheme.SlideMasters.Add(eSlideMaster); return(etheme); }
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { int slideCount = 1; ConvertPresentation cvPresentation = new ConvertPresentation(); using (PresentationDocument presentationDocument = PresentationDocument.Open(presentationFile, false)) { HelperClass helperClass = new HelperClass(); Utils.GetPresentationPart(presentationDocument); #region GetTheme var ss = presentation.SlideMaster.Theme; int count = 0; foreach (Design item in presentation.Designs) { ETheme eTheme = new HelperClass().GetETheme(item, count++); documentMain.ListETheme.Add(eTheme); } documentMain.SelectedTheme = documentMain.ListETheme.FirstOrDefault(); #endregion foreach (Slide slide in Helper.Utils.LstSlideSelected) { NormalPage page = null; //--Chuyển slide PP thành ảnh nền trang if (isBackground) { page = new NormalPage(); page.MainLayer = new PageLayer(); page.MainLayer.ID = ObjectElementsHelper.RandomString(13); page.MainLayer.ThemeLayoutOwnerID = ObjectElementsHelper.RandomString(13); page.CanShowInMenu = true; page.PageConfig = new PageConfig(); page.PageConfig.PreviousButtonEnable = true; cvPresentation.SlideAsBackground(page, slide); slideCount++; } else { page = helperClass.GetNormalPage(slide, helperClass.GetSlidePart(slide.SlideNumber - 1)); page.IDLayout = documentMain.SelectedTheme.SlideMasters[0].LayoutMasters.FirstOrDefault(x => x.SlideName == slide.CustomLayout.MatchingName)?.ID; page.IsHideBackground = slide.DisplayMasterShapes != MsoTriState.msoTrue; slideCount++; } (sender as BackgroundWorker).ReportProgress(slideCount * 100 / Helper.Utils.LstSlideSelected.Count()); documentMain.Pages.Add(page); } } }
/// <summary> /// Convert toàn bộ các trang tài liệu dạng ảnh nền /// </summary> public void SlideAsBackground(NormalPage _page, pp.Slide _slide) { HelperClass helperClass = new HelperClass(); ImageColor imgColor = new ImageColor(); imgColor.Source = new Image(); imgColor.ScaleX = 1; imgColor.ScaleY = 1; imgColor.Source.OpenFile(Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, "Slide_" + _slide.SlideIndex.ToString() + ".png"), false); _page.MainLayer = new PageLayer(); _page.MainLayer.Background = imgColor; _page.ID = ObjectElementsHelper.RandomString(13); //----Hiệu ứng trang helperClass.GetTransition(_slide, _page); }
public static List <ETheme> GetFullThemesCollection() { List <ETheme> _result = new List <ETheme>(); foreach (string fileName in Directory.GetFiles("Themes/")) { if (Path.GetExtension(fileName) == ".athmx") { ETheme eTheme = new ETheme(); eTheme = themesData.OpenETheme(fileName); eTheme.Name = Path.GetFileNameWithoutExtension(fileName); eTheme.ID = ObjectElementsHelper.RandomString(10); eTheme.TagName = "Office"; eTheme.ThemeName = Path.GetFileNameWithoutExtension(fileName); eTheme.FilePath = fileName; eTheme.IsLoaded = false; _result.Add(eTheme); } } return(_result); }
public NormalPage GetNormalPage(pp.Slide slide, SlidePart slidePart) { NormalPage normalPage = new NormalPage(); normalPage.CanShowInMenu = true; normalPage.PageConfig = new PageConfig(); normalPage.PageConfig.PreviousButtonEnable = true; normalPage.Name = slide.Name; normalPage.ID = ObjectElementsHelper.RandomString(13); normalPage.MainLayer = new PageLayer(); normalPage.MainLayer.ID = ObjectElementsHelper.RandomString(13); normalPage.MainLayer.ThemeLayoutOwnerID = ObjectElementsHelper.RandomString(13); normalPage.MainLayer.Background = GetFillColor(slide.Background.Fill, slidePart.Slide.CommonSlideData?.Background, slidePart); foreach (pp.Shape shape in slide.Shapes) { ObjectElementBase element = GetShape(shape, shape.Type, slide.TimeLine, slidePart); foreach (Animations.DataMotionPath motionPath in element.Animations.MotionPaths) { string pathId = motionPath.ID; TriggerDataObject trigger = new TriggerDataObject() { Type = ETriggerType.Layer, Action = EAction.Move, Source = element.ID, SourceDetail = new SourceDetailData() { ObjectId = pathId }, Event = EEvent.TimelineStarts, Target = normalPage.MainLayer.ID }; normalPage.MainLayer.TriggerData.Add(trigger); } normalPage.MainLayer.Children.Add(element); } normalPage.ID = ObjectElementsHelper.RandomString(13); GetTransition(slide, normalPage); return(normalPage); }
/// <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); }
private void ShapeToImage(PageLayer _page, pp.Shape _shape, EAnimation _animation, string _idShape) { EImageContent eImage = new EImageContent(); eImage.ID = _idShape; eImage.Width = _shape.Width * Utils.tlw; eImage.Height = _shape.Height * Utils.tlh; eImage.Top = _shape.Top * Utils.tlh; eImage.Left = _shape.Left * Utils.tlw; eImage.Angle = _shape.Rotation; eImage.ZOder = (int)_shape.ZOrderPosition; eImage.Animations = _animation; eImage.RectCrop = new ESuperPoint(); //Export Shape ra ảnh string pathImage = Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, ObjectElementsHelper.RandomString(13) + ".png"); _shape.Export(pathImage, pp.PpShapeFormat.ppShapeFormatPNG, 0, 0, pp.PpExportMode.ppScaleXY); eImage.Image = new Image(); eImage.Image.Path = pathImage; _page.Children.Add(eImage); }
/// <summary> /// Nhập đối tượng là video /// </summary> /// <param name="_page"></param> /// <param name="_shape"></param> private void ShapeIsVideo(PageLayer _page, pp.Shape _shape, EAnimation _animation, string _idShape) { var lstPic = Utils.slidePart.Slide.Descendants <DocumentFormat.OpenXml.Presentation.Picture>().Select(p => p); P.Picture videoTag = GetPictureTag(lstPic, _shape.Id.ToString()); var videoFromFile = videoTag.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.Descendants <D.VideoFromFile>().Select(p => p); ReferenceRelationship relationship = Utils.slidePart.GetReferenceRelationship(videoFromFile.First().Link.Value); if (videoTag.NonVisualPictureProperties.NonVisualDrawingProperties.HyperlinkOnClick == null) { VideoAsFlash(_page, _shape, relationship, _animation, _idShape); } else { EVideoPlayer eVideoPlayer = new EVideoPlayer(); eVideoPlayer.Name = "Video"; eVideoPlayer.ID = _idShape; eVideoPlayer.Angle = _shape.Rotation; eVideoPlayer.Width = _shape.Width * Utils.tlw; eVideoPlayer.Height = _shape.Height * Utils.tlh; eVideoPlayer.Top = _shape.Top * Utils.tlh; eVideoPlayer.Left = _shape.Left * Utils.tlw; eVideoPlayer.ZOder = _shape.ZOrderPosition; eVideoPlayer.Animations = _animation; //Lấy file video trong gói sử dụng openxml DataPartReferenceRelationship data = (DataPartReferenceRelationship)relationship; string pathVideo = Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, ObjectElementsHelper.RandomString(13) + Path.GetExtension(data.Uri.ToString())); Utils.CopyStream(data.DataPart.GetStream(), pathVideo); eVideoPlayer.Source = new Core.Model.Media.Video(); eVideoPlayer.Source.Path = pathVideo; //Lấy avata video eVideoPlayer.ImageFirst = new Image(); string rId = videoTag.BlipFill.Blip.Embed.Value; OpenXmlPart avtPart = Utils.slidePart.GetPartById(rId); string pathAvata = Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, ObjectElementsHelper.RandomString(13) + Path.GetExtension(avtPart.Uri.ToString())); Utils.CopyStream(avtPart.GetStream(), pathAvata); eVideoPlayer.ImageFirst.Path = pathAvata; _page.Children.Add(eVideoPlayer); } }
/// <summary> /// Nhập đối tượng là audio /// </summary> /// <param name="_page"></param> /// <param name="_shape"></param> private void ShapeIsAudio(PageLayer _page, pp.Shape _shape, EAnimation _animation, string _idShape) { EAudioElement eAudio = new EAudioElement(); eAudio.Name = "Audio"; eAudio.ID = _idShape; eAudio.Width = _shape.Width * Utils.tlw; eAudio.Height = _shape.Height * Utils.tlh; eAudio.Top = _shape.Top * Utils.tlh; eAudio.Left = _shape.Left * Utils.tlw; eAudio.Angle = _shape.Rotation; eAudio.ZOder = (int)_shape.ZOrderPosition; eAudio.Animations = _animation; //Lấy file audio trong gói sử dụng openxml var lstPic = Utils.slidePart.Slide.Descendants <DocumentFormat.OpenXml.Presentation.Picture>().Select(p => p); P.Picture audioTag = GetPictureTag(lstPic, _shape.Id.ToString()); var audioFromFile = audioTag.NonVisualPictureProperties.ApplicationNonVisualDrawingProperties.Descendants <D.AudioFromFile>().Select(p => p); ReferenceRelationship relationship = Utils.slidePart.GetReferenceRelationship(audioFromFile.First().Link.Value); DataPartReferenceRelationship data = (DataPartReferenceRelationship)relationship; string pathAudio = Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, ObjectElementsHelper.RandomString(13) + Path.GetExtension(data.Uri.ToString())); Utils.CopyStream(data.DataPart.GetStream(), pathAudio); eAudio.AudioFileName = new Core.Model.Media.Audio(); eAudio.AudioFileName.Path = pathAudio; _page.Children.Add(eAudio); }
private void ShapeIsPicture(PageLayer _page, pp.Shape _shape, EAnimation _animation, string _idShape) { EImageContent eImage = new EImageContent(); eImage.Name = "Image"; eImage.ID = _idShape; eImage.Width = _shape.Width * Utils.tlw; eImage.Height = _shape.Height * Utils.tlh; eImage.Top = _shape.Top * Utils.tlh; eImage.Left = _shape.Left * Utils.tlw; eImage.Angle = _shape.Rotation; eImage.ZOder = (int)_shape.ZOrderPosition; eImage.Animations = _animation; eImage.RectCrop = new ESuperPoint(); var lstPic = Utils.slidePart.Slide.Descendants <DocumentFormat.OpenXml.Presentation.Picture>().Select(p => p); P.Picture picTag = GetPictureTag(lstPic, _shape.Id.ToString()); string rID = picTag.BlipFill.Blip.Embed.Value; ImagePart part = (ImagePart)Utils.slidePart.GetPartById(rID); string pathImage = Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, ObjectElementsHelper.RandomString(13) + Path.GetExtension(part.Uri.ToString())); Utils.CopyStream(part.GetStream(), pathImage); eImage.Image = new Image(); eImage.Image.Path = pathImage; _page.Children.Add(eImage); }