Exemplo n.º 1
0
        private static void DrawEllipses(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush    = new PdfBrush();
            PdfPen   blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen   redPen   = new PdfPen(PdfRgbColor.Red, 1);

            PdfRgbColor randomPenColor   = new PdfRgbColor();
            PdfPen      randomPen        = new PdfPen(randomPenColor, 1);
            PdfRgbColor randomBrushColor = new PdfRgbColor();
            PdfBrush    randomBrush      = new PdfBrush(randomBrushColor);

            page.Graphics.DrawString("Ellipses", titleFont, brush, 20, 50);

            page.Graphics.DrawLine(blackPen, 20, 150, 300, 150);
            page.Graphics.DrawLine(blackPen, 80, 70, 80, 350);
            page.Graphics.DrawEllipse(redPen, 80, 150, 180, 100);

            page.Graphics.DrawLine(blackPen, 320, 150, 600, 150);
            page.Graphics.DrawLine(blackPen, 380, 70, 380, 350);
            page.Graphics.DrawEllipse(redPen, 380, 150, 180, 100, 30);

            page.Graphics.DrawString("Random ellipses clipped to view", sectionFont, brush, 20, 385);
            PdfPath ellipsePath = new PdfPath();

            ellipsePath.AddEllipse(20, 400, 570, 300);

            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(ellipsePath);

            Random rnd = new Random();

            for (int i = 0; i < 100; i++)
            {
                randomPenColor.R = (byte)rnd.Next(256);
                randomPenColor.G = (byte)rnd.Next(256);
                randomPenColor.B = (byte)rnd.Next(256);

                randomBrushColor.R = (byte)rnd.Next(256);
                randomBrushColor.G = (byte)rnd.Next(256);
                randomBrushColor.B = (byte)rnd.Next(256);

                int    mode        = rnd.Next(3);
                double left        = rnd.NextDouble() * page.Width;
                double top         = 380 + rnd.NextDouble() * 350;
                double width       = rnd.NextDouble() * page.Width;
                double height      = rnd.NextDouble() * 250;
                double orientation = rnd.Next(360);
                switch (mode)
                {
                case 0:
                    // Stroke ellipse outline
                    page.Graphics.DrawEllipse(randomPen, left, top, width, height, orientation);
                    break;

                case 1:
                    // Fill ellipse interior
                    page.Graphics.DrawEllipse(randomBrush, left, top, width, height, orientation);
                    break;

                case 2:
                    // Stroke and fill ellipse
                    page.Graphics.DrawEllipse(randomPen, randomBrush, left, top, width, height, orientation);
                    break;
                }
            }

            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawPath(blackPen, ellipsePath);

            page.Graphics.CompressAndClose();
        }
Exemplo n.º 2
0
        private static void DrawEllipses(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1);

            PdfRgbColor randomPenColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomPenColor, 1);
            PdfRgbColor randomBrushColor = new PdfRgbColor();
            PdfBrush randomBrush = new PdfBrush(randomBrushColor);

            page.Graphics.DrawString("Ellipses", titleFont, brush, 20, 50);

            page.Graphics.DrawLine(blackPen, 20, 150, 300, 150);
            page.Graphics.DrawLine(blackPen, 80, 70, 80, 350);
            page.Graphics.DrawEllipse(redPen, 80, 150, 180, 100);

            page.Graphics.DrawLine(blackPen, 320, 150, 600, 150);
            page.Graphics.DrawLine(blackPen, 380, 70, 380, 350);
            page.Graphics.DrawEllipse(redPen, 380, 150, 180, 100, 30);

            page.Graphics.DrawString("Random ellipses clipped to view", sectionFont, brush, 20, 385);
            PdfPath ellipsePath = new PdfPath();
            ellipsePath.AddEllipse(20, 400, 570, 300);

            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(ellipsePath);

            Random rnd = new Random();
            for (int i = 0; i < 100; i++)
            {
                randomPenColor.R = (byte)rnd.Next(256);
                randomPenColor.G = (byte)rnd.Next(256);
                randomPenColor.B = (byte)rnd.Next(256);

                randomBrushColor.R = (byte)rnd.Next(256);
                randomBrushColor.G = (byte)rnd.Next(256);
                randomBrushColor.B = (byte)rnd.Next(256);

                int mode = rnd.Next(3);
                double left = rnd.NextDouble() * page.Width;
                double top = 380 + rnd.NextDouble() * 350;
                double width = rnd.NextDouble() * page.Width;
                double height = rnd.NextDouble() * 250;
                double orientation = rnd.Next(360);
                switch (mode)
                {
                    case 0:
                        // Stroke ellipse outline
                        page.Graphics.DrawEllipse(randomPen, left, top, width, height, orientation);
                        break;
                    case 1:
                        // Fill ellipse interior
                        page.Graphics.DrawEllipse(randomBrush, left, top, width, height, orientation);
                        break;
                    case 2:
                        // Stroke and fill ellipse
                        page.Graphics.DrawEllipse(randomPen, randomBrush, left, top, width, height, orientation);
                        break;
                }
            }

            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawPath(blackPen, ellipsePath);

            page.Graphics.CompressAndClose();
        }