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

Unexpected results from .pcf font for chars >128 #505

Closed
wiredfool opened this issue Jan 28, 2014 · 1 comment · Fixed by #517
Closed

Unexpected results from .pcf font for chars >128 #505

wiredfool opened this issue Jan 28, 2014 · 1 comment · Fixed by #517

Comments

@wiredfool
Copy link
Member

This is likely a unicode issue somewhere.

In Py2.x, results are as expected. In Py3.x, the high ascii characters are not printed as expected.

excerpted and modified from test_font_pcf.py

fontname = "Tests/fonts/7x13-ISO8859-5.pcf"
tempname = tempfile("temp.pil", "temp.pbm")

def test_draw():

    message = str("".join([chr(i+1) for i in range(223)]))

    font = ImageFont.load(tempname)
    image = Image.new("L", font.getsize(message), "white")
    draw = ImageDraw.Draw(image)
    draw.text((0, 0), message, font=font)
    image.save('chars.png')

Incorrect:
incorrect
Correct:
correct

The generated temp fonts are the same, It appears to be an issue in the rendering.

This was reported in IRC by AleXoundOS, hoisted here to document.

@wiredfool
Copy link
Member Author

The essential problem here is that a unicode string (in python 3) is interpreted as a string that is a series of bytes (in the c-api). I believe that the solution, especially for the old, 256 character non-unicode aware fonts, is to convert the incoming string into a latin-1 encoded bytes object, which should be easily used as a uchar *.

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 a pull request may close this issue.

1 participant