Example #1
0
        Control MetricsPreview()
        {
            metricsPreview = new Drawable {
                Size = new Size(200, 100)
            };
            metricsPreview.Paint += (sender, pe) => {
                var size  = pe.Graphics.MeasureString(selectedFont, preview.Text);
                var scale = this.ParentWindow.Screen.Scale;

                var ypos = Math.Max(0, (selectedFont.Ascent * scale) - size.Height);
                ypos += Math.Max(0, (metricsPreview.Size.Height - (selectedFont.LineHeight * scale)) / 2);

                var baseline = ypos + (selectedFont.Baseline * scale);
                pe.Graphics.DrawLine(Pens.Black(), 0, baseline, 200, baseline);

                pe.Graphics.DrawText(selectedFont, Colors.Black, 0, ypos, preview.Text);

                var ascender = baseline - selectedFont.Ascent * scale;
                pe.Graphics.DrawLine(Pens.Blue(), 0, ascender, 200, ascender);

                var descender = baseline + selectedFont.Descent * scale;
                pe.Graphics.DrawLine(Pens.Red(), 0, descender, 200, descender);

                var xheight = baseline - selectedFont.XHeight * scale;
                pe.Graphics.DrawLine(Pens.Green(), 0, xheight, 200, xheight);

                var lineheight = ypos + selectedFont.LineHeight * scale;
                pe.Graphics.DrawLine(Pens.Orange(), 0, lineheight, 200, lineheight);
            };
            return(metricsPreview);
        }
Example #2
0
        public static void Draw(Graphics graphics)
        {
            var generator = graphics.Generator;
            var image     = TestIcons.TestImage(generator);
            // lines
            var whitePen = Pens.White(generator);

            graphics.DrawLine(whitePen, 1, 1, 99, 99);
            graphics.DrawLine(whitePen, 50, 1, 50, 99);
            graphics.DrawLine(whitePen, 1, 51, 99, 51);

            graphics.DrawRectangle(Pens.White(generator), 101, 1, 100, 100);
            graphics.DrawRectangle(Pens.White(generator), 101, 1, 10, 10);

            graphics.DrawEllipse(Pens.Green(generator), 101, 1, 100, 100);

            graphics.DrawPolygon(Pens.White(generator), new PointF(203, 1), new PointF(253, 51), new Point(203, 101), new PointF(203, 1), new PointF(253, 1), new PointF(253, 101), new PointF(203, 101));

            var rect = new RectangleF(255, 1, 100, 100);

            graphics.DrawArc(Pens.LightGreen(generator), rect, 180, 90);
            graphics.DrawArc(Pens.SkyBlue(generator), rect, 0, 90);
            rect.Inflate(-15, 0);
            graphics.DrawArc(Pens.FloralWhite(generator), rect, -45, 90);
            rect.Inflate(-5, -20);
            graphics.DrawArc(Pens.SlateGray(generator), rect, -45, 270);
            rect.Inflate(-10, -10);
            graphics.DrawArc(Pens.SteelBlue(generator), rect, 180 + 45, 270);

            graphics.DrawImage(image, 100, 1, 100, 100);

            graphics.DrawText(Fonts.Sans(12 * graphics.PointsPerPixel, generator: generator), Colors.White, 0, 104, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");

            // filled
            graphics.FillRectangle(Brushes.White(generator), 101, 120, 100, 100);
            graphics.FillRectangle(Brushes.Gray(generator), 101, 120, 10, 10);

            graphics.FillEllipse(Brushes.Green(generator), 101, 120, 100, 100);

            graphics.FillPolygon(Brushes.White(generator), new PointF(202, 120), new PointF(252, 170), new Point(202, 220), new PointF(202, 120));

            rect = new RectangleF(255, 120, 100, 100);
            graphics.FillPie(Brushes.LightGreen(generator), rect, 180, 90);
            graphics.FillPie(Brushes.SkyBlue(generator), rect, 0, 90);
            rect.Inflate(-15, 0);
            graphics.FillPie(Brushes.FloralWhite(generator), rect, -45, 90);
            rect.Inflate(-5, -20);
            graphics.FillPie(Brushes.SlateGray(generator), rect, -45, 270);
            rect.Inflate(-10, -10);
            graphics.FillPie(Brushes.SteelBlue(generator), rect, 180 + 45, 270);


            graphics.DrawImage(image, 101, 120, 100, 100);
        }
Example #3
0
        PrintDocument GetPrintDocument()
        {
            var document = new PrintDocument();

            document.PrintSettings = settings;
            var font      = Fonts.Serif(16);
            var printTime = DateTime.Now;

            document.PrintPage += (sender, e) => {
                Size pageSize = Size.Round(e.PageSize);

                // draw a border around the printable area
                var rect = new Rectangle(pageSize);
                rect.Inflate(-1, -1);
                e.Graphics.DrawRectangle(Pens.Silver(), rect);

                // draw title
                e.Graphics.DrawText(font, Colors.Black, new Point(50, 20), document.Name);

                // draw page number
                var text     = string.Format("page {0} of {1}", e.CurrentPage + 1, document.PageCount);
                var textSize = Size.Round(e.Graphics.MeasureString(font, text));
                e.Graphics.DrawText(font, Colors.Black, new Point(pageSize.Width - textSize.Width - 50, 20), text);

                // draw date
                text     = string.Format("Printed on {0:f}", printTime);
                textSize = Size.Round(e.Graphics.MeasureString(font, text));
                e.Graphics.DrawText(font, Colors.Black, new Point(pageSize.Width - textSize.Width - 50, pageSize.Height - textSize.Height - 20), text);

                // draw some rectangles
                switch (e.CurrentPage)
                {
                case 0:
                    e.Graphics.DrawRectangle(Pens.Blue(), new Rectangle(50, 50, 100, 100));
                    e.Graphics.DrawRectangle(Pens.Green(), new Rectangle(new Point(pageSize) - new Size(150, 150), new Size(100, 100)));
                    break;

                case 1:
                    e.Graphics.DrawRectangle(Pens.Blue(), new Rectangle(pageSize.Width - 150, 50, 100, 100));
                    e.Graphics.DrawRectangle(Pens.Green(), new Rectangle(50, pageSize.Height - 150, 100, 100));
                    break;
                }
            };
            document.Name      = "Name Of Document";
            document.PageCount = 2;
            return(document);
        }
Example #4
0
        Control MetricsPreview()
        {
            metricsPreview = new Drawable {
                Size = new Size(200, 100)
            };
            metricsPreview.Paint += (sender, pe) =>
            {
                var width = metricsPreview.Size.Width;
                pe.Graphics.PixelOffsetMode = PixelOffsetMode.Half;

                pe.Graphics.DrawRectangle(Colors.Black, new RectangleF(metricsPreview.Size));

                var size  = pe.Graphics.MeasureString(selectedFont, preview.Text);
                var scale = ParentWindow.Screen.Scale;

                var ypos = Math.Max(0, (metricsPreview.Size.Height - size.Height) / 2);

                pe.Graphics.FillRectangle(Brushes.GhostWhite(), new RectangleF(new PointF(0, ypos), size));

                pe.Graphics.DrawText(selectedFont, Colors.Black, 0, ypos, preview.Text);

                var baseline = ypos + selectedFont.Baseline * scale;
                pe.Graphics.DrawLine(Pens.Black(), 0, baseline, width, baseline);

                var ascender = baseline - selectedFont.Ascent * scale;
                pe.Graphics.DrawLine(Pens.Blue(), 0, ascender, width, ascender);

                var descender = baseline + selectedFont.Descent * scale;
                pe.Graphics.DrawLine(Pens.Red(), 0, descender, width, descender);

                var xheight = baseline - selectedFont.XHeight * scale;
                pe.Graphics.DrawLine(Pens.Green(), 0, xheight, width, xheight);

                var lineheight = ypos + selectedFont.LineHeight * scale;
                pe.Graphics.DrawLine(Pens.Orange(), 0, lineheight, width, lineheight);
            };
            return(metricsPreview);
        }