PDA

View Full Version : Using fonts without X server



macbeth
31st July 2006, 12:54
Hello,

I am using Qt to draw some graphics and I want to use the application also form console, without X server running. The problem is, that when I call QPainter::drawText(...) on my QImage, I got runtime error saying

ASSERT failure in QFontDatabase: "A QApplication object needs to be constructed before FontConfig is used.", file text/qfontdatabase_x11.cpp

I can't construct QApplication, because then the application would not run without X server. I tried to construct QCoreApplication, but that did not help. So how can I draw text onto QImage without X server running?

Any advice appreciated...

macbeth
31st July 2006, 13:21
At first, the search didn't return any results, but now I've found a topic about it
here (http://www.qtcentre.org/forum/f-qt-programming-2/t-qpainter-in-console-apps-1758.html/?highlight=font)

...I think that nothing has changed since february, so the answer is probably sad: it is not possible...:(

If somebody knows about anything, please, let me know...

macbeth
31st July 2006, 14:16
Ok folks, that's what I thought up:
a) using an additional library, of course the first thing that crossed my mind
b) save the images of characters in png using alpha channel and resizing them according to the needs (may compromise quality and readability of text )
c) (somehow) save the rendered paths for every character and then used these saved paths

both b) and c) needs some preparation and loading extern resources to the app.

So my question now is: got an idea how to save QPainterPath so the application will be able to load it at startup?

Chicken Blood Machine
31st July 2006, 20:17
Ok folks, that's what I thought up:
a) using an additional library, of course the first thing that crossed my mind
b) save the images of characters in png using alpha channel and resizing them according to the needs (may compromise quality and readability of text )
c) (somehow) save the rendered paths for every character and then used these saved paths

both b) and c) needs some preparation and loading extern resources to the app.

So my question now is: got an idea how to save QPainterPath so the application will be able to load it at startup?

Indeed, you need a connection to an XServer in order to access the font information on that server. No XServer, no fonts.

As for (b) and (c), have you looked at QPicture?

macbeth
31st July 2006, 20:57
Indeed, you need a connection to an XServer in order to access the font information on that server. No XServer, no fonts.

I'm sure there are reasons for that, but it would be nice if there was a possibility of rendering text onto QImage or other QPaintDevice without x server...


As for (b) and (c), have you looked at QPicture?
Probably yes, but I forgot that it can be used this way. Thanks for the tip :)

Chicken Blood Machine
1st August 2006, 03:50
Have a look at TwinLib:

http://twinlib.roard.com/

It hasn't been maintained for a while, but it works with Qt3. Maybe you can port it to Qt4?

Kumosan
1st August 2006, 09:40
Ever tried to use QApplication ( int & argc, char ** argv, bool GUIenabled ) with GUIenabled = false?


Ok, might not help you either. At least not in Qt 4.1. Looks like Qt 4.2 might be your salvation:

int QFontDatabase::addApplicationFont ( const QString & fileName ) [static]

Added in 4.2

macbeth
1st August 2006, 10:33
Ever tried to use QApplication ( int & argc, char ** argv, bool GUIenabled ) with GUIenabled = false?

No, I used QCoreApplication instead. But I've just tried to use QApplication with GUIenabled=false and I got SegFault when trying to draw text on QImage...



Ok, might not help you either. At least not in Qt 4.1. Looks like Qt 4.2 might be your salvation:

int QFontDatabase::addApplicationFont ( const QString & fileName ) [static]

Added in 4.2

I'll try Qt 4.2 TP today and we'll see...

jpn
1st August 2006, 22:43
How about Qtopia Core? It could be one option too..