phronmophobic/membrane

Use more accurate metrics when rendering text in java2d

phronmophobic opened this issue · 3 comments

Currently, .getHeight from FontMetrics is used for line height (see here), but .getHeight returns an integer which is subtly wrong. Instead, the line height should be calculated using LineMetrics (see here).

This also affects text measurement and text selection.

I'm confused. You say that FontMetrics is used in the java2d backend but I'm still only seeing LineMetrics used there. In searching the repo, I did find a use of FontMetrics in the cljfx backend though.

metrics (.getFontMetrics font-loader jfont)

Yes, you're right. I guess I was a little too hasty with my diagnosis.

https://clojurians.slack.com/archives/CVB8K7V50/p1647908746254019?thread_ts=1647890248.556509&cid=CVB8K7V50

line height decremented in LabelRaw draw

(.translate ^Graphics2D *g* ^double (double 0.0) ^double (double (dec line-height)))

line height decremented in text-bounds

maxy (* (dec line-height)

Oh, actually line height is decremented in additional places...