This is a modified version of Font.py with the ability to request a font with a particular character set.
Further, the font name is now optional, and defaults to None. The effect of this is that the system will attempt to locate a font based on the properties passed in. Of course, you can still specific a font by name, but you don't have to.
The new optional charset parameter (default None), can be the integer used by windows to identify the charset (as per wingdi.h), or a string. If a string is passed, then it is mapped to the integer in wingdi.h that best matches. For convenience some alternate names for the same charset are provided. The full list can be seen in the Font.py code in the CharsetMap dictionary. If a string isn't recognised, then no exception is thrown, but the default charset is used.
With these changes, the following code is possible:
font = gui.Font( charset='shift-jis' )
font = gui.Font( charset='japanese' )
font = gui.Font( charset='128')
^^^ all these 3 produce the same result
font = gui.Font( name='Tahoma', charset='default', size=12 )
Feel free to do what you like with these changes.
Richard
Logged In: YES
user_id=41028
Originator: YES
Oops. There's a mistake in the 3rd line of example code above.
font = gui.Font( charset='128' ) # <-- this will not find a matching charset, so will use the default
font = gui.Font( charset=128 ) # <-- is the correct way to manually specify the charset
Logged In: YES
user_id=1638908
Originator: NO
Hi Richard,
The api you suggest seems very intuitive and flexible !
Thanks a lot for your contribution, it'll be a pleasure to integrate it in the next release :)
Best regards,
Alex
Logged In: YES
user_id=1638908
Originator: NO
Richard,
Your patch is now intergrated into ppygui svn,
and will be available in the next formal release :)