A problem with fonts and/or printing PNG files?

Dwight Poplin iwmyfom at myway.com
Sun Mar 2 19:41:16 CST 2008



>> | > I'm having a problem when I try to print a plot in PNG format. Here's
>> | > a simple script that reproduces the problem on my machine:
>> | >
>> | > x = 1:10 ;
>> | > plot (x);
>> | > title ('My plot');
>> | > print myplot.png -dpng
>> | >
>> | > When I type the print command, I get this error message:
>> | >
>> | > gdImageStringFT: Could not find/open font while printing string My plot
>> | > with font Helvetica
>> | >

>> | In the case of
>> | print myplot.png -dpng
>> | the gd+freetype library used by gnuplot cannot find file "helvetica.ttf" and
>> | thus producing the error message. I don't see any such file on my Linux box.
>> | I think that another font, e.g. arial (arial.ttf exists) should be used
>> | instead.
>>
>> On my system (Debian testing, up to date) I also see the error if I
>> use gnuplot directly and ask for Arial:
>>

>This is GD library issue. You need to set GDFONTPATH to the
>directory where it can find Arial.ttf.
>Also if the file name is arial.ttf you need to say to gnuplot:

>set title "foobar" font "arial,10"

>This all looks ugly and perhaps there is a better way, but I do not >know it.

I also do not have Arial fonts installed by default.  One possible default that might work for all platforms is one of the five default fonts supported by the GD library: tiny, small, medium, large or giant.  

Thanks to everyone's comments, I realized that my real problem was not understanding how to use fonts in Octave/gnuplot.  I spent a day figuring it out so I thought I'd share the details for the benefit of other novices like myself who may run into this issue.  This isn't really an Octave bug so lemme know if there's a better place to post this.

Here's the detailed explanation:  First you need some fonts.  You could use one of the five default fonts available in gnuplot but I found them way too limited for my needs.  You probably already have some true type fonts installed (assuming you're using Linux).  If not, you should be able to install some with your package manager.

Next you need to find the path to the fonts.  Try looking in "/usr/share/fonts/truetype".  If they aren't there, you can do "find . -name *.ttf" from /usr or other system directories until you find the font directories.  As an example, I found two font files I wanted to use:

  /usr/share/fonts/truetype/ttf-mgopen/MgOpenModernaBold.ttf
  /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf
     
Now you need to tell gnuplot where to find the fonts.  Do this by setting the GDFONTPATH environment variable.  I had to list each font subdirectory like this:

export GDFONTPATH="/usr/share/fonts/truetype/ttf-mgopen:/usr/share/fonts/truetype/ttf-dejavu"

Now you can use the name of the font file in Octave like this:

  title ('My plot', 'FontName', "MgOpenModernaBold.ttf");

As far as I can tell, the Octave plot window didn't use the font I specified but when I printed to a PNG file, it had the right font.

If for some reason, setting GDFONTPATH doesn't work, you can specify the full path to the font.  It's a yucky hack, but it works.  I discovered thru trial and error that there is some magical length limit on the path name.  When I did this in octave:

  title ('My plot', 'FontName', "/usr/share/fonts/truetype/ttf-mgopen/MgOpenModernaBold.ttf");

I got a "***stack smashing detected***" error.  That sounded like a bad 
thing so I copied the font file to a directory with a shorter name and
shortened the file name as well:

  title ('My plot', 'FontName', "/home/dave/Fonts/MdrnaBd.ttf");

_______________________________________________
No banners. No pop-ups. No kidding.
Make My Way  your home on the Web - http://www.myway.com




More information about the Bug-octave mailing list