Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text layout engine API for C++

I have a project where I need to take input text and render it to an image. The text needs to be wrapped, have margins, kerning, letter spacing, specific fonts, and so on. It seems like I could write most of this by hand, but it also seems like something that there should be pre-existing libraries for.

I've looked at web rendering engines like WebKit and Gecko that seem too complex, LaTeX doesn't seem to have a C++ API, GhostScript looks the most promising so far.

I'm writing the app in C++, and I don't want to have to shell-out to a system call--it seems like that will be inflexible and non-performant. It needs to run on Linux, and preferably Mac OSX too.

Thanks for any advice you can offer.

like image 604
Ian Avatar asked Sep 05 '26 05:09

Ian


1 Answers

Subprocesses can be pretty awesome, but I guess you are looking for something like pango or the font rendering engine in Qt. It looks like you can achieve everything you need with QPainter::drawText(...). See also QFont.

It is worth noting that I have dragged in Qt specifically for font rendering before, without using it for anything else. It needs you to create a QCoreApplication-object, but that's it. Works like a charm :)

like image 164
Magnus Hoff Avatar answered Sep 07 '26 18:09

Magnus Hoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!