I'm trying to generate a font-map using C#'s Graphics class.
The characters are supposed to be perfectly in the middle of their rectangle in order to use them afterwards. Secondly, I want to use the biggest font-size with all characters fitting into their box.
This is my attempt at doing so. However, when I run this, the characters are not in the middle of their rectangle and it seems like they're rather attached to the upper-left corner of it, considering they're pretty jump when you go trough the different maps.
foreach (String FontName in DataHandler.GetFonts())
{
foreach (FontStyle Style in Enum.GetValues(typeof(FontStyle)))
{
try
{
Bitmap map = new Bitmap(585, 559);
Graphics g = Graphics.FromImage(map);
for (int i = 0; i < charOrder.Length; i++)
{
string character = charOrder.Substring(i, 1);
g.DrawString(character, new Font(FontName, 30 / new Font(FontName, 20).FontFamily.GetEmHeight(Style), Style), new SolidBrush(myColor), new RectangleF(new PointF((i % charactersPerRow) * 40, ((i - (i % charactersPerRow)) / charactersPerRow) * 80), new SizeF(40, 80)));
}
map.Save(OutputPath + "\\" + Style.ToString() + "_" + FontName + ".png");
}
catch (Exception)
{
}
}
}
How would I make the characters fit perfectly into in the middle of their rectangle?
EDIT: All characters of one font would have to use the same font-size, obviously.