   Text rendering on CPU
  Referring to this thread from a while back:Quote:Original post by YannLRendering bitmap fonts on the CPU is dirt cheap, and vector fonts aren't slow either. Both are highly multithreadable. And since text usually doesn't change multiple times per frame, it's a rather low frequency operation. It's a waste to use GPU geometry shaders or similar to recomposite something 60 times per second that changes once every ten minutes or so.Just render all text on the CPU (if possible in parallel to the GPU doing something else) into a cache texture, and upload the new data on-demand to the GPU. The latter would then render entire words or rows using a single quad.I am in the process of re-writing a GUI toolkit, and am considering moving all GUI rendering to the CPU, because: a) I have 3/4 cores sitting idle, b) my OpenGL fonts performs terribly and look worse, c) complex layout and clipping is a pain in forward-thinking OpenGL, and d) I would like the toolkit to be independent of 3D rendering API.So I wonder if any of you have suggestions for a lightweight shape, bitmap and text rasterisation library?I have looked at both Cairo and Skia, which seem to be the de facto standards in this area, but neither is particularly lightweight, neither has much in the way of support for text layout, and both are a pain to build on windows.Cairo + Pango seems the most robust option for text layout, but one gives up any semblance of lightweight, and building for Windows becomes that much harder. On the plus side, you get at least a modicum of support for languages like Chinese and Arabic that require complex shaping and alternate layout directions (not that I really need that at this stage, but would be a nice bonus).Any suggestions for something lighter? The text layout is the main concern - I can roll my own shape/image rasteriser if necessary.   
  For windows, I had played a bit interfacing Uniscribe for layout and FreeType2 for the rendering. At a certain point, Uniscribe gives out glyph indices which fetched to FreeScribe produced the intended glyph. Although this was expected, I have tested only a few things before changing my mind so I cannot guarantee it will work in general, although it (very) likely will.That way, you still have to use Cairo-Pango for layout on non-win32 platforms. Are you sure you truly want to rasterize yourself? Rasterizing text is far more complex than arbitrary geometry, as long as hi-quality text is required. Hinting/grid fitting is non-trivial.   ;  Well, we use our own bitmap font rasterizer. We don't support vector fonts at this time beyond an experimental build, because there wasn't really any need for it.Writing a rasterizer for bitmap fonts is obviously easy. Ours splits the text to render into n substrings, where n is between 1 and the number of currently idle CPU cores, and mostly depends on the length of the string. We then try to find suitable locations in the text cache texture that will accommodate each substring. A new cache texture is created if no place was found. A SIMD optimized rasterizer is then launched on n threads, each rendering its substring directly into the respective cache texture location. The GPU is instructed to PBO the modified parts into VRAM, and we're done.This rather basic architecture performs extremely well, even if the entire screen is covered with UI elements. The hard part is handling layout and non-Latin scripts. To be honest, we don't have a lot of support for either. Beyond Latin, we support Cyrillic and Greek (these are obviously straightforward if your text system is Unicode based), and Chinese through a lot of obscure and very ugly hacks. We don't support RTL scripts, such as Arabic or Hebrew. I don't even dare to imagine what a pain in the ass it would be to add those.So yeah, using an external layout and rendering library can be a good idea. Especially for scalable vector font support, which you really don't want to write yourself. Unfortunately, I'm not aware of any lightweight ones. Cairo, Pango and optionally Freetype are actually pretty good, and you'll get support for all the weird scripts around. However, as you mentioned, they're monsters and Freetype is quite slow on the rendering side. I don't think it is or can be multithreaded in a reasonable way.In the end, it depends on what your needs are. We decided to go for our own minimalistic bitmap font-only renderer, because we aren't building a word processing or publishing application that would require high quality typography or advanced layout features. We wanted raw speed at reduced flexibility. Licenses are also worth considering. We weren't allowed to use anything LGPL related, which rules out the above mentioned tools. That might or might not be a problem for you. The software we develop is a rather specific niche market product, and so most of our users from "weird script countries" will be happy to use the english version. But then again, hacking in Chinese was really bad.For simplicity, and if the LGPL is not a problem for you, I would suggest trying Cairo+Pango. If your caching system is good and the GPU uploads are layered correctly, it's unlikely to become a major performance bottleneck. And it's still going to be orders of magnitude faster than a plain OpenGL "little quads ala NeHe style" renderer ;)Sorry to not be of any more help.   ;Quote:Original post by Yann LWell, we use our own bitmap font rasterizer. We don't support vector fonts at this time beyond an experimental build, because there wasn't really any need for it.That seems a very sensible architecture, and not bad for western languages at any rate. I am certainly not adverse to adding FreeType as a dependency to gain access to unicode glyphs for basic foreign language support.Quote:We don't support RTL scripts, such as Arabic or Hebrew. I don't even dare to imagine what a pain in the ass it would be to add those.Direction isn't even half the problem. Writing a layout manager for right-to-left (or even vertical) writing systems is only moderately hard, but the support for the connections between consecutive cursive characters in Arabic/Indic is mind-bogglingly complicated. If you need to support these, and you have a license incompatibility, you might consider using HarfBuzz directly - it is the layout engine underlying pango these days, and is itself licensed under far more liberal terms.Quote:Cairo, Pango and optionally Freetype are actually pretty good, and you'll get support for all the weird scripts around. However, as you mentioned, they're monsters and Freetype is quite slow on the rendering side. I don't think it is or can be multithreaded in a reasonable way.Ja, that is the way I am leaning. If I can get the whole bundle to function correctly in a Windows/Visual Studio toolchain, I think using full-featured libraries will save a lot of grief down the line...   