You Are Here:

Community: Developer Discussion Boards

#1 Old text center align - 2009-03-06, 12:25

Join Date: Jan 2009
Posts: 64
Location: India
Send a message via AIM to pavan.pareta Send a message via MSN to pavan.pareta Send a message via Yahoo to pavan.pareta Send a message via Skype™ to pavan.pareta
pavan.pareta's Avatar
pavan.pareta
Offline
Regular Contributor
Hi All,

word = "Nokia"

How do i print a word on canvas in center align ? i do not want to fixed coordinate on the canvas because the a word is changing dynamically so the word size would be increase like (word = "Computer"). Please help me is there any solution for this issue.


Pavan Pareta

http://www.croozeus.com/started.htm
Reply With Quote

#2 Old Re: text center align - 2009-03-06, 14:51

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Online
Forum Nokia Champion
Hi,

Check out the graphics section from the PyS60 Library Reference. It has a paragraph about the measure_text method:
Quote:
measure_text(text[, font=None, maxwidth=-1, maxadvance=-1])

Measures the size of the given text when drawn using the given font. Optionally you can specify the maximum width of the text or the maximum amount the graphics cursor is allowed to move (both in pixels).

Returns a tuple of three values:
  • the bounding box for the text as a 4-tuple: (topleft-x, topleft-y, bottomright-x, bottomright-y)
  • the number of pixels the graphics cursor would move to the right
  • the number of characters of the text that fits into the given maximum width and advance
So you can measure the size of the word you want to write and calculate the coordinates at which you want to write it so it would be in the center.
Reply With Quote

#3 Old Re: text center align - 2009-03-06, 16:46

Join Date: Jun 2008
Posts: 45
maclun123
Offline
Registered User
This will help you:
Code:
size = img.measure_text(string, (None, None, FONT_BOLD))
img.text(((screen_width-size[1])/2, vertical_position), string, 0xffffff, (None, None, FONT_BOLD))
mac
Reply With Quote

#4 Old Re: text center align - 2009-03-06, 18:18

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Quote:
Originally Posted by pavan.pareta View Post
Hi All,

word = "Nokia"

How do i print a word on canvas in center align ? i do not want to fixed coordinate on the canvas because the a word is changing dynamically so the word size would be increase like (word = "Computer"). Please help me is there any solution for this issue.
Well, what I usually do is measuring the text as mentioned before and do some calculations:

Code:
import graphics
import sysinfo

x, y = sysinfo.display_pixels() #gets width and height of the screen
img = graphics.Image.new((x,y))
text = "Welcome!"

((x1, y1, x2, y2), dummy, dummy) = \
      img.measure_text(text, font='title')
img.text((x/2-x2/2, y+y1), text, (255, 0, 0), 'title')
By the way, also check Font Test by Jouni Miettunen, which is a perfect example for this



Hope it helps,

Rafael.
Last edited by Rafael T. : 2009-03-07 at 04:45.
Reply With Quote

#5 Old Thumbs up Re: text center align - 2009-03-09, 06:03

Join Date: Jan 2009
Posts: 64
Location: India
Send a message via AIM to pavan.pareta Send a message via MSN to pavan.pareta Send a message via Yahoo to pavan.pareta Send a message via Skype™ to pavan.pareta
pavan.pareta's Avatar
pavan.pareta
Offline
Regular Contributor
Hi All,

Really very good solution. Thanks for help me.


Pavan Pareta

http://www.croozeus.com/started.htm
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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 On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Change the align of all the text in the application to "right" mikecotic Mobile Java General 2 2008-12-06 06:38
draw Text "Hello World1\Hello World2" at center of screen junmobus Symbian User Interface 5 2008-05-26 07:10
How do you center text on the screen? Subotai4Winds General Symbian C++ 1 2005-01-24 04:01
Persist text value of user defined option in Enumerated Text Settings List leethomso Symbian User Interface 0 2004-11-24 19:49
How to draw right align text? yingchuan Symbian 1 2004-10-23 03:05

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 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ