FontMetrics' getHeight() doesn't behave accurately

A discussion forum for JFreeSVG (a fast, lightweight, SVG generator for the Java platform).
Locked
retr0yrus
Posts: 1
Joined: Tue Jul 28, 2015 2:26 am
antibot: No, of course not.

FontMetrics' getHeight() doesn't behave accurately

Post by retr0yrus » Tue Jul 28, 2015 2:49 am

I would like to layout a string in an SVG image. FontMetrics' getHeight() method allows me to compute the height of a character in my string and the stringWidth() method allows me to compute the total width. Using these values, it is straightforward to compute the height of the drawing area needed, if I restrict the width of the drawing area to a fixed constant value. But it appears that the answer I get is not consistent with the actual height needed. It appears that when FontMetrics' methods are accessed "through" JFreeSVG, the height returned is always smaller than the correct height needed to layout the string in a particular font. Is this known behavior? Has anybody found a fix?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: FontMetrics' getHeight() doesn't behave accurately

Post by david.gilbert » Sat Sep 05, 2015 7:45 am

The problem here is that JFreeSVG has to use Java API calls to "measure" the text but ultimately the rendering will be done by some other platform (typically a web browser, very often on a different computer from where the SVG was generated). There's no guarantee that the two font rendering systems will give consistent results.

I guess there are ways to deal with this in SVG but so far I haven't had time to investigate it properly.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked