From 8331000eb1d76381fe5f03fa6c090ae936a110b6 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 27 Apr 2013 02:31:08 +0200 Subject: drop scanning fonts.conf in favor of `fc-cat` --- luaotfload-database.lua | 140 ++++++++++++++++-------------------------------- 1 file changed, 45 insertions(+), 95 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index 4980766..e23902a 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -21,6 +21,7 @@ local tonumber = tonumber local fontloaderinfo = fontloader.info local iolines = io.lines local ioopen = io.open +local iopopen = io.popen local kpseexpand_path = kpse.expand_path local kpseexpand_var = kpse.expand_var local kpselookup = kpse.lookup @@ -234,7 +235,6 @@ local find_closest local flush_cache local font_fullinfo local load_names -local read_fonts_conf local reload_db local resolve local save_names @@ -1141,6 +1141,29 @@ local function scan_texmf_fonts(fontnames, newfontnames) return n_scanned, n_new end +--- fc-cat outputs every directory it finds fonts in, +--- so we have to remove all subdirectories from the +--- list. + +--- dir list -> dir list +local collapse_paths = function (dir_lst) + tablesort(dir_lst) + local last = dir_lst[1] + local res = { last } + local ndirs = #dir_lst + if ndirs > 1 then + for i=2, ndirs do + local dir = dir_lst[i] + if stringsub(dir, 1, #last) ~= last then + --- new prefix + res[#res+1] = dir + last = dir + end + end + end + return res +end + --[[ For the OS fonts, there are several options: - if OSFONTDIR is set (which is the case under windows by default but @@ -1148,99 +1171,32 @@ end in the scan_texmf_fonts. - if not: - under Windows and Mac OSX, we take a look at some hardcoded directories - - under Unix, we read /etc/fonts/fonts.conf and read the directories in it + - under Unix, we parse the output of “fc-cat -v” This means that if you have fonts in fancy directories, you need to set them in OSFONTDIR. ]] ---- (string -> tab -> tab -> tab) -read_fonts_conf = function (path, results, passed_paths) - --[[ - This function parses /etc/fonts/fonts.conf and returns all the dir - it finds. The code is minimal, please report any error it may - generate. - - TODO fonts.conf are some kind of XML so in theory the following - is totally inappropriate. Maybe a future version of the - lualibs will include the lxml-* files from Context so we - can write something presentable instead. - ]] - local fh = ioopen(path) - passed_paths[#passed_paths+1] = path - passed_paths_set = tabletohash(passed_paths, true) - if not fh then - report("log", 2, "db", "cannot open file %s", path) - return results - end - local incomments = false - for line in fh:lines() do - while line and line ~= "" do - -- spaghetti code... hmmm... - if incomments then - local tmp = stringfind(line, '-->') --- wtf? - if tmp then - incomments = false - line = stringsub(line, tmp+3) - else - line = nil - end - else - local tmp = stringfind(line, '