Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: pySFML 1.3: UTF-8 characters?  (Read 7611 times)

0 Members and 1 Guest are viewing this topic.

PixelGordo

  • Newbie
  • *
  • Posts: 8
    • View Profile
pySFML 1.3: UTF-8 characters?
« on: October 07, 2014, 07:30:57 pm »
During last week I've been strugling to draw UTF-8 characters on screen without success. I've tried with different encodings in the unicode string (u'aá eé ií oó uú') and combinations with and without # -*- coding: utf-8 -*- at the beginning of the code. The best thing I obtain are squares or interrogation marks instead of the special characters.

Any idea about what should I add or change?

Regards and thanks in advance.

My setup is:
  • Linux Mint 17
  • pySFML 1.3.0
  • Python 2.7.6

And for testing purposes here is my code:

# -*- coding: utf-8 -*-

import math
import sfml

o_window = sfml.RenderWindow(sfml.VideoMode(480, 300), 'PyFe v2.0')
o_window.vertical_synchronization = True
o_window.framerate_limit = 30

o_font = sfml.Font.from_file('/usr/share/fonts/truetype/freefont/FreeSerif.ttf')
o_color = sfml.Color(255, 0, 0)

o_text_ascii = sfml.Text(u'aá eé ií oó uú')
o_text_ascii.color = o_color
o_text_ascii.font = o_font

f_angle = 0

o_rotation = sfml.Transform()
o_rotation.rotate(0.5)


def position(f_angle):
    i_pos_x = 200 + 150 * math.sin(f_angle)
    i_pos_y = 120 + 100 * math.cos(f_angle)

    return i_pos_x, i_pos_y


# Main loop
while o_window.is_open:

    # Handle events
    for event in o_window.events:
        # window closed or escape key pressed: exit
        if type(event) is sfml.CloseEvent:
            o_window.close()

    # Updating
    f_angle += 0.05
    o_text_ascii.position = position(f_angle)

    # Rendering
    o_window.clear(sfml.Color(50, 200, 50))
    o_window.draw(o_text_ascii)

    o_window.display()
 
« Last Edit: October 07, 2014, 08:24:42 pm by PixelGordo »

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: pySFML 1.3: UTF-8 characters?
« Reply #1 on: October 08, 2014, 11:20:15 pm »
With all the recent changes to Python regarding Unicode handling, Python 2.7 with str and unicode types, Python 3.x until 3.2 with str and bytes and now Python 3.3 that reintroduces unicode type, plus the Cython layer that performs automatic conversions, I'm a bit lost.

As far as I can remember, this was a known bug in pySFML 1.3 and the development version contains the fix. I had to change the internal implementation because OSX doesn't support wchar too and I ended up with something working with one issue: a weird character appears in front of any sf.Text. So until I fix that, you could compile and work with the development version of pySFML. :)

Good luck.
Interested in using SFML with Python ? Try out its Python binding!

PixelGordo

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: pySFML 1.3: UTF-8 characters?
« Reply #2 on: November 12, 2014, 07:48:02 pm »
Sorry for my late reply, Sonkun. I've been really busy lately with real life issues.

I didn't know a "simple" encoding problem could be so complicated and I really appreciate your explanation. Unfortunately I think I'll leave my project parked at least until next year. If the problem is still there I'll try to compile pySFML.

Thank you very much and regards