private void DelImg() { ShapeRange orSh = app.ActiveSelectionRange; ShapeRange img = new ShapeRange(); ShapeRange unColor = new ShapeRange(); orSh.UngroupAll(); foreach (Shape sh in orSh) { if (sh.Type == cdrShapeType.cdrBitmapShape) { img.Add(sh); } else if (sh.Fill.Type == cdrFillType.cdrNoFill && sh.Outline.Type == cdrOutlineType.cdrNoOutline) { unColor.Add(sh); } } img.Delete(); if (unColor.Count > 0) { MessageBoxResult result = MessageBox.Show("Phát hiện viền bế ẩn, bạn có muốn tự động xóa?", "Cảnh báo!", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { unColor.Delete(); } } }
/// <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(Shape shape = null, 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(); } else if (shape != null) { shape.Copy(); shape.Delete(); } } catch (COMException e) { // May be thrown when trying to copy Logger.LogException(e, "RestoreClipboard"); } }
private void btnDelOutline_Click(object sender, RoutedEventArgs e) { if (checkActive()) { MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { ShapeRange orSh = app.ActiveSelectionRange; ShapeRange img = new ShapeRange(); orSh.UngroupAll(); foreach (Shape sh in orSh) { if (sh.Name == "txtOutline") { img.Add(sh); } } img.Delete(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); } }
private void TestDeleteTimerBodyPb(ITimerLabController timerLab) { PpOperations.SelectSlide(PbOriginalSlideNo); ShapeRange shapes = PpOperations.SelectShape(TimerBody); shapes.Delete(); MessageBoxUtil.ExpectMessageBoxWillPopUp("Error", "Only one timer allowed per slide.", timerLab.ClickCreateButton, "Ok"); AssertIsSame(PbOriginalSlideNo, PbRecreateBodySlideNo); }
private void EditEnd() { ImportFilter impflt; StructImportOptions impopt; impopt = application.CreateStructImportOptions(); impopt.Mode = cdrImportMode.cdrImportFull; impopt.MaintainLayers = true; impflt = application.ActiveLayer.ImportEx(CPtemp, cdrFilter.cdrPSD, impopt); impflt.Finish(); application.ActiveShape.SetMatrix(d11, d12, d21, d22, tx, ty); application.ActiveShape.OrderToFront(); BitmapA.Delete(); File.Delete(CPtemp); //EndEvent(); }
private void TestEditTextColorAndDeleteProgressBarPb(ITimerLabController timerLab) { PpOperations.SelectSlide(ChangeTextColorAndRecreateSliderSlideNo); int expectedColor = PpOperations.SelectShape(TimerTimeMarkerGroup)[1].TextFrame.TextRange.Font.Color.RGB; PpOperations.SelectSlide(PbOriginalSlideNo); ShapeRange timeMarkerGroup = PpOperations.SelectShape(TimerTimeMarkerGroup); timeMarkerGroup.TextFrame.TextRange.Font.Color.RGB = expectedColor; ShapeRange progressBar = PpOperations.SelectShape(ProgressBar); progressBar.Delete(); MessageBoxUtil.ExpectMessageBoxWillPopUp("Error", "Only one timer allowed per slide.", timerLab.ClickCreateButton, "Ok"); AssertIsSame(PbOriginalSlideNo, PbChangeTextColorAndRecreateSliderSlideNo); }
private void TestEditLineColorAndDeleteTimeMarkerPb(ITimerLabController timerLab) { PpOperations.SelectSlide(ChangeLineColorAndRecreateTimeMarkerSlideNo); int expectedColor = PpOperations.SelectShape(TimerLineMarkerGroup)[1].Line.ForeColor.RGB; PpOperations.SelectSlide(PbOriginalSlideNo); ShapeRange lineMarkerGroup = PpOperations.SelectShape(TimerLineMarkerGroup); lineMarkerGroup.Line.ForeColor.RGB = expectedColor; ShapeRange timeMarkerGroup = PpOperations.SelectShape(TimerTimeMarkerGroup); timeMarkerGroup.Delete(); MessageBoxUtil.ExpectMessageBoxWillPopUp("Error", "Only one timer allowed per slide.", timerLab.ClickCreateButton, "Ok"); AssertIsSame(PbOriginalSlideNo, PbChangeLineColorAndRecreateTimeMarkerSlideNo); }
private void btnCrSemiLine_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 orSh = app.ActiveSelectionRange; Shape sh = app.ActiveLayer.CreateRectangle(orSh.LeftX, orSh.TopY, orSh.RightX, orSh.BottomY); sh.ConvertToCurves(); Curve c = app.ActiveDocument.CreateCurve(); SubPath ss = c.CreateSubPath(orSh.RightX, orSh.BottomY); ss.AppendCurveSegment(orSh.LeftX, orSh.BottomY); ss.AppendCurveSegment(orSh.LeftX, orSh.TopY); sh.Curve.CopyAssign(c); orSh.Delete(); sh.CreateSelection(); orSh = app.ActiveSelectionRange; double space = 0; for (int i = 1; i < numRow.Value; i++) { space += s.y; orSh.AddRange(app.ActiveSelectionRange.Duplicate(0, -space)); } orSh.CreateSelection(); space = 0; for (int j = 1; j < numCol.Value; j++) { space += s.x; orSh.AddRange(app.ActiveSelectionRange.Duplicate(space, 0)); } orSh.Add(app.ActiveLayer.CreateLineSegment(orSh.PositionX, orSh.PositionY, orSh.PositionX + orSh.SizeWidth, orSh.PositionY)); orSh.Add(app.ActiveLayer.CreateLineSegment(orSh.PositionX + orSh.SizeWidth, orSh.PositionY, orSh.PositionX + orSh.SizeWidth, orSh.PositionY - orSh.SizeHeight)); orSh.Group(); app.ActiveLayer.CreateRectangle(orSh.LeftX, orSh.TopY, orSh.RightX, orSh.BottomY).CreateSelection(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); } }
private void TestEditTextColorAndDeleteSlider(ITimerLabController timerLab) { PpOperations.SelectSlide(ChangeTextColorAndRecreateSliderSlideNo); int expectedColor = PpOperations.SelectShape(TimerTimeMarkerGroup)[1].TextFrame.TextRange.Font.Color.RGB; PpOperations.SelectSlide(OriginalSlideNo); ShapeRange timeMarkerGroup = PpOperations.SelectShape(TimerTimeMarkerGroup); timeMarkerGroup.TextFrame.TextRange.Font.Color.RGB = expectedColor; List <string> sliderComponentNames = new List <string> { TimerSliderHead, TimerSliderBody }; ShapeRange sliderComponents = PpOperations.SelectShapes(sliderComponentNames); sliderComponents.Delete(); MessageBoxUtil.ExpectMessageBoxWillPopUp("Error", "Only one timer allowed per slide.", timerLab.ClickCreateButton, "Ok"); AssertIsSame(OriginalSlideNo, ChangeTextColorAndRecreateSliderSlideNo); }
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(); }
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 btnCreInsert_Click(object sender, RoutedEventArgs e) { if (checkActive()) { MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { app.ActiveDocument.Unit = cdrUnit.cdrCentimeter; Size s = new Size(app.ActiveSelection.SizeWidth, app.ActiveSelection.SizeHeight); ShapeRange orSh = app.ActiveSelectionRange; if (orSh.Shapes[1].Type == cdrShapeType.cdrBitmapShape && orSh.Count == 1) { Shape ell = app.ActiveLayer.CreateEllipse2(orSh.CenterX, orSh.CenterY, orSh.SizeWidth / 2, orSh.SizeHeight / 2); Shape newell = ell.Intersect(orSh.Shapes[1], true, true); orSh.Delete(); orSh.Add(newell); orSh.Add(ell); orSh.CreateSelection(); } double size = numInsert.Value; if (size == 0) { return; } double space = 0; spaceCal(); ShapeRange insert = app.ActiveSelectionRange.Duplicate(0, 0); app.ActiveDocument.ReferencePoint = cdrReferencePoint.cdrBottomRight; insert.SizeHeight = size; insert.SizeWidth = size; app.ActiveDocument.ReferencePoint = cdrReferencePoint.cdrTopLeft; double move = (size / 2) + (_space / 2); insert.Move(move, -move); for (int i = 1; i < numRow.Value; i++) { space += s.y + _space; orSh.AddRange(app.ActiveSelectionRange.Duplicate(0, -space)); } orSh.CreateSelection(); space = 0; for (int j = 1; j < numCol.Value; j++) { space += s.x + _space; orSh.AddRange(app.ActiveSelectionRange.Duplicate(space, 0)); } space = 0; insert.CreateSelection(); ShapeRange insertRange = insert; for (int ii = 1; ii < numRow.Value - 1; ii++) { space += s.y + _space; insertRange.AddRange(app.ActiveSelectionRange.Duplicate(0, -space)); } space = 0; insertRange.CreateSelection(); for (int jj = 1; jj < numCol.Value - 1; jj++) { space += s.x + _space; insertRange.AddRange(app.ActiveSelectionRange.Duplicate(space, 0)); } orSh.AddRange(insertRange); orSh.Group(); app.ActiveLayer.CreateRectangle(orSh.LeftX, orSh.TopY, orSh.RightX, orSh.BottomY).CreateSelection(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); } }
private void OkButton_Click(object sender, RoutedEventArgs e) { var marginTopValue = marginTopInput.Value; var marginBottomValue = marginBottomInput.Value; var marginLeftValue = marginLeftInput.Value; var marginRightValue = marginRightInput.Value; // Checks for margin values if (!marginTopValue.HasValue || marginTopValue.GetValueOrDefault() < 0 || !marginBottomValue.HasValue || marginBottomValue.GetValueOrDefault() < 0 || !marginLeftValue.HasValue || marginLeftValue.GetValueOrDefault() < 0 || !marginRightValue.HasValue || marginRightValue.GetValueOrDefault() < 0) { // TODO: Notify the user that not successfully changed return; } PositionsLabMain.SetDistributeMarginTop((float)marginTopValue); PositionsLabMain.SetDistributeMarginBottom((float)marginBottomValue); PositionsLabMain.SetDistributeMarginLeft((float)marginLeftValue); PositionsLabMain.SetDistributeMarginRight((float)marginRightValue); // Checks for distribute grid align reference if (alignLeftButton.IsChecked.GetValueOrDefault()) { PositionsLabMain.SetDistributeGridAlignment(PositionsLabMain.GridAlignment.AlignLeft); } if (alignCenterButton.IsChecked.GetValueOrDefault()) { PositionsLabMain.SetDistributeGridAlignment(PositionsLabMain.GridAlignment.AlignCenter); } if (alignRightButton.IsChecked.GetValueOrDefault()) { PositionsLabMain.SetDistributeGridAlignment(PositionsLabMain.GridAlignment.AlignRight); } ShapeRange simulatedShapes = null; try { var rowValue = rowInput.Value; var colValue = colInput.Value; if (!rowValue.HasValue || rowValue.GetValueOrDefault() == 0 || !colValue.HasValue || colValue.GetValueOrDefault() == 0) { return; } this.StartNewUndoEntry(); var selectedShapes = this.GetCurrentSelection().ShapeRange; simulatedShapes = DuplicateShapes(selectedShapes); var simulatedPPShapes = ConvertShapeRangeToPPShapeList(simulatedShapes, 1); PositionsLabMain.DistributeGrid(simulatedPPShapes, (int)colValue, (int)rowValue); SyncShapes(selectedShapes, simulatedShapes); } catch (Exception ex) { Close(); ShowErrorMessageBox(ex.Message, ex); } finally { simulatedShapes.Delete(); GC.Collect(); } Close(); }
private void btnCreaNum_Click(object sender, RoutedEventArgs e) { if (checkActive()) { MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { if (string.IsNullOrWhiteSpace(txtTextName.Text)) { txtTextName.SetResourceReference(System.Windows.Controls.Control.BorderBrushProperty, "ErrorColor"); MessageBox.Show("Không được để trống phần số gốc đang chọn!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } ShapeRange orSh = app.ActiveSelectionRange; bool flag = false, outline = false, find = false; double x = 0, y = 0; Color black = new Color(); black.CMYKAssign(0, 0, 0, 100); if (orSh.Shapes.Count == 1 && orSh.Shapes.First.Type == cdrShapeType.cdrGroupShape) { orSh.Ungroup(); } foreach (Shape ss in orSh.Shapes) { if (ss.Type == cdrShapeType.cdrTextShape) { if (ss.Text.Contents == txtTextName.Text) { x = ss.PositionX; y = ss.PositionY; ss.Text.AlignProperties.Alignment = cdrAlignment.cdrCenterAlignment; ss.PositionX = x; ss.PositionY = y; flag = true; ss.Name = "txtName"; } } if (!outline) { if (ss.Type == cdrShapeType.cdrCurveShape || ss.Type == cdrShapeType.cdrEllipseShape || ss.Type == cdrShapeType.cdrPolygonShape || ss.Type == cdrShapeType.cdrRectangleShape || ss.Type == cdrShapeType.cdrPerfectShape || ss.Type == cdrShapeType.cdrCustomShape) { if (ss.Fill.Type == cdrFillType.cdrNoFill && ss.Outline.Type != cdrOutlineType.cdrNoOutline) { if (!find) { ss.Name = "txtOutline"; find = true; } if (ss.Outline.Color.IsSame(black)) { ss.Name = "txtOutline"; outline = true; } } } } } if (!flag) { MessageBox.Show("Không tìm thấy Text có nội dung '" + txtTextName.Text + "'!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } orSh.Group().CreateSelection(); Size s = new Size(orSh.SizeWidth, orSh.SizeHeight); double space = 0; double p = spaceCalNum(); orSh = app.ActiveSelectionRange; for (int j = 1; j < numColNum.Value; j++) { space += s.x + p; orSh.AddRange(app.ActiveSelectionRange.Duplicate(space, 0)); } orSh.CreateSelection(); space = 0; for (int i = 1; i < Convert.ToInt32(lblRowNum.Content); i++) { space += s.y + p; orSh.AddRange(app.ActiveSelectionRange.Duplicate(0, -space)); } if (Convert.ToInt32(lblTotalNum.Content) < Convert.ToInt32(lblRowNum.Content) * numColNum.Value) { ShapeRange remove = new ShapeRange(); for (int i = Convert.ToInt32(lblTotalNum.Content) + 1; i <= Convert.ToInt32(lblRowNum.Content) * numColNum.Value; i++) { remove.Add(orSh.Shapes[i]); } remove.Delete(); } orSh.CreateSelection(); orSh = app.ActiveSelectionRange; int count = numFirstNum.Value; int lenght = numLastNum.Value.ToString().Length; foreach (Shape sp in orSh) { if (chk00.IsChecked.Value) { if (chkAuto.IsChecked.Value) { sp.Shapes["txtName"].Text.Contents = txtTextFirst.Text + count.ToString().PadLeft(lenght, '0') + txtTextLast.Text; } else { string num0String = new string('0', num0.Value); sp.Shapes["txtName"].Text.Contents = txtTextFirst.Text + num0String + count.ToString() + txtTextLast.Text; } } else { sp.Shapes["txtName"].Text.Contents = txtTextFirst.Text + count.ToString() + txtTextLast.Text; } count++; } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); } }
public static void SafeDelete(this ShapeRange shapeRange) { shapeRange.Delete(); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shapeRange); GC.Collect(); }
private void CreateShapes() { int lastPoint = 0; try { WriteLog("emf", "Start"); if (listShapes.Count != 0) { WriteLog("emf", " - nb shapes : " + listShapes.Count); Slides listSlide = Globals.ThisAddIn.Application.ActivePresentation.Slides; foreach (Slide maSlide in listSlide) { ShapeRange srd = maSlide.Shapes.Range(); srd.Delete(); WriteLog("emf", " - all existing slides deleted"); List <object> listNames = new List <object>(); int c = 0; foreach (string shapefile in listShapes) { string[] shapeInfo = shapefile.Split('*'); string shapeName = shapeInfo[0]; string[] polygons = shapeInfo[1].Split('_'); WriteLog("emf", " - Working on shape : " + shapeName + " - " + polygons.Length + " polygones"); for (int i = 0; i < polygons.Length; i++) { if (polygons[i] != "") { string[] coordinates = polygons[i].Split(','); if (coordinates.Length > 1) { /* * * * for (int j = 0; j < (coordinates.Length - 1); j++) * { * float val = (float)Convert.ToDouble(coordinates[j].Replace('.', ',')); * * if (y == 0) * { * * points[x, y] = (val); * } * if (y == 1) * { * points[x, y] = (val); * } * x2 = x; * * y++; * if (y == 2) * { * y = 0; * x++; * } * * lastPoint++; * } * */ //Single[,] myPoints = new Single[5, 2]; // {500,50,505,55,510,60,515,65,520,70}; int nbPoints = (coordinates.Length - 1) / 2; WriteLog("emf", " " + nbPoints + " points to create"); Single[,] points = new Single[nbPoints, 2]; int x = 0; int y = 0; int x2 = 0; for (int j = 0; j < (coordinates.Length - 1); j++) { double val = double.Parse(coordinates[j], System.Globalization.CultureInfo.InvariantCulture); if (y == 0) { points[x, y] = (float)val; } if (y == 1) { points[x, y] = (float)val; } x2 = x; y++; if (y == 2) { y = 0; x++; } lastPoint++; } object po = points; // WriteLog("emf", " Shape " + shapeName + " ready to be drawed with " + ((lastPoint) / 2) + "/" + nbPoints + " points, x=" + x + " , y=" + y + ", x2=" + x2); lastPoint = 0; maSlide.Shapes.AddPolyline(po).Name = shapeName; WriteLog("emf", " Shape " + shapeName + " drawed"); listNames.Add(shapeName); } } } } object[] arrayNames = new object[listNames.Count]; foreach (object name in listNames) { arrayNames[c] = name; c++; } ShapeRange sr = maSlide.Shapes.Range(); WriteLog("emf", " - group all shapes"); sr.Group().Name = "MonGoupe"; sr.Flip(Microsoft.Office.Core.MsoFlipCmd.msoFlipVertical); WriteLog("emf", " - prepare to resize the shapes"); float longeur = sr.Width; float hauteur = sr.Height; int maxWidth = 1280; int maxHeight = 500; float coef = 0; if (longeur < hauteur) { c = maxWidth / Convert.ToInt32(longeur); longeur = longeur * c; hauteur = hauteur * c; } else { c = maxHeight / Convert.ToInt32(hauteur); longeur = longeur * c; hauteur = hauteur * c; } sr.Width = longeur; sr.Height = hauteur; WriteLog("emf", " - Shapes reseized"); WriteLog("emf", " - Process End"); WriteLog("emf", " - "); WriteLog("emf", " - "); } // MessageBox.Show("Finished"); this.Close(); //Set myDocument = ActivePresentation.Slides(1) //With myDocument.Shapes // .AddShape(msoShapeCan, 50, 10, 100, 200).Name = "shpOne" // .AddShape(msoShapeCube, 150, 250, 100, 200).Name = "shpTwo" // With.Range(Array("shpOne", "shpTwo")).Group // End With //End With } } catch (Exception ex) { MessageBox.Show(@"An error occurred while creating the map, please send the log files in the folder 'C:\OCHA_logs' to the support [email protected]"); WriteLog("emf", " - Error Message : " + ex.Message); WriteLog("emf", " - Error StackTrace : " + ex.StackTrace); WriteLog("emf", " - Error TargetSite : " + ex.TargetSite); WriteLog("emf", " - Error InnerException : " + ex.InnerException); WriteLog("emf", " - Error ToString : " + ex.ToString()); WriteLog("emf", " - Error GetBaseException : " + ex.GetBaseException().ToString()); } finally { } }