summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-07-31 22:37:07 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2013-07-31 22:37:07 +0200
commite8b9a15801b4d0cd52126d21d4ba262b472ba45c (patch)
tree7b1ae4c096b175797bd7ea7df0627ec51364c6b6
parentf84c7341ed8f83c0624be6be2ea796d4bbb97ae9 (diff)
downloadluaotfload-e8b9a15801b4d0cd52126d21d4ba262b472ba45c.tar.gz
[db] remove --type1 option in favor of --formats, a configurable format set
-rw-r--r--luaotfload-database.lua83
-rwxr-xr-xluaotfload-tool.lua8
2 files changed, 63 insertions, 28 deletions
diff --git a/luaotfload-database.lua b/luaotfload-database.lua
index f53d19f..cfcd27c 100644
--- a/luaotfload-database.lua
+++ b/luaotfload-database.lua
@@ -93,7 +93,7 @@ local names = fonts.names
config = config or { }
config.luaotfload = config.luaotfload or { }
config.luaotfload.resolver = config.luaotfload.resolver or "normal"
-config.luaotfload.include_t1 = config.luaotfload.include_t1 == true
+config.luaotfload.formats = config.luaotfload.formats or "otf,ttf,ttc,dfont"
if config.luaotfload.update_live ~= false then
--- this option allows for disabling updates
@@ -369,6 +369,7 @@ local resolve_fullpath
local save_names
local save_lookups
local update_names
+local set_font_filter
--- state of the database
local fonts_loaded = false
@@ -1263,6 +1264,7 @@ end
local loaders = {
otf = ot_fullinfo,
+ ttc = ot_fullinfo,
ttf = ot_fullinfo,
afm = function (filename, _, texmf, basename)
@@ -1521,13 +1523,13 @@ read_blacklist = function ()
names.blacklist = create_blacklist(blacklist, whitelist)
end
-local ordinary_extensions = { "otf", "ttf", "ttc", "dfont" }
-local type1_extensions = { "pfb", --[[afm]] }
+----- ordinary_extensions = { "otf", "ttf", "ttc", "dfont" }
+----- type1_extensions = { "pfb", --[[afm]] }
----- font_extensions_set = tabletohash (font_extensions)
-local get_font_filter
+local p_font_filter
do
- local luaotfloadconfig = config.luaotfload
+ local current_formats = { }
local extension_pattern = function (list)
local pat
@@ -1539,25 +1541,58 @@ do
pat = pat + P(e)
end
end
- return pat * P(-1)
+ pat = pat * P(-1)
+ return (1 - pat)^1 * pat
end
- local extns = extension_pattern (ordinary_extensions)
- local t1extns = extns + extension_pattern (type1_extensions)
- local ordinary = (1 - extns)^1 * extns
- local with_t1 = (1 - t1extns)^1 * t1extns
+ --- small helper to adjust the font filter pattern (--formats
+ --- option)
- get_font_filter = function ()
- if luaotfloadconfig.include_t1 == true then
- return with_t1
- else
- return ordinary
+ set_font_filter = function (formats)
+
+ if not formats and type (formats) == "string" then
+ return
end
+
+ if stringsub (formats, 1, 1) == "+" then -- add
+ formats = lpegmatch (splitcomma, stringsub (formats, 2))
+ if formats then
+ current_formats = tableappend (current_formats, formats)
+ end
+ elseif stringsub (formats, 1, 1) == "-" then -- add
+ formats = lpegmatch (splitcomma, stringsub (formats, 2))
+ if formats then
+ local newformats = { }
+ for i = 1, #current_formats do
+ local fmt = current_formats[i]
+ local include = true
+ for j = 1, #formats do
+ if current_formats[i] == formats[j] then
+ include = false
+ goto skip
+ end
+ end
+ newformats[#newformats+1] = fmt
+ ::skip::
+ end
+ current_formats = newformats
+ end
+ else -- set
+ formats = lpegmatch (splitcomma, formats)
+ if formats then
+ current_formats = formats
+ end
+ end
+
+ p_font_filter = extension_pattern (current_formats)
end
+
+ --- initialize
+ set_font_filter (config.luaotfload.formats)
end
local process_dir_tree
-process_dir_tree = function (acc, dirs, criterium)
+process_dir_tree = function (acc, dirs)
if not next (dirs) then --- done
return acc
end
@@ -1580,20 +1615,20 @@ process_dir_tree = function (acc, dirs, criterium)
then
dirs[#dirs+1] = fullpath
elseif lfsisfile (fullpath) then
- if lpegmatch (criterium, stringlower (ent))
+ if lpegmatch (p_font_filter, stringlower (ent))
then
newfiles[#newfiles+1] = fullpath
end
end
end
end
- return process_dir_tree (tableappend (acc, newfiles), dirs, criterium)
+ return process_dir_tree (tableappend (acc, newfiles), dirs)
end
--- cannot cd; skip
- return process_dir_tree (acc, dirs, criterium)
+ return process_dir_tree (acc, dirs)
end
-local process_dir = function (dir, criterium)
+local process_dir = function (dir)
local pwd = lfscurrentdir ()
if lfschdir (dir) then
lfschdir (pwd)
@@ -1604,7 +1639,7 @@ local process_dir = function (dir, criterium)
if ent ~= "." and ent ~= ".." and not blacklist[ent] then
local fullpath = dir .. "/" .. ent
if lfsisfile (fullpath) then
- if lpegmatch (criterium, stringlower (ent))
+ if lpegmatch (p_font_filter, stringlower (ent))
then
files[#files+1] = fullpath
end
@@ -1618,12 +1653,11 @@ end
--- string -> bool -> string list
local find_font_files = function (root, recurse)
- local criterium = get_font_filter ()
if lfsisdir (root) then
if recurse == true then
- return process_dir_tree ({}, { root }, criterium)
+ return process_dir_tree ({}, { root })
else --- kpathsea already delivered the necessary subdirs
- return process_dir (root, criterium)
+ return process_dir (root)
end
end
end
@@ -2390,6 +2424,7 @@ end
-----------------------------------------------------------------------
names.scan_dir = scan_dir
+names.set_font_filter = set_font_filter
names.flush_lookup_cache = flush_lookup_cache
names.save_lookups = save_lookups
names.load = load_names
diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua
index 1e88d4f..8cac103 100755
--- a/luaotfload-tool.lua
+++ b/luaotfload-tool.lua
@@ -108,7 +108,7 @@ config.luaotfload.names_dir = config.luaotfload.names_dir or "names"
config.luaotfload.cache_dir = config.luaotfload.cache_dir or "fonts"
config.luaotfload.index_file = config.luaotfload.index_file
or "luaotfload-names.lua"
-config.luaotfload.include_t1 = config.luaotfload.include_t1 == true
+config.luaotfload.formats = config.luaotfload.formats or "otf,ttf,ttc,dfont"
do -- we don’t have file.basename and the likes yet, so inline parser ftw
local slash = P"/"
@@ -1026,7 +1026,7 @@ local process_cmdline = function ( ) -- unit -> jobspec
["prefer-texmf"] = "p",
quiet = "q",
["show-blacklist"] = "b",
- type1 = 0,
+ formats = 1,
update = "u",
verbose = 1,
version = "V",
@@ -1110,8 +1110,8 @@ local process_cmdline = function ( ) -- unit -> jobspec
elseif v == "diagnose" then
action_pending["diagnose"] = true
result.asked_diagnostics = optarg[n]
- elseif v == "type1" then
- config.luaotfload.include_t1 = true
+ elseif v == "formats" then
+ names.set_font_filter (optarg[n])
end
end