diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/typo-cap.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/typo-cap.lua | 173 |
1 files changed, 99 insertions, 74 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/typo-cap.lua b/Master/texmf-dist/tex/context/base/mkiv/typo-cap.lua index 7e8003c620f..4dffd1c49a2 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/typo-cap.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/typo-cap.lua @@ -18,6 +18,8 @@ local report_casing = logs.reporter("typesetting","casing") local nodes, node = nodes, node local nuts = nodes.nuts +local tonode = nuts.tonode +local tonut = nuts.tonut local getnext = nuts.getnext local getprev = nuts.getprev @@ -27,7 +29,6 @@ local takeattr = nuts.takeattr local getfont = nuts.getfont local getsubtype = nuts.getsubtype local getchar = nuts.getchar -local isglyph = nuts.isglyph local getdisc = nuts.getdisc local setattr = nuts.setattr @@ -36,12 +37,12 @@ local setfont = nuts.setfont local copy_node = nuts.copy local end_of_math = nuts.end_of_math +local traverse_id = nuts.traverse_id local insert_after = nuts.insert_after local find_attribute = nuts.find_attribute -local nextglyph = nuts.traversers.glyph - local nodecodes = nodes.nodecodes +local skipcodes = nodes.skipcodes local kerncodes = nodes.kerncodes local glyph_code = nodecodes.glyph @@ -97,6 +98,19 @@ local function get(a) extract(a, 0, 8) -- run end +-- local function get(a) +-- return +-- (a >> 8) & ~(-1 << 8), -- & 0x0FF -- tag +-- (a >> 16) & ~(-1 << 12), -- & 0xFFF -- font +-- (a >> 0) & ~(-1 << 8) -- & 0x0FF -- run +-- end + +-- print(get(set( 1, 0))) +-- print(get(set( 1, 99))) +-- print(get(set( 2, 96))) +-- print(get(set( 30, 922))) +-- print(get(set(250,4000))) + -- a previous implementation used char(0) as placeholder for the larger font, so we needed -- to remove it before it can do further harm ... that was too tricky as we use char 0 for -- other cases too @@ -114,9 +128,10 @@ local categories = characters.categories -- true false true == mixed local function replacer(start,codes) - local char, fnt = isglyph(start) - local dc = codes[char] + local char = getchar(start) + local dc = codes[char] if dc then + local fnt = getfont(start) local ifc = fontchar[fnt] if type(dc) == "table" then for i=1,#dc do @@ -134,11 +149,13 @@ local function replacer(start,codes) insert_after(start,start,g) end end + return start, true elseif ifc[dc] then setchar(start,dc) + return start, true end end - return start + return start, false end local registered, n = { }, 0 @@ -174,9 +191,9 @@ local function Words(start,attr,lastfont,n,count,where,first) -- looks quite com end if count == 1 and where ~= "post" then replacer(first or start,uccodes) - return start, true + return start, true, true else - return start, true + return start, false, true end end @@ -186,9 +203,9 @@ local function Word(start,attr,lastfont,n,count,where,first) end local function camel(start,attr,lastfont,n,count,where,first) - word(start,attr,lastfont,n,count,where,first) - Words(start,attr,lastfont,n,count,where,first) - return start, true + local _, done_1 = word(start,attr,lastfont,n,count,where,first) + local _, done_2 = Words(start,attr,lastfont,n,count,where,first) + return start, done_1 or done_2, true end -- local function mixed(start,attr,lastfont,n,count,where,first) @@ -199,16 +216,19 @@ end -- local char = getchar(first) -- local dc = uccodes[char] -- if not dc then --- -- quit +-- return start, false, true -- elseif dc == char then -- local lfa = lastfont[n] -- if lfa then -- setfont(first,lfa) +-- return start, true, true +-- else +-- return start, false, true -- end -- else -- replacer(first or start,uccodes) +-- return start, true, true -- end --- return start, true -- end local function mixed(start,attr,lastfont,n,count,where,first) @@ -219,33 +239,38 @@ local function mixed(start,attr,lastfont,n,count,where,first) local char = getchar(used) local dc = uccodes[char] if not dc then - -- quit + return start, false, true elseif dc == char then local lfa = lastfont[n] if lfa then setfont(used,lfa) + return start, true, true + else + return start, false, true end - elseif check_kerns then - local p = getprev(used) - if p and getid(p) == glyph_code then - local c = lccodes[char] - local c = type(c) == "table" and c[1] or c - replacer(used,uccodes) - local fp = getfont(p) - local fc = getfont(used) - if fp ~= fc then - local k = fonts.getkern(fontdata[fp],getchar(p),c) - if k ~= 0 then - insert_after(p,p,newkern(k)) + else + if check_kerns then + local p = getprev(used) + if p and getid(p) == glyph_code then + local c = lccodes[char] + local c = type(c) == "table" and c[1] or c + replacer(used,uccodes) + local fp = getfont(p) + local fc = getfont(used) + if fp ~= fc then + local k = fonts.getkern(fontdata[fp],getchar(p),c) + if k ~= 0 then + insert_after(p,p,newkern(k)) + end end + else + replacer(used,uccodes) end else replacer(used,uccodes) end - else - replacer(used,uccodes) + return start, true, true end - return start, true end local function Capital(start,attr,lastfont,n,count,where,first,once) -- 3 @@ -259,11 +284,11 @@ local function Capital(start,attr,lastfont,n,count,where,first,once) -- 3 end end end - local s, c = replacer(first or start,uccodes) + local s, d, c = replacer(first or start,uccodes) if once then lastfont[n] = false -- here end - return start, c + return start, d, c end local function capital(start,attr,lastfont,n,where,count,first,count) -- 4 @@ -271,7 +296,7 @@ local function capital(start,attr,lastfont,n,where,count,first,count) -- 4 end local function none(start,attr,lastfont,n,count,where,first) - return start, true + return start, false, true end local function randomized(start,attr,lastfont,n,count,where,first) @@ -286,7 +311,7 @@ local function randomized(start,attr,lastfont,n,count,where,first) local n = getrandom("capital lu",0x41,0x5A) if tfm[n] then -- this also intercepts tables setchar(used,n) - return start + return start, true end end elseif kind == "ll" then @@ -294,11 +319,11 @@ local function randomized(start,attr,lastfont,n,count,where,first) local n = getrandom("capital ll",0x61,0x7A) if tfm[n] then -- this also intercepts tables setchar(used,n) - return start + return start, true end end end - return start + return start, false end register(variables.WORD, WORD) -- 1 @@ -316,9 +341,10 @@ register(variables.cap, variables.capital) -- clone register(variables.Cap, variables.Capital) -- clone function cases.handler(head) -- not real fast but also not used on much data - local start = head + local start = tonut(head) local lastfont = { } local lastattr = nil + local done = false local count = 0 local previd = nil local prev = nil @@ -341,7 +367,10 @@ function cases.handler(head) -- not real fast but also not used on much data end local action = actions[n] -- map back to low number if action then - start = action(start,attr,lastfont,n,count) + start, ok = action(start,attr,lastfont,n,count) + if ok then + done = true + end if trace_casing then report_casing("case trigger %a, instance %a, fontid %a, result %a",n,m,id,ok) end @@ -367,38 +396,32 @@ function cases.handler(head) -- not real fast but also not used on much data local pre, post, replace = getdisc(start) if replace then local cnt = count - for g in nextglyph, replace do + for g in traverse_id(glyph_code,replace) do cnt = cnt + 1 takeattr(g,a_cases) -- setattr(g,a_cases,unsetvalue) - local h, quit = action(start,attr,lastfont,n,cnt,"replace",g) - if quit then - break - end + local _, _, quit = action(start,attr,lastfont,n,cnt,"replace",g) + if quit then break end end end if pre then local cnt = count - for g in nextglyph, pre do + for g in traverse_id(glyph_code,pre) do cnt = cnt + 1 takeattr(g,a_cases) -- setattr(g,a_cases,unsetvalue) - local h, quit = action(start,attr,lastfont,n,cnt,"pre",g) - if quit then - break - end + local _, _, quit = action(start,attr,lastfont,n,cnt,"pre",g) + if quit then break end end end if post then local cnt = count - for g in nextglyph, post do + for g in traverse_id(glyph_code,post) do cnt = cnt + 1 takeattr(g,a_cases) -- setattr(g,a_cases,unsetvalue) - local h, quit = action(start,attr,lastfont,n,cnt,"post",g) - if quit then - break - end + local _, _, quit = action(start,attr,lastfont,n,cnt,"post",g) + if quit then break end end end end @@ -418,16 +441,17 @@ function cases.handler(head) -- not real fast but also not used on much data start = getnext(start) end end - return head + return head, done end -- function cases.handler(head) -- not real fast but also not used on much data --- local attr, start = find_attribute(head,a_cases) +-- local attr, start = find_attribute(tonut(head),a_cases) -- if not start then -- return head, false -- end -- local lastfont = { } -- local lastattr = nil +-- local done = false -- local count = 0 -- local previd = nil -- local prev = nil @@ -451,7 +475,10 @@ end -- end -- local action = actions[n] -- map back to low number -- if action then --- start = action(start,attr,lastfont,n,count) +-- start, ok = action(start,attr,lastfont,n,count) +-- if ok then +-- done = true +-- end -- if trace_casing then -- report_casing("case trigger %a, instance %a, fontid %a, result %a",n,m,id,ok) -- end @@ -477,38 +504,32 @@ end -- local pre, post, replace = getdisc(start) -- if replace then -- local cnt = count --- for g in glyph_code, replace do +-- for g in traverse_id(glyph_code,replace) do -- cnt = cnt + 1 -- takeattr(g,a_cases) -- -- setattr(g,a_cases,unsetvalue) --- local h, quit = action(start,attr,lastfont,n,cnt,"replace",g) --- if quit then --- break --- end +-- local _, _, quit = action(start,attr,lastfont,n,cnt,"replace",g) +-- if quit then break end -- end -- end -- if pre then -- local cnt = count --- for g in nextglyph, pre do +-- for g in traverse_id(glyph_code,pre) do -- cnt = cnt + 1 -- takeattr(g,a_cases) -- -- setattr(g,a_cases,unsetvalue) --- local h, quit = action(start,attr,lastfont,n,cnt,"pre",g) --- if quit then --- break --- end +-- local _, _, quit = action(start,attr,lastfont,n,cnt,"pre",g) +-- if quit then break end -- end -- end -- if post then -- local cnt = count --- for g in nextglyph, post do +-- for g in traverse_id(glyph_code,post) do -- cnt = cnt + 1 -- takeattr(g,a_cases) -- -- setattr(g,a_cases,unsetvalue) --- local h, quit = action(start,attr,lastfont,n,cnt,"post",g) --- if quit then --- break --- end +-- local _, _, quit = action(start,attr,lastfont,n,cnt,"post",g) +-- if quit then break end -- end -- end -- end @@ -534,22 +555,26 @@ end -- attr, start = find_attribute(start,a_cases) -- end -- end --- return head +-- return head, done -- end -- function cases.handler(head) -- let's assume head doesn't change ... no reason +-- local done = false -- local lastfont = { } --- for first, last, size, attr in nuts.words(head,a_cases) do +-- for first, last, size, attr in nuts.words(tonut(head),a_cases) do -- local n, id, m = get(attr) -- if lastfont[n] == nil then -- lastfont[n] = id -- end -- local action = actions[n] -- if action then --- action(first,attr,lastfont,n) +-- local _, ok = action(first,attr,lastfont,n) +-- if ok then +-- done = true +-- end -- end -- end --- return head +-- return head, done -- end local enabled = false |