How do I get the highest point of a caret located at an offset?

All the methods within Editor offer a way to get from VisualPosition and LogicalPosition to X and Y locations on the screen. However, if the line spacing is greater than 1, these all return locations at the top of a line, which is much higher than a caret. I need something that provides the vertical position of a Caret placed at a certain offset (ie. the highest point of a letter on that line, or the top of a caret located on that line) in terms of Y.

1

There's no API to get that information currently. It can be calculated as follows:

int y = editor.visualPositionToXY(...).y;
FontMetrics fm = editor.getFontMetrics(Font.PLAIN);
int caretTop = y - fm.getHeight() + editor.getLineHeight() - editor.getDescent() + fm.getDescent();

(you'll need to cast Editor to EditorImpl to call some methods)

1

请先登录再写评论。