diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luaotfload/otfl-font-tfm.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luaotfload/otfl-font-tfm.lua | 411 |
1 files changed, 135 insertions, 276 deletions
diff --git a/Master/texmf-dist/tex/luatex/luaotfload/otfl-font-tfm.lua b/Master/texmf-dist/tex/luatex/luaotfload/otfl-font-tfm.lua index efea9def3f9..4b217a3c407 100644 --- a/Master/texmf-dist/tex/luatex/luaotfload/otfl-font-tfm.lua +++ b/Master/texmf-dist/tex/luatex/luaotfload/otfl-font-tfm.lua @@ -36,6 +36,7 @@ fonts.initializers = fonts.initializers or { } fonts.initializers.common = fonts.initializers.common or { } local fontdata = fonts.ids +local disc = node.id('disc') local glyph = node.id('glyph') local set_attribute = node.set_attribute @@ -47,33 +48,9 @@ supplied by <l n='luatex'/>.</p> tfm.resolve_vf = true -- false tfm.share_base_kerns = false -- true (.5 sec slower on mk but brings down mem from 410M to 310M, beware: then script/lang share too) tfm.mathactions = { } +tfm.fontname_mode = "fullpath" -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 +tfm.enhance = tfm.enhance or function() end function tfm.read_from_tfm(specification) local fname, tfmdata = specification.filename or "", nil @@ -186,36 +163,36 @@ fonts.trace_scaling = false -- basekerns are scaled and will be hashed by table id -- sharedkerns are unscaled and are be hashed by concatenated indexes -function tfm.check_base_kerns(tfmdata) - if tfm.share_base_kerns then - local sharedkerns = tfmdata.sharedkerns - if sharedkerns then - local basekerns = { } - tfmdata.basekerns = basekerns - return sharedkerns, basekerns - end - end - return nil, nil -end +--~ function tfm.check_base_kerns(tfmdata) +--~ if tfm.share_base_kerns then +--~ local sharedkerns = tfmdata.sharedkerns +--~ if sharedkerns then +--~ local basekerns = { } +--~ tfmdata.basekerns = basekerns +--~ return sharedkerns, basekerns +--~ end +--~ end +--~ return nil, nil +--~ end -function tfm.prepare_base_kerns(tfmdata) - if tfm.share_base_kerns and not tfmdata.sharedkerns then - local sharedkerns = { } - tfmdata.sharedkerns = sharedkerns - for u, chr in next, tfmdata.characters do - local kerns = chr.kerns - if kerns then - local hash = concat(sortedkeys(kerns), " ") - local base = sharedkerns[hash] - if not base then - sharedkerns[hash] = kerns - else - chr.kerns = base - end - end - end - end -end +--~ function tfm.prepare_base_kerns(tfmdata) +--~ if tfm.share_base_kerns and not tfmdata.sharedkerns then +--~ local sharedkerns = { } +--~ tfmdata.sharedkerns = sharedkerns +--~ for u, chr in next, tfmdata.characters do +--~ local kerns = chr.kerns +--~ if kerns then +--~ local hash = concat(sortedkeys(kerns), " ") +--~ local base = sharedkerns[hash] +--~ if not base then +--~ sharedkerns[hash] = kerns +--~ else +--~ chr.kerns = base +--~ end +--~ end +--~ end +--~ end +--~ end -- we can have cache scaled characters when we are in node mode and don't have -- protruding and expansion: hash == fullname @ size @ protruding @ expansion @@ -228,13 +205,21 @@ local charactercache = { } -- a virtual font has italic correction make sure to set the -- has_italic flag. Some more flags will be added in the future. -function tfm.do_scale(tfmtable, scaledpoints) - tfm.prepare_base_kerns(tfmtable) -- optimalization +function tfm.calculate_scale(tfmtable, scaledpoints, relativeid) if scaledpoints < 0 then scaledpoints = (- scaledpoints/1000) * tfmtable.designsize -- already in sp end - local delta = scaledpoints/(tfmtable.units or 1000) -- brr, some open type fonts have 2048 - local t = { } + local units = tfmtable.units or 1000 + local delta = scaledpoints/units -- brr, some open type fonts have 2048 + return scaledpoints, delta, units +end + +function tfm.do_scale(tfmtable, scaledpoints, relativeid) + -- tfm.prepare_base_kerns(tfmtable) -- optimalization + local t = { } -- the new table + local scaledpoints, delta, units = tfm.calculate_scale(tfmtable, scaledpoints, relativeid) + t.units_per_em = units or 1000 + local hdelta, vdelta = delta, delta -- unicoded unique descriptions shared cidinfo characters changed parameters indices for k,v in next, tfmtable do if type(v) == "table" then @@ -243,6 +228,19 @@ function tfm.do_scale(tfmtable, scaledpoints) t[k] = v end end + local extend_factor = tfmtable.extend_factor or 0 + if extend_factor ~= 0 and extend_factor ~= 1 then + hdelta = hdelta * extend_factor + t.extend = extend_factor * 1000 + else + t.extend = 1000 + end + local slant_factor = tfmtable.slant_factor or 0 + if slant_factor ~= 0 then + t.slant = slant_factor * 1000 + else + t.slant = 0 + end -- status local isvirtual = tfmtable.type == "virtual" or tfmtable.virtualized local hasmath = (tfmtable.math_parameters ~= nil and next(tfmtable.math_parameters) ~= nil) or (tfmtable.MathConstants ~= nil and next(tfmtable.MathConstants) ~= nil) @@ -270,12 +268,12 @@ t.colorscheme = tfmtable.colorscheme local tfmp = tfmtable.parameters -- let's check for indexes -- tp.slant = (tfmp.slant or tfmp[1] or 0) - tp.space = (tfmp.space or tfmp[2] or 0)*delta - tp.space_stretch = (tfmp.space_stretch or tfmp[3] or 0)*delta - tp.space_shrink = (tfmp.space_shrink or tfmp[4] or 0)*delta - tp.x_height = (tfmp.x_height or tfmp[5] or 0)*delta - tp.quad = (tfmp.quad or tfmp[6] or 0)*delta - tp.extra_space = (tfmp.extra_space or tfmp[7] or 0)*delta + tp.space = (tfmp.space or tfmp[2] or 0)*hdelta + tp.space_stretch = (tfmp.space_stretch or tfmp[3] or 0)*hdelta + tp.space_shrink = (tfmp.space_shrink or tfmp[4] or 0)*hdelta + tp.x_height = (tfmp.x_height or tfmp[5] or 0)*vdelta + tp.quad = (tfmp.quad or tfmp[6] or 0)*hdelta + tp.extra_space = (tfmp.extra_space or tfmp[7] or 0)*hdelta local protrusionfactor = (tp.quad ~= 0 and 1000/tp.quad) or 0 local tc = t.characters local characters = tfmtable.characters @@ -289,14 +287,15 @@ t.colorscheme = tfmtable.colorscheme local defaultheight = luatex and luatex.defaultheight or 0 local defaultdepth = luatex and luatex.defaultdepth or 0 -- experimental, sharing kerns (unscaled and scaled) saves memory - local sharedkerns, basekerns = tfm.check_base_kerns(tfmtable) + -- local sharedkerns, basekerns = tfm.check_base_kerns(tfmtable) -- loop over descriptions (afm and otf have descriptions, tfm not) -- there is no need (yet) to assign a value to chr.tonunicode - local scaledwidth = defaultwidth * delta - local scaledheight = defaultheight * delta - local scaleddepth = defaultdepth * delta + local scaledwidth = defaultwidth * hdelta + local scaledheight = defaultheight * vdelta + local scaleddepth = defaultdepth * vdelta local stackmath = tfmtable.ignore_stack_math ~= true -local private = fonts.private + local private = fonts.private + local sharedkerns = { } for k,v in next, characters do local chr, description, index if ischanged then @@ -317,9 +316,9 @@ local private = fonts.private local width = description.width local height = description.height local depth = description.depth - if width then width = delta*width else width = scaledwidth end - if height then height = delta*height else height = scaledheight end - -- if depth then depth = delta*depth else depth = scaleddepth end + if width then width = hdelta*width else width = scaledwidth end + if height then height = vdelta*height else height = scaledheight end + -- if depth then depth = vdelta*depth else depth = scaleddepth end if depth and depth ~= 0 then depth = delta*depth if nameneeded then @@ -383,7 +382,7 @@ local private = fonts.private if hasitalic then local vi = description.italic or v.italic if vi and vi ~= 0 then - chr.italic = vi*delta + chr.italic = vi*hdelta end end -- to be tested @@ -399,19 +398,19 @@ local private = fonts.private for i=1,#vv do local vvi = vv[i] t[i] = { - ["start"] = (vvi["start"] or 0)*delta, - ["end"] = (vvi["end"] or 0)*delta, - ["advance"] = (vvi["advance"] or 0)*delta, + ["start"] = (vvi["start"] or 0)*vdelta, + ["end"] = (vvi["end"] or 0)*vdelta, + ["advance"] = (vvi["advance"] or 0)*vdelta, ["extender"] = vvi["extender"], ["glyph"] = vvi["glyph"], } end chr.vert_variants = t ---~ local ic = v.vert_italic_correction ---~ if ic then ---~ chr.italic = ic * delta ---~ print(format("0x%05X -> %s",k,chr.italic)) ---~ end + --~ local ic = v.vert_italic_correction + --~ if ic then + --~ chr.italic = ic * hdelta + --~ print(format("0x%05X -> %s",k,chr.italic)) + --~ end else local hv = v.horiz_variants if hv then @@ -419,9 +418,9 @@ local private = fonts.private for i=1,#hv do local hvi = hv[i] t[i] = { - ["start"] = (hvi["start"] or 0)*delta, - ["end"] = (hvi["end"] or 0)*delta, - ["advance"] = (hvi["advance"] or 0)*delta, + ["start"] = (hvi["start"] or 0)*hdelta, + ["end"] = (hvi["end"] or 0)*hdelta, + ["advance"] = (hvi["advance"] or 0)*hdelta, ["extender"] = hvi["extender"], ["glyph"] = hvi["glyph"], } @@ -432,31 +431,23 @@ local private = fonts.private end local vt = description.top_accent if vt then - chr.top_accent = delta*vt + chr.top_accent = vdelta*vt end if stackmath then local mk = v.mathkerns if mk then local kerns = { } - -- for k, v in next, mk do - -- local kk = { } - -- for i=1,#v do - -- local vi = v[i] - -- kk[i] = { height = delta*vi.height, kern = delta*vi.kern } - -- end - -- kerns[k] = kk - -- end local v = mk.top_right if v then local k = { } for i=1,#v do local vi = v[i] - k[i] = { height = delta*vi.height, kern = delta*vi.kern } + k[i] = { height = vdelta*vi.height, kern = vdelta*vi.kern } end kerns.top_right = k end local v = mk.top_left if v then local k = { } for i=1,#v do local vi = v[i] - k[i] = { height = delta*vi.height, kern = delta*vi.kern } + k[i] = { height = vdelta*vi.height, kern = vdelta*vi.kern } end kerns.top_left = k end local v = mk.bottom_left if v then local k = { } for i=1,#v do local vi = v[i] - k[i] = { height = delta*vi.height, kern = delta*vi.kern } + k[i] = { height = vdelta*vi.height, kern = vdelta*vi.kern } end kerns.bottom_left = k end local v = mk.bottom_right if v then local k = { } for i=1,#v do local vi = v[i] - k[i] = { height = delta*vi.height, kern = delta*vi.kern } + k[i] = { height = vdelta*vi.height, kern = vdelta*vi.kern } end kerns.bottom_right = k end chr.mathkern = kerns -- singular end @@ -465,19 +456,26 @@ local private = fonts.private if not nodemode then local vk = v.kerns if vk then - if sharedkerns then - local base = basekerns[vk] -- hashed by table id, not content - if not base then - base = {} - for k,v in next, vk do base[k] = v*delta end - basekerns[vk] = base - end - chr.kerns = base - else - local tt = {} - for k,v in next, vk do tt[k] = v*delta end - chr.kerns = tt + --~ if sharedkerns then + --~ local base = basekerns[vk] -- hashed by table id, not content + --~ if not base then + --~ base = {} + --~ for k,v in next, vk do base[k] = v*hdelta end + --~ basekerns[vk] = base + --~ end + --~ chr.kerns = base + --~ else + --~ local tt = {} + --~ for k,v in next, vk do tt[k] = v*hdelta end + --~ chr.kerns = tt + --~ end + local s = sharedkerns[vk] + if not s then + s = { } + for k,v in next, vk do s[k] = v*hdelta end + sharedkerns[vk] = s end + chr.kerns = s end local vl = v.ligatures if vl then @@ -496,6 +494,8 @@ local private = fonts.private local vc = v.commands if vc then -- we assume non scaled commands here + -- tricky .. we need to scale pseudo math glyphs too + -- which is why we deal with rules too local ok = false for i=1,#vc do local key = vc[i][1] @@ -509,8 +509,12 @@ local private = fonts.private for i=1,#vc do local ivc = vc[i] local key = ivc[1] - if key == "right" or key == "down" then - tt[#tt+1] = { key, ivc[2]*delta } + if key == "right" then + tt[#tt+1] = { key, ivc[2]*hdelta } + elseif key == "down" then + tt[#tt+1] = { key, ivc[2]*vdelta } + elseif key == "rule" then + tt[#tt+1] = { key, ivc[2]*vdelta, ivc[3]*hdelta } else -- not comment tt[#tt+1] = ivc -- shared since in cache and untouched end @@ -522,13 +526,12 @@ local private = fonts.private end end tc[k] = chr ---~ if k == 0x222B then ---~ print(t.fontname,table.serialize(chr)) ---~ end end -- t.encodingbytes, t.filename, t.fullname, t.name: elsewhere t.size = scaledpoints t.factor = delta + t.hfactor = hdelta + t.vfactor = vdelta if t.fonts then t.fonts = table.fastcopy(t.fonts) -- maybe we virtualize more afterwards end @@ -536,7 +539,7 @@ local private = fonts.private -- mathematics.extras.copy(t) -- can be done elsewhere if needed local ma = tfm.mathactions for i=1,#ma do - ma[i](t,tfmtable,delta) + ma[i](t,tfmtable,delta,hdelta,vdelta) -- what delta? end end -- needed for \high cum suis @@ -593,21 +596,19 @@ local lastfont = nil -- -- flushing the kern and ligature tables from memory saves a lot (only -- base mode) but it complicates vf building where the new characters --- demand this data - ---~ for id, f in pairs(fonts.ids) do -- or font.fonts ---~ local ffi = font.fonts[id] ---~ f.characters = ffi.characters ---~ f.kerns = ffi.kerns ---~ f.ligatures = ffi.ligatures ---~ end +-- demand this data .. solution: functions that access them function tfm.cleanup_table(tfmdata) -- we need a cleanup callback, now we miss the last one if tfm.auto_cleanup then -- ok, we can hook this into everyshipout or so ... todo if tfmdata.type == 'virtual' or tfmdata.virtualized then for k, v in next, tfmdata.characters do - if v.commands then v.commands = nil end + if v.commands then v.commands = nil end + -- if v.kerns then v.kerns = nil end end + else + -- for k, v in next, tfmdata.characters do + -- if v.kerns then v.kerns = nil end + -- end end end end @@ -615,8 +616,8 @@ end function tfm.cleanup(tfmdata) -- we need a cleanup callback, now we miss the last one end -function tfm.scale(tfmtable, scaledpoints) - local t, factor = tfm.do_scale(tfmtable, scaledpoints) +function tfm.scale(tfmtable, scaledpoints, relativeid) + local t, factor = tfm.do_scale(tfmtable, scaledpoints, relativeid) t.factor = factor t.ascender = factor*(tfmtable.ascender or 0) t.descender = factor*(tfmtable.descender or 0) @@ -650,7 +651,8 @@ function fonts.analyzers.aux.setstate(head,font) local descriptions = tfmdata.descriptions local first, last, current, n, done = nil, nil, head, 0, false -- maybe make n boolean while current do - if current.id == glyph and current.font == font then + local id = current.id + if id == glyph and current.font == font then local d = descriptions[current.char] if d then if d.class == "mark" then @@ -671,6 +673,10 @@ function fonts.analyzers.aux.setstate(head,font) end first, last, n = nil, nil, 0 end + elseif id == disc then + -- always in the middle + set_attribute(current,state,2) -- midi + last = current else -- finish if first and first == last then set_attribute(last,state,4) -- isol @@ -698,155 +704,8 @@ function tfm.replacements(tfm,value) -- tfm.characters[0x0060] = tfm.characters[0x2018] end --- auto complete font with missing composed characters - -table.insert(fonts.manipulators,"compose") - -function fonts.initializers.common.compose(tfmdata,value) - if value then - fonts.vf.aux.compose_characters(tfmdata) - end -end - --- tfm features, experimental - -tfm.features = tfm.features or { } -tfm.features.list = tfm.features.list or { } -tfm.features.default = tfm.features.default or { } - -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.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 not table.is_empty(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 - 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 - 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] - 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 - 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 - -- status info statistics.register("fonts load time", function() - if statistics.elapsedindeed(fonts) then - return format("%s seconds",statistics.elapsedtime(fonts)) - end + return statistics.elapsedseconds(fonts) end) |