3

I just started research on how fonts work under Linux. Till now, I got to know that the Linux font system consists of:

  • FreeType, which is a rasterizer for rasterizing vector-based text to bitmap-based.
  • Fontconfig, which is a library for managing and locating fonts inside the operating system.
  • Xft that is used for displaying desired output on X windows system or so.

(Correct me if I am wrong.)

Is there any direct relation between these three? What is the workflow? And under what circumstances these system libraries are invoked?

migrated from graphicdesign.stackexchange.com Oct 17 '17 at 10:52

This question came from our site for Graphic Design professionals, students, and enthusiasts.

2

They're related like this (using ldd):

  • Xft is a library, which depends on (among other things) the fontconfig library and the freetype library.
  • fontconfig is a set of programs, a library and data. Its library depends upon the freetype library.
  • freetype is a library, which does not depend on the other two.

For example:

$ ldd /usr/lib/x86_64-linux-gnu/libXft.so.2.3.1
        linux-vdso.so.1 =>  (0x00007fffb3df7000)
        libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f40ea07a000)
        libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f40e9ddb000)
        libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f40e9bd1000)
        libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f40e9896000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f40e9509000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f40e92f2000)
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f40e90c8000)
        libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f40e8ea8000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f40e8ca4000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f40ea4c6000)
        libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f40e8aa1000)
        libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f40e889c000)

Some applications (such as xterm) use Xft, which uses an MIT-license. Others (generally the GPL-licensed ones) use libpango. Besides licensing concerns on pango, it has twice as many library-dependencies as Xft.

Looking at the symbols from fontconfig used by Xft:

FcCharSetCopy
FcCharSetCount
FcCharSetDestroy
FcCharSetHasChar
FcConfigGetBlanks
FcConfigSubstitute
FcDefaultSubstitute
FcFontList
FcFontMatch
FcFreeTypeCharIndex
FcFreeTypeCharSet
FcInit
...
FcPatternPrint  
FcPatternVaBuild  
FcStrCmpIgnoreCase
FcUtf16ToUcs4
FcUtf8ToUcs4

and those from freetype:

FT_Done_Face
FT_GlyphSlot_Embolden
FT_Init_FreeType
FT_Library_SetLcdFilter
FT_Load_Glyph
FT_New_Face
FT_Render_Glyph
FT_Set_Char_Size
FT_Set_Transform
FT_Vector_Transform

you can see that Xft uses fontconfig for locating fonts based on patterns, but uses freetype to actually load, display or adjust (scale, etc) a font.

fontconfig uses different calls to freetype to obtain information about a font (the overall size, the number of glyphs, etc):

FT_Done_Face
FT_Done_FreeType
FT_Get_BDF_Property
FT_Get_Char_Index
FT_Get_First_Char
FT_Get_Glyph_Name
FT_Get_Next_Char
FT_Get_PS_Font_Info
FT_Get_Sfnt_Name
FT_Get_Sfnt_Name_Count
FT_Get_Sfnt_Table
FT_Get_X11_Font_Format
FT_Has_PS_Glyph_Names
FT_Init_FreeType
FT_Load_Glyph
FT_Load_Sfnt_Table
FT_New_Face
FT_Select_Charmap
FT_Select_Size

Without freetype, fontconfig hasn't any information: fontconfig organizes information but is not a complete source of information by itself.

  • fine much better. can u please tell what is the main relationship between fontconfig and Freetype? I mean if i do fc-list or any stuff like that, is it dependent of Freetype? In which scenarios Fontconfig calls FreeType? – Ammar Ul Hassan Oct 18 '17 at 12:12
  • Just to make sure what i learned is correct. FreeType is a library that is mainly responsible for digging deep in a font file and taking out the low level information like face, Cmap, glyph details etc. ? And font config is a high level API which usually do the management and location of fonts in Linux operating system? – Ammar Ul Hassan Oct 19 '17 at 2:00
  • that's close enough – Thomas Dickey Oct 19 '17 at 8:05
  • FreeType does font glyph-by-glyph rendering, Fontconfig does font matching. Fontconfig helps you find the right font, FreeType lets you actually use it. – Lawrence D'Oliveiro Nov 4 '17 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.