No font for utf8 error on windows

I use wxPython on windows, whenever the program start, it shows this error:

image.png

I changed the text parameters for wx.MessageBox or wx.MessageDialogue from utf8 to unicode,

and it shows normal. But how can I fix this warning? Should I have to install another font?

···

http://blog.bukn.info

张慧聪 wrote:

I use wxPython on windows, whenever the program start, it shows this error:
...
I changed the text parameters for wx.MessageBox or wx.MessageDialogue from utf8 to unicode,
and it shows normal. But how can I fix this warning? Should I have to install another font?

Windows has never supported UTF8 very well. The right answer is to use Unicode in your Windows APIs.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

utf-8 is one of many encodings that support Unicode. And Unicode is not an encoding (or a font :slight_smile: ) – so what the heck is “Unicode” in this context???

Not questioning the solution – just the vocabulary that Windows(?) uses.

-CHB

···

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Windows APIs internally are all UTF-16. That's what Windows has called "Unicode" for the past 25 years, even though it does not literally cover the entire Unicode space.

Most Windows apps work with 8-bit strings (called "multibyte"). The 8-bit-to-Unicode mapping is called a "code page". The default Windows code page is 437, which is based on the characters in the original IBM PC. Fonts in Windows CAN be tied to a specific 8-bit encoding, although most are encoded as UTF-16. You can switch your default code page at the command line to a large number of different choices. Windows does support UTF-8 as a code page (65001), but there are things that don't work.

I agree that the error he saw is counterintuitive. I checked into the source code briefly to try to figure out why it was issued, but the reasoning in the code didn't make sense to me. If the font is TTF, then it should be able to map through Unicode (UTF-16). My best guess is that he's using a CJK font that has a limited character set.

···

'Chris Barker' via wxPython-users wrote:

On Wed, Dec 26, 2018 at 10:25 AM Tim Roberts <timr@probo.com > <mailto:timr@probo.com>> wrote:

    > I changed the text parameters for wx.MessageBox or
    wx.MessageDialogue
    > from utf8 to unicode,

    Windows has never supported UTF8 very well. The right answer is
    to use
    Unicode in your Windows APIs

utf-8 is one of many encodings that support Unicode. And Unicode is not an encoding (or a font :slight_smile: ) -- so what the heck is "Unicode" in this context???

Not questioning the solution -- just the vocabulary that Windows(?) uses.

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

The error seemed like a standard warning. Because it can issue in other evironment, not just wxPython/wxWidget. I grep wxPython code and see the warning text in every .mo file which under wxPython’s locale directory. I tried to modify the warning text in zh_CN.mo with vim(there a Chinese characters in my program). But the error report doesn’t change. I still don’t know how was it issued.

···

On Thu, Dec 27, 2018 at 7:13 AM Tim Roberts timr@probo.com wrote:

  'Chris Barker' via wxPython-users

wrote:

On Wed, Dec 26, 2018 at 10:25 AM Tim Roberts <timr@probo.com > > > wrote:

        > I changed the text

parameters for wx.MessageBox or wx.MessageDialogue

        > from utf8 to unicode,



        Windows has never supported UTF8 very well.  The right

answer is to use

        Unicode in your Windows APIs
        utf-8 is one of many encodings that support Unicode. And

Unicode is not an encoding (or a font :slight_smile: ) – so what the
heck is “Unicode” in this context???

        Not questioning the solution -- just the vocabulary that

Windows(?) uses.

  Windows APIs internally are all UTF-16.  That's what Windows has

called “Unicode” for the past 25 years, even though it does not
literally cover the entire Unicode space.

  Most Windows apps work with 8-bit strings (called "multibyte"). 

The 8-bit-to-Unicode mapping is called a “code page”. The default
Windows code page is 437, which is based on the characters in the
original IBM PC. Fonts in Windows CAN be tied to a specific 8-bit
encoding, although most are encoded as UTF-16. You can switch
your default code page at the command line to a large number of
different choices. Windows does support UTF-8 as a code page
(65001), but there are things that don’t work.

  I agree that the error he saw is counterintuitive.  I checked

into the source code briefly to try to figure out why it was
issued, but the reasoning in the code didn’t make sense to me. If
the font is TTF, then it should be able to map through Unicode
(UTF-16). My best guess is that he’s using a CJK font that has a
limited character set.

张慧聪 wrote:

The error seemed like a standard warning. Because it can issue in other evironment, not just wxPython/wxWidget. I grep wxPython code and see the warning text in every .mo file which under wxPython's locale directory. I tried to modify the warning text in zh_CN.mo with vim(there a Chinese characters in my program). But the error report doesn't change. I still don't know how was it issued.

It's in the wxWidgets source code, which is the C++ library that wxPython wraps. It's issued by wxFontMapper.:GetAltForEncoding, which gets called every time a new font is used. Is it possible you are selecting a default font that is not actually a TrueType font with full Unicode support?

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

张慧聪 wrote:

        The error seemed like a standard warning. Because it can

issue in other evironment, not just wxPython/wxWidget. I
grep wxPython code and see the warning text in every .mo
file which under wxPython’s locale directory. I tried to
modify the warning text in zh_CN.mo with vim(there a Chinese
characters in my program). But the error report doesn’t
change. I still don’t know how was it issued.

  It's in the wxWidgets source code, which is the C++ library that

wxPython wraps. It’s issued by wxFontMapper.:GetAltForEncoding,
which gets called every time a new font is used. Is it possible
you are selecting a default font that is not actually a TrueType
font with full Unicode support?

The warning shows whenever I start to run the program, and I didn’t do any select on font. I don’t know is there any global settings can specify default font for program. I specified specific font using wx.Font in every DC draw text calling, and everything works well. There were some mistake on wx.MessageDialog object, because I called dlg.SetOKCancelLabels(‘utf8str’, ‘utf8str’). The two labels showed unread code. After I change them to dlg.SetOKCancelLabels(‘utf8str’.decode(‘UTF8’), ‘utf8str’.decode(‘UTF8’)), it showed well.

···

http://blog.bukn.info

Problem solved.
I deleted the “encoding=‘UTF8’” inside wx.Font() call. The warning disappeared. Maybe windows don’t think the font I chose support utf8

···

http://blog.bukn.info

张慧聪 wrote:

Problem solved.
I deleted the "encoding='UTF8'" inside wx.Font() call. The warning disappeared. Maybe windows don't think the font I chose support utf8

It almost certainly does NOT support UTF8. Almost all TrueType font files are encoded in the "Windows Unicode" encoding, which means UCS-16. Yes, all UTF-8 characters (in the basic plane) can be translated into UCS-16, but that's not how the font is actually encoded.

This is a complicated topic. I'm glad you posted your answer, because that's likely to help someone in the future.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

张慧聪 wrote:

Problem solved.

I deleted the “encoding=‘UTF8’” inside wx.Font() call. The warning

disappeared. Maybe windows don’t think the font I chose support utf8

It almost certainly does NOT support UTF8. Almost all TrueType font

files are encoded in the “Windows Unicode” encoding, which means

UCS-16. Yes, all UTF-8 characters (in the basic plane) can be

translated into UCS-16, but that’s not how the font is actually encoded.

This is a complicated topic. I’m glad you posted your answer, because

that’s likely to help someone in the future.
Yeah, hope it helpful.

···

http://blog.bukn.info