Esempio n. 1
0
        public static Page GetPage01_Simple_Fill_Format(Drawing doc)
        {
            var page = new Page(8, 4);
            doc.Pages.Add(page);
           
            // find the id of the master for rounded rectangles
            int rounded_rect_id = doc.GetMasterMetaData("Rounded REctAngle").ID;

            // using that ID draw a rounded rectangle at pinpos(4,3)
            var shape1 = new Shape(rounded_rect_id, 4, 3);
            page.Shapes.Add(shape1);

            // using that ID draw a rounded rectangle at pinpos(2,2) with size (2.5,2)
            var shape2 = new Shape(rounded_rect_id, 2, 2, 2.5, 2);
            page.Shapes.Add(shape2);

            // set the fill properties of the second shape
            shape2.Fill = new Fill();
            shape2.Fill.ForegroundColor.Result = 0xff0000;
            shape2.Fill.BackgroundColor.Result = 0x55ff00;
            shape2.Fill.ForegroundTransparency.Result = 0.1;
            shape2.Fill.BackgroundTransparency.Result = 0.9;
            shape2.Fill.Pattern.Result = 40;

            shape1.Line = new Line();
            shape1.Line.Weight.Result = 1.0;

            shape1.XForm.Angle.Result = Math.PI/4;

            return page;
        }
        /// <inheritdoc/>
        void IProjectExporter.Save(string path, XContainer container)
        {
            var template = new Template();
            var drawing = new Drawing(template);

            Add(drawing, container);

            drawing.Save(path);
        }
        /// <inheritdoc/>
        void IProjectExporter.Save(string path, XDocument document)
        {
            var template = new Template();
            var drawing = new Drawing(template);

            foreach (var container in document.Pages)
            {
                Add(drawing, container);
            }

            drawing.Save(path);
            ClearCache(isZooming: false);
        }
Esempio n. 4
0
        public void CreateVDX(Elements.Drawing vdoc, SXL.XDocument dom)
        {
            if (vdoc == null)
            {
                throw new System.ArgumentNullException(nameof(vdoc));
            }

            if (dom == null)
            {
                throw new System.ArgumentNullException(nameof(dom));
            }

            this._ModifyTemplate(dom, vdoc);
        }
Esempio n. 5
0
        private void _ModifyTemplate(SXL.XDocument dom, Elements.Drawing doc_node)
        {
            if (dom.Root == null)
            {
                throw new System.ArgumentException("DOM must have a root node");
            }

            var root = dom.Root;

            root.AddFirst(doc_node.DocumentProperties.ToXml());

            var xfacenames = root.ElementVisioSchema2003("FaceNames");

            xfacenames.RemoveAll();

            foreach (var vface in doc_node.Faces.Items)
            {
                vface.ToXml(xfacenames);
            }

            var xcolors = root.ElementVisioSchema2003("Colors");

            xcolors.RemoveAll();

            int ix = 0;

            foreach (var color in doc_node.Colors)
            {
                color.AddToElement(xcolors, ix++);
            }

            var xpages = root.ElementVisioSchema2003("Pages");

            foreach (var page_node in doc_node.Pages.Items)
            {
                page_node.AddToElement(xpages);
            }

            if (doc_node.Windows != null && doc_node.Windows.Count > 0)
            {
                var xwindows = Internal.XMLUtil.CreateVisioSchema2003Element("Windows");
                root.Add(xwindows);

                foreach (var window in doc_node.Windows)
                {
                    window.AddToElement(xwindows);
                }
            }
        }
        private void Add(Drawing drawing, XContainer container)
        {
            var width = container.Template.Width;
            var height = container.Template.Height;

            var page = new Page(width, height);
            drawing.Pages.Add(page);

            if (container.Template.Background.A > 0)
            {
                Fill(page, 0, 0, width, height, container.Template.Background);
            }

            Draw(page, container.Template, 0.0, 0.0, container.Data.Properties, container.Data.Record);
            Draw(page, container, 0.0, 0.0, container.Data.Properties, container.Data.Record);
        }
        internal void ValidatePage( Drawing drawing )
        {
            if (drawing==null)
            {
                throw new System.ArgumentNullException("drawing");
            }

            if (this.Page < 0)
            {
                throw new System.ArgumentException("Negative page not allowed in document window");
            }

            bool found = drawing.Pages.Items.Any(p => this.Page == p.ID);

            if (!found)
            {
                string msg = "Document window pointing to page that does not exist";
                throw new System.ArgumentException(msg);
            }
        }
Esempio n. 8
0
        public static Page GetPage02_Locking(Drawing doc)
        {
            var page = new Page(8, 4);
            doc.Pages.Add(page);
            // find the id of the master for rounded rectangles
            int rounded_rect_id = doc.GetMasterMetaData("Rounded REctAngle").ID;

            // find the id of the master for dynamic connector
            int dynamic_connector_id = doc.GetMasterMetaData("Dynamic Connector").ID;

            // using that ID draw a rounded rectangle at pinpos(4,3)
            var shape1 = new Shape(rounded_rect_id, 4, 3);
            page.Shapes.Add(shape1);

            shape1.Text.Add("This shape is completely locked");

            shape1.Protection = new Protection();
            shape1.Protection.SetAll(true);
            return page;
        }
Esempio n. 9
0
        public void CreateVDX(Elements.Drawing vdoc, SXL.XDocument dom, string output_filename)
        {
            if (output_filename == null)
            {
                throw new System.ArgumentNullException(nameof(output_filename));
            }

            // Validate that all Document windows refer to an existing page
            foreach (var window in vdoc.Windows)
            {
                if (window is Elements.DocumentWindow)
                {
                    var docwind = (Elements.DocumentWindow)window;
                    docwind.ValidatePage(vdoc);
                }
            }
            this.CreateVDX(vdoc, dom);

            // important to use DisableFormatting - Visio is very sensitive to whitespace in the <Text> element when there is complex formatting
            var saveoptions = SXL.SaveOptions.DisableFormatting;

            dom.Save(output_filename, saveoptions);
        }
Esempio n. 10
0
        public static Page GetPage03_Text_Block(Drawing doc)
        {
            var page = new Page(8, 4);
            doc.Pages.Add(page);

            // find the id of the masters
            int rounded_rect_id = doc.GetMasterMetaData("Rounded REctAngle").ID;

            // using that ID draw a rounded rectangle at pinpos(4,3)
            var shape1 = new Shape(rounded_rect_id, 4, 3);
            page.Shapes.Add(shape1);

            shape1.Text.Add("This shape has its text block set");

            shape1.TextBlock = new TextBlock();
            shape1.TextBlock.LeftMargin.Result = 0.25;
            shape1.TextBlock.RightMargin.Result = 0.20;
            shape1.TextBlock.TopMargin.Result = 0.1;
            shape1.TextBlock.BottomMargin.Result = 0.15;

            shape1.TextBlock.TextBkgnd.Result = 0xff8800;
            shape1.TextBlock.TextBkgndTrans.Result = 0.5;
            return page;
        }
Esempio n. 11
0
        public static Page GetPage06_All_FillPatterns(Drawing doc)
        {
            var page = new Page(8, 5);
            doc.Pages.Add(page);

            int rect_id = doc.GetMasterMetaData("REctAngle").ID;

            double width = 1.0;
            double height = 1.0;
            int pattern = 0;
            foreach (int row in Enumerable.Range(0, 5))
            {
                foreach (int col in Enumerable.Range(0, 8))
                {
                    double x0 = col*width;
                    double y0 = row*height;

                    double pinx = x0 + width/2.0;
                    double piny = y0 + height/2.0;

                    var shape = new Shape(rect_id, pinx, piny, width, height);
                    page.Shapes.Add(shape);
                    shape.Fill = new Fill();
                    shape.Fill.ForegroundColor.Result = 0xff0000;
                    shape.Fill.BackgroundColor.Result = 0x55ff00;
                    shape.Fill.Pattern.Result = pattern++;
                    shape.Text.Add(pattern.ToString());
                }
            }

            return page;
        }
Esempio n. 12
0
        public static Page GetPage04_Simple_Text(Drawing doc)
        {
            var page = new Page(8, 4);
            doc.Pages.Add(page);

            // find the id of the master for rounded rectangles
            int rounded_rect_id = doc.GetMasterMetaData("Rounded REctAngle").ID;

            var shape1 = new Shape(rounded_rect_id, 1, 3);
            page.Shapes.Add(shape1);
            shape1.Text.Add("Page4Shape1");

            var shape2 = new Shape(rounded_rect_id, 5, 3);
            page.Shapes.Add(shape2);
            shape2.Text.Add("Page4Shape2");

            var shape3 = Shape.CreateDynamicConnector(doc);
            shape3.XForm1D.EndY.Result = 0;

            shape3.Line = new Line();
            shape3.Line.EndArrow.Result = 3;

            page.Shapes.Add(shape3);

            page.ConnectShapesViaConnector(shape3, shape1, shape2);
            return page;
        }
Esempio n. 13
0
        public static Page GetPage14_Hyperlinks(Drawing doc)
        {
            var page = new Page(8, 4);
            doc.Pages.Add(page);

            // find the id of the master for rounded rectangles
            int rounded_rect_id = doc.GetMasterMetaData("Rounded REctAngle").ID;

            var shape1 = new Shape(rounded_rect_id, 1, 3);
            shape1.Text.Add("No Hyperlinks");

            var shape2 = new Shape(rounded_rect_id, 5, 3);
            shape2.Text.Add("1 Hyperlink");
            shape2.Hyperlinks = new List<Hyperlink>();
            shape2.Hyperlinks.Add(new Hyperlink("Google", "http://google.com"));

            var shape3 = new Shape(rounded_rect_id, 5, 3);
            shape3.Text.Add("2 Hyperlinks");
            shape3.Hyperlinks = new List<Hyperlink>();
            shape3.Hyperlinks.Add(new Hyperlink("Google", "http://google.com"));
            shape3.Hyperlinks.Add(new Hyperlink("Microsoft", "http://microsoft.com"));

            page.Shapes.Add(shape1);
            page.Shapes.Add(shape2);
            page.Shapes.Add(shape3);

            page.ConnectShapesViaConnector(shape3, shape1, shape2);
            return page;
        }
Esempio n. 14
0
        public static Page GetPage12_AdjustToTextSize(Drawing doc)
        {
            var page = new Page(8, 4);
            doc.Pages.Add(page);

            int rounded_rect_id = doc.GetMasterMetaData("Rounded REctAngle").ID;

            var shape1 = new Shape(rounded_rect_id, 1, 3);
            page.Shapes.Add(shape1);
            shape1.Text.Add("Page12Shape1");

            shape1.XForm.Width.Formula = "GUARD(TEXTWIDTH(TheText))";
            shape1.XForm.Height.Formula = "GUARD(TEXTHEIGHT(TheText,Width))";

            return page;
        }
Esempio n. 15
0
        public static Page GetPage11_Add_color(Drawing doc)
        {
            var page = new Page(8, 4);
            doc.Pages.Add(page);

            var layer0 = page.AddLayer("Foo", 0);
            var layer1 = page.AddLayer("BAR", 1);

            int rounded_rect_id = doc.GetMasterMetaData("Rounded REctAngle").ID;

            var layout = new Layout();
            layout.ShapeRouteStyle.Result = RouteStyle.TreeEW;

            var shape1 = new Shape(rounded_rect_id, 1, 3);
            page.Shapes.Add(shape1);

            doc.Colors.Add(new ColorEntry {RGB = 0x123456});
            return page;
        }
Esempio n. 16
0
        public static Page GetPage10_layers(Drawing doc)
        {
            var page = new Page(8, 4);
            doc.Pages.Add(page);

            var layer0 = page.AddLayer("Layer0", 0);
            var layer1 = page.AddLayer("Layer1", 1);
            var layer2 = page.AddLayer("Layer2", 2);

            // find the id of the master for rounded rectangles
            int rounded_rect_id = doc.GetMasterMetaData("Rounded REctAngle").ID;

            var layout = new Layout();
            layout.ShapeRouteStyle.Result = RouteStyle.TreeEW;

            var shape1 = new Shape(rounded_rect_id, 1, 3);
            page.Shapes.Add(shape1);
            shape1.Text.Add("Shape1");

            shape1.Layout = layout;

            var shape2 = new Shape(rounded_rect_id, 5, 3);
            page.Shapes.Add(shape2);
            shape2.Text.Add("Shape2");

            shape2.Layout = shape1.Layout;

            var shape3 = Shape.CreateDynamicConnector(doc);
            shape3.XForm1D.EndY.Result = 0;
            page.Shapes.Add(shape3);
            shape3.Geom = new Geom();
            shape3.Geom.Rows.Add(new MoveTo(1, 3));
            shape3.Geom.Rows.Add(new LineTo(5, 3));

            shape3.Layout = shape1.Layout;
            page.ConnectShapesViaConnector(shape3, shape1, shape2);

            shape3.LayerMembership = new List<int> {layer0.Index, layer2.Index};
            shape1.LayerMembership = new List<int> {layer1.Index};
            shape2.LayerMembership = new List<int> {layer2.Index};

            return page;
        }
Esempio n. 17
0
        public static Page GetPage09_Layout(Drawing doc)
        {
            var page = new Page(8, 4);
            doc.Pages.Add(page);

            // find the id of the master for rounded rectangles
            int rounded_rect_id = doc.GetMasterMetaData("Rounded REctAngle").ID;

            var layout = new Layout();
            layout.ShapeRouteStyle.Result = RouteStyle.TreeEW;

            var shape1 = new Shape(rounded_rect_id, 1, 3);
            page.Shapes.Add(shape1);
            shape1.Text.Add("XXX1");

            shape1.Layout = layout;

            var shape2 = new Shape(rounded_rect_id, 5, 3);
            page.Shapes.Add(shape2);
            shape2.Text.Add("XXX2");

            shape2.Layout = shape1.Layout;

            var shape3 = Shape.CreateDynamicConnector(doc);
            shape3.XForm1D.EndY.Result = 0;
            page.Shapes.Add(shape3);
            shape3.Geom = new Geom();
            shape3.Geom.Rows.Add(new MoveTo(1, 3));
            shape3.Geom.Rows.Add(new LineTo(5, 3));

            shape3.Layout = shape1.Layout;
            page.ConnectShapesViaConnector(shape3, shape1, shape2);
            return page;
        }
        public static Shape CreateDynamicConnector(Drawing doc)
        {
            int dynamic_connector_id = doc.GetMasterMetaData("Dynamic Connector").ID;
            var shape_el = new Shape(dynamic_connector_id , false, 0, 0);
            shape_el.XForm1D = new Sections.XForm1D();
            shape_el.XForm1D.BeginX.Formula = "_WALKGLUE(BegTrigger,EndTrigger,WalkPreference)";
            shape_el.XForm1D.BeginX.Result = 0;
            shape_el.XForm1D.BeginY.Formula = "_WALKGLUE(BegTrigger,EndTrigger,WalkPreference)";
            shape_el.XForm1D.BeginY.Result = 0;

            shape_el.XForm1D.EndX.Formula = "_WALKGLUE(BegTrigger,EndTrigger,WalkPreference)";
            shape_el.XForm1D.EndX.Result = 0;
            shape_el.XForm1D.EndY.Formula = "_WALKGLUE(BegTrigger,EndTrigger,WalkPreference)";
            return shape_el;
        }
Esempio n. 19
0
        public static Page GetPage05_Formatted_Text(Drawing doc)
        {
            var page = new Page(8, 4);
            doc.Pages.Add(page);

            // find the id of the master for rounded rectangles
            int rounded_rect_id = doc.GetMasterMetaData("Rounded REctAngle").ID;

            // using that ID draw a rounded rectangle at pinpos(4,3)
            var shape1 = new Shape(rounded_rect_id, 4, 3);
            page.Shapes.Add(shape1);

            // using that ID draw a rounded rectangle at pinpos(2,2) with size (2.5,2)
            var shape2 = new Shape(rounded_rect_id, 2, 2, 2.5, 2);
            page.Shapes.Add(shape2);

            shape1.XForm.Angle.Result = Math.PI/4;

            shape1.Text.Add("HELLO");
            shape2.TextXForm = new TextXForm();
            shape2.TextXForm.PinY.Formula = "-TxtHeight*0.5";

            var font_segoeui = doc.AddFace("Segoe UI");
            var font_gillsans = doc.AddFace("Gill Sans MT");
            var font_trebuchet = doc.AddFace("Trebuchet MS");

            var charfmt1 = new VisioAutomation.VDX.Sections.Char();
            charfmt1.Font.Result = font_gillsans.ID;
            charfmt1.DoubleUnderline.Result = true;
            charfmt1.Size.Result = 18.0;
            charfmt1.Transparency.Result = 0.5;
            charfmt1.Style.Result = CharStyle.Italic | CharStyle.Bold |
                                    CharStyle.Underline;

            var charfmt2 = new VisioAutomation.VDX.Sections.Char();
            charfmt2.Font.Result = font_trebuchet.ID;
            charfmt2.Strikethru.Result = true;
            charfmt2.Size.Result = 26;

            var charfmt3 = new VisioAutomation.VDX.Sections.Char();
            charfmt3.Font.Result = font_segoeui.ID;
            charfmt3.Strikethru.Result = true;
            charfmt3.RTLText.Result = true;

            var parafmt1 = new ParagraphFormat();
            parafmt1.HorzAlign.Result = ParaHorizontalAlignment.Center;

            var parafmt2 = new ParagraphFormat();
            parafmt2.HorzAlign.Result = ParaHorizontalAlignment.Right;

            var parafmt3 = new ParagraphFormat();
            parafmt3.HorzAlign.Result = ParaHorizontalAlignment.Left;

            shape2.CharFormats = new List<VisioAutomation.VDX.Sections.Char>();
            shape2.ParaFormats = new List<ParagraphFormat>();

            shape2.CharFormats.Add(charfmt1);
            shape2.CharFormats.Add(charfmt2);
            shape2.CharFormats.Add(charfmt3);

            shape2.ParaFormats.Add(parafmt1);
            shape2.ParaFormats.Add(parafmt2);
            shape2.ParaFormats.Add(parafmt3);

            shape2.Text.Add("world1\n", 0, 0, null);
            shape2.Text.Add("world2\n", 1, 1, null);
            shape2.Text.Add("world3", 2, 2, null);
            return page;
        }