开发者

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 coul开发者_JS百科d 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.


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 :)


If you want something lower level (and with fewer dependencies than Qt or Pango) you can use FreeType directly. It will take more lines of code to draw the same text (here's their first example1.c) but it might be less than the lines of Makefile required to bring in Qt!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜