예제 #1
0
        public ShapeRange ToShapeRange(IEnumerable <Shape> shapes)
        {
            var shapeList = shapes.ToList();
            var oldNames  = shapeList.Select(shape => shape.Name).ToList();

            var currentShapeNames = Shapes.Cast <Shape>().Select(shape => shape.Name);
            var unusedNames       = Common.GetUnusedStrings(currentShapeNames, shapeList.Count);

            shapeList.Zip(unusedNames, (shape, name) => shape.Name = name).ToList();


            var shapeRange = Shapes.Range(unusedNames);

            shapeList.Zip(oldNames, (shape, name) => shape.Name = name).ToList();

            return(shapeRange);
        }
예제 #2
0
 public static PowerPoint.Shape GetTextShapeToProcess(PowerPoint.Shapes shapes)
 {
     return(GetTextShapeToProcess(shapes.Range()));
 }
예제 #3
0
        /// <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);
        }