diff options
author | Hans Hagen <pragma@wxs.nl> | 2017-04-02 20:46:19 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2017-04-02 20:46:19 +0200 |
commit | e32f57c9c5968f0c09130f6e24e28a96d6e1393d (patch) | |
tree | 476d22407b719a74b18a849d83fb8464f9a042c4 /tex/context/base/mkiv/lang-dis.lua | |
parent | 30ea6ac75b1cf62ea8e17228c07d54824285acfa (diff) | |
download | context-e32f57c9c5968f0c09130f6e24e28a96d6e1393d.tar.gz |
2017-04-02 19:57:00
Diffstat (limited to 'tex/context/base/mkiv/lang-dis.lua')
-rw-r--r-- | tex/context/base/mkiv/lang-dis.lua | 250 |
1 files changed, 131 insertions, 119 deletions
diff --git a/tex/context/base/mkiv/lang-dis.lua b/tex/context/base/mkiv/lang-dis.lua index 448966d49..e2c0d220e 100644 --- a/tex/context/base/mkiv/lang-dis.lua +++ b/tex/context/base/mkiv/lang-dis.lua @@ -62,146 +62,158 @@ local getlanguagedata = languages.getdata local check_regular = true -local expanders = { - [discretionary_code] = function(d,template) - -- \discretionary - return template - end, - [explicit_code] = function(d,template) - -- \- - local pre, post, replace = getdisc(d) - local done = false - if pre then - local char = isglyph(pre) - if char and char <= 0 then - done = true - flush_list(pre) - pre = nil +local expanders -- this will go away + +-- the penalty has been determined by the mode (currently we force 1): +-- +-- 0 : exhyphenpenalty +-- 1 : hyphenpenalty +-- 2 : automatichyphenpenalty +-- +-- following a - : the pre and post chars are already appended and set +-- so we have pre=preex and post=postex .. however, the previous +-- hyphen is already injected ... downside: the font handler sees this +-- so this is another argument for doing a hyphenation pass in context + +if LUATEXVERSION < 1.005 then + + expanders = { + [discretionary_code] = function(d,template) + -- \discretionary + return template + end, + [explicit_code] = function(d,template) + -- \- + local pre, post, replace = getdisc(d) + local done = false + if pre then + local char = isglyph(pre) + if char and char <= 0 then + done = true + flush_list(pre) + pre = nil + end end - end - if post then - local char = isglyph(post) - if char and char <= 0 then - done = true - flush_list(post) - post = nil + if post then + local char = isglyph(post) + if char and char <= 0 then + done = true + flush_list(post) + post = nil + end end - end - if done then - -- todo: take existing penalty - setdisc(d,pre,post,replace,explicit_code,tex.exhyphenpenalty) - else - setsubtype(d,explicit_code) - end - return template - end, - [automatic_code] = function(d,template) - -- the penalty has been determined by the mode (currently we force 1): - -- - -- 0 : exhyphenpenalty - -- 1 : hyphenpenalty - -- 2 : automatichyphenpenalty - -- - -- following a - : the pre and post chars are already appended and set - -- so we have pre=preex and post=postex .. however, the previous - -- hyphen is already injected ... downside: the font handler sees this - -- so this is another argument for doing a hyphenation pass in context - local pre, post, replace = getdisc(d) - if pre then - -- we have a preex characters and want that one to replace the - -- character in front which is the trigger - if not template then - -- can there be font kerns already? - template = getprev(d) - if template and getid(template) ~= glyph_code then - template = getnext(d) + if done then + -- todo: take existing penalty + setdisc(d,pre,post,replace,explicit_code,tex.exhyphenpenalty) + else + setsubtype(d,explicit_code) + end + return template + end, + [automatic_code] = function(d,template) + local pre, post, replace = getdisc(d) + if pre then + -- we have a preex characters and want that one to replace the + -- character in front which is the trigger + if not template then + -- can there be font kerns already? + template = getprev(d) if template and getid(template) ~= glyph_code then - template = nil + template = getnext(d) + if template and getid(template) ~= glyph_code then + template = nil + end end end - end - if template then - local pseudohead = getprev(template) - if pseudohead then - while template ~= d do - pseudohead, template, removed = remove_node(pseudohead,template) - -- free old replace ? - replace = removed - -- break ? + if template then + local pseudohead = getprev(template) + if pseudohead then + while template ~= d do + pseudohead, template, removed = remove_node(pseudohead,template) + -- free old replace ? + replace = removed + -- break ? + end + else + -- can't happen end + setdisc(d,pre,post,replace,automatic_code,tex.hyphenpenalty) else - -- can't happen + -- print("lone regular discretionary ignored") end - setdisc(d,pre,post,replace,automatic_code,tex.hyphenpenalty) else - -- print("lone regular discretionary ignored") + setdisc(d,pre,post,replace,automatic_code,tex.hyphenpenalty) end - else - setdisc(d,pre,post,replace,automatic_code,tex.hyphenpenalty) - end - return template - end, - [regular_code] = function(d,template) - if check_regular then - -- simple - if not template then - -- can there be font kerns already? - template = getprev(d) - if template and getid(template) ~= glyph_code then - template = getnext(d) + return template + end, + [regular_code] = function(d,template) + if check_regular then + -- simple + if not template then + -- can there be font kerns already? + template = getprev(d) if template and getid(template) ~= glyph_code then - template = nil + template = getnext(d) + if template and getid(template) ~= glyph_code then + template = nil + end end end - end - if template then - local language = template and getlang(template) - local data = getlanguagedata(language) - local prechar = data.prehyphenchar - local postchar = data.posthyphenchar - local pre, post, replace = getdisc(d) -- pre can be set - local done = false - if prechar and prechar > 0 then - done = true - pre = copy_node(template) - setchar(pre,prechar) - end - if postchar and postchar > 0 then - done = true - post = copy_node(template) - setchar(post,postchar) - end - if done then - setdisc(d,pre,post,replace,regular_code,tex.hyphenpenalty) + if template then + local language = template and getlang(template) + local data = getlanguagedata(language) + local prechar = data.prehyphenchar + local postchar = data.posthyphenchar + local pre, post, replace = getdisc(d) -- pre can be set + local done = false + if prechar and prechar > 0 then + done = true + pre = copy_node(template) + setchar(pre,prechar) + end + if postchar and postchar > 0 then + done = true + post = copy_node(template) + setchar(post,postchar) + end + if done then + setdisc(d,pre,post,replace,regular_code,tex.hyphenpenalty) + end + else + -- print("lone regular discretionary ignored") end - else - -- print("lone regular discretionary ignored") + return template end - return template - else - -- maybe also set penalty here - setsubtype(d,regular_code) + end, + [disccodes.first] = function() + -- forget about them + end, + [disccodes.second] = function() + -- forget about them + end, + } + + function languages.expand(d,template,subtype) + if not subtype then + subtype = getsubtype(d) end - end, - [disccodes.first] = function() - -- forget about them - end, - [disccodes.second] = function() - -- forget about them - end, -} + if subtype ~= discretionary_code then + return expanders[subtype](d,template) + end + end -languages.expanders = expanders +else -function languages.expand(d,template,subtype) - if not subtype then - subtype = getsubtype(d) - end - if subtype ~= discretionary_code then - return expanders[subtype](d,template) + function languages.expand() + -- nothing to be fixed end + end +languages.expanders = expanders + +-- -- -- -- -- + local setlistcolor = nodes.tracers.colors.setlist function languages.visualizediscretionaries(head) |