diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2010-06-25 10:58:06 +0300 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2010-06-25 10:58:06 +0300 |
commit | eeba4e7b4c68ecef42bd7831d951371f6269f068 (patch) | |
tree | d04c4bf6dc92ef4ba330b58a0790005d1953e876 /otfl-font-nms.lua | |
parent | f6aace6e9db3f96cc08dfc932954dbd695c60ee5 (diff) | |
download | luaotfload-eeba4e7b4c68ecef42bd7831d951371f6269f068.tar.gz |
Implement general font blacklisting mechanism
Blacklisted fonts are listed one per line in a file named
"otfl-blacklist.cnf", there can be as much copies of this file as kpse
can find (we look for "tex" format despite of the file extension, so it
can exist any where a .tex file can) and all found files will be loaded
an read.
The parser is rather dump, it assumes a good formated file; one font
per line, no trailing spaces, no inline comments, lines starting with
"%" and empty lines will be ignored, any other lines will end in the
blacklist table without any further processing.
Diffstat (limited to 'otfl-font-nms.lua')
-rw-r--r-- | otfl-font-nms.lua | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/otfl-font-nms.lua b/otfl-font-nms.lua index 7abc62b..53e66d2 100644 --- a/otfl-font-nms.lua +++ b/otfl-font-nms.lua @@ -362,6 +362,13 @@ local function load_font(filename, fontnames, newfontnames, texmf) local status = fontnames.status local basefile = texmf and basename(filename) or filename if filename then + if table.contains(names.blacklist, filename) or + table.contains(names.blacklist, basename(filename)) then + if trace_search then + logs.report("ignoring font '%s'", filename) + end + return + end local timestamp, db_timestamp db_timestamp = status[basefile] and status[basefile].timestamp timestamp = lfs.attributes(filename, "modification") @@ -460,6 +467,30 @@ else font_extensions = { "otf", "ttf", "ttc", "dfont" } end +names.blacklist = { } + +local function read_blacklist() + local files = { + kpse.lookup("otfl-blacklist.cnf", {all=true, format="tex"}) + } + local blacklist = names.blacklist + + if files and type(files) == "table" then + for _,v in next, files do + for line in io.lines(v) do + if line:find("^%%") or line:is_empty() then + -- comment or empty line + else + if trace_search then + logs.report("blacklisted file: %s", line) + end + blacklist[#blacklist+1] = line + end + end + end + end +end + local function scan_dir(dirname, fontnames, newfontnames, texmf) --[[ this function scans a directory and populates the list of fonts @@ -488,7 +519,7 @@ local function scan_dir(dirname, fontnames, newfontnames, texmf) if trace_search then logs.report("%d fonts found in '%s'", nbfound, dirname) end - list = remove_ignore_fonts(list) -- fixme: general solution required + for _,file in next, list do file = path_normalize(file) if trace_loading then @@ -498,30 +529,6 @@ local function scan_dir(dirname, fontnames, newfontnames, texmf) end end --- Temporary until a general solution is implemented: -if os.name == "macosx" then - ignore_fonts = { - -- this font kills the indexer: - "/System/Library/Fonts/LastResort.ttf" - } - function remove_ignore_fonts(fonts) - for N,fnt in ipairs(fonts) do - if table.contains(ignore_fonts,fnt) then - if trace_search then - logs.report("ignoring font '%s'", fnt) - end - table.remove(fonts,N) - end - end - return fonts - end --- This function is only necessary, for now, on Mac OS X. -else - function remove_ignore_fonts(fonts) - return fonts - end -end - local function scan_texmf_fonts(fontnames, newfontnames) --[[ The function that scans all fonts in the texmf tree, through kpathsea @@ -707,6 +714,7 @@ local function update_names(fontnames, force) end end local newfontnames = fontnames_init() + read_blacklist() scan_texmf_fonts(fontnames, newfontnames) if expandpath("$OSFONTDIR"):is_empty() then scan_os_fonts(fontnames, newfontnames) |