public void FitShapeToText(TargetShapes targets) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); var shapes = targets.ResolveShapes2D(this._client); if (shapes.Shapes.Count < 1) { return; } var application = this._client.Application.Get(); var active_page = application.ActivePage; var shapeids = shapes.Shapes.Select(s => s.ID).ToList(); using (var undoscope = this._client.Application.NewUndoScope("Fit Shape To Text")) { // Calculate the new sizes for each shape var new_sizes = new List <Drawing.Size>(shapeids.Count); foreach (var shape in shapes.Shapes) { var text_bounding_box = shape.GetBoundingBox(IVisio.VisBoundingBoxArgs.visBBoxUprightText).Size; var wh_bounding_box = shape.GetBoundingBox(IVisio.VisBoundingBoxArgs.visBBoxUprightWH).Size; double max_w = System.Math.Max(text_bounding_box.Width, wh_bounding_box.Width); double max_h = System.Math.Max(text_bounding_box.Height, wh_bounding_box.Height); var max_size = new Drawing.Size(max_w, max_h); new_sizes.Add(max_size); } var src_width = VisioAutomation.ShapeSheet.SRCConstants.Width; var src_height = VisioAutomation.ShapeSheet.SRCConstants.Height; var writer = new FormulaWriterSIDSRC(); for (int i = 0; i < new_sizes.Count; i++) { var shapeid = shapeids[i]; var new_size = new_sizes[i]; writer.SetFormula((short)shapeid, src_width, new_size.Width); writer.SetFormula((short)shapeid, src_height, new_size.Height); } writer.Commit(active_page); } }
public void SetTextWrapping(TargetShapes targets, bool wrap) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); var shapes = targets.ResolveShapes2D(this._client); if (shapes.Shapes.Count < 1) { return; } var shapeids = shapes.Shapes.Select(s => s.ID).ToList(); var active_page = this._client.Page.Get(); using (var undoscope = this._client.Application.NewUndoScope("Set Text Wrapping")) { TextHelper.set_text_wrapping(active_page, shapeids, wrap); } }
public void SnapSize(TargetShapes targets, Drawing.Size snapsize, Drawing.Size minsize) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); var shapes = targets.ResolveShapes2D(this._client); if (shapes.Shapes.Count < 1) { return; } var application = this._client.Application.Get(); var page = application.ActivePage; var target_ids = targets.ToShapeIDs(); using (var undoscope = this._client.Application.NewUndoScope("Snap Shape Size")) { ArrangeHelper.SnapSize(page, target_ids, snapsize, minsize); } }
public void SnapCorner(TargetShapes targets, double w, double h, SnapCornerPosition corner) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); var shapes = targets.ResolveShapes2D(this._client); if (shapes.Shapes.Count < 1) { return; } var application = this._client.Application.Get(); var page = application.ActivePage; var target_ids = targets.ToShapeIDs(); using (var undoscope = this._client.Application.NewUndoScope("Snap Shape Corner")) { ArrangeHelper.SnapCorner(page, target_ids, new Drawing.Size(w, h), corner); } }