Пример #1
0
        void RenderPolygons(XGraphics gfx)
        {
            gfx.TranslateTransform(15, 20);

            XPen pen = new XPen(XColors.DarkBlue, 2.5);

            gfx.DrawPolygon(pen, XBrushes.LightCoral, GeometryObjects.GetPentagram(50, new XPoint(60, 70)), XFillMode.Winding);
            gfx.DrawPolygon(pen, XBrushes.LightCoral, GeometryObjects.GetPentagram(50, new XPoint(180, 70)), XFillMode.Alternate);
        }
Пример #2
0
        static void DrawPolygon(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawPolygon");

            XPen pen = new XPen(XColors.DarkBlue, 2.5);

            gfx.DrawPolygon(pen, XBrushes.LightCoral, GetPentagram(50, new XPoint(60, 70)), XFillMode.Winding);
            gfx.DrawPolygon(pen, XBrushes.LightCoral, GetPentagram(50, new XPoint(180, 70)), XFillMode.Alternate);

            EndBox(gfx);
        }
        /// <summary>
        /// Demonstrates the use of XGraphics.Transform.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            gfx.Save();

            gfx.IntersectClip(new XRect(20, 20, 300, 500));
            gfx.DrawRectangle(XBrushes.Yellow, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

            gfx.IntersectClip(new XRect(100, 200, 300, 500));
            gfx.DrawRectangle(XBrushes.LightBlue, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200)));


            Matrix matrix = new Matrix();

            //matrix.Scale(2f, 1.5f);
            //matrix.Translate(-200, -400);
            //matrix.Rotate(45);
            //matrix.Translate(200, 400);
            //gfx.Transform = matrix;
            //gfx.TranslateTransform(50, 30);

#if true
            gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend);
            gfx.RotateTransform(15, XMatrixOrder.Prepend);
#else
            gfx.TranslateTransform(30, 40, XMatrixOrder.Append);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append);
            gfx.RotateTransform(15, XMatrixOrder.Append);
#endif
            bool id = matrix.IsIdentity;
            matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend);
            //matrix.Translate(30, -50);
            matrix.Rotate(15, MatrixOrder.Prepend);
            //Matrix mtx = gfx.Transform.ToGdipMatrix();
            //gfx.Transform = matrix;

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200)));

            //gfx.ResetClip();
            gfx.Restore();

            gfx.DrawLine(XPens.Red, 0, 0, 1000, 1000);

            gfx.DrawPolygon(XPens.SandyBrown, GetPentagram(75, new PointF(150, 200)));
        }
        /// <summary>
        /// Demonstrates the use of XGraphics.DrawPolygon.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200)));

            gfx.DrawPolygon(properties.Brush2.Brush, GetPentagram(75, new PointF(150, 400)), XFillMode.Alternate);

            gfx.DrawPolygon(properties.Brush2.Brush, GetPentagram(75, new PointF(350, 400)), XFillMode.Winding);

            gfx.DrawPolygon(properties.Pen2.Pen, properties.Brush2.Brush, GetPentagram(75, new PointF(150, 600)), XFillMode.Alternate);

            gfx.DrawPolygon(properties.Pen2.Pen, properties.Brush2.Brush, GetPentagram(75, new PointF(350, 600)), XFillMode.Winding);
        }
Пример #5
0
 public override void DrawPolygon(RBrush brush, RPoint[] points)
 {
     if (points != null && points.Length > 0)
     {
         _g.DrawPolygon((XBrush)((BrushAdapter)brush).Brush, Utils.Convert(points), XFillMode.Winding);
     }
 }
Пример #6
0
        /// <summary>
        /// Demonstrates the use of XGraphics.DrawRoundedRectangle.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            // Stroke ellipse
            gfx.DrawEllipse(properties.Pen1.Pen, 50, 100, 450, 150);

            // Fill ellipse
            gfx.DrawEllipse(properties.Brush2.Brush, new Rectangle(50, 300, 450, 150));

            // Stroke and fill ellipse
            gfx.DrawEllipse(properties.Pen2.Pen, properties.Brush2.Brush, new RectangleF(50, 500, 450, 150));

            // Stroke circle
            gfx.DrawEllipse(properties.Pen2.Pen, new XRect(100, 200, 400, 400));

#if DEBUG
            int      count  = 360;
            XPoint[] circle = new XPoint[count];
            for (int idx = 0; idx < count; idx++)
            {
                double rad = idx * 2 * Math.PI / count;
                circle[idx].X = Math.Cos(rad) * 200 + 300;
                circle[idx].Y = Math.Sin(rad) * 200 + 400;
            }
            gfx.DrawPolygon(properties.Pen3.Pen, circle);
#endif
        }
Пример #7
0
        private void DrawPolygon(string fillColor, XPoint [] points)
        {
            //XPen pen = new XPen(XColors.DarkBlue, 2.5);

            XBrush xBrush = XBrush(fillColor);

            gfx.DrawPolygon(xBrush, points, XFillMode.Winding);
        }
Пример #8
0
        protected void DrawMinuteHand(XGraphics gfx, XPen pen, XBrush brush)
        {
            XGraphicsState gs = gfx.Save();

            gfx.RotateTransform(360 * Time.Minute / 60 + 6 * Time.Second / 60);

            gfx.DrawPolygon(pen, brush,
                            new XPoint[] { new XPoint(0, 200), new XPoint(50, 0), new XPoint(0, -800), new XPoint(-50, 0) },
                            XFillMode.Winding);
            gfx.Restore(gs);
        }
Пример #9
0
        public void DrawPolygon(Rect bounds, Point[] points, DrawingStyle style)
        {
            OnRendering(bounds);

            bounds.Offset(0, -_offset);

            _g.TranslateTransform(bounds.Left, bounds.Top);

            if (style.HasFill)
            {
                _g.DrawPolygon(style.Fill.ToXBrush(bounds.Width, bounds.Height), points, XFillMode.Alternate);
            }

            if (style.HasStroke)
            {
                _g.DrawPolygon(new XPen(style.Stroke.ToXColor()), points);
            }

            _g.Restore();
        }
Пример #10
0
        void DrawHourHand(XGraphics gfx, XPen pen, XBrush brush)
        {
            XGraphicsState gs = gfx.Save();

            gfx.RotateTransform(360 * Time.Hour / 12 + 30 * Time.Minute / 60);
            gfx.DrawPolygon(pen, brush,
                            new XPoint[] { new XPoint(0, 150), new XPoint(100, 0),
                                           new XPoint(0, -600), new XPoint(-100, 0) },
                            XFillMode.Winding);
            gfx.Restore(gs);
        }
        /// <summary>
        /// Demonstrates the use of XGraphics.Transform.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            //gfx.Clear(this.properties.General.BackColor.Color);
            //base.RenderPage(gfx);

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200)));

            Matrix matrix = new Matrix();

            //matrix.Scale(2f, 1.5f);
            //matrix.Translate(-200, -400);
            //matrix.Rotate(45);
            //matrix.Translate(200, 400);
            //gfx.Transform = matrix;
            //gfx.TranslateTransform(50, 30);

#if true
            gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend);
            gfx.RotateTransform(15, XMatrixOrder.Prepend);
#else
            gfx.TranslateTransform(30, 40, XMatrixOrder.Append);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append);
            gfx.RotateTransform(15, XMatrixOrder.Append);
#endif
            bool id = matrix.IsIdentity;
            matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend);
            //matrix.Translate(30, -50);
            matrix.Rotate(15, MatrixOrder.Prepend);
            //Matrix mtx = gfx.Transform.ToGdipMatrix();
            //gfx.Transform = matrix;

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200)));
        }
        /// <summary>
        /// Draws the content of the area plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri          = (ChartRendererInfo)_rendererParms.RendererInfo;
            XRect             plotAreaRect = cri.plotAreaRendererInfo.Rect;

            if (plotAreaRect.IsEmpty)
            {
                return;
            }

            XGraphics      gfx   = _rendererParms.Graphics;
            XGraphicsState state = gfx.Save();

            //gfx.SetClip(plotAreaRect, XCombineMode.Intersect);
            gfx.IntersectClip(plotAreaRect);

            XMatrix matrix     = cri.plotAreaRendererInfo._matrix;
            double  xMajorTick = cri.xAxisRendererInfo.MajorTick;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                int      count  = sri._series.Elements.Count;
                XPoint[] points = new XPoint[count + 2];
                points[0] = new XPoint(xMajorTick / 2, 0);
                for (int idx = 0; idx < count; idx++)
                {
                    double pointValue = sri._series.Elements[idx].Value;
                    if (double.IsNaN(pointValue))
                    {
                        pointValue = 0;
                    }
                    points[idx + 1] = new XPoint(idx + xMajorTick / 2, pointValue);
                }
                points[count + 1] = new XPoint(count - 1 + xMajorTick / 2, 0);
                matrix.TransformPoints(points);
                gfx.DrawPolygon(sri.LineFormat, sri.FillFormat, points, XFillMode.Winding);
            }

            //gfx.ResetClip();
            gfx.Restore(state);
        }
Пример #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="img"></param>
        /// <param name="path"></param>
        /// <param name="exportItem"></param>
        /// <returns>byte[]</returns>
        private byte[] createPdf(Image img, MapExportItem exportItem, string fontName)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();

            page.Size        = GetPageSize(exportItem);
            page.Orientation = exportItem.orientation == "L" ? PdfSharp.PageOrientation.Landscape : PdfSharp.PageOrientation.Portrait;

            XGraphics gfx = XGraphics.FromPdfPage(page);

            int    scale      = int.Parse(exportItem.scale);
            double length     = (1.0 / scale);
            double unitLength = (length * 2.82e3);

            Dictionary <int, string> scaleBarTexts = new Dictionary <int, string>()
            {
                { 250, "25 m" },
                { 500, "50 m" },
                { 1000, "50 m" },
                { 2500, "100 m" },
                { 5000, "200 m" },
                { 10000, "500 m" },
                { 25000, "1 km" },
                { 50000, "2 km" },
                { 100000, "5 km" },
                { 250000, "10 km" }
            };

            Dictionary <int, int> scaleBarLengths = new Dictionary <int, int>()
            {
                { 250, 25 },
                { 500, 50 },
                { 1000, 50 },
                { 2500, 100 },
                { 5000, 200 },
                { 10000, 500 },
                { 25000, 1000 },
                { 50000, 2000 },
                { 100000, 5000 },
                { 250000, 10000 }
            };

            int    displayLength = GetDisplayLength(unitLength, scaleBarLengths, scale);
            string displayText   = GetDisplayText(unitLength, scaleBarTexts, scale);

            // adding support for different layouts
            int layout = ConfigurationManager.AppSettings["exportLayout"] != null?int.Parse(ConfigurationManager.AppSettings["exportLayout"]) : 1;

            if (layout == 1)//original layout
            {
                //origina code from github

                this.drawImage(gfx, img, 0, 0, page);

                List <string> copyrights = new List <string>();
                if (ConfigurationManager.AppSettings["exportCopyrightText"] != null)
                {
                    copyrights = ConfigurationManager.AppSettings["exportCopyrightText"].Split(',').ToList();
                }

                string infoText = String.Empty;
                if (ConfigurationManager.AppSettings["exportInfoText"] != null)
                {
                    infoText = ConfigurationManager.AppSettings["exportInfoText"];
                }

                int height = 45 + copyrights.Count * 10;

                XPoint[] points = new XPoint[]
                {
                    new XPoint(12, 12),
                    new XPoint(12, height),
                    new XPoint(55 + displayLength, height),
                    new XPoint(55 + displayLength, 12),
                    new XPoint(12, 12)
                };

                gfx.DrawPolygon(XBrushes.White, points, XFillMode.Winding);

                this.drawText(gfx, fontName, String.Format("Skala 1:{0}", exportItem.scale), 15, 25);
                gfx.DrawLine(XPens.Black, new XPoint(15, 32), new XPoint(15 + displayLength, 32));
                gfx.DrawLine(XPens.Black, new XPoint(15, 28), new XPoint(15, 36));
                gfx.DrawLine(XPens.Black, new XPoint(15 + displayLength, 28), new XPoint(15 + displayLength, 36));
                this.drawText(gfx, fontName, displayText, 20 + displayLength, 35);

                var y = (int)page.Height.Point - 15;

                this.drawText(gfx, fontName, infoText, 15, y);

                int i = 0;
                copyrights.ForEach(copyright =>
                {
                    int start = 50;
                    this.drawText(gfx, fontName, String.Format("© {0}", copyright), 15, start + i * 10);
                    i++;
                });

                XImage logo = XImage.FromFile(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "assets", "logo.png"));
                gfx.DrawImage(logo, (gfx.PageSize.Width - logo.PixelWidth / 2) - 12, 12, logo.PixelWidth / 2, logo.PixelHeight / 2);

                byte[] bytes;

                using (MemoryStream ms = new MemoryStream())
                {
                    document.Save(ms);
                    bytes = ReadFully(ms);
                }

                return(bytes);
            }
            else if (layout == 2)//new layout
            {
                // x and y 0 0(top left corner?)-> change
                this.drawImage(gfx, img, 33, 33, page);

                List <string> copyrights = new List <string>();
                if (ConfigurationManager.AppSettings["exportCopyrightText"] != null)
                {
                    copyrights = ConfigurationManager.AppSettings["exportCopyrightText"].Split(',').ToList();
                }

                string infoText = String.Empty;
                if (ConfigurationManager.AppSettings["exportInfoText"] != null)
                {
                    infoText = ConfigurationManager.AppSettings["exportInfoText"];
                }

                int height = 1;

                XPoint[] points = new XPoint[]
                {
                    new XPoint(12, 12),
                    new XPoint(12, height),
                    new XPoint(55 + displayLength, height),
                    new XPoint(55 + displayLength, 12),
                    new XPoint(12, 12)
                };

                gfx.DrawPolygon(XBrushes.White, points, XFillMode.Winding);
                // x y
                this.drawText(gfx, fontName, String.Format("Skala 1:{0}", exportItem.scale), 33, (int)page.Height.Point - 23, 8);
                gfx.DrawLine(XPens.Black, new XPoint(33, (int)page.Height.Point - 18), new XPoint(33 + displayLength, (int)page.Height.Point - 18));
                gfx.DrawLine(XPens.Black, new XPoint(33, (int)page.Height.Point - 15), new XPoint(33, (int)page.Height.Point - 21));
                gfx.DrawLine(XPens.Black, new XPoint(33 + displayLength / 2, (int)page.Height.Point - 17), new XPoint(33 + displayLength / 2, (int)page.Height.Point - 19));
                gfx.DrawLine(XPens.Black, new XPoint(33 + displayLength, (int)page.Height.Point - 15), new XPoint(33 + displayLength, (int)page.Height.Point - 21));
                this.drawText(gfx, fontName, displayText, 38 + displayLength, (int)page.Height.Point - 16, 8);

                var y = (int)page.Height.Point - 2;

                this.drawText(gfx, fontName, infoText, 33, y, 8);

                int i = 0;
                copyrights.ForEach(copyright =>
                {
                    int start = (int)page.Height.Point - 15;
                    this.drawText(gfx, fontName, String.Format("© {0}", copyright), (int)page.Width.Point - 100, start + i * 10, 8);
                    i++;
                });

                XImage logo = XImage.FromFile(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "assets", "logo.png"));
                gfx.DrawImage(logo, (gfx.PageSize.Width - logo.PixelWidth / 5) - 33, 3.5, logo.PixelWidth / 5, logo.PixelHeight / 5);

                byte[] bytes;

                using (MemoryStream ms = new MemoryStream())
                {
                    document.Save(ms);
                    bytes = ReadFully(ms);
                }

                return(bytes);
            }
            else if (layout == 3)
            {
                List <string> copyrights = new List <string>();
                if (ConfigurationManager.AppSettings["exportCopyrightText"] != null)
                {
                    copyrights = ConfigurationManager.AppSettings["exportCopyrightText"].Split(',').ToList();
                }

                string infoText = String.Empty;
                if (ConfigurationManager.AppSettings["exportInfoText"] != null)
                {
                    infoText = ConfigurationManager.AppSettings["exportInfoText"];
                }

                // Get logoimage
                XImage logo = XImage.FromFile(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "assets", "logo.png"));

                // Set positions, areas, brushes and pens
                XRect margins   = new XRect(33, 33, 33, 33);
                XSize stampSize = new XSize(200, 120);

                // Calculate positions and areas
                XRect  drawingArea        = new XRect(margins.Left, margins.Top, page.Width - (margins.Left + margins.Width), page.Height - (margins.Top + margins.Height));
                XRect  stampArea          = new XRect(new XPoint(drawingArea.Left + 15, drawingArea.Bottom - stampSize.Height - 15), stampSize);
                XRect  logoArea           = new XRect(new XPoint(stampArea.Left + 10, stampArea.Top + 10), new XPoint(stampArea.Right - 10, stampArea.Top + 50));
                XPoint signingLine        = new XPoint(stampArea.Left + 10, logoArea.Bottom + 30);
                XPoint copyrightPosition  = new XPoint(drawingArea.Right - 3, drawingArea.Bottom - 3);
                XPoint scalLegendPosition = new XPoint(stampArea.Left + 10, signingLine.Y + 20);

                double scaling;
                var    scalingY = logo.PointHeight / logoArea.Height;
                var    scalingX = logo.PointWidth / logoArea.Width;
                if (scalingX < scalingY)
                {
                    scaling = scalingX;
                }
                else
                {
                    scaling = scalingY;
                }

                // Pens, Brushes and colors
                XColor mainColor = XColor.FromArgb(0, 119, 188);
                XPen   thickPen  = new XPen(mainColor, 1);
                XPen   thinPen   = new XPen(mainColor, 0.5);

                // Draw map
                this.drawImage(gfx, img, drawingArea.Left, drawingArea.Top, page);

                // Put a border around map
                gfx.DrawRectangle(thickPen, drawingArea);

                // Draw a white "stamparea"
                gfx.DrawRectangle(thickPen, XBrushes.White, stampArea);
                // Draw logo
                gfx.DrawImage(logo, logoArea.Left, logoArea.Top, logo.PointWidth / scaling, logo.PointHeight / scaling);
                // Draw "signing line"

                gfx.DrawLine(thinPen, signingLine, new XPoint(stampArea.Right - 10, signingLine.Y));

                // Draw scale legend
                gfx.DrawLine(XPens.Black, new XPoint(scalLegendPosition.X, scalLegendPosition.Y), new XPoint(scalLegendPosition.X + displayLength, scalLegendPosition.Y));
                gfx.DrawLine(XPens.Black, new XPoint(scalLegendPosition.X, scalLegendPosition.Y - 3), new XPoint(scalLegendPosition.X, scalLegendPosition.Y + 3));
                gfx.DrawLine(XPens.Black, new XPoint(scalLegendPosition.X + displayLength / 2, scalLegendPosition.Y - 2), new XPoint(scalLegendPosition.X + displayLength / 2, scalLegendPosition.Y + 2));
                gfx.DrawLine(XPens.Black, new XPoint(scalLegendPosition.X + displayLength, scalLegendPosition.Y - 3), new XPoint(scalLegendPosition.X + displayLength, scalLegendPosition.Y + 3));
                XFont font = new XFont(fontName, 6);
                gfx.DrawString(String.Format("Skala 1:{0}", exportItem.scale), font, XBrushes.Black, new XRect(new XPoint(scalLegendPosition.X, scalLegendPosition.Y - 12), new XPoint(scalLegendPosition.X + displayLength, scalLegendPosition.Y - 2)), XStringFormats.TopLeft);
                gfx.DrawString(displayText, font, XBrushes.Black, (int)scalLegendPosition.X + displayLength + 10, (int)scalLegendPosition.Y + 2);

                // Draw infotext
                this.drawText(gfx, fontName, infoText, (int)stampArea.Left + 10, (int)stampArea.Bottom - 5, 5);

                // Draw copyright notes
                int i = 0;
                copyrights.ForEach(copyright =>
                {
                    if (i > 0)
                    {
                        copyrightPosition.Offset(0, -10);
                    }
                    gfx.DrawString(String.Format("© {0}", copyright), font, XBrushes.Black, copyrightPosition, XStringFormats.BottomRight);

                    i++;
                });


                byte[] bytes;

                using (MemoryStream ms = new MemoryStream())
                {
                    document.Save(ms);
                    bytes = ReadFully(ms);
                }

                return(bytes);
            }

            return(null);
        }
Пример #14
0
        public void DrawPentagon(XGraphics gfx)
        {
            XRect backgroundRect = new XRect(20, page.Height * 0.15, page.Width - 40, page.Height * 0.425);

            gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromKnownColor(XKnownColor.Gray)),
                                     backgroundRect,
                                     new XSize(40, 40));

            double c1 = Math.Cos((2 * Math.PI) / 5);
            double c2 = Math.Cos(Math.PI / 5);
            double s1 = Math.Sin((2 * Math.PI) / 5);
            double s2 = Math.Sin((4 * Math.PI) / 5);

            XPoint[] pentatPoints = new XPoint[5];

            XPoint center = new XPoint(page.Width * 0.5, page.Height * 0.425);
            XPoint top    = new XPoint(page.Width * 0.5, page.Height * 0.25);

            double lengthOfLine = Distance(top, center);
            XPoint bottomLeft   = new XPoint(center.X + (lengthOfLine * -s2), center.Y - (lengthOfLine * -c2));
            XPoint bottomRight  = new XPoint(center.X + (lengthOfLine * s2), center.Y - (lengthOfLine * -c2));
            XPoint topLeft      = new XPoint(center.X + (lengthOfLine * -s1), center.Y - (lengthOfLine * c1));
            XPoint topRight     = new XPoint(center.X + (lengthOfLine * s1), center.Y - (lengthOfLine * c1));

            pentatPoints[0] = top;
            pentatPoints[1] = topRight;
            pentatPoints[2] = bottomRight;
            pentatPoints[3] = bottomLeft;
            pentatPoints[4] = topLeft;

            gfx.DrawPolygon(XBrushes.DimGray, pentatPoints, XFillMode.Winding);

            XPen yellowPen    = new XPen(XColors.Yellow, 2.5);
            XPen greenPen     = new XPen(XColors.Green, 2.5);
            XPen perimeterPen = XPens.LightGray;
            XPen redPen       = new XPen(XColors.Red, 2.5);

            //center out
            gfx.DrawLine(greenPen, center, top);
            gfx.DrawLine(greenPen, center, bottomLeft);
            gfx.DrawLine(greenPen, center, bottomRight);
            gfx.DrawLine(greenPen, center, topLeft);
            gfx.DrawLine(greenPen, center, topRight);

            XBrush brush       = XBrushes.Black;
            XSize  size        = new XSize(50, 50);
            XSize  ellipseSize = new XSize(10, 10);
            //images
            XImage leftKneeImg    = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Left Knee Stability.png");
            XImage rightKneeImg   = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Right Knee Stability.png");
            XImage tibia_spineImg = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Tibia Spine Angle.png");
            XImage dosImg         = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Depth of Squat.png");
            XImage pelvicImg      = XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Pelvic Stability.png");

            //infoboxes
            DrawPentaInfoBox(gfx, top + new XPoint(-50, -75), tibia_spineImg, userParameters["Tibia / Spine Angle"]);
            DrawPentaInfoBox(gfx, topLeft + new XPoint(-100, -35), leftKneeImg, userParameters["LEFT Knee Stability"]);
            DrawPentaInfoBox(gfx, topRight + new XPoint(25, -35), rightKneeImg, userParameters["RIGHT Knee Stability"]);
            DrawPentaInfoBox(gfx, bottomRight + new XPoint(25, -60), pelvicImg, userParameters["Pelvic Stability"]);
            DrawPentaInfoBox(gfx, bottomLeft + new XPoint(-125, -60), dosImg, userParameters["Depth of Squat"]);

            //percentage Lines
            gfx.DrawString(0 + "%", new XFont("Arial", 10), XBrushes.Black, center + new XPoint(5, 0));
            for (int i = 10; i > 0; i--)
            {
                float increment = -i * 0.1f;

                gfx.DrawString((i * 10).ToString() + "%", new XFont("Arial", 8), XBrushes.Black, Interpolate(center, top, increment) + new XPoint(5, 0));

                gfx.DrawLine(perimeterPen, Interpolate(center, topLeft, increment), Interpolate(center, top, increment));
                gfx.DrawLine(perimeterPen, Interpolate(center, top, increment), Interpolate(center, topRight, increment));
                gfx.DrawLine(perimeterPen, Interpolate(center, topRight, increment), Interpolate(center, bottomRight, increment));
                gfx.DrawLine(perimeterPen, Interpolate(center, bottomRight, increment), Interpolate(center, bottomLeft, increment));
                gfx.DrawLine(perimeterPen, Interpolate(center, bottomLeft, increment), Interpolate(center, topLeft, increment));
            }

            XPoint centerTibia           = Interpolate(center, top, -userParameters["Tibia / Spine Angle"].Percentage);
            XPoint centerRightKnee       = Interpolate(center, topRight, -userParameters["RIGHT Knee Stability"].Percentage);
            XPoint centerPelvicStability = Interpolate(center, bottomRight, -userParameters["Pelvic Stability"].Percentage);
            XPoint centerDos             = Interpolate(center, bottomLeft, -userParameters["Depth of Squat"].Percentage);
            XPoint centerLeftKnee        = Interpolate(center, topLeft, -userParameters["LEFT Knee Stability"].Percentage);

            gfx.DrawLine(redPen, center, Interpolate(center, top, -userParameters["Tibia / Spine Angle"].RedVal));
            gfx.DrawLine(redPen, center, Interpolate(center, topRight, -userParameters["RIGHT Knee Stability"].RedVal));
            gfx.DrawLine(redPen, center, Interpolate(center, bottomRight, -userParameters["Pelvic Stability"].RedVal));
            gfx.DrawLine(redPen, center, Interpolate(center, bottomLeft, -userParameters["Depth of Squat"].RedVal));
            gfx.DrawLine(redPen, center, Interpolate(center, topLeft, -userParameters["LEFT Knee Stability"].RedVal));

            gfx.DrawPolygon(new XPen(XColor.FromArgb(1, 0, 255, 255)),
                            new XSolidBrush(XColor.FromArgb(127, 255, 255, 0)),
                            new XPoint[] { centerTibia, centerRightKnee, centerPelvicStability, centerDos, centerLeftKnee },
                            XFillMode.Alternate);
        }
Пример #15
0
 void IDrawingCanvas.DrawPolygon(PenEx pen, PointF[] points)
 {
     _graphics.DrawPolygon((Pen)pen, points.Select(p => PdfConverter.Convert(p)).ToArray());
 }
Пример #16
0
        /// <summary>
        /// Demonstrates the use of XGraphics.Transform.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            XGraphicsState state1, state2;

            base.RenderPage(gfx);

            state1 = gfx.Save(); // Level 1
            gfx.TranslateTransform(20, 50);
            gfx.DrawLine(XPens.Blue, 0, 0, 10, 10);
            gfx.Restore(state1);

            state1 = gfx.Save(); // Level 2
            gfx.TranslateTransform(220, 50);
            gfx.DrawLine(XPens.Blue, 0, 0, 10, 10);
            XGraphicsPath clipPath = new XGraphicsPath();

            clipPath.AddPie(0, 10, 150, 100, -50, 100);
            gfx.IntersectClip(clipPath);
            gfx.DrawRectangle(XBrushes.LightYellow, 0, 0, 1000, 1000);

            state2 = gfx.Save(); // Level 3
            gfx.ScaleTransform(10);
            gfx.DrawLine(XPens.Red, 1, 1, 10, 10);

            //gfx.ResetClip();
            gfx.Restore(state2); // Level 2

            gfx.DrawLine(XPens.Red, 1, 1, 10, 10);

            gfx.Restore(state1);

#if true_
            gfx.SetClip(new XRect(20, 20, 300, 500));
            gfx.DrawRectangle(XBrushes.Yellow, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

            gfx.SetClip(new XRect(100, 200, 300, 500), XCombineMode.Intersect);
            gfx.DrawRectangle(XBrushes.LightBlue, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200)));


            Matrix matrix = new Matrix();
            //matrix.Scale(2f, 1.5f);
            //matrix.Translate(-200, -400);
            //matrix.Rotate(45);
            //matrix.Translate(200, 400);
            //gfx.Transform = matrix;
            //gfx.TranslateTransform(50, 30);

#if true
            gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend);
            gfx.RotateTransform(15, XMatrixOrder.Prepend);
#else
            gfx.TranslateTransform(30, 40, XMatrixOrder.Append);
            gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append);
            gfx.RotateTransform(15, XMatrixOrder.Append);
#endif
            bool id = matrix.IsIdentity;
            matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend);
            //matrix.Translate(30, -50);
            matrix.Rotate(15, MatrixOrder.Prepend);
            Matrix mtx = gfx.Transform.ToMatrix();
            //gfx.Transform = matrix;

            gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
            gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200)));

            gfx.ResetClip();

            gfx.DrawLine(XPens.Red, 0, 0, 1000, 1000);

            gfx.DrawPolygon(XPens.SandyBrown, GetPentagram(75, new PointF(150, 200)));
#endif
        }
Пример #17
0
 public void DrawPolygon(Pen pen, Point[] points)
 {
     _graphics.DrawPolygon(PenToXPen(pen), points);
 }
Пример #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="img"></param>
        /// <param name="path"></param>
        /// <param name="exportItem"></param>
        /// <returns>byte[]</returns>
        private byte[] createPdf(Image img, MapExportItem exportItem, string fontName)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();

            page.Size        = GetPageSize(exportItem);
            page.Orientation = exportItem.orientation == "L" ? PdfSharp.PageOrientation.Landscape : PdfSharp.PageOrientation.Portrait;

            XGraphics gfx = XGraphics.FromPdfPage(page);

            int    scale      = int.Parse(exportItem.scale);
            double length     = (1.0 / scale);
            double unitLength = (length * 2.82e3);

            Dictionary <int, string> scaleBarTexts = new Dictionary <int, string>()
            {
                { 250, "25 m" },
                { 500, "50 m" },
                { 1000, "50 m" },
                { 2500, "100 m" },
                { 5000, "200 m" },
                { 10000, "500 m" },
                { 25000, "1 km" },
                { 50000, "2 km" },
                { 100000, "5 km" },
                { 250000, "10 km" }
            };

            Dictionary <int, int> scaleBarLengths = new Dictionary <int, int>()
            {
                { 250, 25 },
                { 500, 50 },
                { 1000, 50 },
                { 2500, 100 },
                { 5000, 200 },
                { 10000, 500 },
                { 25000, 1000 },
                { 50000, 2000 },
                { 100000, 5000 },
                { 250000, 10000 }
            };

            int    displayLength = GetDisplayLength(unitLength, scaleBarLengths, scale);
            string displayText   = GetDisplayText(unitLength, scaleBarTexts, scale);

            // adding support for different layouts
            int layout = ConfigurationManager.AppSettings["exportLayout"] != null?int.Parse(ConfigurationManager.AppSettings["exportLayout"]) : 1;

            if (layout == 1)//original layout
            {
                //origina code from github

                this.drawImage(gfx, img, 0, 0, page);

                List <string> copyrights = new List <string>();
                if (ConfigurationManager.AppSettings["exportCopyrightText"] != null)
                {
                    copyrights = ConfigurationManager.AppSettings["exportCopyrightText"].Split(',').ToList();
                }

                string infoText = String.Empty;
                if (ConfigurationManager.AppSettings["exportInfoText"] != null)
                {
                    infoText = ConfigurationManager.AppSettings["exportInfoText"];
                }

                int height = 45 + copyrights.Count * 10;

                XPoint[] points = new XPoint[]
                {
                    new XPoint(12, 12),
                    new XPoint(12, height),
                    new XPoint(55 + displayLength, height),
                    new XPoint(55 + displayLength, 12),
                    new XPoint(12, 12)
                };

                gfx.DrawPolygon(XBrushes.White, points, XFillMode.Winding);

                this.drawText(gfx, fontName, String.Format("Skala 1:{0}", exportItem.scale), 15, 25);
                gfx.DrawLine(XPens.Black, new XPoint(15, 32), new XPoint(15 + displayLength, 32));
                gfx.DrawLine(XPens.Black, new XPoint(15, 28), new XPoint(15, 36));
                gfx.DrawLine(XPens.Black, new XPoint(15 + displayLength, 28), new XPoint(15 + displayLength, 36));
                this.drawText(gfx, fontName, displayText, 20 + displayLength, 35);

                var y = (int)page.Height.Point - 15;

                this.drawText(gfx, fontName, infoText, 15, y);

                int i = 0;
                copyrights.ForEach(copyright =>
                {
                    int start = 50;
                    this.drawText(gfx, fontName, String.Format("© {0}", copyright), 15, start + i * 10);
                    i++;
                });

                XImage logo = XImage.FromFile(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "assets", "logo.png"));
                gfx.DrawImage(logo, (gfx.PageSize.Width - logo.PixelWidth / 2) - 12, 12, logo.PixelWidth / 2, logo.PixelHeight / 2);

                byte[] bytes;

                using (MemoryStream ms = new MemoryStream())
                {
                    document.Save(ms);
                    bytes = ReadFully(ms);
                }

                return(bytes);
            }
            else if (layout == 2)//new layout
            {
                // x and y 0 0(top left corner?)-> change
                this.drawImage(gfx, img, 33, 33, page);

                List <string> copyrights = new List <string>();
                if (ConfigurationManager.AppSettings["exportCopyrightText"] != null)
                {
                    copyrights = ConfigurationManager.AppSettings["exportCopyrightText"].Split(',').ToList();
                }

                string infoText = String.Empty;
                if (ConfigurationManager.AppSettings["exportInfoText"] != null)
                {
                    infoText = ConfigurationManager.AppSettings["exportInfoText"];
                }

                int height = 1;

                XPoint[] points = new XPoint[]
                {
                    new XPoint(12, 12),
                    new XPoint(12, height),
                    new XPoint(55 + displayLength, height),
                    new XPoint(55 + displayLength, 12),
                    new XPoint(12, 12)
                };

                gfx.DrawPolygon(XBrushes.White, points, XFillMode.Winding);
                // x y
                this.drawText(gfx, fontName, String.Format("Skala 1:{0}", exportItem.scale), 33, (int)page.Height.Point - 23, 8);
                gfx.DrawLine(XPens.Black, new XPoint(33, (int)page.Height.Point - 18), new XPoint(33 + displayLength, (int)page.Height.Point - 18));
                gfx.DrawLine(XPens.Black, new XPoint(33, (int)page.Height.Point - 15), new XPoint(33, (int)page.Height.Point - 21));
                gfx.DrawLine(XPens.Black, new XPoint(33 + displayLength / 2, (int)page.Height.Point - 17), new XPoint(33 + displayLength / 2, (int)page.Height.Point - 19));
                gfx.DrawLine(XPens.Black, new XPoint(33 + displayLength, (int)page.Height.Point - 15), new XPoint(33 + displayLength, (int)page.Height.Point - 21));
                this.drawText(gfx, fontName, displayText, 38 + displayLength, (int)page.Height.Point - 16, 8);

                var y = (int)page.Height.Point - 2;

                this.drawText(gfx, fontName, infoText, 33, y, 8);

                int i = 0;
                copyrights.ForEach(copyright =>
                {
                    int start = (int)page.Height.Point - 15;
                    this.drawText(gfx, fontName, String.Format("© {0}", copyright), (int)page.Width.Point - 100, start + i * 10, 8);
                    i++;
                });

                XImage logo = XImage.FromFile(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "assets", "logo.png"));
                gfx.DrawImage(logo, (gfx.PageSize.Width - logo.PixelWidth / 5) - 33, 3.5, logo.PixelWidth / 5, logo.PixelHeight / 5);

                byte[] bytes;

                using (MemoryStream ms = new MemoryStream())
                {
                    document.Save(ms);
                    bytes = ReadFully(ms);
                }

                return(bytes);
            }

            return(null);
        }
        ///<summary>The only instance of this command.</summary>
        ///<param name="doc" RhinoDoc></param>
        ///<param name="mode" Run mode></param>
        ///<returns>returns sucess if doc is successfully created </returns>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            #region set all the file parameters

            pdfOptionForm = new PDFOptionForm();
            Application.Run(pdfOptionForm);
            getSelectedOption = PDFOptionForm.optionsSelected;

            myUniqueFileName = string.Format(@"{0}" + ext, Guid.NewGuid());
            string logFilePath = Rhino.ApplicationSettings.FileSettings.WorkingFolder + "\\Log-" + DateTime.Now.GetHashCode().ToString() + ".txt";
            string curveType   = "C";
            try
            {
                string[] checkFileName = Rhino.ApplicationSettings.FileSettings.RecentlyOpenedFiles()[0].ToString().Split('\\');
                int      checklength   = checkFileName.Length;
                rhinoFile = Rhino.ApplicationSettings.FileSettings.RecentlyOpenedFiles()[0].ToString().Split('\\')[--checklength];
            }
            catch (FileNotFoundException fnf) { logFile(fnf.Message); }
            catch (IndexOutOfRangeException ioor) { logFile(ioor.Message); }

            string rhinoFileName = rhinoFile.Split('.')[0];
            string filename      = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + rhinoFileName + "-" + myUniqueFileName;

            #endregion

            Rhino.RhinoApp.RunScript("-_Save Enter", false);

            logFile("Process started for ---> " + rhinoFileName + "-" + myUniqueFileName);

            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();

            XGraphics gfx  = XGraphics.FromPdfPage(page);
            XFont     font = new XFont("Verdana", 20, XFontStyle.Bold);

            #region Check the selected curve
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = ObjectType.AnyObject;

            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("{0} objects are selected.", go.ObjectCount);

            #endregion

            // Process the list of objects
            logFile("Processing List of Object");

            #region set the paramenters for Xgraph to process shapes

            List <GeometryBase> geoList = new List <GeometryBase>();

            double minX, minY, maxX, maxY;
            minX = double.MaxValue;
            minY = double.MaxValue;

            maxX = double.MinValue;
            maxY = double.MinValue;

            List <Curve>      curveList      = new List <Curve>();
            List <TextEntity> textEntityList = new List <TextEntity>();

            List <Circle>   circleList = new List <Circle>();
            List <Polyline> polyList   = new List <Polyline>();
            Circle          circleCurve;
            Polyline        polygon;

            #endregion

            for (int i = 0; i < go.ObjectCount; i++)
            {
                // Check the type of the Object and process differently
                Curve curve = go.Object(i).Curve();

                if (go.Object(i).Curve().TryGetCircle(out circleCurve))
                {
                    circleList.Add(circleCurve);
                }
                if (go.Object(i).Curve().TryGetPolyline(out polygon))
                {
                    polyList.Add(polygon);
                }
                if (curve != null)
                {
                    curveList.Add(curve);
                }

                TextEntity te = go.Object(i).TextEntity();

                if (te != null)
                {
                    textEntityList.Add(te);
                }

                GeometryBase geo  = go.Object(i).Geometry();
                BoundingBox  bbox = geo.GetBoundingBox(Rhino.Geometry.Plane.WorldXY);

                if (bbox.Min.X < minX)
                {
                    minX = bbox.Min.X;
                }
                if (bbox.Min.Y < minY)
                {
                    minY = bbox.Min.Y;
                }
                if (bbox.Max.X > maxX)
                {
                    maxX = bbox.Max.X;
                }
                if (bbox.Max.Y > maxY)
                {
                    maxY = bbox.Max.Y;
                }

                geoList.Add(geo);
            }

            page.Height = maxY - minY;
            page.Width  = maxX - minX;


            foreach (GeometryBase g in geoList)
            {
                if (g.GetType().Equals(typeof(PolyCurve)))
                {
                    //System.Windows.Forms.MessageBox.Show("PolyCurve changed");
                    PolyCurve polyCurve = (PolyCurve)g;
                    curveType = "NC";
                    break;
                }
                else if (g.GetType().Equals(typeof(Curve)))
                {
                    System.Windows.Forms.MessageBox.Show("Curve");
                    Curve curve = (Curve)g;
                }
                else if (g.GetType().Equals(typeof(TextEntity)))
                {
                    System.Windows.Forms.MessageBox.Show("TextEntity");
                    TextEntity textEntity = (TextEntity)g;
                    curveType = "T";
                }
            }

            logFile("Checking the pattern");
            if (curveType.Equals("C") || curveType.Equals("T"))
            {
                logFile("Objects processed sucessfully");

                double x1, y1, width, height;

                logFile("Creating Circles on the PDF");
                //Loop to draw the circles
                foreach (Circle c in circleList)
                {
                    XPen pen = new XPen(XColors.Black, 0.5);
                    x1     = c.BoundingBox.Min.X - minX;
                    y1     = maxY - c.BoundingBox.Max.Y;
                    width  = c.BoundingBox.Max.X - c.BoundingBox.Min.X;
                    height = c.BoundingBox.Max.Y - c.BoundingBox.Min.Y;
                    gfx.DrawEllipse(XBrushes.Black, x1, y1, width, height);
                }

                //Loop used to draw rectangles
                foreach (Polyline p in polyList)
                {
                    XPen pen = new XPen(XColors.Black, 0.5);
                    x1     = p.BoundingBox.Min.X - minX;
                    y1     = maxY - p.BoundingBox.Max.Y;
                    width  = p.BoundingBox.Max.X - p.BoundingBox.Min.X;
                    height = p.BoundingBox.Max.Y - p.BoundingBox.Min.Y;
                    XPoint   p1     = new XPoint(x1, y1);
                    XPoint   p2     = new XPoint(x1 + width, y1);
                    XPoint   p3     = new XPoint(x1, y1 + height);
                    XPoint   p4     = new XPoint(x1 + width, y1 + height);
                    XRect    rect   = new XRect(x1, y1, width, height);
                    XPoint[] xPoint = new XPoint[] { p1, p2, p4, p3 };
                    //XPoint mid = new XPoint( (x1 + x1)/2);
                    XGraphicsState gs = gfx.Save();
                    gfx.RotateAtTransform(-45, p1);
                    gfx.DrawPolygon(pen, XBrushes.Black, xPoint, XFillMode.Alternate);
                    gfx.Restore(gs);
                }



                #region Print the PDF as per the option selected
                if (getSelectedOption.Equals('N'))
                {
                    logFile("Normal PDF feature was selected");
                    document.Save(filename);
                    logFile("Document saved successfully - " + Rhino.ApplicationSettings.FileSettings.WorkingFolder);
                }
                if (getSelectedOption.Equals('C'))
                {
                    logFile("Compressed PDF feature was selected");
                    CompressMyPdf(document);
                    string compressedFileName = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "C-" + rhinoFileName + "-" + myUniqueFileName;
                    document.Save(compressedFileName);
                }
                if (getSelectedOption.Equals('E'))
                {
                    logFile("Encrypted PDF feature was selected");
                    EncryptMyPdf(document);
                    string encryptPdf = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "E-" + rhinoFileName + "-" + myUniqueFileName;
                    document.Save(encryptPdf);
                }
                if (getSelectedOption.Equals('P'))
                {
                    logFile("Password Protection PDF feature was selected");
                    PasswordProtectMyPdf(document);
                    string passwordProtectPdf = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "PP-" + rhinoFileName + "-" + myUniqueFileName;
                    document.Save(passwordProtectPdf);
                }

                #endregion

                logFile("Document saved successfully - " + Rhino.ApplicationSettings.FileSettings.WorkingFolder);

                logFile("Panel perforated successfully. Check File --> " + rhinoFileName + "-" + myUniqueFileName);
                System.Windows.Forms.MessageBox.Show("         <----SUCCESS---->       " + Environment.NewLine + Environment.NewLine + " Pannels perforated Successfully. ");
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("                           ERROR!     " + Environment.NewLine + Environment.NewLine + "The curve you have selected contains some invalid shape." + Environment.NewLine + " Please select the appropriate patterns. ");
                logFile("Please select the appropriate pattern");
            }

            logFile("----------------- WAITING FOR THE NEXT PANEL PERFORATION ---------------------");

            return(Result.Success);
        }
Пример #20
0
        public string ExportPDF(MapExportItem exportItem)
        {
            string tempPath = "/Temp";
            string path     = HttpContext.Current.Server.MapPath(tempPath);
            string filename = Guid.NewGuid() + ".pdf";
            string localPdf = path + "\\" + filename;

            Image       img      = MapImageCreator.GetImage(exportItem);
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();

            page.Size        = exportItem.format == "A4" ? PdfSharp.PageSize.A4 : PdfSharp.PageSize.A3;
            page.Orientation = exportItem.orientation == "L" ? PdfSharp.PageOrientation.Landscape : PdfSharp.PageOrientation.Portrait;

            XGraphics gfx = XGraphics.FromPdfPage(page);

            int    scale      = int.Parse(exportItem.scale);
            double length     = (1.0 / scale);
            double unitLength = (length * 2.82e3);

            Dictionary <int, string> scaleBarTexts = new Dictionary <int, string>()
            {
                { 1000, "50 m" },
                { 2000, "100 m" },
                { 5000, "200 m" },
                { 10000, "500 m" },
                { 20000, "1 km" },
                { 50000, "2 km" },
                { 100000, "5 km" },
                { 250000, "10 km" }
            };

            Dictionary <int, int> scaleBarLengths = new Dictionary <int, int>()
            {
                { 1000, 50 },
                { 2000, 100 },
                { 5000, 200 },
                { 10000, 500 },
                { 20000, 1000 },
                { 50000, 2000 },
                { 100000, 5000 },
                { 250000, 10000 }
            };

            int    displayLength = (int)(unitLength * scaleBarLengths.FirstOrDefault(a => a.Key == scale).Value);
            string displayText   = scaleBarTexts.FirstOrDefault(a => a.Key == scale).Value;

            this.drawImage(gfx, img, 10, 10, page);

            Point[] points = new Point[] {
                new Point(12, 12),
                new Point(12, 55),
                new Point(55 + displayLength, 55),
                new Point(55 + displayLength, 12),
                new Point(12, 12)
            };

            gfx.DrawPolygon(XBrushes.White, points, XFillMode.Winding);

            gfx.DrawLine(XPens.Black, new Point(15, 47), new Point(15 + displayLength, 47));
            gfx.DrawLine(XPens.Black, new Point(15, 44), new Point(15, 50));
            gfx.DrawLine(XPens.Black, new Point(15 + displayLength, 44), new Point(15 + displayLength, 50));

            string copyright = ConfigurationManager.AppSettings["exportCopyrightText"];

            this.drawText(gfx, String.Format("© {0}", copyright), 15, 25);
            this.drawText(gfx, String.Format("Skala 1:{0}", exportItem.scale), 15, 40);
            this.drawText(gfx, displayText, 20 + displayLength, 50);

            XImage logo = XImage.FromFile(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "assets", "logo.png"));

            gfx.DrawImage(logo, gfx.PageSize.Width - 212, 12, 200, 67);

            document.Save(localPdf);

            return(tempPath + "/" + filename);
        }
Пример #21
0
        /// <summary>
        /// Draw a filled polygon consisting of straight lines connecting an ordered set of vertexes in sequence.
        /// </summary>
        /// <param name="vertexes">The vertexes of the polygon to draw.</param>
        public void DrawFilledPolygon(IEnumerable <UniPoint> vertexes)
        {
            XBrush brush = XBrushes.Black;

            _core.DrawPolygon(brush, vertexes.Select(v => new XPoint(v.X, v.Y)).ToArray(), XFillMode.Alternate);
        }
Пример #22
0
        public override void Draw(XGraphics graphics, Palette palette, DrawingContext context)
        {
            Random random = new Random(Name.GetHashCode());

            var topLeft     = InnerBounds.GetCorner(CompassPoint.NorthWest);
            var topRight    = InnerBounds.GetCorner(CompassPoint.NorthEast);
            var bottomLeft  = InnerBounds.GetCorner(CompassPoint.SouthWest);
            var bottomRight = InnerBounds.GetCorner(CompassPoint.SouthEast);

            var top    = new LineSegment(topLeft, topRight);
            var right  = new LineSegment(topRight, bottomRight);
            var bottom = new LineSegment(bottomRight, bottomLeft);
            var left   = new LineSegment(bottomLeft, topLeft);

            context.LinesDrawn.Add(top);
            context.LinesDrawn.Add(right);
            context.LinesDrawn.Add(bottom);
            context.LinesDrawn.Add(left);

            var brush = context.Selected ? palette.BorderBrush : palette.FillBrush;

            if (!Settings.DebugDisableLineRendering)
            {
                var path = palette.Path();
                Drawing.AddLine(path, top, random);
                Drawing.AddLine(path, right, random);
                Drawing.AddLine(path, bottom, random);
                Drawing.AddLine(path, left, random);
                graphics.DrawPath(brush, path);

                if (IsDark)
                {
                    var state = graphics.Save();
                    graphics.IntersectClip(path);
                    brush = context.Selected ? palette.FillBrush : palette.BorderBrush;
                    graphics.DrawPolygon(brush, new PointF[] { topRight.ToPointF(), new PointF(topRight.X - Settings.DarknessStripeSize, topRight.Y), new PointF(topRight.X, topRight.Y + Settings.DarknessStripeSize) }, XFillMode.Alternate);
                    graphics.Restore(state);
                }

                graphics.DrawPath(palette.BorderPen, path);
            }

            var font = Settings.LargeFont;

            brush = context.Selected ? palette.FillBrush : palette.LargeTextBrush;
            Rect textBounds = InnerBounds;

            textBounds.Inflate(-5, -5);

            if (textBounds.Width > 0 && textBounds.Height > 0)
            {
                m_name.Draw(graphics, font, brush, textBounds.Position, textBounds.Size, XStringFormats.Center);
            }

            var expandedBounds = InnerBounds;

            expandedBounds.Inflate(Settings.ObjectListOffsetFromRoom, Settings.ObjectListOffsetFromRoom);
            var drawnObjectList = false;

            font  = Settings.SmallFont;
            brush = palette.SmallTextBrush;

            if (!string.IsNullOrEmpty(Objects))
            {
                XStringFormat format = new XStringFormat();
                Vector        pos    = expandedBounds.GetCorner(m_objectsPosition);
                if (!Drawing.SetAlignmentFromCardinalOrOrdinalDirection(format, m_objectsPosition))
                {
                    // object list appears inside the room below its name
                    format.LineAlignment = XLineAlignment.Far;
                    format.Alignment     = XStringAlignment.Near;
                    //format.Trimming = StringTrimming.EllipsisCharacter;
                    //format.FormatFlags = StringFormatFlags.LineLimit;
                    var height = InnerBounds.Height / 2 - font.Height / 2;
                    var bounds = new Rect(InnerBounds.Left + Settings.ObjectListOffsetFromRoom, InnerBounds.Bottom - height, InnerBounds.Width - Settings.ObjectListOffsetFromRoom, height - Settings.ObjectListOffsetFromRoom);
                    brush = context.Selected ? palette.FillBrush : brush;
                    if (bounds.Width > 0 && bounds.Height > 0)
                    {
                        m_objects.Draw(graphics, font, brush, bounds.Position, bounds.Size, format);
                    }
                    drawnObjectList = true;
                }
                else if (m_objectsPosition == CompassPoint.North || m_objectsPosition == CompassPoint.South)
                {
                    pos.X += Settings.ObjectListOffsetFromRoom;
                }

                if (!drawnObjectList)
                {
                    m_objects.Draw(graphics, font, brush, pos, Vector.Zero, format);
                }
            }
        }
Пример #23
0
 public override void FillPolygon(PBrush b, PointF[] pts)
 {
     g.DrawPolygon(createBrush(b), pts, XFillMode.Alternate);
 }
Пример #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="img"></param>
        /// <param name="path"></param>
        /// <param name="exportItem"></param>
        /// <returns>byte[]</returns>
        private byte[] createPdf(Image img, MapExportItem exportItem)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();

            page.Size        = exportItem.format == "A4" ? PdfSharp.PageSize.A4 : PdfSharp.PageSize.A3;
            page.Orientation = exportItem.orientation == "L" ? PdfSharp.PageOrientation.Landscape : PdfSharp.PageOrientation.Portrait;

            XGraphics gfx = XGraphics.FromPdfPage(page);

            int    scale      = int.Parse(exportItem.scale);
            double length     = (1.0 / scale);
            double unitLength = (length * 2.82e3);

            Dictionary <int, string> scaleBarTexts = new Dictionary <int, string>()
            {
                { 250, "25 m" },
                { 500, "50 m" },
                { 1000, "50 m" },
                { 2500, "100 m" },
                { 5000, "200 m" },
                { 10000, "500 m" },
                { 25000, "1 km" },
                { 50000, "2 km" },
                { 100000, "5 km" },
                { 250000, "10 km" }
            };

            Dictionary <int, int> scaleBarLengths = new Dictionary <int, int>()
            {
                { 250, 25 },
                { 500, 50 },
                { 1000, 50 },
                { 2500, 100 },
                { 5000, 200 },
                { 10000, 500 },
                { 25000, 1000 },
                { 50000, 2000 },
                { 100000, 5000 },
                { 250000, 10000 }
            };

            int    displayLength = (int)(unitLength * scaleBarLengths.FirstOrDefault(a => a.Key == scale).Value);
            string displayText   = scaleBarTexts.FirstOrDefault(a => a.Key == scale).Value;

            this.drawImage(gfx, img, 0, 0, page);

            List <string> copyrights = new List <string>();

            if (ConfigurationManager.AppSettings["exportCopyrightText"] != null)
            {
                copyrights = ConfigurationManager.AppSettings["exportCopyrightText"].Split(',').ToList();
            }

            string infoText = String.Empty;

            if (ConfigurationManager.AppSettings["exportInfoText"] != null)
            {
                infoText = ConfigurationManager.AppSettings["exportInfoText"];
            }

            int height = 45 + copyrights.Count * 10;

            XPoint[] points = new XPoint[]
            {
                new XPoint(12, 12),
                new XPoint(12, height),
                new XPoint(55 + displayLength, height),
                new XPoint(55 + displayLength, 12),
                new XPoint(12, 12)
            };

            gfx.DrawPolygon(XBrushes.White, points, XFillMode.Winding);

            this.drawText(gfx, String.Format("Skala 1:{0}", exportItem.scale), 15, 25);
            gfx.DrawLine(XPens.Black, new XPoint(15, 32), new XPoint(15 + displayLength, 32));
            gfx.DrawLine(XPens.Black, new XPoint(15, 28), new XPoint(15, 36));
            gfx.DrawLine(XPens.Black, new XPoint(15 + displayLength, 28), new XPoint(15 + displayLength, 36));
            this.drawText(gfx, displayText, 20 + displayLength, 35);

            var y = (int)page.Height.Point - 15;

            this.drawText(gfx, infoText, 15, y);

            int i = 0;

            copyrights.ForEach(copyright =>
            {
                int start = 50;
                this.drawText(gfx, String.Format("© {0}", copyright), 15, start + i * 10);
                i++;
            });

            XImage logo = XImage.FromFile(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "assets", "logo.png"));

            gfx.DrawImage(logo, (gfx.PageSize.Width - logo.PixelWidth / 2) - 12, 12, logo.PixelWidth / 2, logo.PixelHeight / 2);

            byte[] bytes;

            using (MemoryStream ms = new MemoryStream()) {
                document.Save(ms);
                bytes = ReadFully(ms);
            }

            return(bytes);
        }