Ejemplo n.º 1
0
        public static void ExportShape(ShapeRange shapeRange, string exportPath)
        {
            var slideWidth = (int)PowerPointPresentation.Current.SlideWidth;
            var slideHeight = (int)PowerPointPresentation.Current.SlideHeight;

            shapeRange.Export(exportPath, PpShapeFormat.ppShapeFormatPNG, slideWidth,
                              slideHeight, PpExportMode.ppScaleToFit);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Stretches all selected shapes to the left edge of reference shape
        /// </summary>
        /// <param name="stretchShapes">The shapes to stretch</param>
        public void StretchLeft(PowerPoint.ShapeRange stretchShapes)
        {
            GetAppropriateStretchAction appropriateStretch = new GetAppropriateStretchAction((referenceEdge, checkShape) =>
            {
                // Opposite stretch
                if (GetRight(checkShape) < referenceEdge)
                {
                    return(StretchRightAction);
                }
                return(StretchLeftAction);
            });
            GetDefaultReferenceEdge defaultReferenceEdge = new GetDefaultReferenceEdge(referenceShape => referenceShape.VisualLeft);

            Stretch(stretchShapes, appropriateStretch, defaultReferenceEdge, StretchType.Left);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Stretches all selected shapes to the top edge of reference shape
        /// </summary>
        /// <param name="stretchShapes">The shapes to stretch</param>
        public void StretchTop(PowerPoint.ShapeRange stretchShapes)
        {
            GetAppropriateStretchAction appropriateStretch = new GetAppropriateStretchAction((referenceEdge, checkShape) =>
            {
                // Opposite stretch
                if (GetBottom(checkShape) < referenceEdge)
                {
                    return(StretchBottomAction);
                }
                return(StretchTopAction);
            });
            GetDefaultReferenceEdge defaultReferenceEdge = new GetDefaultReferenceEdge(referenceShape => referenceShape.VisualTop);

            Stretch(stretchShapes, appropriateStretch, defaultReferenceEdge, StretchType.Top);
        }
Ejemplo n.º 4
0
        public static PowerPoint.ShapeRange ExecuteBlurSelected(Models.PowerPointSlide slide, PowerPoint.Selection selection, int percentage)
        {
            if (!IsValidSelection(selection))
            {
                return(null);
            }

            PowerPoint.ShapeRange range = BlurSelected(slide, selection, percentage);
            if (range != null)
            {
                range.Select();
            }

            return(range);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Stretches all selected shapes to the left edge of reference shape
        /// </summary>
        /// <param name="stretchShapes">The shapes to stretch</param>
        public void StretchBottom(PowerPoint.ShapeRange stretchShapes)
        {
            var appropriateStretch = new GetAppropriateStretchAction((referenceEdge, checkShape) =>
            {
                // Opposite stretch
                if (checkShape.VisualTop > referenceEdge)
                {
                    return(StretchTopAction);
                }
                return(StretchBottomAction);
            });
            var defaultReferenceEdge = new GetDefaultReferenceEdge(referenceShape => referenceShape.VisualTop + referenceShape.AbsoluteHeight);

            Stretch(stretchShapes, appropriateStretch, defaultReferenceEdge, StretchType.Bottom);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Stretches all selected shapes to the right edge of reference shape
        /// </summary>
        /// <param name="stretchShapes">The shapes to stretch</param>
        public void StretchRight(PowerPoint.ShapeRange stretchShapes)
        {
            var appropriateStretch = new GetAppropriateStretchAction((referenceEdge, checkShape) =>
            {
                // Opposite stretch
                if (checkShape.VisualLeft > referenceEdge)
                {
                    return(StretchLeftAction);
                }
                return(StretchRightAction);
            });
            var defaultReferenceEdge = new GetDefaultReferenceEdge(referenceShape => referenceShape.VisualLeft + referenceShape.AbsoluteWidth);

            Stretch(stretchShapes, appropriateStretch, defaultReferenceEdge, StretchType.Right);
        }
Ejemplo n.º 7
0
 public static bool IsAllPictureWithReferenceObject(ShapeRange shapeRange)
 {
     if (!IsPictureOrShape(shapeRange[1]))
     {
         return(false);
     }
     for (int i = 2; i <= shapeRange.Count; i++)
     {
         if (!IsPicture(shapeRange[i]))
         {
             return(false);
         }
     }
     return(true);
 }
        private void ClickHandler(Action <PowerPoint.ShapeRange, float, float, bool> resizeAction, int minNoOfSelectedShapes,
                                  string[] errorParameters)
        {
            PowerPoint.ShapeRange selectedShapes = GetSelectedShapes();
            float slideWidth  = this.GetCurrentPresentation().SlideWidth;
            float slideHeight = this.GetCurrentPresentation().SlideHeight;

            if (selectedShapes == null || selectedShapes.Count < minNoOfSelectedShapes)
            {
                _errorHandler.ProcessErrorCode(ResizeLabErrorHandler.ErrorCodeInvalidSelection, errorParameters);
                return;
            }

            ModifySelectionAspectRatio();
            ExecuteResizeAction(selectedShapes, slideWidth, slideHeight, resizeAction);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get the width of the reference shape.
        /// </summary>
        /// <param name="selectedShapes"></param>
        /// <returns></returns>
        private float GetReferenceWidth(PowerPoint.ShapeRange selectedShapes)
        {
            if (selectedShapes.Count <= 0)
            {
                return(-1);
            }
            switch (ResizeType)
            {
            case ResizeBy.Visual:
                return(new PPShape(selectedShapes[1]).AbsoluteWidth);

            case ResizeBy.Actual:
                return(new PPShape(selectedShapes[1], false).ShapeWidth);
            }
            return(-1);
        }
Ejemplo n.º 10
0
        private void PreviewHandler(Action <PowerPoint.ShapeRange> previewAction, int minNoOfSelectedShapes)
        {
            Focus();
            _previewCallBack = delegate
            {
                PowerPoint.ShapeRange selectedShapes = GetSelectedShapes();

                ModifySelectionAspectRatio();
                Preview(selectedShapes, previewAction, minNoOfSelectedShapes);
                _isPreviewed = true;
            };
            if (IsPreviewKeyPressed())
            {
                _previewCallBack.Invoke();
            }
        }
Ejemplo n.º 11
0
        public void TestAlignOneHorizontalDefault()
        {
            PositionsLabSettings.AlignReference = PositionsLabSettings.AlignReferenceObject.PowerpointDefaults;
            _shapeNames = new List <string> {
                RotatedRectangle
            };
            PowerPoint.ShapeRange actualShapes = GetShapes(OriginalShapesSlideNo, _shapeNames);
            float slideHeight = Pres.PageSetup.SlideHeight;

            PositionsLabMain.AlignHorizontalCenter(actualShapes, slideHeight);

            PpOperations.SelectSlide(AlignOneShapeHorizontalDefaultNo);
            PowerPoint.ShapeRange expectedShapes = PpOperations.SelectShapes(_shapeNames);

            CheckShapes(expectedShapes, actualShapes);
        }
Ejemplo n.º 12
0
        public void TestAlignVerticalDefault()
        {
            PositionsLabSettings.AlignReference = PositionsLabSettings.AlignReferenceObject.PowerpointDefaults;
            _shapeNames = new List <string> {
                UnrotatedRectangle, Oval, RotatedArrow, RotatedRectangle
            };
            PowerPoint.ShapeRange actualShapes = GetShapes(OriginalShapesSlideNo, _shapeNames);
            float slideWidth = Pres.PageSetup.SlideWidth;

            PositionsLabMain.AlignVerticalCenter(actualShapes, slideWidth);

            PpOperations.SelectSlide(AlignShapesVerticalDefaultNo);
            PowerPoint.ShapeRange expectedShapes = PpOperations.SelectShapes(_shapeNames);

            CheckShapes(expectedShapes, actualShapes);
        }
Ejemplo n.º 13
0
 private void button5_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes && ((!sel.HasChildShapeRange && (sel.ShapeRange.Type == Microsoft.Office.Core.MsoShapeType.msoPicture || sel.ShapeRange.Fill.Type == Microsoft.Office.Core.MsoFillType.msoFillPicture)) || (sel.HasChildShapeRange && (sel.ChildShapeRange.Type == Microsoft.Office.Core.MsoShapeType.msoPicture || sel.ChildShapeRange.Fill.Type == Microsoft.Office.Core.MsoFillType.msoFillPicture))))
     {
         PowerPoint.ShapeRange range = sel.ShapeRange;
         if (sel.HasChildShapeRange)
         {
             range = sel.ChildShapeRange;
         }
         else
         {
             range = sel.ShapeRange;
         }
         PowerPoint.Shape pic = range[1];
         if (h0 == 0)
         {
             h0            = pic.PictureFormat.Crop.PictureHeight;
             w0            = pic.PictureFormat.Crop.PictureWidth;
             id            = pic.Id;
             textBox2.Text = PtoCM(pic.PictureFormat.Crop.PictureHeight).ToString();
             textBox3.Text = PtoCM(pic.PictureFormat.Crop.PictureWidth).ToString();
         }
         else
         {
             if (pic.Id == id)
             {
                 pic.PictureFormat.Crop.PictureHeight = h0;
                 pic.PictureFormat.Crop.PictureWidth  = w0;
                 textBox2.Text = PtoCM(pic.PictureFormat.Crop.PictureHeight).ToString();
                 textBox3.Text = PtoCM(pic.PictureFormat.Crop.PictureWidth).ToString();
             }
             else
             {
                 h0            = pic.PictureFormat.Crop.PictureHeight;
                 w0            = pic.PictureFormat.Crop.PictureWidth;
                 id            = pic.Id;
                 textBox2.Text = PtoCM(pic.PictureFormat.Crop.PictureHeight).ToString();
                 textBox3.Text = PtoCM(pic.PictureFormat.Crop.PictureWidth).ToString();
             }
         }
     }
     else
     {
         MessageBox.Show("请先选择一张图片");
     }
 }
Ejemplo n.º 14
0
        protected void ExecutePositionsAction(Action <PowerPoint.ShapeRange> positionsAction, PowerPoint.ShapeRange selectedShapes,
                                              bool isConvertPPShape = true)
        {
            if (selectedShapes == null || selectedShapes.Count == 0)
            {
                throw new Exception(ErrorInvalidShapesSelected);
            }

            PowerPoint.ShapeRange simulatedShapes = null;

            try
            {
                simulatedShapes = DuplicateShapes(selectedShapes);

                if (PositionsLabSettings.AlignReference == PositionsLabSettings.AlignReferenceObject.PowerpointDefaults)
                {
                    positionsAction.Invoke(selectedShapes);
                }
                else if (isConvertPPShape)
                {
                    var simulatedPPShapes = ConvertShapeRangeToPPShapeList(simulatedShapes, 1);
                    var initialPositions  = SaveOriginalPositions(simulatedPPShapes);

                    positionsAction.Invoke(simulatedShapes);

                    SyncShapes(selectedShapes, simulatedShapes, initialPositions);
                }
                else
                {
                    positionsAction.Invoke(simulatedShapes);

                    SyncShapes(selectedShapes, simulatedShapes);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (simulatedShapes != null)
                {
                    simulatedShapes.Delete();
                    GC.Collect();
                }
            }
        }
Ejemplo n.º 15
0
 private void button2_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionNone)
     {
         forms.MessageBox.Show("请至少选择两个形状");
     }
     else
     {
         PowerPoint.ShapeRange range = sel.ShapeRange;
         if (sel.HasChildShapeRange)
         {
             range = sel.ChildShapeRange;
         }
         else
         {
             range = sel.ShapeRange;
         }
         int count = range.Count;
         if (count == 1)
         {
             if (range[1].Type == Office.MsoShapeType.msoGroup)
             {
                 for (int i = 1; i <= range[1].GroupItems.Count; i++)
                 {
                     for (int j = 2; j <= range[1].GroupItems.Count; j++)
                     {
                         range[1].GroupItems[j].Top  = range[1].GroupItems[j - 1].Top;
                         range[1].GroupItems[j].Left = range[1].GroupItems[j - 1].Left + range[1].GroupItems[j - 1].Width;
                     }
                 }
             }
             else
             {
                 MessageBox.Show("请至少选择两个形状");
             }
         }
         else
         {
             for (int i = 2; i <= count; i++)
             {
                 range[i].Left = range[i - 1].Left + range[i - 1].Width;
                 range[i].Top  = range[i - 1].Top;
             }
         }
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Resize the selected shapes to the same size (width and height) with
        /// the reference to first selected shape.
        /// </summary>
        /// <param name="selectedShapes"></param>
        public void ResizeToSameHeightAndWidth(PowerPoint.ShapeRange selectedShapes)
        {
            var isAspectRatio = selectedShapes.LockAspectRatio;

            selectedShapes.LockAspectRatio = MsoTriState.msoFalse;
            switch (ResizeType)
            {
            case ResizeBy.Visual:
                ResizeVisualShapes(selectedShapes, Dimension.HeightAndWidth);
                break;

            case ResizeBy.Actual:
                ResizeActualShapes(selectedShapes, Dimension.HeightAndWidth);
                break;
            }
            selectedShapes.LockAspectRatio = isAspectRatio;
        }
Ejemplo n.º 17
0
        public static bool IsShapeRangeShapeOrText(ShapeRange selectedShapes)
        {
            if ((selectedShapes == null))
            {
                return(false);
            }

            foreach (Shape shape in selectedShapes)
            {
                if (shape.Type == MsoShapeType.msoPlaceholder)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 18
0
        public void TestAlignLeftToSlide()
        {
            PositionsLabSettings.AlignReference = PositionsLabSettings.AlignReferenceObject.Slide;
            _shapeNames = new List <string> {
                UnrotatedRectangle, Oval, RotatedArrow, RotatedRectangle
            };
            PowerPoint.ShapeRange actualShapes = GetShapes(OriginalShapesSlideNo, _shapeNames);

            Action <PowerPoint.ShapeRange> positionsAction = shapes => PositionsLabMain.AlignLeft(shapes);

            ExecutePositionsAction(positionsAction, actualShapes);

            PpOperations.SelectSlide(AlignShapesLeftToSlideNo);
            PowerPoint.ShapeRange expectedShapes = PpOperations.SelectShapes(_shapeNames);

            CheckShapes(expectedShapes, actualShapes);
        }
Ejemplo n.º 19
0
        public void TestAdjoinHorizontalWithoutAlignWithRotatedRef()
        {
            PositionsLabMain.AdjoinWithoutAligning();
            _shapeNames = new List <string> {
                RotatedRectangle, UnrotatedRectangle, Oval, RotatedArrow
            };
            PowerPoint.ShapeRange actualShapes = GetShapes(OriginalShapesSlideNo, _shapeNames);

            Action <List <PPShape> > positionsAction = (shapes) => PositionsLabMain.AdjoinHorizontal(shapes);

            ExecutePositionsAction(positionsAction, actualShapes);

            PpOperations.SelectSlide(AdjoinHorizontalWithoutAlignWithRotatedRef);
            PowerPoint.ShapeRange expectedShapes = PpOperations.SelectShapes(_shapeNames);

            CheckShapes(expectedShapes, actualShapes);
        }
Ejemplo n.º 20
0
        public static PowerPoint.ShapeRange UngroupAllForShapeRange(PowerPoint.ShapeRange range, bool remove = true)
        {
            var ungroupedShapeNames = new List <string>();
            var queue = new Queue <PowerPoint.Shape>();

            foreach (var item in range)
            {
                queue.Enqueue(item as PowerPoint.Shape);
            }
            while (queue.Count != 0)
            {
                var shape = queue.Dequeue();
                if (shape.Type == Office.MsoShapeType.msoGroup)
                {
                    var subRange = shape.Ungroup();
                    foreach (var item in subRange)
                    {
                        queue.Enqueue(item as PowerPoint.Shape);
                    }
                }
                else if ((int)shape.Rotation != 0)
                {
                    if (remove)
                    {
                        RemoveShapesForUngroupAll(shape, ungroupedShapeNames, queue);
                    }

                    ThrowErrorCode(ErrorCodeForRotationNonZero);
                }
                else if (!IsShape(shape))
                {
                    if (remove)
                    {
                        RemoveShapesForUngroupAll(shape, ungroupedShapeNames, queue);
                    }

                    ThrowErrorCode(ErrorCodeForSelectionNonShape);
                }
                else
                {
                    shape.Name += Guid.NewGuid().ToString();
                    ungroupedShapeNames.Add(shape.Name);
                }
            }
            return(PowerPointCurrentPresentationInfo.CurrentSlide.Shapes.Range(ungroupedShapeNames.ToArray()));
        }
Ejemplo n.º 21
0
        public static PowerPoint.ShapeRange Crop(PowerPoint.ShapeRange shapeRange, float aspectRatio)
        {
            bool hasChange = false;

            for (int i = 1; i <= shapeRange.Count; i++)
            {
                PowerPoint.ShapeRange origShape = shapeRange[i].Duplicate();
                origShape.ScaleWidth(1, Office.MsoTriState.msoTrue);
                origShape.ScaleHeight(1, Office.MsoTriState.msoTrue);
                float origWidth  = origShape.Width;
                float origHeight = origShape.Height;
                origShape.Delete();

                float currentWidth       = shapeRange[i].Width - (shapeRange[i].PictureFormat.CropLeft + shapeRange[i].PictureFormat.CropRight) / origWidth;
                float currentHeight      = shapeRange[i].Height - (shapeRange[i].PictureFormat.CropTop + shapeRange[i].PictureFormat.CropBottom) / origHeight;
                float currentProportions = currentWidth / currentHeight;

                if (IsApproximatelyEquals(currentProportions, aspectRatio))
                {
                    continue;
                }
                else if (currentProportions > aspectRatio)
                {
                    // Crop the width
                    float desiredWidth = currentHeight * aspectRatio;
                    float widthToCrop  = origWidth * ((currentWidth - desiredWidth) / currentWidth);
                    CropHorizontal(shapeRange[i], widthToCrop);
                    hasChange = true;
                }
                else if (currentProportions < aspectRatio)
                {
                    // Crop the height
                    float desiredHeight = currentWidth / aspectRatio;
                    float heightToCrop  = origHeight * ((currentHeight - desiredHeight) / currentHeight);
                    CropVertical(shapeRange[i], heightToCrop);
                    hasChange = true;
                }
            }

            if (!hasChange)
            {
                throw new CropLabException(CropLabErrorHandler.ErrorCodeNoAspectRatioCropped.ToString());
            }

            return(shapeRange);
        }
Ejemplo n.º 22
0
 private static void CopyShapesTo(ShapeRange refShapes, PowerPointSlide candidate)
 {
     foreach (Shape shape in refShapes)
     {
         try
         {
             shape.Copy();
             candidate.Shapes.Paste();
         }
         catch (COMException)
         {
             // A COMException occurs if you try to copy paste an empty placeholder shape. So I catch it here.
             // I can't figure out any other way to detect that it's an empty placeholder shape.
             // You know, those things like "Click to add title..."
         }
     }
 }
        public void TestDistributeAngleAtSecondWithEdgesDynamicShapeOrientation()
        {
            PositionsLabSettings.DistributeRadialReference  = PositionsLabSettings.DistributeRadialReferenceObject.AtSecondShape;
            PositionsLabSettings.DistributeSpaceReference   = PositionsLabSettings.DistributeSpaceReferenceObject.ObjectBoundary;
            PositionsLabSettings.DistributeShapeOrientation = PositionsLabSettings.RadialShapeOrientationObject.Dynamic;

            PowerPoint.ShapeRange actualShapes = GetShapes(OriginalShapesSlideNo, _shapeNames);

            Action <PowerPoint.ShapeRange> positionsAction = (shapes) => PositionsLabMain.DistributeRadial(shapes);

            ExecutePositionsAction(positionsAction, actualShapes, isConvertPPShape: false);

            PpOperations.SelectSlide(DistributeAngleAtSecondWithEdgesDynamicShapeOrientationSlide);
            PowerPoint.ShapeRange expectedShapes = PpOperations.SelectShapes(_shapeNames);

            CheckShapes(expectedShapes, actualShapes);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Configrue the shape mode bar to an appropriate state based on the current
        /// selection.
        /// </summary>
        private void ConfigureShapeModeBar()
        {
            // DONE CMPRINCE: Make this work correctly
            PowerPoint.ShapeRange shapes = this.myPPT.GetSelectedShapes();
            if (shapes == null || shapes.Count == 0)
            {
                // DONE CMPRINCE: Make this work correctly
                this.DisableShapesBar();
                return;
            }

            // Figure out on which restrictions the selection agrees.
            IDictionary restrictionTable = new Hashtable();
            int         count            = 0;

            foreach (PowerPoint.Shape shape in shapes)
            {
                this.CountRestrictions(shape, restrictionTable, ref count);
            }

            // Set all buttons to enabled but only those on which the selection agrees to down.
            // ProjectedSetButton
            this.ribbon.ProjectedSetEnabled = true;
            if (restrictionTable.Contains(this.myModes[0]) &&
                (int)restrictionTable[this.myModes[0]] == count)
            {
                this.ribbon.UnrestrictedState = true;
            }
            else
            {
                this.ribbon.UnrestrictedState = false;
            }

            // InstructorSetButton
            this.ribbon.InstructorSetEnabled = true;
            if (restrictionTable.Contains(this.myModes[1]) &&
                (int)restrictionTable[this.myModes[1]] == count)
            {
                this.ribbon.UnrestrictedState = false;
            }
            else
            {
                this.ribbon.UnrestrictedState = true;
            }
        }
Ejemplo n.º 25
0
        private void button2_Click(object sender, EventArgs e)
        {
            PowerPoint.Selection sel = app.ActiveWindow.Selection;
            if (sel.Type == PowerPoint.PpSelectionType.ppSelectionNone || sel.ShapeRange.Count > 1)
            {
                forms.MessageBox.Show("只支持单个图形的旋转复制");
            }
            else
            {
                PowerPoint.ShapeRange range = sel.ShapeRange;
                if (sel.HasChildShapeRange)
                {
                    range = sel.ChildShapeRange;
                }
                else
                {
                    range = sel.ShapeRange;
                }
                PowerPoint.Shape shape = range[1];

                int   n  = int.Parse(textBox1.Text.Trim()) - 1;
                float r0 = float.Parse(textBox2.Text.Trim());
                for (int i = 1; i <= n; i++)
                {
                    PowerPoint.Shape nshape = shape.Duplicate()[1];
                    nshape.ThreeD.IncrementRotationY(-r0 * i);
                    if (checkBox1.Checked)
                    {
                        float a = shape.ThreeD.BevelTopDepth;
                        float b = shape.ThreeD.BevelBottomDepth;
                        float c = shape.ThreeD.Depth;
                        if (shape.ThreeD.Visible != Office.MsoTriState.msoTrue)
                        {
                            shape.ThreeD.Visible = Office.MsoTriState.msoTrue;
                            c = shape.ThreeD.Depth - 36;
                        }
                        shape.ThreeD.Z  = (float)(shape.Width / 2 / Math.Tan(r0 * Math.PI / 360)) + a + b + c;
                        nshape.ThreeD.Z = shape.ThreeD.Z;
                    }
                    nshape.Left = shape.Left;
                    nshape.Top  = shape.Top;
                    nshape.ZOrder(Office.MsoZOrderCmd.msoSendToBack);
                }
            }
        }
Ejemplo n.º 26
0
        private void PreviewHandler(Action <PowerPoint.ShapeRange, float, float, bool> previewAction)
        {
            Focus();
            _previewCallBack = delegate
            {
                PowerPoint.ShapeRange selectedShapes = GetSelectedShapes();
                float slideWidth  = this.GetCurrentPresentation().SlideWidth;
                float slideHeight = this.GetCurrentPresentation().SlideHeight;

                ModifySelectionAspectRatio();
                Preview(selectedShapes, slideWidth, slideHeight, previewAction);
                _isPreviewed = true;
            };
            if (IsPreviewKeyPressed())
            {
                _previewCallBack.Invoke();
            }
        }
Ejemplo n.º 27
0
        public void TestAlignRightToSlide()
        {
            PositionsLabSettings.AlignReference = PositionsLabSettings.AlignReferenceObject.Slide;
            _shapeNames = new List <string> {
                UnrotatedRectangle, Oval, RotatedArrow, RotatedRectangle
            };
            PowerPoint.ShapeRange actualShapes = GetShapes(OriginalShapesSlideNo, _shapeNames);
            float slideWidth = Pres.PageSetup.SlideWidth;

            Action <PowerPoint.ShapeRange, float> positionsAction = (shapes, width) => PositionsLabMain.AlignRight(shapes, width);

            ExecutePositionsAction(positionsAction, actualShapes, slideWidth);

            PpOperations.SelectSlide(AlignShapesRightToSlideNo);
            PowerPoint.ShapeRange expectedShapes = PpOperations.SelectShapes(_shapeNames);

            CheckShapes(expectedShapes, actualShapes);
        }
Ejemplo n.º 28
0
        private void SlightAdjustVisualShape(PowerPoint.ShapeRange shapes, Action <PPShape> resizeAction)
        {
            try
            {
                foreach (PowerPoint.Shape shape in shapes)
                {
                    PPShape ppShape = new PPShape(shape);
                    System.Drawing.PointF anchorPoint = GetVisualAnchorPoint(ppShape);

                    resizeAction(ppShape);
                    AlignVisualShape(ppShape, anchorPoint);
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e, "SlightAdjustVisualShape");
            }
        }
Ejemplo n.º 29
0
        private void SlightAdjustActualShape(PowerPoint.ShapeRange shapes, Action <PPShape> resizeAction)
        {
            try
            {
                foreach (PowerPoint.Shape shape in shapes)
                {
                    var ppShape     = new PPShape(shape, false);
                    var anchorPoint = GetActualAnchorPoint(ppShape);

                    resizeAction(ppShape);
                    AlignActualShape(ppShape, anchorPoint);
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e, "SlightAdjustActualShape");
            }
        }
Ejemplo n.º 30
0
        protected PowerPoint.ShapeRange DuplicateShapes(PowerPoint.ShapeRange range)
        {
            int totalShapes = PpOperations.GetCurrentSlide().Shapes.Count;

            int[] duplicatedShapeIndices = new int[range.Count];

            for (int i = 1; i <= range.Count; i++)
            {
                var shape      = range[i];
                var duplicated = shape.Duplicate()[1];
                duplicated.Name = shape.Id + "";
                duplicated.Left = shape.Left;
                duplicated.Top  = shape.Top;
                duplicatedShapeIndices[i - 1] = totalShapes + i;
            }

            return(PpOperations.GetCurrentSlide().Shapes.Range(duplicatedShapeIndices));
        }
Ejemplo n.º 31
0
        private Color GetSelectedShapeColor(PowerPoint.ShapeRange selectedShapes)
        {
            Color colorToReturn = Color.Empty;

            foreach (object selectedShape in selectedShapes)
            {
                Color color = GetSelectedShapeColor(selectedShape as PowerPoint.Shape);
                if (colorToReturn.Equals(Color.Empty))
                {
                    colorToReturn = color;
                }
                else if (!colorToReturn.Equals(color))
                {
                    return(Color.Black);
                }
            }
            return(colorToReturn);
        }
        public ShapeRange SelectShapesByPrefix(string prefix)
        {
            if (CurrentSlide == null) return null;

            var nameList = new List<string>();
            foreach (Shape shape in CurrentSlide.Shapes)
            {
                if (shape.Name.StartsWith(prefix))
                {
                    nameList.Add(shape.Name);
                }
            }
            _currentShape = CurrentSlide.Shapes.Range(nameList.ToArray());
            return _currentShape;
        }
Ejemplo n.º 33
0
        private void SelectShapes()
        {
            try
            {
                var selection = PowerPointCurrentPresentationInfo.CurrentSelection;
                if (selection == null) return;

                if (selection.Type == PpSelectionType.ppSelectionShapes &&
                    selection.HasChildShapeRange)
                {
                    _selectedShapes = selection.ChildShapeRange;
                }
                else if (selection.Type == PpSelectionType.ppSelectionShapes)
                {
                    _selectedShapes = selection.ShapeRange;
                }
                else if (selection.Type == PpSelectionType.ppSelectionText)
                {
                    _selectedText = selection.TextRange;
                }
                else
                {
                    _selectedShapes = null;
                    _selectedText = null;
                }
            }
            catch (Exception)
            {
                _selectedShapes = null;
                _selectedText = null;
            }
        }
        public ShapeRange SelectShape(string shapeName)
        {
            if (CurrentSlide == null) return null;

            var nameList = new List<string>();
            nameList.Add(shapeName);
            _currentShape = CurrentSlide.Shapes.Range(nameList.ToArray());
            return _currentShape;
        }
Ejemplo n.º 35
0
 //评分核心函数
 public int check_Kernel(List<OfficeElement> ls)
 {
     int points = 0, i;
     int curPart = -1;               //当前正在分析哪一部分的考点
     for (i = 0; i < ls.Count; i++)
     {
         OfficeElement oe = ls[i];
         #region 具体考点对象定位
         if (oe.AttribName == "Root")
             continue;
         if (oe.AttribName == "Presentations")
             continue;
         if (oe.AttribName == "Slide")
         {
             #region 幻灯片定位
             try
             {
                 int slideId = int.Parse(oe.AttribValue);
                 stuSld = stuPpt.Slides[slideId];
                 ansSld = ansPpt.Slides[slideId];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_SLIDE;
             continue;
         }
         if (oe.AttribName == "Background")
         {
             #region 幻灯片背景定位
             try
             {
                 stuBg = stuSld.Background;
                 ansBg = ansSld.Background;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_BACKGROUND;
             continue;
         }
         if (oe.AttribName == "Transition")
         {
             #region 过渡动画定位
             try
             {
                 stuTrans = stuSld.SlideShowTransition;
                 ansTrans = ansSld.SlideShowTransition;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_TRANSITION;
             continue;
         }
         if (oe.AttribName == "Effects")
         {
             continue;
         }
         if (oe.AttribName == "Effect")
         {
             #region 幻灯片动画定位
             try
             {
                 int effId = int.Parse(oe.AttribValue);
                 stuEffect = stuSld.TimeLine.MainSequence[effId];
                 ansEffect = ansSld.TimeLine.MainSequence[effId];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_EFFECT;
             continue;
         }
         if (oe.AttribName == "Shape")
         {
             #region Shape定位
             try
             {
                 int shapeId = int.Parse(oe.AttribValue);
                 stuShape = stuSld.Shapes[shapeId];
                 ansShape = ansSld.Shapes[shapeId];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_SHAPE;
             continue;
         }
         if (oe.AttribName == "Location")
         {
             curPart = PART_LOCATION;
             continue;
         }
         if (oe.AttribName == "Picture")
         {
             #region 图片属性定位
             try
             {
                 stuPf = stuShape.PictureFormat;
                 ansPf = ansShape.PictureFormat;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_PICTURE;
             continue;
         }
         if (oe.AttribName == "Run")
         {
             #region 文字部分定位
             try
             {
                 int runId = int.Parse(oe.AttribValue);
                 stuTr = stuShape.TextFrame.TextRange.Runs(0, 100);
                 ansTr = ansShape.TextFrame.TextRange.Runs(0, 100);
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_TEXTRANGE;
             continue;
         }
         if (oe.AttribName == "WordArt")
         {
             #region 艺术字定位
             try
             {
                 stuTf = stuShape.TextEffect;
                 ansTf = ansShape.TextEffect;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_WORDART;
             continue;
         }
         if (oe.AttribName == "ThreeD")
         {
             #region 三维属性定位
             try
             {
                 stu3d = stuShape.ThreeD;
                 ans3d = ansShape.ThreeD;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_3D;
             continue;
         }
         if (oe.AttribName == "Animation")
         {
             #region 自定义动画定位
             try
             {
                 stuAm = stuShape.AnimationSettings;
                 ansAm = ansShape.AnimationSettings;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_ANIMATION;
             continue;
         }
         if (oe.AttribName == "ClickAction")
         {
             #region 单击动作定位
             try
             {
                 stuAcs = stuShape.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick];
                 ansAcs = ansShape.ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_ACTION;
             continue;
         }
         if (oe.AttribName == "MoveAction")
         {
             #region 鼠标移动动作定位
             try
             {
                 stuAcs = stuShape.ActionSettings[PowerPoint.PpMouseActivation.ppMouseOver];
                 ansAcs = ansShape.ActionSettings[PowerPoint.PpMouseActivation.ppMouseOver];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_ACTION;
             continue;
         }
         #endregion
         #region 幻灯片判分
         if (curPart == PART_SLIDE)
         {
             switch (oe.AttribName)
             {
                 case "SlideName":
                     if (stuSld.Name == ansSld.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "SlideIndex":
                     if (stuSld.SlideIndex == ansSld.SlideIndex)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Layout":
                     if (stuSld.Layout == ansSld.Layout)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 幻灯片背景判分
         if (curPart == PART_BACKGROUND)
         {
             switch (oe.AttribName)
             {
                 case "Fill":
                     if (stuBg.Fill.Type.Equals(ansBg.Fill.Type))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "GradientType":
                     if (stuBg.Fill.PresetGradientType == ansBg.Fill.PresetGradientType)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "GradientStyle":
                     if (stuBg.Fill.GradientStyle == ansBg.Fill.GradientStyle)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 幻灯片过渡动画判分
         if (curPart == PART_TRANSITION)
         {
             switch (oe.AttribName)
             {
                 case "AdvanceOnClick":
                     if (stuTrans.AdvanceOnClick.Equals(ansTrans.AdvanceOnClick))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "AdvanceOnTime":
                     if (stuTrans.AdvanceOnTime.Equals(ansTrans.AdvanceOnTime))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "AdvanceTime":
                     if (stuTrans.AdvanceTime == ansTrans.AdvanceTime)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "EntryEffect":
                     if (stuTrans.EntryEffect.Equals(ansTrans.EntryEffect))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Speed":
                     if (stuTrans.Speed.Equals(ansTrans.Speed))
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 幻灯片动画判分
         if (curPart == PART_EFFECT)
         {
             switch (oe.AttribName)
             {
                 case "DisplayName":
                     if (stuEffect.DisplayName == ansEffect.DisplayName)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "EffectType":
                     if (stuEffect.EffectType.Equals(ansEffect.EffectType))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Exit":
                     if (stuEffect.Exit.Equals(ansEffect.Exit))
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Index":
                     if (stuEffect.Index == ansEffect.Index)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "ShapeName":
                     if (stuEffect.Shape.Name == ansEffect.Shape.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Duration":
                     if (stuEffect.Timing.Duration == ansEffect.Timing.Duration)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Paragraph":
                     try
                     {
                         if (stuEffect.Paragraph == ansEffect.Paragraph)
                             points = int.Parse(oe.AttribValue);
                     }
                     catch { points = 0; }
                     break;
                 case "TextRangeStart":
                     try
                     {
                         if (stuEffect.TextRangeStart == ansEffect.TextRangeStart)
                             points = int.Parse(oe.AttribValue);
                     }
                     catch { points = 0; }
                     break;
                 case "TextRangeLength":
                     try
                     {
                         if (stuEffect.TextRangeLength == ansEffect.TextRangeLength)
                             points = int.Parse(oe.AttribValue);
                     }
                     catch { points = 0; }
                     break;
             }
             continue;
         }
         #endregion
         #region 幻灯片对象判分
         if (curPart == PART_SHAPE)
         {
             continue;
         }
         #endregion
         #region 对象类型、定位判分
         if (curPart == PART_LOCATION)
         {
             switch (oe.AttribName)
             {
                 case "ShapeName":
                     if (stuShape.Name == ansShape.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Type":
                     if (stuShape.Type == ansShape.Type)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Top":
                     if (stuShape.Top == ansShape.Top)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Left":
                     if (stuShape.Left == ansShape.Left)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Height":
                     if (stuShape.Height == ansShape.Height)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Width":
                     if (stuShape.Width == ansShape.Width)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 图片属性判分
         if (curPart == PART_PICTURE)
         {
             switch (oe.AttribName)
             {
                 case "CropLeft":
                     if (stuPf.CropLeft == ansPf.CropLeft)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CropTop":
                     if (stuPf.CropTop == ansPf.CropTop)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CropRight":
                     if (stuPf.CropRight == ansPf.CropRight)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CropBottom":
                     if (stuPf.CropBottom == ansPf.CropBottom)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 文本属性判分
         if (curPart == PART_TEXTRANGE)
         {
             switch (oe.AttribName)
             {
                 case "Text":
                     if (stuTr.Text == ansTr.Text)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Bold":
                     if (stuTr.Font.Bold == ansTr.Font.Bold)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Italic":
                     if (stuTr.Font.Italic == ansTr.Font.Italic)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Underline":
                     if (stuTr.Font.Underline == ansTr.Font.Underline)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontName":
                     if (stuTr.Font.Name == ansTr.Font.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontSize":
                     if (stuTr.Font.Size == ansTr.Font.Size)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Shadow":
                     if (stuTr.Font.Shadow == ansTr.Font.Shadow)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Superscript":
                     if (stuTr.Font.Superscript == ansTr.Font.Superscript)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Subscript":
                     if (stuTr.Font.Subscript == ansTr.Font.Subscript)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "ForeColor":
                     if (stuTr.Font.Color.RGB == ansTr.Font.Color.RGB)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 艺术字属性判分
         if (curPart == PART_WORDART)
         {
             switch (oe.AttribName)
             {
                 case "Text":
                     if (stuTf.Text == ansTf.Text)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Bold":
                     if (stuTf.FontBold == ansTf.FontBold)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Italic":
                     if (stuTf.FontItalic == ansTf.FontItalic)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontName":
                     if (stuTf.FontName == ansTf.FontName)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontSize":
                     if (stuTf.FontSize == ansTf.FontSize)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Alignment":
                     if (stuTf.Alignment.ToString() == ansTf.Alignment.ToString())
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "PresetShape":
                     if (stuTf.PresetShape.ToString() == ansTf.PresetShape.ToString())
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "RotatedChars":
                     if (stuTf.RotatedChars.ToString() == ansTf.RotatedChars.ToString())
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Tracking":
                     if (stuTf.Tracking.ToString() == ansTf.Tracking.ToString())
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 三维属性判分
         if (curPart == PART_3D)
         {
             switch (oe.AttribName)
             {
                 case "ThreeDFormat":
                     if (stu3d.PresetThreeDFormat == ans3d.PresetThreeDFormat)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LightingDirection":
                     if (stu3d.PresetLightingDirection == ans3d.PresetLightingDirection)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LightingSoftness":
                     if (stu3d.PresetLightingSoftness == ans3d.PresetLightingSoftness)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Material":
                     if (stu3d.PresetMaterial == ans3d.PresetMaterial)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Depth":
                     if (stu3d.Depth == ans3d.Depth)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "ExtrusionDirection":
                     if (stu3d.PresetExtrusionDirection == ans3d.PresetExtrusionDirection)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 自定义动画判分
         if (curPart == PART_ANIMATION)
         {
             switch (oe.AttribName)
             {
                 case "AnimationOrder":
                     if (stuAm.AnimationOrder == ansAm.AnimationOrder)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "EntryEffect":
                     if (stuAm.EntryEffect == ansAm.EntryEffect)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "AdvanceMode":
                     if (stuAm.AdvanceMode == ansAm.AdvanceMode)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "AdvanceTime":
                     if (stuAm.AdvanceTime == ansAm.AdvanceTime)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 对象动作判分
         if (curPart == PART_ACTION)
         {
             switch (oe.AttribName)
             {
                 case "Action":
                     if (stuAcs.Action == ansAcs.Action)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "HyperlinkAddr":
                     if (stuAcs.Hyperlink.Address == ansAcs.Hyperlink.Address)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "HyperlinkSubAddr":
                     if (stuAcs.Hyperlink.SubAddress == ansAcs.Hyperlink.SubAddress)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
     }
     return points;
 }
 public ShapeRange SelectShapes(IEnumerable<string> shapeNames)
 {
     if (CurrentSlide == null) return null;
     _currentShape = CurrentSlide.Shapes.Range(shapeNames.ToArray());
     return _currentShape;
 }
 private static void CopyShapesTo(ShapeRange refShapes, PowerPointSlide candidate)
 {
     foreach (Shape shape in refShapes)
     {
         try
         {
             shape.Copy();
             candidate.Shapes.Paste();
         }
         catch (COMException)
         {
             // A COMException occurs if you try to copy paste an empty placeholder shape. So I catch it here.
             // I can't figure out any other way to detect that it's an empty placeholder shape.
             // You know, those things like "Click to add title..."
         }
     }
 }
        /// <summary>
        /// Copies the shaperange into this slide, without the usual position offset when pasting over an existing shape.
        /// If you are having difficulty getting a shaperange, use the ToShapeRange method.
        /// TODO: Test this method more thoroughly in more cases other than Graphics.SquashSlides
        /// </summary>
        public ShapeRange CopyShapesToSlide(ShapeRange shapes)
        {
            // First Index all the shapes by name, so they can be identified later.
            int index = 0;
            var originalShapes = new Dictionary<string, Shape>();
            var originalNames = new Dictionary<string, string>();
            foreach (Shape shape in shapes)
            {
                var tempName = index.ToString();
                index++;

                originalNames.Add(tempName, shape.Name);
                originalShapes.Add(tempName, shape);
                // temporarily set the name before copy, so we can locate it again in the new slide.
                shape.Name = tempName;
            }

            // Copy all the shapes over.
            shapes.Copy();
            var newShapes = _slide.Shapes.Paste();

            // Now use the indexed names to set back the names and positions to the original shapes'
            foreach (Shape shape in newShapes)
            {
                var key = shape.Name;
                var originalName = originalNames[key];
                var originalShape = originalShapes[key];

                originalShape.Name = originalName;
                shape.Name = originalName;
                shape.Left = originalShape.Left;
                shape.Top = originalShape.Top;
            }

            return newShapes;
        }
Ejemplo n.º 39
0
 public static void MakeShapeViewTimeInvisible(ShapeRange shapeRange, Slide curSlide)
 {
     foreach (Shape shape in shapeRange)
     {
         MakeShapeViewTimeInvisible(shape, curSlide);
     }
 }
Ejemplo n.º 40
0
 public static void MakeShapeViewTimeInvisible(ShapeRange shapeRange, PowerPointSlide curSlide)
 {
     MakeShapeViewTimeInvisible(shapeRange, curSlide.GetNativeSlide());
 }
Ejemplo n.º 41
0
        public static void SyncShapeRange(ShapeRange refShapeRange, ShapeRange candidateShapeRange)
        {
            // all names of identical shapes should be consistent
            if (refShapeRange.Count != candidateShapeRange.Count)
            {
                return;
            }

            foreach (var shape in candidateShapeRange)
            {
                var candidateShape = shape as Shape;
                var refShape = refShapeRange.Cast<Shape>().FirstOrDefault(item => IsSameType(item, candidateShape) &&
                                                                                  IsSamePosition(item, candidateShape,
                                                                                                 false, 15) &&
                                                                                  IsSameSize(item, candidateShape));

                if (candidateShape == null || refShape == null) continue;

                candidateShape.Name = refShape.Name;
            }
        }