Exemplo n.º 1
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);
        }