示例#1
0
 public void Apply(SidSrcWriter writer, short shapeid_label, short shapeid_box)
 {
     writer.SetValues(shapeid_label, this.ParagraphFormatCells, 0);
     writer.SetValues(shapeid_label, this.CharacterFormatCells, 0);
     writer.SetValues(shapeid_box, this.ShapeFormatCells);
     writer.SetValues(shapeid_box, this.TextBlockCells);
 }
示例#2
0
        public void ApplyFormus(SidSrcWriter writer)
        {
            short title_shapeid = this.VisioShape.ID16;

            writer.SetValues(title_shapeid, this.TextBlockCells);
            writer.SetValues(title_shapeid, this.ParagraphFormatCells, 0);
            writer.SetValues(title_shapeid, this.CharacterFormatCells, 0);
            writer.SetValues(title_shapeid, this.FormatCells);
        }
示例#3
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }

            // First handle any page properties
            if (this.Name != null)
            {
                page.NameU = this.Name;
            }

            this.VisioPage = page;
            var page_sheet = page.PageSheet;
            var app        = page.Application;

            using (var perfscope = new RenderPerformanceScope(app, this.RenderPerforfmanceSettings))
            {
                if (this.Size.HasValue)
                {
                    this.PageFormatCells.Height = this.Size.Value.Height;
                    this.PageFormatCells.Width  = this.Size.Value.Width;
                }

                var writer = new SidSrcWriter();
                writer.SetValues((short)page_sheet.ID, this.PageFormatCells);
                writer.SetValues((short)page_sheet.ID, this.PageLayoutCells);
                writer.Commit(page, ShapeSheet.CellValueType.Formula);

                // Then render the shapes
                this.Shapes.Render(page);

                // Perform any additional layout
                if (this.Layout != null)
                {
                    this.Layout.Apply(page);
                }

                // Optionally, perform page resizing to fit contents
                if (this.ResizeToFit)
                {
                    if (this.ResizeToFitMargin.HasValue)
                    {
                        page.ResizeToFitContents(this.ResizeToFitMargin.Value);
                    }
                    else
                    {
                        page.ResizeToFitContents();
                    }
                }
            }
        }
示例#4
0
        public static void Spirograph()
        {
            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            page.Name = "Spirograph";

            var colors = new[]
            {
                0xf26420, 0xf7931c, 0xfec20d, 0xfff200,
                0xcada28, 0x8cc63e, 0x6c9d30, 0x288f39,
                0x006f3a, 0x006f71, 0x008eb0, 0x00adee,
                0x008ed3, 0x0071bb, 0x0053a6, 0x2e3091,
                0x5b57a6, 0x652d91, 0x92278e, 0xbd198c,
                0xec008b, 0xec1c23, 0xc1272c, 0x981a1e
            };

            var    origin             = new VA.Geometry.Point(4, 4);
            double radius             = 3.0;
            int    numpoints          = colors.Length;
            double angle_step         = (System.Math.PI * 2 / numpoints);
            var    angles             = Enumerable.Range(0, numpoints).Select(i => i * angle_step).ToList();
            var    centers            = angles.Select(a => PlaygroundSamples.GetPointAtRadius(origin, a, radius)).ToList();
            var    shapes             = centers.Select(p => PlaygroundSamples.draw_leaf(page, p)).ToList();
            var    culture            = CultureInfo.InvariantCulture;
            var    angles_as_formulas = angles.Select(a => a.ToString(culture)).ToList();

            var color_formulas = colors.Select(x => new VA.Models.Color.ColorRgb(x).ToFormula()).ToList();

            var shapeids = shapes.Select(s => s.ID16).ToList();

            var writer = new SidSrcWriter();
            var format = new VA.Shapes.ShapeFormatCells();
            var xfrm   = new VA.Shapes.ShapeXFormCells();

            foreach (int i in Enumerable.Range(0, shapeids.Count))
            {
                short shapeid = shapeids[i];

                xfrm.Angle                        = angles_as_formulas[i];
                format.FillForeground             = color_formulas[i];
                format.LineWeight                 = 0;
                format.LinePattern                = 0;
                format.FillForegroundTransparency = 0.5;

                writer.SetValues(shapeid, xfrm);
                writer.SetValues(shapeid, format);
            }

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

            page.ResizeToFitContents(new VA.Geometry.Size(1.0, 1.0));
        }
示例#5
0
        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    xfrm   = new VA.Shapes.ShapeXFormCells();

            xfrm.PinX   = string.Format("GUARD({0}!PinX-{0}!LocPinX+LocPinX)", bkname);
            xfrm.PinY   = string.Format("GUARD({0}!PinY)", bkname);
            xfrm.Width  = string.Format("GUARD({0}!Width*(PAGENUMBER()/PAGECOUNT()))", bkname);
            xfrm.Height = string.Format("GUARD({0}!Height)", bkname);

            var writer = new SidSrcWriter();

            writer.SetValues(progress.ID16, xfrm);
            writer.SetValues(progress.ID16, background_fmt);
            writer.SetValues(progress.ID16, progress_fmt);

            writer.CommitFormulas(page_a);

            var markup1 = new VisioAutomation.Models.Text.Element();

            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 Finish()
        {
            var writer = new SidSrcWriter();

            foreach (var block in this.Blocks)
            {
                writer.SetValues((short)block.VisioShapeID, block.FormatCells);
                writer.SetValues((short)block.VisioShapeID, block.TextBlockCells);

                writer.SetValues((short)block.VisioShapeID, block.ParagraphFormatCells, 0);
                writer.SetValues((short)block.VisioShapeID, block.CharacterFormatCells, 0);
            }

            writer.CommitFormulas(this._page);
        }
示例#7
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);
        }
        public static void ColorGrid()
        {
            // Draws a grid rectangles and then formats the shapes
            // with different colors

            // Demonstrates:
            // How use the GridLayout object to quickly drop a grid
            // How to use ShapeFormatCells to apply formatting to shapes
            // How UpdateBase can be used to modfiy multiple shapes at once

            int[] colors =
            {
                0x0A3B76, 0x4395D1, 0x99D9EA, 0x0D686B, 0x00A99D, 0x7ACCC8, 0x82CA9C,
                0x74A402,
                0xC4DF9B, 0xD9D56F, 0xFFF468, 0xFFF799, 0xFFC20E, 0xEB6119, 0xFBAF5D,
                0xE57300, 0xC14000, 0xB82832, 0xD85171, 0xFEDFEC, 0x563F7F, 0xA186BE,
                0xD9CFE5
            };

            const int num_cols = 5;
            const int num_rows = 5;

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

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

            SampleEnvironment.SetPageSize(page, page_size);

            var stencil = SampleEnvironment.Application.Documents.OpenStencil("basic_u.vss");
            var master  = stencil.Masters["Rectangle"];

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

            layout.Origin       = new VA.Geometry.Point(0, 0);
            layout.CellSpacing  = new VA.Geometry.Size(0, 0);
            layout.RowDirection = RowDirection.BottomToTop;

            layout.PerformLayout();
            layout.Render(page);

            var fmtcells = new VA.Shapes.ShapeFormatCells();
            int i        = 0;
            var writer   = new SidSrcWriter();

            foreach (var node in layout.Nodes)
            {
                var shapeid     = node.ShapeID;
                int color_index = i % colors.Length;
                var color       = colors[color_index];
                fmtcells.FillForeground = new VisioAutomation.Models.Color.ColorRgb(color).ToFormula();
                fmtcells.LinePattern    = 0;
                fmtcells.LineWeight     = 0;

                writer.SetValues(shapeid, fmtcells);
                i++;
            }

            writer.CommitFormulas(page);

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

            page.ResizeToFitContents(bordersize);
        }