×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    5

    Displaying unicode in graphics module (specifically greek extended characters)

    Thanks to posts elsewhere I know how to display unicode characters but this seems to be rather limited. Though precisely what the limits are isn't clear to me.

    For the application I'm writing (a vocabulary memorisation program) I would very much like to include characters from the greek extended set (see for example here) and other unusual character sets. Is there any way of doing this via pys60 graphics module?

    Many thanks

  2. #2
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: Displaying unicode in graphics module (specifically greek extended characters)

    Quote Originally Posted by james2k6 View Post
    Thanks to posts elsewhere I know how to display unicode characters but this seems to be rather limited. Though precisely what the limits are isn't clear to me.

    For the application I'm writing (a vocabulary memorisation program) I would very much like to include characters from the greek extended set (see for example here) and other unusual character sets. Is there any way of doing this via pys60 graphics module?

    Many thanks
    Hi james,

    Enter the "Character Map" program on Windows and check the code for each character. The code and description of the character selected will appear at the bottom bar. For example, if you want to print the ^ character, you would use:

    Code:
    print "\u005e"
    You can also decode the characters:

    Code:
    print "^".decode("utf-8")
    For completeness, check this thread.


    Hope it helps,

    Rafael.
    Last edited by Rafael T.; 2008-12-22 at 21:56.

  3. #3
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Displaying unicode in graphics module (specifically greek extended characters)

    Just completing Rafael's answer, you can display Greek (or other special characters) using the graphics module the same way that you would normal characters.
    Code:
    #Create a new image
    img = graphics.Image.new((240,320))
    
    #Write on it
    img.text((50,50), u"Phi is \u03A6", font='title')

  4. #4
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: Displaying unicode in graphics module (specifically greek extended characters)

    Quote Originally Posted by bogdan.galiceanu View Post
    Just completing Rafael's answer, you can display Greek (or other special characters) using the graphics module the same way that you would normal characters.
    Code:
    #Create a new image
    img = graphics.Image.new((240,320))
    
    #Write on it
    img.text((50,50), u"Phi is \u03A6", font='title')
    Thanks for completing, Bogdan

    Thinking in a more dynamic way to do it, if you will use it a lot in your code: you could create a function to return the decoded text. Just assign the string to the text you want and use it as the parameter.

    Example using a note:

    Code:
    import appuifw
    
    def dec(text):
        return text.decode("utf-8")
    
    t = "^ is a special character"
    appuifw.note(dec(t))
    BR,

    Rafael.
    Last edited by Rafael T.; 2008-12-22 at 22:26.

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    5

    Re: Displaying unicode in graphics module (specifically greek extended characters)

    Thanks for your quick replies, unfortunately I wasn't clear enough in my question: I should have given an example.

    I can get basic characters like the Greek alphabet working (reading in from a unicode text file, then printing to screen). The problem arises with certain unusual characters like, using the \u form, "\u0310". (I've consulted this chart.)

    Is the Pys60 implementation limited to a subset of special characters, and if so which set?

    PS I'm not sure if this will work but here is the first few lines of the "deck" of flashcards:

    ἤ|or, either, than|0|1|0|0
    ὅς, ἥ, ὅ|who, whom, that, which|0|1|0|0
    καί|and, even, also, namely|0|1|0|0
    εἶπεν|he she it said|0|1|0|0
    ἔχω|I have, hold; intrans: I am|0|1|0|0
    ὅτι|that, since, because|0|1|0|0

    And I've been reading it in using (omitting the basic file handling etc):
    Code:
                    str= line.decode("utf-8")
                    temp = str.split(u"|")
                    if len(temp) == 6:
                        self.cards.append(Card(temp[0],temp[1],int(temp[2]),int(temp[3]),int(temp[4]),int(temp[5]),n))
    I'm sure there are nicer ways of doing it, but I'd like to get a prototype working before I consider this.

  6. #6
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: Displaying unicode in graphics module (specifically greek extended characters)

    Well, not all characters are supported. As jethro.fn says in the thread I linked on post #2, PyS60 is based on Python 2.2.2, which only understands the ISO-8859-1 character set when considering unicode literals. So make sure the characters you are using are from that set. Anyway, jpauril already said that a new version of PyS60 will be available soon, which will be based in the one of the latest Python versions. With that new version, you will probably have support to more characters


    BR,

    Rafael.

  7. #7
    Regular Contributor
    Join Date
    Jan 2004
    Location
    Helsinki
    Posts
    376

    Exclamation Re: Displaying unicode in graphics module (specifically greek extended characters)

    Quote Originally Posted by james2k6 View Post
    tion limited to a subset of special characters, and if so which set?
    Available charsets vary by firmware language pack versions.

    Once we send application to signing in China, but they couldn't do it, since the particular font we had used in our UI didn't have Latin characters in Chinese language pack.
    Mikko Ohtamaa

    http://mfabrik.com
    http://blog.mfabrik.com

  8. #8
    Super Contributor
    Join Date
    May 2004
    Location
    Tampere, Finland
    Posts
    524

    Re: Displaying unicode in graphics module (specifically greek extended characters)

    Quote Originally Posted by Rafael T. View Post
    Well, not all characters are supported. As jethro.fn says in the thread I linked on post #2, PyS60 is based on Python 2.2.2, which only understands the ISO-8859-1 character set when considering unicode literals. So make sure the characters you are using are from that set.
    Well, its not quite that bad. What I meant back then was that if you don't explicitly do mytext.decode("utf-8"), Python 2.2.2 considers the text to be in ISO-8859-1 (i.e. Latin 1) encoding. Newer Python versions allow you to select any encoding for string literals at the beginning of the file. You can still enter any Unicode character by explicitly decoding the string manually, like above. Of course, supported characters in S60 fonts are limited and vary between language variants, like Mikko (miohtama) said.

  9. #9
    Registered User
    Join Date
    Dec 2008
    Posts
    5

    Re: Displaying unicode in graphics module (specifically greek extended characters)

    So is there a way of adding a font which does support greek extended characters? (or indeed any unicode characters?)

    I've found some talk about unicode fonts for s60, though am still looking for precise details/download. But can pys60 use fonts other than the built in ones*? I found a guide to adding fonts which I will try this afternoon (GMT), but if someone knows that this will not work I'd be grateful if you could warn me first!

    And by language variants are you referring to editions of pys60 or symbian itself?

    *On my device (a UK e71) the appuifw.available_fonts() gives: Nokia Hindi S60, Nokia Hindi TitleSmBd S6, Series 60 ZDigi.

  10. #10
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: Displaying unicode in graphics module (specifically greek extended characters)

    Quote Originally Posted by jethro.fn View Post
    Well, its not quite that bad. What I meant back then was that if you don't explicitly do mytext.decode("utf-8"), Python 2.2.2 considers the text to be in ISO-8859-1 (i.e. Latin 1) encoding. Newer Python versions allow you to select any encoding for string literals at the beginning of the file. You can still enter any Unicode character by explicitly decoding the string manually, like above. Of course, supported characters in S60 fonts are limited and vary between language variants, like Mikko (miohtama) said.
    Yes, I thought he said he wasn't able to insert such characters with the keyboard(indeed I forgot to talk about the alt+XXX shortcuts), so in this case he would need to use the characters from that set, I supose

    Quote Originally Posted by james2k6 View Post
    So is there a way of adding a font which does support greek extended characters? (or indeed any unicode characters?)

    I've found some talk about unicode fonts for s60, though am still looking for precise details/download. But can pys60 use fonts other than the built in ones*? I found a guide to adding fonts which I will try this afternoon (GMT), but if someone knows that this will not work I'd be grateful if you could warn me first!

    And by language variants are you referring to editions of pys60 or symbian itself?

    *On my device (a UK e71) the appuifw.available_fonts() gives: Nokia Hindi S60, Nokia Hindi TitleSmBd S6, Series 60 ZDigi.
    Well, I don't think the S60 fonts support all those greek characters you want to use

    Try to test the most unsual characters with the default fonts. If you don't get it to work, try using the solution you find



    BR,

    Rafael.

Similar Threads

  1. Displaying Unicode characters
    By jp4symbian in forum Symbian User Interface
    Replies: 47
    Last Post: 2009-11-10, 14:52
  2. Carbide.j 1.5 and Netbeans 5.5 beta 2
    By ovjo12 in forum Mobile Java Tools & SDKs
    Replies: 5
    Last Post: 2007-06-11, 05:43
  3. Replies: 2
    Last Post: 2003-05-22, 14:50
  4. Replies: 1
    Last Post: 2002-06-13, 05:39
  5. Unicode characters
    By Nokia_Archive in forum Browsing and Mark-ups
    Replies: 1
    Last Post: 2002-05-17, 14:09

Posting Permissions

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