vendredi 1 juillet 2016

Rendering unicode font with pygame


I'm currently attempting to render text read from a file onto the screen using pygame. However, when I attempt to render a non-standard Unicode character (i.e. Japanese hirigana), it responds only with an assortment of random characters and boxes. I've searched through everything I could find and nothing works. Any ideas? The file is properly encoded and read in UTF-8, so the problem is during the rendering stage.

My text rendering code:

def text(screen, pos, text='', font=None, color=BLACK, halign='LEFT', valign='TOP'):
    if font == None: font = pygame.font.Font(None,16)
    draw = font.render(text.encode('utf8'), True, color)
    pos = list(pos)

    if halign.upper() == 'CENTER': pos[0] -= font.size(text)[0]/2
    if halign.upper() == 'RIGHT': pos[0] -= font.size(text)[0]

    if valign.upper() == 'CENTER': pos[1] -= font.size(text)[1]/2
    if valign.upper() == 'BOTTOM': pos[1] -= font.size(text)[1]

    screen.blit(draw, pos)

The text I'm trying to render:

おはようございます、みんな!

The result: http://imgur.com/VDctx8N

EDIT: After some testing, it turns out that it was the font I was using... Along those lines, does anyone know of an alternative to Segoe UI Light that has kana support?


Aucun commentaire:

Enregistrer un commentaire