Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 86
Registered: ‎05-13-2009
My Device: Not Specified

HI a question about Font.getAdvance(String)?

Hi All,

 

   I have a doubt whether Font.getAdvance(String) uses Font.getAdvance(char) internally for calculations? Coz say i was writing a code to wrap a text and i thought if i wrap text based on words it would be faster so i went with Font.getAdvance(String) but still am not sure whether this function itself uses Font.getAdvance(char) internally for calculation. Plz help me on this.

 

Thanks a lot,

Sagar

Highlighted
New Developer
Posts: 86
Registered: ‎05-13-2009
My Device: Not Specified

Re: HI a question about Font.getAdvance(String)?

Hi All,

 

    Also is there no native method that can give me the number of characters of a string with a given font that will fit in a given width i know i can achieve this by writing my own logic but it would be nice to know if there is any native method for this plz let me know.

 

Thanks a lot,

Sagar

 

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: HI a question about Font.getAdvance(String)?

My guess is that Font.getAdvance(String) does not rely on Font.getAdvance(char). The String version needs to deal with kerning, combining characters, ligatures, bidirectional text analysis, and possibly other stuff, that the char version can safely ignore.

 

As to your second question, there is no built-in method that I know of to fit characters to a fixed width. The Graphics class docs make reference to a TextMetrics class, but that class is apparently not exposed (and who knows if it does what you want?) I think that your best bet is, as you suspected, to write your own logic.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 242
Registered: ‎01-29-2009
My Device: Not Specified

Re: HI a question about Font.getAdvance(String)?

And what's your actual problem?

New Developer
Posts: 86
Registered: ‎05-13-2009
My Device: Not Specified

Re: HI a question about Font.getAdvance(String)?

Hi Ted_Hopp, Thx for ur reply can u also plz let me know whether Font.getAdvance(String) would be much costly or calling Font.getAdvance(Char) for each character in the string as both be heavy operations. Thx a lot, Sagar
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: HI a question about Font.getAdvance(String)?

For analyzing a fixed piece of text, my guess is that Font.getAdvance(String) will be faster than repeated calls to Font.getAdvance(char) for each character in the String.

 

I'm not sure what you mean by "heavy operations". My guess is that both are pretty efficient. I'd be very surprised if the choice of method would make any noticeable difference in the performance of your app. (This depends on the application, of course, so I might be off base here. But I doubt it.) Just pick the one that fits best with the rest of your application logic.

 

If you are indeed experiencing performance problems, I suggest profiling your code to confirm the source. If you are simply anticipating performance issues, my advice is to not bother. (This advice is based on the old programmer's maxim: "I'd rather optimize debugged code than debug optimized code.")




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.