From 0a1b9b746b5ce4cd740af8948f083685879c4eb9 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 15 Feb 2016 08:26:54 +0100 Subject: [parsers,features] parse combo requests Highly experimental at this point. The font request parser has been extended to handle combinations of already defined fonts. Nothing else has been implemented yet, so the request handler will simply error out with a message. --- src/luaotfload-parsers.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/luaotfload-parsers.lua') diff --git a/src/luaotfload-parsers.lua b/src/luaotfload-parsers.lua index 0349cdc..5ebe8d5 100644 --- a/src/luaotfload-parsers.lua +++ b/src/luaotfload-parsers.lua @@ -45,6 +45,7 @@ local lfsisdir = lfs.isdir --- COMMON PATTERNS ------------------------------------------------------------------------------- +local asterisk = P"*" local dot = P"." local colon = P":" local semicolon = P";" @@ -72,6 +73,8 @@ local digit = R"09" local alpha = R("az", "AZ") local anum = alpha + digit local decimal = digit^1 * (dot * digit^0)^-1 +local hexdigit = R("09", "af", "AF") +local hex = P"0x" * hexdigit^1 ------------------------------------------------------------------------------- --- FONTCONFIG @@ -560,9 +563,35 @@ local modifier = slash * (other_modifier --> ignore + garbage_modifier) --> warn local modifier_list = Cg(Ct(modifier^0), "modifiers") +--- combining --------------------------------------------------------- +--- +--- \font \three = combo:1/42,2/99/0xdeadbeef,3/1/U+2a-U+1337*42 +--- v +~ v +~ +~~~~~~~~~ v v +~~~ +~~~~~ +~ +--- | | | | | | | | | | +--- | | | | | | | | | | +--- idx : --+-÷--+-÷--÷----------+ | +----+ | +--- | | | | | | +--- id : ----+----+--÷------------+ +-----------+ +--- | | +--- chars : ------------+--------------+ +--- +local combohex = hex / tonumber +local combouint = digit^1 / tonumber +local tonumber16 = function (s) return tonumber (s, 16) end +local combouni = P"U+" * (digit^1 / tonumber16) +local combonum = combohex + combouni + combouint +local comborange = Ct(combonum * dash * combonum) + combonum +local combochars = comborange * (asterisk * comborange)^0 +local combodef1 = Ct( Cg(combouint, "idx") --> no chars + * slash * Cg(combouint, "id" )) +local combodef = Ct( Cg(combouint, "idx" ) + * slash * Cg(combouint, "id" ) + * slash * Cg(Ct(combochars^1), "chars")) +local combolist = Ct(combodef1 * (comma * combodef)^1) --- lookups ----------------------------------------------------------- local fontname = C((1-S":(/")^1) --- like luatex-fonts local unsupported = Cmt((1-S":(")^1, check_garbage) +local combo = P"combo:" * ws * Cg(combolist, "combo") local prefixed = P"name:" * ws * Cg(fontname, "name") --- initially we intended file: to emulate the behavior of --- luatex-fonts, i.e. no paths allowed. after all, we do have XeTeX @@ -626,6 +655,7 @@ local specification = (prefixed + unprefixed) * subfont^-1 * modifier_list^-1 local font_request = Ct(path_lookup * (colon^-1 * features)^-1 + + combo --> TODO: feature list needed? + specification * (colon * features)^-1) -- lpeg.print(font_request) -- cgit v1.2.3 From 128b005cd8b44483ce2a58bd0cf078318663c696 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 19 Feb 2016 08:10:26 +0100 Subject: [parsers] allow whitespace around combo elements This gives more leeway to the notation, allowing font definitions to become more readable: \font \f = "combo: 1 / \fontid\one, 2 / \fontid\two / 0x41-0x5a, 3 / \fontid\three / 0x42, 4 / \fontid\three / 0x54 * 69 * U+58" --- src/luaotfload-parsers.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/luaotfload-parsers.lua') diff --git a/src/luaotfload-parsers.lua b/src/luaotfload-parsers.lua index 5ebe8d5..0f87256 100644 --- a/src/luaotfload-parsers.lua +++ b/src/luaotfload-parsers.lua @@ -575,19 +575,22 @@ local modifier_list = Cg(Ct(modifier^0), "modifiers") --- | | --- chars : ------------+--------------+ --- +local comborowsep = ws * comma * ws +local combocolsep = ws * slash * ws +local comborangesep = ws * asterisk * ws local combohex = hex / tonumber local combouint = digit^1 / tonumber local tonumber16 = function (s) return tonumber (s, 16) end local combouni = P"U+" * (digit^1 / tonumber16) local combonum = combohex + combouni + combouint local comborange = Ct(combonum * dash * combonum) + combonum -local combochars = comborange * (asterisk * comborange)^0 -local combodef1 = Ct( Cg(combouint, "idx") --> no chars - * slash * Cg(combouint, "id" )) -local combodef = Ct( Cg(combouint, "idx" ) - * slash * Cg(combouint, "id" ) - * slash * Cg(Ct(combochars^1), "chars")) -local combolist = Ct(combodef1 * (comma * combodef)^1) +local combochars = comborange * (comborangesep * comborange)^0 +local combodef1 = Ct( Cg(combouint, "idx") --> no chars + * combocolsep * Cg(combouint, "id" )) +local combodef = Ct( Cg(combouint, "idx" ) + * combocolsep * Cg(combouint, "id" ) + * combocolsep * Cg(Ct(combochars^1), "chars")) +local combolist = Ct(combodef1 * (comborowsep * combodef)^1) --- lookups ----------------------------------------------------------- local fontname = C((1-S":(/")^1) --- like luatex-fonts local unsupported = Cmt((1-S":(")^1, check_garbage) -- cgit v1.2.3 From 9e04cce348b4de350b2e0612698c81311e6e6e9d Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 19 Feb 2016 21:57:24 +0100 Subject: [parsers] rework combo syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use arrows to emphasise what’s mapped. Allow whitespace to visually separate items. Also allow optional grouping with parentheses. Now it’s possible to define a combination as follows: \font \f = "combo: 1 -> 42; 2 -> 1337, U+0042-U+0084; 3 -> (55, 0x54 * 0x45 * 0x58)" --- src/luaotfload-parsers.lua | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'src/luaotfload-parsers.lua') diff --git a/src/luaotfload-parsers.lua b/src/luaotfload-parsers.lua index 0f87256..71e539d 100644 --- a/src/luaotfload-parsers.lua +++ b/src/luaotfload-parsers.lua @@ -565,19 +565,21 @@ local modifier_list = Cg(Ct(modifier^0), "modifiers") --- combining --------------------------------------------------------- --- ---- \font \three = combo:1/42,2/99/0xdeadbeef,3/1/U+2a-U+1337*42 ---- v +~ v +~ +~~~~~~~~~ v v +~~~ +~~~~~ +~ ---- | | | | | | | | | | ---- | | | | | | | | | | ---- idx : --+-÷--+-÷--÷----------+ | +----+ | ---- | | | | | | ---- id : ----+----+--÷------------+ +-----------+ ---- | | ---- chars : ------------+--------------+ +--- \font \three = combo: 1->42; 2->99,0xdeadbeef; 3->(1,U+2a-U+1337*42) +--- v +~ v +~ +~~~~~~~~~ v v +~~~ +~~~~~ +~ +--- | | | | | | | | | | +--- | | | | | | | | | | +--- idx : ---+--÷---+--÷--÷-----------+ | +----+ | +--- | | | | | | +--- id : ------+------+--÷---------------+ +-----------+ +--- | | +--- chars : ----------------+-----------------+ --- -local comborowsep = ws * comma * ws -local combocolsep = ws * slash * ws -local comborangesep = ws * asterisk * ws +local comborowsep = ws * semicolon * ws +local combomapsep = ws * P"->" * ws +local combodefsep = ws * comma * ws +local comborangesep = ws * asterisk * ws + local combohex = hex / tonumber local combouint = digit^1 / tonumber local tonumber16 = function (s) return tonumber (s, 16) end @@ -585,12 +587,20 @@ local combouni = P"U+" * (digit^1 / tonumber16) local combonum = combohex + combouni + combouint local comborange = Ct(combonum * dash * combonum) + combonum local combochars = comborange * (comborangesep * comborange)^0 -local combodef1 = Ct( Cg(combouint, "idx") --> no chars - * combocolsep * Cg(combouint, "id" )) -local combodef = Ct( Cg(combouint, "idx" ) - * combocolsep * Cg(combouint, "id" ) - * combocolsep * Cg(Ct(combochars^1), "chars")) +local parenthesized = function (p) return P"(" * ws * p * ws * P")" end + +local comboidxpat = Cg(combouint, "idx") +local comboidpat = Cg(combouint, "id" ) +local combocharspat = comboidpat * combodefsep * Cg(Ct(combochars^1), "chars") + +local comboidx = parenthesized (comboidxpat ) + comboidxpat +local comboid = parenthesized (comboidpat ) + comboidpat +local comboidchars = parenthesized (combocharspat) + combocharspat + +local combodef1 = Ct(comboidx * combomapsep * comboid) --> no chars +local combodef = Ct(comboidx * combomapsep * comboidchars) local combolist = Ct(combodef1 * (comborowsep * combodef)^1) + --- lookups ----------------------------------------------------------- local fontname = C((1-S":(/")^1) --- like luatex-fonts local unsupported = Cmt((1-S":(")^1, check_garbage) -- cgit v1.2.3 From 3447815896954281938500d49bedef715078a140 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 19 Feb 2016 22:41:23 +0100 Subject: [features,parsers] implement font fallbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Building on the combination mechanism, this allows defining fallback fonts of which all glyphs are pulled that aren’t currently part of the base font. Example: \input luaotfload.sty \font \lm = file:lmroman10-regular.otf:mode=base \font \cmu = file:cmunrm.otf:mode=base \font \lmu = "combo: 1->\fontid\lm; 2->\fontid\cmu,fallback" \lmu Eh bien, mon prince. Gênes et Lueques ne sont plus que des apanages, des поместья, de la famille Buonaparte. \bye This allows setting Latin Modern text that contains Cyrillic letters. Note that -- as with the other combinations -- only glyphs are considered, no other properties of the fallback font. So besides the occasional letter in a different script this functionality is probably useless. --- src/luaotfload-parsers.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/luaotfload-parsers.lua') diff --git a/src/luaotfload-parsers.lua b/src/luaotfload-parsers.lua index 71e539d..b190c2c 100644 --- a/src/luaotfload-parsers.lua +++ b/src/luaotfload-parsers.lua @@ -591,11 +591,12 @@ local parenthesized = function (p) return P"(" * ws * p * ws * P")" end local comboidxpat = Cg(combouint, "idx") local comboidpat = Cg(combouint, "id" ) -local combocharspat = comboidpat * combodefsep * Cg(Ct(combochars^1), "chars") +local combocharspat = Cg(P"fallback" * Cc(true) + Ct(combochars^1), "chars") +local comboidcharspat = comboidpat * combodefsep * combocharspat -local comboidx = parenthesized (comboidxpat ) + comboidxpat -local comboid = parenthesized (comboidpat ) + comboidpat -local comboidchars = parenthesized (combocharspat) + combocharspat +local comboidx = parenthesized (comboidxpat ) + comboidxpat +local comboid = parenthesized (comboidpat ) + comboidpat +local comboidchars = parenthesized (comboidcharspat) + comboidcharspat local combodef1 = Ct(comboidx * combomapsep * comboid) --> no chars local combodef = Ct(comboidx * combomapsep * comboidchars) -- cgit v1.2.3