I get the x and y coordinates for a text from a Java backend. Now I want to draw that font in C# (Graphics.DrawString) the exact way as Java does it. For that I have to calculate the baseline. I have a code that makes it kind of right for some fonts, but is not rendered correctly for other fonts.
SizeF size = graphics.MeasureString(str, font);
int descent = font.FontFamily.GetCellDescent(font.Style);
float factor = font.Size / font.FontFamily.GetEmHeight(font.Style);
float leadingCalc = (ascent * factor + descent * factor) - emHeight * factor;
graphics.DrawString(str + "", font, brush, x, y - font.Height + descent * factor + leadingCalc);
The question is, does someone know are more precise or better way to calculate the baseline?