summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2014-07-13 14:29:10 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2014-07-13 14:29:10 +0200
commit88f95fa579f23ed08c72eb936d5866edc291edfd (patch)
tree04b9936adfdf3ee3520c80f994002e8a4558d434 /src
parent9491abe57c42b97253c6daffd8720b4251f6ddff (diff)
downloadluaotfload-88f95fa579f23ed08c72eb936d5866edc291edfd.tar.gz
[features,conf] configure default font features through configuration file
Diffstat (limited to 'src')
-rw-r--r--src/luaotfload-configuration.lua141
-rw-r--r--src/luaotfload-features.lua66
2 files changed, 137 insertions, 70 deletions
diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua
index e302ca6..1e1e907 100644
--- a/src/luaotfload-configuration.lua
+++ b/src/luaotfload-configuration.lua
@@ -2,10 +2,10 @@
-------------------------------------------------------------------------------
-- FILE: luaotfload-configuration.lua
-- DESCRIPTION: config file reader
--- REQUIREMENTS: Luaotfload > 2.4
+-- REQUIREMENTS: Luaotfload 2.5 or above
-- AUTHOR: Philipp Gesang (Phg), <phg42.2a@gmail.com>
-- VERSION: same as Luaotfload
--- CREATED: 2014-04-21 14:03:52+0200
+-- MODIFIED: 2014-07-13 14:19:32+0200
-------------------------------------------------------------------------------
--
@@ -47,7 +47,8 @@ local osgetenv = os.getenv
local lpeg = require "lpeg"
local lpegmatch = lpeg.match
-local lpegsplitter = lpeg.splitat ","
+local commasplitter = lpeg.splitat ","
+local equalssplitter = lpeg.splitat "="
local kpse = kpse
local kpseexpand_path = kpse.expand_path
@@ -99,6 +100,33 @@ local valid_formats = tabletohash {
"otf", "ttc", "ttf", "dfont", "afm", "pfb", "pfa",
}
+local feature_presets = {
+ arab = {
+ "ccmp", "locl", "isol", "fina", "fin2",
+ "fin3", "medi", "med2", "init", "rlig",
+ "calt", "liga", "cswh", "mset", "curs",
+ "kern", "mark", "mkmk",
+ },
+ deva = {
+ "ccmp", "locl", "init", "nukt", "akhn",
+ "rphf", "blwf", "half", "pstf", "vatu",
+ "pres", "blws", "abvs", "psts", "haln",
+ "calt", "blwm", "abvm", "dist", "kern",
+ "mark", "mkmk",
+ },
+ khmr = {
+ "ccmp", "locl", "pref", "blwf", "abvf",
+ "pstf", "pres", "blws", "abvs", "psts",
+ "clig", "calt", "blwm", "abvm", "dist",
+ "kern", "mark", "mkmk",
+ },
+ thai = {
+ "ccmp", "locl", "liga", "kern", "mark",
+ "mkmk",
+ },
+}
+
+
-------------------------------------------------------------------------------
--- DEFAULTS
@@ -136,6 +164,36 @@ local default_config = {
index_path_lua = nil,
index_path_luc = nil,
},
+ default_features = {
+ global = { mode = "node" },
+ dflt = {
+ "ccmp", "locl", "rlig", "liga", "clig",
+ "kern", "mark", "mkmk", 'itlc',
+ },
+
+ arab = feature_presets.arab,
+ syrc = feature_presets.arab,
+ mong = feature_presets.arab,
+ nko = feature_presets.arab,
+
+ deva = feature_presets.deva,
+ beng = feature_presets.deva,
+ guru = feature_presets.deva,
+ gujr = feature_presets.deva,
+ orya = feature_presets.deva,
+ taml = feature_presets.deva,
+ telu = feature_presets.deva,
+ knda = feature_presets.deva,
+ mlym = feature_presets.deva,
+ sinh = feature_presets.deva,
+
+ khmr = feature_presets.khmr,
+ tibt = feature_presets.khmr,
+ thai = feature_presets.thai,
+ lao = feature_presets.thai,
+
+ hang = { "ccmp", "ljmo", "vjmo", "tjmo", },
+ },
}
-------------------------------------------------------------------------------
@@ -234,12 +292,32 @@ local build_cache_paths = function ()
return true
end
+
+local set_default_features = function ()
+ local default_features = config.luaotfload.default_features
+ luaotfload.features = luaotfload.features or {
+ global = { },
+ defaults = { },
+ }
+ current_features = luaotfload.features
+ for var, val in next, default_features do
+ if var == "global" then
+ current_features.global = val
+ else
+ current_features.defaults[var] = val
+ end
+ end
+ return true
+end
+
+
reconf_tasks = {
- { "Set the log level" , set_loglevel },
- { "Build cache paths" , build_cache_paths },
- { "Check terminal dimensions" , check_termwidth },
- { "Set the font filter" , set_font_filter },
- { "Install font name resolver", set_name_resolver },
+ { "Set the log level" , set_loglevel },
+ { "Build cache paths" , build_cache_paths },
+ { "Check terminal dimensions" , check_termwidth },
+ { "Set the font filter" , set_font_filter },
+ { "Install font name resolver", set_name_resolver },
+ { "Set default features" , set_default_features },
}
-------------------------------------------------------------------------------
@@ -259,13 +337,26 @@ local tointeger = function (n)
end
end
+local toarray = function (s)
+ local fields = { lpegmatch (commasplitter, s) }
+ local ret = { }
+ for i = 1, #fields do
+ local field = stringstrip (fields[i])
+ if field and field ~= "" then
+ ret[#ret + 1] = field
+ end
+ end
+ return ret
+end
+
+
local option_spec = {
db = {
formats = {
in_t = string_t,
out_t = string_t,
transform = function (f)
- local fields = { lpegmatch (lpegsplitter, f) }
+ local fields = toarray (f)
--- check validity
if not fields then
@@ -278,7 +369,7 @@ local option_spec = {
local known = { }
local result = { }
for i = 1, #fields do
- local field = stringstrip (fields[i])
+ local field = fields[i]
if known[field] ~= true then
--- yet unknown, tag as seen
known[field] = true
@@ -361,6 +452,34 @@ local option_spec = {
index_path_lua = { in_t = string_t, },
index_path_luc = { in_t = string_t, },
},
+ default_features = {
+ global = {
+ in_t = string_t,
+ out_t = table_t,
+ transform = function (s)
+ --- Split key=value arguments into hash.
+ local result = { }
+ local fields = toarray (s)
+ for _, field in next, fields do
+ local var, val = lpegmatch (equalssplitter, field)
+ if var and val then
+ if val == "true" then
+ result[var] = true
+ else
+ result[var] = val
+ end
+ end
+ end
+ return result
+ end,
+ },
+ dflt = { in_t = string_t, out_t = table_t, transform = toarray, },
+ arab = { in_t = string_t, out_t = table_t, transform = toarray, },
+ deva = { in_t = string_t, out_t = table_t, transform = toarray, },
+ khmr = { in_t = string_t, out_t = table_t, transform = toarray, },
+ thai = { in_t = string_t, out_t = table_t, transform = toarray, },
+ hang = { in_t = string_t, out_t = table_t, transform = toarray, },
+ },
}
-------------------------------------------------------------------------------
@@ -447,7 +566,7 @@ local process_options = function (opts)
local vspec = spec[var]
local t_val = type (val)
if not vspec then
- logreport ("both", 0, "conf",
+ logreport ("both", 2, "conf",
"Section %d (%s): invalid configuration variable %q (%q); ignoring.",
i, title,
var, tostring (val))
diff --git a/src/luaotfload-features.lua b/src/luaotfload-features.lua
index 4ad188f..0dc7d0a 100644
--- a/src/luaotfload-features.lua
+++ b/src/luaotfload-features.lua
@@ -65,58 +65,6 @@ local stringformat = string.format
local stringis_empty = string.is_empty
local mathceil = math.ceil
-local defaults = {
- dflt = {
- "ccmp", "locl", "rlig", "liga", "clig",
- "kern", "mark", "mkmk", 'itlc',
- },
- arab = {
- "ccmp", "locl", "isol", "fina", "fin2",
- "fin3", "medi", "med2", "init", "rlig",
- "calt", "liga", "cswh", "mset", "curs",
- "kern", "mark", "mkmk",
- },
- deva = {
- "ccmp", "locl", "init", "nukt", "akhn",
- "rphf", "blwf", "half", "pstf", "vatu",
- "pres", "blws", "abvs", "psts", "haln",
- "calt", "blwm", "abvm", "dist", "kern",
- "mark", "mkmk",
- },
- khmr = {
- "ccmp", "locl", "pref", "blwf", "abvf",
- "pstf", "pres", "blws", "abvs", "psts",
- "clig", "calt", "blwm", "abvm", "dist",
- "kern", "mark", "mkmk",
- },
- thai = {
- "ccmp", "locl", "liga", "kern", "mark",
- "mkmk",
- },
- hang = {
- "ccmp", "ljmo", "vjmo", "tjmo",
- },
-}
-
-local global_defaults = { mode = "node" }
-
-defaults.beng = defaults.deva
-defaults.guru = defaults.deva
-defaults.gujr = defaults.deva
-defaults.orya = defaults.deva
-defaults.taml = defaults.deva
-defaults.telu = defaults.deva
-defaults.knda = defaults.deva
-defaults.mlym = defaults.deva
-defaults.sinh = defaults.deva
-
-defaults.syrc = defaults.arab
-defaults.mong = defaults.arab
-defaults.nko = defaults.arab
-
-defaults.tibt = defaults.khmr
-
-defaults.lao = defaults.thai
---[[ begin excerpt from font-ott.lua ]]
@@ -800,8 +748,8 @@ local set_default_features = function (speclist)
or "dflt"
if support_incomplete[script] then
report("log", 0, "load",
- "support for the requested script: "
- .. "%q may be incomplete", script)
+ "Support for the requested script: "
+ .. "%q may be incomplete.", script)
end
else
script = "dflt"
@@ -809,15 +757,15 @@ local set_default_features = function (speclist)
speclist.script = script
report("log", 1, "load",
- "auto-selecting default features for script: %s",
+ "Auto-selecting default features for script: %s.",
script)
- local requested = defaults[script]
+ local requested = luaotfload.features.defaults[script]
if not requested then
report("log", 1, "load",
- "no defaults for script %q, falling back to \"dflt\"",
+ "No default features for script %q, falling back to \"dflt\".",
script)
- requested = defaults.dflt
+ requested = luaotfload.features.defaults.dflt
end
for i=1, #requested do
@@ -825,7 +773,7 @@ local set_default_features = function (speclist)
if speclist[feat] ~= false then speclist[feat] = true end
end
- for feat, state in next, global_defaults do
+ for feat, state in next, luaotfload.features.global do
--- This is primarily intended for setting node
--- mode unless “base” is requested, as stated
--- in the manual.