Hangar's picture

Multiple fonts.

Is there already a good way to lay out multiple fonts in the same box of text? I want to get different styles, like bolding.

The best I can figure is to divide it into a series of "runs": groups of text + meta information (font, color) then lay it out one line at a time. If there's more than one font in a line with different sizes, I adjust so that the base line matches up and then also do the horizontal alignment manually. My question is if there are any real problems with this approach.

I have to use MeasureString to get the number of characters consumed on a line. Is there a way to get this info from MeasureCharacterRanges instead? And why do you P/Invoke instead using of the version in System.Drawing?

Also, I'm worried about things like bidirectional layout, spacing, and positioning different fonts next to each other. Do you see any gotchas?