How to obtain font/string metrics? (Ascent, descent, leading, and advance).
908740Jan 29 2012 — edited Jun 1 2012Swing offered methods for obtaining font metrics for a font (ascent, the height the font extends above the baseline; descent, the height it extends below the baseline; and leading, the space between the top of this line and the bottom of the previous line, assuming the same font on both lines), and for calculating the width a string would take if it was displayed in a given font.
Unfortunately, this seems to have disappeared in JavaFX 2. I can see no good way of calculating the ascent, leading, or descent, and the only way I've been able to figure out to calculate the width of a piece of text is to make a Label from it and get the width of a label.
Surely there's got to be a good, simple, and officially approved way of calculating these measures? They are needed for any app that needs to do precise placement of text, eg. layout programs.
Thanks,
Ken McDonald