Skip to main content

[JAVA2D] java2d Glyph questions

6 replies [Last post]
Anonymous

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Phil Race

I replied to this in the javadesktop forum on Friday but for
some reason it never showed up here in the email list :
So here it is again.

> 1) how to determine the max pixel with of the characters in a font ?
> Font.getMaxCharBounds() does not return correct values (expecially
> with some
> italic fonts). A silly workaround is to find the max size of the chars
> glyph
> outlines bounds..

IIRC we pull information from the font itself. If that
information is inaccurate that's a problem in the font.
But there's a couple of places you can get this in the
case of a TrueType font - the 'hhea' table
http://www.microsoft.com/typography/otspec/hhea.htm
is what I think our rasteriser accesses. I'm not where I can see our sources right now.
But the mention of italic fonts suggests that the
values for min left side bearing may not be included.
ie we are returning the maximunm logical bounds which
maybe isn't what you'd expect from this API

We'd have to think carefully before changing this
implementation as it may cause apps to layout differently
and also I still don't think it can be guaranteed to
enclose *all* the pixels.

If you want a definite answer then you'll need to go
through the expensive process of calling
GlyphVector.getPixelBounds() for each char in the font.

>
> 2) why Graphics2D.drawString() gives so different visual results from
> drawing a glyphVector as a Shape ?

The former does scan conversion into a bitmap in the
rasteriser. That scan conversion process in the font
understands hints for dropout control etc which are
specific to the technology. The shape path gets the
outline and is now completely out of the rasteriser
into the 2D geometric code. That is known to have
some deficiencies for small paths but you cannot
ever expect it to produce identical results as the
font rasteriser.

-phil.

Michele Puccini wrote:
> Thanks all for the hints.
>
> while stringWidth() is not for me (I want to get te maximum w,h of the
> glyphs in a font), g2d.getFontMetrics().xxx() sounds promising. I'll do
> further checks and let you know.
>
> Mik
> ============================================================================
>
>
>> ClassX Development Italy Via Francesca, 368/I I-56030 S.M. a Monte
>> (PI) <
>> Tel.(+39)-0587-705153 Fax.(+39)-0587-705153 WEB:
>> http://www.classx.it <
>
> ============================================================================
>
>
> ----- Original Message -----
> From: "Bill Dodson"
> To:
> Sent: Friday, October 21, 2005 8:48 PM
> Subject: Re: [JAVA2D] java2d Glyph questions
>
>
>> I am not the person to give a definitive answer, but have you tried the
>> FontMetrics class? I get the total width and height of a string with
>> the following code:
>>
>> int sw = g2d.getFontMetrics().stringWidth(text);
>> int sh = g2d.getFontMetrics().getHeight();
>>
>> I notice there is also a getMaxCharBounds in this class. It uses a
>> Graphics context instead of FontRenderContext.
>>
>> Hope this helps.
>> bill
>>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Michele Puccini

Thanks all for the hints.

while stringWidth() is not for me (I want to get te maximum w,h of the
glyphs in a font), g2d.getFontMetrics().xxx() sounds promising. I'll do
further checks and let you know.

Mik
============================================================================
> ClassX Development Italy Via Francesca, 368/I I-56030 S.M. a Monte (PI) <
> Tel.(+39)-0587-705153 Fax.(+39)-0587-705153 WEB: http://www.classx.it <
============================================================================

----- Original Message -----
From: "Bill Dodson"
To:
Sent: Friday, October 21, 2005 8:48 PM
Subject: Re: [JAVA2D] java2d Glyph questions

>I am not the person to give a definitive answer, but have you tried the
> FontMetrics class? I get the total width and height of a string with
> the following code:
>
> int sw = g2d.getFontMetrics().stringWidth(text);
> int sh = g2d.getFontMetrics().getHeight();
>
> I notice there is also a getMaxCharBounds in this class. It uses a
> Graphics context instead of FontRenderContext.
>
> Hope this helps.
> bill
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Dmitri Trembovetski

Hi Michele,

take a look at this JavaOne presentation by the Java2D team members.
I think you'll find exactly what you need:
"Advanced Java 2D API Topics for Desktop Applications: TS-3214, 2005"
http://developers.sun.com/learning/javaoneonline/2005/desktop/TS-3214.pdf
http://developers.sun.com/learning/javaoneonline/2005/desktop/TS-3214.html

Thanks,
Dmitri

On Mon, Oct 24, 2005 at 03:05:14PM +0200, Michele Puccini wrote:
> Thanks all for the hints.
>
> while stringWidth() is not for me (I want to get te maximum w,h of the
> glyphs in a font), g2d.getFontMetrics().xxx() sounds promising. I'll do
> further checks and let you know.
>
> Mik
> ============================================================================
> >ClassX Development Italy Via Francesca, 368/I I-56030 S.M. a Monte (PI) <
> >Tel.(+39)-0587-705153 Fax.(+39)-0587-705153 WEB: http://www.classx.it <
> ============================================================================
>
> From: "Bill Dodson"
> To:
> Sent: Friday, October 21, 2005 8:48 PM
> Subject: Re: [JAVA2D] java2d Glyph questions
>
>
> >I am not the person to give a definitive answer, but have you tried the
> >FontMetrics class? I get the total width and height of a string with
> >the following code:
> >
> > int sw = g2d.getFontMetrics().stringWidth(text);
> > int sh = g2d.getFontMetrics().getHeight();
> >
> >I notice there is also a getMaxCharBounds in this class. It uses a
> >Graphics context instead of FontRenderContext.
> >
> >Hope this helps.
> >bill
> >
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Bira Neto

have you tried getStringBounds (from Font)?

Michele Puccini wrote:

> Hello,
>
> I have some questions:
>
> 1) how to determine the max pixel with of the characters in a font ?
> Font.getMaxCharBounds() does not return correct values (expecially
> with some
> italic fonts). A silly workaround is to find the max size of the chars
> glyph
> outlines bounds.. But it's so ugly!
>
> 2) why Graphics2D.drawString() gives so different visual results from
> drawing a glyphVector as a Shape ?
>
> Many thanks,
>
> Mik
> ============================================================================
>
>
>> ClassX Development Italy Via Francesca, 368/I I-56030 S.M. a Monte
>> (PI) <
>> Tel.(+39)-0587-705153 Fax.(+39)-0587-705153 WEB:
>> http://www.classx.it <
>
> ============================================================================
>
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff JAVA2D-INTEREST". For general help, send
> email to
> listserv@java.sun.com and include in the body of the message "help".
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Bill Dodson

I am not the person to give a definitive answer, but have you tried the
FontMetrics class? I get the total width and height of a string with
the following code:

int sw = g2d.getFontMetrics().stringWidth(text);
int sh = g2d.getFontMetrics().getHeight();

I notice there is also a getMaxCharBounds in this class. It uses a
Graphics context instead of FontRenderContext.

Hope this helps.
bill

Michele Puccini wrote:

> Hello,
>
> I have some questions:
>
> 1) how to determine the max pixel with of the characters in a font ?
> Font.getMaxCharBounds() does not return correct values (expecially
> with some
> italic fonts). A silly workaround is to find the max size of the chars
> glyph
> outlines bounds.. But it's so ugly!
>
> 2) why Graphics2D.drawString() gives so different visual results from
> drawing a glyphVector as a Shape ?
>
> Many thanks,
>
> Mik
> ============================================================================
>
>
>> ClassX Development Italy Via Francesca, 368/I I-56030 S.M. a Monte
>> (PI) <
>> Tel.(+39)-0587-705153 Fax.(+39)-0587-705153 WEB:
>> http://www.classx.it <
>
> ============================================================================
>
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff JAVA2D-INTEREST". For general help, send
> email to
> listserv@java.sun.com and include in the body of the message "help".
>
> .
>

--
Bill Dodson
Parkline, Inc. http://www.parkline.com
phone: 304-586-2113 x149
fax: 304-586-3842
email: bdodson@parkline.com

Email Disclaimer

The information in any email is confidential and may be legally privileged. It is intended solely for the addressee. Access to the email message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. If you have received an email message in error, please notify the sender immediately by email, facsimile or telephone and return and/or destroy the original message.

Thank you.

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

philrace
Offline
Joined: 2003-06-09

I'd like to reply to the original post directly but
for some reason I don't see it.

> 1) how to determine the max pixel with of the characters in a font ?
> Font.getMaxCharBounds() does not return correct values (expecially
> with some
> italic fonts). A silly workaround is to find the max size of the chars
> glyph
> outlines bounds..

IIRC we pull information from the font itself. If that
information is inaccurate that's a problem in the font.
But there's a couple of places you can get this in the
case of a TrueType font - the 'hhea' table
http://www.microsoft.com/typography/otspec/hhea.htm
is what I think our rasteriser accesses. I'm not where I can see our sources right now.
But the mention of italic fonts suggests that the
values for min left side bearing may not be included.
ie we are returning the maximunm logical bounds which
maybe isn't what you'd expect from this API

We'd have to think carefully before changing this
implementation as it may cause apps to layout differently
and also I still don't think it can be guaranteed to
enclose *all* the pixels.

If you want a definite answer then you'll need to go
through the expensive process of calling
GlyphVector.getPixelBounds() for each char in the font.

>
> 2) why Graphics2D.drawString() gives so different visual results from
> drawing a glyphVector as a Shape ?

The former does scan conversion into a bitmap in the
rasteriser. That scan conversion process in the font
understands hints for dropout control etc which are
specific to the technology. The shape path gets the
outline and is now completely out of the rasteriser
into the 2D geometric code. That is known to have
some deficiencies for small paths but you cannot
ever expect it to produce identical results as the
font rasteriser.