Finding System Font Files?
I’m writing an application which combines OpenGL and Qt. I’m using another library (FTGL) to plot text in an OpenGL viewport. Now, to load a font in FTGL, I need to supply the filename of the font, this is where the rubber hits the road. Is it possible to map a font family/face to the file it came from using Qt (possibly QFontDatabase)? Or will I have to find the font files myself and use Qt to interrogate each file individually the get both the information QFontDatabase can give me, plus the filenames? If this is the case, is it possible to determine the system font directories using Qt? Thanks.
Hello ,from my mind i am using “Nokia Sans” family name. setFamily(“Nokia Sans”) in the QFont to set it.
i am wondering also if the font() from the painter , i mean
- void GLWidget::draw()
- QPainter p(this);
return the default font from the system.
@mohsen This seems like the only way to go, but a bit inneficient and moving a ton of fonts, some which may fall under copy protection a bit of an issue. It would seem the best alternative would be to acquire the operating systems font directories – I’ll look into doing this externally to Qt, if anyone else has any suggestions or ideas on this front, I’d greatly appreciate your input.
As far as I remember it, Qt relies on the operating system/window system facilities for getting the fonts and does not open the files itself.
Ah okay, well that might mean I’ll have to write my own methods for acquiring the system fonts list. I’m honestly not entirely sure how dependent Qt is on win32 or the host operating system whatever it may be, weather it just acquires a rendering context and makes everything look pretty from there, or something else. I’m familiar with FreeType, and have used that in the past (and am now) used it to load and render fonts, does everything you could need.
The fonts directory is a sticky point, I’m going to produce something similar to what QFontDatabase provides, but with a mapping to the files a particular face/family combination came from. How the directories will enter into this, remains to be seen.
Hi, just have stumbled on QDesktopServices::storageLocation [doc.qt.nokia.com] and I hope it will help you. But I didn’t try it myself, though.
QDesktopServices::storageLocation [doc.qt.nokia.com] and I hope it will help you. But I didn’t try it myself, though.Hi, just have stumbled on
Unfortunately this gives you only the location for the user fonts, not the system fonts :-/
Not necessarily a Unix issue, more of a Unix/Linux flavour. Most of them have some font dir in the user’s home dir because writing to the system directory is forbidden for many of the users (no root password!). On my old KDE box it’s in $HOME/.fonts. The new linux/freedesktop standards may set it different!
Mac OS X does have a user font dir too: $HOME/Library/Fonts.
ixSciixSci, great find, thanks!
Volker, the users font directory is largely sufficient, the system fonts directory can be picked up by navigating from root. If the user knows enough to move it, then he should be smart enough to specify where he moved it to in the settings/directories dialog of my application :).
I should also add, there is no notion of user fonts on a windows PC. There is however, System and user fonts on Unix, and on OSX there is a third concept, network fonts. I aim to support all concepts as much as possible, however system fonts is the minimum target at this time.