PDA

View Full Version : unable to find font when placed under lib/font dir



menkey18
12th December 2012, 17:13
Hi Advanced Qt users,

I am trying to display UTF-8 characters on my app ui,
I have downloaded the .ttc font file and placed in under /path_to_Qt/lib/font/

The problem is that the font is unable to be found, the app simply leaves the area blank.

I have complied the qt-everywhere lib as shared libraries, and dynamically link it to my app.
One thing I did notice is that I have modified my $LD_LIBRARY_PATH , should I change it to my Qt lib path?

I have tried qt.conf file, but I am not able to get it work.
I have printed the font families available from QFontDataBase, it is unrelated to the font files in /path_to_Qt/lib/font/

At the end of the day I found one font from the given font family list, it works but looks distorted.

Cound anyone tell me how am I able to find the configured font path, and how to change it please?

Thank you very much in advance.

Lan

menkey18
13th December 2012, 04:02
For more info, shown below are the font families available, dumped using QFontDatabase.
I am not sure where is the path to these fonts, and how can I modify the path to include new fonts.

I have compiled qt-everywhere with shared libraries.
And I am using ubuntu 12.04 64

Fonts:

(
"Bitstream Charter",
"Clean", "Clearlyu",
"Clearlyu Alternate Glyphs",
"Clearlyu Arabic",
"Clearlyu Arabic Extra",
"Clearlyu Devanagari",
"Clearlyu Devangari Extra",
"Clearlyu Ligature",
"Clearlyu Pua",
"Courier 10 Pitch",
"Fangsong Ti",
"Fixed [Jis]",
"Fixed [Misc]",
"Fixed [Sony]",
"Gothic",
"Mincho",
"Newspaper",
"Nil",
"Song Ti",
"Standard Symbols L"
)

ChrisW67
13th December 2012, 06:03
The system will typically only look in specific paths for fonts. On my machine these are /usr/share/fonts, /usr/local/share/fonts, and the user's own ~/.fonts directory. Ubuntu may do it differently, but you could look for a file fonts.conf in the /etc directory or a subdirectory and read it.

Try putting the ttc file into ~/.fonts, running fc-cache ~/.fonts, then running fc-list | grep -i yourfontname to see if your font is there.

menkey18
13th December 2012, 14:02
Hi Thank you for your reply.

I have tried your solutions. clearly the library I compiled as shared libraries didn't use any of these paths: /usr/share/fonts, /usr/local/share/fonts, ~/.fonts

There is another Qt build which have installed from the software centre, this build will use /usr/share/fonts as font directory.

I am still confused how Qt finds it's font path.

I found QPlatformFontDatabase, which suggests that I can overwrite the findDir() function to redirect to my own directory.
But I am unable to compile the class, which reports an error: QtGui/private/qfort_p.h is not found.

I think if I can look into the mechanism how Qt searches for font paths, and understand how to provide a path for the fonts, that would be a great help.

menkey18
13th December 2012, 17:09
I have been search on this topic for over 30 hours now, and narrowed it down to the following questions:

1. how can I find the predefined font paths which my Qt shared libs search for fonts?

2. how to get the file names of the current Qfont available so that I can find the current font path?

3. is there a way to direct my Qt libs to use the system fonts stored in /usr/share/fonts ?

4. can I load a *.ttc or *.ttf file into a QFont? -- Tried QFontDatabase::addApplicationFont always return -1 no matter what I've tried...

Any of the above questions if given a working answer will solve my problems.

Thank you very much and hoping to get a solution on this problem...

ChrisW67
13th December 2012, 22:18
1. I have already told you.

A default Qt build on Linux uses an external library called fontconfig (http://www.freedesktop.org/wiki/Software/fontconfig) to find the fonts on the system and freetype to render them. Fontconfig uses a central configuration file, usually /etc/fonts/fonts.conf, and possibly a set of subsidiary configurations files to the define the places it looks for fonts. Ubuntu fonts (https://wiki.ubuntu.com/Fonts) seem to follow this pattern.

If you have built Qt without fontconfig support then you will also have removed TTF font support from Qt. You will only see bitmap fonts; probably only those identified in the font path defined in your X11 server configuration (xorg.conf). In this case you will not be able to use your font.

2. The point of fontconfig is that there's a single place that defines where they might come from. See 1. If that's too hard, try locate .pfb or locate .ttf although I am not certain locate is a standard part of Ubuntu.

3. You can explicitly load a TrueType fonts, font collections, and OpenType fonts using QFontDatabase if you have not compiled the fontconfig/freetype support out of Qt.

4. See 3.


You can see if your Qt was build with fontconfig support by locating your libQtGui.so file and running ldd on it. If fontconfig and freetype are not in the list then you cannot use TTF fonts.

menkey18
14th December 2012, 07:45
Hi chris,

Thank you for pointing me to the right information. Yes the Qt shared libs I compile didn't include fontconfig.so, and therefore wasn't able to recognize my fonts.

The original reason for compiling the libs myself was to make it portable, my current solution is to install Qt in Ubuntu using the software centre, which has included fontconfig.so, and copy the Qt libs from /usr/lib to the directory I want, and then modify the environment variables: $LD_LIBRARY_PATH.

I am surprised that I was solving a problem that is not necessary to be solved in the first place, and spent almost 2 days on it. would there be a better methodorogy in this area?

Thank you very much for all the answers.

Lan