From a82850e3121af3f0c2412a9a2d8b442cf44cbac2 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 27 Apr 2013 12:26:55 +0200 Subject: Revert to old fonts.conf scanner because of ``io.popen`` restrictions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apparently ``fc-cat`` would have to be whitelisted in TeX Live if we want to rebuild the database during document compilation. Thanks Élie, FOR POINTing that out to me. --- luaotfload-database.lua | 140 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 45 deletions(-) (limited to 'luaotfload-database.lua') diff --git a/luaotfload-database.lua b/luaotfload-database.lua index e23902a..4980766 100644 --- a/luaotfload-database.lua +++ b/luaotfload-database.lua @@ -21,7 +21,6 @@ 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 @@ -235,6 +234,7 @@ 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,29 +1141,6 @@ 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 @@ -1171,32 +1148,99 @@ end in the scan_texmf_fonts. - if not: - under Windows and Mac OSX, we take a look at some hardcoded directories - - under Unix, we parse the output of “fc-cat -v” + - under Unix, we read /etc/fonts/fonts.conf and read the directories in it This means that if you have fonts in fancy directories, you need to set them in OSFONTDIR. ]] ---[[doc-- -Instead of processing the fontconfig configuration files with a -haphazarad XML parser, we scan the output of fc-cache for search paths -and use these. This way we don’t need to resolve possible included -files. ---doc]]-- -local get_fontconfig_paths = function ( ) - local fc_cat_cmd = "fc-cat -v 2> /dev/null" - local res = { } - local chan = assert(iopopen(fc_cat_cmd, "r"), - "cannot read from pipe") - local nlines = 0 - for line in chan:lines() do - nlines = nlines + 1 - if stringsub(line, 1, 11) == "Directory: " then - res[#res+1] = string.explode(line, " ")[2] .. "/" +--- (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, '