/// <summary> /// Find the title of the slide - this is just the text of the first rectangle /// </summary> /// <param name="tsList"></param> /// <returns></returns> private static string FindSlideTitle(List <TaggedShape> tsList) { foreach (TaggedShape ts in tsList) { if (ts.disp == SheetDisposition.All && ts.shape.Name.StartsWith("Rectangle") && ts.shape.TextFrame != null && ts.shape.TextFrame.TextRange != null) { return(PPTDeckIO.CleanString(ts.shape.TextFrame.TextRange.Text)); } } return(""); }
private static void AddTaggedShapeToList(List <TaggedShape> tsList, ref int index, PowerPoint.Shape shape, PPTPaneManagement.PPTPaneManager pptpm) { TaggedShape ts; ts.shape = shape; ts.index = index; index++; ts.isImage = (shape.Name.StartsWith("Picture")); // A shape is an image if its called a picture! string[] modes = pptpm.GetModes(shape); if (modes.Length == 0) { ts.disp = SheetDisposition.All; tsList.Add(ts); } else { foreach (string mode in modes) { ts.disp = PPTDeckIO.Disposition(mode); // Make a copy for each mode, and add to the list tsList.Add(ts); } } }
/// <summary> /// /// </summary> /// <param name="tfc"></param> /// <param name="shapes"></param> /// <param name="range"></param> /// <param name="deck"></param> /// <param name="slide"></param> /// <param name="disposition"></param> /// <param name="emfHeight"></param> /// <param name="startHeight">The starting height to place this sheet at</param> private static void ProcessLayer(List <TaggedShape> layer, TempFileCollection tfc, PowerPoint.Shapes shapes, Model.Presentation.DeckModel deck, Model.Presentation.SlideModel slide, float emfWidthRatio, float emfHeightRatio, int startHeight) { if (layer.Count < 1) { return; } //Create the image int[] range = PPTDeckIO.BuildIntRange(layer); PowerPoint.ShapeRange sr = shapes.Range(range); PowerPoint.PpShapeFormat format; string fileExt = ""; bool bitmapMode = layer[0].isImage; if (bitmapMode) { format = PowerPoint.PpShapeFormat.ppShapeFormatJPG; fileExt = "jpg"; } else { format = PowerPoint.PpShapeFormat.ppShapeFormatEMF; fileExt = "emf"; } //Generate a new filename string dirpath = tfc.BasePath; string filename = PPTDeckIO.GenerateFilename(); filename = dirpath + "\\" + filename + "." + fileExt; while (File.Exists(filename)) { filename = PPTDeckIO.GenerateFilename(); filename = dirpath + "\\" + filename + "." + fileExt; } sr.Export(filename, format, 0, 0, PowerPoint.PpExportMode.ppRelativeToSlide); tfc.AddFile(filename, false); //Compute the MD5 of the BG FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); MD5 md5Provider = new MD5CryptoServiceProvider(); byte[] md5 = md5Provider.ComputeHash(fs); fs.Seek(0, SeekOrigin.Begin); Image image = Image.FromStream(fs); if (bitmapMode) { image = DisassociateBitmap(image); } fs.Close(); //Calculate the geometry int xCoord = 0; int yCoord = 0; int width = 0; int height = 0; PPTDeckIO.CalculateGeometry(image, shapes, range, emfWidthRatio, emfHeightRatio, ref xCoord, ref yCoord, ref width, ref height); //Create the ImageSheet ImageSheetModel sheet = new ImageSheetModel(deck, Guid.NewGuid(), layer[0].disp, new Rectangle(xCoord, yCoord, width, height), (ByteArray)md5, startHeight); //Add the ImageSheet to the Slide slide.ContentSheets.Add(sheet); //Add the Image+MD5 to the deck deck.AddSlideContent((ByteArray)md5, image); }
public static DeckModel OpenPPT(FileInfo file) { return(PPTDeckIO.OpenPPT(file, null, null)); }
/// <summary> /// Create a slide model from a powerpoint slide /// </summary> /// <param name="pageSetup"></param> /// <param name="pptpm"></param> /// <param name="deck"></param> /// <param name="tempFileCollection"></param> /// <param name="dirpath"></param> /// <param name="currentSlide"></param> /// <returns></returns> private static SlideModel CreateSlide(PowerPoint.PageSetup pageSetup, PPTPaneManagement.PPTPaneManager pptpm, DeckModel deck, TempFileCollection tempFileCollection, string dirpath, PowerPoint._Slide currentSlide) { int slideWidth = (int)pageSetup.SlideWidth; //Standard = 720 => 6000 int slideHeight = (int)pageSetup.SlideHeight; //Standard = 540 => 4500 float emfWidth = slideWidth * 25 / 3; float emfHeight = slideHeight * 25 / 3; PowerPoint.Shapes currentShapes = currentSlide.Shapes; List <TaggedShape> taggedShapeList = PPTDeckIO.BuildTaggedShapeList(currentShapes, pptpm); //Create a new SlideModel SlideModel newSlideModel = new SlideModel(Guid.NewGuid(), new LocalId(), SlideDisposition.Empty, new Rectangle(0, 0, slideWidth, slideHeight)); //Lock it using (Synchronizer.Lock(newSlideModel.SyncRoot)) { //Set the slide's title newSlideModel.Title = PPTDeckIO.FindSlideTitle(taggedShapeList); PPTDeckIO.MakeShapesInvisible(currentShapes); //Create the Background image //Generate a new filename string filename = PPTDeckIO.GenerateFilename(); bool bitmapMode = true; if (bitmapMode) { filename = dirpath + "\\" + filename + ".JPG"; currentSlide.Export(filename, "JPG", 0, 0); // Need to also export as EMF to get the size of the slide in inches currentSlide.Export(filename + "_TEMP", "EMF", 0, 0); tempFileCollection.AddFile(filename + "_TEMP", false); } else { filename = dirpath + "\\" + filename + ".emf"; currentSlide.Export(filename, "EMF", 0, 0); } tempFileCollection.AddFile(filename, false); //Compute the MD5 of the BG FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); MD5 md5Provider = new MD5CryptoServiceProvider(); byte[] md5 = md5Provider.ComputeHash(fs); fs.Seek(0, SeekOrigin.Begin); Image image = Image.FromStream(fs); if (bitmapMode) { image = DisassociateBitmap(image); } fs.Close(); // Open the EMF version if we used a bitmap to get the conversion if (bitmapMode) { FileStream fsEMF = new FileStream(filename + "_TEMP", FileMode.Open, FileAccess.Read); Image image_emf = Image.FromStream(fsEMF); emfWidth = image_emf.Width; emfHeight = image_emf.Height; fsEMF.Close(); image_emf.Dispose(); } else { emfWidth = image.Width; emfHeight = image.Height; } //Create the ImageSheet ImageSheetModel sheet = new ImageSheetModel(deck, Guid.NewGuid(), Model.Presentation.SheetDisposition.Background, new Rectangle(0, 0, slideWidth, slideHeight), (ByteArray)md5, 1); //Add the ImageSheet to the Slide newSlideModel.ContentSheets.Add(sheet); //Add the Image+MD5 to the deck deck.AddSlideContent((ByteArray)md5, image); // Restore visibility - this makes everything visible - a bug? PPTDeckIO.MakeShapesVisible(currentShapes); List <List <TaggedShape> > layerList = PPTDeckIO.SeparateIntoLayers(taggedShapeList); int startHeight = 2; foreach (List <TaggedShape> layer in layerList) { PPTDeckIO.ProcessLayer(layer, tempFileCollection, currentShapes, deck, newSlideModel, slideWidth / emfWidth, slideHeight / emfHeight, startHeight++); } //Add SlideModel to the deck deck.InsertSlide(newSlideModel); } return(newSlideModel); }
private void RunWorker(object sender, DoWorkEventArgs progress) { DeckModel deck = this.m_Marshal.ReadDeckAsync(((FileInfo)progress.Argument), ((BackgroundWorker)sender), progress); // Failure is indicated by a null deck - not clear if this is the best way to handle things if (deck != null) { using (Synchronizer.Lock(deck)) { ///in order to have the tabbed files display correctly, we need to set their ///'HumanName' property. Since most people don't want to see the '.cp3' or '.ppt'part ///we'll just erase this. BUG 961 fixed ///Also erase '.pptx', BUG 1130 fixed string fileName = file_to_open_.Name; if (file_to_open_.Name.EndsWith(".cp3") || file_to_open_.Name.EndsWith(".ppt")) { fileName = fileName.Remove(fileName.Length - 4); } if (file_to_open_.Name.EndsWith(".pptx")) { fileName = fileName.Remove(fileName.Length - 5); } deck.HumanName = fileName; //Since opened from a file, the dirty bit should be false, even if //it's a student submission deck. deck.Dirty = false; if (deck.Disposition == DeckDisposition.StudentSubmission) { deck.Group = Network.Groups.Group.Submissions; } } DeckTraversalModel traversal = new SlideDeckTraversalModel(Guid.NewGuid(), deck); #if WEBSERVER // TODO CMPRINCE WEBSERVER: This isn't an ideal solution // Export the deck now as images for the web server using (Synchronizer.Lock(traversal.SyncRoot)) { using (Synchronizer.Lock(traversal.Deck.SyncRoot)) { string imagePath = Path.Combine(Web.WebService.WebRoot, "images\\decks\\" + traversal.Deck.HumanName + "\\" + traversal.Deck.HumanName + "\\"); PPTDeckIO.ExportDeck((DefaultDeckTraversalModel)traversal, imagePath, System.Drawing.Imaging.ImageFormat.Png); string imagePath2 = Path.Combine(Web.WebService.WebRoot, "images\\decks\\" + traversal.Deck.HumanName + "\\" + traversal.Deck.HumanName + "\\thumbnails\\"); PPTDeckIO.ExportDeck((DefaultDeckTraversalModel)traversal, imagePath2, System.Drawing.Imaging.ImageFormat.Png, 0, 0, 0.5f); } } #endif using (this.m_Model.Workspace.Lock()) { if (~this.m_Model.Workspace.CurrentPresentation != null) { using (Synchronizer.Lock((~this.m_Model.Workspace.CurrentPresentation).SyncRoot)) { (~this.m_Model.Workspace.CurrentPresentation).DeckTraversals.Add(traversal); } } else { this.m_Model.Workspace.DeckTraversals.Add(traversal); } } } }