internal PositionsDistributeGridDialog(ShapeRange selectedShapes, int rowLength, int colLength) { IsOpen = true; _selectedShapes = selectedShapes; _numShapesSelected = selectedShapes.Count; _rowLength = rowLength; _colLength = colLength; InitializeComponent(); }
private void btnCrLine_Click(object sender, RoutedEventArgs e) { if (checkActive()) { MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { Size s = new Size(app.ActiveSelection.SizeWidth, app.ActiveSelection.SizeHeight); Size position = new Size(app.ActiveSelectionRange.PositionX, app.ActiveSelectionRange.PositionY); Size size = new Size(s.x * numCol.Value, s.y * numRow.Value); app.ActiveSelection.Delete(); ShapeRange orSh = CrLine(s, position, size); app.ActiveLayer.CreateRectangle(orSh.LeftX, orSh.TopY, orSh.RightX, orSh.BottomY).CreateSelection(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); } }
/// <summary> /// Tries to restore clipboard with provided SlideRange first, then ShapeRange then finally Shape. /// Note that clipboard cannot be restored if last copied item was a placeholder (for now) /// </summary> /// <returns>True if successfully restored</returns> private static void RestoreClipboard(ShapeRange shapes = null, SlideRange slides = null) { try { if (slides != null) { slides.Copy(); slides.Delete(); } else if (shapes != null && shapes.Count >= 1) { shapes.Copy(); shapes.Delete(); } } catch (COMException e) { // May be thrown when trying to copy Logger.LogException(e, "RestoreClipboard"); } }
public static void Execute(PowerPointSlide slide, ShapeRange pastingShapes, float slideWidth, float slideHeight) { pastingShapes = ShapeUtil.GetShapesWhenTypeNotMatches(slide, pastingShapes, Microsoft.Office.Core.MsoShapeType.msoPlaceholder); if (pastingShapes.Count == 0) { return; } Shape shapeToFitSlide = pastingShapes[1]; if (pastingShapes.Count > 1) { shapeToFitSlide = pastingShapes.Group(); } shapeToFitSlide.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue; PPShape ppShapeToFitSlide = new PPShape(shapeToFitSlide); ResizeShape(ppShapeToFitSlide, slideWidth, slideHeight); ppShapeToFitSlide.VisualCenter = new System.Drawing.PointF(slideWidth / 2, slideHeight / 2); }
// ArrangeBackground - Arranges Backgrounds behind the decals kit. FMR_K needs to be moved to the bottom left and FMR_M needs to be moved down by a bit. private void ArrangeBackground(ShapeRange kit, VGCore.Shape background, string variant = null, string number = null, string name = null) { background.OrderToBack(); if (background.Name != "FMR_K.cdr") { background.SetSize(kit.SizeWidth + 5); background.CenterX = kit.CenterX; background.CenterY = kit.CenterY; if (background.Name == "FMR_M.cdr") { background.CenterY = kit.CenterY + 1; } } else { background.SetSize(kit.SizeWidth + 15); background.CenterX = kit.CenterX - 5; background.CenterY = kit.CenterY + 2; } if (background.Name == "msmx.cdr") { if (name.Length > 0 || number.Length > 0) { background.Shapes.FindShape("custom", cdrShapeType.cdrTextShape).Text.Replace("#XX XXXXXXXXX", "#" + number + " " + name, true); } else { background.Shapes.FindShape("custom", cdrShapeType.cdrTextShape).Text.Replace("#XX XXXXXXXXX", "", true); } background.Shapes.FindShape("design", cdrShapeType.cdrTextShape).Text.Replace("X XXXX -XX", variant, true); background.CenterY = kit.CenterY + 3; } }
/// <summary> /// This method assumes that there is valid data on the clipboard. DO NOT lock the clipboard. /// </summary> public static ShapeRange PasteShapesFromClipboard(PowerPointPresentation pres, PowerPointSlide slide) { try { ShapeRange shapes = null; try { shapes = PasteWithCorrectSlideCheck(slide); // Try to get enumerator and sees if it throws an error // Will throw error if its a web picture shapes.GetEnumerator(); return(shapes); } catch (COMException e) { Logger.LogException(e, "PasteShapesFromClipboard"); // Delete previously pasted "shapes" because it is not a valid shape if (shapes != null) { shapes[1].SafeDelete(); } ShapeRange picture = TryPastingAsPNG(slide); if (picture == null) { picture = TryPastingAsBitmap(slide); } if (picture == null) { picture = TryPastingOntoView(pres, slide); } return(picture); } } catch (COMException e) { // May be thrown if there is placeholder shape in clipboard Logger.LogException(e, "PasteShapesFromClipboard"); return(null); } }
private ShapeRange traceBitmap(Shape s, Point p) { var sr = new ShapeRange(); sr.RemoveAll(); try { Shape dub = s.Duplicate(p.X, p.Y); dub.Bitmap.Resample(0, 0, true, 72, 72); dub.ApplyEffectBCI(-100, 100, -100); ShapeRange tr = dub.Bitmap.Trace( cdrTraceType.cdrTraceLineArt, -1, 1, cdrColorType.cdrColorCMYK, cdrPaletteID.cdrCustom, 1, true, false, true ).Finish(); Shape path = tr.UngroupAllEx().Combine(); path.Curve.Nodes.All().AutoReduce(0.01); sr.Add(path); if ((bool)cbBitmapToPowerClip.IsChecked) { Shape clip = path.Duplicate(p.X * -1, p.Y * -1); clip.OrderBackOf(s); clip.Fill.ApplyNoFill(); clip.Outline.SetNoOutline(); s.AddToPowerClip(clip); sr.Add(clip); } return(sr); } catch (Exception err) { MessageBox.Show(err.ToString(), MName, MessageBoxButton.OK, MessageBoxImage.Error); return(sr); } }
private void btnAutoText_Click(object sender, RoutedEventArgs e) { if (checkActive()) { MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { ShapeRange orSh = app.ActiveSelectionRange; double x = 0, y = 0; bool flag = false; if (orSh.Shapes.Count == 1 && orSh.Shapes.First.Type == cdrShapeType.cdrGroupShape) { orSh.Ungroup(); } foreach (Shape s in orSh.Shapes) { if (s.Type == cdrShapeType.cdrTextShape) { txtTextName.Text = s.Text.Contents; x = s.PositionX; y = s.PositionY; s.Text.AlignProperties.Alignment = cdrAlignment.cdrCenterAlignment; s.PositionX = x; s.PositionY = y; flag = true; break; } } if (!flag) { MessageBox.Show("Không tìm thấy đối tượng dạng Text!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); } }
protected override void ExecuteAction(string ribbonId) { IMessageService cropLabMessageService = MessageServiceFactory.GetCropLabMessageService(); CropLabErrorHandler errorHandler = CropLabErrorHandler.InitializeErrorHandler(cropLabMessageService); Selection selection = this.GetCurrentSelection(); if (!ShapeUtil.IsSelectionShape(selection)) { HandleInvalidSelectionError(CropLabErrorHandler.ErrorCodeSelectionIsInvalid, FeatureName, CropLabErrorHandler.SelectionTypePicture, 1, errorHandler); return; } ShapeRange shapeRange = selection.ShapeRange; if (selection.HasChildShapeRange) { shapeRange = selection.ChildShapeRange; } if (shapeRange.Count < 1) { HandleInvalidSelectionError(CropLabErrorHandler.ErrorCodeSelectionIsInvalid, FeatureName, CropLabErrorHandler.SelectionTypePicture, 1, errorHandler); return; } if (!ShapeUtil.IsAllPicture(shapeRange)) { HandleErrorCode(CropLabErrorHandler.ErrorCodeSelectionMustBePicture, FeatureName, errorHandler); return; } try { ShapeRange result = CropOutPadding.Crop(shapeRange); result?.Select(); } catch (CropLabException e) { HandleCropLabException(e, FeatureName, errorHandler); } }
private ShapeRange CrLine(Size s, Size position, Size size) { app.ActiveLayer.CreateLineSegment(position.x, position.y, position.x, position.y - size.y).CreateSelection(); ShapeRange orSh = app.ActiveSelectionRange; double space = 0; for (int i = 0; i < numCol.Value; i++) { space += s.x; orSh.AddRange(app.ActiveSelectionRange.Duplicate(space, 0)); } space = 0; app.ActiveLayer.CreateLineSegment(position.x, position.y, position.x + size.x, position.y).CreateSelection(); orSh.AddRange(app.ActiveSelectionRange); for (int j = 0; j < numRow.Value; j++) { space += s.y; orSh.AddRange(app.ActiveSelectionRange.Duplicate(0, -space)); } orSh.Group(); return(orSh); }
private float calSizeInsert() { if (checkActive()) { MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return(0); } try { app.ActiveDocument.Unit = cdrUnit.cdrCentimeter; ShapeRange orSh = app.ActiveSelectionRange; double sRec = orSh.SizeHeight * orSh.SizeWidth; double sEll = Math.Pow(orSh.SizeWidth / 2, 2) * Math.PI; double d = Math.Sqrt(((sRec - sEll) / 1.5775796) / Math.PI) * 2; return((float)Math.Round(d, 1)); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); return(0); } }
private void createMark() { double mSize = 1.6; double mWid = 0.06; app.ActiveDocument.Unit = cdrUnit.cdrCentimeter; ShapeRange orSh = app.ActiveSelectionRange; Shape botRight = app.ActiveLayer.CreateRectangle(0, 0, mSize, mSize); botRight.ConvertToCurves(); Curve c = app.ActiveDocument.CreateCurve(); SubPath ss = c.CreateSubPath(mSize, mSize); ss.AppendCurveSegment(0, mSize); ss.AppendCurveSegment(0, 0); botRight.Curve.CopyAssign(c); botRight.Outline.Width = mWid; botRight.Outline.Color.CMYKAssign(30, 30, 30, 100); Shape topRight = botRight.Duplicate(0, 0); topRight.Flip(cdrFlipAxes.cdrFlipVertical); topRight.AddToSelection(); Shape topLeft = botRight.Duplicate(0, 0); topLeft.Flip(cdrFlipAxes.cdrFlipBoth); topLeft.AddToSelection(); Shape botLeft = botRight.Duplicate(0, 0); botLeft.Flip(cdrFlipAxes.cdrFlipHorizontal); botLeft.AddToSelection(); botRight.Move(orSh.PositionX + orSh.SizeWidth, orSh.PositionY - orSh.SizeHeight - mSize); topRight.Move(orSh.PositionX + orSh.SizeWidth, orSh.PositionY); topLeft.Move(orSh.PositionX - mSize, orSh.PositionY); botLeft.Move(orSh.PositionX - mSize, orSh.PositionY - orSh.SizeHeight - mSize); Shape mark = app.ActiveSelectionRange.Combine(); mark.Name = "FineCut_TomboGroup"; orSh.Delete(); }
protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide, ShapeRange selectedShapes, ShapeRange selectedChildShapes) { if (selectedShapes.Count <= 0) { MessageBox.Show(TextCollection.PasteLabText.ReplaceWithClipboardActionHandlerReminderText, TextCollection.CommonText.ErrorTitle); return(null); } this.StartNewUndoEntry(); ShapeRange pastingShapes = ClipboardUtil.PasteShapesFromClipboard(presentation, slide); if (pastingShapes == null) { Logger.Log("PasteLab: Could not paste clipboard contents."); MessageBox.Show(PasteLabText.ErrorPaste, PasteLabText.ErrorDialogTitle); return(null); } return(ReplaceWithClipboard.Execute(presentation, slide, selectedShapes, selectedChildShapes, pastingShapes)); }
private void DrawMarks(HashSet <Mark> marks, DoMarksProperties props) { ShapeRange sr = new ShapeRange(); foreach (var item in marks) { sr.Add(DrawLine(item)); } Shape groupMarks = sr.Group(); if (props.WhiteSubMark) { Shape wsm = groupMarks.Duplicate(); wsm.Outline.SetProperties(1, corelApp.OutlineStyles[0], corelApp.CreateCMYKColor(0, 0, 0, 0)); wsm.OrderBackOne(); ShapeRange tempSr = new ShapeRange(); tempSr.Add(wsm); tempSr.Add(groupMarks); tempSr.Group(); } }
protected override void ExecuteAction(string ribbonId) { IMessageService cropLabMessageService = MessageServiceFactory.GetCropLabMessageService(); CropLabErrorHandler errorHandler = CropLabErrorHandler.InitializeErrorHandler(cropLabMessageService); Selection selection = this.GetCurrentSelection(); if (!ShapeUtil.IsSelectionShape(selection)) { HandleInvalidSelectionError(CropLabErrorHandler.ErrorCodeSelectionIsInvalid, FeatureName, CropLabErrorHandler.SelectionTypePicture, 1, errorHandler); return; } ShapeRange shapeRange = selection.ShapeRange; if (shapeRange.Count < 1) { HandleInvalidSelectionError(CropLabErrorHandler.ErrorCodeSelectionIsInvalid, FeatureName, CropLabErrorHandler.SelectionTypePicture, 1, errorHandler); return; } if (!ShapeUtil.IsAllPicture(shapeRange)) { HandleErrorCode(CropLabErrorHandler.ErrorCodeSelectionMustBePicture, FeatureName, errorHandler); return; } if (ribbonId.Contains(CommonText.DynamicMenuButtonId)) { CustomAspectRatioDialogBox dialog = new CustomAspectRatioDialogBox(shapeRange[1]); dialog.DialogConfirmedHandler += ExecuteCropToAspectRatio; dialog.ShowDialog(); } else if (ribbonId.Contains(CommonText.DynamicMenuOptionId)) { int optionRawStringStartIndex = ribbonId.LastIndexOf(CommonText.DynamicMenuButtonId) + CommonText.DynamicMenuOptionId.Length; string optionRawString = ribbonId.Substring(optionRawStringStartIndex).Replace('_', ':'); ExecuteCropToAspectRatio(optionRawString); } }
private void button1_Click(object sender, EventArgs e) { StartEvent(true); if (application.ActiveDocument.Selection().Shapes.Count == 0) { MessageBox.Show("请至少选择一个对象"); } application.ActiveDocument.Unit = cdrUnit.cdrMillimeter; ShapeRange s = application.ActiveSelectionRange; Shape rec; double Radius = 0; if (checkBox1.Checked) { double.TryParse(textBox1.Text, out Radius); } rec = application.ActiveLayer.CreateRectangle2(s.LeftX, s.BottomY, s.SizeWidth, s.SizeHeight, Radius, Radius, Radius, Radius); rec.Rectangle.CornerType = cdrCornerType.cdrCornerTypeRound; rec.Rectangle.RelativeCornerScaling = true; rec.Fill.ApplyNoFill(); s.AddToPowerClip(rec, cdrTriState.cdrFalse); EndEvent(); }
/// <summary> /// Adds the line string to the path. /// </summary> /// <param name="path">Path to add the line string to.</param> /// <param name="vertices">Vertices of the line string.</param> /// <param name="shpx">Shape range of the line string.</param> /// <param name="args">The map arguments.</param> /// <param name="clipRect">The clip rectangle.</param> internal static void BuildLineString(GraphicsPath path, double[] vertices, ShapeRange shpx, MapArgs args, Rectangle clipRect) { double minX = args.MinX; double maxY = args.MaxY; double dx = args.Dx; double dy = args.Dy; for (int prt = 0; prt < shpx.Parts.Count; prt++) { PartRange prtx = shpx.Parts[prt]; int start = prtx.StartIndex; int end = prtx.EndIndex; var points = new List <double[]>(end - start + 1); for (int i = start; i <= end; i++) { var pt = new[] { (vertices[i * 2] - minX) * dx, (maxY - vertices[(i * 2) + 1]) * dy }; points.Add(pt); } AddLineStringToPath(path, args, shpx.Extent, points, clipRect); } }
private HashSet <FigureBBox> GetFigureBBoxes(ShapeRange sr, DoMarksProperties props) { HashSet <FigureBBox> result = new HashSet <FigureBBox>(); foreach (corel.Shape item in sr) { if (!props.OneCutting) { result.Add(new FigureBBox(item.BoundingBox)); } else { var bbox = item.BoundingBox; var x = bbox.x - props.Offset; var y = bbox.y - props.Offset; var width = props.Offset * 2 + bbox.Width; var height = props.Offset * 2 + bbox.Height; result.Add(new FigureBBox(x, y, width, height)); } } return(result); }
private void button1_Click(object sender, EventArgs e) { ShapeRange OrigSelection = app.ActiveSelectionRange; ExportFilter expflt; StructExportOptions expopt = app.CreateStructExportOptions(); expopt.UseColorProfile = false; expopt.ResolutionX = 72; expopt.ResolutionY = 72; expopt.ImageType = cdrImageType.cdrCMYKColorImage; StructPaletteOptions exppopt = app.CreateStructPaletteOptions(); expflt = app.ActiveDocument.ExportEx("C:\\PStoCurve.eps", cdrFilter.cdrEPS, cdrExportRange.cdrSelection, expopt, exppopt); expflt.Finish(); ImportFilter impflt; StructImportOptions impopt = app.CreateStructImportOptions(); impopt.MaintainLayers = true; impflt = app.ActiveLayer.ImportEx("C:\\PStoCurve.eps", cdrFilter.cdrPSInterpreted, impopt); impflt.Finish(); OrigSelection.Delete(); }
private void btnAutoLine_Click(object sender, RoutedEventArgs e) { if (checkActive()) { MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (initFile("line")) { try { Size s = new Size(app.ActiveSelection.SizeWidth, app.ActiveSelection.SizeHeight); Size position = new Size(app.ActiveSelectionRange.PositionX, app.ActiveSelectionRange.PositionY); Size size = new Size(s.x * numCol.Value, s.y * numRow.Value); Shape orSh = CreateBe(); Shape mark1 = app.ActiveLayer.CreateRectangle(orSh.LeftX, orSh.TopY, orSh.RightX, orSh.BottomY); mark1.CreateSelection(); createMark(); orSh.Outline.SetNoOutline(); ShapeRange be = CrLine(s, position, size); be.Move(be.SizeWidth + 15, 0); Shape mark2 = app.ActiveLayer.CreateRectangle(be.LeftX, be.TopY, be.RightX, be.BottomY); mark2.CreateSelection(); createMark(); app.ActiveWindow.ActiveView.ToFitAllObjects(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); } } else { MessageBox.Show("Chưa thỏa điều kiện tạo file bế thẳng!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private static void FastBuildLine(GraphicsPath graphPath, double[] vertices, ShapeRange shpx, double minX, double maxY, double dx, double dy) { for (int prt = 0; prt < shpx.Parts.Count; prt++) { PartRange prtx = shpx.Parts[prt]; int start = prtx.StartIndex; int end = prtx.EndIndex; List <Point> partPoints = new List <Point>(); Point previousPoint = default(Point); for (int i = start; i <= end; i++) { if (double.IsNaN(vertices[i * 2]) || double.IsNaN(vertices[(i * 2) + 1])) { continue; } var pt = new Point { X = Convert.ToInt32((vertices[i * 2] - minX) * dx), Y = Convert.ToInt32((maxY - vertices[(i * 2) + 1]) * dy) }; if (i == 0 || (pt.X != previousPoint.X || pt.Y != previousPoint.Y)) { // Don't add the same point twice partPoints.Add(pt); previousPoint = pt; } } if (partPoints.Count < 2) { continue; // we need two distinct points to make a line } graphPath.StartFigure(); graphPath.AddLines(partPoints.ToArray()); } }
/// <summary> /// Appends the specified polygon to the graphics path. /// </summary> private static void BuildPolygon(double[] vertices, ShapeRange shpx, GraphicsPath borderPath, MapArgs args, SoutherlandHodgman shClip) { double minX = args.MinX; double maxY = args.MaxY; double dx = args.Dx; double dy = args.Dy; for (int prt = 0; prt < shpx.Parts.Count; prt++) { PartRange prtx = shpx.Parts[prt]; int start = prtx.StartIndex; int end = prtx.EndIndex; var points = new List <double[]>(end - start + 1); for (int i = start; i <= end; i++) { var pt = new[] { (vertices[i * 2] - minX) * dx, (maxY - vertices[i * 2 + 1]) * dy }; points.Add(pt); } if (null != shClip) { points = shClip.Clip(points); } var intPoints = DuplicationPreventer.Clean(points).ToArray(); if (intPoints.Length < 2) { continue; } borderPath.StartFigure(); borderPath.AddLines(intPoints); } }
protected static void CheckIfClipboardIsRestored(Action action, int actualSlideNum, string shapeNameToBeCopied, int expSlideNum, string expShapeNameToDelete, string expCopiedShapeName) { Slide actualSlide = PpOperations.SelectSlide(actualSlideNum); ShapeRange shapeToBeCopied = PpOperations.SelectShape(shapeNameToBeCopied); Assert.AreEqual(1, shapeToBeCopied.Count); ShapeRange newShape = PPLClipboard.Instance.LockAndRelease(() => { // Add this shape to clipboard shapeToBeCopied.Copy(); action(); // Paste whatever in clipboard return(actualSlide.Shapes.Paste()); }); // Check if pasted shape is the same as the shape added to clipboard originally Assert.AreEqual(shapeNameToBeCopied, newShape.Name); Assert.AreEqual(shapeToBeCopied.Count, newShape.Count); Slide expSlide = PpOperations.SelectSlide(expSlideNum); if (expShapeNameToDelete != "") { PpOperations.SelectShape(expShapeNameToDelete)[1].Delete(); } //Set the pasted shape location because the location of the pasted shape is flaky Shape expCopied = PpOperations.SelectShape(expCopiedShapeName)[1]; newShape.Top = expCopied.Top; newShape.Left = expCopied.Left; SlideUtil.IsSameLooking(expSlide, actualSlide); }
public static void Execute(PowerPointPresentation pres, PowerPointSlide slide, ShapeRange pastingShapes, float slideWidth, float slideHeight) { pastingShapes = ShapeUtil.GetShapesWhenTypeNotMatches(slide, pastingShapes, Microsoft.Office.Core.MsoShapeType.msoPlaceholder); if (pastingShapes.Count == 0) { return; } Shape pastingShape = pastingShapes[1]; if (pastingShapes.Count > 1) { pastingShape = pastingShapes.Group(); } // Temporary house the latest clipboard shapes ShapeRange origClipboardShapes = ClipboardUtil.PasteShapesFromClipboard(pres, slide); // Compression of large image(s) Shape shapeToFillSlide = GraphicsUtil.CompressImageInShape(pastingShape, slide); // Bring the same original shapes back into clipboard, preserving original size origClipboardShapes.Cut(); shapeToFillSlide.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue; PPShape ppShapeToFillSlide = new PPShape(shapeToFillSlide); ppShapeToFillSlide.AbsoluteHeight = slideHeight; if (ppShapeToFillSlide.AbsoluteWidth < slideWidth) { ppShapeToFillSlide.AbsoluteWidth = slideWidth; } ppShapeToFillSlide.VisualCenter = new System.Drawing.PointF(slideWidth / 2, slideHeight / 2); CropLab.CropToSlide.Crop(shapeToFillSlide, slide, slideWidth, slideHeight); }
protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide, ShapeRange selectedShapes, ShapeRange selectedChildShapes) { if (selectedShapes.Count <= 0) { Logger.Log("PasteIntoGroup failed. No valid shape is selected."); return(null); } if (selectedShapes.Count == 1 && !ShapeUtil.IsAGroup(selectedShapes[1])) { Logger.Log("PasteIntoGroup failed. Selection is only a single shape."); return(null); } ShapeRange pastingShapes = PasteShapesFromClipboard(slide); if (pastingShapes == null) { return(null); } return(PasteIntoGroup.Execute(presentation, slide, selectedShapes, pastingShapes)); }
protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide, ShapeRange selectedShapes, ShapeRange selectedChildShapes) { PowerPointSlide tempSlide = presentation.AddSlide(index: slide.Index); ShapeRange tempPastingShapes = ClipboardUtil.PasteShapesFromClipboard(presentation, tempSlide); if (tempPastingShapes == null) { tempSlide.Delete(); ShapeRange shapes = ClipboardUtil.PasteShapesFromClipboard(presentation, slide); if (shapes == null) { Logger.Log("PasteLab: Could not paste clipboard contents."); MessageBox.Show(PasteLabText.ErrorPaste, PasteLabText.ErrorDialogTitle); } return(shapes); } ShapeRange pastingShapes = slide.CopyShapesToSlide(tempPastingShapes); tempSlide.Delete(); return(pastingShapes); }
public static ShapeRange Execute(PowerPointPresentation presentation, PowerPointSlide slide, ShapeRange selectedShapes, ShapeRange selectedChildShapes, ShapeRange pastingShapes) { // ignore height & width, it doesn't always make sense to sync the height & width especially for circles, squares List <Format> formatsToIgnore = new List <Format> { new PositionHeightFormat(), new PositionWidthFormat() }; // Replacing individual shape if (selectedChildShapes.Count == 0) { Shape selectedShape = selectedShapes[1]; Shape pastingShape = pastingShapes[1]; if (pastingShapes.Count > 1) { pastingShape = pastingShapes.Group(); } pastingShape.Left = selectedShape.Left; pastingShape.Top = selectedShape.Top; ShapeUtil.MoveZToJustInFront(pastingShape, selectedShape); slide.DeleteShapeAnimations(pastingShape); slide.TransferAnimation(selectedShape, pastingShape); ShapeUtil.ApplyAllPossibleFormats(selectedShape, pastingShape, formatsToIgnore); selectedShape.SafeDelete(); return(slide.ToShapeRange(pastingShape)); } // Replacing shape within a group else { Shape selectedGroup = selectedShapes[1]; Shape selectedChildShape = selectedChildShapes[1]; string originalGroupName = selectedGroup.Name; int zOrder = selectedChildShape.ZOrderPosition; Shape shapeAbove = null; float posLeft = selectedChildShape.Left; float posTop = selectedChildShape.Top; Shape tempShapeForAnimation = slide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 0, 0, 1, 1); slide.TransferAnimation(selectedGroup, tempShapeForAnimation); // Get all siblings of selected child List <Shape> selectedGroupShapeList = new List <Shape>(); for (int i = 1; i <= selectedGroup.GroupItems.Count; i++) { Shape shape = selectedGroup.GroupItems.Range(i)[1]; if (shape == selectedChildShape) { continue; } selectedGroupShapeList.Add(shape); if (shape.ZOrderPosition - 1 == zOrder) { shapeAbove = shape; } } // apply all styles from shapes to be pasted, but ignore x,y positions // x,y must be applied individually // each item replaced has a different positioneach shape in PasteIntoGroup.Execute(...), List <Format> positionFormats = new List <Format> { new PositionXFormat(), new PositionYFormat() }; formatsToIgnore.AddRange(positionFormats); for (int i = 1; i <= pastingShapes.Count; i++) { ShapeUtil.ApplyAllPossibleFormats(selectedChildShape, pastingShapes[i], formatsToIgnore); } // Remove selected child since it is being replaced ShapeRange shapesToGroup = slide.ToShapeRange(selectedGroupShapeList); selectedGroup.Ungroup(); selectedChildShape.SafeDelete(); ShapeRange result = PasteIntoGroup.Execute(presentation, slide, shapesToGroup, pastingShapes, posLeft, posTop, shapeAbove); result[1].Name = originalGroupName; slide.TransferAnimation(tempShapeForAnimation, result[1]); tempShapeForAnimation.SafeDelete(); return(result); } }
private static Shape MakeFrontImage(ShapeRange shapeRange) { foreach (Shape shape in shapeRange) { shape.SoftEdge.Radius = Math.Min(Math.Min(shape.Width, shape.Height) * 0.15f, 10f); } var croppedShape = CropToShape.Crop(shapeRange, handleError: false); return croppedShape; }
private bool initFile(string type) { app.ActiveDocument.Unit = cdrUnit.cdrCentimeter; ShapeRange orSh = app.ActiveSelectionRange; Size size = new Size(orSh.SizeWidth, orSh.SizeHeight); try { if (orSh.Count == 1) { if (orSh.Shapes.First.Type == cdrShapeType.cdrBitmapShape) { if (type == "circle") { orSh.Add(app.ActiveLayer.CreateEllipse2(orSh.CenterX, orSh.CenterY, orSh.SizeWidth / 2, orSh.SizeHeight / 2)); orSh.CreateSelection(); return(true); } if (type == "line") { return(true); } else { return(false); } } else if (orSh.Shapes.First.Type == cdrShapeType.cdrGroupShape) { if (type == "custom") { return(true); } else { orSh.Add(orSh.Shapes.First.ConvertToBitmapEx(cdrImageType.cdrCMYKColorImage, false, false, 720, cdrAntiAliasingType.cdrNormalAntiAliasing, true, false, 95)); orSh.SizeWidth = size.x; orSh.SizeHeight = size.y; if (type == "circle") { orSh.Add(app.ActiveLayer.CreateEllipse2(orSh.CenterX, orSh.CenterY, orSh.SizeWidth / 2, orSh.SizeHeight / 2)); } orSh.CreateSelection(); return(true); } } else { return(false); } } else { if (type == "custom") { return(true); } else { orSh.Group().CreateSelection(); orSh = app.ActiveSelectionRange; orSh.Add(orSh.FirstShape.ConvertToBitmapEx(cdrImageType.cdrCMYKColorImage, false, false, 720, cdrAntiAliasingType.cdrNormalAntiAliasing, true, false, 95)); orSh.SizeWidth = size.x; orSh.SizeHeight = size.y; if (type == "circle") { orSh.Add(app.ActiveLayer.CreateEllipse2(orSh.CenterX, orSh.CenterY, orSh.SizeWidth / 2, orSh.SizeHeight / 2)); } orSh.CreateSelection(); return(true); } } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); return(false); } }
private void btnCrLineColor_Click(object sender, RoutedEventArgs e) { if (checkActive()) { MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { Size s = new Size(app.ActiveSelection.SizeWidth, app.ActiveSelection.SizeHeight); ShapeRange rowRange = app.ActiveSelectionRange; ShapeRange colRev = app.ActiveSelectionRange; ShapeRange rowRev = app.ActiveSelectionRange; colRev.RemoveAll(); rowRev.RemoveAll(); rowRange.RemoveAll(); Size position = new Size(app.ActiveSelectionRange.PositionX, app.ActiveSelectionRange.PositionY); Size size = new Size(s.x * numCol.Value, s.y * numRow.Value); app.ActiveSelection.Delete(); Shape shapeCol = app.ActiveLayer.CreateLineSegment(position.x, position.y, position.x, position.y - size.y); shapeCol.Outline.Color.CMYKAssign(100, 0, 100, 0); double space = 0; for (int i = 0; i < numCol.Value; i++) { space += s.x; if (i % 2 == 0 || i == numCol.Value - 1) { colRev.Add(shapeCol.Duplicate(space, 0)); } else { shapeCol.Duplicate(space, 0); } } shapeCol.OrderToFront(); colRev.Flip(cdrFlipAxes.cdrFlipVertical); space = 0; Shape shapeRow = app.ActiveLayer.CreateLineSegment(position.x, position.y, position.x + size.x, position.y); shapeRow.Outline.Color.CMYKAssign(0, 100, 100, 0); rowRev.Add(shapeRow); for (int j = 0; j < numRow.Value; j++) { space += s.y; if (j % 2 != 0 || j == numRow.Value - 1) { rowRev.Add(shapeRow.Duplicate(0, -space)); } else { rowRange.Add(shapeRow.Duplicate(0, -space)); } } shapeRow.OrderToFront(); rowRange.AddRange(rowRev); rowRange.OrderReverse(); rowRev.Flip(cdrFlipAxes.cdrFlipHorizontal); app.ActiveLayer.CreateRectangle2(position.x, position.y - size.y, size.x, size.y).CreateSelection(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); } }
private static PowerPointBgEffectSlide PrepareForeground(ShapeRange oriShapeRange, ShapeRange copyShapeRange, Slide refSlide, PowerPointSlide newSlide) { try { // crop in the original slide and put into clipboard var croppedShape = MakeFrontImage(oriShapeRange); croppedShape.Cut(); // swap the uncropped shapes and cropped shapes var pastedCrop = newSlide.Shapes.Paste(); // calibrate pasted shapes pastedCrop.Left -= 12; pastedCrop.Top -= 12; // ungroup front image if necessary if (pastedCrop[1].Type == Core.MsoShapeType.msoGroup) { pastedCrop[1].Ungroup(); } copyShapeRange.Cut(); oriShapeRange = refSlide.Shapes.Paste(); oriShapeRange.Fill.ForeColor.RGB = 0xaaaaaa; oriShapeRange.Fill.Transparency = 0.7f; oriShapeRange.Line.Visible = Core.MsoTriState.msoTrue; oriShapeRange.Line.ForeColor.RGB = 0x000000; Utils.Graphics.MakeShapeViewTimeInvisible(oriShapeRange, refSlide); oriShapeRange.Select(); // finally add transition to the new slide newSlide.Transition.EntryEffect = PpEntryEffect.ppEffectFadeSmoothly; newSlide.Transition.Duration = 0.5f; return new PowerPointBgEffectSlide(newSlide.GetNativeSlide()); } catch (Exception e) { var errorMessage = CropToShape.GetErrorMessageForErrorCode(e.Message); errorMessage = errorMessage.Replace("Crop To Shape", "Blur/Recolor Remainder"); newSlide.Delete(); throw new InvalidOperationException(errorMessage); } }
private ShapeRange DuplicateShapes(ShapeRange range) { String[] duplicatedShapeNames = new String[range.Count]; for (int i = 0; i < range.Count; i++) { var shape = range[i + 1]; var duplicated = shape.Duplicate()[1]; duplicated.Name = shape.Name + "_Copy"; duplicated.Left = shape.Left; duplicated.Top = shape.Top; duplicatedShapeNames[i] = duplicated.Name; } return this.GetCurrentSlide().Shapes.Range(duplicatedShapeNames); }
private List<PPShape> ConvertShapeRangeToPPShapeList(ShapeRange range, int index) { var shapes = new List<PPShape>(); for (var i = index; i <= range.Count; i++) { shapes.Add(new PPShape(range[i])); } return shapes; }
private void decorateShape(semImage curShape) { ShapeRange SR = new ShapeRange(); ShapeRange TextShapes = new ShapeRange(); Shape Brect, Lrect, Wline, Ttext, Gr; double LmarginH, LmarginV, TmarginH, TmarginV, Theight; double Lwidth, Wwidth, Wheight, Lheight; double Left, Bottom, Width, Height; double oldCenterX, oldCenterY; double cimgratio; bool NoBar = false; Shape s = curShape.imgShape; semImageData d = curShape.imgData; double OffsetResolution = s.Bitmap.SizeWidth / s.SizeWidth; double bCut = 1d - d.CutBottom; Color White, Black; White = new Color(); Black = new Color(); Black.CMYKAssign(0, 0, 0, 100); White.CMYKAssign(0, 0, 0, 0); oldCenterX = s.CenterX; oldCenterY = s.CenterY; Left = s.LeftX; Bottom = s.BottomY; cimgratio = (s.SizeHeight * bCut) / s.SizeWidth; if (d.Width == 0d && d.Height == 0d) { Width = s.SizeWidth; Height = s.SizeHeight * bCut; } else if (d.Width == 0d) { Height = cmToUnit(d.Height); Width = Height / cimgratio; } else if (d.Height == 0d) { Width = cmToUnit(d.Width); Height = Width * cimgratio; } else { Width = cmToUnit(d.Width); Height = cmToUnit(d.Height); } double newRatio = Height / Width; if (newRatio <= cimgratio) { s.SizeWidth = Width; s.SizeHeight = (Width * cimgratio) / bCut; } else { s.SizeHeight = Height / bCut; s.SizeWidth = Height / cimgratio; } s.LeftX = Left; s.BottomY = Bottom; if (d.Mode == (int)CreateMode.Calib) { curShape.calcScale(); } else if (d.Width == 0 || d.BarText == "") { NoBar = true; } Lwidth = cmToUnit(curShape.imgData.BarLength); Lheight = ptToUnit(8); LmarginH = ptToUnit(8); LmarginV = ptToUnit(4); TmarginH = ptToUnit(4); TmarginV = ptToUnit(4); Theight = ptToUnit(d.FontSize); Wwidth = Lwidth + 2 * LmarginH; Wheight = Lheight + LmarginV + TmarginV; Brect = CDWin.ActiveLayer.CreateRectangle2(Left, Bottom, Width, Height); Brect.Outline.Color = Black; Brect.Outline.Width = ptToUnit(d.BorderWidth); s.Name = "semItemContent"; s.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignTop, Brect); s.AddToPowerClip(Brect, CorelDRAW.cdrTriState.cdrFalse); if (d.ValInBar == true) { Wheight = Theight + 2 * TmarginV; } if (!NoBar) { Lrect = CDWin.ActiveLayer.CreateRectangle2(Left + Width - Wwidth, Bottom, Wwidth, Wheight + ((d.ValInBar != true) ? Theight : 0)); Wline = CDWin.ActiveLayer.CreateLineSegment(Left + Width - LmarginH - Lwidth, Bottom + Wheight / 2, Left + Width - LmarginH, Bottom + Wheight / 2); Ttext = CDWin.ActiveLayer.CreateArtisticText(Left + Width - Wwidth / 2, Bottom + Wheight / 2 + TmarginV, d.BarText, Alignment: CorelDRAW.cdrAlignment.cdrCenterAlignment, Size: d.FontSize, Font: d.FontName); //Ttext.Text.Story.Font Ttext.Text.Story.Bold = d.TextBold == true; Lrect.Outline.Width = 0; Lrect.Fill.ApplyUniformFill(White); Wline.Outline.Width = ptToUnit(d.BarWidth); Wline.Outline.Color = Black; Wline.Outline.EndArrow = CDWin.ArrowHeads[59]; Wline.Outline.StartArrow = CDWin.ArrowHeads[59]; if (d.ValInBar == true) { Shape Trect; Trect = CDWin.ActiveLayer.CreateRectangle2(Left + Width, Bottom, 2d * TmarginH + Ttext.SizeWidth, Ttext.SizeHeight); Ttext.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignVCenter, Wline, CorelDRAW.cdrTextAlignOrigin.cdrTextAlignBoundingBox); Ttext.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignHCenter, Wline, CorelDRAW.cdrTextAlignOrigin.cdrTextAlignBoundingBox); Trect.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignVCenter, Ttext); Trect.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignHCenter, Ttext); Trect.Fill.ApplyUniformFill(White); Trect.Outline.Width = 0; Trect.OrderBackOf(Ttext); SR.Add(Trect); } SR.Add(Lrect); SR.Add(Wline); SR.Add(Ttext); Gr = SR.Group(); Gr.AddToPowerClip(Brect, CorelDRAW.cdrTriState.cdrFalse); } if (d.ULtext.Trim() != "") { Shape back, text; text = CDWin.ActiveLayer.CreateArtisticText(Left + TmarginH, Bottom + Height - Theight - TmarginV, d.ULtext, Alignment: CorelDRAW.cdrAlignment.cdrLeftAlignment, Size: d.FontSize, Font: d.FontName); back = CDWin.ActiveLayer.CreateRectangle2(Left, Bottom + Height - Theight - 2d * TmarginV, text.SizeWidth + 2d * TmarginH, Theight + 2 * TmarginV); back.Fill.ApplyUniformFill(White); text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignHCenter, back); text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignBottom, back, CorelDRAW.cdrTextAlignOrigin.cdrTextAlignFirstBaseline); text.BottomY += TmarginV; back.Outline.Width = 0; back.OrderBackOf(text); text.Text.Story.Bold = d.TextBold == true; TextShapes.Add(text); TextShapes.Add(back); } if (d.URtext != "") { Shape back, text; text = CDWin.ActiveLayer.CreateArtisticText(Left + Width - TmarginH, Bottom + Height - Theight - TmarginV, d.URtext, Alignment: CorelDRAW.cdrAlignment.cdrRightAlignment, Size: d.FontSize, Font: d.FontName); back = CDWin.ActiveLayer.CreateRectangle2(Left + Width - text.SizeWidth - 2 * TmarginH, Bottom + Height - Theight - 2 * TmarginV, text.SizeWidth + 2 * TmarginH, Theight + 2 * TmarginV); back.Fill.ApplyUniformFill(White); text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignHCenter, back); text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignBottom, back, CorelDRAW.cdrTextAlignOrigin.cdrTextAlignFirstBaseline); text.BottomY += TmarginV; back.Outline.Width = 0; back.OrderBackOf(text); text.Text.Story.Bold = d.TextBold == true; TextShapes.Add(text); TextShapes.Add(back); } if (d.BLtext != "") { Shape back, text; text = CDWin.ActiveLayer.CreateArtisticText(Left + TmarginH, Bottom + TmarginV, d.BLtext, Alignment: CorelDRAW.cdrAlignment.cdrLeftAlignment, Size: d.FontSize, Font: d.FontName); back = CDWin.ActiveLayer.CreateRectangle2(Left, Bottom, text.SizeWidth + 2 * TmarginH, Theight + 2 * TmarginV); back.Fill.ApplyUniformFill(White); text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignHCenter, back); text.AlignToShape(CorelDRAW.cdrAlignType.cdrAlignBottom, back, CorelDRAW.cdrTextAlignOrigin.cdrTextAlignFirstBaseline); text.BottomY += TmarginV; back.Outline.Width = 0; back.OrderBackOf(text); text.Text.Story.Bold = d.TextBold == true; TextShapes.Add(text); TextShapes.Add(back); } TextShapes.AddToPowerClip(Brect, CorelDRAW.cdrTriState.cdrFalse); Brect.Properties["semItem", 0] = true; Brect.Properties["semItem", 1] = curShape.imgData.ToString(); if (d.filename != "") Brect.Name = d.filename; Brect.CenterX = oldCenterX; Brect.CenterY = oldCenterY; CDWin.ActiveWindow.Refresh(); CDWin.Application.Refresh(); CDWin.ActiveDocument.ClearSelection(); Brect.Selected = true; }
// Sealed method: Subclasses should override ExecutePasteAction instead protected sealed override void ExecuteAction(string ribbonId) { this.StartNewUndoEntry(); PowerPointPresentation presentation = this.GetCurrentPresentation(); PowerPointSlide slide = this.GetCurrentSlide(); Selection selection = this.GetCurrentSelection(); if (ClipboardUtil.IsClipboardEmpty()) { Logger.Log(ribbonId + " failed. Clipboard is empty."); MessageBox.Show(PasteLabText.ErrorEmptyClipboard, PasteLabText.ErrorDialogTitle); return; } ShapeRange passedSelectedShapes = null; ShapeRange passedSelectedChildShapes = null; if (ShapeUtil.IsSelectionShape(selection) && !IsSelectionIgnored(ribbonId)) { // When pasting some objects, the selection may change to the pasted object (e.g. jpg from desktop). // Therefore we must capture the selection first. ShapeRange selectedShapes = selection.ShapeRange; // Preserve selection by tagging them for (int i = 1; i <= selectedShapes.Count; i++) { selectedShapes[i].Tags.Add(SelectOrderTagName, i.ToString()); } ShapeRange selectedChildShapes = null; if (selection.HasChildShapeRange) { selectedChildShapes = selection.ChildShapeRange; for (int i = 1; i <= selectedChildShapes.Count; i++) { selectedChildShapes[i].Tags.Add(SelectChildOrderTagName, i.ToString()); } } // Corruption correction ShapeRange correctedShapes = ShapeUtil.CorruptionCorrection(selectedShapes, slide); // Reselect the preserved selections List <Shape> correctedShapeList = new List <Shape>(); List <Shape> correctedChildShapeList = new List <Shape>(); foreach (Shape shape in correctedShapes) { correctedShapeList.Add(shape); correctedChildShapeList.AddRange(ShapeUtil.GetChildrenWithNonEmptyTag(shape, SelectChildOrderTagName)); } correctedShapeList.Sort((sh1, sh2) => int.Parse(sh1.Tags[SelectOrderTagName]) - int.Parse(sh2.Tags[SelectOrderTagName])); correctedChildShapeList.Sort((sh1, sh2) => int.Parse(sh1.Tags[SelectChildOrderTagName]) - int.Parse(sh2.Tags[SelectChildOrderTagName])); passedSelectedShapes = slide.ToShapeRange(correctedShapeList); passedSelectedChildShapes = slide.ToShapeRange(correctedChildShapeList); // Remove shape tags after they have been used ShapeUtil.DeleteTagFromShapes(passedSelectedShapes, SelectOrderTagName); ShapeUtil.DeleteTagFromShapes(passedSelectedChildShapes, SelectChildOrderTagName); } ShapeRange result = ExecutePasteAction(ribbonId, presentation, slide, passedSelectedShapes, passedSelectedChildShapes); if (result != null) { result.Select(); } }
protected abstract ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide, ShapeRange selectedShapes, ShapeRange selectedChildShapes);
private void SyncShapes(ShapeRange selected, ShapeRange simulatedShapes) { for (int i = 1; i <= selected.Count; i++) { var selectedShape = selected[i]; var simulatedShape = simulatedShapes[i]; var selectedCenter = Graphics.GetCenterPoint(selectedShape); var simulatedCenter = Graphics.GetCenterPoint(simulatedShape); selectedShape.IncrementLeft(simulatedCenter.X - selectedCenter.X); selectedShape.IncrementTop(simulatedCenter.Y - selectedCenter.Y); } }