Freebsd – n Easy Way to Add Fonts

fontconfigfontsfreebsdxorg

After losing my beloved 5+ year Gentoo install to a hardware failure, I've gone to FreeBSD. I felt this was the next logical step in my exploration and use of source based operating systems. In reading all the associated documentation for FreeBSD, while installing the XOrg Server, the 5.6 – Using Fonts in XOrg section caught my attention. Having realized I never added the line:

Section "Files"
   FontPath  "/usr/share/fonts/...."
EndSection

for any fonts on my Gentoo install, I now understand why my DE looked like crap. Being a disabled one handed typist makes it tougher on me to edit the Files Section by hand, and I would prefer to add fonts by hand as a last resort. As such, is there a way to add the output from fc-list : file to the Files Section of xorg.conf using either a tool someone created that I have yet to find, or some fancy shell script etc that the readers here are so good at crafting?

Note: I use nvidia-xconfig to generate my xorg.conf file, so it's far from the modular approach recommended nowadays. Can I mix and match the conf.d approach with the generated config if need be?

Best Answer

If I am understanding the question, and you have vim installed on the system (this could work with vi as well, as these are just ex commands)
Running the below command at a terminal, will:

  • read in the file: xorg.conf - obviously replace this with the file you want to modify. Note: this file xorg.conf will not be modified, in case something goes wrong with the script.
  • do some text manipulation
  • the output of the commands will be place in file: /tmp/temp_xorg.conf

If after these operations, you are satisfied with the state of /tmp/temp_xorg.conf you could copy it to the location of your real, working xorg config file.


run the commands

run this at a shell prompt to produce fontpaths directories which are in a format that can go in an xorg conf file (thanks to @meuh for this command).

fc-list : file | sed -E 's#(.*)/.*#\tFontPath "\1"#' | sort -u > /tmp/filepaths.txt

then run this command, which will take the output of the above command and insert it into the "Files" sections

$ vim -e xorg.conf << 'EOF' 
" move cursor to the line with the text: `Section "Files"`
/Section "Files"
" read in the output of `fc-list` at this point
r !fc-list
write /tmp/temp_xorg.conf
EOF

so if for example, xorg.conf looked like this:

Section "InputClass"
    Identifier  "trackpoint catchall"
    MatchIsPointer  "true"
    MatchProduct    "TrackPoint|DualPoint Stick"
    MatchDevicePath "/dev/input/event*"
    Option  "Emulate3Buttons"   "true"
    Option  "EmulateWheel"  "true"
    Option  "EmulateWheelButton"    "2"
    Option  "XAxisMapping"  "6 7"
    Option  "YAxisMapping"  "4 5"
EndSection

Section "Files"
    Identifier  "trackpoint catchall"
    MatchIsPointer  "true"
    MatchProduct    "TrackPoint|DualPoint Stick"
    MatchDevicePath "/dev/input/event*"
    Option  "Emulate3Buttons"   "true"
    Option  "EmulateWheel"  "true"
    Option  "EmulateWheelButton"    "2"
    Option  "XAxisMapping"  "6 7"
    Option  "YAxisMapping"  "4 5"
EndSection


Section "InputClass"
    Identifier  "trackpoint catchall"
    MatchIsPointer  "true"
    MatchProduct    "TrackPoint|DualPoint Stick"
    MatchDevicePath "/dev/input/event*"
    Option  "Emulate3Buttons"   "true"
    Option  "EmulateWheel"  "true"
    Option  "EmulateWheelButton"    "2"
    Option  "XAxisMapping"  "6 7"
    Option  "YAxisMapping"  "4 5"
EndSection

After running the above command /tmp/temp_xorg.conf should look like this:

Section "InputClass"
    Identifier  "trackpoint catchall"
    MatchIsPointer  "true"
    MatchProduct    "TrackPoint|DualPoint Stick"
    MatchDevicePath "/dev/input/event*"
    Option  "Emulate3Buttons"   "true"
    Option  "EmulateWheel"  "true"
    Option  "EmulateWheelButton"    "2"
    Option  "XAxisMapping"  "6 7"
    Option  "YAxisMapping"  "4 5"
EndSection

Section "Files"
    FontPath "/home/ubuntu/.fonts"
    FontPath "/usr/share/fonts/opentype/noto"
    FontPath "/usr/share/fonts/opentype/stix"
    FontPath "/usr/share/fonts/opentype/stix-word"
    FontPath "/usr/share/fonts/truetype"
    FontPath "/usr/share/fonts/truetype/abyssinica"
    FontPath "/usr/share/fonts/truetype/ancient-scripts"
    FontPath "/usr/share/fonts/truetype/dejavu"
    FontPath "/usr/share/fonts/truetype/fonts-guru-extra"
    FontPath "/usr/share/fonts/truetype/freefont"
    FontPath "/usr/share/fonts/truetype/kacst"
    FontPath "/usr/share/fonts/truetype/kacst-one"
    FontPath "/usr/share/fonts/truetype/lao"
    FontPath "/usr/share/fonts/truetype/lato"
    FontPath "/usr/share/fonts/truetype/liberation"
    FontPath "/usr/share/fonts/truetype/lohit-punjabi"
    FontPath "/usr/share/fonts/truetype/nanum"
    FontPath "/usr/share/fonts/truetype/openoffice"
    FontPath "/usr/share/fonts/truetype/padauk"
    FontPath "/usr/share/fonts/truetype/sinhala"
    FontPath "/usr/share/fonts/truetype/takao-gothic"
    FontPath "/usr/share/fonts/truetype/tibetan-machine"
    FontPath "/usr/share/fonts/truetype/tlwg"
    FontPath "/usr/share/fonts/truetype/ttf-khmeros-core"
    FontPath "/usr/share/fonts/truetype/ubuntu-font-family"
    FontPath "/usr/share/fonts/type1/gsfonts"
    FontPath "/usr/share/fonts/X11/Type1"
    Identifier  "trackpoint catchall"
    MatchIsPointer  "true"
    MatchProduct    "TrackPoint|DualPoint Stick"
    MatchDevicePath "/dev/input/event*"
    Option  "Emulate3Buttons"   "true"
    Option  "EmulateWheel"  "true"
    Option  "EmulateWheelButton"    "2"
    Option  "XAxisMapping"  "6 7"
    Option  "YAxisMapping"  "4 5"
EndSection


Section "InputClass"
    Identifier  "trackpoint catchall"
    MatchIsPointer  "true"
    MatchProduct    "TrackPoint|DualPoint Stick"
    MatchDevicePath "/dev/input/event*"
    Option  "Emulate3Buttons"   "true"
    Option  "EmulateWheel"  "true"
    Option  "EmulateWheelButton"    "2"
    Option  "XAxisMapping"  "6 7"
    Option  "YAxisMapping"  "4 5"
EndSection
Related Question