/// <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)));
        }
Exemple #2
0
        /// <summary>
        /// Draws an image transformed.
        /// </summary>
        void DrawImageSheared(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawImage (sheared)");

            XImage image = XImage.FromFile(jpegSamplePath);

            const double dx = 250, dy = 140;

            //XMatrix matrix = gfx.Transform;
            //matrix.TranslatePrepend(dx / 2, dy / 2);
            //matrix.ScalePrepend(-0.7, 0.7);
            //matrix.ShearPrepend(-0.4, -0.3);
            //matrix.TranslatePrepend(-dx / 2, -dy / 2);
            //gfx.Transform = matrix;

            gfx.TranslateTransform(dx / 2, dy / 2);
            gfx.ScaleTransform(-0.7, 0.7);
            gfx.ShearTransform(-0.4, -0.3);
            gfx.TranslateTransform(-dx / 2, -dy / 2);

            double width  = image.PixelWidth * 72 / image.HorizontalResolution;
            double height = image.PixelHeight * 72 / image.HorizontalResolution;

            gfx.DrawImage(image, (dx - width) / 2, 0, width, height);

            EndBox(gfx);
        }
Exemple #3
0
        /// <summary>
        /// Draws a clock on a square page.
        /// Inspired by Charles Petzold's AnalogClock sample in
        /// 'Programming Microsoft Windows with C#'.
        /// </summary>
        void RenderClock(XGraphics gfx)
        {
            // Clocks should always look happy on hardcopies...
            //this.time = new DateTime(2005, 1, 1, 11, 6, 22, 500);

            XColor strokeColor = XColors.DarkBlue;
            XColor fillColor   = XColors.DarkOrange;

            XPen   pen   = new XPen(strokeColor, 5);
            XBrush brush = new XSolidBrush(fillColor);

            strokeColor.A = 0.8;
            fillColor.A   = 0.8;
            XPen   handPen   = new XPen(strokeColor, 5);
            XBrush handBrush = new XSolidBrush(fillColor);

            DrawText(gfx, pen, brush);

            double width  = gfx.PageSize.Width;
            double height = gfx.PageSize.Height;

            gfx.TranslateTransform(width / 2, height / 2);
            double scale = Math.Min(width, height);

            gfx.ScaleTransform(scale / 2000);

            DrawFace(gfx, pen, brush);
            DrawHourHand(gfx, handPen, handBrush);
            DrawMinuteHand(gfx, handPen, handBrush);
            DrawSecondHand(gfx, new XPen(XColors.Red, 7));
        }
Exemple #4
0
        bool StoreTempImage(string fileName)
        {
            try
            {
                const float resolution = 96;
                int         horzPixels = (int)(GetShapeWidth().Inch *resolution);
                int         vertPixels = (int)(GetShapeHeight().Inch *resolution);
                Bitmap      bmp        = new Bitmap(horzPixels, vertPixels);
#if true
                XGraphics gfx = XGraphics.CreateMeasureContext(new XSize(horzPixels, vertPixels), XGraphicsUnit.Point, XPageDirection.Downwards);
#else
#if GDI
                XGraphics gfx = XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels));
#endif
#if WPF
                // TODOWPF
                XGraphics gfx = null; //XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels));
#endif
#endif
                //REM: Should not be necessary:
                gfx.ScaleTransform(resolution / 72);
                //gfx.PageUnit = XGraphicsUnit.Point;

                DocumentRenderer renderer = new DocumentRenderer(_chart.Document);
                renderer.RenderObject(gfx, 0, 0, GetShapeWidth().Point, _chart);
                bmp.SetResolution(resolution, resolution);
                bmp.Save(fileName, ImageFormat.Png);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Exemple #5
0
        bool StoreTempImage(string fileName)
        {
            try
            {
                float  resolution = 300;
                int    horzPixels = (int)(GetShapeWidth().Inch *resolution);
                int    vertPixels = (int)(GetShapeHeight().Inch *resolution);
                Bitmap bmp        = new Bitmap(horzPixels, vertPixels);
                // Always renders to a Bitmap for embedding in output.
                XGraphics gfx = XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels));

                //REM: Should not be necessary:
                gfx.ScaleTransform(resolution / 72);
                //gfx.PageUnit = XGraphicsUnit.Point;

                DocumentRenderer renderer = new DocumentRenderer(this.chart.Document);
                renderer.RenderObject(gfx, 0, 0, GetShapeWidth().Point, this.chart);
                bmp.SetResolution(resolution, resolution);
                bmp.Save(fileName, ImageFormat.Png);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Exemple #6
0
        public void SavePDF(string path, ProgressBar pb = null)
        {
            if (pb != null)
            {
                pb.Maximum = Pages.Count * 2;
                pb.Value   = 0;
            }
            MemoryStream mstream = new MemoryStream();
            PdfDocument  doc     = new PdfDocument();

            for (int i = 0; i < Pages.Count; i++)
            {
                if (Pages[i].OriginalPage != null)
                {
                    PdfPage page = Pages[i].OriginalPage;
                    doc.AddPage(page);
                }
                else
                {
                    PdfPage page = doc.AddPage();
                    page.Width  = new XUnit(Pages[i].Format.Width, XGraphicsUnit.Millimeter);
                    page.Height = new XUnit(Pages[i].Format.Height, XGraphicsUnit.Millimeter);
                }
                if (pb != null)
                {
                    pb.Value++;
                }
            }
            doc.Save(mstream);

            PdfDocument doc2 = PdfReader.Open(mstream, PdfDocumentOpenMode.Modify);

            for (int i = 0; i < doc2.Pages.Count; i++)
            {
                XGraphics gfx = XGraphics.FromPdfPage(doc2.Pages[i]);
                SizeF     s   = Pages[i].Format.GetPixelSize();
                float     sX  = (float)doc2.Pages[i].Width.Point / s.Width;
                float     sY  = (float)doc2.Pages[i].Height.Point / s.Height;
                gfx.ScaleTransform(sX, sY);
                Renderer.PdfRenderer r = new Renderer.PdfRenderer(gfx);
                r.RenderSpecial = false;
                var pSize = Pages[i].Format.GetPixelSize();
                if (Pages[i].OriginalPage == null && Pages[i].BackgroundImage != null)
                {
                    r.DrawImage(Pages[i].BackgroundImage, new RectangleF(0, 0, pSize.Width, pSize.Height));
                }
                Pages[i].Draw(r);
                if (pb != null)
                {
                    pb.Value++;
                }
            }
            doc2.Save(path);

            mstream.Close();
        }
        void InitializeCoordinates(XGraphics gfx)
        {
            double width  = 600;
            double height = 800;

            gfx.TranslateTransform(width / 2, height / 2);

            //float fInches = Math.Min(width / gfx.DpiX, height / gfx.DpiY);
            double fInches = Math.Min(width, height);

            gfx.ScaleTransform(fInches * 1 / 2000);
        }
        private void DrawFormXObject(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "DrawImage (Form XObject)");
            XImage xImage = XImage.FromFile("../../../../../PDFs/SomeLayout.pdf");

            gfx.TranslateTransform(125.0, 70.0);
            gfx.ScaleTransform(0.35);
            gfx.TranslateTransform(-125.0, -70.0);
            double num  = (double)(xImage.PixelWidth * 72) / xImage.HorizontalResolution;
            double num2 = (double)(xImage.PixelHeight * 72) / xImage.HorizontalResolution;

            gfx.DrawImage(xImage, (250.0 - num) / 2.0, (140.0 - num2) / 2.0, num, num2);
            base.EndBox(gfx);
        }
        private void DrawImageSheared(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "DrawImage (sheared)");
            XImage xImage = XImage.FromFile("../../../../../../dev/XGraphicsLab/images/Z3.jpg");

            gfx.TranslateTransform(125.0, 70.0);
            gfx.ScaleTransform(-0.7, 0.7);
            gfx.ShearTransform(-0.4, -0.3);
            gfx.TranslateTransform(-125.0, -70.0);
            double num    = (double)(xImage.PixelWidth * 72) / xImage.HorizontalResolution;
            double height = (double)(xImage.PixelHeight * 72) / xImage.HorizontalResolution;

            gfx.DrawImage(xImage, (250.0 - num) / 2.0, 0.0, num, height);
            base.EndBox(gfx);
        }
        /// <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)));
        }
Exemple #11
0
        public override void SetTransformation(double translateX, double translateY, double rotate, double scaleX, double scaleY)
        {
            // Revert to original state, and immediately put this state on the stack again.
            XGraphics.Restore();
            XGraphics.Save();

            XGraphics.TranslateTransform(translateX, translateY);
            if (rotate != 0.0)
            {
                XGraphics.RotateTransform(rotate / System.Math.PI * 180.0);
            }
            if (scaleX != 1.0 || scaleY != 1.0)
            {
                XGraphics.ScaleTransform(scaleX, scaleY);
            }
        }
        /// <summary>
        /// Draws an image transformed.
        /// </summary>
        void DrawImageRotated(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawImage (rotated)");

            var image = XImage.FromFile(JpegSamplePath);

            const double dx = 250, dy = 140;

            gfx.TranslateTransform(dx / 2, dy / 2);
            gfx.ScaleTransform(0.7);
            gfx.RotateTransform(-25);
            gfx.TranslateTransform(-dx / 2, -dy / 2);
            var width  = image.PixelWidth * 72 / image.HorizontalResolution;
            var height = image.PixelHeight * 72 / image.HorizontalResolution;

            gfx.DrawImage(image, (dx - width) / 2, 0, width, height);

            EndBox(gfx);
        }
        /// <summary>
        /// Draws a form XObject (a page from an external PDF file).
        /// </summary>
        void DrawFormXObject(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawImage (Form XObject)");

            var image = XImage.FromFile(PdfSamplePath);

            const double dx = 250, dy = 140;

            gfx.TranslateTransform(dx / 2, dy / 2);
            gfx.ScaleTransform(0.35);
            gfx.TranslateTransform(-dx / 2, -dy / 2);

            var width  = image.PixelWidth * 72 / image.HorizontalResolution;
            var height = image.PixelHeight * 72 / image.HorizontalResolution;

            gfx.DrawImage(image, (dx - width) / 2, (dy - height) / 2, width, height);

            EndBox(gfx);
        }
Exemple #14
0
        public static void DrawChevron(XGraphics graphics, PointF pos, float angle, float size, Brush fillBrush)
        {
            if (m_chevronPath == null)
            {
                var apex        = new PointF(0.5f, 0);
                var leftCorner  = new PointF(-0.5f, 0.5f);
                var rightCorner = new PointF(-0.5f, -0.5f);
                m_chevronPath = new XGraphicsPath();
                m_chevronPath.AddLine(apex, rightCorner);
                m_chevronPath.AddLine(rightCorner, leftCorner);
                m_chevronPath.AddLine(leftCorner, apex);
            }
            var state = graphics.Save();

            graphics.TranslateTransform(pos.X, pos.Y);
            graphics.RotateTransform(angle);
            graphics.ScaleTransform(size, size);
            graphics.DrawPath(fillBrush, m_chevronPath);
            graphics.Restore(state);
        }
Exemple #15
0
        static void DrawFormXObject(XGraphics gfx, int number)
        {
            //this.backColor = XColors.LightSalmon;
            BeginBox(gfx, number, "DrawImage (Form XObject)");

            XImage image = XImage.FromFile(pdfSamplePath);

            const double dx = 250, dy = 140;

            gfx.TranslateTransform(dx / 2, dy / 2);
            gfx.ScaleTransform(0.35);
            gfx.TranslateTransform(-dx / 2, -dy / 2);

            double width  = image.PixelWidth * 72 / image.HorizontalResolution;
            double height = image.PixelHeight * 72 / image.HorizontalResolution;

            gfx.DrawImage(image, (dx - width) / 2, (dy - height) / 2, width, height);

            EndBox(gfx);
        }
        public void Paint(XGraphics graphics, RectangleF rect, MapOptions options, Color dotColor, XBrush labelBrush, XFont labelFont)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics");
            }

            Point pt = Astrometrics.LocationToCoordinates(Location);

            using (RenderUtil.SaveState(graphics))
            {
                graphics.SmoothingMode = XSmoothingMode.HighSpeed;
                graphics.TranslateTransform(pt.X, pt.Y);
                graphics.ScaleTransform(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY);

                const float radius = 3;

                XBrush brush = new XSolidBrush(dotColor);
                XPen   pen   = new XPen(dotColor);
                graphics.DrawEllipse(brush, -radius / 2, -radius / 2, radius, radius);

                graphics.SmoothingMode = XSmoothingMode.HighQuality;
                graphics.DrawEllipse(pen, -radius / 2, -radius / 2, radius, radius);

                XStringFormat format = (LabelBiasX == -1) ? RenderUtil.StringFormatTopRight :
                                       (LabelBiasX == 1) ? RenderUtil.StringFormatTopLeft : RenderUtil.StringFormatTopCenter;

                XSize  size = graphics.MeasureString(Name, labelFont);
                XPoint pos  = new XPoint(0, 0);

                //pos.X += ( LabelBiasX * radius / 2 ) + ( -size.Width  * ( 1 - LabelBiasX ) / 2.0f );
                pos.Y += (LabelBiasY * radius / 2) + (-size.Height * (1 - LabelBiasY) / 2.0f);
                pos.X += (LabelBiasX * radius / 2);
                //pos.Y += ( LabelBiasY * radius / 2 );

                graphics.DrawString(Name, labelFont, labelBrush, pos.X, pos.Y, format);
            }
        }
Exemple #17
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            #region image Sample
            string      filename = "HelloWorld.pdf";
            PdfDocument document = new PdfDocument();
            string      path     = "H:/haixt111/图片/1Rose (RGB 8).tif";
            //// Create an empty page
            //Image image = Image.FromFile(path);
            PDFSharpImages PDFImage = new PDFSharpImages(document);
            //PDFImage.DrawImage(document, image,10, 10);
            PdfPage page = document.AddPage();
            page.Size = PdfSharp.PageSize.A4;

            //    ////// Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            XImage       image = XImage.FromFile(path);
            const double dx = 4, dy = 4;
            gfx.TranslateTransform(dx / 2, dy / 2);
            //gfx.ScaleTransform(0.35);
            gfx.ScaleTransform(0.3);
            gfx.TranslateTransform(-dx / 2, -dy / 2);

            double width  = image.PixelWidth * 30 / image.HorizontalResolution;
            double height = image.PixelHeight * 30 / image.HorizontalResolution;

            gfx.DrawImage(image, (dx - width) / 2, (dy - height) / 2, width, height);

            //PDFImage.DrawImage(gfx, path);
            document.Save(filename);
            //// ...and start a viewer.
            Process.Start(filename);
            #endregion
        }
Exemple #18
0
 public void ScaleTransform(float sx, float sy)
 {
     _transform.Scale(sx, sy);
     _graphics.ScaleTransform(sx, sy);
 }
        /// <summary>
        /// Demonstrates the use of XLinearGradientBrush.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            XRect rect;
            XLinearGradientBrush brush;
            Graphics             grfx = gfx.Internals.Graphics;

            XLinearGradientBrush brush2 =
                new XLinearGradientBrush(
                    new XPoint(100, 100),
                    new XPoint(300, 300),
                    XColors.DarkRed, XColors.Yellow);

            //gfx.FillRectangle(brush, 0, 0, 600, 600);
            //gfx.TranslateTransform(35, 200);
            //gfx.RotateTransform(17);

            rect  = new XRect(20, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.DarkRed, XColors.Yellow, XLinearGradientMode.Horizontal);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(140, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.DarkRed, XColors.Yellow, XLinearGradientMode.Vertical);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(260, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.DarkRed, XColors.Yellow, XLinearGradientMode.ForwardDiagonal);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(380, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.DarkRed, XColors.Yellow, XLinearGradientMode.BackwardDiagonal);
            gfx.DrawRectangle(XPens.Red, brush, rect);


            gfx.TranslateTransform(80, 250);
            gfx.ScaleTransform(1.1);
            gfx.RotateTransform(20);

            rect  = new XRect(20, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.Orange, XColors.DarkBlue, XLinearGradientMode.Horizontal);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(140, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.Orange, XColors.DarkBlue, XLinearGradientMode.Vertical);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(260, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.Orange, XColors.DarkBlue, XLinearGradientMode.ForwardDiagonal);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(380, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.Orange, XColors.DarkBlue, XLinearGradientMode.BackwardDiagonal);
            gfx.DrawRectangle(XPens.Red, brush, rect);
        }
Exemple #20
0
        private static void DrawLayers(XGraphics gfx, IatRunConfiguration config, ComponentLayer componentLayer, double scaleFactor, IPcbLayer overlayLayer, IPcbLayer pasteLayer, IPcbLayer mechanicalLayer, double maxExtensionX, double maxExtensionY, Dictionary <string, List <Component> > componentGroup, List <XColor> colorsFromConfiguration)
        {
            var state = gfx.Save();

            if (componentLayer == ComponentLayer.Top)
            {
                gfx.ScaleTransform(1, -1);
                gfx.TranslateTransform(1, -maxExtensionY);
                gfx.TranslateTransform(gfx.PdfPage.Width * 0.05, -gfx.PdfPage.Height * 0.05);
                gfx.TranslateTransform(1, -maxExtensionY * scaleFactor + maxExtensionY);
                gfx.ScaleTransform(scaleFactor);
            }
            else
            {
                gfx.ScaleTransform(-1, -1);
                gfx.TranslateTransform(-maxExtensionX, -maxExtensionY);
                gfx.TranslateTransform(-gfx.PdfPage.Width * 0.05, -gfx.PdfPage.Height * 0.05);
                gfx.TranslateTransform(-maxExtensionX * scaleFactor + maxExtensionX, -maxExtensionY * scaleFactor + maxExtensionY);
                gfx.ScaleTransform(scaleFactor);
            }

            XPen xpenPasteLayer = new XPen(XColors.Gray)
            {
                Width    = 0.1,
                LineCap  = XLineCap.Round,
                LineJoin = XLineJoin.Round
            };

            foreach (PcbShape s in pasteLayer.PcbShapes)
            {
                DrawElement(gfx, s, xpenPasteLayer);
            }

            XPen xpenOverlayLayer = new XPen(XColors.Black)
            {
                Width    = 0.1,
                LineCap  = XLineCap.Round,
                LineJoin = XLineJoin.Round
            };

            foreach (PcbShape s in overlayLayer.PcbShapes)
            {
                DrawElement(gfx, s, xpenOverlayLayer);
            }

            XPen xpenMechanicalOutlineLayer = new XPen(XColors.DarkRed)
            {
                Width    = 0.1,
                LineCap  = XLineCap.Round,
                LineJoin = XLineJoin.Round
            };

            foreach (PcbShape s in mechanicalLayer.PcbShapes)
            {
                DrawElement(gfx, s, xpenMechanicalOutlineLayer);
            }

            int nrLines = config.OutputSettings.ComponentColors.Count;

            for (int lineIndex = 0; lineIndex < Math.Min(nrLines, componentGroup.Count); lineIndex++)
            {
                XPen xpenComponent = new XPen(colorsFromConfiguration[lineIndex])
                {
                    Width    = 0.1,
                    LineCap  = XLineCap.Round,
                    LineJoin = XLineJoin.Round
                };
                XBrush xb = new XSolidBrush(colorsFromConfiguration[lineIndex]);

                double width          = 0.5;
                double dotScaleFactor = (double)config.OutputSettings.DotScaleFactor;
                foreach (Component c in componentGroup.Values.ElementAt(lineIndex))
                {
                    double posX    = (double)c.PositionX - width * dotScaleFactor / 2;
                    double posY    = (double)c.PositionY - width * dotScaleFactor / 2;
                    double widthXY = width * dotScaleFactor;
                    gfx.DrawRectangle(xpenComponent, xb, posX, posY, widthXY, widthXY);
                }
            }

            gfx.Restore(state);
        }
Exemple #21
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
        }
Exemple #22
0
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            PointF[] origins = new PointF[]
            {
                new PointF(100, 200), new PointF(300, 200),
                new PointF(100, 400), new PointF(300, 400),
                new PointF(100, 600), new PointF(350, 600),
            };
            PointF             origin;
            XGraphicsContainer container;
            float length = 100;

            // Not transformed
            origin = origins[0];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, origin);

            // Translation
            container = gfx.BeginContainer(new RectangleF(10, 10, 1, 1), new RectangleF(0, 0, 1, 1), XGraphicsUnit.Point);
            origin    = origins[1];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(20, -30);
            DrawAxes(gfx, XPens.DarkGray, origin, length);
            gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, origin);
            gfx.EndContainer(container);

            // Scaling
            container = gfx.BeginContainer(new RectangleF(0, 0, 1, 1), new RectangleF(0, 0, 1, 1), XGraphicsUnit.Point);
            origin    = origins[2];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.ScaleTransform(1.3f, 1.5f);
            DrawAxes(gfx, XPens.DarkGray, new PointF(), length);
            gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, 0, 0);
            gfx.EndContainer(container);

            // Rotation
            container = gfx.BeginContainer(new RectangleF(0, 0, 1, 1), new RectangleF(0, 0, 1, 1), XGraphicsUnit.Point);
            origin    = origins[3];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.RotateTransform(-45);
            DrawAxes(gfx, XPens.DarkGray, new PointF(), length);
            gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, 0, 0);
            gfx.EndContainer(container);

            // Skewing (or shearing)
            container = gfx.BeginContainer(new RectangleF(0, 0, 1, 1), new RectangleF(0, 0, 1, 1), XGraphicsUnit.Point);
            origin    = origins[4];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.MultiplyTransform(new Matrix(1, -0.3f, -0.4f, 1, 0, 0));
            DrawAxes(gfx, XPens.DarkGray, new PointF(), length);
            gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, 0, 0);
            gfx.EndContainer(container);

            // Reflection
            container = gfx.BeginContainer(new RectangleF(0, 0, 1, 1), new RectangleF(0, 0, 1, 1), XGraphicsUnit.Point);
            origin    = origins[5];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.MultiplyTransform(new Matrix(-1, 0, 0, -1, 0, 0));
            DrawAxes(gfx, XPens.DarkGray, new PointF(), length);
            gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, 0, 0);
            gfx.EndContainer(container);
        }
Exemple #23
0
        public override void RenderPage(XGraphics gfx)
        {
            //base.RenderPage(gfx);

            XPoint[] origins = new XPoint[]
            {
                new XPoint(100, 200), new XPoint(300, 200),
                new XPoint(100, 400), new XPoint(300, 400),
                new XPoint(100, 600), new XPoint(350, 600),
            };

            XPoint         origin;
            XGraphicsState state;
            float          length = 100;

            // Not transformed
            origin = origins[0];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, origin);

            // Translation
            state  = gfx.Save();
            origin = origins[1];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(20, -30);
            DrawAxes(gfx, XPens.DarkGray, origin, length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, origin);
            gfx.Restore(state);

#if true
            // Scaling
            state  = gfx.Save();
            origin = origins[2];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.ScaleTransform(1.3, 1.5);
            DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0, 0);
            gfx.Restore(state);

            // Rotation
            state  = gfx.Save();
            origin = origins[3];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.RotateTransform(-45);
            DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0, 0);
            gfx.Restore(state);

            // Skewing (or shearing)
            state  = gfx.Save();
            origin = origins[4];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.MultiplyTransform(new Matrix(1, -0.3f, -0.4f, 1, 0, 0));
            DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0, 0);
            gfx.Restore(state);

            // Reflection
            state  = gfx.Save();
            origin = origins[5];
            DrawAxes(gfx, XPens.Black, origin, length);
            gfx.TranslateTransform(origin.X, origin.Y);
            gfx.MultiplyTransform(new Matrix(-1, 0, 0, -1, 0, 0));
            DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
            gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0, 0);
            gfx.Restore(state);
#endif
        }