tags:

views:

412

answers:

1

I've been struggling for a while with the text rendering in GDI+. We are dynamically generating images of headlines but there seems to be a lot to whish for in the library. I can set the font, font size and a few other things but I cannot control row height or letter spacing.

I have built my own class that takes a generated text image, cuts out the individual rows of text (the settings for each font is manually encoded into settings files) and reassembles them with a the row height I want. I haven't been able to solve the same problem for letter spacing though.

Does anyone have a solution for this or a recommendation of a library (OS or commercial) that solves this?

+1  A: 

I don't know if this will be applicable to your solution, but in the past when I needed to render out some more sophisticated text and I wanted to have a fair amount of flexibility in how it would be rendered, I used this library:

http://www.terrainformatica.com/htmlayout/main.whtm

It's not open source, but it is free...

Alternatively, in the game space I've used bitmap fonts extensively - if you store out information such as character spacing, etc it can look exactly the same as a TTF, but you loose the ability to scale it much without introducing some decent artifacts. To get a better feel for this approach, here's a tool for building the fonts:

http://www.angelcode.com/products/bmfont/

Hopefully one of those gives you some help - either one will give you control over character spacing and row height, but they also have their limitations.

Mark
Thanks for the answer. The second link might be exactly what I'm looking for (I'll check it out a bit further before marking the answer as accepted though :). The first one I didn't quite get though. Maybe I'm just plain stupid but as I understood that was a system for rendering HTML out of the browser?
Johan Öbrink
That's correct, HTMLayout is an HTML rendering component, but you can just render it into an offscreen buffer and use that... In that way you just prototype your text is HTML with the printed text being something that you search and replace with the text you actually want to display. It gives you more flexibility since you can do it via CSS and have very specific control over how it's displayed.
Mark
One other thing, if you are going down the bitmap font path, and you decide that you do need scaling, there's a technique called Alpha-Tested Magnification that works REALLY well - here's the whitepaper from the Valve guys on it:http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdfUsing this technique keeps the font edges nice and crisp as it shrinks and scales.
Mark
Since you're more interested in the bitmap font approach, here's a link that goes into more detail, and includes code, etc:http://www.geocities.com/foetsch/bmpfonts/bmpfonts.htm
Mark