January 4, 2011

LiamMaru LiamMaru
Lab Rat
63 posts

Finding System Font Files?

 

Hey All,

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.

12 replies

January 4, 2011

dguimard dguimard
Lab Rat
61 posts

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
http://doc.qt.nokia.com/latest/qpainter.html#font void

  1. void GLWidget::draw()
  2. {
  3.     QPainter p(this);
  4.     p.font();
  5.  
  6.  
  7. ......
  8. ...

return the default font from the system.

January 4, 2011

peppe peppe
Ant Farmer
1026 posts

What that reply has to do with OP’s issue?!?

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

January 4, 2011

dguimard dguimard
Lab Rat
61 posts

humm sorry misunderstanding

January 4, 2011

Mohsen Mohsen
Robot Herder
730 posts

you may copy every needed font in a directory of your choice and use that path for your reference.

 Signature 

www.madagon.com

January 5, 2011

LiamMaru LiamMaru
Lab Rat
63 posts

@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.

January 5, 2011

Volker Volker
Robot Herder
5428 posts

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.

January 5, 2011

LiamMaru LiamMaru
Lab Rat
63 posts

Volker wrote:
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.

January 9, 2011

ixSci ixSci
Lab Rat
203 posts

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.

January 10, 2011

Volker Volker
Robot Herder
5428 posts
ixSci wrote:
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.

Unfortunately this gives you only the location for the user fonts, not the system fonts :-/

January 10, 2011

ixSci ixSci
Lab Rat
203 posts

Volker, I just have tested it and it gave me C:\Windows\Fonts. As long as I know there is no such a notion as user fonts in Windows. Is it there a user fonts notion in unix family?

January 10, 2011

Volker Volker
Robot Herder
5428 posts

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.

January 21, 2011

LiamMaru LiamMaru
Lab Rat
63 posts

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.

 
  ‹‹ Has Aero been implemented in Qt 4.7?      QFtp with unicode ››

You must log in to post a reply. Not a member yet? Register here!