diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-gds.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/font-gds.lua | 132 |
1 files changed, 90 insertions, 42 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-gds.lua b/Master/texmf-dist/tex/context/base/font-gds.lua index 3b87e4c772b..91a5ea66c30 100644 --- a/Master/texmf-dist/tex/context/base/font-gds.lua +++ b/Master/texmf-dist/tex/context/base/font-gds.lua @@ -8,49 +8,46 @@ if not modules then modules = { } end modules ['font-gds'] = { -- depends on ctx -local type, next = type, next +local type, next, tonumber = type, next, tonumber local gmatch, format, lower, find, splitup = string.gmatch, string.format, string.lower, string.find, string.splitup local texsp = tex.sp local fonts, nodes, attributes, node = fonts, nodes, attributes, node -local trace_goodies = false - -trackers.register("fonts.goodies", function(v) trace_goodies = v end) - +local trace_goodies = false trackers.register("fonts.goodies", function(v) trace_goodies = v end) local report_goodies = logs.reporter("fonts","goodies") local allocate = utilities.storage.allocate local otf = fonts.handlers.otf -local addotffeature = otf.enhancers.addfeature - -local otffeatures = fonts.constructors.newfeatures("otf") -local registerotffeature = otffeatures.register +local afm = fonts.handlers.afm +local tfm = fonts.handlers.tfm -local afmfeatures = fonts.constructors.newfeatures("afm") -local registerafmfeature = afmfeatures.register +local registerotffeature = otf.features.register +local registerafmfeature = afm.features.register +local registertfmfeature = tfm.features.register -local tfmfeatures = fonts.constructors.newfeatures("tfm") -local registertfmfeature = tfmfeatures.register - -local fontgoodies = { } +local fontgoodies = fonts.goodies or { } fonts.goodies = fontgoodies -local typefaces = allocate() +local typefaces = fonts.typefaces or allocate() fonts.typefaces = typefaces -local data = allocate() -fontgoodies.data = fontgoodies.data +local data = fontgoodies.data or allocate() +fontgoodies.data = data -local list = { } +local list = fontgoodies.list or { } fontgoodies.list = list -- no allocate as we want to see what is there +local addotffeature = otf.enhancers.addfeature + +local findfile = resolvers.findfile + function fontgoodies.report(what,trace,goodies) if trace_goodies or trace then local whatever = goodies[what] if whatever then - report_goodies("goodie '%s' found in '%s'",what,goodies.name) + report_goodies("goodie %a found in %a",what,goodies.name) end end end @@ -60,9 +57,9 @@ local function loadgoodies(filename) -- maybe a merge is better if goodies ~= nil then -- found or tagged unfound elseif type(filename) == "string" then - local fullname = resolvers.findfile(file.addsuffix(filename,"lfg")) or "" -- prefered suffix + local fullname = findfile(file.addsuffix(filename,"lfg")) or "" -- prefered suffix if fullname == "" then - fullname = resolvers.findfile(file.addsuffix(filename,"lua")) or "" -- fallback suffix + fullname = findfile(file.addsuffix(filename,"lua")) or "" -- fallback suffix end if fullname == "" then report_goodies("goodie file '%s.lfg' is not found",filename) @@ -70,10 +67,10 @@ local function loadgoodies(filename) -- maybe a merge is better else goodies = dofile(fullname) or false if not goodies then - report_goodies("goodie file '%s' is invalid",fullname) + report_goodies("goodie file %a is invalid",fullname) return nil elseif trace_goodies then - report_goodies("goodie file '%s' is loaded",fullname) + report_goodies("goodie file %a is loaded",fullname) end goodies.name = goodies.name or "no name" for name, fnc in next, list do @@ -105,7 +102,7 @@ local function setgoodies(tfmdata,value) local ok = loadgoodies(filename) if ok then if trace_goodies then - report_goodies("assigning goodie '%s'",filename) + report_goodies("assigning goodie %a",filename) end goodies[#goodies+1] = ok end @@ -141,28 +138,30 @@ end -- fonts.features.flattened = flattenedfeatures -function fontgoodies.prepare_features(goodies,name,set) +local function prepare_features(goodies,name,set) if set then local ff = flattenedfeatures(set) local fullname = goodies.name .. "::" .. name local n, s = fonts.specifiers.presetcontext(fullname,"",ff) goodies.featuresets[name] = s -- set if trace_goodies then - report_goodies("feature set '%s' gets number %s and name '%s'",name,n,fullname) + report_goodies("feature set %a gets number %a and name %a",name,n,fullname) end return n end end +fontgoodies.prepare_features = prepare_features + local function initialize(goodies,tfmdata) local featuresets = goodies.featuresets local goodiesname = goodies.name if featuresets then if trace_goodies then - report_goodies("checking featuresets in '%s'",goodies.name) + report_goodies("checking featuresets in %a",goodies.name) end for name, set in next, featuresets do - fontgoodies.prepare_features(goodies,name,set) + prepare_features(goodies,name,set) end end end @@ -177,7 +176,7 @@ local function setfeatureset(tfmdata,set,features) for i=1,#goodies do -- last one wins local g = goodies[i] - what = (g.featuresets and g.featuresets[set]) or what + what = g.featuresets and g.featuresets[set] or what end if what then for feature, value in next, what do @@ -193,12 +192,13 @@ end -- postprocessors (we could hash processor and share code) function fontgoodies.registerpostprocessor(tfmdata,f,prepend) - if not tfmdata.postprocessors then + local postprocessors = tfmdata.postprocessors + if not postprocessors then tfmdata.postprocessors = { f } elseif prepend then - table.insert(tfmdata.postprocessors,f,1) + table.insert(postprocessors,f,1) else - table.insert(tfmdata.postprocessors,f) + table.insert(postprocessors,f) end end @@ -236,9 +236,9 @@ end -- colorschemes -local colorschemes = { } +local colorschemes = fontgoodies.colorschemes or allocate { } fontgoodies.colorschemes = colorschemes -colorschemes.data = { } +colorschemes.data = colorschemes.data or { } local function setcolorscheme(tfmdata,scheme) if type(scheme) == "string" then @@ -249,7 +249,7 @@ local function setcolorscheme(tfmdata,scheme) for i=1,#goodies do -- last one counts local g = goodies[i] - what = (g.colorschemes and g.colorschemes[scheme]) or what + what = g.colorschemes and g.colorschemes[scheme] or what end if type(what) == "table" then -- this is font bound but we can share them if needed @@ -300,7 +300,6 @@ end local fontdata = fonts.hashes.identifiers local setnodecolor = nodes.tracers.colors.set -local has_attribute = node.has_attribute local traverse_id = node.traverse_id local a_colorscheme = attributes.private('colorscheme') local glyph = node.id("glyph") @@ -309,7 +308,7 @@ function colorschemes.coloring(head) local lastfont, lastscheme local done = false for n in traverse_id(glyph,head) do - local a = has_attribute(n,a_colorscheme) + local a = n[a_colorscheme] if a then local f = n.font if f ~= lastfont then @@ -486,7 +485,7 @@ local function initialize(tfmdata) mathitalics = mathitalics[file.nameonly(properties.name)] or mathitalics if mathitalics then if trace_goodies then - report_goodies("loading mathitalics for font '%s'",properties.name) + report_goodies("loading mathitalics for font %a",properties.name) end local corrections = mathitalics.corrections local defaultfactor = mathitalics.defaultfactor @@ -511,7 +510,7 @@ local function initialize(tfmdata) properties.mathitalics = disableengine end if trace_goodies then - report_goodies("assigning mathitalics for font '%s'",properties.name) + report_goodies("assigning mathitalics for font %a",properties.name) end local mathitalics = properties.mathitalics local quad = parameters.quad @@ -605,9 +604,42 @@ end fontgoodies.register("compositions", initialize) -local designsizes = { } +local filenames = fontgoodies.filenames or allocate() +fontgoodies.filenames = filenames + +local filedata = filenames.data or allocate() +filenames.data = filedata + +local function initialize(goodies) -- design sizes are registered global + local fn = goodies.filenames + if fn then + for usedname, alternativenames in next, fn do + filedata[usedname] = alternativenames + end + end +end + +fontgoodies.register("filenames", initialize) + +function fontgoodies.filenames.resolve(name) + local fd = filedata[name] + if fd and findfile(name) == "" then + for i=1,#fd do + local fn = fd[i] + if findfile(fn) ~= "" then + return fn + end + end + else + -- no lookup, just use the regular mechanism + end + return name +end + +local designsizes = fontgoodies.designsizes or allocate() fontgoodies.designsizes = designsizes -local designdata = allocate() + +local designdata = designsizes.data or allocate() designsizes.data = designdata local function initialize(goodies) -- design sizes are registered global @@ -687,3 +719,19 @@ end commands.loadfontgoodies = fontgoodies.load commands.enablefontcolorschemes = colorschemes.enable + +-- weird place ... depends on math + +local function finalize(tfmdata,feature,value) + mathematics.overloaddimensions(tfmdata,tfmdata,value) +end + +registerotffeature { + name = "mathdimensions", + description = "manipulate math dimensions", + -- default = true, + manipulators = { + base = finalize, + node = finalize, + } +} |