summaryrefslogtreecommitdiff
path: root/src/fontloader/misc/fontloader-font-map.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/fontloader/misc/fontloader-font-map.lua')
-rw-r--r--src/fontloader/misc/fontloader-font-map.lua96
1 files changed, 53 insertions, 43 deletions
diff --git a/src/fontloader/misc/fontloader-font-map.lua b/src/fontloader/misc/fontloader-font-map.lua
index dc3f499..db501f0 100644
--- a/src/fontloader/misc/fontloader-font-map.lua
+++ b/src/fontloader/misc/fontloader-font-map.lua
@@ -80,12 +80,11 @@ local f_double = formatters["%04X%04X"]
-- local tounicodes = table.setmetatableindex(function(t,unicode)
-- local s
--- if unicode < 0x10000 then
+-- if unicode < 0xD7FF or (unicode > 0xDFFF and unicode <= 0xFFFF) then
-- s = f_single(unicode)
--- elseif unicode < 0x1FFFFFFFFF then
--- s = f_double(floor(unicode/1024),unicode%1024+0xDC00)
-- else
--- s = false
+-- unicode = unicode - 0x10000
+-- s = f_double(floor(unicode/1024)+0xD800,unicode%1024+0xDC00)
-- end
-- t[unicode] = s
-- return s
@@ -140,12 +139,11 @@ local f_double = formatters["%04X%04X"]
-- end
local function tounicode16(unicode,name)
- if unicode < 0x10000 then
+ if unicode < 0xD7FF or (unicode > 0xDFFF and unicode <= 0xFFFF) then
return f_single(unicode)
- elseif unicode < 0x1FFFFFFFFF then
- return f_double(floor(unicode/1024),unicode%1024+0xDC00)
else
- report_fonts("can't convert %a in %a into tounicode",unicode,name)
+ unicode = unicode - 0x10000
+ return f_double(floor(unicode/1024)+0xD800,unicode%1024+0xDC00)
end
end
@@ -153,13 +151,11 @@ local function tounicode16sequence(unicodes,name)
local t = { }
for l=1,#unicodes do
local u = unicodes[l]
- if u < 0x10000 then
+ if u < 0xD7FF or (u > 0xDFFF and u <= 0xFFFF) then
t[l] = f_single(u)
- elseif unicode < 0x1FFFFFFFFF then
- t[l] = f_double(floor(u/1024),u%1024+0xDC00)
else
- report_fonts ("can't convert %a in %a into tounicode",u,name)
- return
+ u = u - 0x10000
+ t[l] = f_double(floor(u/1024)+0xD800,u%1024+0xDC00)
end
end
return concat(t)
@@ -170,23 +166,20 @@ local function tounicode(unicode,name)
local t = { }
for l=1,#unicode do
local u = unicode[l]
- if u < 0x10000 then
+ if u < 0xD7FF or (u > 0xDFFF and u <= 0xFFFF) then
t[l] = f_single(u)
- elseif u < 0x1FFFFFFFFF then
- t[l] = f_double(floor(u/1024),u%1024+0xDC00)
else
- report_fonts ("can't convert %a in %a into tounicode",u,name)
- return
+ u = u - 0x10000
+ t[l] = f_double(floor(u/1024)+0xD800,u%1024+0xDC00)
end
end
return concat(t)
else
- if unicode < 0x10000 then
+ if unicode < 0xD7FF or (unicode > 0xDFFF and unicode <= 0xFFFF) then
return f_single(unicode)
- elseif unicode < 0x1FFFFFFFFF then
- return f_double(floor(unicode/1024),unicode%1024+0xDC00)
else
- report_fonts("can't convert %a in %a into tounicode",unicode,name)
+ unicode = unicode - 0x10000
+ return f_double(floor(unicode/1024)+0xD800,unicode%1024+0xDC00)
end
end
end
@@ -196,7 +189,8 @@ local function fromunicode16(str)
return tonumber(str,16)
else
local l, r = match(str,"(....)(....)")
- return (tonumber(l,16))*0x400 + tonumber(r,16) - 0xDC00
+ -- return (tonumber(l,16))*0x400 + tonumber(r,16) - 0xDC00
+ return 0x10000 + (tonumber(l,16)-0xD800)*0x400 + tonumber(r,16) - 0xDC00
end
end
@@ -214,26 +208,6 @@ end
-- return lpegmatch(p,str)
-- end
--- This is quite a bit faster but at the cost of some memory but if we
--- do this we will also use it elsewhere so let's not follow this route
--- now. I might use this method in the plain variant (no caching there)
--- but then I need a flag that distinguishes between code branches.
---
--- local cache = { }
---
--- function mappings.tounicode16(unicode)
--- local s = cache[unicode]
--- if not s then
--- if unicode < 0x10000 then
--- s = format("%04X",unicode)
--- else
--- s = format("%04X%04X",unicode/0x400+0xD800,unicode%0x400+0xDC00)
--- end
--- cache[unicode] = s
--- end
--- return s
--- end
-
mappings.makenameparser = makenameparser
mappings.tounicode = tounicode
mappings.tounicode16 = tounicode16
@@ -463,7 +437,43 @@ function mappings.addtounicode(data,filename,checklookups)
if type(checklookups) == "function" then
checklookups(data,missing,nofmissing)
end
+
-- todo: go lowercase
+
+ local collected = false
+ local unicoded = 0
+ for unicode, glyph in next, descriptions do
+ if not glyph.unicode and glyph.class == "ligature" then
+ if not collected then
+ collected = fonts.handlers.otf.readers.getcomponents(data)
+ if not collected then
+ break
+ end
+ end
+ local u = collected[unicode] -- always tables
+ if u then
+ local n = #u
+ for i=1,n do
+ if u[i] > private then
+ n = 0
+ break
+ end
+ end
+ if n > 0 then
+ if n > 1 then
+ glyph.unicode = u
+ else
+ glyph.unicode = u[1]
+ end
+ unicoded = unicoded + 1
+ end
+ end
+ end
+ end
+ if trace_mapping and unicoded > 0 then
+ report_fonts("%n ligature tounicode mappings deduced from gsub ligature features",unicoded)
+ end
+
if trace_mapping then
for unic, glyph in table.sortedhash(descriptions) do
local name = glyph.name