GNUplot add OSX system font to PDF output - gnuplot

I need to use a symbol font called Moon Fonts TTF in the PDF output from GNUplot. GNUplot finds it with no problem in the Aqua terminal.
I've tried:
set fontpath "/Users/house/Library/Fonts/MoonPhases.ttf"
and other add fontfile suggestions from the gnuplot help pages with no luck.
I have also tried a series of .ttf, .otf, postscript and unicode-mapped fonts with some support from a typography expert, with no luck at all: pdfcairo, postscript or epscairo cannot seem to find it.
GNUplot's 'show fontpath' gives:
system fontpath is "/System/Library/Fonts" "/Library/Fonts" "/Users/house/Library/Fonts"
and the fonts are there in one of those paths. I also tried placing them directly in GN's working directory.
If anyone has suggestions about how to make this work it would be much appreciated.
OSX Snow Leopard
GNUplot 4.6.2

You could first use the postscript eps terminal to plot, and then convert the eps to postscript using epstopdf which, at least on my system, embeds the needed fonts into the resulting pdf. If it doesn't you can try to force it by providing the ghostscript parameter directly.
To make your font visible for the postscript terminal, install it into your fontpath and then use
fc-cache -fv
to reload your font cache. The name of the font might vary, because for postscript you have to find the postscript name of the font:
fc-query /path/to/your/font/MoonPhases.ttf | grep postscript
For more examples of this, read this Blogpost:
Schriftarten über Umwege: Gnuplot unter Linux und Mac OS X
It is in german language, but google Translate should help.

Related

Eps to svg, special character not converted

I'm trying to convert an eps (created with Mathtype) to svg format.
I don't have any problems with math characteres, but I'm unable to get any special characters (aka àâä...)
I have tried on unix and windows, and none of those works.
The font used is Arial, and is installed properly(Default on Windows, manually added in fonts folder in unix)
I have oppened the Arial font in windows font manager and the non working character are in.
They just aren't converted.
Actually, to convert I use Inkscape (with ghostscript) like this :
inkscape -z -f in.eps -l out.svg
Thanks in advance,
Edit :
Added in.eps file
https://pastebin.com/vBtUVy69
The fact that you have installed Arial on your Windows box has little to do with the problem.
Does the EPS file include the embedded Arial font ? If not then you are dependent on font substitution. You should probably post a sample EPS file so that we can look at it.
My guess is that the Arial font is not embedded, so Ghostscript substittues Helvetica, and the Helvetica font doesn't have those glyphs, or they are not encoded at the character codes which the EPS file thinks they are.
[EDIT]
The EPS comments say DocumentNeededFonts: Arial-BoldMT", so the EPS does not include the font and you get font substitution.
I can't tell you immediately why the SVG says Arial. I can guess, but in the absence of a complete description as to how you are producing the SVG I can't (obviously) be sure.
Now... if the conversion path uses Ghostscript's pdfwrite device to create a PDF file from the EPS, and that PDF file is then somehow converted to Inkscape's internal format (or directly to SVG using something other than Ghostscript) then what is happening is that Ghostscript is substituting Helvetica for the missing Arial-BoldMT and when it produces the PDF file it embeds the Helvetica font, but calls it Arial-BoldMT (or whatever). That's a consequence of the font substitution, the font that gets substituted gets renamed to the expected name.
I think you can avoid that by setting -dEmbedAllFonts to false, though I haven't tested it. Even if you do, all that happens is that the PDF file then doesn't have the font, just the same as the EPS file. So the SVG creation will (presumably) have to use a substitute font instead. All you do is shove the problem further down.
The correct answer to this is 'always embed fonts'.
You can also make the Arial-BoldMT font available to Ghostscript by editing its fontmap.GS file in ghostpdl/Resource/Init for builds where the resources are not built into a ROM file system. For builds which do use a ROM file system (eg Windows) you must pick up a copy of the Resources (from the Ghostscript Git repository), modify the fontmap.GS file and then tell Ghostscript to use the modified resources by pointing to it with the -I switch.
This is still a hack, because its a TrueType font being used as a replacement for a PostScript font, so there's a certain amount of guesswork going on inside Ghostscript, but it usually works well enough, YMMV.

Not the same font in gnuplot when using command line or gnuplot commands

I have a file containing some commands :
$ cat components.plg
set terminal png
set output output
set font "Helvetica,10"
unset xtics
unset ytics
unset border
plot "reportGraph_0" with lines title "Component 0", "reportGraph_1" with lines title "Component 1", "aoi.txt" with lines title "Area of interest"
$
I won't display the contents of reportGraph_# here, but anything with 2 points in them is valid.
I then launch gnuplot with this file as parameter, and I get a warning about Arial (I'm not entirely sure why).
$ gnuplot -e "output='footprint.png' " components.plg
Could not find/open font when opening font "arial", using internal non-scalable font
$
However, the result image has its text in non-Helvetica (but more in something like Monospace sans).
Here are the two images (first the output of the command line, second the output of the same sequence of commands launched in a gnuplot shell, and exporting the result image). There is one difference, I didn't use the first two commands (set terminal png and set output output) in gnuplot - I merely "exported" the image as png.
The question is : why don't I have the same font in these two images?
I would like to have Helvetica (or Lucida Grande, but not a monospace font).
Gnuplot has a large variety of terminals. When you launch an interactive gnuplot session and plot you probably use the wxt or qt terminal. By exporting the image from the plot window you save the image as theyes were created by those terminals.
Now, with set terminal png you use a different and quite old terminal, with different capabilities, especially regarding font rendering.
If you want to save your image directly as png, use the pngcairoterminal, which produces higher quality images (the result should be equivalent to that of the exported image from wxt).
The pngcairo, or the pdfcairo terminals should also handle your fonts properly.
The png terminal is older than pngcairo, but it can still use a specified font. You can just specify a path to a .ttf or .pfa font file:
set terminal png font "/path/to/your/Helvetica.pfa"
or a comma-separated pair of the font file path and point size:
set terminal png font '/usr/share/fonts/liberation/LiberationSans-Regular.ttf,9'
gnuplot uses libgd so if you set the environment variable GDFONTPATH to the directory containing your .ttf or .pfa font files, you can specify just the font name instead of the full path:
set terminal png font 'LiberationSans-Regular'
Documentation for setting fonts with different terminals is available within gnuplot under help fonts gd, help fonts cairo, and help fonts postscript.

gnuplot gif not scalable with ttf font

After installing libgd on RedHat Linux, I found the path to .ttf fonts and used the full pathname to a DejaVu .ttf font (in 'set terminal gif font...") to create a .gif file from gnuplot. It looks good in a Firefox window, but when I change the size, it looks bad, as though the font is not scalable.
I am using the default binaries. Do I need to recompile gnuplot with different settings to make it scalable? I get no errors or msgs when the image is created from gnuplot (i.e. it finds and uses the .ttf file; I know because I tried several fonts and the image responded accordingly, with .pfa fonts also).
The gnuplot documentation says that TrueType fonts are fully scalable. Maybe I don't understand what scalable means. I had a similar problem with SUN OS, and my solution was to create a postscript (.eps) file from gnuplot and then convert it to .gif, and then it was scalable, but I don't have such a conversion utility on Linux (yet), and it seems like an unnecessary step.
I don't have the actual code/output in front of me, but I can add some if it would help. Also, I can't find any arial.ttf fonts on the system. Maybe that is a clue to the problem.
I heard good things about pngcairo (to avoid using gd), but 'set terminal' does not list it as an image type.
This is not a definitive answer, but it allows to show me a picture of the situation on my machine.
This plot was generated as gif using gnuplot 4.6p5 and Suse Linux 13.2.
The upper plot shows labels written in DejaVu, left using the full path to the TTF file, right using the name of the font. (DejaVu is an installed font here.)
The lower plot shows the same, the font is from the game Minecraft (i.e. very pixelated). I do not get any error message about missing fonts or similar, but gnuplot uses its default font here, but not what I want. More interesting: When I do not specify the font, I get Liberation Serif...
However, it seems my system ONLY uses fonts, regardless if referenced by name or path, when the font is correctly installed. Nevertheless, also the default font is smooth and scalable. (the gnuplot help says, gd has some not scalable build-in fonts, which may be used in your plot)

Suppress the missing font warning with gnuplot

I am using gnuplot and get this warning everytime I generate a graph:
Could not find/open font when opening font "arial", using internal non-scalable font
Is there a way to suppress the warning?
This warning is generated by the gd backend I believe. Suppressing it might be a little tricky (you could try redirecting stderr of the gnuplot process), but gnuplot seems to like to write useful things to stderr, so I don't advise that ... and the builtin (non-scalable) font looks like garbage. The easiest fix is to see if your gnuplot was built with pango-cairo support. Just try:
set term pngcairo
instead of:
set term png
In this case, the font subsystem of cairo will take over rather than of gd. As a side bonus, I've found that I'm much happier with the cairo plots.
If that's not an option, you can download/find a suitable font and put it in a directory somewhere. Then you can set an environment variable GDFONTPATH to point to that directory. For example, find a truetype font that looks like Arial and put it in ~/fonts/arial.ttf. Then set your environment export GDFONTPATH=${HOME}/fonts and all should work.
If you're willing to live with the ugly font that gd provides, you can use the builtin fonts explicitly:
set term png tiny
or:
set term png large
See help fonts gd for more information.

How do I access various true type fonts through gnuplot with png terminal?

I am trying to output a png image with an arial size 14 font. I use mac OS X 10.6 and did not build GNUPLOT myself. I got the program from a website called High Performance Computing for OS X in the package for Octave. Here is what I entered in gnuplot:
G N U P L O T
Version 4.2 patchlevel 5
last modified Mar 2009
System: Darwin 10.0.0
Copyright (C) 1986 - 1993, 1998, 2004, 2007 - 2009
Thomas Williams, Colin Kelley and many others
Type `help` to access the on-line reference manual.
The gnuplot FAQ is available from http://www.gnuplot.info/faq/
Send bug reports and suggestions to <http://sourceforge.net/projects/gnuplot>
Terminal type set to 'x11'
gnuplot> set term png font "arial" 14
Terminal type set to 'png'
No TTF font support, using internal non-scalable font
^
invalid color spec, must be xRRGGBB
gnuplot>
Any help would be greatly appreciated. Thanks!
The following works on Mac OS X 10.5 with gnuplot installed via MacPorts:
set terminal png font "/Library/Fonts/Arial.ttf" 14
The documentation is available via help terminal png (emphasis mine):
If gnuplot was built with support for TrueType (.ttf) or Adobe Type 1
(.pfa) fonts, they may be selected using the 'font {}'
option. is either the full pathname to the font file, or a font
face name that is assumed to be the first part of a filename in one of the
directories listed in the GDFONTPATH environmental variable. That is,
'set term png font "Face"' will look for a font file named either
/Face.ttf or /Face.pfa. Both TrueType and
Adobe Type 1 fonts are fully scalable and may be rotated through any angle.
If no font is specified, gnuplot checks the environmental variable
GNUPLOT_DEFAULT_GDFONT to see if there is a preferred default font.
Update: I just noticed that your gnuplot installation complains about "No TTF font support", so the above may not work for you. In order to get true type fonts to work at all, you probably have to re-install gnuplot.
Thanks! The info with $GDFONTPATH was really helpful for on MacOS.
Adding the line:
export GDFONTPATH=/System/Library/Fonts:$GDFONTPATH
to my /Users/username/.profile solved the Problem for me. Don't forget to source the .profilefile. Or to restart the Terminal. So that the variable gets loaded.
It depends on the terminal type
On (X)Ubuntu LTS GNU/Linux, gnuplot seems to look up fonts in a whole host of directories by default. For example, the following line worked by default with the terminal png:
set terminal png font "texgyrepagella-regular.otf" 12
Even though I had no environment variables set and the package manager had previously installed this font in /usr/share/texmf/fonts/opentype/public/tex-gyre. Nice!
However, if I employ the more advanced terminal pngcairo, the very same font is specified by its name; not its filename. Even nicer!
set terminal pngcairo font "TeX Gyre Pagella, 12"
Please, also notice the syntactic difference in specifying the font size.

Resources