diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/font-ext.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/font-ext.lua | 194 |
1 files changed, 171 insertions, 23 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/font-ext.lua b/Master/texmf-dist/tex/context/base/mkiv/font-ext.lua index f9db5e0d9c0..d873dccd4d3 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/font-ext.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/font-ext.lua @@ -30,9 +30,10 @@ of neutral.</p> local handlers = fonts.handlers local hashes = fonts.hashes local otf = handlers.otf +local afm = handlers.afm -local registerotffeature = handlers.otf.features.register -local registerafmfeature = handlers.afm.features.register +local registerotffeature = otf.features.register +local registerafmfeature = afm.features.register local fontdata = hashes.identifiers local fontproperties = hashes.properties @@ -181,7 +182,7 @@ fonts.goodies.register("expansions", function(...) return fonts.goodies.report( implement { name = "setupfontexpansion", - arguments = { "string", "string" }, + arguments = "2 strings", actions = function(class,settings) getparameters(classes,class,'preset',settings) end } @@ -492,7 +493,7 @@ fonts.goodies.register("protrusions", function(...) return fonts.goodies.report( implement { name = "setupfontprotrusion", - arguments = { "string", "string" }, + arguments = "2 strings", actions = function(class,settings) getparameters(classes,class,'preset',settings) end } @@ -671,15 +672,15 @@ local function manipulatedimensions(tfmdata,key,value) local width = newwidth or oldwidth or 0 local height = newheight or oldheight or 0 local depth = newdepth or olddepth or 0 - if oldwidth ~= width then - -- Defining the tables in one step is more efficient - -- than adding fields later. + if oldwidth ~= width or oldheight ~= height or olddepth ~= depth then local private = getprivate(tfmdata) + local newslot = { "slot", 1, private } -- { "slot", 0, private } local new_c - local commands = { + local commands = oldwidth ~= width and { { "right", (width - oldwidth) / 2 }, - { "slot", 1, private }, - -- { "slot", 0, private }, + newslot, + } or { + newslot, } if height > 0 then if depth > 0 then @@ -718,19 +719,19 @@ local function manipulatedimensions(tfmdata,key,value) for k, v in next, additions do characters[k] = v end - elseif height > 0 and depth > 0 then - for unicode, old_c in next, characters do - old_c.height = height - old_c.depth = depth - end - elseif height > 0 then - for unicode, old_c in next, characters do - old_c.height = height - end - elseif depth > 0 then - for unicode, old_c in next, characters do - old_c.depth = depth - end + -- elseif height > 0 and depth > 0 then + -- for unicode, old_c in next, characters do + -- old_c.height = height + -- old_c.depth = depth + -- end + -- elseif height > 0 then + -- for unicode, old_c in next, characters do + -- old_c.height = height + -- end + -- elseif depth > 0 then + -- for unicode, old_c in next, characters do + -- old_c.depth = depth + -- end end end end @@ -1706,3 +1707,150 @@ do } end + +-- maybe useful + +local function initializeoutline(tfmdata,value) + value = tonumber(value) + if not value then + value = 0 + else + value = tonumber(value) or 0 + end + if value then + value = value * 1000 + end + tfmdata.parameters.mode = 1 + tfmdata.parameters.width = value +end + +local outline_specification = { + name = "outline", + description = "outline glyphs", + initializers = { + base = initializeoutline, + node = initializeoutline, + } +} + +registerotffeature(outline_specification) +registerafmfeature(outline_specification) + +-- definitely ugly + +local report_effect = logs.reporter("fonts","effect") +local trace_effect = false + +trackers.register("fonts.effect", function(v) trace_effect = v end) + +local effects = { + inner = 0, + normal = 0, + outer = 1, + outline = 1, + both = 2, + hidden = 3, +} + +local function initializeeffect(tfmdata,value) + local spec + if type(value) == "number" then + spec = { width = value } + else + spec = settings_to_hash(value) + end + local effect = spec.effect or "both" + local width = tonumber(spec.width) or 0 + local mode = effects[effect] + if not mode then + report_effect("invalid effect %a",effect) + elseif width == 0 and mode == 0 then + report_effect("invalid width %a for effect %a",width,effect) + else + local parameters = tfmdata.parameters + local properties = tfmdata.properties + parameters.mode = mode + parameters.width = width * 1000 + local factor = tonumber(spec.factor) or 0 + local hfactor = tonumber(spec.vfactor) or factor + local vfactor = tonumber(spec.hfactor) or factor + local delta = tonumber(spec.delta) or 1 + local wdelta = tonumber(spec.wdelta) or delta + local hdelta = tonumber(spec.hdelta) or delta + local ddelta = tonumber(spec.ddelta) or hdelta + properties.effect = { + effect = effect, + width = width, + factor = factor, + hfactor = hfactor, + vfactor = vfactor, + wdelta = wdelta, + hdelta = hdelta, + ddelta = ddelta, + } + end +end + +local function manipulateeffect(tfmdata) + local effect = tfmdata.properties.effect + if effect then + local characters = tfmdata.characters + local parameters = tfmdata.parameters + local multiplier = effect.width * 100 + local wdelta = effect.wdelta * parameters.hfactor * multiplier + local hdelta = effect.hdelta * parameters.vfactor * multiplier + local ddelta = effect.ddelta * parameters.vfactor * multiplier + local hshift = wdelta / 2 + local factor = (1 + effect.factor) * parameters.factor + local hfactor = (1 + effect.hfactor) * parameters.hfactor + local vfactor = (1 + effect.vfactor) * parameters.vfactor + for unicode, old_c in next, characters do + local oldwidth = old_c.width + local oldheight = old_c.height + local olddepth = old_c.depth + if oldwidth and oldwidth > 0 then + old_c.width = oldwidth + wdelta + old_c.commands = { + { "right", hshift }, + { "char", unicode }, + } + end + if oldheight and oldheight > 0 then + old_c.height = oldheight + hdelta + end + if olddepth and olddepth > 0 then + old_c.depth = olddepth + ddelta + end + end + parameters.factor = factor + parameters.hfactor = hfactor + parameters.vfactor = vfactor + if trace_effect then + report_effect("applying effect") + report_effect(" effect : %s", effect.effect) + report_effect(" width : %s => %s", effect.width, multiplier) + report_effect(" factor : %s => %s", effect.factor, factor ) + report_effect(" hfactor : %s => %s", effect.hfactor,hfactor) + report_effect(" vfactor : %s => %s", effect.vfactor,vfactor) + report_effect(" wdelta : %s => %s", effect.wdelta, wdelta) + report_effect(" hdelta : %s => %s", effect.hdelta, hdelta) + report_effect(" ddelta : %s => %s", effect.ddelta, ddelta) + end + end +end + +local effect_specification = { + name = "effect", + description = "apply effects to glyphs", + initializers = { + base = initializeeffect, + node = initializeeffect, + }, + manipulators = { + base = manipulateeffect, + node = manipulateeffect, + }, +} + +registerotffeature(effect_specification) +registerafmfeature(effect_specification) |