diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-def.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/font-def.lua | 88 |
1 files changed, 54 insertions, 34 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-def.lua b/Master/texmf-dist/tex/context/base/font-def.lua index 96de480ac86..5074e49ed75 100644 --- a/Master/texmf-dist/tex/context/base/font-def.lua +++ b/Master/texmf-dist/tex/context/base/font-def.lua @@ -6,7 +6,8 @@ if not modules then modules = { } end modules ['font-def'] = { license = "see context related readme files" } -local concat = table.concat +-- We can overload some of the definers.functions so we don't local them. + local format, gmatch, match, find, lower, gsub = string.format, string.gmatch, string.match, string.find, string.lower, string.gsub local tostring, next = tostring, next local lpegmatch = lpeg.match @@ -32,6 +33,7 @@ local readers = fonts.readers local definers = fonts.definers local specifiers = fonts.specifiers local constructors = fonts.constructors +local fontgoodies = fonts.goodies readers.sequence = allocate { 'otf', 'ttf', 'afm', 'tfm', 'lua' } -- dfont ttc @@ -42,10 +44,13 @@ definers.methods = definers.methods or { } local internalized = allocate() -- internal tex numbers (private) - local loadedfonts = constructors.loadedfonts local designsizes = constructors.designsizes +-- not in generic (some day I'll make two defs, one for context, one for generic) + +local resolvefile = fontgoodies and fontgoodies.filenames and fontgoodies.filenames.resolve or function(s) return s end + --[[ldx-- <p>We hardly gain anything when we cache the final (pre scaled) <l n='tfm'/> table. But it can be handy for debugging, so we no @@ -72,7 +77,7 @@ and prepares a table that will move along as we proceed.</p> -- name name(sub) name(sub)*spec name*spec -- name@spec*oeps -local splitter, splitspecifiers = nil, "" +local splitter, splitspecifiers = nil, "" -- not so nice local P, C, S, Cc = lpeg.P, lpeg.C, lpeg.S, lpeg.Cc @@ -83,7 +88,7 @@ local space = P(" ") definers.defaultlookup = "file" -local prefixpattern = P(false) +local prefixpattern = P(false) local function addspecifier(symbol) splitspecifiers = splitspecifiers .. symbol @@ -119,16 +124,15 @@ function definers.registersplit(symbol,action,verbosename) end end -function definers.makespecification(specification,lookup,name,sub,method,detail,size) +local function makespecification(specification,lookup,name,sub,method,detail,size) size = size or 655360 - if trace_defining then - report_defining("%s -> lookup: %s, name: %s, sub: %s, method: %s, detail: %s", - specification, (lookup ~= "" and lookup) or "[file]", (name ~= "" and name) or "-", - (sub ~= "" and sub) or "-", (method ~= "" and method) or "-", (detail ~= "" and detail) or "-") - end if not lookup or lookup == "" then lookup = definers.defaultlookup end + if trace_defining then + report_defining("specification %a, lookup %a, name %a, sub %a, method %a, detail %a", + specification, lookup, name, sub, method, detail) + end local t = { lookup = lookup, -- forced type specification = specification, -- full specification @@ -144,10 +148,13 @@ function definers.makespecification(specification,lookup,name,sub,method,detail, return t end + +definers.makespecification = makespecification + function definers.analyze(specification, size) -- can be optimized with locals local lookup, name, sub, method, detail = getspecification(specification or "") - return definers.makespecification(specification, lookup, name, sub, method, detail, size) + return makespecification(specification, lookup, name, sub, method, detail, size) end --[[ldx-- @@ -160,10 +167,13 @@ local resolvers = definers.resolvers -- todo: reporter function resolvers.file(specification) - local suffix = file.suffix(specification.name) + local name = resolvefile(specification.name) -- catch for renames + local suffix = file.suffix(name) if fonts.formats[suffix] then specification.forced = suffix - specification.name = file.removesuffix(specification.name) + specification.name = file.removesuffix(name) + else + specification.name = name -- cna be resolved end end @@ -194,7 +204,7 @@ function resolvers.spec(specification) if resolved then specification.resolved = resolved specification.sub = sub - specification.forced = file.extname(resolved) + specification.forced = file.suffix(resolved) specification.name = file.removesuffix(resolved) end else @@ -242,12 +252,13 @@ specification yet.</p> function definers.applypostprocessors(tfmdata) local postprocessors = tfmdata.postprocessors if postprocessors then + local properties = tfmdata.properties for i=1,#postprocessors do local extrahash = postprocessors[i](tfmdata) -- after scaling etc if type(extrahash) == "string" and extrahash ~= "" then -- e.g. a reencoding needs this extrahash = gsub(lower(extrahash),"[^a-z]","-") - tfmdata.properties.fullname = format("%s-%s",tfmdata.properties.fullname,extrahash) + properties.fullname = format("%s-%s",properties.fullname,extrahash) end end end @@ -285,7 +296,7 @@ function definers.loadfont(specification) local reader = readers[lower(forced)] tfmdata = reader and reader(specification) if not tfmdata then - report_defining("forced type %s of %s not found",forced,specification.name) + report_defining("forced type %a of %a not found",forced,specification.name) end else local sequence = readers.sequence -- can be overloaded so only a shortcut here @@ -293,7 +304,7 @@ function definers.loadfont(specification) local reader = sequence[s] if readers[reader] then -- we skip not loaded readers if trace_defining then - report_defining("trying (reader sequence driven) type %s for %s with file %s",reader,specification.name,specification.filename or "unknown") + report_defining("trying (reader sequence driven) type %a for %a with file %a",reader,specification.name,specification.filename) end tfmdata = readers[reader](specification) if tfmdata then @@ -312,14 +323,26 @@ function definers.loadfont(specification) end end if not tfmdata then - report_defining("font with asked name '%s' is not found using lookup '%s'",specification.name,specification.lookup) + report_defining("font with asked name %a is not found using lookup %a",specification.name,specification.lookup) end return tfmdata end ---[[ldx-- -<p>For virtual fonts we need a slightly different approach:</p> ---ldx]]-- +local function checkvirtual(tfmdata) + -- begin of experiment: we can use { "slot", 0, number } in virtual fonts + local fonts = tfmdata.fonts + local selfid = font.nextid() + if fonts and #fonts > 0 then + for i=1,#fonts do + if fonts[i][2] == 0 then + fonts[i][2] = selfid + end + end + else + tfmdata.fonts = { "id", selfid } + end + -- end of experiment +end function constructors.readanddefine(name,size) -- no id -- maybe a dummy first local specification = definers.analyze(name,size) @@ -333,7 +356,7 @@ function constructors.readanddefine(name,size) -- no id -- maybe a dummy first if not id then local tfmdata = definers.loadfont(specification) if tfmdata then - tfmdata.properties.hash = hash + checkvirtual(tfmdata) -- experiment, will become obsolete when slots can selfreference id = font.define(tfmdata) definers.register(tfmdata,id) else @@ -373,7 +396,7 @@ function definers.register(tfmdata,id) if not internalized[hash] then internalized[hash] = id if trace_defining then - report_defining("registering font, id: %s, hash: %s",id or "?",hash or "?") + report_defining("registering font, id %s, hash %a",id,hash) end fontdata[id] = tfmdata end @@ -402,7 +425,6 @@ function definers.read(specification,size,id) -- id can be optional, name can al if trace_defining then report_defining("loaded and hashed: %s",hash) end - --~ constructors.checkvirtualid(tfmdata) -- interferes tfmdata.properties.hash = hash if id then definers.register(tfmdata,id) @@ -415,24 +437,22 @@ function definers.read(specification,size,id) -- id can be optional, name can al end lastdefined = tfmdata or id -- todo ! ! ! ! ! if not tfmdata then -- or id? - report_defining( "unknown font %s, loading aborted",specification.name) + report_defining( "unknown font %a, loading aborted",specification.name) elseif trace_defining and type(tfmdata) == "table" then local properties = tfmdata.properties or { } local parameters = tfmdata.parameters or { } - report_defining("using %s font with id %s, name:%s size:%s bytes:%s encoding:%s fullname:%s filename:%s", - properties.format or "unknown", - id or "?", - properties.name or "?", - parameters.size or "default", - properties.encodingbytes or "?", - properties.encodingname or "unicode", - properties.fullname or "?", - file.basename(properties.filename or "?")) + report_defining("using %s font with id %a, name %a, size %a, bytes %a, encoding %a, fullname %a, filename %a", + properties.format, id, properties.name, parameters.size, properties.encodingbytes, + properties.encodingname, properties.fullname, file.basename(properties.filename)) end statistics.stoptiming(fonts) return tfmdata end +function font.getfont(id) + return fontdata[id] -- otherwise issues +end + --[[ldx-- <p>We overload the <l n='tfm'/> reader.</p> --ldx]]-- |