Difference in SkiaSharp measureText and System Drawing's measureText

Viewed 31

I am trying to find out the a character's width and height in windows environment using this code:

using(Graphics g = Graphics.FromImage(new Bitmap(800,550)))
{
        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
        SizeF size = g.MeasureString("0",new Font(FontFamily.GenericMonospace, 10) , new PointF(0, 0), 
            StringFormat.GenericTypographic);
        Console.WriteLine(size.Height);
        Console.WriteLine(size.Width);
}

The output is: Height: 15.104165 Width: 8.001301

I am trying to port this process to cross platform code using SkiaSharp using this code:

using (SKPaint p = new SKPaint
           {
               IsAntialias = true, Typeface = SKTypeface.FromFamilyName("monospace"),
               TextSize = 10
           })
    {
            string text = "0" ;
            SKRect textBounds = SKRect.Empty;
            p.Color = SKColors.Black;
            p.Style = SKPaintStyle.Fill;
            p.MeasureText(text, ref textBounds);
            Console.WriteLine(textBounds.Height);
            Console.WriteLine(textBounds.Width);
    }

This is the height and width of same character in SkiaSharp: Height: 7 Width: 5

Can I get some help regarding this? What am I missing?

0 Answers
Related