public static PowerPoint.Shape GetTextShapeToProcess(PowerPoint.Shapes shapes) { return GetTextShapeToProcess(shapes.Range()); }
/// <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.ppShapeFormatPNG; fileExt = "png"; } 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); if (bitmapMode) { // Starting with Office 2013, bitmaps may not be exported in the correct size. double version; if (!double.TryParse(((PowerPoint.Application)shapes.Application).Version, out version)) { version = 0.0; } if (version >= 15.0) { ScaleShapeImage(sr, filename); } } 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); }