private static IList <TabStop> GetTabStops(IVisio.Shape shape) { if (shape == null) { throw new System.ArgumentNullException("shape"); } int num_stops = VA.Text.TextFormat.GetTabStopCount(shape); if (num_stops < 1) { return(new List <TabStop>(0)); } const short row = 0; var srcs = new List <VA.ShapeSheet.SRC>(num_stops * 3); for (int stop_index = 0; stop_index < num_stops; stop_index++) { int i = stop_index * 3; var src_tabpos = new VA.ShapeSheet.SRC(tab_section, row, (short)(i + 1)); var src_tabalign = new VA.ShapeSheet.SRC(tab_section, row, (short)(i + 2)); var src_tabother = new VA.ShapeSheet.SRC(tab_section, row, (short)(i + 3)); srcs.Add(src_tabpos); srcs.Add(src_tabalign); srcs.Add(src_tabother); } var surface = new VA.Drawing.DrawingSurface(shape); var stream = VA.ShapeSheet.SRC.ToStream(srcs); var unitcodes = srcs.Select(i => IVisio.VisUnitCodes.visNumber).ToList(); var results = surface.GetResults_3 <double>(stream, unitcodes); var stops_list = new List <TabStop>(num_stops); for (int stop_index = 0; stop_index < num_stops; stop_index++) { var pos = results[(stop_index * 3) + 1]; var align = (VA.Text.TabStopAlignment)((int)results[(stop_index * 3) + 2]); var ts = new VA.Text.TabStop(pos, align); stops_list.Add(ts); } return(stops_list); }
public void Text_TabStops_Set() { var no_tab_stops = new VisioAutomation.Text.TabStop[] { }; var tabstops = new[] { new VisioAutomation.Text.TabStop(0.5, VisioAutomation.Text.TabStopAlignment.Left), new VisioAutomation.Text.TabStop(1.5, VisioAutomation.Text.TabStopAlignment.Right), new VisioAutomation.Text.TabStop(2.5, VisioAutomation.Text.TabStopAlignment.Center), new VisioAutomation.Text.TabStop(4.0, VisioAutomation.Text.TabStopAlignment.Decimal) }; var page1 = this.GetNewPage(); var s1 = page1.DrawRectangle(0, 0, 4, 4); // shapes shoould not have any tab stops by default var m0 = VisioAutomation.Text.TextFormat.GetFormat(s1, CellValueType.Formula); Assert.AreEqual(0, m0.TabStops.Count); // clearing tab stops shoudl work even if there are no tab stops VisioAutomation.Text.TextHelper.SetTabStops(s1, no_tab_stops); var m1 = VisioAutomation.Text.TextFormat.GetFormat(s1, CellValueType.Formula); Assert.AreEqual(0, m1.TabStops.Count); // set the 3 tab stops VisioAutomation.Text.TextHelper.SetTabStops(s1, tabstops); // should have exactly the same number we set var m2 = VisioAutomation.Text.TextFormat.GetFormat(s1, CellValueType.Formula); Assert.AreEqual(tabstops.Length, m2.TabStops.Count); Assert.AreEqual(0.5, tabstops[0].Position); Assert.AreEqual(1.5, tabstops[1].Position); Assert.AreEqual(2.5, tabstops[2].Position); Assert.AreEqual(4.0, tabstops[3].Position); Assert.AreEqual(VisioAutomation.Text.TabStopAlignment.Left, tabstops[0].Alignment); Assert.AreEqual(VisioAutomation.Text.TabStopAlignment.Right, tabstops[1].Alignment); Assert.AreEqual(VisioAutomation.Text.TabStopAlignment.Center, tabstops[2].Alignment); Assert.AreEqual(VisioAutomation.Text.TabStopAlignment.Decimal, tabstops[3].Alignment); // clear the tab stops VisioAutomation.Text.TextHelper.SetTabStops(s1, no_tab_stops); var m3 = VisioAutomation.Text.TextFormat.GetFormat(s1, CellValueType.Formula); Assert.AreEqual(0, m3.TabStops.Count); page1.Delete(0); }
public void Text_TabStops_Set() { var no_tab_stops = new VisioAutomation.Text.TabStop[] { }; var tabstops = new[] { new VisioAutomation.Text.TabStop(0.5, VisioAutomation.Text.TabStopAlignment.Left), new VisioAutomation.Text.TabStop(1.5, VisioAutomation.Text.TabStopAlignment.Right), new VisioAutomation.Text.TabStop(2.5, VisioAutomation.Text.TabStopAlignment.Center), new VisioAutomation.Text.TabStop(4.0, VisioAutomation.Text.TabStopAlignment.Decimal) }; var page1 = this.GetNewPage(); var s1 = page1.DrawRectangle(0, 0, 4, 4); // shapes shoould not have any tab stops by default var m0 = VisioAutomation.Text.TextFormat.GetFormat(s1); Assert.AreEqual(0, m0.TabStops.Count); // clearing tab stops shoudl work even if there are no tab stops VisioAutomation.Text.TextFormat.SetTabStops(s1, no_tab_stops); var m1 = VisioAutomation.Text.TextFormat.GetFormat(s1); Assert.AreEqual(0, m1.TabStops.Count); // set the 3 tab stops VisioAutomation.Text.TextFormat.SetTabStops(s1, tabstops); // should have exactly the same number we set var m2 = VisioAutomation.Text.TextFormat.GetFormat(s1); Assert.AreEqual(tabstops.Length, m2.TabStops.Count); Assert.AreEqual(0.5, tabstops[0].Position); Assert.AreEqual(1.5, tabstops[1].Position); Assert.AreEqual(2.5, tabstops[2].Position); Assert.AreEqual(4.0, tabstops[3].Position); Assert.AreEqual(VisioAutomation.Text.TabStopAlignment.Left, tabstops[0].Alignment); Assert.AreEqual(VisioAutomation.Text.TabStopAlignment.Right, tabstops[1].Alignment); Assert.AreEqual(VisioAutomation.Text.TabStopAlignment.Center, tabstops[2].Alignment); Assert.AreEqual(VisioAutomation.Text.TabStopAlignment.Decimal, tabstops[3].Alignment); // clear the tab stops VisioAutomation.Text.TextFormat.SetTabStops(s1, no_tab_stops); var m3 = VisioAutomation.Text.TextFormat.GetFormat(s1); Assert.AreEqual(0, m3.TabStops.Count); page1.Delete(0); }
private static IList<TabStop> GetTabStops(IVisio.Shape shape) { if (shape == null) { throw new System.ArgumentNullException("shape"); } int num_stops = VA.Text.TextFormat.GetTabStopCount(shape); if (num_stops < 1) { return new List<TabStop>(0); } const short row = 0; var srcs = new List<VA.ShapeSheet.SRC>(num_stops*3); for (int stop_index = 0; stop_index < num_stops; stop_index++) { int i = stop_index * 3; var src_tabpos = new VA.ShapeSheet.SRC(tab_section, row, (short)(i + 1)); var src_tabalign = new VA.ShapeSheet.SRC(tab_section, row, (short)(i + 2)); var src_tabother = new VA.ShapeSheet.SRC(tab_section, row, (short)(i + 3)); srcs.Add(src_tabpos); srcs.Add(src_tabalign ); srcs.Add(src_tabother); } var surface = new VA.Drawing.DrawingSurface(shape); var stream = VA.ShapeSheet.SRC.ToStream(srcs); var unitcodes = srcs.Select(i => IVisio.VisUnitCodes.visNumber).ToList(); var results = surface.GetResults_3<double>(stream, unitcodes); var stops_list = new List<TabStop>(num_stops); for (int stop_index = 0; stop_index < num_stops; stop_index++) { var pos = results[(stop_index*3) + 1]; var align = (VA.Text.TabStopAlignment) ((int)results[(stop_index*3) + 2]); var ts = new VA.Text.TabStop(pos, align); stops_list.Add(ts); } return stops_list; }