i am trying to measure single chars of different fonts from Google fonts. I tried a lot, but the proportion of height and width was always wrong... Here are some of my attempts:
- TextRenderer
font:= the bloburi of a Google font-example: "https://github.com/FontFaceKit/open-sans/blob/gh-pages/fonts/Bold/OpenSans-Bold.ttf?raw=true"
FontRequestHelper helper = new FontRequestHelper(font);
iFontCollection = helper.iFontCollection;
FontStyle style = iFontCollection.Families[0].IsStyleAvailable(FontStyle.Bold) ? FontStyle.Bold : FontStyle.Regular;
System.Drawing.Font googlefont = new System.Drawing.Font(iFontCollection.Families[0], tSize, FontStyle.Regular);
size = TextRenderer.MeasureText("A", googlefont);
- MeasureString
i tried different ones, always not accurated...
SizeF sizeFf = new SizeF();
using (var image = new Bitmap(1, 1))
{
using (var g = Graphics.FromImage(image))
{
sizeFf = g.MeasureString("A", googlefont);
}
}
or
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
{
sizeFf = g.MeasureString("A", googlefont);
}
I dont need the exact width and height, the right proportion would be also reasonable. Online i only find this two solutions as good... Why does it not work for me?
Thx a lot