Automatic font selection

Started by
2 comments, last by Anon Mike 15 years, 4 months ago
I'm in the process of making my engine able to render text (with DX8) with any font found in Windows. If I for example want to render a Chinese character I can load "Microsoft YaHei" font which contains Chinese characters. While experimenting I hardcoded some strings in VC2005 for rendering with the engine. I noticed that I could also enter characters from any language into the source code. That is a little strange, because VC2005 uses "Courier New" font, which does not contain for example, Chinese characters. It must somehow find a different font to print out the text. Notepad does the same thing and I suspect most other applications do this aswell. How do they do that? Is this built into Windows and if so, can I access it?
Advertisement
I imagine that the OS handles it by default. But at a programming level, you could set several fonts for different code ranges. E.g. Characters 0x0000-0x00BF (ASCII) = "Courier New", 0x0F00-0x0FFF = "Microsoft YaHei" What you want to use is Unicode, since it's capable of displaying more than one codepage at a time.

Here are some good Unicode resources:
Unicode FAQ
Quick Unicode question
Standard UTF-8 decoder
That's exactly what I do now. I have a list of fonts and a list of unicode ranges for each one. I then search through the list when I need a character.
Later on I saw the behaviour I mentioned in other apps and I thought that maybe I could do that too somehow.
Windows has several different mechanisms that kick in automatically for apps that don't do anything special.
-Mike

This topic is closed to new replies.

Advertisement