diff options
author | Marius <mariausol@gmail.com> | 2011-03-25 19:20:25 +0200 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2011-03-25 19:20:25 +0200 |
commit | 1455dd60b68c9140db1b9977c9e5ce372b772ec8 (patch) | |
tree | d2b7060a4d9891966a056dcf143ef20d43390561 /tex/context/base/font-enh.lua | |
parent | 2a9554684f61df8db63dec6d4e874f49b25a212b (diff) | |
download | context-1455dd60b68c9140db1b9977c9e5ce372b772ec8.tar.gz |
beta 2011.03.25 18:03
Diffstat (limited to 'tex/context/base/font-enh.lua')
-rw-r--r-- | tex/context/base/font-enh.lua | 235 |
1 files changed, 50 insertions, 185 deletions
diff --git a/tex/context/base/font-enh.lua b/tex/context/base/font-enh.lua index 34cdd9264..3e3535f87 100644 --- a/tex/context/base/font-enh.lua +++ b/tex/context/base/font-enh.lua @@ -6,172 +6,56 @@ if not modules then modules = { } end modules ['font-enh'] = { license = "see context related readme files" } --- todo: optimize a bit +local next = next -local next, match = next, string.match +local trace_defining = false trackers.register("fonts.defining", function(v) trace_defining = v end) +local report_defining = logs.reporter("fonts","defining") -local trace_defining = false trackers.register("fonts.defining", function(v) trace_defining = v end) +local fonts = fonts +local constructors = fonts.constructors -local report_defining = logs.reporter("fonts","defining") +local tfmfeatures = constructors.newfeatures("tfm") +local registertfmfeature = tfmfeatures.register --- 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 +local fontencodings = fonts.encodings +fontencodings.remappings = fontencodings.remappings or { } ---[[ldx-- -<p>Here we only implement a few helper functions.</p> ---ldx]]-- - -local fonts = fonts -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 - --- tfm features, experimental - -tfm.features = tfm.features or { } -tfm.features.list = tfm.features.list or { } -tfm.features.default = tfm.features.default or { } - -local initializers = fonts.initializers -local triggers = fonts.triggers -local manipulators = fonts.manipulators -local featurelist = tfm.features.list -local defaultfeaturelist = tfm.features.default - -table.insert(manipulators,"compose") - -function initializers.common.compose(tfmdata,value) - if value then - fonts.vf.aux.compose_characters(tfmdata) - end -end - -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 - end - end - tfm.setfeatures(tfmdata) -end - -function tfm.setfeatures(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 features.mode or "base" - local fi = initializers[mode] - if fi and fi.tfm then - local function initialize(list) -- using tex lig and kerning - if list then - -- fi adapts ! - for i=1,#list do - local f = list[i] - local value = features[f] - if value then - local fitfmf = fi.tfm[f] -- brr - if fitfmf then - if tfm.trace_features then - report_defining("initializing feature %s to %s for mode %s for font %s",f,tostring(value),mode or 'unknown',tfmdata.name or 'unknown') - end - fitfmf(tfmdata,value) - mode = tfmdata.mode or features.mode or "base" - fi = initializers[mode] - end - end - end - end - end - initialize(triggers) - initialize(featurelist) - initialize(manipulators) - end - local fm = fonts.methods[mode] - if fm then - local fmtfm = fm.tfm - if fmtfm then - local function register(list) -- node manipulations - if list then - local sp = shared.processors - local ns = sp and #sp - for i=1,#list do - local f = list[i] - if features[f] then - local fmtfmf = fmtfm[f] - if not fmtfmf then - -- brr - elseif not sp then - sp = { fmtfmf } - ns = 1 - shared.processors = sp - else - ns = ns + 1 - sp[ns] = fmtfmf - end - end - end - end - end - register(featurelist) - end - end - end -end - -function tfm.features.register(name,default) - featurelist[#tfm.features.list+1] = name - defaultfeaturelist[name] = default -end - -function tfm.reencode(tfmdata,encoding) - if encoding and fonts.enc.known[encoding] then - local data = fonts.enc.load(encoding) +local function reencode(tfmdata,encoding) + if encoding and fontencodings.known[encoding] then + local data = fontencodings.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 + 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 k,v in next, data.unicodes do - if k ~= v then + for newcode, oldcode in next, data.unicodes do + if newcode ~= oldcode then if trace_defining then - report_defining("reencoding U+%04X to U+%04X",k,v) + report_defining("reencoding U+%04X to U+%04X",newcode,oldcode) end - characters[k] = original[v] + characters[newcode] = original[oldcode] end end end end end -tfm.features.register('reencode') - -initializers.base.tfm.reencode = tfm.reencode -initializers.node.tfm.reencode = tfm.reencode - -fonts.enc = fonts.enc or { } -fonts.enc.remappings = fonts.enc.remappings or { } +registertfmfeature { + name = "reencode", + description = "reencode", + manipulators = { + base = reencode, + node = reencode, + } +} -function tfm.remap(tfmdata,remapping) - local vector = remapping and fonts.enc.remappings[remapping] +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 @@ -187,41 +71,22 @@ function tfm.remap(tfmdata,remapping) c.index = k end end - tfmdata.encodingbytes = 2 - tfmdata.format = tfmdata.format or 'type1' + 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 -tfm.features.register('remap') - -initializers.base.tfm.remap = tfm.remap -initializers.node.tfm.remap = tfm.remap - ---~ 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 ---~ report_defining("mapping %s onto %s",k,v) ---~ end ---~ characters[k] = original[v] ---~ end ---~ end ---~ end ---~ end ---~ end +registertfmfeature { + name = "remap", + description = "remap", + manipulators = { + base = remap, + node = remap, + } +} |