gtkgtk3pangocairo

can I use GtkTextView widget without gtk_init() / gtk_main()?


I currently use cairo/pango to generate raw image data from dynamic text. My application is not a Gtk+ GUI app, just a native C++ headless video server. Using dynamic text, I generated raw images for overlays and then alpha blend them over the video streams the server processes and distributes via the network. There is no text editing involved for this text, but given text I generate a corresponding image overlay suitable for alpha blending.

However, I need more formatting flexibility (indents, center alignment, etc). Doing extensive formatting in cairo/pango is painful.

I have been looking at the GtkTextView/GtkTextBuffer API and I think it has easier formatting using GtkTextTag. These widgets obviously have extensive editing capabilities but I only need the formatting capabilities.

Question: can I use GtkTextView/GtkTextBuffer/GtkTextTag without running the main gtk+ loop via gtk_init()/gtk_main() ?

Question: how do I get a reference to the raw formatted buffer (cairo image surface or widget pixbuf) after all of the tags have formatted the text?

I have been using the gtk_widget_get_pango_context(), pango_layout_new(), gtk_widget_create_pango_layout(), routines but get all sorts of errors because there is no screen.

Edit: Additional Info: what I am trying to do is essentially use only the GtkTextView/GtkTextBuffer/GtkTextTag routines as a sort of standalone library for generating image data of rendered and formatted text.

Thanks, -Andres


Solution

  • Basically no. You can't use Gtk without init() and/or mainloop(). Why? Because any drawing event is queued and is only drawn in the idle loop. Without mainloop() you don't have any idle time.

    On the other hand, you are jumping from low-level drawing in Cairo to Widgets in gtk (which uses Cairo at a low level). There are many intermediate solutions which you could consider. You could generate Latex and compile it. Markdown can take of simple formatting. There's HTML of course, where you can even use CSS, and render it to about anything.