FontMetrics' getHeight() doesn't behave accurately

A discussion forum for JFreeSVG (a fast, lightweight, SVG generator for the Java platform).

FontMetrics' getHeight() doesn't behave accurately

Postby 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?
retr0yrus
 
Posts: 1
Joined: Tue Jul 28, 2015 2:26 am

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

Postby 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: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11623
Joined: Fri Mar 14, 2003 10:29 am


Return to JFreeSVG

Who is online

Users browsing this forum: No registered users and 1 guest