From 9a3d389e0390feab7f35ad24e7e75226a60c2c9b Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 15 Sep 2016 08:14:52 +0200 Subject: [fontloader] sync with Context as of 2016-09-15 --- src/fontloader/misc/fontloader-font-map.lua | 100 ++++++++++++++++++---------- 1 file changed, 64 insertions(+), 36 deletions(-) (limited to 'src/fontloader/misc/fontloader-font-map.lua') diff --git a/src/fontloader/misc/fontloader-font-map.lua b/src/fontloader/misc/fontloader-font-map.lua index 7f3b0f9..e2254f8 100644 --- a/src/fontloader/misc/fontloader-font-map.lua +++ b/src/fontloader/misc/fontloader-font-map.lua @@ -12,6 +12,7 @@ local match, format, find, concat, gsub, lower = string.match, string.format, st local P, R, S, C, Ct, Cc, lpegmatch = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cc, lpeg.match local floor = math.floor local formatters = string.formatters +local sortedhash, sortedkeys = table.sortedhash, table.sortedkeys local trace_loading = false trackers.register("fonts.loading", function(v) trace_loading = v end) local trace_mapping = false trackers.register("fonts.mapping", function(v) trace_mapping = v end) @@ -236,30 +237,37 @@ local namesplitter = Ct(C((1 - ligseparator - varseparator)^1) * (ligseparator * -- to be completed .. for fonts that use unicodes for ligatures which -- is a actually a bad thing and should be avoided in the first place -local overloads = allocate { - IJ = { name = "I_J", unicode = { 0x49, 0x4A }, mess = 0x0132 }, - ij = { name = "i_j", unicode = { 0x69, 0x6A }, mess = 0x0133 }, - ff = { name = "f_f", unicode = { 0x66, 0x66 }, mess = 0xFB00 }, - fi = { name = "f_i", unicode = { 0x66, 0x69 }, mess = 0xFB01 }, - fl = { name = "f_l", unicode = { 0x66, 0x6C }, mess = 0xFB02 }, - ffi = { name = "f_f_i", unicode = { 0x66, 0x66, 0x69 }, mess = 0xFB03 }, - ffl = { name = "f_f_l", unicode = { 0x66, 0x66, 0x6C }, mess = 0xFB04 }, - fj = { name = "f_j", unicode = { 0x66, 0x6A } }, - fk = { name = "f_k", unicode = { 0x66, 0x6B } }, -} - -for k, v in next, overloads do - local name = v.name - local mess = v.mess - if name then - overloads[name] = v - end - if mess then - overloads[mess] = v +do + + local overloads = allocate { + IJ = { name = "I_J", unicode = { 0x49, 0x4A }, mess = 0x0132 }, + ij = { name = "i_j", unicode = { 0x69, 0x6A }, mess = 0x0133 }, + ff = { name = "f_f", unicode = { 0x66, 0x66 }, mess = 0xFB00 }, + fi = { name = "f_i", unicode = { 0x66, 0x69 }, mess = 0xFB01 }, + fl = { name = "f_l", unicode = { 0x66, 0x6C }, mess = 0xFB02 }, + ffi = { name = "f_f_i", unicode = { 0x66, 0x66, 0x69 }, mess = 0xFB03 }, + ffl = { name = "f_f_l", unicode = { 0x66, 0x66, 0x6C }, mess = 0xFB04 }, + fj = { name = "f_j", unicode = { 0x66, 0x6A } }, + fk = { name = "f_k", unicode = { 0x66, 0x6B } }, + } + + local o = { } + + for k, v in next, overloads do + local name = v.name + local mess = v.mess + if name then + o[name] = v + end + if mess then + o[mess] = v + end + o[k] = v end -end -mappings.overloads = overloads + mappings.overloads = o + +end function mappings.addtounicode(data,filename,checklookups) local resources = data.resources @@ -272,6 +280,7 @@ function mappings.addtounicode(data,filename,checklookups) end local properties = data.properties local descriptions = data.descriptions + local overloads = mappings.overloads -- we need to move this code unicodes['space'] = unicodes['space'] or 32 unicodes['hyphen'] = unicodes['hyphen'] or 45 @@ -290,17 +299,25 @@ function mappings.addtounicode(data,filename,checklookups) local usedmap = cidinfo and fonts.cid.getmap(cidinfo) local uparser = makenameparser() -- hm, every time? if usedmap then - oparser = usedmap and makenameparser(cidinfo.ordering) - cidnames = usedmap.names - cidcodes = usedmap.unicodes + oparser = usedmap and makenameparser(cidinfo.ordering) + cidnames = usedmap.names + cidcodes = usedmap.unicodes end - local ns = 0 - local nl = 0 + local ns = 0 + local nl = 0 + -- + -- in order to avoid differences between runs due to hash randomization we + -- run over a sorted list -- - for du, glyph in next, descriptions do - local name = glyph.name + local dlist = sortedkeys(descriptions) + -- + -- for du, glyph in next, descriptions do + for i=1,#dlist do + local du = dlist[i] + local glyph = descriptions[du] + local name = glyph.name if name then - local overload = overloads[name] + local overload = overloads[name] or overloads[du] if overload then -- get rid of weird ligatures -- glyph.name = overload.name @@ -436,6 +453,11 @@ function mappings.addtounicode(data,filename,checklookups) end end end + else + local overload = overloads[du] + if overload then + glyph.unicode = overload.unicode + end end end if type(checklookups) == "function" then @@ -446,7 +468,10 @@ function mappings.addtounicode(data,filename,checklookups) local collected = false local unicoded = 0 - for unicode, glyph in next, descriptions do + -- for du, glyph in next, descriptions do + for i=1,#dlist do + local du = dlist[i] + local glyph = descriptions[du] if glyph.class == "ligature" and (force_ligatures or not glyph.unicode) then if not collected then collected = fonts.handlers.otf.readers.getcomponents(data) @@ -454,7 +479,7 @@ function mappings.addtounicode(data,filename,checklookups) break end end - local u = collected[unicode] -- always tables + local u = collected[du] -- always tables if u then local n = #u for i=1,n do @@ -478,7 +503,10 @@ function mappings.addtounicode(data,filename,checklookups) 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 + -- for unic, glyph in sortedhash(descriptions) do + for i=1,#dlist do + local du = dlist[i] + local glyph = descriptions[du] local name = glyph.name or "-" local index = glyph.index or 0 local unicode = glyph.unicode @@ -488,12 +516,12 @@ function mappings.addtounicode(data,filename,checklookups) for i=1,#unicode do unicodes[i] = formatters("%U",unicode[i]) end - report_fonts("internal slot %U, name %a, unicode %U, tounicode % t",index,name,unic,unicodes) + report_fonts("internal slot %U, name %a, unicode %U, tounicode % t",index,name,du,unicodes) else - report_fonts("internal slot %U, name %a, unicode %U, tounicode %U",index,name,unic,unicode) + report_fonts("internal slot %U, name %a, unicode %U, tounicode %U",index,name,du,unicode) end else - report_fonts("internal slot %U, name %a, unicode %U",index,name,unic) + report_fonts("internal slot %U, name %a, unicode %U",index,name,du) end end end -- cgit v1.2.3