You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Tomas Rimšelis <to...@gmail.com> on 2010/01/04 15:31:31 UTC
Text of given font width
Hello,
I need to programatically get a width of some text (word, specifically) in a
given font, size and style, which will be generated in Apache FOP (version
0.95) PDF document.
The problem is that I need to know, if given word will fit to a column with
a known width, and if it won't - resize to a fitable size. So far I have
used java.awt.FontMetrics.stringWidth() method for this, but it seems that
Java AWT's and FOP's PDF renderer generate text of different sizes.
Re: Text of given font width
Posted by Vincent Hennebert <vh...@gmail.com>.
Hi Tomas,
Sorry about the delay.
Tomas Rimšelis wrote:
> I have came up with the solution - I've
> used FontMetrics's getWidth(codePoint, fontSize) for the character width and
> sum all the characters in a word. It is not as clear as a solution with Java
> AWT, but still it works.
The PDF renderer doesn’t use Java AWT to get glyph sizes, but FOP’s own
font sub-system. This is because the font (or a subset of it) must
usually be embedded into the resulting PDF, and AWT doesn’t give access
to the font file for that purpose.
Note that your solution is only approximate: kerning may occur between
some glyphs (increasing or reducing the space between two glyphs to make
the text look better). Also, glyph substitution may occur, or even
a different font selected if the current font is missing glyphs for some
characters.
However, this approximation will probably be good enough in most cases
to suit your needs.
> 2010/1/4 Tomas Rimšelis <to...@gmail.com>
>
>> Hello,
>> I need to programatically get a width of some text (word, specifically) in
>> a given font, size and style, which will be generated in Apache FOP (version
>> 0.95) PDF document.
>>
>> The problem is that I need to know, if given word will fit to a column with
>> a known width, and if it won't - resize to a fitable size. So far I have
>> used java.awt.FontMetrics.stringWidth() method for this, but it seems that
>> Java AWT's and FOP's PDF renderer generate text of different sizes.
Vincent
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
Re: Text of given font width
Posted by Tomas Rimšelis <to...@gmail.com>.
I have came up with the solution - I've
used FontMetrics's getWidth(codePoint, fontSize) for the character width and
sum all the characters in a word. It is not as clear as a solution with Java
AWT, but still it works.
2010/1/4 Tomas Rimšelis <to...@gmail.com>
> Hello,
> I need to programatically get a width of some text (word, specifically) in
> a given font, size and style, which will be generated in Apache FOP (version
> 0.95) PDF document.
>
> The problem is that I need to know, if given word will fit to a column with
> a known width, and if it won't - resize to a fitable size. So far I have
> used java.awt.FontMetrics.stringWidth() method for this, but it seems that
> Java AWT's and FOP's PDF renderer generate text of different sizes.
>