public void CropMultipleShapesSuccessfully() { Microsoft.Office.Interop.PowerPoint.Slide actualSlide = PpOperations.SelectSlide(7); Microsoft.Office.Interop.PowerPoint.ShapeRange shapesBeforeCrop = PpOperations.SelectShapesByPrefix("selectMe"); Assert.AreEqual(6, shapesBeforeCrop.Count); // Execute the Crop To Shape feature PplFeatures.AutoCrop(); // the result shape after crop multiple shapes will have name starts with // Group Microsoft.Office.Interop.PowerPoint.Shape resultShape = PpOperations.SelectShapesByPrefix("Group")[1]; System.IO.FileInfo resultShapeInPic = PpOperations.ExportSelectedShapes(); Microsoft.Office.Interop.PowerPoint.Slide expSlide = PpOperations.SelectSlide(8); Microsoft.Office.Interop.PowerPoint.Shape expShape = PpOperations.SelectShapesByPrefix("Group")[1]; System.IO.FileInfo expShapeInPic = PpOperations.ExportSelectedShapes(); // remove elements that affect comparing slides // e.g. "Expected" textbox PpOperations.SelectShapesByPrefix("text").Delete(); SlideUtil.IsSameLooking(expShape, expShapeInPic, resultShape, resultShapeInPic); SlideUtil.IsSameLooking(expSlide, actualSlide); }
public void TestAdjustAreaProportionallyWithAspectRatio() { _shapeNames = new List <string> { RefShapeName, BlackCornerRectangleName, BlueCornerRectangleName }; InitOriginalShapes(SlideNo.AdjustAreaProportionallyAutoShapeOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNo.AdjustAreaProportionallyAutoShapeOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNo.AdjustAreaProportionallyAutoShapeAspectRatio, _shapeNames); actualShapes.LockAspectRatio = MsoTriState.msoTrue; _resizeLab.ResizeType = ResizeLabMain.ResizeBy.Actual; _resizeLab.AdjustProportionallyProportionList = _proportionList; _resizeLab.AdjustAreaProportionally(actualShapes); CheckShapes(expectedShapes, actualShapes); RestoreShapes(SlideNo.AdjustAreaProportionallyAutoShapeOrigin, _shapeNames); InitOriginalShapes(SlideNo.AdjustAreaProportionallyFreeformOrigin, _shapeNames); actualShapes = GetShapes(SlideNo.AdjustAreaProportionallyFreeformOrigin, _shapeNames); expectedShapes = GetShapes(SlideNo.AdjustAreaProportionallyFreeformAspectRatio, _shapeNames); actualShapes.LockAspectRatio = MsoTriState.msoTrue; _resizeLab.AdjustProportionallyProportionList = _proportionList; _resizeLab.AdjustAreaProportionally(actualShapes); CheckShapes(expectedShapes, actualShapes); RestoreShapes(SlideNo.AdjustAreaProportionallyFreeformOrigin, _shapeNames); }
public void CropOutPaddingRotatedPicture() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNumberRotatedPictureActual, selectOneShapeNames); actualShapes = CropOutPadding.Crop(actualShapes); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNumberRotatedPictureExpected, selectOneShapeNames); CheckShapes(expectedShapes, actualShapes); }
public void CropToAspectRatioMultiplePictures() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNumberMultiplePicturesActual, selectMultipleShapesNames); actualShapes = CropToAspectRatio.Crop(actualShapes, 0.1f); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNumberMultiplePicturesExpected, selectMultipleShapesNames); CheckShapes(expectedShapes, actualShapes); }
public void TestStretchRightWithoutAspectRatio() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNo.StretchOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNo.StretchRight, _shapeNames); _resizeLab.StretchRight(actualShapes); CheckShapes(expectedShapes, actualShapes); }
public void TestGetTextBoxInfoForEmptyTextBoxes() { Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = PpOperations.SelectShapesByPrefix("TextBox"); TextBoxes textBoxes = new TextBoxes(shapes, Pres.PageSetup.SlideWidth, Pres.PageSetup.SlideHeight); TextBoxInfo textBoxInfo = textBoxes.GetTextBoxesInfo(); Assert.AreEqual(null, textBoxInfo); }
public void CropOutPaddingMultipleChildPictures() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNumberMultipleChildPicturesActual, selectMultipleShapesNames); actualShapes = CropOutPadding.Crop(actualShapes); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNumberMultipleChildPicturesExpected, selectMultipleShapesNames); CheckShapes(expectedShapes, actualShapes); }
private void PasteToFillSlide(int originalSlideNo, int expSlideNo) { Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = GetShapesByPrefix(originalSlideNo, ShapeToCopyPrefix); shapes.Cut(); PplFeatures.PasteToFillSlide(); AssertIsSame(originalSlideNo, expSlideNo); }
public void TestStretchRightOuterMost() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNo.StretchOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNo.StretchRightOuterMost, _shapeNames); _resizeLab.ReferenceType = ResizeLabMain.StretchRefType.Outermost; _resizeLab.StretchRight(actualShapes); CheckShapes(expectedShapes, actualShapes); }
public void TestStretchLeftWithAspectRatio() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNo.StretchOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNo.StretchLeftAspectRatio, _shapeNames); actualShapes.LockAspectRatio = MsoTriState.msoTrue; _resizeLab.StretchLeft(actualShapes); CheckShapes(expectedShapes, actualShapes); }
public void TestActualMatchHeight() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNo.MatchOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNo.MatchActualHeight, _shapeNames); _resizeLab.ResizeType = ResizeLabMain.ResizeBy.Actual; _resizeLab.MatchHeight(actualShapes); CheckShapes(expectedShapes, actualShapes); }
private void AddShapesToSlideFromShapesLab(IShapesLabController shapesLab, string shapeName, string expectedShapePrefix) { Point point = shapesLab.GetShapeForClicking(shapeName); // Add shapes from Shapes Lab to slide by double clicking DoubleClick(point); Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = PpOperations.SelectShapesByPrefix(expectedShapePrefix); Assert.IsTrue(shapes.Count > 0, "Failed to add shapes from Shapes Lab."); }
public void TestSlightDecreaseVisualWidthWithoutAspectRatio() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNo.SlightAdjustOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNo.SlightVisualDecreaseWidth, _shapeNames); actualShapes.LockAspectRatio = MsoTriState.msoFalse; _resizeLab.ResizeType = ResizeLabMain.ResizeBy.Visual; _resizeLab.DecreaseWidth(actualShapes); CheckShapes(expectedShapes, actualShapes); }
public void CropAndCompare(int testSlideNo, int expectedSlideNo) { // Execute the Crop To Same feature Microsoft.Office.Interop.PowerPoint.ShapeRange testShapes = GetShapes(testSlideNo, selectMultipleShapesNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expShapes = GetShapes(expectedSlideNo, selectMultipleShapesNames); CropToSame.CropSelection(testShapes); testShapes = GetShapes(testSlideNo, selectMultipleShapesNames); CheckShapes(testShapes, expShapes); }
private void PasteIntoGroup(int originalSlideNo, int expSlideNo) { Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = GetShapesByPrefix(originalSlideNo, ShapeToCopyPrefix); shapes.Cut(); PpOperations.SelectShape(GroupToPaste); PplFeatures.PasteIntoGroup(); AssertIsSame(originalSlideNo, expSlideNo); }
private void AddShapesToSlideFromShapesLab(IShapesLabController shapesLab, string shapeThumbnail, string expectedShapePrefix) { IShapesLabLabeledThumbnail thumbnail = shapesLab.GetLabeledThumbnail(shapeThumbnail); thumbnail.FinishNameEdit(); // Add shapes from Shapes Lab to slide by double clicking DoubleClick(thumbnail as Control); Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = PpOperations.SelectShapesByPrefix(expectedShapePrefix); Assert.IsTrue(shapes.Count > 0, "Failed to add shapes from Shapes Lab."); }
public void TestEqualizeActualWidthWithAspectRatio() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNo.EqualizeOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNo.EqualizeActualWidthAspectRatio, _shapeNames); actualShapes.LockAspectRatio = MsoTriState.msoTrue; _resizeLab.ResizeType = ResizeLabMain.ResizeBy.Actual; _resizeLab.ResizeToSameWidth(actualShapes); CheckShapes(expectedShapes, actualShapes); }
public void TestSlightIncreaseActualHeightWithAspectRatio() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNo.SlightAdjustOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNo.SlightActualIncreaseHeightAspectRatio, _shapeNames); actualShapes.LockAspectRatio = MsoTriState.msoTrue; _resizeLab.ResizeType = ResizeLabMain.ResizeBy.Actual; _resizeLab.IncreaseHeight(actualShapes); CheckShapes(expectedShapes, actualShapes); }
public void TestEqualizeVisualHeightWithoutAspectRatio() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNo.EqualizeOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNo.EqualizeVisualHeight, _shapeNames); actualShapes.LockAspectRatio = MsoTriState.msoFalse; _resizeLab.ResizeType = ResizeLabMain.ResizeBy.Visual; _resizeLab.ResizeToSameHeight(actualShapes); CheckShapes(expectedShapes, actualShapes); }
public void TestFitToFillWithAspectRatio() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNo.FitToSlideOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNo.FitToSlideFillAspectRatio, _shapeNames); float slideWidth = Pres.PageSetup.SlideWidth; float slideHeight = Pres.PageSetup.SlideHeight; _resizeLab.FitToFill(actualShapes, slideWidth, slideHeight, true); CheckShapes(expectedShapes, actualShapes); }
public void TestAdjustActualWidthProportionallyWithAspectRatio() { Microsoft.Office.Interop.PowerPoint.ShapeRange actualShapes = GetShapes(SlideNo.AdjustProportionallyOrigin, _shapeNames); Microsoft.Office.Interop.PowerPoint.ShapeRange expectedShapes = GetShapes(SlideNo.AdjustActualWidthProportionallyAspectRatio, _shapeNames); actualShapes.LockAspectRatio = MsoTriState.msoTrue; _resizeLab.ResizeType = ResizeLabMain.ResizeBy.Actual; _resizeLab.AdjustProportionallyProportionList = _proportionList; _resizeLab.AdjustWidthProportionally(actualShapes); CheckShapes(expectedShapes, actualShapes); }
public TextBoxes(ShapeRange shapes, float slideWidth, float slideHeight) { _slideWidth = slideWidth; _slideHeight = slideHeight; TextShapes = new List<Shape>(); var shape = ShapeUtil.GetTextShapeToProcess(shapes); if (shape != null) { TextShapes.Add(shape); } }
private void IsClipboardRestoredPasteIntoGroup(int originalSlideNo, int expSlideNo) { CheckIfClipboardIsRestored(() => { Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = GetShapesByPrefix(OrigIsClipboardRestoredPasteIntoGroupSlideNo, ShapeToCopyPrefix); // This should be restored to clipboard later shapes.Cut(); PpOperations.SelectShape(GroupToPaste); PplFeatures.PasteIntoGroup(); }, originalSlideNo, ShapeToCopyPrefix, expSlideNo, "", ShapeToCompareCopied); }
private void ReplaceWithClipboard(int originalSlideNo, int expSlideNo) { Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = GetShapesByPrefix(originalSlideNo, ShapeToCopyPrefix); shapes.Cut(); PpOperations.SelectShapes(new List <string> { ShapeToReplace }); PplFeatures.ReplaceWithClipboard(); AssertIsSame(originalSlideNo, expSlideNo); }
private void PasteAtCursorPosition(int originalSlideNo, int expSlideNo) { Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = GetShapesByPrefix(originalSlideNo, ShapeToCopyPrefix); shapes.Cut(); RightClick(GetShapesByPrefix(originalSlideNo, ShapeToClick)[1]); // wait for awhile for click to register properly ThreadUtil.WaitFor(500); PplFeatures.PasteAtCursorPosition(); AssertIsSame(originalSlideNo, expSlideNo); }
public static Shape Crop(PowerPointSlide currentSlide, Selection selection, double magnifyRatio = 1.0, bool isInPlace = false, bool handleError = true) { ShapeRange shapeRange = ShapeUtil.GetShapeRange(selection); Shape croppedShape = Crop(currentSlide, shapeRange, isInPlace: isInPlace, handleError: handleError); if (croppedShape != null) { croppedShape.Select(); } return(croppedShape); }
public void TestStartBoxing() { PpOperations.SelectSlide(2); Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = PpOperations.SelectShapesByPrefix("TextBox"); TextBoxes textBoxes = new TextBoxes(shapes, Pres.PageSetup.SlideWidth, Pres.PageSetup.SlideHeight); textBoxes .SetAlignment(Alignment.Centre) .SetPosition(Position.Left) .StartBoxing(); TextBoxInfo textBoxInfo = textBoxes.GetTextBoxesInfo(); Assert.IsTrue(SlideUtil.IsRoughlySame(57.5200043f, textBoxInfo.Height)); Assert.IsTrue(SlideUtil.IsRoughlySame(25f, textBoxInfo.Left)); Assert.IsTrue(SlideUtil.IsRoughlySame(241.240036f, textBoxInfo.Top)); Assert.IsTrue(SlideUtil.IsRoughlySame(710.945068f, textBoxInfo.Width)); textBoxes .SetAlignment(Alignment.Centre) .SetPosition(Position.Centre) .StartBoxing(); textBoxInfo = textBoxes.GetTextBoxesInfo(); Assert.IsTrue(SlideUtil.IsRoughlySame(124.527481f, textBoxInfo.Left)); Assert.IsTrue(SlideUtil.IsRoughlySame(241.240036f, textBoxInfo.Top)); textBoxes .SetAlignment(Alignment.Centre) .SetPosition(Position.BottomLeft) .StartBoxing(); textBoxInfo = textBoxes.GetTextBoxesInfo(); Assert.IsTrue(SlideUtil.IsRoughlySame(25f, textBoxInfo.Left)); Assert.IsTrue(SlideUtil.IsRoughlySame(457.480042f, textBoxInfo.Top)); textBoxes .SetAlignment(Alignment.Centre) .SetPosition(Position.Bottom) .StartBoxing(); textBoxInfo = textBoxes.GetTextBoxesInfo(); Assert.IsTrue(SlideUtil.IsRoughlySame(124.527481f, textBoxInfo.Left)); Assert.IsTrue(SlideUtil.IsRoughlySame(457.480042f, textBoxInfo.Top)); textBoxes .SetAlignment(Alignment.Centre) .SetPosition(Position.Right) .StartBoxing(); textBoxInfo = textBoxes.GetTextBoxesInfo(); Assert.IsTrue(SlideUtil.IsRoughlySame(224.054962f, textBoxInfo.Left)); Assert.IsTrue(SlideUtil.IsRoughlySame(241.23996f, textBoxInfo.Top)); }
private void IsClipboardRestoredReplaceWithClipboard(int originalSlideNo, int expSlideNo) { CheckIfClipboardIsRestored(() => { Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = GetShapesByPrefix(OrigIsClipboardRestoredReplaceWithClipboardSlideNo, ShapeToCopyPrefix); // This should be restored to clipboard later shapes.Cut(); PpOperations.SelectShapes(new List <string> { ShapeToReplace }); PplFeatures.ReplaceWithClipboard(); }, originalSlideNo, ShapeToCopyPrefix, expSlideNo, "", ShapeToCompareCopied); }
private void IsDegradedAfterReplaceWithClipboard(int originalSlideNo, int replacedSlideNo, int degradedSlideNo) { Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = GetShapesByPrefix(replacedSlideNo, ShapeToCopyPrefix); shapes.Cut(); PpOperations.SelectShapes(new List <string> { ShapeToReplace }); PplFeatures.ReplaceWithClipboard(); // Degradation results in subtle differences, therefore comparison threshold must be stricter AssertIsSame(originalSlideNo, replacedSlideNo, 0.999999999); // Verify that the degradation is detectable AssertNotSame(originalSlideNo, degradedSlideNo, 0.999999999); }
public Shape ApplyFrostedGlassBannerEffect(BannerDirection direction, Position textPos, Shape blurImage, string overlayColor, int transparency) { TextBoxInfo tbInfo = new TextBoxes(Shapes.Range(), SlideWidth, SlideHeight) .GetTextBoxesInfo(); if (tbInfo == null) { return(null); } TextBoxes.AddMargin(tbInfo); Shape overlayShape; Shape blurBanner = blurImage.Duplicate()[1]; blurBanner.Left = blurImage.Left; blurBanner.Top = blurImage.Top; direction = HandleAutoDirection(direction, textPos); switch (direction) { case BannerDirection.Horizontal: overlayShape = ApplyOverlayEffect(overlayColor, transparency, 0, tbInfo.Top, SlideWidth, tbInfo.Height); CropPicture(blurBanner, 0, tbInfo.Top, SlideWidth, tbInfo.Height); break; // case BannerDirection.Vertical: default: overlayShape = ApplyOverlayEffect(overlayColor, transparency, tbInfo.Left, 0, tbInfo.Width, SlideHeight); CropPicture(blurBanner, tbInfo.Left, 0, tbInfo.Width, SlideHeight); break; } ChangeName(overlayShape, EffectName.Banner); ChangeName(blurBanner, EffectName.Banner); overlayShape.ZOrder(MsoZOrderCmd.msoSendToBack); Utils.ShapeUtil.MoveZToJustBehind(blurBanner, overlayShape); Microsoft.Office.Interop.PowerPoint.ShapeRange range = Shapes.Range(new[] { blurBanner.Name, overlayShape.Name }); Shape resultShape = range.Group(); ChangeName(resultShape, EffectName.Banner); return(resultShape); }
public TextBoxes(ShapeRange shapes, float slideWidth, float slideHeight) { _slideWidth = slideWidth; _slideHeight = slideHeight; TextShapes = new List<Shape>(); foreach (Shape shape in shapes) { if ((shape.Type != MsoShapeType.msoPlaceholder && shape.Type != MsoShapeType.msoTextBox) || shape.TextFrame.HasText == MsoTriState.msoFalse || StringUtil.IsEmpty(shape.TextFrame2.TextRange.Paragraphs.TrimText().Text) || StringUtil.IsNotEmpty(shape.Tags[Tag.ImageReference])) { continue; } TextShapes.Add(shape); } }
public void TestGetTextBoxInfo() { PpOperations.SelectSlide(2); Microsoft.Office.Interop.PowerPoint.ShapeRange shapes = PpOperations.SelectShapesByPrefix("TextBox"); TextBoxes textBoxes = new TextBoxes(shapes, Pres.PageSetup.SlideWidth, Pres.PageSetup.SlideHeight); TextBoxInfo textBoxInfo = textBoxes.GetTextBoxesInfo(); Assert.IsTrue(SlideUtil.IsRoughlySame(57.5200043f, textBoxInfo.Height)); Assert.IsTrue(SlideUtil.IsRoughlySame(68.2f, textBoxInfo.Left)); Assert.IsTrue(SlideUtil.IsRoughlySame(52.17752f, textBoxInfo.Top)); Assert.IsTrue(SlideUtil.IsRoughlySame(710.945068f, textBoxInfo.Width)); TextBoxes.AddMargin(textBoxInfo, 25); Assert.IsTrue(SlideUtil.IsRoughlySame(107.520004f, textBoxInfo.Height)); Assert.IsTrue(SlideUtil.IsRoughlySame(43.1999969f, textBoxInfo.Left)); Assert.IsTrue(SlideUtil.IsRoughlySame(27.17752f, textBoxInfo.Top)); Assert.IsTrue(SlideUtil.IsRoughlySame(760.945068f, textBoxInfo.Width)); }
public static void AlignLeft(ShapeRange toAlign) { var selectedShapes = new List<PPShape>(); switch (AlignReference) { case AlignReferenceObject.Slide: selectedShapes = ConvertShapeRangeToPPShapeList(toAlign); foreach (var s in selectedShapes) { s.IncrementLeft(-s.VisualLeft); } break; case AlignReferenceObject.SelectedShape: if (toAlign.Count < 2) { throw new Exception(ErrorMessageFewerThanTwoSelection); } selectedShapes = ConvertShapeRangeToPPShapeList(toAlign); var refShape = selectedShapes[0]; for (var i = 1; i < selectedShapes.Count; i++) { var s = selectedShapes[i]; s.IncrementLeft(refShape.VisualLeft - s.VisualLeft); } break; case AlignReferenceObject.PowerpointDefaults: if (toAlign.Count == 1) { toAlign.Align(MsoAlignCmd.msoAlignLefts, MsoTriState.msoTrue); } else { toAlign.Align(MsoAlignCmd.msoAlignLefts, MsoTriState.msoFalse); } break; default: throw new ArgumentOutOfRangeException(); } }
private static List<PPShape> ConvertShapeRangeToPPShapeList(ShapeRange toAlign) { var selectedShapes = new List<PPShape>(); for (var i = 1; i <= toAlign.Count; i++) { var s = toAlign[i]; if (s.Type.Equals(Office.MsoShapeType.msoPicture)) { selectedShapes.Add(new PPShape(toAlign[i], false)); } else { selectedShapes.Add(new PPShape(toAlign[i])); } } return selectedShapes; }
public static void AlignBottom(ShapeRange toAlign, float slideHeight) { var selectedShapes = new List<PPShape>(); switch (AlignReference) { case AlignReferenceObject.Slide: selectedShapes = ConvertShapeRangeToPPShapeList(toAlign); foreach (var s in selectedShapes) { s.IncrementTop(slideHeight - s.VisualTop - s.AbsoluteHeight); } break; case AlignReferenceObject.SelectedShape: if (toAlign.Count < 2) { throw new Exception(ErrorMessageFewerThanTwoSelection); } selectedShapes = ConvertShapeRangeToPPShapeList(toAlign); var refShape = selectedShapes[0]; var lowestRefPoint = refShape.VisualTop + refShape.AbsoluteHeight; for (var i = 1; i < selectedShapes.Count; i++) { var s = selectedShapes[i]; var lowestPoint = s.VisualTop + s.AbsoluteHeight; s.IncrementTop(lowestRefPoint - lowestPoint); } break; case AlignReferenceObject.PowerpointDefaults: if (toAlign.Count == 1) { toAlign.Align(MsoAlignCmd.msoAlignBottoms, MsoTriState.msoTrue); } else { toAlign.Align(MsoAlignCmd.msoAlignBottoms, MsoTriState.msoFalse); } break; default: throw new ArgumentOutOfRangeException(); } }
public static void AlignCenter(ShapeRange toAlign, float slideHeight, float slideWidth) { var selectedShapes = new List<PPShape>(); switch (AlignReference) { case AlignReferenceObject.Slide: selectedShapes = ConvertShapeRangeToPPShapeList(toAlign); foreach (var s in selectedShapes) { s.IncrementTop(slideHeight / 2 - s.VisualTop - s.AbsoluteHeight / 2); s.IncrementLeft(slideWidth / 2 - s.VisualLeft - s.AbsoluteWidth / 2); } break; case AlignReferenceObject.SelectedShape: if (toAlign.Count < 2) { throw new Exception(ErrorMessageFewerThanTwoSelection); } selectedShapes = ConvertShapeRangeToPPShapeList(toAlign); var refShape = selectedShapes[0]; for (var i = 1; i < selectedShapes.Count; i++) { var s = selectedShapes[i]; s.IncrementTop(refShape.VisualCenter.Y - s.VisualCenter.Y); s.IncrementLeft(refShape.VisualCenter.X - s.VisualCenter.X); } break; case AlignReferenceObject.PowerpointDefaults: if (toAlign.Count == 1) { toAlign.Align(MsoAlignCmd.msoAlignMiddles, MsoTriState.msoTrue); toAlign.Align(MsoAlignCmd.msoAlignCenters, MsoTriState.msoTrue); } else { toAlign.Align(MsoAlignCmd.msoAlignMiddles, MsoTriState.msoFalse); toAlign.Align(MsoAlignCmd.msoAlignCenters, MsoTriState.msoFalse); } break; default: throw new ArgumentOutOfRangeException(); } }