April 2015
« Feb    

Using strace to solve apparently installed font problems with gnuplot

The issue

During the execution of a gnuplot script, some special mathematical symbols could be correctly displayed on the X11 terminal. However, these mathematical symbols were not displayed whenever generating the same output as a png graphic file. An error concerning fonts was issued:

./prova.gnuplot_script_png > a.png
Could not find/open font when opening font LiberationSans, trying default
gdImageStringFT: Could not find/open font while printing string a with font Symbol
gdImageStringFT: Could not find/open font while printing string a with font Symbol

As shown in the next figures, the left one is the X11 terminal-output (let’s focus on the mathematical symbols on the bottom-half), and the right one shows the same script but this time it was the output png graphic file, clearly without any mathematical symbols on it:

Gnuplot and some irritating font path issue

Running gnuplot through strace

As it happens, the only way to be sure what’s going on when something goes wrong with a piece of software is to determine what’s happening behind the scenes. One feasible thing to do is to run gnuplot through strace, to have a look, firstly, at what kind of fonts it is trying to open and why it cannot accomplish something of that sort. According to the error messages, it was not gnuplot, but libgd (that is, a library) the one complaining about the font. Moreover, the error message seemed to be related not to the fact the font wasn’t there, but the font was not suitable to print some special strings:

gdImageStringFT: Could not find/open font while printing string a with font Symbol

A first running using strace, showed:


access(“/usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf”, R_OK) = 0
open(“/usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf”, O_RDONLY) = 4

So, gnuplot did open the font “LiberationSans”. This was the choosen font according to the script:

18 set terminal wxt enhanced font “LiberationSans,18″

Next step would be to check the Symbol font out:


access(“/usr/lib/X11/fonts/Type1/Symbol.dfont”, R_OK) = -1 ENOENT (No such file or directory)
access(“/usr/openwin/lib/X11/fonts/Type1/Symbol.ttf”, R_OK) = -1 ENOENT (No such file or directory)

So, according to the strace output, the Symbol font was not opened at all. That was the main problem, not the character encoding, as the error messages could suggest, but a trivial and mere font path problem issued by  libgd.

Fixing it

Libgd does have a session variable to manipulate and set up its font paths. Then:

export GDFONTPATH=/usr/share/fonts/X11/Type1:/usr/share/fonts/truetype/ttf-liberation/

Running the script again did not show any sort of error messages, and the png output file generated showed exactly the same mathematical symbols as in the X11 output.

4 comments to Using strace to solve apparently installed font problems with gnuplot

  • sanjoy

    Thank you for elucidating the solution for setting up the font path for “png” terminal. But I did not understand where should I add the “export GDFONTPATH=/….” line ? I’ll be grateful if you let me know where to add this line.


  • Hi Sanjoy,
    thanks for reading my post. Well, it is easy as pie: all you have to do is to add the export line, as shown in my post, on your bash profile. Generally speaking, you can do so by adding the entire line:
    export GDFONTPATH=/usr/share/fonts/X11/Type1:/usr/share/fonts/truetype/ttf-liberation/
    in your .bashrc file.
    You can add this line in the /etc/profile or /etc/bash.bashrc file, instead, thus affecting all the users on your GNU/Linux box.

  • […] error “gdImageStringFT: Could not find/open font while printing string”), I found tonicas post on debugging the issue. Although helpful, it did not give the full solution to my problem. It turns out, many of the old […]

  • Hello there! I could have sworn I’ve visited this website before
    but after looking at a few of the articles I realized it’s new to me.
    Nonetheless, I’m certainly happy I stumbled upon it and I’ll be
    book-marking it and checking back frequently!

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>