Esempio n. 1
0
        public void Test_LettersDontRenderAsRectangles_SerifFont()
        {
            // this test ensures letters don't render as rectangles
            // https://github.com/ScottPlot/ScottPlot/issues/1079

            System.Drawing.Bitmap bmp = new(200, 100);
            using var gfx         = Graphics.FromImage(bmp);
            gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
            gfx.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;

            string[] fontNames = { InstalledFont.Serif(), InstalledFont.Sans(), InstalledFont.Monospace() };

            foreach (string fontName in fontNames)
            {
                gfx.Clear(Color.Navy);
                System.Drawing.Font fnt = new(fontName, 18);

                gfx.DrawString("tttt", fnt, Brushes.Yellow, 10, 10);
                string hash1 = ScottPlot.Tools.BitmapHash(bmp);

                gfx.DrawString("eeee", fnt, Brushes.Yellow, 10, 10);
                string hash2 = ScottPlot.Tools.BitmapHash(bmp);

                Assert.AreNotEqual(hash1, hash2);
            }
        }
Esempio n. 2
0
        public void Test_DrawString_Aligned()
        {
            using System.Drawing.Bitmap bmp = new(400, 300);
            using Graphics gfx = Graphics.FromImage(bmp);
            gfx.Clear(Color.Navy);

            gfx.DrawLine(Pens.Gray, 150, 0, 150, 300);
            gfx.DrawLine(Pens.Gray, 0, 150, 400, 150);
            gfx.DrawEllipse(Pens.White, 145, 145, 10, 10);

            GDI.DrawLabel(
                gfx, "testing", 150, 150, InstalledFont.Sans(), 16, true,
                HorizontalAlignment.Left, VerticalAlignment.Upper,
                Color.Yellow, Color.Magenta);

            TestTools.SaveBitmap(bmp);
        }
Esempio n. 3
0
        public void Test_DefaultFont_MatchesOsExpectations()
        {
            string defaultFont = InstalledFont.Default();

            Console.WriteLine($">>> Default font: {defaultFont}");

            string defaultFontSans = InstalledFont.Sans();

            Console.WriteLine($">>> Default sans font: {defaultFontSans}");

            string defaultFontSerif = InstalledFont.Serif();

            Console.WriteLine($">>> Default serif font: {defaultFontSerif}");

            string defaultFontMonospace = InstalledFont.Monospace();

            Console.WriteLine($">>> Default monospace font: {defaultFontMonospace}");

            Assert.That(defaultFont == defaultFontSans);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Assert.That(defaultFontSans == "Segoe UI");
                Assert.That(defaultFontSerif == "Times New Roman");
                Assert.That(defaultFontMonospace == "Consolas");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Assert.That(defaultFontSans == "DejaVu Sans");
                Assert.That(defaultFontSerif == "DejaVu Serif");
                Assert.That(defaultFontMonospace == "DejaVu Sans Mono");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                Assert.That(defaultFontSans == "Helvetica");
                Assert.That(defaultFontSerif.StartsWith("Times"));
                Assert.That(defaultFontMonospace == "Courier");
            }
        }