Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unicode paths for Font() and saved images #649

Merged
merged 13 commits into from Dec 2, 2018
Merged

Conversation

@dlon
Copy link
Member

@dlon dlon commented Nov 29, 2018

fopen() doesn't work for unicode paths on Windows. As a result, saving surfaces to images and loading fonts could fail.

Fixes #645 and #196.

  • test unicode paths
  • ftfont: accept unicode paths too
@dlon dlon added the Windows label Nov 29, 2018
@illume
Copy link
Member

@illume illume commented Nov 29, 2018

Nice one :)

Here is a test...

>>> import pygame
>>> pygame.font.init()
>>> from pygame.tests.test_utils import example_path                                          
>>> import os
>>> import tempfile                                                                           
>>> import shutil
>>> tmpdirname = tempfile.mkdtemp()
>>> try:
...     newfontpath = os.path.join(tmpdirname, u"运城国际学校.ttf")
...     pgfont = example_path('data/sans.ttf')  
...     shutil.copy(pgfont, newfontpath)  
...     pygame.font.Font(newfontpath, 20)  
... finally:
...     shutil.rmtree(tmpdirname)

I guess we can't use the python io.open for this?

@dlon
Copy link
Member Author

@dlon dlon commented Nov 29, 2018

I guess it's possible: open() -> PyObject_AsFileDescriptor() -> fdopen(). Also, there's this in CPython:

/* Open a file. Call _wfopen() on Windows, or encode the path to the filesystem
   encoding and call fopen() otherwise.

   Return the new file object on success. Raise an exception and return NULL
   on error.

   The file descriptor is created non-inheritable.

   When interrupted by a signal (open() fails with EINTR), retry the syscall,
   except if the Python signal handler raises an exception.

   Release the GIL to call _wfopen() or fopen(). The caller must hold
   the GIL. */
FILE*
_Py_fopen_obj(PyObject *path, const char *mode)

https://github.com/python/cpython/blob/master/Python/fileutils.c

@dlon
Copy link
Member Author

@dlon dlon commented Nov 29, 2018

There's an issue with the CI: error: can't copy 'test\fixtures\fonts\?????????.bdf': doesn't exist or not a regular file

@illume
Copy link
Member

@illume illume commented Nov 29, 2018

Hrmm. I guess that is distutils Windows code not able to handle that filename.
It works locally for you? Might be easiest to work around that bug.

Seems to pass on travis Linux, and Mac.

@dlon dlon force-pushed the dlon:fopen-fix branch 3 times, most recently from 51323b4 to c8100ec Nov 30, 2018
@dlon dlon force-pushed the dlon:fopen-fix branch from c8100ec to 8e5df15 Nov 30, 2018
@dlon dlon force-pushed the dlon:fopen-fix branch 2 times, most recently from 086aebc to 81fbaf8 Dec 1, 2018
@dlon dlon force-pushed the dlon:fopen-fix branch from 81fbaf8 to a191a8c Dec 2, 2018
@dlon dlon changed the base branch from master to unicode Dec 2, 2018
@dlon dlon merged commit 646f541 into pygame:unicode Dec 2, 2018
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@dlon dlon deleted the dlon:fopen-fix branch Dec 2, 2018
@dlon dlon mentioned this pull request Mar 23, 2019
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants