diff options
author | Hans Hagen <pragma@wxs.nl> | 2018-04-13 15:51:39 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2018-04-13 15:51:39 +0200 |
commit | 25fcad7435f56cdce2658336909f4da6a65589c0 (patch) | |
tree | c23d5d04a7e86c7ddc2ebeca06d3de63ebdc806e /tex/context/base/mkiv/font-map.lua | |
parent | 1e5d7f41ddede5e6400a2a7762032823d3545df4 (diff) | |
download | context-25fcad7435f56cdce2658336909f4da6a65589c0.tar.gz |
2018-04-13 15:02:00
Diffstat (limited to 'tex/context/base/mkiv/font-map.lua')
-rw-r--r-- | tex/context/base/mkiv/font-map.lua | 105 |
1 files changed, 67 insertions, 38 deletions
diff --git a/tex/context/base/mkiv/font-map.lua b/tex/context/base/mkiv/font-map.lua index 66cf2db39..b44e20ede 100644 --- a/tex/context/base/mkiv/font-map.lua +++ b/tex/context/base/mkiv/font-map.lua @@ -168,55 +168,84 @@ local function tounicode16sequence(unicodes) return concat(t) end -local function tounicode(unicode) - if type(unicode) == "table" then - local t = { } - for l=1,#unicode do - local u = unicode[l] - if u < 0xD7FF or (u > 0xDFFF and u <= 0xFFFF) then - t[l] = f_single(u) - else - u = u - 0x10000 - t[l] = f_double(rshift(u,10)+0xD800,u%1024+0xDC00) - end - end - return concat(t) - else - if unicode < 0xD7FF or (unicode > 0xDFFF and unicode <= 0xFFFF) then - return f_single(unicode) - else - unicode = unicode - 0x10000 - return f_double(rshift(unicode,10)+0xD800,unicode%1024+0xDC00) - end - end -end - --- no real gain on runs - --- local hash = table.setmetatableindex(function(t,u) --- local v --- if u < 0xD7FF or (u > 0xDFFF and u <= 0xFFFF) then --- v = f_single(u) +-- local function tounicode(unicode) +-- if type(unicode) == "table" then +-- local t = { } +-- for l=1,#unicode do +-- local u = unicode[l] +-- if u < 0xD7FF or (u > 0xDFFF and u <= 0xFFFF) then +-- t[l] = f_single(u) +-- else +-- u = u - 0x10000 +-- t[l] = f_double(rshift(u,10)+0xD800,u%1024+0xDC00) +-- end +-- end +-- return concat(t) -- else --- u = u - 0x10000 --- v = f_double(rshift(u,10)+0xD800,u%1024+0xDC00) +-- if unicode < 0xD7FF or (unicode > 0xDFFF and unicode <= 0xFFFF) then +-- return f_single(unicode) +-- else +-- unicode = unicode - 0x10000 +-- return f_double(rshift(unicode,10)+0xD800,unicode%1024+0xDC00) +-- end -- end --- t[u] = v --- return v --- end) --- --- local function tounicode(unicode,name) +-- end + +local unknown = f_single(0xFFFD) + +-- local function tounicode(unicode) -- if type(unicode) == "table" then -- local t = { } -- for l=1,#unicode do --- t[l] = hash[unicode[l]] +-- t[l] = tounicode(unicode[l]) -- end -- return concat(t) +-- elseif unicode >= 0x00E000 and unicode <= 0x00F8FF then +-- return unknown +-- elseif unicode >= 0x0F0000 and unicode <= 0x0FFFFF then +-- return unknown +-- elseif unicode >= 0x100000 and unicode <= 0x10FFFF then +-- return unknown +-- elseif unicode < 0xD7FF or (unicode > 0xDFFF and unicode <= 0xFFFF) then +-- return f_single(unicode) -- else --- return hash[unicode] +-- unicode = unicode - 0x10000 +-- return f_double(rshift(unicode,10)+0xD800,unicode%1024+0xDC00) -- end -- end +local hash = table.setmetatableindex(function(t,k) + local v + if k >= 0x00E000 and k <= 0x00F8FF then + v = unknown + elseif k >= 0x0F0000 and k <= 0x0FFFFF then + v = unknown + elseif k >= 0x100000 and k <= 0x10FFFF then + v = unknown + elseif k < 0xD7FF or (k > 0xDFFF and k <= 0xFFFF) then + v = f_single(k) + else + v = k - 0x10000 + v = f_double(rshift(k,10)+0xD800,k%1024+0xDC00) + end + t[k] = v + return v +end) + +table.makeweak(hash) + +local function tounicode(unicode,name) + if type(unicode) == "table" then + local t = { } + for l=1,#unicode do + t[l] = hash[unicode[l]] + end + return concat(t) + else + return hash[unicode] + end +end + local function fromunicode16(str) if #str == 4 then return tonumber(str,16) |