SFML community forums

Bindings - other languages => Python => Topic started by: FrozenTux on May 22, 2015, 11:19:06 pm

Title: sf.Text adding a symbol before text
Post by: FrozenTux on May 22, 2015, 11:19:06 pm
Hello,

I have used pySFML on python 2.7 for some time, and having recently switched to 3.4, I have started my first SFML python 3 project.

I have discovered that sfml.graphics.Text adds '\ufeff' before it's text, which then shows up as a square when rendered, as you can see on this image : http://monosnap.com/file/JBBAqDPIvQcHs9EzLTxwE1SyjQ8xZG.png .

This is not linked to the font itself or the rendering as the supplementary symbol is present in the string attribute of the Text object. Setting the text after initialisation does not fix the issue as the prefix is added again.

I have tried to pass utf-8 bytes instead of str, but it causes an error and the text is not set.

I am using :

As I never encountered this problem before, I have tried to run my program under Python 2.7 with the latest official binary, and the square did not appear (with or without using unicode)

This led me to think that the problem may be caused by my unofficial binary. I have tried to build from source with SFML 2.3, but unfortunately I am stuck at the last step with the error "unresolved external".
I have put the libs and includes in the correct folders with the compiler, and I have copied the dlls to the indicated location in the python folder, without success.
Maybe it's very simple to fix but I am not familiar with compilation and thus completely lost.

I would like to know if anyone encountered this issue and found a way to fix it.
Title: Re: sf.Text adding a symbol before text
Post by: Tank on May 25, 2015, 08:02:36 pm
I have the same issue. It's something with properly encoding the strings. I will soon have a look into that.
Title: Re: sf.Text adding a symbol before text
Post by: FrozenTux on June 16, 2015, 09:33:25 pm
Good to know it's an actual bug and not a Chair-Keyboard interface issue.
Did you make any progress concerning that problem ? Unable to modify and compile pySFML myself, I ended up falling back to python 2.7 for the time being.
Title: Re: sf.Text adding a symbol before text
Post by: Tank on June 19, 2015, 08:36:27 am
Unfortunately not, I'm currently busy with work stuff and won't have reasonable free time until mid/end of July. :(

Regarding building PySFML, have you tried to pip-install from the Git repository? It's what works for me all the time, and which is one of the easiest methods anyway:

Code: [Select]
pip install cython
pip install git+https://github.com/Sonkun/python-sfml
Title: Re: sf.Text adding a symbol before text
Post by: FrozenTux on June 20, 2015, 01:42:45 am
Unfortunately not, I'm currently busy with work stuff and won't have reasonable free time until mid/end of July. :(
No problem, we all have a lives :). I'll stick with python 2 for now, it works just fine.

Regarding building PySFML, have you tried to pip-install from the Git repository? It's what works for me all the time, and which is one of the easiest methods anyway:

Code: [Select]
pip install cython
pip install git+https://github.com/Sonkun/python-sfml

I was doing basically the same thing, that is to say cloning the repository and running setup.py install. The pip method produces the same error with less output.

More specifically, sfml.system, sfml.window and sfml.graphics build correctly, but when it reaches sfml.audio, the linker fails because there are "2 unresolved externals". I have uploaded the full output even if i don't think it tells a lot : http://hastebin.com/uwoxesebec.txt

What I have tried :

I have run out of ideas of other things to try. If you think of something I might have been doing wrong (even if it seems silly; it should be obvious by now that I don't know at all what I'm doing), feel free to push me in the right direction.

Anyway, thanks a lot for your continued support !
Title: Re: sf.Text adding a symbol before text
Post by: Tank on June 23, 2015, 09:49:15 am
Using a compiler which is recommended/required by Python would have been something I would have suggested to you, but you are already using that. So I'm kinda like out of ideas as well. :(

I will try to build it myself as soon as I have some time available, but like said, that can take some weeks. I guess until then, you are up on your own. ;)
Title: Re: sf.Text adding a symbol before text
Post by: GalakTozawr on December 19, 2015, 08:46:56 am
I have a problem problems with non-ASCII characters(russian languge). I use
#!/usr/bin/python
# -*- encoding: utf-8 -*-
import sfml as sf
import json
class draws:
    def __init__(self):
        with open('setting.json') as data_file:    
            setting = json.load(data_file)
        print
        self.window = sf.RenderWindow(sf.VideoMode(setting['window_width'],
                                                   setting['window_height']),
                                                   setting['title'])
        self.run()#bot
    def run(self):
        font = sf.Font.from_file("arial.ttf")
        text = sf.Text("Русский текст", font, 16)#this error string
        while self.window.is_open:
            for event in self.window.events:
                if type(event) is sf.CloseEvent:
                    self.window.close()
            self.window.clear(sf.Color.BLUE)
            self.window.draw(text)
            self.window.display()
if __name__ == "__main__":
    Tree = draws()
but i get error:
Console error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

I use unicode:
text = sf.Text(u"Русский текст", font, 16)#this error string
 
exelent, but wrong drawing literals. image error:
(http://i.stack.imgur.com/aMZpZ.png)

I use cp1253(russian decode)
text = sf.Text(u"Русский текст".decode('cp1253'), font, 16)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-6: ordin al not in range(128)

i use python 2.7 and pysfml 2.2 in exe installer
English text exelent draw. I now not see as this job.
You redactor replacement code, this link pastebin:
http://pastebin.com/nw04s6Ca
http://pastebin.com/Tyfae3RC
Title: Re: sf.Text adding a symbol before text
Post by: eXpl0it3r on December 19, 2015, 10:26:10 am
Does arial.ttf support these glyphs?
Title: Re: sf.Text adding a symbol before text
Post by: GalakTozawr on December 19, 2015, 04:54:35 pm
Yes, i get system font, this font support my languafe, i screen  view frontforge
(http://i.imgur.com/Dpko6Un.png)
I would be grateful for a solution to my problem.

Still, I can say that in front of me managed to forge change addresses of the Russian into English, but it does not solve my problem.
(http://i.imgur.com/nJgdls0.png)