Esempio n. 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);
        }
Esempio n. 2
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);
        }