diff options
Diffstat (limited to 'src/luaotfload-parsers.lua')
-rw-r--r-- | src/luaotfload-parsers.lua | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/src/luaotfload-parsers.lua b/src/luaotfload-parsers.lua index c2b4f2e..b188bb0 100644 --- a/src/luaotfload-parsers.lua +++ b/src/luaotfload-parsers.lua @@ -12,7 +12,8 @@ local traversal_maxdepth = 42 --- prevent stack overflows local rawset = rawset local lpeg = require "lpeg" -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local patterns = lpeg.patterns +local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V local lpegmatch = lpeg.match local C, Cc, Cf = lpeg.C, lpeg.Cc, lpeg.Cf local Cg, Cmt, Cs, Ct = lpeg.Cg, lpeg.Cmt, lpeg.Cs, lpeg.Ct @@ -57,6 +58,7 @@ local equals = P"=" local dash = P"-" local gartenzaun = P"#" local lbrk, rbrk = P"[", P"]" +local brackets = lbrk + rbrk local squote = P"'" local dquote = P"\"" @@ -602,6 +604,22 @@ local combodef1 = Ct(comboidx * combomapsep * comboid) --> no chars local combodef = Ct(comboidx * combomapsep * comboidchars) local combolist = Ct(combodef1 * (comborowsep * combodef)^1) +--- subfonts ---------------------------------------------------------- +--- This rule is present in the original parser. It sets the “sub” +--- field of the specification which allows addressing a specific +--- font inside a TTC container. Neither in Luatex-Fonts nor in +--- Luaotfload is this documented, so we might as well silently drop +--- it. However, as backward compatibility is one of our prime goals we +--- just insert it here and leave it undocumented until someone cares +--- to ask. (Note: afair subfonts are numbered, but this rule matches a +--- string; I won’t mess with it though until someone reports a +--- problem.) +--- local subvalue = P("(") * (C(P(1-S("()"))^1)/issub) * P(")") -- for Kim +--- Note to self: subfonts apparently start at index 0. Tested with +--- Cambria.ttc that includes “Cambria Math” at 0 and “Cambria” at 1. +--- Other values cause luatex to segfault. +local subfont = P"(" * Cg((1 - S"()")^1, "sub") * P")" + --- lookups ----------------------------------------------------------- local fontname = C((1-S":(/")^1) --- like luatex-fonts local unsupported = Cmt((1-S":(")^1, check_garbage) @@ -618,7 +636,19 @@ local prefixed = P"name:" * ws * Cg(fontname, "name") + P"kpse:" * ws * Cg(fontname, "kpse") + P"my:" * ws * Cg(fontname, "my") local unprefixed = Cg(fontname, "anon") -local path_lookup = lbrk * Cg(C((1-rbrk)^1), "path") * rbrk +--- Bracketed “path” lookups: These may contain any character except +--- for unbalanced brackets. A backslash escapes any following +--- character. Everything inside the outermost brackets is treated as +--- part of the filename or path to look up. Subfonts may be specified +--- in parens *after* the closing bracket. Note that this differs from +--- Xetex whose syntax expects the subfont passed inside the brackets, +--- separated by a colon. +local path_escape = backslash / "" * patterns.utf8char +local path_content = path_escape + (1 - brackets) +local path_balanced = { (path_content + V(2))^1 + , lbrk * V(1)^-1 * rbrk } +local path_lookup = lbrk * Cg(Cs(path_balanced), "path") * rbrk + * subfont^-1 --- features ---------------------------------------------------------- local field_char = anum + S"+-.!?" --- sic! @@ -644,22 +674,6 @@ local feature_list = Cf(Ct"" * (featuresep * option^-1)^0 , rawset) * featuresep^-1 - ---- other ------------------------------------------------------------- ---- This rule is present in the original parser. It sets the “sub” ---- field of the specification which allows addressing a specific ---- font inside a TTC container. Neither in Luatex-Fonts nor in ---- Luaotfload is this documented, so we might as well silently drop ---- it. However, as backward compatibility is one of our prime goals we ---- just insert it here and leave it undocumented until someone cares ---- to ask. (Note: afair subfonts are numbered, but this rule matches a ---- string; I won’t mess with it though until someone reports a ---- problem.) ---- local subvalue = P("(") * (C(P(1-S("()"))^1)/issub) * P(")") -- for Kim ---- Note to self: subfonts apparently start at index 0. Tested with ---- Cambria.ttc that includes “Cambria Math” at 0 and “Cambria” at 1. ---- Other values cause luatex to segfault. -local subfont = P"(" * Cg((1 - S"()")^1, "sub") * P")" --- top-level rules --------------------------------------------------- --- \font\foo=<specification>:<features> local features = Cg(feature_list, "features") |