Ejemplo n.º 1
0
        public static VAM.Text.Element AddElementEx(
            this VAM.Text.Element p,
            string text,
            TextFmt textfmt)
        {
            var el = p.AddElement(text);

            if (textfmt != null && textfmt.FontID != null)
            {
                el.CharacterFormatting.Font = textfmt.FontID.Value;
            }

            if (textfmt != null && textfmt.FontSize.HasValue)
            {
                el.CharacterFormatting.Size = string.Format("{0}pt", textfmt.FontSize.Value);
            }

            if (textfmt != null && textfmt.Color.HasValue)
            {
                var c = new VAM.Color.ColorRgb(textfmt.Color.Value);
                el.CharacterFormatting.Color = c.ToFormula();
            }

            if (textfmt != null && textfmt.HAlign.HasValue)
            {
                el.ParagraphFormatting.HorizontalAlign = (int)textfmt.HAlign.Value;
            }

            if (textfmt != null && textfmt.CharStyle.HasValue)
            {
                el.CharacterFormatting.Style = (int)textfmt.CharStyle;
            }

            return(el);
        }
Ejemplo n.º 2
0
        public static void GradientTransparencies()
        {
            int num_cols = 1;
            int num_rows = 10;
            var color1   = new VAM.Color.ColorRgb(0xff000);
            var color2   = new VAM.Color.ColorRgb(0x000ff);

            var page_size = new VA.Geometry.Size(num_rows / 2.0, num_rows);
            var upperleft = new VA.Geometry.Point(0, page_size.Height);

            var page    = SampleEnvironment.Application.ActiveDocument.Pages.Add();
            var app     = page.Application;
            var docs    = app.Documents;
            var stencil = docs.OpenStencil("basic_U.vss");
            var master  = stencil.Masters["Rectangle"];

            SampleEnvironment.SetPageSize(page, page_size);

            var layout = new VAM.Layouts.Grid.GridLayout(num_cols, num_rows, new VA.Geometry.Size(6.0, 1.0), master);

            layout.RowDirection = VAM.Layouts.Grid.RowDirection.TopToBottom;
            layout.Origin       = upperleft;
            layout.CellSpacing  = new VA.Geometry.Size(0.1, 0.1);
            layout.PerformLayout();

            double[] trans = EffectsSamples.RangeSteps(0.0, 1.0, num_rows).ToArray();

            int i = 0;

            foreach (var node in layout.Nodes)
            {
                double transparency = trans[i];

                var fmt = new VAM.Dom.ShapeCells();
                node.Cells = fmt;

                fmt.FillPattern                = 25; // Linear pattern left to right
                fmt.FillForeground             = color1.ToFormula();
                fmt.FillBackground             = color2.ToFormula();
                fmt.FillForegroundTransparency = 0;
                fmt.FillBackgroundTransparency = transparency;
                fmt.LinePattern                = 0;

                node.Text = string.Format("bg trans = {0}%", transparency);
                i++;
            }

            layout.Render(page);

            page.ResizeToFitContents();
        }
        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 VAM.Text.Element();
            var color_red = new VAM.Color.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 static DirectedGraphDocument LoadFromXml(Client client, SXL.XDocument xmldoc)
        {
            var dgdoc     = new DirectedGraphDocument();
            var pagedatas = DirectedGraphDocumentLoader._load_page_data_from_xml(client, xmldoc);

            // STOP IF ANY ERRORS
            int num_errors = pagedatas.Select(pagedata => pagedata.Errors.Count).Sum();

            if (num_errors > 1)
            {
                foreach (var pagedata in pagedatas)
                {
                    foreach (var error in pagedata.Errors)
                    {
                        client.Output.WriteVerbose(error.Text);
                    }
                    client.Output.WriteVerbose("Errors encountered in shape data. Stopping.");
                }
            }

            // DRAW EACH PAGE
            foreach (var pagedata in pagedatas)
            {
                client.Output.WriteVerbose("Creating shape AutoLayout nodes");
                foreach (var shape_info in pagedata.ShapeInfos)
                {
                    var dg_shape = pagedata.DirectedGraph.AddNode(shape_info.ID, shape_info.Label, shape_info.Stencil, shape_info.Master);
                    dg_shape.Url = shape_info.Url;
                    dg_shape.CustomProperties = new CustomPropertyDictionary();
                    foreach (var kv in shape_info.CustProps)
                    {
                        var cp_cells = kv.Value;
                        cp_cells.EncodeValues();
                        dg_shape.CustomProperties[kv.Key] = kv.Value;
                    }
                }

                client.Output.WriteVerbose("Creating connector AutoLayout nodes");
                foreach (var con_info in pagedata.ConnectorInfos)
                {
                    var def_connector_type = VisioAutomation.Models.ConnectorType.Curved;
                    var connectory_type    = def_connector_type;

                    var from_shape = pagedata.DirectedGraph.Nodes.Find(con_info.From);
                    var to_shape   = pagedata.DirectedGraph.Nodes.Find(con_info.To);

                    var def_con_color  = new VisioAutomation.Models.Color.ColorRgb(0x000000);
                    var def_con_weight = 1.0 / 72.0;
                    var def_end_arrow  = 2;
                    var dg_connector   = pagedata.DirectedGraph.AddEdge(con_info.ID, from_shape, to_shape, con_info.Label, connectory_type);

                    dg_connector.Cells              = new ShapeCells();
                    dg_connector.Cells.LineColor    = con_info.Element.AttributeAsColor("color", def_con_color).ToFormula();
                    dg_connector.Cells.LineWeight   = con_info.Element.AttributeAsInches("weight", def_con_weight);
                    dg_connector.Cells.LineEndArrow = def_end_arrow;
                }
                client.Output.WriteVerbose("Rendering AutoLayout...");
            }
            client.Output.WriteVerbose("Finished rendering AutoLayout");

            var layouts = pagedatas.Select(pagedata => pagedata.DirectedGraph);

            dgdoc.Layouts.AddRange(layouts);

            return(dgdoc);
        }
Ejemplo n.º 5
0
        public static void DrawAllGradients()
        {
            var app     = SampleEnvironment.Application;
            var docs    = app.Documents;
            var stencil = docs.OpenStencil("basic_u.vss");
            var master  = stencil.Masters["Rectangle"];
            var page    = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            int num_cols = 7;
            int num_rows = 7;

            var page_size = new VA.Geometry.Size(5, 5);

            SampleEnvironment.SetPageSize(page, page_size);

            var lowerleft        = new VA.Geometry.Point(0, 0);
            var actual_page_size = SampleEnvironment.GetPageSize(page);
            var page_rect        = new VA.Geometry.Rectangle(lowerleft, actual_page_size);

            var layout = new GridLayout(num_cols, num_rows, new VA.Geometry.Size(1, 1), master);

            layout.RowDirection = RowDirection.TopToBottom;
            layout.Origin       = page_rect.UpperLeft;
            layout.CellSpacing  = new VA.Geometry.Size(0, 0);
            layout.PerformLayout();

            int max_grad_id = 40;
            int n           = 0;

            foreach (var node in layout.Nodes)
            {
                int grad_id = n % max_grad_id;
                node.Text = grad_id.ToString();
                n++;
            }

            layout.Render(page);

            var color1 = new VA.Models.Color.ColorRgb(0xffdddd);
            var color2 = new VA.Models.Color.ColorRgb(0x00ffff);

            var format = new VA.Shapes.ShapeFormatCells();

            var writer = new SidSrcWriter();

            string color1_formula = color1.ToFormula();
            string color2_formula = color2.ToFormula();

            n = 0;

            foreach (var node in layout.Nodes)
            {
                short shapeid = node.ShapeID;
                int   grad_id = n % max_grad_id;

                format.FillPattern    = grad_id;
                format.FillForeground = color1_formula;
                format.FillBackground = color2_formula;
                format.LinePattern    = 0;
                format.LineWeight     = 0;

                writer.SetValues(shapeid, format);

                n++;
            }

            writer.Commit(page, VA.ShapeSheet.CellValueType.Formula);

            var bordersize = new VA.Geometry.Size(1, 1);

            page.ResizeToFitContents(bordersize);
        }
Ejemplo n.º 6
0
 public static VisioAutomation.Models.Color.ColorRgb AttributeAsColor(this SXL.XElement el, string name,
                                                                      VisioAutomation.Models.Color.ColorRgb def)
 {
     return(el.GetAttributeValue(name, def, VisioAutomation.Models.Color.ColorRgb.ParseWebColor));
 }