Skip to content

Monospaced font not shown correctly (Xubuntu 20.04)

6 messages · Paul Murrell, Wolfgang Viechtbauer, Rasmus Liland

#
Hi all,

On my system (Xubuntu 20.04), using par(family="mono") is not rendered correctly. The same issue was raised here:

https://stackoverflow.com/questions/64207220/rendering-plot-in-r-with-mono-spaced-family-font-does-not-display-characters-any

Using par(family="monospace") does work:

par(mfrow=c(1,2))
par(family="mono")
plot(1)
par(family="monospace")
plot(1)

Also, when saving to pdf, it works fine:

pdf("plot.pdf"); par(family="mono"); plot(1); dev.off()

I have forced a refresh of the font cache:

fc-cache -r --verbose --really-force

And Courier is available:
/usr/share/fonts/X11/Type1/c0419bt_.pfb: Courier 10 Pitch:style=Regular
/usr/share/fonts/type1/texlive-fonts-recommended/pcrb8a.pfb: Courier:style=Bold
/usr/share/fonts/X11/Type1/c0611bt_.pfb: Courier 10 Pitch:style=Bold Italic
/usr/share/fonts/type1/texlive-fonts-recommended/pcrr8a.pfb: Courier:style=Regular
/usr/share/fonts/X11/Type1/c0582bt_.pfb: Courier 10 Pitch:style=Italic
/usr/share/fonts/X11/Type1/c0583bt_.pfb: Courier 10 Pitch:style=Bold
/usr/share/fonts/type1/texlive-fonts-recommended/pcrro8a.pfb: Courier:style=Italic
/usr/share/fonts/type1/texlive-fonts-recommended/pcrbo8a.pfb: Courier:style=Bold Italic

Any other ideas how to fix this?

Best,
Wolfgang

(happy to move this to R-SIG-Debian if this would be more appropriate)
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=C               LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.0.3 tools_4.0.3
$serif
[1] "-*-times-%s-%s-*-*-%d-*-*-*-*-*-*-*"

$sans
[1] "-*-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"

$mono
[1] "-*-courier-%s-%s-*-*-%d-*-*-*-*-*-*-*"

$Times
[1] "-adobe-times-%s-%s-*-*-%d-*-*-*-*-*-*-*"

$Helvetica
[1] "-adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"

$CyrTimes
[1] "-cronyx-times-%s-%s-*-*-%d-*-*-*-*-*-*-*"

$CyrHelvetica
[1] "-cronyx-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"

$Arial
[1] "-monotype-arial-%s-%s-*-*-%d-*-*-*-*-*-*-*"

$Mincho
[1] "-*-mincho-%s-%s-*-*-%d-*-*-*-*-*-*-*"
#
Hi

The switch to XUbunutu 20.04 may mean a switch to Pango > 1.44 (it does 
on Ubuntu 20.04), which means loss of support for Type 1 fonts (on 
Cairo-based graphics devices).

The Courier fonts (the default for "mono" on Cairo-based devices) that 
you found are all Type 1 (.pfb) fonts.

What does this give you (the matches for the default "sans" and "serif" 
on Cairo-based devices) ... ?

fc-match Times
fc-match Helvetica

If those are .ttf or .otf fonts then that would explain why "sans" and 
"serif" still work.

A workaround is to specify the family name for a non-Type-1 monospaced 
font, e.g., "Courier New" (?), or install a non-Type-1 Courier 
replacement (and specify that).

Hope that helps.

Paul
On 20/01/21 3:48 am, Viechtbauer, Wolfgang (SP) wrote:

  
    
#
Dear Paul,

Thanks for the helpful reply. Indeed:
NimbusRoman-Regular.otf: "Nimbus Roman" "Regular"
NimbusSans-Regular.otf: "Nimbus Sans" "Regular"

are OpenType fonts. Also:

X11(type="Xlib", family="mono")
plot(1)

works. So does

X11(family="Courier New") # type="cairo" by default
plot(1)

or

X11(family="Inconsolata")
plot(1)

Can I not override what is specified under X11Fonts() with? Because this does not work:

X11Fonts(mono="-*-inconsolata-%s-%s-*-*-%d-*-*-*-*-*-*-*")
X11(family="mono")
plot(1)

Best,
Wolfgang
#
Ah, nevermind. X11Fonts() is only for Xlib.

I'll see if I can figure out how to get 'fc-match Courier' to point to a otf/ttf font. I guess this is explained here: https://www.freedesktop.org/software/fontconfig/fontconfig-user.html

Best,
Wolfgang
#
And to conclude this little saga (that nobody is probably reading, but at least then there is a solution in the archives):

Adding the following to ~/.config/fontconfig/fonts.conf worked for me:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <match>
        <test name="family">
            <string>Courier</string>
        </test>
        <edit mode="assign" name="file">
            <string>/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf</string>
        </edit>
    </match>
</fontconfig>

Substitute your favorite (ttf/otf) monospaced font above.

Best,
Wolfgang
#
On 2021-01-20 09:45 +0000, Viechtbauer, Wolfgang (SP) wrote:
Glad you got to the bottom of this!  

I have this in my ~/.fonts.conf:

	<?xml version='1.0'?>
	<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
	<fontconfig>
	
	    <alias>
	        <family>serif</family>
	        <prefer>
	            <family>XITS</family>
	            <family>Times New Roman</family>
	            <family>DejaVu Serif</family>
	            <family>Linux Libertine</family>
	            <family>JoyPixels</family>
	        </prefer>
	    </alias>
	    <alias>
	        <family>sans-serif</family>
	        <prefer>
	            <family>DejaVu Sans</family>
	            <family>Droid Sans</family>
	            <family>ProFontIIx</family>
	        </prefer>
	    </alias>
	    <alias>
	        <family>sans</family>
	        <prefer>
	            <family>DejaVu Sans</family>
	            <family>Liberation</family>
	            <family>Droid Sans</family>
	            <family>JoyPixels</family>
	        </prefer>
	    </alias>
	    <alias>
	        <family>monospace</family>
	        <prefer>
	            <family>DejaVu Sans Mono</family>
	            <family>Liberation Mono</family>
	            <family>Droid Sans Mono</family>
	            <family>Inconsolata</family>
	            <family>JoyPixels</family>
	        </prefer>
	    </alias>
	    <alias>
	        <family>mono</family>
	        <prefer>
	            <family>DejaVu Sans Mono</family>
	            <family>Liberation Mono</family>
	            <family>Droid Sans Mono</family>
	            <family>Inconsolata</family>
	            <family>JoyPixels</family>
	        </prefer>
	    </alias>
	
	    <match target="pattern">
	        <test name="prgname" qual="any">
	            <string>rofi</string>
	        </test>
	        <edit name="family" mode="prepend_first">
	            <string>Noto Color Emoji</string>
	        </edit>
	    </match>
	   
	    <match target="pattern">
	        <test name="prgname" qual="any">
	            <string>geany</string>
	        </test>
	        <edit name="family" mode="prepend_first">
	            <string>Noto Color Emoji</string>
	        </edit>
	    </match>
	
	</fontconfig>

Best,
Rasmus