5

I am new to the Linux environment, and I have started research on fonts.

I have read that fontconfig is the library which actually deals with the font management in Linux. So for this sake I have downloaded the fontconfig source code and I have compiled it and it's ready to use.

When I went into the main source directory I saw many sub modules like fc-cache, fc-list, fc-query etc. I tried to search about them but couldn't find any great detail of how they actually work. So I have decided to understand the source myself but I'm facing lots of troubles as I don't know what's the actually starting point, like when we write command on terminal like below, what is actually happening.

$ fc-query /usr/share/fonts/truetype/fonts-japanese-gothic.ttf

Lets suppose I want to modify a fontconfig file, like Fcquery.c, to make it call some other function which resides in some other shared library. What do I have to do? Will just compiling work, or do I have to register some thing in the Makefile.

I am new so please elaborate.

closed as off-topic by Thomas Dickey, GAD3R, mdpc, jasonwryan, roaima Jan 18 '17 at 8:53

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." – Thomas Dickey, GAD3R, mdpc
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I would start with reading the API documentation which can be found here freedesktop.org/software/fontconfig/fontconfig-devel – Paul H. Jan 17 '17 at 14:25
  • @PaulH. I abstractly read this Documentation earlier. Actually this doc explains more about the functions and datatypes etc but not how each module works or any idea related to that :( – Ammar Ul Hassan Jan 17 '17 at 14:42
  • OK. but If you want to understand the source code, that documentation will be helpful since the data types and functions are used in the source code. What exactly is your goal? Is it to know how to use those commands you mentioned or to understand what exactly is going on "under the hood"? – Paul H. Jan 17 '17 at 18:07
  • @PaulH. My main goal is both you mentioned but first goal is what actually is happening? – Ammar Ul Hassan Jan 18 '17 at 1:39
6

TL;DR: Understanding fontconfig requires understanding why it was created and what problems it is trying to solve. That require a lot of understanding of Xorg.

Font configuration on UNIX machines went through different phases and fontconfig is simply one of the possibilities you can use to use fonts through Xorg. Reading the source of fontconfig without a good understanding of the source of Xorg is probably very difficult. But, I believe that an understanding of the concepts behind the evolution of fonts may prove a decent starting point.

Disclaimer: I deal a lot with fonts on Linux, but I never really needed to change Xorg code relating to fonts.

The Arch Linux wiki has a lot of info on this too

A bit of history

Original UNIX fonts were simply bitmap fonts. Today these can be found in /usr/share/fonts/misc, the PCF (portable compiled format) is used for pretty much all of them today. It is a binary format. There have been other formats of binary fonts but I need to admit that I never needed to use any other format than PCF for binary fonts. Using xfontsel you can configure a Xorg string to define the points, spacing, pixel size, terminal weight (bold, slant), encoding, among others of the font.

The bitmap fonts have different files for different pixel sizes of the font. The bitmap fonts already introduce the concept of font family.

Postscript (and TeX to some extent) created Type 1 fonts which are vector based fonts. These are in /usr/share/fonts/Type1. Vector fonts are configured with several configuration values, e.g. antialias, embolden, dpi, or size (not necessarily point based this time).

Vector based fonts are scaled and do not require several files.

Xorg used both bitmap and Type1 fonts. And it created the XFT (well X FreeType is an interface to FreeType which is a GPL/BSD library that mimics and extends Type1). XFT not only allows the usage of Type1 and FreeType fonts but it also other formats: OTF by Adobe and Microsoft, TTF by Apple. Moreover XFT allows scaling of the old bitmap fonts to look like Type1 fonts.

Several other attributes, like hinting or hintstyle, were added to define attributes of these fonts.

All that can be found in subfolders of /usr/share/fonts. And XFT parameters can be configured in your Xresources.

FontConfig

And fontconfig needs to deal with all the discrepancies of the above. In other words fontconfig is an attempt of configuring all the font types above in a manner that can exploit the attributes that the distinct fonts have with a common syntax.

The bitmap fonts have their problems:

  • several different files for a single font
  • limited sizes by points and pixel sizes.

But so does the vector based fonts:

  • scaling takes time, especially if several parameters are used
  • not all font attributes affect different font types in the same way

And both have the problem that there are many font formats, and that a user may wish to install fonts of his own in his home. Fontconfig tries to solve these problems.

fc-query tells you what fontconfig understand about the font file. Notably what attributes the file is for (for bitmap fonts for example) and what attributes can be used (for vector fonts).

fc-list is a way of telling you what fonts can be found in the directories fontconfig is looking at, and therefore con be used by applications. Finally fc-cache performs an indexing of these fonts to find them easier and to scale them (among other things) for application use.

The fontocnfig shared library on the other hand is the most interesting part. It uses the configuration files (/etc/fonts, ~/.config/fontconfig) and the font cache to give preprepared fonts directly to applications that are linked against it. Since most applications used XFT (and therefore FreeType) and the FreeType library is using calls from the fontconfig library, the use of these fonts become ubiquitous.

But note that you can compile a program that will ask Xorg for a bitmap font in the old style (e.g. -*-terminus-medium-r-normal-*-*-200-*-*-c-*-*-u) and the call will not go through the fontconfig shared lib.

  • Thanks for your detail answer i understand what your trying to say. Actually you defined Fc-query and fc-list but i want to know things like when some toy level program tries to use FC and its functions where is the request first sent? i mean what is the starting point? I tried to add a statement like printf(" testing") in fc-query main function and than i wrote the fc-query command from terminal but i couldnt see that. i compiled it again by the make command though – Ammar Ul Hassan Jan 18 '17 at 1:50
  • @AmmarUlHassan - Heh, printf("something") will never use fontconfig library 'cause what is dealing with the font is the terminal emulator. To use fontconfig you need a program linked to X11, and it needs to draw the fonts on the screen by itself. But if you can't get a printf in main() to show on the terminal that is likely a PATH problem, 'cause you certainly do have fontconfig installed already. – grochmal Jan 18 '17 at 1:59
  • ok fine. But what if i want some small script in fontconfig which can actually call some function of some other Shared library on my system. Ideal scenario is that i will add one header file of that lib in fontconfig (some file i dont know which 1) and than i will recompile the fontconfig and run that file so that it calls function of that library. – Ammar Ul Hassan Jan 18 '17 at 2:05
  • @AmmarUlHassan - That's too many things. Fontconfig is not a scripting environment, it simply does what it is meant to do: provide precopiled/cached fonts for Xorg to display when ti is refreshing the screen. If you need applications to use the shared library of the fontconfig you compiled you need to reconfigure ldconfig to use your shared library instead of the library that libfreetype2 is currently calling. I have the impression you're trying to bite on too much stuff at once. – grochmal Jan 18 '17 at 2:18
  • ha ha yeah may be... So the conclusion is that before digging deep i need to understand about the history? Xft? and than FC functions and datatypes? – Ammar Ul Hassan Jan 18 '17 at 2:27

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