Example #1
0
        private void method_9(IActiveView pView, IPoint point, double num, bool flag, IRgbColor color)
        {
            this.method_8(point, num, flag);
            ISegmentCollection segmentCollection = new Polygon() as ISegmentCollection;
            ICircularArc       circularArc       = this.method_8(point, num, flag);
            object             missing           = Type.Missing;

            segmentCollection.AddSegment(circularArc as ISegment, ref missing, ref missing);
            ICircleElement circleElement = new CircleElement() as ICircleElement;
            IElement       element       = (IElement)circleElement;

            element.Geometry = (segmentCollection as IGeometry);
            IFillShapeElement fillShapeElement = (IFillShapeElement)circleElement;
            ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol();
            ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol();

            simpleLineSymbol.Color   = (color);
            simpleLineSymbol.Width   = (2.0);
            simpleLineSymbol.Style   = (0);
            simpleFillSymbol.Color   = (color);
            simpleFillSymbol.Style   = (esriSimpleFillStyle)(1);
            simpleFillSymbol.Outline = (simpleLineSymbol);
            fillShapeElement.Symbol  = (simpleFillSymbol);
            IGraphicsContainer graphicsContainer = (IGraphicsContainer)pView;

            graphicsContainer.AddElement((IElement)circleElement, 0);
        }
Example #2
0
            public void SetColors(IEnumerable <Color> colors)
            {
                Children.Clear();
                foreach (var color in colors)
                {
                    var e = new CircleElement();
                    e.Style.BackColor = color;

                    Children.Add(e);
                }
            }
Example #3
0
        static ElementFactory()
        {
            _boxPrototype = new BoxElement();
            _boxPrototype.Title = "New box element.";

            _circleProrotype = new CircleElement();
            _circleProrotype.Title = "New circle element";

            _connectorPrototype = new ConnectorElement();
            _connectorPrototype.Title = "New connector element";

        }
Example #4
0
        public static void Implement()
        {
            BoxElement boxPrototype = new BoxElement();
            DynamiFabric.AddPrototype(boxPrototype);

            CircleElement circlePrototype = new CircleElement();
            DynamiFabric.AddPrototype(circlePrototype);

            ConnectorElement connectorPrototype = new ConnectorElement();
            DynamiFabric.AddPrototype(connectorPrototype);

            BoxElement newBox = (BoxElement)DynamiFabric.CreateObject((typeof(BoxElement)));
        }
        /// <summary>
        /// 块
        /// </summary>
        /// <param name="block"></param>
        /// <returns></returns>
        //private Canvas LoadBlock(RTSafe.DxfCore.Blocks.Block block)
        //{
        //    Canvas c = new Canvas();
        //    foreach (var item in block.Entities)
        //    {
        //        switch (item.Type)
        //        {
        //            case RTSafe.DxfCore.Entities.EntityType.Text: c.Children.Add(LoadText(item as RTSafe.DxfCore.Entities.Text)); break;
        //            case RTSafe.DxfCore.Entities.EntityType.Line: this._container.Children.Add(LoadLine(item as RTSafe.DxfCore.Entities.Line)); break;
        //            case RTSafe.DxfCore.Entities.EntityType.LightWeightPolyline: c.Children.Add(LoadWpLine(item as RTSafe.DxfCore.Entities.LightWeightPolyline)); break;

        //        }
        //    }
        //    SetLocal(c, block.BasePoint);
        //    return c;
        //}
        /// <summary>
        /// 圆
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private CircleElement LoadCircle(Circle item, int type)
        {
            CircleElement circleElement = new CircleElement();

            circleElement.Tag    = item.Layer.Name;
            circleElement.Height = circleElement.Width = 2 * item.Radius;
            circleElement.Radius = item.Radius;
            //e.StrokeThickness = GetThickness(item.Thickness);
            circleElement.Color = GetBrush(item.Color, item.Layer, type);
            foreach (var i in item.LineType.Segments)
            {
                //e.StrokeDashArray.Add(i);
            }
            circleElement.EPoint = new EPoint(item.Center.X - MinX, MaxY - item.Center.Y);
            return(circleElement);
        }
 public override void OnMouseUp(int button, int shift, int x, int y)
 {
     if (this._circleFeedback != null)
     {
         try
         {
             ICircularArc circularArc = this._circleFeedback.Stop();
             this._circleFeedback = null;
             IPolygon polygon = new Polygon() as IPolygon;
             object   value   = Missing.Value;
             (polygon as ISegmentCollection).AddSegment(circularArc as ISegment, ref value, ref value);
             IElement element = new CircleElement
             {
                 Geometry = polygon
             };
             INewElementOperation operation = new NewElementOperation
             {
                 ActiveView  = this._context.ActiveView,
                 ContainHook = this.GetActiveView(),
                 Element     = element
             };
             this._context.OperationStack.Do(operation);
             //if (this._context.Hook is IApplication)
             //{
             //    if ((this._context.Hook as IApplication).ContainerHook != null)
             //    {
             //        DocumentManager.DocumentChanged((this._context.Hook as IApplication).ContainerHook);
             //    }
             //    else
             //    {
             //        DocumentManager.DocumentChanged((this._context.Hook as IApplication).Hook);
             //    }
             //}
             //else
             //{
             //    DocumentManager.DocumentChanged(this._context.Hook);
             //}
         }
         catch (Exception exception_)
         {
             //CErrorLog.writeErrorLog(this, exception_, "");
         }
     }
 }
Example #7
0
        /// <summary>
        /// 块
        /// </summary>
        /// <param name="block"></param>
        /// <returns></returns>
        //private Canvas LoadBlock(RTSafe.DxfCore.Blocks.Block block)
        //{
        //    Canvas c = new Canvas();
        //    foreach (var item in block.Entities)
        //    {
        //        switch (item.Type)
        //        {
        //            case RTSafe.DxfCore.Entities.EntityType.Text: c.Children.Add(LoadText(item as RTSafe.DxfCore.Entities.Text)); break;
        //            case RTSafe.DxfCore.Entities.EntityType.Line: this._container.Children.Add(LoadLine(item as RTSafe.DxfCore.Entities.Line)); break;
        //            case RTSafe.DxfCore.Entities.EntityType.LightWeightPolyline: c.Children.Add(LoadWpLine(item as RTSafe.DxfCore.Entities.LightWeightPolyline)); break;

        //        }
        //    }
        //    SetLocal(c, block.BasePoint);
        //    return c;
        //}
        /// <summary>
        /// 圆
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private Element LoadCircle(Circle item, int type)
        {
            var           color         = GetBrush(item.Color, item.Layer, type).Color;
            CircleElement circleElement = new CircleElement
            {
                Tag       = item.Layer.Name,
                LayerName = item.Layer.Name,
                R         = color.R,
                G         = color.G,
                B         = color.B,
                Radius    = item.Radius
            };

            //circleElement.Height = circleElement.Width = 2 * item.Radius;
            //e.StrokeThickness = GetThickness(item.Thickness);
            foreach (var i in item.LineType.Segments)
            {
                //e.StrokeDashArray.Add(i);
            }
            //circleElement.EPoint = new EPoint(item.Center.X  - MinX, MaxY - item.Center.Y );
            circleElement.X = item.Center.X - MinX;
            circleElement.Y = MaxY - item.Center.Y;
            return(circleElement);
        }
Example #8
0
        public void Update(Boolean useTransition)
        {
            LegendAreaWidth = 0;
            D3Data          = new Data()
            {
                List = Data.Select(d => d as Object).ToList()
            };

            CircleData   = Data.SelectMany(l => l.DataPoints).Where(dp => dp.Item2 != null).ToList();
            D3CircleData = new Data()
            {
                List = CircleData.Select(d => d as Object).ToList()
            };

            if (LegendVisibility == Visibility.Visible)
            {
                LegendRectangleElement.Data = D3Data;
                LegendRectangleElement.Update(useTransition ? TransitionType.Opacity : TransitionType.None);

                LegendTextElement.Data = D3Data;
                LegendTextElement.Update(useTransition ? TransitionType.Opacity : TransitionType.None);
                LegendTextElement.ForceMeasure();

                LegendAreaWidth          = Math.Max(LegendTextElement.MaxActualWidth + Const.LegendPatchWidth + Const.LegendPatchSpace + Const.PaddingRight, Const.MinimumLegendWidth);
                LegendTitleElement.Width = LegendAreaWidth;
                LegendTitleElement.Text  = LegendTitle;
                Canvas.SetTop(LegendTitleElement, LegendPatchYGetter(null, 0) - 30);
            }

            Canvas.SetLeft(LegendPanel, this.Width - LegendAreaWidth);

            if (HorizontalAxisVisibility == Visibility.Visible)
            {
                ChartAreaEndY = this.Height - Const.PaddingBottom - Const.HorizontalAxisHeight - Const.HorizontalAxisLabelHeight;
            }
            else
            {
                ChartAreaEndY = this.Height - Const.PaddingBottom;
            }

            if (LegendVisibility == Visibility.Visible)
            {
                ChartAreaEndX = this.Width - Const.PaddingRight - LegendAreaWidth;
            }
            else
            {
                ChartAreaEndX = this.Width - Const.PaddingRight;
            }

            HorizontalAxisLabelCanvasLeft = Const.PaddingLeft + Const.VerticalAxisWidth + Const.VerticalAxisLabelWidth;
            HorizontalAxisLabelCanvasTop  = ChartAreaEndY + Const.HorizontalAxisHeight;
            HorizontalAxisLabelWidth      = ChartAreaEndX - Const.PaddingLeft - Const.VerticalAxisWidth - Const.VerticalAxisLabelWidth;

            VerticalAxisCanvasLeft      = Const.PaddingLeft + Const.VerticalAxisLabelWidth + Const.VerticalAxisWidth;
            VerticalAxisLabelCanvasLeft = Const.PaddingLeft + Const.VerticalAxisLabelWidth / 2 - (ChartAreaEndY - Const.PaddingTop) / 2;
            VerticalAxisLabelCanvasTop  = Const.PaddingTop + (ChartAreaEndY - Const.PaddingTop) / 2;
            VerticalAxisLabelHeight     = ChartAreaEndY - Const.PaddingTop;


            Double yMin = Math.Min(CircleData.Select(d => (Double)d.EnvelopeItem2).Min(), CircleData.Select(d => (Double)d.Item2).Min()),
                   yMax = Math.Max(CircleData.Select(d => (Double)d.EnvelopeItem2).Max(), CircleData.Select(d => (Double)d.Item2).Max());

            if (YStartsFromZero)
            {
                yMin = 0;
            }
            else if (yMin == yMax)
            {
                if (yMin == 0.0)
                {
                    yMin = -1; yMax = 1;
                }
                else if (yMin < 0)
                {
                    yMin *= 1.2;
                    yMax *= 0.8;
                }
                else
                {
                    yMin *= 0.8;
                    yMax *= 1.2;
                }
            }
            else
            {
                if (yMin > 0)
                {
                    yMin *= 0.9;
                }
                else
                {
                    yMin *= 1.1;
                }
            }

            YScale = new Linear()
            {
                DomainStart = yMin,
                DomainEnd   = yMax,
                RangeStart  = ChartAreaEndY,
                RangeEnd    = Const.PaddingTop
            };

            YScale.Nice();

            XScale = new Ordinal()
            {
                RangeStart = VerticalAxisCanvasLeft,
                RangeEnd   = ChartAreaEndX + Const.PaddingLeft
            };

            foreach (Object item1 in CircleData.OrderBy(dp => dp.Order)
                     .Select(cd => cd.Item1).Distinct())
            {
                XScale.Domain.Add(item1);
            }

            HandleLineElement.Data   = D3Data;
            EnvelopeLineElement.Data = D3Data;
            LineElement.Data         = D3Data;

            EnvelopeCircleElement.Data = D3CircleData;
            CircleElement.Data         = D3CircleData;

            HorizontalAxis.Scale = XScale;
            Canvas.SetTop(HorizontalAxis, ChartAreaEndY);
            HorizontalAxis.Visibility = HorizontalAxisVisibility;

            Canvas.SetTop(HorizontalAxisTitleElement, HorizontalAxisLabelCanvasTop);
            Canvas.SetLeft(HorizontalAxisTitleElement, HorizontalAxisLabelCanvasLeft);
            HorizontalAxisTitleElement.Width      = HorizontalAxisLabelWidth;
            HorizontalAxisTitleElement.Visibility = HorizontalAxisVisibility;
            HorizontalAxisTitleElement.Text       = HorizontalAxisTitle;

            VerticalAxis.Scale = YScale;
            Canvas.SetLeft(VerticalAxis, VerticalAxisCanvasLeft);

            Canvas.SetTop(VerticalAxisTitleElement, VerticalAxisLabelCanvasTop);
            Canvas.SetLeft(VerticalAxisTitleElement, VerticalAxisLabelCanvasLeft);
            VerticalAxisTitleElement.Width = VerticalAxisLabelHeight;
            VerticalAxisTitleElement.Text  = VerticalAxisTitle;

            LegendHandleRectangleElement.Data       = D3Data;
            LegendHandleRectangleElement.Visibility = LegendVisibility;

            IndicatorTextElement.Data = D3CircleData;

            HandleLineElement.Update(useTransition ? TransitionType.Opacity : TransitionType.None);
            LineElement.Update(useTransition ? TransitionType.Opacity & TransitionType.Color: TransitionType.None);
            EnvelopeCircleElement.Update(useTransition ? TransitionType.Opacity : TransitionType.None);
            EnvelopeLineElement.Update(useTransition ? TransitionType.Opacity & TransitionType.Color : TransitionType.None);
            CircleElement.Update(TransitionType.None);        // useTransition ? TransitionType.Opacity : TransitionType.None);
            LegendHandleRectangleElement.Update(TransitionType.None);
            IndicatorTextElement.Update(TransitionType.None); // useTransition ? TransitionType.Opacity : TransitionType.None);
            HorizontalAxis.Update(useTransition);
            VerticalAxis.Update(useTransition);
        }
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            // Create a PDF document
            Document pdfDocument = new Document(serverIP, serverPort);

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // The titles font used to mark various sections of the PDF document
            PdfFont titleFont = new PdfFont("Times New Roman", 12, true);

            titleFont.Bold = true;

            // Create a PDF page in PDF document
            PdfPage pdfPage = pdfDocument.AddPage();

            // Line Elements

            // Add section title
            TextElement titleTextElement = new TextElement(5, 5, "Line Elements", titleFont);

            titleTextElement.ForeColor = RgbColor.Black;
            pdfPage.AddElement(titleTextElement);

            // Add a line with default properties
            LineElement lineElement = new LineElement(0, 0, 50, 0);

            pdfDocument.AddElement(lineElement, 10);

            // Add a bold line
            LineElement boldLineElement = new LineElement(0, 0, 50, 0);

            boldLineElement.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(boldLineElement, 10, true, false, 0, true, false);

            // Add dotted line
            LineElement dottedLineElement = new LineElement(0, 0, 50, 0);

            dottedLineElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
            dottedLineElement.ForeColor = RgbColor.Green;
            pdfDocument.AddElement(dottedLineElement, 10, true, false, 0, true, false);

            // Add a dashed line
            LineElement dashedLineElement = new LineElement(0, 0, 50, 0);

            dashedLineElement.LineStyle.LineDashStyle = LineDashStyle.Dash;
            dashedLineElement.ForeColor = RgbColor.Green;
            pdfDocument.AddElement(dashedLineElement, 10, true, false, 0, true, false);

            // Add a dash-dot-dot line
            LineElement dashDotDotLineElement = new LineElement(0, 0, 50, 0);

            dashDotDotLineElement.LineStyle.LineDashStyle = LineDashStyle.DashDotDot;
            dashDotDotLineElement.ForeColor = RgbColor.Green;
            pdfDocument.AddElement(dashDotDotLineElement, 10, true, false, 0, true, false);

            // Add a bold line with rounded cap style
            LineElement roundCapBoldLine = new LineElement(0, 0, 50, 0);

            roundCapBoldLine.LineStyle.LineWidth    = 5;
            roundCapBoldLine.LineStyle.LineCapStyle = LineCapStyle.RoundCap;
            roundCapBoldLine.ForeColor = RgbColor.Blue;
            pdfDocument.AddElement(roundCapBoldLine, 10, true, false, 0, true, false);

            // Add a bold line with projecting square cap style
            LineElement projectingSquareCapBoldLine = new LineElement(0, 0, 50, 0);

            projectingSquareCapBoldLine.LineStyle.LineWidth    = 5;
            projectingSquareCapBoldLine.LineStyle.LineCapStyle = LineCapStyle.ProjectingSquareCap;
            projectingSquareCapBoldLine.ForeColor = RgbColor.Blue;
            pdfDocument.AddElement(projectingSquareCapBoldLine, 10, true, false, 0, true, false);

            // Add a bold line with projecting butt cap style
            LineElement buttCapBoldLine = new LineElement(0, 0, 50, 0);

            buttCapBoldLine.LineStyle.LineWidth    = 5;
            buttCapBoldLine.LineStyle.LineCapStyle = LineCapStyle.ButtCap;
            buttCapBoldLine.ForeColor = RgbColor.Blue;
            pdfDocument.AddElement(buttCapBoldLine, 10, true, false, 0, true, false);

            // Line Join Styles

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Line Join and Cap Styles", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Add graphic path with miter join line style
            PathElement miterJoinPath = new PathElement(new PointFloat(0, 50));

            // Add path lines
            miterJoinPath.AddLineSegment(new PointFloat(25, 0));
            miterJoinPath.AddLineSegment(new PointFloat(50, 50));
            // Set path style
            miterJoinPath.LineStyle.LineWidth     = 5;
            miterJoinPath.LineStyle.LineCapStyle  = LineCapStyle.ProjectingSquareCap;
            miterJoinPath.LineStyle.LineJoinStyle = LineJoinStyle.MiterJoin;
            miterJoinPath.ForeColor = RgbColor.Coral;
            pdfDocument.AddElement(miterJoinPath, 5, false, 10, true);

            // Add graphic path with round join line style
            PathElement roundJoinPath = new PathElement(new PointFloat(0, 50));

            // Add path lines
            roundJoinPath.AddLineSegment(new PointFloat(25, 0));
            roundJoinPath.AddLineSegment(new PointFloat(50, 50));
            // Set path style
            roundJoinPath.LineStyle.LineWidth     = 5;
            roundJoinPath.LineStyle.LineCapStyle  = LineCapStyle.RoundCap;
            roundJoinPath.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
            roundJoinPath.ForeColor = RgbColor.Coral;
            pdfDocument.AddElement(roundJoinPath, 20, true, false, 0, true, false);


            // Add graphic path with bevel join line style
            PathElement bevelJoinPath = new PathElement(new PointFloat(0, 50));

            // Add lines to path
            bevelJoinPath.AddLineSegment(new PointFloat(25, 0));
            bevelJoinPath.AddLineSegment(new PointFloat(50, 50));
            // Set path style
            bevelJoinPath.LineStyle.LineWidth     = 5;
            bevelJoinPath.LineStyle.LineCapStyle  = LineCapStyle.ButtCap;
            bevelJoinPath.LineStyle.LineJoinStyle = LineJoinStyle.BevelJoin;
            bevelJoinPath.ForeColor = RgbColor.Coral;
            // Add element to document
            pdfDocument.AddElement(bevelJoinPath, 20, true, false, 0, true, false);

            // Add a polygon with miter join line style
            PointFloat[] polygonPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(25, 0),
                new PointFloat(50, 50)
            };
            PolygonElement miterJoinPolygon = new PolygonElement(polygonPoints);

            // Set polygon style
            miterJoinPolygon.LineStyle.LineWidth     = 5;
            miterJoinPolygon.LineStyle.LineJoinStyle = LineJoinStyle.MiterJoin;
            miterJoinPolygon.ForeColor = RgbColor.Green;
            miterJoinPolygon.BackColor = RgbColor.AliceBlue;
            pdfDocument.AddElement(miterJoinPolygon, 20, true, false, 0, true, false);

            // Add a polygon with round join line style
            polygonPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(25, 0),
                new PointFloat(50, 50)
            };
            PolygonElement roundJoinPolygon = new PolygonElement(polygonPoints);

            // Set polygon style
            roundJoinPolygon.LineStyle.LineWidth     = 5;
            roundJoinPolygon.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
            roundJoinPolygon.ForeColor = RgbColor.Green;
            roundJoinPolygon.BackColor = RgbColor.Blue;
            pdfDocument.AddElement(roundJoinPolygon, 20, true, false, 0, true, false);

            // Add a polygon with bevel join line style
            polygonPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(25, 0),
                new PointFloat(50, 50)
            };
            PolygonElement bevelJoinPolygon = new PolygonElement(polygonPoints);

            // Set polygon style
            bevelJoinPolygon.LineStyle.LineWidth     = 5;
            bevelJoinPolygon.LineStyle.LineJoinStyle = LineJoinStyle.BevelJoin;
            bevelJoinPolygon.ForeColor = RgbColor.Green;
            bevelJoinPolygon.BackColor = RgbColor.Blue;
            pdfDocument.AddElement(bevelJoinPolygon, 20, true, false, 0, true, false);


            // Add a Graphics Path Element

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Path Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Create the path
            PathElement graphicsPath = new PathElement(new PointFloat(0, 0));

            // Add line and Bezier curve segments
            graphicsPath.AddLineSegment(new PointFloat(50, 50));
            graphicsPath.AddBezierCurveSegment(new PointFloat(100, 0), new PointFloat(200, 100), new PointFloat(250, 50));
            graphicsPath.AddLineSegment(new PointFloat(300, 0));
            // Close path
            graphicsPath.ClosePath = true;
            // Set path style
            graphicsPath.LineStyle.LineWidth     = 3;
            graphicsPath.LineStyle.LineJoinStyle = LineJoinStyle.MiterJoin;
            graphicsPath.LineStyle.LineCapStyle  = LineCapStyle.RoundCap;
            graphicsPath.ForeColor = RgbColor.Green;
            //graphicsPath.BackColor = Color.Green;
            graphicsPath.Gradient = new GradientColor(GradientDirection.Vertical, RgbColor.LightGreen, RgbColor.Blue);
            // Add element to document
            pdfDocument.AddElement(graphicsPath, 5, false, 10, true);


            // Add Circle Elements

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Circle Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Add a Circle Element with default settings
            CircleElement circleElement = new CircleElement(30, 30, 30);

            pdfDocument.AddElement(circleElement, 10);

            // Add dotted circle element
            CircleElement dottedCircleElement = new CircleElement(30, 30, 30);

            dottedCircleElement.ForeColor = RgbColor.Green;
            dottedCircleElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
            pdfDocument.AddElement(dottedCircleElement, 10, true, false, 0, true, false);

            // Add a disc
            CircleElement discElement = new CircleElement(30, 30, 30);

            discElement.ForeColor = RgbColor.Green;
            discElement.BackColor = RgbColor.LightGray;
            pdfDocument.AddElement(discElement, 10, true, false, 0, true, false);

            // Add disc with bold border
            CircleElement discWithBoldBorder = new CircleElement(30, 30, 30);

            discWithBoldBorder.LineStyle.LineWidth = 5;
            discWithBoldBorder.BackColor           = RgbColor.Coral;
            discWithBoldBorder.ForeColor           = RgbColor.Blue;
            pdfDocument.AddElement(discWithBoldBorder, 10, true, false, 0, true, false);

            // Add colored disc with bold border
            for (int i = 30; i > 0; i = i - 3)
            {
                CircleElement coloredDisc = new CircleElement(30, 30, i);
                coloredDisc.LineStyle.LineWidth = 3;
                switch ((i / 3) % 7)
                {
                case 0:
                    coloredDisc.BackColor = RgbColor.Red;
                    break;

                case 1:
                    coloredDisc.BackColor = RgbColor.Orange;
                    break;

                case 2:
                    coloredDisc.BackColor = RgbColor.Yellow;
                    break;

                case 3:
                    coloredDisc.BackColor = RgbColor.Green;
                    break;

                case 4:
                    coloredDisc.BackColor = RgbColor.Blue;
                    break;

                case 5:
                    coloredDisc.BackColor = RgbColor.Indigo;
                    break;

                case 6:
                    coloredDisc.BackColor = RgbColor.Violet;
                    break;

                default:
                    break;
                }
                if (i == 30)
                {
                    pdfDocument.AddElement(coloredDisc, 10, true, false, 0, true, false);
                }
                else
                {
                    pdfDocument.AddElement(coloredDisc, 3, true, true, 3, true, false);
                }
            }

            // Add a doughnut
            CircleElement exteriorNoBorderDisc = new CircleElement(30, 30, 30);

            exteriorNoBorderDisc.BackColor = RgbColor.Coral;
            pdfDocument.AddElement(exteriorNoBorderDisc, 40, true, false, -30, true, false);

            CircleElement interiorNoBorderDisc = new CircleElement(30, 30, 15);

            interiorNoBorderDisc.BackColor = RgbColor.White;
            pdfDocument.AddElement(interiorNoBorderDisc, 15, true, true, 15, true, false);

            // Add a simple disc
            CircleElement simpleDisc = new CircleElement(30, 30, 30);

            simpleDisc.BackColor = RgbColor.Green;
            pdfDocument.AddElement(simpleDisc, 25, true, false, -15, true, false);


            // Add Ellipse Elements

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Ellipse Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Add an Ellipse Element with default settings
            EllipseElement ellipseElement = new EllipseElement(50, 30, 50, 30);

            pdfDocument.AddElement(ellipseElement, 5, false, 10, true);

            // Add an Ellipse Element with background color and line color
            EllipseElement ellipseWithBackgroundAndBorder = new EllipseElement(50, 30, 50, 30);

            ellipseWithBackgroundAndBorder.BackColor = RgbColor.LightGray;
            ellipseWithBackgroundAndBorder.ForeColor = RgbColor.Green;
            pdfDocument.AddElement(ellipseWithBackgroundAndBorder, 10, true, false, 0, true, false);

            // Create an ellipse from multiple Ellipse Arc Elements
            EllipseArcElement ellipseArcElement1 = new EllipseArcElement(0, 0, 100, 60, 0, 100);

            ellipseArcElement1.ForeColor           = RgbColor.Coral;
            ellipseArcElement1.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(ellipseArcElement1, 10, true, false, 0, true, false);

            EllipseArcElement ellipseArcElement2 = new EllipseArcElement(0, 0, 100, 60, 100, 100);

            ellipseArcElement2.ForeColor           = RgbColor.Blue;
            ellipseArcElement2.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(ellipseArcElement2, 0, true, true, 0, true, false);

            EllipseArcElement ellipseArcElement3 = new EllipseArcElement(0, 0, 100, 60, 180, 100);

            ellipseArcElement3.ForeColor           = RgbColor.Green;
            ellipseArcElement3.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(ellipseArcElement3, 0, true, true, 0, true, false);

            EllipseArcElement ellipseArcElement4 = new EllipseArcElement(0, 0, 100, 60, 270, 100);

            ellipseArcElement4.ForeColor           = RgbColor.Violet;
            ellipseArcElement4.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(ellipseArcElement4, 0, true, true, 0, true, false);

            // Create an ellipse from multiple Ellipse Slice Elements
            EllipseSliceElement ellipseSliceElement1 = new EllipseSliceElement(0, 0, 100, 60, 0, 90);

            ellipseSliceElement1.BackColor = RgbColor.Coral;
            pdfDocument.AddElement(ellipseSliceElement1, 10, true, false, 0, true, false);

            EllipseSliceElement ellipseSliceElement2 = new EllipseSliceElement(0, 0, 100, 60, 90, 90);

            ellipseSliceElement2.BackColor = RgbColor.Blue;
            pdfDocument.AddElement(ellipseSliceElement2, 0, true, true, 0, true, false);

            EllipseSliceElement ellipseSliceElement3 = new EllipseSliceElement(0, 0, 100, 60, 180, 90);

            ellipseSliceElement3.BackColor = RgbColor.Green;
            pdfDocument.AddElement(ellipseSliceElement3, 0, true, true, 0, true, false);


            EllipseSliceElement ellipseSliceElement4 = new EllipseSliceElement(0, 0, 100, 60, 270, 90);

            ellipseSliceElement4.BackColor = RgbColor.Violet;
            pdfDocument.AddElement(ellipseSliceElement4, 0, true, true, 0, true, false);

            // Add an Ellipse Element with background
            EllipseElement ellipseWithBackground = new EllipseElement(0, 0, 50, 30);

            ellipseWithBackground.BackColor = RgbColor.Green;
            pdfDocument.AddElement(ellipseWithBackground, 10, true, false, 0, true, false);


            // Add Rectangle Elements

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Rectangle Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Add a Rectangle Element with default settings
            RectangleElement rectangleElement = new RectangleElement(0, 0, 100, 60);

            pdfDocument.AddElement(rectangleElement, 10);

            // Add a Rectangle Element with background color and dotted line
            RectangleElement rectangleElementWithDottedLine = new RectangleElement(0, 0, 100, 60);

            rectangleElementWithDottedLine.BackColor = RgbColor.LightGray;
            rectangleElementWithDottedLine.ForeColor = RgbColor.Green;
            rectangleElementWithDottedLine.LineStyle.LineDashStyle = LineDashStyle.Dot;
            pdfDocument.AddElement(rectangleElementWithDottedLine, 10, true, false, 0, true, false);

            // Add a Rectangle Element with background color without border
            RectangleElement rectangleElementWithoutBorder = new RectangleElement(0, 0, 100, 60);

            rectangleElementWithoutBorder.BackColor = RgbColor.Green;
            pdfDocument.AddElement(rectangleElementWithoutBorder, 10, true, false, 0, true, false);

            // Add a Rectangle Element with background color, bold border line and rounded corners
            RectangleElement rectangleElementWithRoundedCorners = new RectangleElement(0, 0, 100, 60);

            rectangleElementWithRoundedCorners.BackColor               = RgbColor.Coral;
            rectangleElementWithRoundedCorners.ForeColor               = RgbColor.Blue;
            rectangleElementWithRoundedCorners.LineStyle.LineWidth     = 5;
            rectangleElementWithRoundedCorners.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
            pdfDocument.AddElement(rectangleElementWithRoundedCorners, 10, true, false, 0, true, false);


            // Add Polygon Elements

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Polygon Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            PointFloat[] polygonElementPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(50, 0),
                new PointFloat(100, 50),
                new PointFloat(50, 100)
            };

            // Add a Polygon Element with default settings
            PolygonElement polygonElement = new PolygonElement(polygonElementPoints);

            pdfDocument.AddElement(polygonElement, 10);

            polygonElementPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(50, 0),
                new PointFloat(100, 50),
                new PointFloat(50, 100)
            };

            // Add a Polygon Element with background color and border
            polygonElement           = new PolygonElement(polygonElementPoints);
            polygonElement.BackColor = RgbColor.LightGray;
            polygonElement.ForeColor = RgbColor.Green;
            polygonElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
            pdfDocument.AddElement(polygonElement, 10, true, false, 0, true, false);

            polygonElementPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(50, 0),
                new PointFloat(100, 50),
                new PointFloat(50, 100)
            };

            // Add a Polygon Element with background color
            polygonElement           = new PolygonElement(polygonElementPoints);
            polygonElement.BackColor = RgbColor.Green;
            pdfDocument.AddElement(polygonElement, 10, true, false, 0, true, false);

            PointFloat[] polyFillPoints = new PointFloat[] {
                new PointFloat(0, 50),
                new PointFloat(50, 0),
                new PointFloat(100, 50),
                new PointFloat(50, 100)
            };

            // Add a Polygon Element with background color and rounded line joins
            PolygonElement polygonElementWithBackgruondColorAndBorder = new PolygonElement(polyFillPoints);

            polygonElementWithBackgruondColorAndBorder.ForeColor               = RgbColor.Blue;
            polygonElementWithBackgruondColorAndBorder.BackColor               = RgbColor.Coral;
            polygonElementWithBackgruondColorAndBorder.LineStyle.LineWidth     = 5;
            polygonElementWithBackgruondColorAndBorder.LineStyle.LineCapStyle  = LineCapStyle.RoundCap;
            polygonElementWithBackgruondColorAndBorder.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
            pdfDocument.AddElement(polygonElementWithBackgruondColorAndBorder, 10, true, false, 0, true, false);

            // Add Bezier Curve Elements

            // Add section title
            titleTextElement           = new TextElement(0, 0, "Bezier Curve Elements", titleFont);
            titleTextElement.ForeColor = RgbColor.Black;
            pdfDocument.AddElement(titleTextElement, 5, false, 10, true);

            // Add a Bezier Curve Element with normal style

            BezierCurveElement bezierCurveElement = new BezierCurveElement(0, 50, 50, 0, 100, 100, 150, 50);

            bezierCurveElement.ForeColor           = RgbColor.Blue;
            bezierCurveElement.LineStyle.LineWidth = 3;
            pdfDocument.AddElement(bezierCurveElement, 10);

            // Add a Bezier Curve Element with dotted line using the controlling points above

            bezierCurveElement           = new BezierCurveElement(0, 50, 50, 0, 100, 100, 150, 50);
            bezierCurveElement.ForeColor = RgbColor.Green;
            bezierCurveElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
            bezierCurveElement.LineStyle.LineWidth     = 1;
            pdfDocument.AddElement(bezierCurveElement, 30, true, false, 0, true, false);


            // Mark the points controlling the Bezier curve
            CircleElement controlPoint1 = new CircleElement(0, 0, 10);

            controlPoint1.BackColor = RgbColor.Violet;
            controlPoint1.Opacity   = 75;
            pdfDocument.AddElement(controlPoint1, -10, true, true, 40, true, false);

            CircleElement controlPoint2 = new CircleElement(0, 0, 10);

            controlPoint2.BackColor = RgbColor.Violet;
            pdfDocument.AddElement(controlPoint2, 50, true, true, -50, true, false);

            CircleElement controlPoint3 = new CircleElement(0, 0, 10);

            controlPoint3.BackColor = RgbColor.Violet;
            pdfDocument.AddElement(controlPoint3, 50, true, true, 100, true, false);

            CircleElement controlPoint4 = new CircleElement(0, 0, 10);

            controlPoint4.BackColor = RgbColor.Violet;
            pdfDocument.AddElement(controlPoint4, 50, true, true, -50, true, false);

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Graphic_Elements.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }
Example #10
0
        private static IElement CreateSvgLine(XdObjectJson xdObject, List <IDefElement> defs)
        {
            var id       = xdObject.GetSimpleName().Replace(" ", "_");
            var dataName = xdObject.GetSimpleName();
            var shape    = xdObject.Shape;

            var parameter = new ElementParameter
            {
                Id = id
            };

            parameter.Transform = new Transform {
                Value = xdObject.Transform
            };

            var opacity = xdObject.Style?.Opacity;

            parameter.Opacity = opacity;

            if (xdObject.Group != null)
            {
                if (MaskGroupParser.Is(xdObject))
                {
                    var clipPathId = $"clip-path{defs.Count}";
                    parameter.ClipPath = $"url(#{clipPathId})";
                    var clipPathChildren = xdObject.Meta.Ux.ClipPathResources.Children.Select(x => CreateSvgLine(x, defs));
                    defs.Add(new ClipPathDefElement {
                        Id = clipPathId, Children = clipPathChildren.ToArray()
                    });
                }

                parameter.DataName = dataName;
                var blendMode = xdObject.Style?.BlendMode;
                var isolation = xdObject.Style?.Isolation;
                var children  = xdObject.Group.Children.Select(x => CreateSvgLine(x, defs)).ToArray();
                return(new GroupElement {
                    Parameter = parameter, Children = children, BlendMode = blendMode, Isolation = isolation
                });
            }

            XdStyleFillPatternJson image = null;
            var fill = xdObject.Style?.Fill;

            parameter.EnableFill = true;
            if (fill != null && fill.Type != "none")
            {
                var color = xdObject.Style.Fill.ToUnityColor();
                parameter.Fill = color;

                if (fill.Type == "solid" || fill.Type == "gradient")
                {
                    // nothing to do
                    // gradientはサポートしていないが、知らないタイプというわけではないのでスルー
                }
                else if (fill.Type == "pattern")
                {
                    image          = fill.Pattern;
                    parameter.Fill = null;
                }
                else
                {
                    Debug.LogWarning($"Unknown fill type {fill.Type} in {xdObject.Name}");
                }

                if (!string.IsNullOrWhiteSpace(shape.Winding))
                {
                    parameter.FillRule = shape.Winding;
                }
            }

            float?shapeR = null;

            if (shape.R != null)
            {
                if (shape.R is List <object> list)
                {
                    shapeR = (float)(double)list[0];
                }
                else if (shape.R is double d)
                {
                    shapeR = (float)d;
                }
                else
                {
                    throw new NotSupportedException($"Unknown shape.r type {shape.R.GetType()}");
                }
            }

            if (shapeR != null && shape.Type != CircleElement.Name)
            {
                parameter.Rx = shapeR;
                if (parameter.Rx > shape.Width / 2f)
                {
                    parameter.Rx = shape.Width / 2f;
                }
                if (parameter.Rx > shape.Height / 2f)
                {
                    parameter.Rx = shape.Height / 2f;
                }
            }

            var    stroke      = xdObject.Style?.Stroke;
            string strokeAlign = null;

            if (stroke != null && stroke.Type != "none")
            {
                parameter.EnableStroke     = true;
                parameter.Stroke           = stroke.ToUnityColor();
                parameter.StrokeWidth      = stroke.Width;
                parameter.StrokeMiterLimit = stroke.MiterLimit;

                if (!string.IsNullOrWhiteSpace(stroke.Join))
                {
                    parameter.StrokeLinejoin = stroke.Join;
                }

                if (!string.IsNullOrWhiteSpace(stroke.Cap))
                {
                    parameter.StrokeLinecap = stroke.Cap;
                }

                if (stroke.Dash != null)
                {
                    parameter.StrokeDasharray = stroke.Dash;
                }

                if (stroke.Align == null)
                {
                    strokeAlign = null;
                }
                else if (stroke.Align == "outside")
                {
                    strokeAlign = "outside";
                }
                else if (stroke.Align == "inside")
                {
                    strokeAlign = "inside";
                }
                else
                {
                    throw new NotSupportedException($"{xdObject} has unknown align type {stroke.Align}");
                }
            }

            if (image != null)
            {
                var imageBytes = XdImporter.XdFile.GetResource(fill.Pattern.Meta);
                return(new ImageElement {
                    Parameter = parameter, ImageBytes = imageBytes, Width = shape.Width, Height = shape.Height
                });
            }

            if (shape.Type == PathElement.Name)
            {
                return new PathElement {
                           Parameter = parameter, D = shape.Path
                }
            }
            ;

            if (shape.Type == CompoundElement.Name)
            {
                return new CompoundElement {
                           Parameter = parameter, D = shape.Path
                }
            }
            ;

            if (shape.Type == LineElement.Name)
            {
                return new LineElement {
                           Parameter = parameter, X1 = shape.X1, Y1 = shape.Y1, X2 = shape.X2, Y2 = shape.Y2
                }
            }
            ;

            if (shape.Type == RectElement.Name)
            {
                if (strokeAlign == "outside")
                {
                    return(RectElement.Outside(shape, parameter));
                }
                if (strokeAlign == "inside")
                {
                    return(RectElement.Inside(shape, parameter));
                }
                return(new RectElement {
                    Parameter = parameter, Width = shape.Width, Height = shape.Height
                });
            }

            if (shape.Type == CircleElement.Name)
            {
                if (strokeAlign == "outside")
                {
                    return(CircleElement.Outside(shape, parameter, shapeR));
                }
                if (strokeAlign == "inside")
                {
                    return(CircleElement.Inside(shape, parameter, shapeR));
                }
                return(new CircleElement {
                    Parameter = parameter, Cx = shape.Cx, Cy = shape.Cy, R = shapeR.Value
                });
            }

            if (shape.Type == EllipseElement.Name)
            {
                if (strokeAlign == "outside")
                {
                    return(EllipseElement.Outside(shape, parameter));
                }
                if (strokeAlign == "inside")
                {
                    return(EllipseElement.Inside(shape, parameter));
                }
                return(new EllipseElement {
                    Parameter = parameter, Cx = shape.Cx, Cy = shape.Cy, Rx = shape.Rx, Ry = shape.Ry
                });
            }

            throw new NotSupportedException($"Unknown type {shape.Type}");
        }
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Create a PDF document
            Document pdfDocument = new Document();

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            try
            {
                // The result of adding elements to PDF document
                AddElementResult addElementResult = null;

                // The titles font used to mark various sections of the PDF document
                PdfFont titleFont = pdfDocument.AddFont(new Font("Times New Roman", 12, FontStyle.Bold, GraphicsUnit.Point));

                // The position on X anf Y axes where to add the next element
                float yLocation = 5;
                float xLocation = 5;

                // Create a PDF page in PDF document
                PdfPage pdfPage = pdfDocument.AddPage();

                // Line Elements

                // Add section title
                TextElement titleTextElement = new TextElement(xLocation, yLocation, "Line Elements", titleFont);
                titleTextElement.ForeColor = Color.Black;
                addElementResult           = pdfPage.AddElement(titleTextElement);
                yLocation  = addElementResult.EndPageBounds.Bottom + 10;
                xLocation += 5;
                pdfPage    = addElementResult.EndPdfPage;

                // Add a line with default properties
                LineElement lineElement = new LineElement(xLocation, yLocation, xLocation + 50, yLocation);
                addElementResult = pdfPage.AddElement(lineElement);

                // Add a bold line
                LineElement boldLineElement = new LineElement(xLocation + 60, yLocation, xLocation + 110, yLocation);
                boldLineElement.LineStyle.LineWidth = 3;
                addElementResult = pdfPage.AddElement(boldLineElement);

                // Add dotted line
                LineElement dottedLineElement = new LineElement(xLocation + 120, yLocation, xLocation + 170, yLocation);
                dottedLineElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
                dottedLineElement.ForeColor = Color.Green;
                addElementResult            = pdfPage.AddElement(dottedLineElement);

                // Add a dashed line
                LineElement dashedLineElement = new LineElement(xLocation + 180, yLocation, xLocation + 230, yLocation);
                dashedLineElement.LineStyle.LineDashStyle = LineDashStyle.Dash;
                dashedLineElement.ForeColor = Color.Green;
                addElementResult            = pdfPage.AddElement(dashedLineElement);

                // Add a dash-dot-dot line
                LineElement dashDotDotLineElement = new LineElement(xLocation + 240, yLocation, xLocation + 290, yLocation);
                dashDotDotLineElement.LineStyle.LineDashStyle = LineDashStyle.DashDotDot;
                dashDotDotLineElement.ForeColor = Color.Green;
                addElementResult = pdfPage.AddElement(dashDotDotLineElement);

                // Add a bold line with rounded cap style
                LineElement roundCapBoldLine = new LineElement(xLocation + 300, yLocation, xLocation + 350, yLocation);
                roundCapBoldLine.LineStyle.LineWidth    = 5;
                roundCapBoldLine.LineStyle.LineCapStyle = LineCapStyle.RoundCap;
                roundCapBoldLine.ForeColor = Color.Blue;
                addElementResult           = pdfPage.AddElement(roundCapBoldLine);

                // Add a bold line with projecting square cap style
                LineElement projectingSquareCapBoldLine = new LineElement(xLocation + 360, yLocation, xLocation + 410, yLocation);
                projectingSquareCapBoldLine.LineStyle.LineWidth    = 5;
                projectingSquareCapBoldLine.LineStyle.LineCapStyle = LineCapStyle.ProjectingSquareCap;
                projectingSquareCapBoldLine.ForeColor = Color.Blue;
                addElementResult = pdfPage.AddElement(projectingSquareCapBoldLine);

                // Add a bold line with projecting butt cap style
                LineElement buttCapBoldLine = new LineElement(xLocation + 420, yLocation, xLocation + 470, yLocation);
                buttCapBoldLine.LineStyle.LineWidth    = 5;
                buttCapBoldLine.LineStyle.LineCapStyle = LineCapStyle.ButtCap;
                buttCapBoldLine.ForeColor = Color.Blue;
                addElementResult          = pdfPage.AddElement(buttCapBoldLine);

                yLocation = addElementResult.EndPageBounds.Bottom + 3;
                pdfPage   = addElementResult.EndPdfPage;

                // Line Join Styles

                // Add section title
                xLocation                 -= 5;
                yLocation                 += 10;
                titleTextElement           = new TextElement(xLocation, yLocation, "Line Join and Cap Styles", titleFont);
                titleTextElement.ForeColor = Color.Black;
                addElementResult           = pdfPage.AddElement(titleTextElement);
                yLocation                  = addElementResult.EndPageBounds.Bottom + 10;
                xLocation                 += 5;
                pdfPage = addElementResult.EndPdfPage;

                // Add graphic path with miter join line style
                PathElement miterJoinPath = new PathElement(new PointF(xLocation, yLocation + 50));
                // Add path lines
                miterJoinPath.AddLineSegment(new PointF(xLocation + 25, yLocation));
                miterJoinPath.AddLineSegment(new PointF(xLocation + 50, yLocation + 50));
                // Set path style
                miterJoinPath.LineStyle.LineWidth     = 5;
                miterJoinPath.LineStyle.LineCapStyle  = LineCapStyle.ProjectingSquareCap;
                miterJoinPath.LineStyle.LineJoinStyle = LineJoinStyle.MiterJoin;
                miterJoinPath.ForeColor = Color.Coral;
                addElementResult        = pdfPage.AddElement(miterJoinPath);

                // Add graphic path with round join line style
                PathElement roundJoinPath = new PathElement(new PointF(xLocation + 70, yLocation + 50));
                // Add path lines
                roundJoinPath.AddLineSegment(new PointF(xLocation + 95, yLocation));
                roundJoinPath.AddLineSegment(new PointF(xLocation + 120, yLocation + 50));
                // Set path style
                roundJoinPath.LineStyle.LineWidth     = 5;
                roundJoinPath.LineStyle.LineCapStyle  = LineCapStyle.RoundCap;
                roundJoinPath.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
                roundJoinPath.ForeColor = Color.Coral;
                addElementResult        = pdfPage.AddElement(roundJoinPath);

                // Add graphic path with bevel join line style
                PathElement bevelJoinPath = new PathElement(new PointF(xLocation + 140, yLocation + 50));
                // Add lines to path
                bevelJoinPath.AddLineSegment(new PointF(xLocation + 165, yLocation));
                bevelJoinPath.AddLineSegment(new PointF(xLocation + 190, yLocation + 50));
                // Set path style
                bevelJoinPath.LineStyle.LineWidth     = 5;
                bevelJoinPath.LineStyle.LineCapStyle  = LineCapStyle.ButtCap;
                bevelJoinPath.LineStyle.LineJoinStyle = LineJoinStyle.BevelJoin;
                bevelJoinPath.ForeColor = Color.Coral;
                // Add element to document
                addElementResult = pdfPage.AddElement(bevelJoinPath);

                // Add a polygon with miter join line style
                PointF[] polygonPoints = new PointF[] {
                    new PointF(xLocation + 210, yLocation + 50),
                    new PointF(xLocation + 235, yLocation),
                    new PointF(xLocation + 260, yLocation + 50)
                };
                PolygonElement miterJoinPolygon = new PolygonElement(polygonPoints);
                // Set polygon style
                miterJoinPolygon.LineStyle.LineWidth     = 5;
                miterJoinPolygon.LineStyle.LineJoinStyle = LineJoinStyle.MiterJoin;
                miterJoinPolygon.ForeColor = Color.Green;
                miterJoinPolygon.BackColor = Color.AliceBlue;
                addElementResult           = pdfPage.AddElement(miterJoinPolygon);

                // Add a polygon with round join line style
                polygonPoints = new PointF[] {
                    new PointF(xLocation + 280, yLocation + 50),
                    new PointF(xLocation + 305, yLocation),
                    new PointF(xLocation + 330, yLocation + 50)
                };
                PolygonElement roundJoinPolygon = new PolygonElement(polygonPoints);
                // Set polygon style
                roundJoinPolygon.LineStyle.LineWidth     = 5;
                roundJoinPolygon.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
                roundJoinPolygon.ForeColor = Color.Green;
                roundJoinPolygon.BackColor = Color.Blue;
                addElementResult           = pdfPage.AddElement(roundJoinPolygon);

                // Add a polygon with bevel join line style
                polygonPoints = new PointF[] {
                    new PointF(xLocation + 350, yLocation + 50),
                    new PointF(xLocation + 375, yLocation),
                    new PointF(xLocation + 400, yLocation + 50)
                };
                PolygonElement bevelJoinPolygon = new PolygonElement(polygonPoints);
                // Set polygon style
                bevelJoinPolygon.LineStyle.LineWidth     = 5;
                bevelJoinPolygon.LineStyle.LineJoinStyle = LineJoinStyle.BevelJoin;
                bevelJoinPolygon.ForeColor = Color.Green;
                bevelJoinPolygon.BackColor = Color.Blue;
                addElementResult           = pdfPage.AddElement(bevelJoinPolygon);

                yLocation = addElementResult.EndPageBounds.Bottom + 3;
                pdfPage   = addElementResult.EndPdfPage;

                // Add a Graphics Path Element

                // Add section title
                xLocation                 -= 5;
                yLocation                 += 10;
                titleTextElement           = new TextElement(xLocation, yLocation, "Path Elements", titleFont);
                titleTextElement.ForeColor = Color.Black;
                addElementResult           = pdfPage.AddElement(titleTextElement);
                yLocation                  = addElementResult.EndPageBounds.Bottom + 10;
                xLocation                 += 5;
                pdfPage = addElementResult.EndPdfPage;

                // Create the path
                PathElement graphicsPath = new PathElement(new PointF(xLocation, yLocation));
                // Add line and Bezier curve segments
                graphicsPath.AddLineSegment(new PointF(xLocation + 50, yLocation + 50));
                graphicsPath.AddBezierCurveSegment(new PointF(xLocation + 100, yLocation), new PointF(xLocation + 200, yLocation + 100),
                                                   new PointF(xLocation + 250, yLocation + 50));
                graphicsPath.AddLineSegment(new PointF(xLocation + 300, yLocation));
                // Close path
                graphicsPath.ClosePath = true;
                // Set path style
                graphicsPath.LineStyle.LineWidth     = 3;
                graphicsPath.LineStyle.LineJoinStyle = LineJoinStyle.MiterJoin;
                graphicsPath.LineStyle.LineCapStyle  = LineCapStyle.RoundCap;
                graphicsPath.ForeColor = Color.Green;
                //graphicsPath.BackColor = Color.Green;
                graphicsPath.Gradient = new GradientColor(GradientDirection.Vertical, System.Drawing.Color.LightGreen, System.Drawing.Color.Blue);
                // Add element to document
                addElementResult = pdfPage.AddElement(graphicsPath);

                yLocation = addElementResult.EndPageBounds.Bottom + 3;
                pdfPage   = addElementResult.EndPdfPage;

                // Add Circle Elements

                // Add section title
                xLocation                 -= 5;
                yLocation                 -= 10;
                titleTextElement           = new TextElement(xLocation, yLocation, "Circle Elements", titleFont);
                titleTextElement.ForeColor = Color.Black;
                addElementResult           = pdfPage.AddElement(titleTextElement);
                yLocation                  = addElementResult.EndPageBounds.Bottom + 10;
                xLocation                 += 5;
                pdfPage = addElementResult.EndPdfPage;

                // Add a Circle Element with default settings
                CircleElement circleElement = new CircleElement(xLocation + 30, yLocation + 30, 30);
                addElementResult = pdfPage.AddElement(circleElement);

                // Add dotted circle element
                CircleElement dottedCircleElement = new CircleElement(xLocation + 100, yLocation + 30, 30);
                dottedCircleElement.ForeColor = Color.Green;
                dottedCircleElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
                addElementResult = pdfPage.AddElement(dottedCircleElement);

                // Add a disc
                CircleElement discElement = new CircleElement(xLocation + 170, yLocation + 30, 30);
                discElement.ForeColor = Color.Green;
                discElement.BackColor = Color.LightGray;
                addElementResult      = pdfPage.AddElement(discElement);

                // Add disc with bold border
                CircleElement discWithBoldBorder = new CircleElement(xLocation + 240, yLocation + 30, 30);
                discWithBoldBorder.LineStyle.LineWidth = 5;
                discWithBoldBorder.BackColor           = Color.Coral;
                discWithBoldBorder.ForeColor           = Color.Blue;
                addElementResult = pdfPage.AddElement(discWithBoldBorder);

                // Add colored disc with bold border
                for (int i = 30; i >= 0; i = i - 3)
                {
                    CircleElement coloredDisc = new CircleElement(xLocation + 310, yLocation + 30, i == 0 ? 1 : i);
                    coloredDisc.LineStyle.LineWidth = 3;
                    switch ((i / 3) % 7)
                    {
                    case 0:
                        coloredDisc.BackColor = Color.Red;
                        break;

                    case 1:
                        coloredDisc.BackColor = Color.Orange;
                        break;

                    case 2:
                        coloredDisc.BackColor = Color.Yellow;
                        break;

                    case 3:
                        coloredDisc.BackColor = Color.Green;
                        break;

                    case 4:
                        coloredDisc.BackColor = Color.Blue;
                        break;

                    case 5:
                        coloredDisc.BackColor = Color.Indigo;
                        break;

                    case 6:
                        coloredDisc.BackColor = Color.Violet;
                        break;

                    default:
                        break;
                    }
                    addElementResult = pdfPage.AddElement(coloredDisc);
                }

                // Add a doughnut
                CircleElement exteriorNoBorderDisc = new CircleElement(xLocation + 380, yLocation + 30, 30);
                exteriorNoBorderDisc.BackColor = Color.Coral;
                addElementResult = pdfPage.AddElement(exteriorNoBorderDisc);

                CircleElement interiorNoBorderDisc = new CircleElement(xLocation + 380, yLocation + 30, 15);
                interiorNoBorderDisc.BackColor = Color.White;
                pdfPage.AddElement(interiorNoBorderDisc);

                // Add a simple disc
                CircleElement simpleDisc = new CircleElement(xLocation + 450, yLocation + 30, 30);
                simpleDisc.BackColor = Color.Green;
                addElementResult     = pdfPage.AddElement(simpleDisc);

                yLocation = addElementResult.EndPageBounds.Bottom + 3;
                pdfPage   = addElementResult.EndPdfPage;

                // Add Ellipse Elements

                // Add section title
                xLocation                 -= 5;
                yLocation                 += 10;
                titleTextElement           = new TextElement(xLocation, yLocation, "Ellipse Elements", titleFont);
                titleTextElement.ForeColor = Color.Black;
                addElementResult           = pdfPage.AddElement(titleTextElement);
                yLocation                  = addElementResult.EndPageBounds.Bottom + 10;
                xLocation                 += 5;
                pdfPage = addElementResult.EndPdfPage;

                // Add an Ellipse Element with default settings
                EllipseElement ellipseElement = new EllipseElement(xLocation + 50, yLocation + 30, 50, 30);
                addElementResult = pdfPage.AddElement(ellipseElement);

                // Add an Ellipse Element with background color and line color
                EllipseElement ellipseWithBackgroundAndBorder = new EllipseElement(xLocation + 160, yLocation + 30, 50, 30);
                ellipseWithBackgroundAndBorder.BackColor = Color.LightGray;
                ellipseWithBackgroundAndBorder.ForeColor = Color.Green;
                addElementResult = pdfPage.AddElement(ellipseWithBackgroundAndBorder);

                // Create an ellipse from multiple Ellipse Arc Elements
                EllipseArcElement ellipseArcElement1 = new EllipseArcElement(xLocation + 220, yLocation, 100, 60, 0, 100);
                ellipseArcElement1.ForeColor           = Color.Coral;
                ellipseArcElement1.LineStyle.LineWidth = 3;
                addElementResult = pdfPage.AddElement(ellipseArcElement1);

                EllipseArcElement ellipseArcElement2 = new EllipseArcElement(xLocation + 220, yLocation, 100, 60, 100, 100);
                ellipseArcElement2.ForeColor           = Color.Blue;
                ellipseArcElement2.LineStyle.LineWidth = 3;
                addElementResult = pdfPage.AddElement(ellipseArcElement2);

                EllipseArcElement ellipseArcElement3 = new EllipseArcElement(xLocation + 220, yLocation, 100, 60, 180, 100);
                ellipseArcElement3.ForeColor           = Color.Green;
                ellipseArcElement3.LineStyle.LineWidth = 3;
                addElementResult = pdfPage.AddElement(ellipseArcElement3);

                EllipseArcElement ellipseArcElement4 = new EllipseArcElement(xLocation + 220, yLocation, 100, 60, 270, 100);
                ellipseArcElement4.ForeColor           = Color.Violet;
                ellipseArcElement4.LineStyle.LineWidth = 3;
                addElementResult = pdfPage.AddElement(ellipseArcElement4);

                // Create an ellipse from multiple Ellipse Slice Elements
                EllipseSliceElement ellipseSliceElement1 = new EllipseSliceElement(xLocation + 330, yLocation, 100, 60, 0, 90);
                ellipseSliceElement1.BackColor = Color.Coral;
                addElementResult = pdfPage.AddElement(ellipseSliceElement1);

                EllipseSliceElement ellipseSliceElement2 = new EllipseSliceElement(xLocation + 330, yLocation, 100, 60, 90, 90);
                ellipseSliceElement2.BackColor = Color.Blue;
                addElementResult = pdfPage.AddElement(ellipseSliceElement2);

                EllipseSliceElement ellipseSliceElement3 = new EllipseSliceElement(xLocation + 330, yLocation, 100, 60, 180, 90);
                ellipseSliceElement3.BackColor = Color.Green;
                addElementResult = pdfPage.AddElement(ellipseSliceElement3);

                EllipseSliceElement ellipseSliceElement4 = new EllipseSliceElement(xLocation + 330, yLocation, 100, 60, 270, 90);
                ellipseSliceElement4.BackColor = Color.Violet;
                addElementResult = pdfPage.AddElement(ellipseSliceElement4);

                // Add an Ellipse Element with background
                EllipseElement ellipseWithBackground = new EllipseElement(xLocation + 490, yLocation + 30, 50, 30);
                ellipseWithBackground.BackColor = Color.Green;
                addElementResult = pdfPage.AddElement(ellipseWithBackground);

                yLocation = addElementResult.EndPageBounds.Bottom + 3;
                pdfPage   = addElementResult.EndPdfPage;

                // Add Rectangle Elements

                // Add section title
                xLocation                 -= 5;
                yLocation                 += 10;
                titleTextElement           = new TextElement(xLocation, yLocation, "Rectangle Elements", titleFont);
                titleTextElement.ForeColor = Color.Black;
                addElementResult           = pdfPage.AddElement(titleTextElement);
                yLocation                  = addElementResult.EndPageBounds.Bottom + 10;
                xLocation                 += 5;
                pdfPage = addElementResult.EndPdfPage;

                // Add a Rectangle Element with default settings
                RectangleElement rectangleElement = new RectangleElement(xLocation, yLocation, 100, 60);
                addElementResult = pdfPage.AddElement(rectangleElement);

                // Add a Rectangle Element with background color and dotted line
                RectangleElement rectangleElementWithDottedLine = new RectangleElement(xLocation + 110, yLocation, 100, 60);
                rectangleElementWithDottedLine.BackColor = Color.LightGray;
                rectangleElementWithDottedLine.ForeColor = Color.Green;
                rectangleElementWithDottedLine.LineStyle.LineDashStyle = LineDashStyle.Dot;
                addElementResult = pdfPage.AddElement(rectangleElementWithDottedLine);

                // Add a Rectangle Element with background color without border
                RectangleElement rectangleElementWithoutBorder = new RectangleElement(xLocation + 220, yLocation, 100, 60);
                rectangleElementWithoutBorder.BackColor = Color.Green;
                addElementResult = pdfPage.AddElement(rectangleElementWithoutBorder);

                // Add a Rectangle Element with background color, bold border line and rounded corners
                RectangleElement rectangleElementWithRoundedCorners = new RectangleElement(xLocation + 330, yLocation, 100, 60);
                rectangleElementWithRoundedCorners.BackColor               = Color.Coral;
                rectangleElementWithRoundedCorners.ForeColor               = Color.Blue;
                rectangleElementWithRoundedCorners.LineStyle.LineWidth     = 5;
                rectangleElementWithRoundedCorners.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
                addElementResult = pdfPage.AddElement(rectangleElementWithRoundedCorners);

                yLocation = addElementResult.EndPageBounds.Bottom + 3;
                pdfPage   = addElementResult.EndPdfPage;

                // Add Polygon Elements

                // Add section title
                xLocation                 -= 5;
                yLocation                 += 10;
                titleTextElement           = new TextElement(xLocation, yLocation, "Polygon Elements", titleFont);
                titleTextElement.ForeColor = Color.Black;
                addElementResult           = pdfPage.AddElement(titleTextElement);
                yLocation                  = addElementResult.EndPageBounds.Bottom + 10;
                xLocation                 += 5;
                pdfPage = addElementResult.EndPdfPage;

                PointF[] polygonElementPoints = new PointF[] {
                    new PointF(xLocation, yLocation + 50),
                    new PointF(xLocation + 50, yLocation),
                    new PointF(xLocation + 100, yLocation + 50),
                    new PointF(xLocation + 50, yLocation + 100)
                };

                // Add a Polygon Element with default settings
                PolygonElement polygonElement = new PolygonElement(polygonElementPoints);
                addElementResult = pdfPage.AddElement(polygonElement);

                polygonElementPoints = new PointF[] {
                    new PointF(xLocation + 110, yLocation + 50),
                    new PointF(xLocation + 160, yLocation),
                    new PointF(xLocation + 210, yLocation + 50),
                    new PointF(xLocation + 160, yLocation + 100)
                };

                // Add a Polygon Element with background color and border
                polygonElement           = new PolygonElement(polygonElementPoints);
                polygonElement.BackColor = Color.LightGray;
                polygonElement.ForeColor = Color.Green;
                polygonElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
                addElementResult = pdfPage.AddElement(polygonElement);

                polygonElementPoints = new PointF[] {
                    new PointF(xLocation + 220, yLocation + 50),
                    new PointF(xLocation + 270, yLocation),
                    new PointF(xLocation + 320, yLocation + 50),
                    new PointF(xLocation + 270, yLocation + 100)
                };

                // Add a Polygon Element with background color
                polygonElement           = new PolygonElement(polygonElementPoints);
                polygonElement.BackColor = Color.Green;
                addElementResult         = pdfPage.AddElement(polygonElement);

                PointF[] polyFillPoints = new PointF[] {
                    new PointF(xLocation + 330, yLocation + 50),
                    new PointF(xLocation + 380, yLocation),
                    new PointF(xLocation + 430, yLocation + 50),
                    new PointF(xLocation + 380, yLocation + 100)
                };

                // Add a Polygon Element with background color and rounded line joins
                PolygonElement polygonElementWithBackgruondColorAndBorder = new PolygonElement(polyFillPoints);
                polygonElementWithBackgruondColorAndBorder.ForeColor               = Color.Blue;
                polygonElementWithBackgruondColorAndBorder.BackColor               = Color.Coral;
                polygonElementWithBackgruondColorAndBorder.LineStyle.LineWidth     = 5;
                polygonElementWithBackgruondColorAndBorder.LineStyle.LineCapStyle  = LineCapStyle.RoundCap;
                polygonElementWithBackgruondColorAndBorder.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin;
                addElementResult = pdfPage.AddElement(polygonElementWithBackgruondColorAndBorder);

                yLocation = addElementResult.EndPageBounds.Bottom + 3;
                pdfPage   = addElementResult.EndPdfPage;

                // Add Bezier Curve Elements

                // Add section title
                xLocation                 -= 5;
                yLocation                 += 10;
                titleTextElement           = new TextElement(xLocation, yLocation, "Bezier Curve Elements", titleFont);
                titleTextElement.ForeColor = Color.Black;
                addElementResult           = pdfPage.AddElement(titleTextElement);
                yLocation                  = addElementResult.EndPageBounds.Bottom + 10;
                xLocation                 += 5;
                pdfPage = addElementResult.EndPdfPage;

                // Add a Bezier Curve Element with normal style

                BezierCurveElement bezierCurveElement = new BezierCurveElement(xLocation, yLocation + 50, xLocation + 50, yLocation,
                                                                               xLocation + 100, yLocation + 100, xLocation + 150, yLocation + 50);
                bezierCurveElement.ForeColor           = Color.Blue;
                bezierCurveElement.LineStyle.LineWidth = 3;
                addElementResult = pdfPage.AddElement(bezierCurveElement);

                // Mark the points controlling the Bezier curve
                CircleElement controlPoint1 = new CircleElement(xLocation + 200, yLocation + 50, 2);
                controlPoint1.BackColor = Color.Violet;
                pdfPage.AddElement(controlPoint1);

                CircleElement controlPoint2 = new CircleElement(xLocation + 250, yLocation, 2);
                controlPoint2.BackColor = Color.Violet;
                pdfPage.AddElement(controlPoint2);

                CircleElement controlPoint3 = new CircleElement(xLocation + 300, yLocation + 100, 2);
                controlPoint3.BackColor = Color.Violet;
                pdfPage.AddElement(controlPoint3);

                CircleElement controlPoint4 = new CircleElement(xLocation + 350, yLocation + 50, 2);
                controlPoint4.BackColor = Color.Violet;
                pdfPage.AddElement(controlPoint4);

                // Add a Bezier Curve Element with dotted line using the controlling points above

                bezierCurveElement = new BezierCurveElement(controlPoint1.X, controlPoint1.Y, controlPoint2.X, controlPoint2.Y,
                                                            controlPoint3.X, controlPoint3.Y, controlPoint4.X, controlPoint4.Y);
                bezierCurveElement.ForeColor = Color.Green;
                bezierCurveElement.LineStyle.LineDashStyle = LineDashStyle.Dot;
                bezierCurveElement.LineStyle.LineWidth     = 1;
                addElementResult = pdfPage.AddElement(bezierCurveElement);

                // Save the PDF document in a memory buffer
                byte[] outPdfBuffer = pdfDocument.Save();

                // Send the PDF as response to browser

                // Set response content type
                Response.AddHeader("Content-Type", "application/pdf");

                // Instruct the browser to open the PDF file as an attachment or inline
                Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Graphic_Elements.pdf; size={0}", outPdfBuffer.Length.ToString()));

                // Write the PDF document buffer to HTTP response
                Response.BinaryWrite(outPdfBuffer);

                // End the HTTP response and stop the current page processing
                Response.End();
            }
            finally
            {
                // Close the PDF document
                pdfDocument.Close();
            }
        }
Example #12
0
        /// <summary>
        /// 添加图元
        /// </summary>
        /// <param name="pGeometry"></param>
        /// <param name="pActiveView"></param>
        /// <param name="pSymbol"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public IElement AddElement(IGeometry pGeometry, ISymbol pSymbol, string key)
        {
            try
            {
                IActiveView        pActiveView        = mapControl.ActiveView;
                IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;
                IElement           pElement           = null;
                ILineElement       pLineElement       = null;
                IFillShapeElement  pFillShapeElement  = null;
                IMarkerElement     pMarkerElement     = null;
                ICircleElement     pCircleElement     = null;
                IElementProperties pElmentProperties  = null;
                switch (pGeometry.GeometryType)
                {
                case esriGeometryType.esriGeometryEnvelope:
                {
                    pElement                 = new RectangleElement();
                    pElement.Geometry        = pGeometry;
                    pFillShapeElement        = (IFillShapeElement)pElement;
                    pFillShapeElement.Symbol = (IFillSymbol)pSymbol;
                    break;
                }

                case esriGeometryType.esriGeometryPolyline:
                {
                    pElement            = new LineElement();
                    pElement.Geometry   = pGeometry;
                    pLineElement        = (ILineElement)pElement;
                    pLineElement.Symbol = (ILineSymbol)pSymbol;
                    break;
                }

                case esriGeometryType.esriGeometryLine:
                {
                    pElement          = new LineElement();
                    pElement.Geometry = pGeometry;

                    pLineElement        = (ILineElement)pElement;
                    pLineElement.Symbol = (ILineSymbol)pSymbol;
                    break;
                }

                case esriGeometryType.esriGeometryPolygon:
                {
                    pElement          = new PolygonElement();
                    pElement.Geometry = pGeometry;
                    pFillShapeElement = (IFillShapeElement)pElement;

                    pFillShapeElement.Symbol = (IFillSymbol)pSymbol;
                    break;
                }

                case esriGeometryType.esriGeometryMultipoint:
                case esriGeometryType.esriGeometryPoint:
                {
                    pElement          = new MarkerElement();
                    pElement.Geometry = pGeometry;

                    pMarkerElement = (IMarkerElement)pElement;

                    pMarkerElement.Symbol = (IMarkerSymbol)pSymbol;
                    break;
                }

                case esriGeometryType.esriGeometryCircularArc:
                {
                    pElement          = new CircleElement();
                    pElement.Geometry = pGeometry;

                    pCircleElement = (ICircleElement)pElement;
                    break;
                }

                default:
                    pElement = null;
                    break;
                }

                if (pElement != null)
                {
                    pElmentProperties      = pElement as IElementProperties;
                    pElmentProperties.Name = key;
                    pGraphicsContainer.AddElement(pElement, 0);
                    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, pGeometry.Envelope);
                    return(pElement);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #13
0
        private static IElement CreateSvgLine(XdObjectJson xdObject, List <IDefElement> defs)
        {
            var id       = xdObject.Name.Replace(" ", "_");
            var dataName = xdObject.Name;
            var shape    = xdObject.Shape;

            var parameter = new ElementParameter
            {
                Id = id
            };

            var tx = xdObject.Transform?.Tx ?? 0f;
            var ty = xdObject.Transform?.Ty ?? 0f;

            parameter.Transform.X = tx;
            parameter.Transform.Y = ty;

            var opacity = xdObject.Style?.Opacity;

            parameter.Opacity = opacity;

            if (xdObject.Group != null)
            {
                parameter.DataName = dataName;
                if (xdObject.Meta?.Ux?.ClipPathResources?.Type == "clipPath")
                {
                    var clipPath = xdObject.Meta.Ux.ClipPathResources.Children[0];
                    parameter.ClipPath = "url(#clip-path)";

                    var clipPathPath = new PathElement
                    {
                        Parameter = new ElementParameter
                        {
                            Id        = "_Clipping_Path_",
                            DataName  = "Clipping Path",
                            Transform = new Transform
                            {
                                X = clipPath.Transform.Tx,
                                Y = clipPath.Transform.Ty,
                            },
                        },
                        D = clipPath.Shape.Path,
                    };
                    defs.Add(new ClipPathDefElement {
                        Id = "clip-path", Path = clipPathPath
                    });
                }

                var children = xdObject.Group.Children.Select(x => CreateSvgLine(x, defs)).ToArray();
                return(new GroupElement {
                    Parameter = parameter, Children = children
                });
            }

            var fill = xdObject.Style?.Fill;

            parameter.EnableFill = true;
            if (fill != null && fill.Type != "none")
            {
                var color = xdObject.GetFillColor();
                parameter.Fill = color;

                if (!string.IsNullOrWhiteSpace(shape.Winding))
                {
                    parameter.FillRule = shape.Winding;
                }
            }

            float?shapeR = null;

            if (shape.R != null)
            {
                if (shape.R is Newtonsoft.Json.Linq.JValue jValue)
                {
                    shapeR = (float)jValue;
                }
                else if (shape.R is Newtonsoft.Json.Linq.JArray jArray)
                {
                    shapeR = (float)jArray[0];
                }
                else if (shape.R is long l)
                {
                    shapeR = l;
                }
                else if (shape.R is double d)
                {
                    shapeR = (float)d;
                }
                else
                {
                    throw new NotSupportedException($"Unknown shape.r type {shape.R.GetType()}");
                }
            }

            if (shapeR != null && shape.Type != CircleElement.Name)
            {
                parameter.Rx = shapeR;
                if (parameter.Rx > shape.Width / 2f)
                {
                    parameter.Rx = shape.Width / 2f;
                }
                if (parameter.Rx > shape.Height / 2f)
                {
                    parameter.Rx = shape.Height / 2f;
                }
            }

            var    stroke      = xdObject.Style?.Stroke;
            string strokeAlign = null;

            if (stroke != null && stroke.Type != "none")
            {
                parameter.EnableStroke     = true;
                parameter.Stroke           = stroke.Color.Value;
                parameter.StrokeWidth      = stroke.Width;
                parameter.StrokeMiterLimit = stroke.MiterLimit;

                if (!string.IsNullOrWhiteSpace(stroke.Join))
                {
                    parameter.StrokeLinejoin = stroke.Join;
                }

                if (!string.IsNullOrWhiteSpace(stroke.Cap))
                {
                    parameter.StrokeLinecap = stroke.Cap;
                }

                if (stroke.Dash != null)
                {
                    parameter.StrokeDasharray = stroke.Dash;
                }

                if (stroke.Align == null)
                {
                    strokeAlign = null;
                }
                else if (stroke.Align == "outside")
                {
                    strokeAlign = "outside";
                }
                else if (stroke.Align == "inside")
                {
                    strokeAlign = "inside";
                }
                else
                {
                    throw new NotSupportedException($"{xdObject} has unknown align type {stroke.Align}");
                }
            }

            if (shape.Type == PathElement.Name)
            {
                return new PathElement {
                           Parameter = parameter, D = shape.Path
                }
            }
            ;

            if (shape.Type == CompoundElement.Name)
            {
                return new CompoundElement {
                           Parameter = parameter, D = shape.Path
                }
            }
            ;

            if (shape.Type == LineElement.Name)
            {
                return new LineElement {
                           Parameter = parameter, X1 = shape.X1, Y1 = shape.Y1, X2 = shape.X2, Y2 = shape.Y2
                }
            }
            ;

            if (shape.Type == RectElement.Name)
            {
                if (strokeAlign == "outside")
                {
                    return(RectElement.Outside(shape, parameter));
                }
                if (strokeAlign == "inside")
                {
                    return(RectElement.Inside(shape, parameter));
                }
                return(new RectElement {
                    Parameter = parameter, Width = shape.Width, Height = shape.Height
                });
            }

            if (shape.Type == CircleElement.Name)
            {
                if (strokeAlign == "outside")
                {
                    return(CircleElement.Outside(shape, parameter, shapeR));
                }
                if (strokeAlign == "inside")
                {
                    return(CircleElement.Inside(shape, parameter, shapeR));
                }
                return(new CircleElement {
                    Parameter = parameter, Cx = shape.Cx, Cy = shape.Cy, R = shapeR.Value
                });
            }

            if (shape.Type == EllipseElement.Name)
            {
                if (strokeAlign == "outside")
                {
                    return(EllipseElement.Outside(shape, parameter));
                }
                if (strokeAlign == "inside")
                {
                    return(EllipseElement.Inside(shape, parameter));
                }
                return(new EllipseElement {
                    Parameter = parameter, Cx = shape.Cx, Cy = shape.Cy, Rx = shape.Rx, Ry = shape.Ry
                });
            }

            throw new NotSupportedException($"Unknown type {shape.Type}");
        }
        /// <summary>
        /// 加载图形
        /// </summary>
        /// <param name="shaps"></param>
        /// <param name="type"></param>
        private List <ElementList> LoadShaps(ReadOnlyCollection <IEntityObject> shaps, int type)
        {
            var enumerable = shaps.GroupBy(c => new { c.Type, c.Layer.Name }).Select(c => new { c.Key }).OrderBy(c => c.Key.Type).ToList();
            List <TextElement>   textElements   = new List <TextElement>();
            List <LineElement>   lineElements   = new List <LineElement>();
            List <ElementList>   elementLists   = new List <ElementList>();
            List <PathElement>   pathElements   = new List <PathElement>();
            List <CircleElement> circleElements = new List <CircleElement>();
            List <LightWeightPolylineElement> lightWeightPolylineElements = new List <LightWeightPolylineElement>();


            var entityTypes = shaps.GroupBy(c => c.Type).Select(c => new { c.Key }).ToList();

            foreach (var item in shaps)
            {
                switch (item.Type)
                {
                case EntityType.Arc:
                    PathElement
                         pathElement = LoadArc(item as Arc, type);
                    if (pathElement != null)
                    {
                        pathElements.Add(pathElement);
                    }
                    break;

                case EntityType.Circle:
                    CircleElement circleElement = LoadCircle(item as Circle, type);

                    if (circleElement != null)
                    {
                        circleElements.Add(circleElement);
                    }

                    break;

                case EntityType.LightWeightPolyline:
                    var eel = LoadWpLine(item as LightWeightPolyline, type);

                    if (eel != null)
                    {
                        lightWeightPolylineElements.Add(eel);
                    }
                    break;

                case EntityType.Line:

                    LineElement line = LoadLine(item as Line, type);

                    if (line != null)
                    {
                        lineElements.Add(line);
                    }
                    break;

                case EntityType.Text:
                    TextElement text = LoadText(item as Text, type);
                    if (text != null)
                    {
                        textElements.Add(text);
                    }
                    break;

                //        //case EntityType.Point: e = LoadPoint(item as Point); break;
                //        //case EntityType.Solid: e = LoadSolid(item as Solid); break;
                //        // case Entities.EntityType.Hatch
                case EntityType.Polyline:
                    break;

                case EntityType.Polyline3d:
                    break;

                case EntityType.PolyfaceMesh:
                    break;

                case EntityType.NurbsCurve:
                    break;

                case EntityType.Ellipse:
                    break;

                case EntityType.Point:
                    break;

                case EntityType.Face3D:
                    break;

                case EntityType.Solid:
                    break;

                case EntityType.Insert:
                    break;

                case EntityType.Hatch:
                    break;

                case EntityType.Attribute:
                    break;

                case EntityType.AttributeDefinition:
                    break;

                case EntityType.LightWeightPolylineVertex:
                    break;

                case EntityType.PolylineVertex:
                    break;

                case EntityType.Polyline3dVertex:
                    break;

                case EntityType.PolyfaceMeshVertex:
                    break;

                case EntityType.PolyfaceMeshFace:
                    break;

                case EntityType.Dimension:
                    break;

                case EntityType.Vertex:
                    break;

                case EntityType.Spline:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            ElementList elementList = new ElementList();

            if (textElements.Count != 0)
            {
                elementList.TextElements = textElements;
            }
            if (lineElements.Count != 0)
            {
                elementList.LineElements = lineElements;
            }
            if (lineElements.Count != 0)
            {
                elementList.PathElements = pathElements;
            }

            if (circleElements.Count != 0)
            {
                elementList.CircleElements = circleElements;
            }

            if (lightWeightPolylineElements.Count != 0)
            {
                elementList.LightWeightPolylineElements = lightWeightPolylineElements;
            }


            elementLists.Add(elementList);
            return(elementLists); //textElements;
        }
 public CircleElement(uint serialNumber, CircleElement next = null)
 {
     SerialNumber = serialNumber;
     Next         = next;
 }
Example #16
0
        public void Update(Boolean useTransition)
        {
            categoricalColumnViewModel = Data.First().ColumnViewModel;

            LegendAreaWidth = 0;
            D3Data          = new Data()
            {
                List = Data.Select(d => d as Object).ToList()
            };

            LegendData   = Data.Select(d => d.Key).Distinct().ToList();
            D3LegendData = new Data()
            {
                List = LegendData.Select(d => d as Object).ToList()
            };

            if (LegendVisibility == Visibility.Visible)
            {
                LegendRectangleElement.Data = D3LegendData;
                LegendRectangleElement.Update(useTransition ? TransitionType.Opacity : TransitionType.None);

                LegendTextElement.Data = D3LegendData;
                LegendTextElement.Update(useTransition ? TransitionType.Opacity : TransitionType.None);
                LegendTextElement.ForceMeasure();

                LegendAreaWidth          = LegendTextElement.MaxActualWidth + Const.LegendPatchWidth + Const.LegendPatchSpace + Const.PaddingRight;
                LegendTitleElement.Width = LegendAreaWidth;
                LegendTitleElement.Text  = LegendTitle;
                Canvas.SetTop(LegendTitleElement, LegendPatchYGetter(null, 0) - 30);
            }

            Canvas.SetLeft(LegendPanel, this.Width - LegendAreaWidth);

            if (HorizontalAxisVisibility == Visibility.Visible)
            {
                ChartAreaEndY = this.Height - Const.PaddingBottom - Const.HorizontalAxisHeight - Const.HorizontalAxisLabelHeight;
            }
            else
            {
                ChartAreaEndY = this.Height - Const.PaddingBottom;
            }

            if (LegendVisibility == Visibility.Visible)
            {
                ChartAreaEndX = this.Width - Const.PaddingRight - LegendAreaWidth;
            }
            else
            {
                ChartAreaEndX = this.Width - Const.PaddingRight - 20;
            }

            HorizontalAxisLabelCanvasLeft = Const.PaddingLeft + Const.VerticalAxisWidth + Const.VerticalAxisLabelWidth;
            HorizontalAxisLabelCanvasTop  = ChartAreaEndY + Const.HorizontalAxisHeight;
            HorizontalAxisLabelWidth      = ChartAreaEndX - Const.PaddingLeft - Const.VerticalAxisWidth - Const.VerticalAxisLabelWidth;

            VerticalAxisCanvasLeft      = Const.PaddingLeft + Const.VerticalAxisLabelWidth + Const.VerticalAxisWidth;
            VerticalAxisLabelCanvasLeft = Const.PaddingLeft + Const.VerticalAxisLabelWidth / 2 - (ChartAreaEndY - Const.PaddingTop) / 2;
            VerticalAxisLabelCanvasTop  = Const.PaddingTop + (ChartAreaEndY - Const.PaddingTop) / 2;
            VerticalAxisLabelHeight     = ChartAreaEndY - Const.PaddingTop;

            XScale = new Linear()
            {
                DomainStart = Data.Select(d => d.Value1).Min(),
                DomainEnd   = Data.Select(d => d.Value1).Max(),
                RangeStart  = VerticalAxisCanvasLeft,
                RangeEnd    = ChartAreaEndX + Const.PaddingLeft
            };

            if (XScale.DomainStart < 0)
            {
                XScale.DomainStart *= 1.1;
            }
            else
            {
                XScale.DomainStart *= 0.9;
            }

            if (XScale.DomainEnd < 0)
            {
                XScale.DomainEnd *= 0.9;
            }
            else
            {
                XScale.DomainEnd *= 1.1;
            }

            XScale.Nice();

            YScale = new Linear()
            {
                DomainStart = Data.Select(d => d.Value2).Min(),
                DomainEnd   = Data.Select(d => d.Value2).Max(),
                RangeStart  = ChartAreaEndY,
                RangeEnd    = Const.PaddingTop
            };

            if (YScale.DomainStart < 0)
            {
                YScale.DomainStart *= 1.1;
            }
            else
            {
                YScale.DomainStart *= 0.9;
            }

            if (YScale.DomainEnd < 0)
            {
                YScale.DomainEnd *= 0.9;
            }
            else
            {
                YScale.DomainEnd *= 1.1;
            }

            YScale.Nice();

            CircleElement.Data = D3Data;

            HorizontalAxis.Scale = XScale;
            Canvas.SetTop(HorizontalAxis, ChartAreaEndY);
            HorizontalAxis.Visibility = HorizontalAxisVisibility;

            Canvas.SetTop(HorizontalAxisTitleElement, HorizontalAxisLabelCanvasTop);
            Canvas.SetLeft(HorizontalAxisTitleElement, HorizontalAxisLabelCanvasLeft);
            HorizontalAxisTitleElement.Width      = HorizontalAxisLabelWidth;
            HorizontalAxisTitleElement.Visibility = HorizontalAxisVisibility;
            HorizontalAxisTitleElement.Text       = HorizontalAxisTitle;

            VerticalAxis.Scale = YScale;
            Canvas.SetLeft(VerticalAxis, VerticalAxisCanvasLeft);

            Canvas.SetTop(VerticalAxisTitleElement, VerticalAxisLabelCanvasTop);
            Canvas.SetLeft(VerticalAxisTitleElement, VerticalAxisLabelCanvasLeft);
            VerticalAxisTitleElement.Width = VerticalAxisLabelHeight;
            VerticalAxisTitleElement.Text  = VerticalAxisTitle;

            LegendHandleRectangleElement.Data       = D3LegendData;
            LegendHandleRectangleElement.Visibility = LegendVisibility;

            LegendRectangleElement.Data       = D3LegendData;
            LegendRectangleElement.Visibility = LegendVisibility;

            LegendTextElement.Data       = D3LegendData;
            LegendTextElement.Visibility = LegendVisibility;

            LegendHandleRectangleElement.Update(TransitionType.None);
            CircleElement.Update(useTransition ? TransitionType.All : TransitionType.None);
            //CircleElement.UpdateLayout();
            HorizontalAxis.Update(useTransition);
            VerticalAxis.Update(useTransition);
        }