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

Add Unicode fallbacks on Windows, prioritizing CJK fonts #70

Merged
merged 2 commits into from
Dec 30, 2019
Merged

Add Unicode fallbacks on Windows, prioritizing CJK fonts #70

merged 2 commits into from
Dec 30, 2019

Conversation

kjerk
Copy link
Contributor

@kjerk kjerk commented Dec 30, 2019

This PR replaces the default fonts on windows to add Unicode support. I noticed there were several problems on windows with any type of Unicode in the filename or path, spaces, etc. I've defaulted to builtin Microsoft CJK unicode fonts and fall back several layers though options and finally default to Arial which has okay Unicode support. I borrowed a Youtube video as a test scenario.

Tested On:

  • Windows 10 Professional Version 10.0.18362
  • Python 3.7.4

Before:
Won't execute, winds up with a stack dump.

Processing .\20190921 - こんにちは、ガチョウです #01【Untitled Goose Game】 - [NJBd1WA37ew].mp4...
Sampling... 16/16
Composing contact sheet...
Falling back to default font.
Falling back to default font.
    main()
  File "C:\Dev\Cloned\vcsi\vcsi\vcsi.py", line 1615, in main
    process_file_or_ignore(filename, args)
  File "C:\Dev\Cloned\vcsi\vcsi\vcsi.py", line 1589, in process_file_or_ignore
    process_file(filepath, args)
  File "C:\Dev\Cloned\vcsi\vcsi\vcsi.py", line 1746, in process_file
    image = compose_contact_sheet(media_info, selected_frames, args)
  File "C:\Dev\Cloned\vcsi\vcsi\vcsi.py", line 954, in compose_contact_sheet
    template_path=args.metadata_template_path)
  File "C:\Dev\Cloned\vcsi\vcsi\vcsi.py", line 865, in prepare_metadata_text_lines
    text=remaining_chars)
  File "C:\Dev\Cloned\vcsi\vcsi\vcsi.py", line 829, in max_line_length
    text_width = 0 if len(text_chunk) == 0 else metadata_font.getsize(text_chunk)[0]
  File "C:\Dev\Lang\python-3.7.4\lib\site-packages\PIL\ImageFont.py", line 120, in getsize
    return self.font.getsize(text)
UnicodeEncodeError: 'latin-1' codec can't encode character '\u3053' in position 11: ordinal not in range(256)

After Best Case:

> python C:\Dev\Cloned\vcsi\vcsi\vcsi.py -w 1024 '.\20190921 - こんにちは、ガチョウです #01【Untitled Goose Game】 - [NJBd1WA37ew].mp4'
Sampling... 16/16
Composing contact sheet...
Cleaning up temporary files...

Contact Sheet:
image

After Worst Case (Fallback all the way to Arial):
image

So at least in the worst case, you may wind up with missing characters, but you will still get your contact sheet.

@coveralls
Copy link

coveralls commented Dec 30, 2019

Coverage Status

Coverage decreased (-0.03%) to 31.843% when pulling e65e721 on kjerk:add-windows-unicode into c9f0a42 on amietn:master.

@amietn amietn merged commit c904a99 into amietn:master Dec 30, 2019
@amietn
Copy link
Owner

amietn commented Dec 30, 2019

Thank you! Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants