How to display text encoded with utf-8

54 views
Skip to first unread message

dave berk

unread,
Mar 31, 2008, 1:35:05 PM3/31/08
to pyglet...@googlegroups.com
I'm trying to display some non-english text within the opengl window. I pre'd the text with u, but it doesn't seem to help. All I get is question marks. What should I do to display utf-8 encoded text? is it even supported?

Regards
Dave

Nathan

unread,
Mar 31, 2008, 1:36:48 PM3/31/08
to pyglet...@googlegroups.com

Did you load a font that supports unicode? (I don't know anything
about the internals of pyglet.font, but that seems like a good place
to start)

~ Nathan

Thomas Woelz

unread,
Mar 31, 2008, 3:00:08 PM3/31/08
to pyglet-users
Dave,
It is supported. Did you set the encoding in the beginning of your
script? If not try adding something like:
# -*- coding: <encoding name> -*-

Examples:
# -*- coding: UTF-8 -*-
or
# -*- coding: Latin-1 -*-

Thomas Woelz

Richard Jones

unread,
Mar 31, 2008, 5:09:44 PM3/31/08
to pyglet...@googlegroups.com

pyglet's text rendering will accept a unicode string for rendering just fine.
In some instances your selected font may not support certain glyphs so you'll
see a placeholder glyph instead.

Try this:

import pyglet
t = pyglet.text.Label(u'\u20ac')
w = pyglet.window.Window()
@w.event
def on_draw():
t.draw()
pyglet.app.run()

It should render a Euro symbol in the bottom-left of the window.


Richard

Richard Jones

unread,
Mar 31, 2008, 5:16:01 PM3/31/08
to pyglet...@googlegroups.com
On Tue, 1 Apr 2008, Richard Jones wrote:
> On Tue, 1 Apr 2008, dave berk wrote:
> > I'm trying to display some non-english text within the opengl window. I
> > pre'd the text with u, but it doesn't seem to help. All I get is question
> > marks. What should I do to display utf-8 encoded text? is it even
> > supported?
>
> pyglet's text rendering will accept a unicode string for rendering just
> fine.

ps. if you don't know about unicode and utf8 or other text encoding then I
suggest you read something like:

http://www.amk.ca/python/howto/unicode
http://www.jorendorff.com/articles/unicode/python.html
http://wiki.laptop.org/go/Python_Unicode


Richard

dave berk

unread,
Apr 1, 2008, 9:18:54 AM4/1/08
to pyglet...@googlegroups.com
Thanks, everyone. As you surmised correctly I forgot to add the encoding at the beginning of the file. Now, though I have another problem. I am trying to render some text in hebrew (a right to left language). Unfortunately, the text appear reversed on the screen. Is there some way to tell pyglet I'm trying to display a right to left language?

Regards
Dave

Alex Holkner

unread,
Apr 1, 2008, 9:20:45 AM4/1/08
to pyglet...@googlegroups.com

Sorry, there's no bidi (bidirectional text) support in pyglet...
you're the first person who's asked for it. If this is an important
issue for you I'd like to work with you to get support in for pyglet
1.2 later this year (I don't read or write any right-to-left
languages, so I need someone to check correctness).

Alex.

dave berk

unread,
Apr 1, 2008, 9:34:03 AM4/1/08
to pyglet...@googlegroups.com
I'd help you in any way I can.

Regards
Dave


Reply all
Reply to author
Forward
0 new messages