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 shapeToFillSlide = pastingShapes[1]; if (pastingShapes.Count > 1) { shapeToFillSlide = pastingShapes.Group(); } 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); }
private void TransparentEffect(ShapeRange shapeRange) { foreach (Shape shape in shapeRange) { if (shape.Type == Office.MsoShapeType.msoGroup) { ShapeRange subShapeRange = shape.Ungroup(); TransparentEffect(subShapeRange); subShapeRange.Group(); } else if (shape.Type == Office.MsoShapeType.msoPlaceholder) { PlaceholderTransparencyHandler(shape); } else if (shape.Type == Office.MsoShapeType.msoPicture) { PictureTransparencyHandler(shape); } else if (shape.Type == Office.MsoShapeType.msoLine) { LineTransparencyHandler(shape); } else if (IsTransparentableShape(shape)) { ShapeTransparencyHandler(shape); } } }
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 shapeToFitSlide = GraphicsUtil.CompressImageInShape(pastingShape, slide); // Bring the same original shapes back into clipboard, preserving original size origClipboardShapes.Cut(); 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); }
public static ShapeRange Execute(PowerPointPresentation presentation, PowerPointSlide slide, Selection selection) { ShapeRange selectedShapes = selection.ShapeRange; Shape firstSelectedShape = selectedShapes[1]; // Temporarily save the animation Shape tempShapeForAnimation = slide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 0, 0, 1, 1); slide.TransferAnimation(firstSelectedShape, tempShapeForAnimation); // Ungroup first selection and add into list string groupName = firstSelectedShape.Name; bool isFirstSelectionGroup = false; List <Shape> newShapesList = new List <Shape>(); if (firstSelectedShape.IsCorrupted()) { firstSelectedShape = ShapeUtil.CorruptionCorrection(firstSelectedShape, slide); } if (firstSelectedShape.IsAGroup()) { isFirstSelectionGroup = true; ShapeRange ungroupedShapes = firstSelectedShape.Ungroup(); foreach (Shape shape in ungroupedShapes) { newShapesList.Add(shape); } } else { newShapesList.Add(firstSelectedShape); } // Add all other selections into list for (int i = 2; i <= selectedShapes.Count; i++) { Shape shape = selectedShapes[i]; if (shape.IsCorrupted()) { shape = ShapeUtil.CorruptionCorrection(shape, slide); } newShapesList.Add(shape); } // Create the new group from the list selectedShapes = slide.ToShapeRange(newShapesList); Shape selectedGroup = selectedShapes.Group(); selectedGroup.Name = isFirstSelectionGroup ? groupName : selectedGroup.Name; // Transfer the animation slide.TransferAnimation(tempShapeForAnimation, selectedGroup); tempShapeForAnimation.SafeDelete(); return(slide.ToShapeRange(selectedGroup)); }
// groups the shaperange only if there is 2 or more elements public static Shape SafeGroup(this ShapeRange range) { if (range.Count > 1) { return(range.Group()); } else if (range.Count == 1) { return(range[1]); } else { return(null); } }
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 Shape CreateBe() { ShapeRange orSh = app.ActiveSelectionRange; Size s = new Size(orSh.SizeWidth, orSh.SizeHeight); double space = 0; 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)); } return(orSh.Group()); }
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 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(); } }
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 { } }
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 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 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 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"); } }
private void DoDrawCropMarks() { double X, y, cx, cy; double sx, sy, dx, ty; double Off, l, Cu; long N; ShapeRange sr = new ShapeRange(); Shape s, s1; ShapeRange AllShapes = new ShapeRange(); this.StartEvent(); app.ActiveDocument.Unit = cdrUnit.cdrMillimeter; app.ActiveDocument.PreserveSelection = false; app.ActiveDocument.Selection().GetBoundingBox(out X, out y, out cx, out cy, false); Off = (double)nudOffset.Value; l = (double)nudLen.Value; sr.Add(DrawLine(X - Off - l, y, X - Off, y)); sr.Add(DrawLine(X - Off - l, y + cy, X - Off, y + cy)); sr.Add(DrawLine(X + cx + Off, y, X + cx + Off + l, y)); sr.Add(DrawLine(X + cx + Off, y + cy, X + cx + Off + l, y + cy)); sr.Add(DrawLine(X, y - Off - l, X, y - Off)); sr.Add(DrawLine(X + cx, y - Off - l, X + cx, y - Off)); sr.Add(DrawLine(X, y + Off + l + cy, X, y + Off + cy)); sr.Add(DrawLine(X + cx, y + Off + l + cy, X + cx, y + Off + cy)); AllShapes.Add(sr.Group()); if (chkCu.Checked) { Cu = (double)nudCu.Value; sr.RemoveAll(); sr.Add(DrawLine(X - Off - l, y + Cu, X - Off, y + Cu)); sr.Add(DrawLine(X - Off - l, y + cy - Cu, X - Off, y + cy - Cu)); sr.Add(DrawLine(X + cx + Off, y + Cu, X + cx + Off + l, y + Cu)); sr.Add(DrawLine(X + cx + Off, y + cy - Cu, X + cx + Off + l, y + cy - Cu)); sr.Add(DrawLine(X + Cu, y - Off - l, X + Cu, y - Off)); sr.Add(DrawLine(X + cx - Cu, y - Off - l, X + cx - Cu, y - Off)); sr.Add(DrawLine(X + Cu, y + Off + l + cy, X + Cu, y + Off + cy)); sr.Add(DrawLine(X + cx - Cu, y + Off + l + cy, X + cx - Cu, y + Off + cy)); AllShapes.Add(sr.Group()); } if (chkZxsp.Checked) { sr.RemoveAll(); sr.RemoveAll(); sr.Add(DrawLine(X - Off - l, y + cy / 2, X, y + cy / 2)); sr.Add(DrawLine(X + cx, y + cy / 2, X + cx + Off + l, y + cy / 2)); Outline ol = new Outline(); sr.SetOutlinePropertiesEx(-1, new OutlineStyle(), app.CreateCMYKColor(100, 100, 100, 100), null, null, cdrTriState.cdrFalse, cdrTriState.cdrFalse, cdrOutlineLineCaps.cdrOutlineButtLineCaps); //sr.SetOutlineProperties(0.2, new OutlineStyle(2)); AllShapes.Add(sr.Group()); } if (chkZxcz.Checked) { sr.RemoveAll(); sr.Add(DrawLine(X + cx / 2, y + cy, X + cx / 2, y + cy + Off + l)); sr.Add(DrawLine(X + cx / 2, y, X + cx / 2, y - Off - l)); OutlineStyle ols = new OutlineStyle(); sr.SetOutlineProperties(0.2, ols); AllShapes.Add(sr.Group()); } if (chkJdsp.Checked) { Cu = (double)nudCu.Value; sr.RemoveAll(); sr.Add(DrawLine(X - Off - l, y + cy / 2 + Cu, X - Off, y + cy / 2 + Cu)); sr.Add(DrawLine(X - Off - l, y + cy / 2 - Cu, X - Off, y + cy / 2 - Cu)); sr.Add(DrawLine(X + cx + Off, y + cy / 2 + Cu, X + cx + Off + l, y + cy / 2 + Cu)); sr.Add(DrawLine(X + cx + Off, y + cy / 2 - Cu, X + cx + Off + l, y + cy / 2 - Cu)); AllShapes.Add(sr.Group()); } if (chkJdcz.Checked) { Cu = (double)nudCu.Value; sr.RemoveAll(); sr.Add(DrawLine(X + cx / 2 + Cu, y + cy + Off, X + cx / 2 + Cu, y + cy + Off + l)); sr.Add(DrawLine(X + cx / 2 - Cu, y + cy + Off, X + cx / 2 - Cu, y + cy + Off + l)); sr.Add(DrawLine(X + cx / 2 + Cu, y - Off, X + cx / 2 + Cu, y - Off - l)); sr.Add(DrawLine(X + cx / 2 - Cu, y - Off, X + cx / 2 - Cu, y - Off - l)); AllShapes.Add(sr.Group()); } AllShapes.Group(); this.EndEvent(); }
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; }
private void createShadow(Shape s, Shape sh, int dpi, double angle, double size) { try { ShapeRange forComb = null; double tw = 0, th = 0, tx = 0, ty = 0; if ((bool)cbInnerShadow.IsChecked) { double nw = 0, nh = 0, nx = 0, ny = 0; sh.GetSize(out nw, out nh); sh.GetPositionEx(cdrReferencePoint.cdrCenter, out nx, out ny); //double dist = str2dbl(tbDistance.Text); //if (dist == 0) dist = size; //if (dist == 0) dist = 0.1; //nw = nw + (dist * 4); nh = nh + (dist * 4); nw = nw + (nw / 2); nh = nh + (nh / 2); Shape sAround = sh.Layer.CreateRectangle2(0, 0, nw, nh, 0, 0, 0, 0); sAround.SetPositionEx(cdrReferencePoint.cdrCenter, nx, ny); forComb = new ShapeRange(); forComb.Add(sh); forComb.Add(sAround); sh = forComb.Combine(); } sh.OrderBackOf(s); sh.Fill.UniformColor.CopyAssign(_shColor); sh.Outline.SetProperties(size, null, _shColor); if ((bool)cbInnerShadow.IsChecked) { sh.FillMode = cdrFillMode.cdrFillAlternate; //new fill fix } var imgType = cdrImageType.cdrCMYKColorImage; switch (_shColor.Type.ToString()) { case "cdrColorGray": imgType = cdrImageType.cdrGrayscaleImage; break; case "cdrColorLab": imgType = cdrImageType.cdrLABImage; break; case "cdrColorRGB": imgType = cdrImageType.cdrRGBColorImage; break; } sh = sh.ConvertToBitmapEx(imgType, false, true, dpi, cdrAntiAliasingType.cdrNormalAntiAliasing, true, false); double feather = str2dbl(tbFeather.Text) * 100; // TODO: Looks like ApplyBitmapEffect doesn't work correctly in 2019 sh.Bitmap.ApplyBitmapEffect(@"Gaussian Blur", @"GaussianBlurEffect GaussianBlurRadius=" + feather.ToString(CultureInfo.InvariantCulture) + ", GaussianBlurResampled=0"); int opacity = (Convert.ToInt32(tbOpacity.Text) - 100) * -1; sh.Transparency.ApplyUniformTransparency(opacity); sh.Transparency.AppliedTo = cdrTransparencyAppliedTo.cdrApplyToFillAndOutline; switch (cbMode.SelectedValue.ToString()) { case "Normal": sh.Transparency.MergeMode = cdrMergeMode.cdrMergeNormal; break; case "Multiply": sh.Transparency.MergeMode = cdrMergeMode.cdrMergeMultiply; break; case "Add": sh.Transparency.MergeMode = cdrMergeMode.cdrMergeAdd; break; //case "0": sh.Transparency.MergeMode = } sh = sh.ConvertToBitmapEx(imgType, false, true, dpi, cdrAntiAliasingType.cdrNormalAntiAliasing, true, false); sh.Properties["DS2", 1] = createPresetStr(); //add settings if ((bool)cbOverPrint.IsChecked) { sh.OverprintBitmap = true; } if ((bool)cbInnerShadow.IsChecked) { sh.AddToPowerClip(s); } else { if ((bool)cbGroup.IsChecked) { var gr = new ShapeRange(); gr.Add(s); gr.Add(sh); gr.Group(); gr = null; } } } catch (Exception err) { MessageBox.Show(err.ToString(), MName, MessageBoxButton.OK, MessageBoxImage.Error); } }
public static ShapeRange Execute(PowerPointPresentation presentation, PowerPointSlide slide, ShapeRange selectedShapes, ShapeRange selectedChildShapes, ShapeRange pastingShapes) { // 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); selectedShape.Delete(); 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; } } // Remove selected child since it is being replaced ShapeRange shapesToGroup = slide.ToShapeRange(selectedGroupShapeList); selectedGroup.Ungroup(); selectedChildShape.Delete(); ShapeRange result = PasteIntoGroup.Execute(presentation, slide, shapesToGroup, pastingShapes, posLeft, posTop, shapeAbove); result[1].Name = originalGroupName; slide.TransferAnimation(tempShapeForAnimation, result[1]); tempShapeForAnimation.Delete(); return(result); } }
public static ShapeRange Execute(PowerPointPresentation presentation, PowerPointSlide slide, ShapeRange selectedShapes, ShapeRange pastingShapes, float?posLeft = null, float?posTop = null, Shape shapeAbove = null) { Shape firstSelectedShape = selectedShapes[1]; Shape tempShapeForAnimation = slide.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 0, 0, 1, 1); slide.TransferAnimation(firstSelectedShape, tempShapeForAnimation); ShapeUtil.MoveZToJustInFront(tempShapeForAnimation, firstSelectedShape); string originalGroupName = null; if (selectedShapes.Count == 1 && firstSelectedShape.IsAGroup()) { originalGroupName = firstSelectedShape.Name; selectedShapes = firstSelectedShape.Ungroup(); } // Calculate the center to paste at if not specified float selectionLeft = selectedShapes[1].Left; float selectionTop = selectedShapes[1].Top; float selectionWidth = selectedShapes[1].Width; float selectionHeight = selectedShapes[1].Height; if (selectedShapes.Count > 1) { Shape selectionGroup = selectedShapes.Group(); selectionLeft = selectionGroup.Left; selectionTop = selectionGroup.Top; selectionWidth = selectionGroup.Width; selectionHeight = selectionGroup.Height; selectionGroup.Ungroup(); } posLeft = posLeft ?? (selectionLeft + (selectionWidth - pastingShapes[1].Width) / 2); posTop = posTop ?? (selectionTop + (selectionHeight - pastingShapes[1].Height) / 2); PasteAtCursorPosition.Execute(presentation, slide, pastingShapes, posLeft.Value, posTop.Value); List <Shape> shapesToGroupList = new List <Shape>(); for (int i = 1; i <= selectedShapes.Count; i++) { shapesToGroupList.Add(selectedShapes[i]); } for (int i = 1; i <= pastingShapes.Count; i++) { shapesToGroupList.Add(pastingShapes[i]); } ShapeRange shapesToGroup = slide.ToShapeRange(shapesToGroupList); Shape resultGroup = shapesToGroup.Group(); resultGroup.Name = originalGroupName ?? resultGroup.Name; slide.TransferAnimation(tempShapeForAnimation, resultGroup); ShapeUtil.MoveZToJustInFront(resultGroup, tempShapeForAnimation); tempShapeForAnimation.SafeDelete(); if (shapeAbove == null) { pastingShapes.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoBringToFront); } else { ShapeUtil.MoveZToJustBehind(pastingShapes[1], shapeAbove); } return(slide.ToShapeRange(resultGroup)); }