Text layout engine API for C++ - 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.

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!

Related

How to add support for printing into my C++ application

I have what seems like a simple task. I wrote a Windows application using C++. Now I need to add to it a capability to print forms -- nothing fancy, just plain text, with lines, tables, and simple graphics. Besides printing, a user needs to be able to preview on the screen all forms being printed.
Previously I was able to get away with this task by using an embedded Internet Explorer control and design all forms in HTML (which I like -- the HTML part.) But the problem comes with IE... hmm... I wish I had a nickel every time I heard that phrase :) Anyway, IE can print an HTML page but it does not provide any easy way for users of my software to customize page size, page margins, etc.
I spent a good deal of the last week trying to make IE Print Templates work with what I need ... but eventually failed. That stuff is very poorly documented and what I was able to do seems to randomly crash on me. So at this point I gave up on IE...
So my question to you -- is there a way to incorporate printing into my C++ program for the purposes like I described above?
If I remember correctly, printers have their own HDC, and you can draw on it. That'll work if have something simple. If you want to render HTML page using pure WinAPI, you're in big trouble.
I'd advise to abandon winapi and try GUI framework instead.
Qt 4(and 5, most likely) has text editor that can display rich text, layout engine for rich text, component that can display web pages. Read documentation a bit, and you will most likely find a way to render web page onto printer instead of screen. So far it looks like exactly what you would need.
Using Qt will add dependencies (20+ MB of DLLs for your project), but, IMO< it is a better idea than trying to use IE COM interfaces.
If you don't want to use Qt, you could try something like WebKIT, but I had some bad experiences with it, plus Qt might be just easier to use.
Additional info on printing: Printing with Qt.
Try searching for GDI, if you want to use win32 builtins.
Or use another toolkit like wxWidgets. Or consider writing to PDF with some library. Or let LaTeX do the heavy lifting - writing text files is easy. The LaTeX-way works as long as you don't want to modify your output depending on the layout (one Use-Case that doesn't work with LaTeX is the "balance" at the top/bottom of each page.)
Consider having your program generate XML files and using XSLT to render them into HTML.
By attaching stylesheets you will make it much easier to customize the presentation.

Code editor skins?

This is a kind of unorthodox question. Frankly, I won't lie to you. I am new to programming and am planning to improve myself. I enjoy coding but I need something to keep me going during the down times, so my question is:
Is there such a thing as a code editor skin? A compiler skin?
For example, you have the Command Prompt, it has a black background with white writing, it seems geeky, exactly what I want.
I want a compiler that looks like command prompt...black with white writing (or green) or still has color coding (some compilers change color of text based on command). Yes, this is mainly for boasting, but I don't want to show someone something that basically looks like a text editor, I just want something that looks a little cooler.
P.S (This question may seem a little unnecessary, it is because it is my first question, I'd like to warm up to this community before I start asking some real questions about code.)
Visual Studio is an editor/compiler etc that you can use to do C++ development, and it is highly themeable. You might be interested in http://www.phpvs.net/vs-themes/ and http://techietweaks.blogspot.com/2008/11/visual-studio-themes-gallery.html .
A text editor with a black background still looks like a text editor.
If you want a console-esque editor, look into vim and emacs - though they take some getting used to, once you're proficient with either they are pretty damn awesome.
I think you're confusing Compiler with IDE, the compiler is the program that converts your code into machine code/byte-code/etc.
The IDE is the editor itself, which usually works alongside the compiler.
For just text-editing you can use Notepad++. Then you can use the Style Configurator to change to default skins or make your own.
For a complete IDE, I recommend Code::Blocks especially if you're just starting out. You can change themes on Preferences.

Text Editor API. Scintilla for experimental IDE. Do you use something else?

I have discovered Scintilla/Notepad++ API this week end.
As there is a nice Template vcproj for Notepad++ Plugins available on line then I could start to play with some pseudo code-source really really fastly.
I have just looked briefly at the Scintilla documentation which expose the API which looks promising. Sometimes it is still hazy for me, sometimes not as feature-full as I expect/dream, but that's really meaningless details for now.
So now it is time I experiment with a language of my fancy, for the moment I nickname it "Entity". And what best to do than design a light IDE for it.
So I am going to invest much time in Notepad++/Scintilla environement.
I have have not thought about using Emacs because I never got accustomed to it.
But if you use another type of Text Editor API than Scintilla, preferably in C++ since it is my language experience... what other Text Editor API would you use/have you used ?
Just want to be sure of my choice before diving deeper.
I found Scintilla to be very feature-packed, and covered everything I needed. You have to do a bit of work to get all the functionality out of it (ensuring that keyboard short-cuts perform the desired effect, etceteras), but it was incredibly easy to compile, include and get working, though as I said you have to do a bit of legwork to get everything out of it, but this is better than having to tear your hair out getting an "all-purpose" control to stop doing something you don't want to. It is as if the authors have given you a toolbox to work with.

GTK theme engine: where to start?

I would like to start coding a gtk theme engine, but i'm wondering where i can find some documentation, if any exists.
I know how to have look at someone else engine's code, examples, or torture tests and widget factories etc.., what i want instead is any documentation type, design, references, examples or tutorials possibly from reliable sources such as the Gnome foundation or the like.
You know, when coding for the Win32 platform one can pinpoint reliable references on the subject by following the MSDN and then read a variety of other sources to see how the problem has been tackled, if any.
So, where to find an authoritative, reliable and possibly complete source of documentation about GTK theme engine development? Is there any for real?
Later added:
Also, how to debug such an engine? What's the most sane and painless way to perform testing and debugging on such a delicate os' ui component?
Well, you can look for instance at the source for the gtk smooth engine in Ubuntu most of which is in one fairly enormous C file smooth_gtk2_drawing.c. I don't know if that's an especially good example, but probably finding whichever looks simplest or most actively maintained would be a good idea.
A theme engine is typically used to change the shape of widgets among other things. If you're just trying to change the color scheme and so on, you just need to create a theme.
Just like the theme engines, theres not a whole lot of documentation when it comes to creating a theme either. However, there are a ton of examples at http://www.gnome-look.org

Simple Frameworks for Displaying Bitmaps and Handling Button Presses

We have a set of applications that basically display a bunch of bitmaps and text, then allow user to press "buttons" (certain bitmaps) that cause actions to occur.
We currently have these implemented using DirectX and a bunch of code to place the bitmaps and handle the button-presses. But we'd like to have the following features:
portable to Linux
some sort of "editor" that would allow us to lay out screens without hard-coding locations of elements in code
animation
we need to be able to overlay video
not resource intensive (these terminals don't have a lot of memory or CPU)
we're currently using C++, so management would prefer that, but other languages would be considered
We'd prefer a free, open-source solution, but would be willing to buy something if it is not too expensive. (We have a couple dozen developers, and tens of thousands of terminals deployed.)
We don't like the common GUI toolkits or widgets. We want something that has more of the look of a game than of a dialog box.
Any suggestions for off-the-shelf stuff we could use?
Maybe the way to go is something like Clutter or Allegro. If you check in this article at ArsTechnica what they are using Clutter for, you might get an idea how to use it. I don't know for sure if it works on Windows, but I'm pretty sure it does, considering it only depends on libraries that are supported under Windows.
You could try wxWidgets (it has wxBitmapButton) or try to implement your own solution using SDL for all of the graphics.
"We don't like the common GUI toolkits or widgets. We want something that has more of the look of a game than of a dialog box."
You realize that Trolltech's QT has a style sheet language for widgets? Take a look at their white paper, specifically page 60
http://trolltech.com/pdf/qt43-whitepaper-us.pdf
Going over your other requirements:
portable to Linux
Yes. Also supports Windows, Mac, and embedded environments.
some sort of "editor" that would allow us to lay out screens without hard-coding locations of elements in code
Qt's Designer is a very nice tool. I use it all the time.
animation
Qt supports this.
we need to be able to overlay video
Qt supports this.
not resource intensive (these terminals don't have a lot of memory or CPU)
This might be the fly in the ointment. You could check out Qt's embedded option. I've never used that myself.
we're currently using C++, so management would prefer that, but other languages would be considered
Qt is for C++ and works with all major compilers.
We'd prefer a free, open-source solution, but would be willing to buy something if it is not too expensive. (We have a couple dozen developers, and tens of thousands of terminals deployed.)
Qt has both open-source and closed source options.