From b0cb116048d189b72d15f1a6c19f0fb365e65d40 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 22 Oct 2016 19:57:52 +0200 Subject: [fontloader] sync with Context as of 2016-10-22 --- src/fontloader/misc/fontloader-font-dsp.lua | 57 +++++++++++++++++++------ src/fontloader/runtime/fontloader-reference.lua | 45 ++++++++++++++----- 2 files changed, 79 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/fontloader/misc/fontloader-font-dsp.lua b/src/fontloader/misc/fontloader-font-dsp.lua index cd28168..14e3a1d 100644 --- a/src/fontloader/misc/fontloader-font-dsp.lua +++ b/src/fontloader/misc/fontloader-font-dsp.lua @@ -70,6 +70,7 @@ local readers = fonts.handlers.otf.readers local streamreader = readers.streamreader local setposition = streamreader.setposition +local getposition = streamreader.getposition local skipshort = streamreader.skipshort local readushort = streamreader.readcardinal2 -- 16-bit unsigned integer local readulong = streamreader.readcardinal4 -- 24-bit unsigned integer @@ -397,7 +398,7 @@ local function readlookuparray(f,noflookups,nofcurrent) end end -- if length > nofcurrent then - -- report_issue("more lookups than currently matched characters") + -- report("more lookups than currently matched characters") -- end end return lookups @@ -413,7 +414,7 @@ end -- for i=1,noflookups do -- local index = readushort(f) + 1 -- if index > nofcurrent then --- report_issue("more lookups than currently matched characters") +-- report("more lookups than currently matched characters") -- for i=nofcurrent+1,index-1 do -- lookups[i] = false -- end @@ -1285,20 +1286,50 @@ do local plugins = { } - function plugins.size(f,fontdata,tableoffset,parameters) - if not fontdata.designsize then - setposition(f,tableoffset+parameters) - local designsize = readushort(f) - if designsize > 0 then - fontdata.designsize = designsize - skipshort(f,2) - fontdata.minsize = readushort(f) - fontdata.maxsize = readushort(f) + function plugins.size(f,fontdata,tableoffset,feature) + if fontdata.designsize then + -- yes, there are fonts with multiple size entries ... it probably relates + -- to the other two fields (menu entries in some language) + else + local function check(offset) + setposition(f,offset) + local designsize = readushort(f) + if designsize > 0 then -- we could also have a threshold + local fontstyle = readushort(f) + local guimenuid = readushort(f) + local minsize = readushort(f) + local maxsize = readushort(f) + if minsize == 0 and maxsize == 0 and fontstyleid == 0 and guimenuid == 0 then + minsize = designsize + maxsize = designsize + end + if designsize >= minsize and designsize <= maxsize then + return minsize, maxsize, designsize + end + end + end + local minsize, maxsize, designsize = check(tableoffset+feature.offset+feature.parameters) + if not designsize then + -- some old adobe fonts have: tableoffset+feature.parameters and we could + -- use some heuristic but why bother ... this extra check will be removed + -- some day and/or when we run into an issue + minsize, maxsize, designsize = check(tableoffset+feature.parameters) + if designsize then + report("bad size feature in %a, falling back to wrong offset",fontdata.filename or "?") + else + report("bad size feature in %a,",fontdata.filename or "?") + end + end + if designsize then + fontdata.minsize = minsize + fontdata.maxsize = maxsize + fontdata.designsize = designsize end end end - -- feature order needs checking ... as we loop over a hash + -- feature order needs checking ... as we loop over a hash ... however, in the file + -- they are sorted so order is not that relevant local function reorderfeatures(fontdata,scripts,features) local scriptlangs = { } @@ -1440,7 +1471,7 @@ do feature.parameters = parameters local plugin = plugins[feature.tag] if plugin then - plugin(f,fontdata,offset,parameters) + plugin(f,fontdata,featureoffset,feature) end end end diff --git a/src/fontloader/runtime/fontloader-reference.lua b/src/fontloader/runtime/fontloader-reference.lua index a0b906d..287ef1a 100644 --- a/src/fontloader/runtime/fontloader-reference.lua +++ b/src/fontloader/runtime/fontloader-reference.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 10/19/16 22:51:32 +-- merge date : 10/22/16 10:43:17 do -- begin closure to overcome local limits and interference @@ -11398,6 +11398,7 @@ local report=logs.reporter("otf reader") local readers=fonts.handlers.otf.readers local streamreader=readers.streamreader local setposition=streamreader.setposition +local getposition=streamreader.getposition local skipshort=streamreader.skipshort local readushort=streamreader.readcardinal2 local readulong=streamreader.readcardinal4 @@ -12453,15 +12454,39 @@ function gposhandlers.extension(f,fontdata,lookupid,lookupoffset,offset,glyphs,n end do local plugins={} - function plugins.size(f,fontdata,tableoffset,parameters) - if not fontdata.designsize then - setposition(f,tableoffset+parameters) - local designsize=readushort(f) - if designsize>0 then + function plugins.size(f,fontdata,tableoffset,feature) + if fontdata.designsize then + else + local function check(offset) + setposition(f,offset) + local designsize=readushort(f) + if designsize>0 then + local fontstyle=readushort(f) + local guimenuid=readushort(f) + local minsize=readushort(f) + local maxsize=readushort(f) + if minsize==0 and maxsize==0 and fontstyleid==0 and guimenuid==0 then + minsize=designsize + maxsize=designsize + end + if designsize>=minsize and designsize<=maxsize then + return minsize,maxsize,designsize + end + end + end + local minsize,maxsize,designsize=check(tableoffset+feature.offset+feature.parameters) + if not designsize then + minsize,maxsize,designsize=check(tableoffset+feature.parameters) + if designsize then + report("bad size feature in %a, falling back to wrong offset",fontdata.filename or "?") + else + report("bad size feature in %a,",fontdata.filename or "?") + end + end + if designsize then + fontdata.minsize=minsize + fontdata.maxsize=maxsize fontdata.designsize=designsize - skipshort(f,2) - fontdata.minsize=readushort(f) - fontdata.maxsize=readushort(f) end end end @@ -12598,7 +12623,7 @@ do feature.parameters=parameters local plugin=plugins[feature.tag] if plugin then - plugin(f,fontdata,offset,parameters) + plugin(f,fontdata,featureoffset,feature) end end end -- cgit v1.2.3