Jump to content
  • Advertisement
Sign in to follow this  
andreas_b

(j2me) Aligning text with drawString()

This topic is 5399 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I am trying to find out how text can fit into the smallest screensizes. To do this I need to know the width and height in pixels of the text I would like to draw, is there any way to calculate/find out this? I want to be certain that nothing is drawn out of bounds. One more thing. I just discovered that "\n" works inside drawString() with my Siemens C65, but the WTK emulator ignores it. Can I espect "\n" to work on most phones, or is this just a nice non standard feature Siemens has implemented? All this makes me wonder if just using a TextField on a Form or a TextBox would be the way to go, but it just doesnt look that good. Any words on how you are dealing with this issue will be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by andreas_b
Hi.
I am trying to find out how text can fit into the smallest screensizes. To do this I need to know the width and height in pixels of the text I would like to draw, is there any way to calculate/find out this? I want to be certain that nothing is drawn out of bounds.


As mentioned, there are appropriate static methods in class Font that will give you the required information.

Quote:

One more thing. I just discovered that "\n" works inside drawString() with my Siemens C65, but the WTK emulator ignores it. Can I espect "\n" to work on most phones, or is this just a nice non standard feature Siemens has implemented?


I wouldn't count on it. I can't find anything in the specification that says one way or another how it's supposed to behave, but IIRC it doesn't work on any Nokias, for example.

Quote:

All this makes me wonder if just using a TextField on a Form or a TextBox would be the way to go, but it just doesnt look that good.


You can't really expect to be taken seriously as a games developer (as opposed to a general applications developer) if you go that route, sadly.

One other thing to be aware of is that on Nokia Series 60 phones (at least the 3650), Graphics.drawString() will not work "properly" on an offscreen buffer, but only when the Graphics draws directly to the screen. Which is to say, the text will be drawn as usual on those offscreen buffers, but always in black, incorrectly ignoring the current colour setting. Apparently this is fairly well known, but I had to find out the hard way :(

Share this post


Link to post
Share on other sites
Quote:
Original post by andreas_b
One more thing. I just discovered that "\n" works inside drawString() with my Siemens C65, but the WTK emulator ignores it. Can I espect "\n" to work on most phones, or is this just a nice non standard feature Siemens has implemented?

Not only does it not work as expected on most phones (I've never seen it work on any phone), but on some devices you might get some weird characters printed out.

shmoove

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Zahlman

Quote:

All this makes me wonder if just using a TextField on a Form or a TextBox would be the way to go, but it just doesnt look that good.


You can't really expect to be taken seriously as a games developer (as opposed to a general applications developer) if you go that route, sadly.


Then I will go for the long run, thanx for the inputs.

Share this post


Link to post
Share on other sites
Just wanted to point out that the font's getHeight() isn't allways correct on the phone. I think there's a problem atleast with Nokia's series 60.

/MindWipe

Share this post


Link to post
Share on other sites
Yeah, IIRC it returns 14/15/16, and I'm pretty sure the large font is bigger than that. You might find even the small font is a bit "dense" at 14 pixel spacing and needs more leading.

Series 40 is 9/16/23 or something - the large font is ungodly huge on those 128x128 screens.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!