3 ms·
You can do that! I've done it. I tapped into Uniscribe on Windows, Core Text on macOS, and PangoCairo on Linux. The problem is that this looks horrifically inco
by klodolph 6y ago
You can do that! I've done it. I tapped into Uniscribe on Windows, Core Text on macOS, and PangoCairo on Linux. The problem is that this looks horrifically inconsistent between platforms. You also end up doing a ton of work to figure out how to accomplish a simple task like, "I want this text in this box, that word is italic, please add the line breaks, here is a font file." That's simple on one platform, but you end up having to duplicate everything you do across all the platforms you support, and typically you will find one platform that breaks your assumptions about how libraries should handle this task. Your code ends up being convoluted so it can hide the (major) differences between different APIs.
It's actually so much work that you probably want your game engine to do it internally in a way that is consistent cross-platform. Fortunately, most of the guts have already been figured out for you by the amazing people that work on HarfBuzz. The basic formula is to take your Unicode string, take your font, and feed it to HarfBuzz to have HarfBuzz figure out the metrics and glyph offsets. You then use the metrics to do layout and line breaks.
It is a lot of work, but it turns out to be less work than figuring out how to this working cross-platform using system libraries. This is also, generally speaking, how web browsers deal with their text. There are a couple other pieces that you need like text segmentation but these are tractable.