5

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?

1

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
7
  • That's very close... Every Directory entry needs a FontPath. See FreeBSD fonts – eyoung100 Apr 12 '17 at 18:48
  • @eyoung100 and the path needs to be wrapped in quotes and indented too, right? – the_velour_fog Apr 12 '17 at 19:11
  • @eyoung100 , I cant get the above command to fix up all the inserted lines programmatically, but on my instance of vim visually selecting all the inserted lines and running this on the command line worked :'<,'>normal! I^IFontPath "^[A"^[j note: in this case ^I is a real <TAB> character, and ^[ is a real <Escape> character, Im not sure if they will be preserved through this web interface. But, for some reason, that command wont work when running vim in the non-interactive ex mode (thats what vim -e does) – the_velour_fog Apr 12 '17 at 20:22
  • I'll try this shortly... trying to install DE now and running into a hurdle... Oh ad the font names don't need to be there, only one occurence of each fonts directory – eyoung100 Apr 12 '17 at 20:25
  • @eyoung100 oh ok, do you know how to get fc-list to only output the folder name, without the fonts?, I tried using the command in your description fc-list :file but it did the same thing as fc-list – the_velour_fog Apr 12 '17 at 20:59
1

For the configuration "mix and match" part of the question - the answer is "kind of".

The xorg.conf man page lists the configuration sources in order of precedence, and states "When the same information is supplied in more than one way, the highest precedence mechanism is used".

By observation (since "same information" and "more than one way" aren't clearly defined in the man page, to my mind), this means you cannot override/update a section in xorg.conf (like Section "Files" for fonts) with an xorg.conf.d file since that has lower precedence. Although lower precedence files are read and parsed, section contents are silently disregarded for those sections that already exist at a higher precedence.

The current Nvidia driver (396, on Linux only) does now use an xorg.conf.d fragment, but only for the Linux DRM Xorg driver, it still creates a near-monolithic xorg.conf during installation.

Happily, nvidia-xconfig does not change this section, so if it helps you could comment it out of xorg.conf and migrate it into one or more xorg.conf.d files. Multiple duplicate sections at the same precedence, i.e. all within a single xorg.conf.d directory, does result in merged values as hoped.

An easy way to generate the directives is:

fc-list -f 'Fontpath "%{file|dirname}"\n' : | sort -u

This uses the formatted output (-f) of fc-list to create the required configuration lines, %{file} is the filename of each font, |dirname is a filter that outputs the directory name (exactly like the dirname shell command), then sort -u for unique paths. You may wish to reorder the paths if you have many fonts, if you have bitmap versions you can do something like this to reorder:

fc-list -f '    Fontpath "%{file|dirname}"\n' :scalable=true | sort -u
fc-list -f '    Fontpath "%{file|dirname}"\n' :scalable=false | sort -u

You can paste that output as required - or - as an example of all the steps (as root)

# extract Files section from xorg.conf to a separate conf
sed -n '/^Section..Files/,/^EndSection/p' \
  < /etc/X11/xorg.conf > /etc/x11/xorg.conf.d/10-section-files.conf
# comment out Files section in xorg.conf
sed -i.bak '/^Section..Files/,/^EndSection/ s/^/#/' /etc/X11/xorg.conf

# paths for scalable fonts
( echo 'Section "Files"'; 
  fc-list -f '    Fontpath "%{file|dirname}"\n' :scalable=true | sort -u;
  echo 'EndSection' ) > /etc/X11/xorg.conf.d/20-fontpath.conf

# paths for non-scalable fonts
( echo 'Section "Files"'; 
  fc-list -f '    Fontpath "%{file|dirname}"\n' :scalable=False | sort -u;
  echo 'EndSection' ) > /etc/X11/xorg.conf.d/30-fontpath-fixed.conf

Reorder and remove duplicates if required, and restart X.

For completeness, you can also modify the font paths on the fly with xset, e.g.

xset +fp /usr/local/share/fonts/TTF

Check the current paths with xset q. You could trivially modify this to add such commands to your .xinitrc script so font paths persist independently of any subsequent X configuration changes, and save restarting X too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.