set title '{/Times-New-Roman aaa}' font ',24'
plot x
"Times New Roman" is default selif font on windows . On enhanced text mode does not allow font name with space. In fontconfig releted terminals (gd(png, ...), cairo (wxt, pngciaro, ....)), and postscirpt one can use font name with hyphen like the above example.
However, this font specication is ignored on x11, windows, qt, emf and svg terminals.
(I have not tested on other terminals.)
I think that font specification like /Times-New-Roman on enhanced text should be available on all terminals.
The font handling is not done by gnuplot.
There may be problems in gnuplot such as mis-parsing font names containing blank space. That would be a fixable bug. But interprerting font names and substituting whatever equivalent may be installed on the local system is outside of gnuplot's scope. It relies on external libraries or utilities for that.
Last edit: Ethan Merritt 2019-01-28
OK. I understand the situation.
Is font names containing blank space can be treated like
"{/Times\ New\ Roman aaa}"
one of ideas?
My suggestion would be font aliases, e.g. like
But then in the age of utf8, you normally only need one font per label, i.e. you don't need to switch between symbol and normal font. So it's probably not really an issue. Since nobody has complained about this ever since enhanced text mode was introduced ...
I personally got this trobuble when gnuplot 5 appeared.
But at that time, I did not report this issue.
Tested on linux using terminals
wxt qt svg png
~~~
set label 1 "{/Times This label uses font Times}" at 0,0
set label 2 "{/TimesNewRoman This label uses font TimesNewRoman}" at 0, -.1
set label 3 "{/Times-New-Roman This label uses font Times-New-Roman}" at 0, -.2
plot [-1:1][-1:1] -1
~~~
qt:
Times works and finds Adobe Times font
TimesNewRoman works and finds MS Times New Roman
Times-New-Roman does not work - uses default font
wxt, svg:
Times works and finds Adobe Times font
TimesNewRoman works and finds MS Times New Roman
Times-New-Roman works and fins MS Times New Roman
png (gd):
Times works and find Adobe Times font
TimesNewRoman works and finds MS Times New Roman
Times-New-Roman works but finds Adobe Times
Ethan thanks for experiments
On windows
qt:
Times does not work - uses default font
TimesNewRoman does not work - uses default font
Times-New-Roman does not work - uses default font
wxt:
Times does not work - uses default font
TimesNewRoman does not work - uses default font
Times-New-Roman works and fins MS Times New Roman
svg:
Times works and finds MS Times New Roman?.
TimesNewRoman does not work - uses default font
Times-New-Roman does not work - uses default font
png (gd):
Times works and finds MS Times New Roman?.
TimesNewRoman works and finds MS Times New Roman
Times-New-Roman works and fins MS Times New Roman
emf:
Times works and finds MS Times New Roman?.
TimesNewRoman does not work - uses default font
Times-New-Roman does not work - uses default font
Unlike Linux font name deleted space almost does not work on windows.
Last edit: Tatsuro MATSUOKA 2019-01-29
I should have added that I tested svg by viewing it in the chrome browser. This is actually a test of browser font handling, not of svg itself.
Tatsuro:
What do you see when viewing the svg file I attached? If your machine does not display it correctly then I think this demonstrates that the font problem needs to be fixed by changing the maching configuration, not by changing gnuplot output.
If you do see correct output from the svg file generated on linux, but bad output from the svg file generated on windows, that indicates a different sort of problem.
In that case can you attach a copy of your non-working svg file so I can see what is different?
As you say, svg is viewer dependent.
The previous post I saw svg file by firefox on windows.
I saw it by inkscape then :
Times works and finds MS Times New Roman?.
TimesNewRoman works and find MS Times New Roman
Times-New-Roman does not work - uses default font
Your upload file (foo.svg) in firefox
Times works and finds MS Times New Roman?.
TimesNewRoman does not work - uses default font
Times-New-Roman does not work - uses default font
I upload svg file created by gnuplot 5.3 on windows
Last edit: Tatsuro MATSUOKA 2019-01-29
You are packaging gnuplot with libfontconfig-1.dll, right?
So I guess that your font problem comes from a failure of that library to find the correct information in the system font configuration files. I do not know where these live on a Windows system.
For example, here is part of the output from the utility program fc-list showing configured variants of Times that come from ttf files (i.e. not the Adobe ones)
fc-list | & grep -i times | grep ttf
/home/local/share/ttfonts/times.ttf: Times New Roman:style=Regular,Normal
/home/local/share/fonts/t/timesbd.ttf: Times New Roman:style=Bold,Negreta
/home/local/share/fonts/t/timesbi.ttf: Times New Roman:style=Bold Italic,Negreta cursiva
/home/local/share/ttfonts/timesbi.ttf: Times New Roman:style=Bold Italic,Negreta cursiva
/home/local/share/ttfonts/timesbd.ttf: Times New Roman:style=Bold,Negreta
/home/local/share/fonts/t/times.ttf: Times New Roman:style=Regular,Normal
/home/local/share/fonts/t/timesi.ttf: Times New Roman:style=Italic,cursiva,kurzíva,kursiv
/home/local/share/ttfonts/timesi.ttf: Times New Roman:style=Italic,cursiva,kurzíva,kursiv
It finds these fonts because in their directories are listed in the configuration file /etc/fonts/local.conf:
On windows, each application has its own fontconfig setting.
On font confiration file should be placed relative to libfontconfig-1.dll location (path).
../etc/fonts/fonts.conf
The fonts.conf is attached.
The binary package for gnuplot for windows has now renamed fontconfig utlilities like fc-list-gp.
I execute the below on Msys2 (unixy like environments on windows.)
$ "C:\Programs\gp530-64\bin\fc-list-gp" | grep -i times | grep ttf
C:/WINDOWS/fonts/times.ttf: Times New Roman:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,thường,Arrunta
C:/WINDOWS/fonts/timesbi.ttf: Times New Roman:style=Bold Italic,Negreta cursiva,tučné kurzíva,fed kursiv,Fett Kursiv,Έντονα Πλάγια,Negrita Cursiva,Lihavoitu Kursivoi,Gras Italique,Félkövér dőlt,Grassetto Corsivo,Vet Cursief,Halvfet Kursiv,Pogrubiona kursywa,Negrito Itálico,Полужирный Курсив,Tučná kurzíva,Fet Kursiv,Kalın İtalik,Krepko poševno,nghiêng đậm,Lodi etzana
C:/WINDOWS/fonts/timesi.ttf: Times New Roman:style=Italic,cursiva,kurzíva,kursiv,Πλάγια,Kursivoitu,Italique,Dőlt,Corsivo,Cursief,kursywa,Itálico,Курсив,İtalik,Poševno,nghiêng,Etzana
C:/WINDOWS/fonts/timesbd.ttf: Times New Roman:style=Bold,Negreta,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiona,Negrito,Полужирный,Fet,Kalın,Krepko,đậm,Lodia
On Windows, the cairo and windows terminals use the "native" API to find fonts.
The gd terminals and qt use fontconfig. For gd terminals, it is only a fall-back.
The font "Times New Roman" is available on Windows 10. The designer is "Monotype".
The translation of '-' to spaces is done in
gp_cairo_set_font()for the cairo terminals.The fontconfig command
fc-pattern -d "Times-New-Roman"is successfull on Windows/MSYS2, as tests for "Times" and "Time New Roman". So that could explain why it works for the gd terminals.Qt5 on Windows makes use of fontconfig, too. But apparently it does not do name substitutions. The following Qt bug report might be related: https://bugreports.qt.io/browse/QTBUG-48580
The windows terminal (D2D) has a built-in substitution for
Timesin d2dSetFont(). For the GDI and GDI+ variants that substitution is done by the Windows API itself. It does not currently support "Times-New-Roman" (with '-'). Adding support for this like the cairo terminals would be simple.Drawback of this is that font faces with names containing '-' would no longer be accessible. (But are there any?) IMHO such a treatment should be done in the gnuplot core and not in terminal code.
Taking a step back, I have a question. Where are these hyphens in the font name coming from? I know that the old Adobe Postscript standard font names mixed font properties with the face name using hyphens:
Times TImes-Bold Times-Bold Times-Italic Times-BoldItalic
The family name itself did not contain hyphens. For the name field they removed spaces so that for instance "Franklin Gothic Book" became "FranklinGothic-Book", where the face name has no spaces and is separated from the variant by a hyphen.
But that was Adobe. I don't know that anyone else ever adopted that scheme except insofar as they accommodated Adobe fonts. Gnuplot's postscript terminal required you to provide whatever string Adobe PostScript expected to find in a *.ps file. So the gnuplot command had to be
set term postscript "NewCenturySchlbk-Roman"
even though the formal name of the font face was "New Century Schoolbook".
So no, I don't think it is gnuplot's job to remove hyphens because I don't think the hyphens are a standard part of a font name to begin with. As this discussion shows, font handling varies a lot from one system to another. I think it is up to the user to specify font names using whatever convention their local system requires for fonts.
I do agree that if the machine's local convention requires spaces in the font name then gnuplot should be able to deal with spaces (which it currently cannot do). I am thinking that the most straightforward adjustment is to accept quotes around a font name. I can also think of reasons why this might not work.
Btw. a possible work-around for cases where one would like to change the font of the object is to use the
fontproperty instead of enhanced text. Like for e.g. inset title font "Times New Roman".Ethan, the mechanism of this replacing hyphens with spaces is already built-in for some terminals. Either explicitely (cairo) or indirectly (maybe by using fontconfig). So I was kind of assuming that this is a somewhat "known" convention. If we were to implement that, then it should be in the core. But I agree that there may be better ways of handling spaces in font names. Seems like a worthwhile addition.
The comment in front of the hyphen-into-space code in the cairo terminal indicates that it was intended to separate the font name from properties like Bold or Italic. I.e. to recover "Times" from "Times-Bold" or "Times-Italic". Allowing "Times New Roman" to be specified as "Times-New-Roman" as Tatsuro is seeing for the wxt terminal was probably a side effect.
Are you sure the cairo terminal on Windows does not use the pango library (and hence fontconfig)? I can see that libpango.dll and libpangocairo.dll are in the gnuplot Windows package. Maybe it requires an extra step?
https://github.com/Alexpux/MINGW-packages/issues/4293
It uses cairo/pango/pangocairo indeed. But the default font backend used is the
win32native one. You can force pango to use thefcfontconfig backend by setting thePANGOCAIRO_BACKENDenvironment variable. Hence it also links to fontconfig. Also thegdterminal can make use of the fontconfig mechanism on Windows, but typically does not. fontconfig is used by Qt, though. See also https://developer.gnome.org/pango/stable/pango-Cairo-Rendering.html#pango-cairo-font-map-newThe fontconfig mechanism is somewhat alien to the Windows platform, as already pointed out by Tatsuro. So we avoid that if possible. (One major problem of the Qt terminal on Windows is timeouts while the fontconfig cache is being re-built.)
I also have not noticed that pango works windows native in default setting.
I also see libpangowin32-1.0-0.dll. Perhaps this is for win32 backend and this is used by default.
I will do some experiments by setting PANGOCAIRO_BACKEND environment variable.
That is actually trivial to verify. Just set the fontconfig environment variable
FC_DEBUG=1(font matching) before loading console mode gnuplot. Try a command likeWithout
PANGOCAIRO_BACKEND=fcyou will not see any debug output, meaning fontconfig is not used. Alternatively, setFC_DEBUG=1024to see if and which config files are loaded.This has been like that since 2011, see commits [0dc98e] and [ed84fa].
Related
Commit: [0dc98e]
Commit: [ed84fa]
Has there been any further progress regarding this issue?
As Karl and Bastian point out above, the simplest way to avoid the problem is to move the font specification outside of the label text. I.e.
In the bad old days when a separate Symbol font was needed there was good reason to change fonts in the middle of a string if that string contained Greek or math symbols, but in the new era of UTF8 encoding this is no longer needed.
Old style:
New style:
So unless someone comes up with an example where the simple solution doesn't work, I'm inclined to consider the resolution to be "won't fix" or "out of date"
Thanks Ethan,
I'm actually calling gnuplot commands and generating graphs from within a Fortran program i'm writing on Windows, so i cannot rely on writing Greek and math symbols from within Fortran, which is why i am still using the old style.
I don't get it. Even if you need/want to use a separate Symbol font, the fontname "Symbol" has no hyphens or spaces in it so why is this issue relevant?
But actually I don't see why you would need a separate symbol font just because you are working in Fortran. Here is an example:
chartest.for:
Maybe working under Windows adds an extra layer of craziness, but I cannot help with that part.
As one of Japanese, I want to use Laten fonts and Japanese fonts at the same label. So that for me, the issue is important and do not want to be "won't fix" or "out of date".
Last edit: Tatsuro MATSUOKA 2019-02-06