public static VisioAutomation.Models.Text.TextElement AddElementEx(this VisioAutomation.Models.Text.TextElement p, string text, int?font, double?size, int?color, AlignmentHorizontal?halign, VA.Models.Text.CharStyle?cs) { var el = p.AddElement(text); if (font != null) { el.CharacterFormatting.Font = font.Value; } if (size.HasValue) { el.CharacterFormatting.Size = string.Format("{0}pt", size.Value); } if (color.HasValue) { var c = new VisioAutomation.Drawing.ColorRGB(color.Value); el.CharacterFormatting.Color = c.ToFormula(); } if (halign.HasValue) { el.ParagraphFormatting.HorizontalAlign = (int)halign.Value; } if (cs.HasValue) { el.CharacterFormatting.Style = (int)cs; } return(el); }
public static void ProgressBar() { var page_a = SampleEnvironment.Application.ActiveDocument.Pages.Add(); // Draw some shapes var background = page_a.DrawRectangle(0, 0, 5, 1); var progress = page_a.DrawRectangle(0, 0, 1, 1); var background_fmt = new VA.Shapes.ShapeFormatCells(); background_fmt.FillForeground = "rgb(240,240,240)"; background_fmt.LineColor = "rgb(100,100,100)"; var progress_fmt = new VA.Shapes.ShapeFormatCells(); progress_fmt.FillForeground = "rgb(100,150,240)"; progress_fmt.LineColor = "rgb(100,100,100)"; // group the two shapes together page_a.Application.ActiveWindow.SelectAll(); var group = page_a.Application.ActiveWindow.Selection.Group(); // Set the progress shape update itself based on its position string bkname = background.NameID; var xform = new VA.Shapes.XFormCells(); xform.PinX = string.Format("GUARD({0}!PinX-{0}!LocPinX+LocPinX)", bkname); xform.PinY = string.Format("GUARD({0}!PinY)", bkname); xform.Width = string.Format("GUARD({0}!Width*(PAGENUMBER()/PAGECOUNT()))", bkname); xform.Height = string.Format("GUARD({0}!Height)", bkname); var writer = new SidSrcWriter(); xform.SetFormulas(progress.ID16, writer); background_fmt.SetFormulas(progress.ID16, writer); progress_fmt.SetFormulas(progress.ID16, writer); writer.Commit(page_a); var markup1 = new VisioAutomation.Models.Text.TextElement(); markup1.AddField(VisioAutomation.Models.Text.FieldConstants.PageName); markup1.AddText(" ("); markup1.AddField(VisioAutomation.Models.Text.FieldConstants.PageNumber); markup1.AddText(" of "); markup1.AddField(VisioAutomation.Models.Text.FieldConstants.NumberOfPages); markup1.AddText(") "); markup1.SetText(group); }
public void DomText_CharacterPlain() { var m = new VisioAutomation.Models.Text.TextElement("{Normal}"); var page1 = this.GetNewPage(new VisioAutomation.Drawing.Size(5, 5)); var s0 = page1.DrawRectangle(0, 0, 4, 4); m.SetText(s0); var textfmt = VisioAutomation.Text.TextFormat.GetFormat(s0); var charfmt = textfmt.CharacterFormats; Assert.AreEqual(1, charfmt.Count); page1.Delete(0); }
public void DomText_ParagraphDefault() { var m = new VisioAutomation.Models.Text.TextElement("{DefaultPara}"); var page1 = this.GetNewPage(new VisioAutomation.Drawing.Size(5, 5)); var s0 = page1.DrawRectangle(0, 0, 4, 4); m.SetText(s0); var textfmt = VisioAutomation.Text.TextFormat.GetFormat(s0); var parafmt = textfmt.ParagraphFormats; Assert.AreEqual(1, parafmt.Count); page1.Delete(0); }
public static void TextFields() { var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); var s0 = page.DrawRectangle(1, 1, 4, 4); var markup1 = new VisioAutomation.Models.Text.TextElement(); markup1.AddField(VisioAutomation.Models.Text.FieldConstants.PageName); markup1.AddText(" ("); markup1.AddField(VisioAutomation.Models.Text.FieldConstants.PageNumber); markup1.AddText(" of "); markup1.AddField(VisioAutomation.Models.Text.FieldConstants.NumberOfPages); markup1.AddText(") "); markup1.SetText(s0); }
public static void TextMarkup14() { var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); // Create the Shapes that will hold the text var s1 = page.DrawRectangle(0, 0, 8.5, 11); var e1 = new VisioAutomation.Models.Text.TextElement(); e1.AddText("This shape is "); e1.AddField(VisioAutomation.Models.Text.FieldConstants.Width); e1.AddText("inches wide by "); e1.AddField(VisioAutomation.Models.Text.FieldConstants.Height); e1.AddText("inches tall."); e1.SetText(s1); }
public static void TextMarkup11() { var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); // Create the Shapes that will hold the text var s1 = page.DrawRectangle(0, 0, 8.5, 11); var tnr = page.Document.Fonts["Times New Roman"]; var e1 = new VisioAutomation.Models.Text.TextElement(); var color_red = new ColorRGB(0xff0000); e1.CharacterFormatting.Color = color_red.ToFormula(); e1.CharacterFormatting.Font = tnr.ID; e1.CharacterFormatting.Font = "20pt"; e1.AddText("Hello World"); e1.SetText(s1); }
public void DomText_CharacterItalic() { var m = new VisioAutomation.Models.Text.TextElement("{Italic}"); m.CharacterFormatting.Style = (int)VA.Models.Text.CharStyle.Italic; var page1 = this.GetNewPage(new VisioAutomation.Drawing.Size(5, 5)); var s0 = page1.DrawRectangle(0, 0, 4, 4); m.SetText(s0); var textfmt = VisioAutomation.Text.TextFormat.GetFormat(s0); var charfmt = textfmt.CharacterFormats; Assert.AreEqual(1, charfmt.Count); Assert.AreEqual(((int)VA.Models.Text.CharStyle.Italic).ToString(), charfmt[0].Style.Result); page1.Delete(0); }
public static void TextMarkup13() { var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); var segoe_ui = page.Document.Fonts["Segoe UI"]; // Create the Shapes that will hold the text var s1 = page.DrawRectangle(0, 0, 8.5, 11); var e1 = new VisioAutomation.Models.Text.TextElement(); e1.AddText("When, from behind that craggy steep\n"); e1.AddText("till then the horizon’s bound\n"); var e2 = e1.AddElementEx("a huge peak, black and huge\n", null, null, null, AlignmentHorizontal.Left, VA.Models.Text.CharStyle.Italic); var e3 = e1.AddElementEx("As if with voluntary power instinct\n", segoe_ui.ID, null, null, AlignmentHorizontal.Center, VA.Models.Text.CharStyle.Bold); var e4 = e1.AddElementEx("Upreared its head.\n", null, null, null, AlignmentHorizontal.Right, VA.Models.Text.CharStyle.Italic); e1.AddText("-William Wordsworth, the Prelude"); e1.SetText(s1); }
public void DomText_ParagraphRight() { var m = new VisioAutomation.Models.Text.TextElement("{RightHAlign}"); m.ParagraphFormatting.HorizontalAlign = (int)AlignmentHorizontal.Right; var page1 = this.GetNewPage(new VisioAutomation.Drawing.Size(5, 5)); var s0 = page1.DrawRectangle(0, 0, 4, 4); m.SetText(s0); var textfmt = VisioAutomation.Text.TextFormat.GetFormat(s0); var parafmt = textfmt.ParagraphFormats; Assert.AreEqual(1, parafmt.Count); Assert.AreEqual(((int)AlignmentHorizontal.Right).ToString(), parafmt[0].HorizontalAlign.Result); page1.Delete(0); }
public void DomText_CharacterFont() { var page1 = this.GetNewPage(new VisioAutomation.Drawing.Size(5, 5)); var impact = page1.Document.Fonts["Arial"]; var m = new VisioAutomation.Models.Text.TextElement("Normal Text in Impact Font"); m.CharacterFormatting.Font = impact.ID; var s0 = page1.DrawRectangle(0, 0, 4, 4); m.SetText(s0); var textfmt = VisioAutomation.Text.TextFormat.GetFormat(s0); var charfmt = textfmt.CharacterFormats; Assert.AreEqual(1, charfmt.Count); Assert.AreEqual("0", charfmt[0].Style.Result); Assert.AreEqual(impact.ID.ToString(), charfmt[0].Font.Result); page1.Delete(0); }
public static void TextMarkup5() { var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); // Create the Shapes that will hold the text var s1 = page.DrawRectangle(0, 0, 8.5, 11); var e1 = new VisioAutomation.Models.Text.TextElement(); e1.ParagraphFormatting.HorizontalAlign = 0; var e2 = e1.AddElement("Hello Worldline1\nline2\nline3\n"); e2.ParagraphFormatting.IndentFirst = "0.5pt"; e2.ParagraphFormatting.IndentLeft = "0.25pt"; var e3 = e1.AddElement("Goodbye\nline1\nline2\nline3"); e3.ParagraphFormatting.IndentFirst = "1.0pt"; e3.ParagraphFormatting.IndentLeft = "0.75pt"; e1.SetText(s1); }
public Container(VisioAutomation.Models.Text.TextElement text) { this.Text = text; this.ContainerItems = new List <ContainerItem>(); }
public void DomText_CharacterComplex() { var page1 = this.GetNewPage(new VisioAutomation.Drawing.Size(5, 5)); var doc = page1.Document; var fonts = doc.Fonts; var segoeui = fonts["Segoe UI"]; var impact = fonts["Arial"]; var couriernew = fonts["Courier New"]; var georgia = fonts["Georgia"]; var t1 = new VisioAutomation.Models.Text.TextElement("{Normal}"); t1.CharacterFormatting.Font = segoeui.ID; var t2 = t1.AddElement("{Italic}"); t2.CharacterFormatting.Style = (int)VA.Models.Text.CharStyle.Italic; t2.CharacterFormatting.Font = impact.ID; var t3 = t2.AddElement("{Bold}"); t3.CharacterFormatting.Style = (int)VA.Models.Text.CharStyle.Bold; t3.CharacterFormatting.Font = couriernew.ID; var t4 = t2.AddElement("{Bold Italic}"); t4.CharacterFormatting.Style = (int)(VA.Models.Text.CharStyle.Bold | VA.Models.Text.CharStyle.Italic); t4.CharacterFormatting.Font = georgia.ID; var s0 = page1.DrawRectangle(0, 0, 4, 4); t1.SetText(s0); var textfmt = VisioAutomation.Text.TextFormat.GetFormat(s0); var charfmt = textfmt.CharacterFormats; // check the number of character regions Assert.AreEqual(5, charfmt.Count); // check the fonts Assert.AreEqual(segoeui.ID.ToString(), charfmt[0].Font.Result); Assert.AreEqual(impact.ID.ToString(), charfmt[1].Font.Result); Assert.AreEqual(couriernew.ID.ToString(), charfmt[2].Font.Result); Assert.AreEqual(georgia.ID.ToString(), charfmt[3].Font.Result); Assert.AreEqual(segoeui.ID.ToString(), charfmt[4].Font.Result); // check the styles Assert.AreEqual(((int)VA.Models.Text.CharStyle.None).ToString(), charfmt[0].Style.Result); Assert.AreEqual(((int)VA.Models.Text.CharStyle.Italic).ToString(), charfmt[1].Style.Result); Assert.AreEqual(((int)VA.Models.Text.CharStyle.Bold).ToString(), charfmt[2].Style.Result); Assert.AreEqual(((int)(VA.Models.Text.CharStyle.Italic | VA.Models.Text.CharStyle.Bold)).ToString(), charfmt[3].Style.Result); Assert.AreEqual(((int)(VA.Models.Text.CharStyle.None)).ToString(), charfmt[4].Style.Result); // check the text run content var charruns = textfmt.CharacterTextRuns; Assert.AreEqual(4, charruns.Count); Assert.AreEqual("{Normal}", charruns[0].Text); Assert.AreEqual("{Italic}", charruns[1].Text); Assert.AreEqual("{Bold}", charruns[2].Text); Assert.AreEqual("{Bold Italic}", charruns[3].Text); // cleanup page1.Delete(0); }
public IVisio.Document DrawNamespacesAndClasses(IList <Type> types_) { this._client.Application.AssertApplicationAvailable(); string segoeui_fontname = "Segoe UI"; string segoeuilight_fontname = "Segoe UI Light"; string def_linecolor = "rgb(180,180,180)"; string def_shape_fill = "rgb(245,245,245)"; string template = null; var page_size = new VisioAutomation.Drawing.Size(8.5, 11); var doc = this._client.Document.New(page_size, template); var fonts = doc.Fonts; var font_segoe = fonts[segoeui_fontname]; var font_segoelight = fonts[segoeuilight_fontname]; int fontid_segoe = font_segoe.ID16; int fontid_segoelight = font_segoelight.ID16; var types = types_.Select(t => new TypeInfo(t)); var pathbuilder = new PathTreeBuilder(); foreach (var type in types) { pathbuilder.Add(type.Type.Namespace); } var namespaces = pathbuilder.GetPaths(); var tree_layout = new VATREE.Drawing(); tree_layout.LayoutOptions.Direction = VATREE.LayoutDirection.Down; tree_layout.LayoutOptions.ConnectorType = VATREE.ConnectorType.PolyLine; var ns_node_map = new Dictionary <string, VATREE.Node>(namespaces.Count); var node_to_nslabel = new Dictionary <VATREE.Node, string>(namespaces.Count); // create nodes for every namespace foreach (string ns in namespaces) { string label = ns; int index_of_last_sep = ns.LastIndexOf(pathbuilder.Separator, StringComparison.Ordinal); if (index_of_last_sep > 0) { label = ns.Substring(index_of_last_sep + 1); } string ns1 = ns; var types_in_namespace = types.Where(t => t.Type.Namespace == ns1) .OrderBy(t => t.Type.Name) .Select(t => t.Label); var node = new VATREE.Node(ns); node.Size = new Drawing.Size(2.0, (0.15) * (1 + 2 + types_in_namespace.Count())); var markup = new VisioAutomation.Models.Text.TextElement(); var m1 = markup.AddElement(label + "\n"); m1.CharacterFormatting.Font = fontid_segoe; m1.CharacterFormatting.Size = "12.0pt"; m1.CharacterFormatting.Style = "1"; // Bold var m2 = markup.AddElement(); m2.CharacterFormatting.Font = fontid_segoe; m2.CharacterFormatting.Size = "8.0pt"; m2.AddText(string.Join("\n", types_in_namespace)); node.Text = markup; ns_node_map[ns] = node; node_to_nslabel[node] = label; } // add children to nodes foreach (string ns in namespaces) { var parent_ns = pathbuilder.PathToParentPath[ns]; if (parent_ns != null) { // the current namespace has a parent var parent_node = ns_node_map[parent_ns]; var child_node = ns_node_map[ns]; parent_node.Children.Add(child_node); } else { // that means this namespace is a root, forget about it } } if (pathbuilder.Roots.Count == 0) { } else if (pathbuilder.Roots.Count == 1) { // when there is exactly one root namespace, then that node will be the tree's root node var first_root = pathbuilder.Roots[0]; var root_n = ns_node_map[first_root]; tree_layout.Root = root_n; } else { // if there are multiple root namespaces, inject an empty placeholder root var root_n = new VATREE.Node(); tree_layout.Root = root_n; foreach (var root_ns in pathbuilder.Roots) { var node = ns_node_map[root_ns]; tree_layout.Root.Children.Add(node); } } // format the shapes foreach (var node in tree_layout.Nodes) { if (node.Cells == null) { node.Cells = new ShapeCells(); } node.Cells.FillForegnd = def_shape_fill; //node.ShapeCells.LineWeight = "0"; //node.ShapeCells.LinePattern = "0"; node.Cells.LineColor = def_linecolor; node.Cells.ParaHorizontalAlign = "0"; node.Cells.VerticalAlign = "0"; } var cxn_cells = new ShapeCells(); cxn_cells.LineColor = def_linecolor; tree_layout.LayoutOptions.ConnectorCells = cxn_cells; tree_layout.Render(doc.Application.ActivePage); DeveloperCommands.hide_ui_stuff(doc); return(doc); }