diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-syn.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/font-syn.lua | 101 |
1 files changed, 70 insertions, 31 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-syn.lua b/Master/texmf-dist/tex/context/base/font-syn.lua index 18ed46a2f88..bf46c85730f 100644 --- a/Master/texmf-dist/tex/context/base/font-syn.lua +++ b/Master/texmf-dist/tex/context/base/font-syn.lua @@ -33,7 +33,14 @@ local exists = io.exists local findfile = resolvers.findfile local cleanpath = resolvers.cleanpath -local resolveresolved = resolvers.resolve +local resolveprefix = resolvers.resolve + +local fontloader = fontloader +local font_to_table = fontloader.to_table +local open_font = fontloader.open +local get_font_info = fontloader.info +local close_font = fontloader.close +local font_fields = fontloader.fields local settings_to_hash = utilities.parsers.settings_to_hash_tolerant @@ -50,7 +57,7 @@ using a table that has keys filtered from the font related files.</p> fonts = fonts or { } -- also used elsewhere -local names = font.names or allocate { } +local names = fonts.names or allocate { } fonts.names = names local filters = names.filters or { } @@ -298,10 +305,10 @@ end but to keep the overview, we define them here.</p> --ldx]]-- -filters.otf = fontloader.info -filters.ttf = fontloader.info -filters.ttc = fontloader.info -filters.dfont = fontloader.info +filters.otf = get_font_info +filters.ttf = get_font_info +filters.ttc = get_font_info +filters.dfont = get_font_info -- We had this as temporary solution because we needed a bit more info but in the -- meantime it got an interesting side effect: currently luatex delays loading of e.g. @@ -311,12 +318,12 @@ filters.dfont = fontloader.info -- missing: names, units_per_em, design_range_bottom, design_range_top, design_size, -- pfminfo, top_side_bearing --- function fontloader.fullinfo(...) -- check with taco what we get / could get --- local ff = fontloader.open(...) +-- local function get_full_info(...) -- check with taco what we get / could get +-- local ff = open_font(...) -- if ff then --- local d = ff -- and fontloader.to_table(ff) +-- local d = ff -- and font_to_table(ff) -- d.glyphs, d.subfonts, d.gpos, d.gsub, d.lookups = nil, nil, nil, nil, nil --- fontloader.close(ff) +-- close_font(ff) -- return d -- else -- return nil, "error in loading font" @@ -327,10 +334,10 @@ filters.dfont = fontloader.info -- return these keys/values (and maybe some more) but at least we close the loader which -- might save some memory in the end. --- function fontloader.fullinfo(name) --- local ff = fontloader.open(name) +-- local function get_full_info(name) +-- local ff = open_font(name) -- if ff then --- local fields = table.tohash(fontloader.fields(ff),true) +-- local fields = table.tohash(font_fields(ff),true) -- isn't that one stable -- local d = { -- names = fields.names and ff.names, -- familyname = fields.familyname and ff.familyname, @@ -349,36 +356,68 @@ filters.dfont = fontloader.info -- setmetatableindex(d,function(t,k) -- report_names("warning, trying to access field %a in font table of %a",k,name) -- end) --- fontloader.close(ff) +-- close_font(ff) -- return d -- else -- return nil, "error in loading font" -- end -- end --- As we have lazy loading anyway, this one still is full and with less code than --- the previous one. But this depends on the garbage collector to kick in. +-- more efficient: + +local fields = nil -function fontloader.fullinfo(...) - local ff = fontloader.open(...) +local function get_full_info(name) + local ff = open_font(name) if ff then - local d = { } -- ff is userdata so [1] or # fails on it - setmetatableindex(d,ff) + if not fields then + fields = table.tohash(font_fields(ff),true) + end + -- unfortunately luatex aborts when a field is not available + local d = { + names = fields.names and ff.names, + familyname = fields.familyname and ff.familyname, + fullname = fields.fullname and ff.fullname, + fontname = fields.fontname and ff.fontname, + weight = fields.weight and ff.weight, + italicangle = fields.italicangle and ff.italicangle, + units_per_em = fields.units_per_em and ff.units_per_em, + design_range_bottom = fields.design_range_bottom and ff.design_range_bottom, + design_range_top = fields.design_range_top and ff.design_range_top, + design_size = fields.design_size and ff.design_size, + italicangle = fields.italicangle and ff.italicangle, + pfminfo = fields.pfminfo and ff.pfminfo, + top_side_bearing = fields.top_side_bearing and ff.top_side_bearing, -- not there + } + setmetatableindex(d,function(t,k) + report_names("warning, trying to access field %a in font table of %a",k,name) + end) + close_font(ff) return d else return nil, "error in loading font" end end --- We don't get the design_* values here as for that the fontloader has to load feature --- info and therefore we're not much better off than using 'open'. --- --- if tonumber(status.luatex_version) > 78 or (tonumber(status.luatex_version) == 78 and tonumber(status.luatex_revision) > 0) then --- fontloader.fullinfo = fontloader.info +-- As we have lazy loading anyway, this one still is full and with less code than +-- the previous one. But this depends on the garbage collector to kick in and in the +-- current version that somehow happens not that often (on my machine I end up with +-- soem 3 GB extra before that happens). + +-- local function get_full_info(...) +-- local ff = open_font(...) +-- if ff then +-- local d = { } -- ff is userdata so [1] or # fails on it +-- setmetatableindex(d,ff) +-- return d -- garbage collection will do the close_font(ff) +-- else +-- return nil, "error in loading font" +-- end -- end -filters.otf = fontloader.fullinfo -filters.ttf = fontloader.fullinfo +fontloader.fullinfo = get_full_info +filters .otf = get_full_info +filters .ttf = get_full_info function filters.afm(name) -- we could parse the afm file as well, and then report an error but @@ -408,7 +447,7 @@ function filters.afm(name) end function filters.pfb(name) - return fontloader.info(name) + return get_font_info(name) end --[[ldx-- @@ -1065,15 +1104,15 @@ local function analyzefiles(olddata) resolvers.dowithfilesintree(".*%." .. suffix .. "$", function(method,root,path,name) if method == "file" or method == "tree" then local completename = root .."/" .. path .. "/" .. name - completename = resolveresolved(completename) -- no shortcut + completename = resolveprefix(completename) -- no shortcut identify(completename,name,suffix,name) return true end end, function(blobtype,blobpath,pattern) - blobpath = resolveresolved(blobpath) -- no shortcut + blobpath = resolveprefix(blobpath) -- no shortcut report_names("scanning path %a for %s files",blobpath,suffix) end, function(blobtype,blobpath,pattern,total,checked,done) - blobpath = resolveresolved(blobpath) -- no shortcut + blobpath = resolveprefix(blobpath) -- no shortcut report_names("%s entries found, %s %s files checked, %s okay",total,checked,suffix,done) end) end |