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()