Hi Fred, thanks for pointing that out...
fredx181 wrote:@step, MochiMoppel pointed out at the beginning of this thread "fclist produces duplicates when font folders are symlinked."
I simply added "u" to the sort command at line 382 of your fifth update:
And no duplicates are showing for me.
Forgive my lengthy answer, there's a short summary at the end if you don't have the time. I considered duplicates before and decided not to discard them by design. My reasons are that one can have different revisions of the same font file (I do), and can have multiple fonts in the same physical file (I do).
Code: Select all
LINE 382:
# fc-list -f '%{file|basename}\n%{file}\n%{index}\b' | tr '\b' '\0' | LC_ALL=C sort -fsz -t $'\n' -k1,1n -k1,1 -k3,3n
Let me point out that fc-list on line 382 produces a unique key for each _font_ (not just for the font _file_). Fc-list extracts basename+fullpathname+index. You'd think that fullpathname is unique enough, as there can't be two files with the same full path in Linux, but when the font file is a True Type font Collection file (TTC) only the index discriminates among the fonts inside the file because basename and fullpathname are all the same.
I fail to understand why one would want to symlink folders under /usr/share/fonts and other XDG_DATA directories. I think the symlinks would produce more data for fontconfig to shuffle but no benefit.
Setting my consideration aside, let's see what changing -fnz to -fnzu on line 382 does. Indeed it discards duplicated font files residing in symlinked _folders_. However, it also discards all fonts but the first one (index=0) in a TTC file. That's undesirable.
There's more. If you set up an experiment similar to the one shown below, where in addition to symlinking a folder I have also symlinked a file therein, and add -u to -fnz, you will discover that the duplicated _file_ isn't discarded (at least it isn't with the version of GNU sort that is installed in my system).
Code: Select all
cd /usr/share/fonts/X11
# ln -sT TTF DUP
# ln -s DejaVuSans.ttf TTF/DUP.ttf
# stat --printf "%i\t%N\n" -- {DUP,TTF}/{DejaVuSans,DUP}.ttf
5792 'DUP/DejaVuSans.ttf'
34216 'DUP/DUP.ttf' -> 'DejaVuSans.ttf'
5792 'TTF/DejaVuSans.ttf'
34216 'TTF/DUP.ttf' -> 'DejaVuSans.ttf'
The reason is to be found in the way GNU sort options work.
info sort wrote:
...
The following options affect the ordering of output lines. They may
be specified globally or as part of a specific key field. If no key
fields are specified, global options apply to comparison of entire
lines; otherwise the global options are inherited by key fields that do
not specify any special options of their own. In pre-POSIX versions of
‘sort’, global options affect only later key fields, so portable shell
scripts should specify global options first.
Line 382 specifies three key fields, k1,1n, k1,1 and k3,3n. With -u added globally to -fnz, uniqueness is applied to the second key only, that is to k1,1, which is the basename. That's why most TTC fonts will be missing.
EDIT: But maybe it's your purpose showing all listed, then please ignore this.
Yes, showing all listed was my purpose. And I couldn't ignore you very good question
In summary:
I prefer to leave the script as is because it can display versions of the same font and TTC font files correctly, and because in my system I don't symlink folders under /usr/share/X11/fonts.
For people who do, and don't use TTC or font versions, your edit is good.