diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-enh.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/font-enh.lua | 326 |
1 files changed, 151 insertions, 175 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-enh.lua b/Master/texmf-dist/tex/context/base/font-enh.lua index fc70c04c566..ca9893e3d84 100644 --- a/Master/texmf-dist/tex/context/base/font-enh.lua +++ b/Master/texmf-dist/tex/context/base/font-enh.lua @@ -6,196 +6,172 @@ if not modules then modules = { } end modules ['font-enh'] = { license = "see context related readme files" } -local next, match = next, string.match +local next = next -local trace_defining = false trackers.register("fonts.defining", function(v) trace_defining = v end) +local trace_defining = false trackers.register("fonts.defining", function(v) trace_defining = v end) +local report_defining = logs.reporter("fonts","defining") --- tfmdata has also fast access to indices and unicodes --- to be checked: otf -> tfm -> tfmscaled --- --- watch out: no negative depths and negative eights permitted in regular fonts - ---[[ldx-- -<p>Here we only implement a few helper functions.</p> ---ldx]]-- - -local tfm = fonts.tfm - ---[[ldx-- -<p>The next function encapsulates the standard <l n='tfm'/> loader as -supplied by <l n='luatex'/>.</p> ---ldx]]-- - --- auto complete font with missing composed characters +local fonts = fonts +local constructors = fonts.constructors -table.insert(fonts.manipulators,"compose") +local tfmfeatures = constructors.newfeatures("tfm") +local registertfmfeature = tfmfeatures.register -function fonts.initializers.common.compose(tfmdata,value) - if value then - fonts.vf.aux.compose_characters(tfmdata) - end -end - --- tfm features, experimental +local afmfeatures = fonts.constructors.newfeatures("afm") +local registerafmfeature = afmfeatures.register -tfm.features = tfm.features or { } -tfm.features.list = tfm.features.list or { } -tfm.features.default = tfm.features.default or { } +local otffeatures = fonts.constructors.newfeatures("otf") +local registerotffeature = otffeatures.register -function tfm.enhance(tfmdata,specification) - -- we don't really share tfm data because we always reload - -- but this is more in sycn with afm and such - local features = (specification.features and specification.features.normal ) or { } - tfmdata.shared = tfmdata.shared or { } - tfmdata.shared.features = features - -- tfmdata.shared.tfmdata = tfmdata -- circular - tfmdata.filename = specification.name - if not features.encoding then - local name, size = specification.name, specification.size - local encoding, filename = match(name,"^(.-)%-(.*)$") -- context: encoding-name.* - if filename and encoding and fonts.enc.known[encoding] then - features.encoding = encoding +-- -- these will become goodies (when needed at all) +-- +-- local fontencodings = fonts.encodings +-- fontencodings.remappings = fontencodings.remappings or { } +-- +-- local function reencode(tfmdata,encoding) +-- if encoding and fontencodings.known[encoding] then +-- local data = fontencodings.load(encoding) +-- if data then +-- tfmdata.properties.encoding = encoding +-- local characters = tfmdata.characters +-- local original = { } +-- local vector = data.vector +-- for unicode, character in next, characters do +-- character.name = vector[unicode] +-- character.index = unicode, character +-- original[unicode] = character +-- end +-- for newcode, oldcode in next, data.unicodes do +-- if newcode ~= oldcode then +-- if trace_defining then +-- report_defining("reencoding U+%05X to U+%05X",oldcode,newcode) +-- end +-- characters[newcode] = original[oldcode] +-- end +-- end +-- end +-- end +-- end +-- +-- registertfmfeature { +-- name = "reencode", +-- description = "reencode", +-- manipulators = { +-- base = reencode, +-- node = reencode, +-- } +-- } +-- +-- local function remap(tfmdata,remapping) +-- local vector = remapping and fontencodings.remappings[remapping] +-- if vector then +-- local characters, original = tfmdata.characters, { } +-- for k, v in next, characters do +-- original[k], characters[k] = v, nil +-- end +-- for k,v in next, vector do +-- if k ~= v then +-- if trace_defining then +-- report_defining("remapping U+%05X to U+%05X",k,v) +-- end +-- local c = original[k] +-- characters[v] = c +-- c.index = k +-- end +-- end +-- local properties = tfmdata.properties +-- if not properties then +-- properties = { } +-- tfmdata.properties = properties +-- else +-- properties.encodingbytes = 2 +-- properties.format = properties.format or 'type1' +-- end +-- end +-- end +-- +-- registertfmfeature { +-- name = "remap", +-- description = "remap", +-- manipulators = { +-- base = remap, +-- node = remap, +-- } +-- } + +-- \definefontfeature[dingbats][goodies=dingbats,unicoding=yes] + +-- we only add and don't replace +-- we could also add kerns but we asssume symbols +-- todo: complain if not basemode + +-- remapping = { +-- tounicode = true, +-- unicodes = { +-- a1 = 0x2701, + +local tosixteen = fonts.mappings.tounicode16 + +local function initializeunicoding(tfmdata) + local goodies = tfmdata.goodies + local newcoding = nil + local tounicode = false + for i=1,#goodies do + local remapping = goodies[i].remapping + if remapping and remapping.unicodes then + newcoding = remapping.unicodes -- names to unicodes + tounicode = remapping.tounicode end end - tfm.set_features(tfmdata) -end - -function tfm.set_features(tfmdata) - -- todo: no local functions - local shared = tfmdata.shared --- local tfmdata = shared.tfmdata - local features = shared.features - if features and next(features) then - local mode = tfmdata.mode or fonts.mode - local fi = fonts.initializers[mode] - if fi and fi.tfm then - local function initialize(list) -- using tex lig and kerning - if list then - for i=1,#list do - local f = list[i] - local value = features[f] - if value and fi.tfm[f] then -- brr - if tfm.trace_features then - logs.report("define font","initializing feature %s to %s for mode %s for font %s",f,tostring(value),mode or 'unknown',tfmdata.name or 'unknown') - end - fi.tfm[f](tfmdata,value) - mode = tfmdata.mode or fonts.mode - fi = fonts.initializers[mode] - end - end - end + if newcoding then + local characters = tfmdata.characters + local descriptions = tfmdata.descriptions + local oldcoding = tfmdata.resources.unicodes + local tounicodes = tfmdata.resources.tounicode -- index to unicode + local originals = { } + for name, newcode in next, newcoding do + local oldcode = oldcoding[name] + if characters[newcode] and not originals[newcode] then + originals[newcode] = { + character = characters [newcode], + description = descriptions[newcode], + } end - initialize(fonts.triggers) - initialize(tfm.features.list) - initialize(fonts.manipulators) - end - local fm = fonts.methods[mode] - if fm and fm.tfm then - local function register(list) -- node manipulations - if list then - for i=1,#list do - local f = list[i] - if features[f] and fm.tfm[f] then -- brr - if not shared.processors then -- maybe also predefine - shared.processors = { fm.tfm[f] } - else - shared.processors[#shared.processors+1] = fm.tfm[f] - end - end - end - end + local original = originals[oldcode] + if original then + characters [newcode] = original.character + descriptions[newcode] = original.description + else + characters [newcode] = characters [oldcode] + descriptions[newcode] = descriptions[oldcode] end - register(tfm.features.list) - end - end -end - -function tfm.features.register(name,default) - tfm.features.list[#tfm.features.list+1] = name - tfm.features.default[name] = default -end - -function tfm.reencode(tfmdata,encoding) - if encoding and fonts.enc.known[encoding] then - local data = fonts.enc.load(encoding) - if data then - local characters, original, vector = tfmdata.characters, { }, data.vector - tfmdata.encoding = encoding -- not needed - for k, v in next, characters do - v.name, v.index, original[k] = vector[k], k, v - end - for k,v in next, data.unicodes do - if k ~= v then - if trace_defining then - logs.report("define font","reencoding U+%04X to U+%04X",k,v) - end - characters[k] = original[v] + if tounicode then + local index = descriptions[newcode].index + if not tounicodes[index] then + tounicodes[index] = tosixteen(newcode) -- shared (we could have a metatable) end end - end - end -end - -tfm.features.register('reencode') - -fonts.initializers.base.tfm.reencode = tfm.reencode -fonts.initializers.node.tfm.reencode = tfm.reencode - -fonts.enc = fonts.enc or { } -fonts.enc.remappings = fonts.enc.remappings or { } - -function tfm.remap(tfmdata,remapping) - local vector = remapping and fonts.enc.remappings[remapping] - if vector then - local characters, original = tfmdata.characters, { } - for k, v in next, characters do - original[k], characters[k] = v, nil - end - for k,v in next, vector do - if k ~= v then - if trace_defining then - logs.report("define font","remapping U+%04X to U+%04X",k,v) - end - local c = original[k] - characters[v] = c - c.index = k + if trace_defining then + report_defining("aliasing glyph '%s' from U+%05X to U+%05X",name,oldcode,newcode) end end - tfmdata.encodingbytes = 2 - tfmdata.format = 'type1' end end -tfm.features.register('remap') - -fonts.initializers.base.tfm.remap = tfm.remap -fonts.initializers.node.tfm.remap = tfm.remap +registerafmfeature { + name = "unicoding", + description = "adapt unicode table", + initializers = { + base = initializeunicoding, + node = initializeunicoding, + } +} ---~ obsolete ---~ ---~ function tfm.enhance(tfmdata,specification) ---~ local name, size = specification.name, specification.size ---~ local encoding, filename = match(name,"^(.-)%-(.*)$") -- context: encoding-name.* ---~ if filename and encoding and fonts.enc.known[encoding] then ---~ local data = fonts.enc.load(encoding) ---~ if data then ---~ local characters = tfmdata.characters ---~ tfmdata.encoding = encoding ---~ local vector = data.vector ---~ local original = { } ---~ for k, v in next, characters do ---~ v.name = vector[k] ---~ v.index = k ---~ original[k] = v ---~ end ---~ for k,v in next, data.unicodes do ---~ if k ~= v then ---~ if trace_defining then ---~ logs.report("define font","mapping %s onto %s",k,v) ---~ end ---~ characters[k] = original[v] ---~ end ---~ end ---~ end ---~ end ---~ end +registerotffeature { + name = "unicoding", + description = "adapt unicode table", + initializers = { + base = initializeunicoding, + node = initializeunicoding, + } +} |