Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Non-ascii 8-bit string handling #494

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

Merged
merged 2 commits into from
Sep 30, 2011

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Sep 26, 2011

This is an alternative solution to pull request #492.

The unicode() call in is_math_text() is strictly unnecessary to get things done, but it provides an important early warning to the user that they are probably doing something wrong (and is_math_text is called on all "displayed" text in maplotlib, so it's a convenient place to do this check).

If the user passes in any non-ascii 8-bit string, the encoding is "unknown" (one can assume for particular locales and platforms, but not in the general sense), and therefore since the encoding is very likely to not match the font selected, we may get the wrong or missing characters in the output, therefore raising an exception is the right thing to do. Think of this as shorthand for:

if not is_unicode(s) and [s contains codepoints > 127]: throw

A lot of this confusion goes away in the Python 3 world.

This pull request improves the error message when the user passes in an 8-bit string containing non-ascii characters.

It also fixes a bug in font_table_ttf where it is passing non-ascii characters in an 8-bit string rather than using Unicode.

efiring added a commit that referenced this pull request Sep 30, 2011
@efiring efiring merged commit 7514e3e into matplotlib:v1.1.x Sep 30, 2011
@mdboom mdboom deleted the font_tables_ttf_bug branch March 3, 2015 18:43
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.

2 participants