You Are Here:

Community: Developer Discussion Boards

#1 Old Wrap text using drawString ? - 2004-01-18, 12:40

Join Date: Dec 2003
Posts: 109
artemg
Offline
Regular Contributor
I have my app load text from a server. A lot of times the text gets fairly long, and to fit it better on the screen, I would like to decrease font size.

It seems that MIDP 1.0 (and I DO want to stick to 1.0) does not offer any way to change font for TextBox, TextField, nor StringItem. Canvas does have the option of specifying font however.

My problem is such. When I use drawString with Canvas, the text does not wrap and I only get one line of text. Since text is generated dynamically, I have no way to insert line breaks in the text itself. Is there a way to wrap the text using drawString? Thank you.
Reply With Quote

#2 Old 2004-01-18, 13:33

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
You have to implement the wrapping yourself. Lucky for you someone already did most of the work.

shmoove
Reply With Quote

#3 Old 2004-01-18, 14:59

Join Date: Dec 2003
Posts: 109
artemg
Offline
Regular Contributor
Thank you. Frankly, since MIDP 1.0 does not support setFont method for any Screens, I would just leave this alone (it's only a minor drawback). But recently I have come across an MIDP 1.0 application, which successfully displays dynamic text in various sizes. Now I can't let it go - gotta know ;)

I came to thinking that this application was using Canvas to draw text, but I don't think that Canvas is scrollable. In this application, that I am referring to, one can scroll text - not line by line but in "chunks" equal to display size.

Any ideas how this has been achieved?
Reply With Quote

#4 Old 2004-01-18, 15:19

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
When you get the "big" string you can split it into an array (or Vector, or whatever) of smaller strings, each of the smaller strings can fit in one line (using the WordWrap function). Then you need a variable to tell you what "page" you're currently viewing, and you calculate how many lines fit in one "page". Then you just need to draw the appropiate strings from your collection (the ones that go in the current page).

shmoove
Reply With Quote

#5 Old 2004-01-19, 00:33

Join Date: Dec 2003
Posts: 109
artemg
Offline
Regular Contributor
I will try that. Thanks a lot!
Reply With Quote

#6 Old Re: Wrap text using drawString ? - 2009-06-25, 09:17

Join Date: Jun 2009
Posts: 3
Welysson
Offline
Registered User
Quote:
Originally Posted by shmoove View Post
You have to implement the wrapping yourself. Lucky for you someone already did most of the work.

shmoove
Hi shmoove

Seems this link is no longer working, can you post this code in another place and send us the new link?

Thank you
Reply With Quote

#7 Old Re: Wrap text using drawString ? - 2009-06-25, 11:25

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
The code is now here.

Graham.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia