Results 1 to 7 of 7

Thread: unable to find font when placed under lib/font dir

  1. #1

    Default unable to find font when placed under lib/font dir

    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

  2. #2

    Default Re: unable to find font when placed under lib/font dir

    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"
    )

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: unable to find font when placed under lib/font dir

    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.

  4. #4

    Default Re: unable to find font when placed under lib/font dir

    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.

  5. #5

    Default Re: unable to find font when placed under lib/font dir

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

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: unable to find font when placed under lib/font dir

    1. I have already told you.

    A default Qt build on Linux uses an external library called 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 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.

  7. #7

    Default Re: unable to find font when placed under lib/font dir

    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

Similar Threads

  1. QFontDatabase:Cannot find font directory
    By soumya in forum Qt for Embedded and Mobile
    Replies: 9
    Last Post: 10th November 2014, 06:08
  2. Unable to see Korean Font on the Ui
    By kapoorsudhish in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 25th October 2010, 12:50
  3. Font Height and width based on font size
    By Ghufran in forum Qt Programming
    Replies: 1
    Last Post: 31st July 2010, 08:02
  4. Change Font of QListWidget to Monospace Font
    By pospiech in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 18:23
  5. Find font files
    By kovid in forum Qt Programming
    Replies: 0
    Last Post: 8th June 2008, 22:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.