phronmophobic / membrane

A Simple UI Library That Runs Anywhere
Apache License 2.0
560 stars 19 forks source link

Use more accurate metrics when rendering text in java2d #40

Open phronmophobic opened 2 years ago

phronmophobic commented 2 years ago

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.

rgkirch commented 2 years ago

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. https://github.com/phronmophobic/membrane/blob/d3198021d793fac0e3eac0500996f536076087f7/src/membrane/cljfx.clj#L465

phronmophobic commented 2 years ago

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

rgkirch commented 2 years ago

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

line height decremented in LabelRaw draw https://github.com/phronmophobic/membrane/blob/87c8ec2d0e749c9ccc6eaeb3ede432f3fd8c3b33/src/membrane/java2d.clj#L280

line height decremented in text-bounds https://github.com/phronmophobic/membrane/blob/e547cdcec33239b3920428a47b9966b93d300be8/src/membrane/java2d.clj#L251

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