Unicode and Bitmap Fonts
We will have access to
System.Text with unicode on the Windows platform. But for cross-compatibility, a bitmap font should be used, right? Or do you have something up your sleeve?Bitmap fonts are great, because you don't mess up your layout with them, but to make international programs, supporting Asian languages, would be hell if I had to texturize every Japanese and Chinese pictogram.
Will there be some solution? Maybe integrated into the Content Pipeline? I understand if there won't be in the beta, but what about the final product?
I think they have to have something up their sleeve, they will be giving us this CPL (content pipeline) that will make getting things into our projects easy. Why make just putting up words more work.
As we haven't completely locked down our feature set we can't guarantee, but I think we'll have something in the XNA Framework Content Pipeline to help you out. You'll aslo see some examples of how Spacewar is doing this outside the XNA Framework Content Pipeline.
Thanks!
I would suggest the following solution:
- Create a DC (can be some offscreen via CreateCompatibleDC)
- Select a true-type font into it
- Loop for every character:
+ Begin a path -> BeginPath
+ Render the character -> TextOut
+ End the path -> EndPath
+ Flatten the path -> FlattenPath
+ Do another loop calling the GetPath function (respect PT_LINETO and PT_MOVETO)
+ Feed this into a triangulator (hint, hint, hint GLU tesselators can be used without a GL context
hehehe)
+ Get back the triangulated data
+ Continue the "character loop"
Save the polygons, and a simple char-to-offset-into-polygon-array-mapping-table with it.
Voila, scaleable true-type fonts ready to pump out to the device 
Just check out windows GDI... it's simple as eating donuts.
I wrote about this on my blog yesterday, and finally got around to posting some followups to it earlier this evening. There are two posts:
One Codepage to rule them all : Unicode, C#, XNA & Fonts
Creating and using bitmap fonts in XNA
and a longish article about how to use the font creation tool:
Creating Bitmap Fonts using bmfontgen
These should answer some of your questions WRT using Unicode bitmap fonts in XNA.
The executive summary:
I wrote a tool (bmfontgen) to create bitmap fonts from Windows fonts.
It only supports Unicode encodings.
It was specifically designed to work with XNA.
You can create fonts with more than 256 characters.
You can select the characters that are included in the font via specified ranges (e.g., 0400-04FF to support Russian) or by specifying a file (e.g., include all the characters found in this UTF8 file).
You can override individual characters with custom glyphs.
I made available a class (BitmapFont.cs) that loads these fonts and exposes a DrawString interface.
There is sample code available showing how to use the BitmapFont class.
The ability to specify ranges allows you to choose which languages you want to support. The ability to specify a file and automatically include all the characters is useful for Chinese/Japanese/Korean since you can point it at a file containing your dialog script and the font will contain only the characters needed for your game.
The known limitations are that it doesn't support ligatures or surrogates and there is no special support for bi-di scripts (Hebrew, Arabic, ...). I may remove these limitations in a future version if there is a need.
So, this is a solution, but it's not an official XNA release nor is it integrated into the Content Pipeline. It is, however, available for the beta ^_^.
Well, I assume that it will simply eventually become an official converter for the content pipeline, which is an excellent idea. Your implementation appears to be pretty sound, too, although it might be possible to optimize your BitmapFont class a bit.
Anyhow, will these Microsoft supplied converters like bmfontgen be any kind of open source, so we can modify them at will?
One thing that I'm considering adding to BMFontGen/BitmapFont is support for a binary version of the font so that you don't have individual XML and PNG files that can get separated. This would also eliminate the need to parse the XML when the font is created.
There are currently no plans to release the source to BMFontGen (however, that might change in the future). If you need it to do something that it doesn't currently do, let me know.
Well, that's a good idea, but in that case you should allow for another step to convert the png to some suitable raw texture format first, such as a RGBA4444 texture (DXT isn't good for fonts, and colors might be needed for replaced glyphs), before mashing it together with binary font data. If the texture stays as png you still deal with the decompression time (although with today's CPU:s that may not be significant).
Actually, since your converter supports both replacing glyphs with bitmaps and kerning, I can't really think of anything else I'd need, so open sourcing this particular converter isn't all that important. It would still be nice though.
It would also be cool to be able to draw colored text, while NOT coloring replaced glyphs, so I could for example print yellow text that still draws the replaced glyphs representing for example xbox buttons in their right colors. That could easily be accomplished with a per-glyph flag that says whether it [has been replaced and contains color], or not.
I'm still trying to figure out what exactly to do with a binary format. I wasn't considerig supporting anything except PNG, but I'll look into some of the raw formats to see if it makes sense to include them. Note that the option to create separate XML/PNG files will still be available.
I like the idea of turning off color for the custom glyphs. I'll add a parameter to the -custom option in BMFontGen.exe to force the glyph to be displayed in "White" (ie: ignore the current font color when drawing the glyph). Thanks for the suggestion!
Well, it probably isn't very important to have a super-duper efficient format for fonts, as most games will only use 2 or 3, maybe 4 different bitmap fonts. To have more than would just look incoherent and bad.
Thanks for implementing my suggestion, I really like this new open attitude with early betas and community feedback that some divisions of Microsoft are using.
[EDIT: And I really need to stop prefixing all my posts with "Well, "] :P
hi gray
Can you tell me, how can i convert any Font (Suppose Hindi) into unicode in .Net?.
hope for positive response.