summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex-nabc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex-nabc.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex-nabc.lua124
1 files changed, 84 insertions, 40 deletions
diff --git a/Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex-nabc.lua b/Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex-nabc.lua
index 14abe5637e4..108bdc6f185 100644
--- a/Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex-nabc.lua
+++ b/Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex-nabc.lua
@@ -1,6 +1,6 @@
--GregorioTeX Nabc Lua file.
--
---Copyright (C) 2014-2016 The Gregorio Project (see CONTRIBUTORS.md)
+--Copyright (C) 2014-2017 The Gregorio Project (see CONTRIBUTORS.md)
--
--This file is part of Gregorio.
--
@@ -20,7 +20,7 @@
-- this file contains lua functions used by GregorioTeX St. Gall ancient
-- neume support when called with LuaTeX.
--- GREGORIO_VERSION 4.1.5
+-- GREGORIO_VERSION 5.0.1
local catcode_at_letter = luatexbase.catcodetables['gre@atletter']
@@ -71,7 +71,7 @@ local gregallaliases = {
["pf!cl~ppt1"] = "cl!po>ppt1"
}
-local function gregallreadfont(font_id)
+local function gregallreadfont(fontname, font_id)
local tab = {}
local metrics = {}
local fontdata = font.getfont(font_id)
@@ -92,10 +92,12 @@ local function gregallreadfont(font_id)
metrics[name] = { width = g.width, height = g.height, depth = (g.depth and g.depth or 0) }
end
end
- for key, value in pairs(gregallaliases) do
- if tab[value] and not tab[key] then
- tab[key] = tab[value]
- metrics[key] = metrics[value]
+ if fontname ~= "grelaon" then
+ for key, value in pairs(gregallaliases) do
+ if tab[value] and not tab[key] then
+ tab[key] = tab[value]
+ metrics[key] = metrics[value]
+ end
end
end
return tab, metrics
@@ -105,12 +107,15 @@ local gregalltab = {}
local gregallmetrics = {}
local gregallneumekinds = { vi = 1, pu = 1, ta = 1, gr = 1, cl = 1, un = 1, pv = 1, pe = 1, po = 1, to = 1, ci = 1, sc = 1, pf = 1, sf = 1, tr = 1,
- st = 1, ds = 1, ts = 1, tg = 1, bv = 1, tv = 1, pr = 1, pi = 1, vs = 1, ["or"] = 1, sa = 1, pq = 1, qi = 1, ql = 1, pt = 1 }
+ st = 1, ds = 1, ts = 1, tg = 1, bv = 1, tv = 1, pr = 1, pi = 1, vs = 1, ["or"] = 1, sa = 1, pq = 1, qi = 1, ql = 1, pt = 1,
+ un = 1, oc = 1 }
local gregalllskinds = { c = 1, t = 1, s = 1, l = 1, x = 1, ["+"] = 1, a = 1, al = 1, am = 1, b = 1, cm = 1, co = 1, cw = 1, d = 1, e = 1, eq = 1,
ew = 1, f = 1, fid = 1, fr = 1, g = 1, h = 1, hp = 1, hn = 1, i = 1, im = 1, iv = 1, k = 1, lb = 1, lc = 1, len = 1,
lm = 1, lp = 1, lt = 1, m = 1, md = 1, moll = 1, n = 1, nl = 1, nt = 1, p = 1, par = 1, pfec = 1, pm = 1, q = 1,
sb = 1, sc = 1, sc = 1, simil = 1, simul = 1, sj = 1, sjc = 1, sjcm = 1, sm = 1, st = 1, sta = 1, su = 1, tb = 1,
- th = 1, tm = 1, tw = 1, v = 1, ve = 1, vol = 1 }
+ th = 1, tm = 1, tw = 1, v = 1, ve = 1, vol = 1,
+ ["eq-"] = 1, equ = 1, simp = 1, simpl = 1, sp = 1 }
+local grelaonltkinds = { i = 1, ["do"] = 1, dr = 1, dx = 1, ps = 1, qm = 1, sb = 1, se = 1, sj = 1, sl = 1, sn = 1, sp = 1, sr = 1, st = 1, us = 1 }
-- Parse a single base neume
local gregallparse_base = function (str, idx, len)
@@ -137,9 +142,9 @@ local gregallparse_base = function (str, idx, len)
end
-- Ambitus not handled yet, neither during parsing, nor when
-- typesetting.
- -- Optional height, h[a-m].
+ -- Optional height, h[a-np].
if idx < len and str:sub(idx, idx) == "h" then
- local p = string.find("abcdefghijklm", str:sub(idx + 1, idx + 1))
+ local p = string.find("abcdefghijklmnp", str:sub(idx + 1, idx + 1))
if not p then return 1 end
height = p - 1
idx = idx + 2
@@ -170,18 +175,27 @@ local gregallparse_neume = function (str, idx, len)
local v = str:sub(idx, idx + 1)
if v == "ls" then
local idx2 = idx + 2
- while idx2 <= len and not string.find("12346789", str:sub(idx2, idx2)) do
+ while idx2 <= len and not string.find("123456789", str:sub(idx2, idx2)) do
idx2 = idx2 + 1
end
if idx2 > len or not gregalllskinds[str:sub(idx + 2, idx2 - 1)] then return 1 end
ls[lsidx] = str:sub(idx, idx2)
lsidx = lsidx + 1
idx = idx2 + 1
+ elseif v == "lt" then
+ local idx2 = idx + 2
+ while idx2 <= len and not string.find("123456789", str:sub(idx2, idx2)) do
+ idx2 = idx2 + 1
+ end
+ if idx2 > len or not grelaonltkinds[str:sub(idx + 2, idx2 - 1)] then return 1 end
+ ls[lsidx] = str:sub(idx, idx2)
+ lsidx = lsidx + 1
+ idx = idx2 + 1
elseif v == "su" or v == "pp" then
local mod = ''
idx = idx + 2
local c = str:sub(idx, idx)
- if idx <= len and string.find("tuvwxy", c) then
+ if idx <= len and string.find("tuvwxyqnz", c) then
mod = mod .. c
idx = idx + 1
c = str:sub(idx, idx)
@@ -197,7 +211,7 @@ local gregallparse_neume = function (str, idx, len)
return 0, idx, bases, heights, ls, pp, su
end
-local add_ls = function(base, pre, ls, position, glyphbox, lsbox, baseraise, lwidths, curlwidths, scale)
+local add_ls = function(base, pre, post, ls, position, glyphbox, lsbox, baseraise, lwidths, curlwidths, scale)
local raise = 0
if position == 3 or position == 6 or position == 9 then
if position == 3 then
@@ -217,7 +231,7 @@ local add_ls = function(base, pre, ls, position, glyphbox, lsbox, baseraise, lwi
kern1 = kern1 * scale
kern2 = kern2 * scale
raise = raise * scale
- return base..'\\kern '..string.format("%.3f",kern1)..'sp\\raise '..string.format("%.3f",raise)..'sp\\hbox{'..ls..'}\\kern '..string.format("%.3f",kern2)..'sp', pre
+ return base, pre, post..'\\kern '..string.format("%.3f",kern1)..'sp\\raise '..string.format("%.3f",raise)..'sp\\hbox{'..ls..'}\\kern '..string.format("%.3f",kern2)..'sp'
elseif position == 2 or position == 8 then
if position == 2 then
raise = glyphbox.height + lsbox.depth + baseraise
@@ -235,7 +249,7 @@ local add_ls = function(base, pre, ls, position, glyphbox, lsbox, baseraise, lwi
kern1 = kern1 * scale
kern2 = kern2 * scale
raise = raise * scale
- return base..'\\kern '..string.format("%.3f",kern1)..'sp\\raise '..string.format("%.3f",raise)..'sp\\hbox{'..ls..'}\\kern '..string.format("%.3f",kern2)..'sp', pre
+ return base..'\\kern '..string.format("%.3f",kern1)..'sp\\raise '..string.format("%.3f",raise)..'sp\\hbox{'..ls..'}\\kern '..string.format("%.3f",kern2)..'sp', pre, post
else
if position == 1 then
raise = glyphbox.height - (lsbox.height-lsbox.depth)/2 + baseraise
@@ -254,23 +268,23 @@ local add_ls = function(base, pre, ls, position, glyphbox, lsbox, baseraise, lwi
kern1 = kern1 * scale
kern2 = kern2 * scale
raise = raise * scale
- return base, pre..'\\kern '..string.format("%.3f",kern1)..'sp\\raise '..string.format("%.3f",raise)..'sp\\hbox{'..ls..'}\\kern '..string.format("%.3f",kern2)..'sp'
+ return base, pre..'\\kern '..string.format("%.3f",kern1)..'sp\\raise '..string.format("%.3f",raise)..'sp\\hbox{'..ls..'}\\kern '..string.format("%.3f",kern2)..'sp', post
end
end
local add_spacing = function(str, len, idx, ret)
while idx <= len and (str:sub(idx, idx) == "/" or str:sub(idx, idx) == "`") do
if idx < len and str:sub(idx, idx + 1) == "//" then
- ret = ret .. "\\hskip \\gre@space@skip@nabclargerspace"
+ ret = ret .. "\\gre@hskip \\gre@space@skip@nabclargerspace"
idx = idx + 2
elseif idx < len and str:sub(idx, idx + 1) == "``" then
- ret = ret .. "\\hskip -\\gre@space@skip@nabclargerspace"
+ ret = ret .. "\\gre@hskip -\\gre@space@skip@nabclargerspace"
idx = idx + 2
elseif str:sub(idx, idx) == "/" then
- ret = ret .. "\\hskip \\gre@space@skip@nabcinterelementspace"
+ ret = ret .. "\\gre@hskip \\gre@space@skip@nabcinterelementspace"
idx = idx + 1
else
- ret = ret .. "\\hskip -\\gre@space@skip@nabcinterelementspace"
+ ret = ret .. "\\gre@hskip -\\gre@space@skip@nabcinterelementspace"
idx = idx + 1
end
end
@@ -293,46 +307,75 @@ local gregallparse_neumes = function(str, kind, scale)
local h = heights[i] - heights[0]
if h ~= 0 then
h = h + 5
- if h < 0 or h > 12 then
+ if h < 0 or h > 14 then
base = "ERR"
break
end
- base = base .. string.sub("abcdefghijklm", h + 1, h + 1)
+ base = base .. string.sub("abcdefghijklmnp", h + 1, h + 1)
end
i = i + 1
end
+ local ls5 = ''
lscount = 0
while ls[lscount] do
if not gregalltab[kind][ls[lscount]:sub(1, -2)] then base = "ERR" end
+ if tonumber(ls[lscount]:sub(-1, -1)) == 5 then
+ ls5 = ls5 .. ls[lscount]
+ ls[lscount] = ''
+ end
lscount = lscount + 1
end
if base ~= "ERR" then
local l = {}
- function l.try (kind, base, parts, pp, su, ls)
- if parts == 2 and pp ~= '' and su ~= '' and gregalltab[kind][base .. pp .. su .. ls] then return base .. pp .. su .. ls, '', '' end
+ function l.try (kind, base, parts, pp, su, ls5, ls)
+ if parts == 2 and pp ~= '' and su ~= '' and gregalltab[kind][base .. pp .. su .. ls5 .. ls] then return base .. pp .. su .. ls5 .. ls, '', '' end
-- Prefer subpunctis over prepunctis.
- if parts == 1 and su ~= '' and gregalltab[kind][base .. su .. ls] then return base .. su .. ls, pp, '' end
- if parts == 1 and pp ~= '' and gregalltab[kind][base .. pp .. ls] then return base .. pp .. ls, '', su end
+ if parts == 1 and su ~= '' and gregalltab[kind][base .. su .. ls5 .. ls] then return base .. su .. ls5 .. ls, pp, '' end
+ if parts == 1 and pp ~= '' and gregalltab[kind][base .. pp .. ls5 .. ls] then return base .. pp .. ls5 .. ls, '', su end
-- Prefer subpunctis over significative letters.
- if parts == 0 and su ~= '' and ls ~= '' and gregalltab[kind][base .. su] then return nil, pp, su end
- if parts == 0 and gregalltab[kind][base .. ls] then return base .. ls, pp, su end
+ if parts == 0 and su ~= '' and ls ~= '' and gregalltab[kind][base .. su .. ls5] then return nil, pp, su end
+ if parts == 0 and gregalltab[kind][base .. ls5 .. ls] then return base .. ls5 .. ls, pp, su end
return nil, pp, su
end
local r = nil
local ppsuparts = 0
if pp ~= '' then ppsuparts = 1 end
if su ~= '' then ppsuparts = ppsuparts + 1 end
- -- We assume here no character in the font has more than two
- -- significative letters.
+ -- We assume here no character in the font has more than three
+ -- significative letters. Significative letters with position 5
+ -- are always required to be in font and have preference over
+ -- pre/subpunctis and other significative letters.
local allparts = ppsuparts + lscount
- if lscount >= 2 then allparts = ppsuparts + 2 end
+ if lscount >= 3 then allparts = ppsuparts + 3 end
-- Try to match as many parts (ls sequences, pp string, su string) as possible
-- except that for ls accept any of ls sequences only if we have all of them.
for parts = allparts, 0, -1 do
+ if lscount == 3 and parts >= 3 and parts <= 3 + ppsuparts then
+ r, pp, su = l.try(kind, base, parts - 3, pp, su, ls5, ls[0] .. ls[1] .. ls[2])
+ if (not r) and ls[0] ~= '' and ls[1] ~= '' and ls[2] ~= '' then
+ local p0 = tonumber(ls[0]:sub(-1, -1))
+ local p1 = tonumber(ls[1]:sub(-1, -1))
+ local p2 = tonumber(ls[2]:sub(-1, -1))
+ if (p0 ~= p1) and (p0 ~= p2) and (p1 ~= p2) then
+ r, pp, su = l.try(kind, base, parts - 3, pp, su, ls5, ls[1] .. ls[0] .. ls[2])
+ if not r then r, pp, su = l.try(kind, base, parts - 3, pp, su, ls5, ls[0] .. ls[2] .. ls[1]) end
+ if not r then r, pp, su = l.try(kind, base, parts - 3, pp, su, ls5, ls[1] .. ls[2] .. ls[0]) end
+ if not r then r, pp, su = l.try(kind, base, parts - 3, pp, su, ls5, ls[2] .. ls[0] .. ls[1]) end
+ if not r then r, pp, su = l.try(kind, base, parts - 3, pp, su, ls5, ls[2] .. ls[1] .. ls[0]) end
+ end
+ end
+ if r then
+ ls[0] = ''
+ ls[1] = ''
+ ls[2] = ''
+ break
+ end
+ if r then break end
+ end
if lscount == 2 and parts >= 2 and parts <= 2 + ppsuparts then
- r, pp, su = l.try(kind, base, parts - 2, pp, su, ls[0] .. ls[1])
- if not r then
- r, pp, su = l.try(kind, base, parts - 2, pp, su, ls[1] .. ls[0])
+ r, pp, su = l.try(kind, base, parts - 2, pp, su, ls5, ls[0] .. ls[1])
+ if (not r) and ls[0] ~= '' and ls[1] ~= '' and (tonumber(ls[0]:sub(-1, -1)) ~= tonumber(ls[1]:sub(-1, -1))) then
+ r, pp, su = l.try(kind, base, parts - 2, pp, su, ls5, ls[1] .. ls[0])
end
if r then
ls[0] = ''
@@ -342,13 +385,13 @@ local gregallparse_neumes = function(str, kind, scale)
if r then break end
end
if lscount == 1 and parts >= 1 and parts <= 1 + ppsuparts then
- r, pp, su = l.try(kind, base, parts - 1, pp, su, ls[0])
+ r, pp, su = l.try(kind, base, parts - 1, pp, su, ls5, ls[0])
if r then
ls[0] = ''
break
end
end
- r, pp, su = l.try(kind, base, parts, pp, su, '')
+ r, pp, su = l.try(kind, base, parts, pp, su, ls5, '')
if r then break end
end
if not r or (pp ~= '' and not gregalltab[kind][pp]) or (su ~= '' and not gregalltab[kind][su]) then
@@ -392,15 +435,16 @@ local gregallparse_neumes = function(str, kind, scale)
lwidths[11] = math.max (lwidths[2], lwidths[8])
lwidths[12] = math.max (lwidths[3], lwidths[6], lwidths[9])
local pre = ''
+ local post = ''
for i = 0, lscount - 1 do
if ls[i] ~= '' then
local p = tonumber(ls[i]:sub(-1, -1))
local l = ls[i]:sub(1, -2)
local lstr = gregalltab[kind][l]
- base, pre = add_ls(base, pre, lstr, p, rmetrics, gregallmetrics[kind][l], baseraise, lwidths, curlwidths, scale)
+ base, pre, post = add_ls(base, pre, post, lstr, p, rmetrics, gregallmetrics[kind][l], baseraise, lwidths, curlwidths, scale)
end
end
- base = pre..base
+ base = pre..base..post
end
end
ret = ret .. base
@@ -411,7 +455,7 @@ end
local function init_font(fontname)
if not gregalltab[fontname] then
- gregalltab[fontname], gregallmetrics[fontname] = gregallreadfont(font.current())
+ gregalltab[fontname], gregallmetrics[fontname] = gregallreadfont(fontname, font.current())
end
end