summaryrefslogtreecommitdiff
path: root/tex/context/base/font-con.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/font-con.lua')
-rw-r--r--tex/context/base/font-con.lua153
1 files changed, 52 insertions, 101 deletions
diff --git a/tex/context/base/font-con.lua b/tex/context/base/font-con.lua
index 434f64215..7e823c6e2 100644
--- a/tex/context/base/font-con.lua
+++ b/tex/context/base/font-con.lua
@@ -39,7 +39,6 @@ local contextnumbers = specifiers.contextnumbers
-- will be directives
-constructors.sharebasekerns = false -- true (.5 sec slower on mk but brings down mem from 410M to 310M, beware: then script/lang share too)
constructors.dontembed = allocate()
constructors.mathactions = { }
constructors.autocleanup = true
@@ -97,47 +96,6 @@ in the process; numbers are of course copies. Here 65536 equals 1pt. (Due to
excessive memory usage in CJK fonts, we no longer pass the boundingbox.)</p>
--ldx]]--
--- the following hack costs a bit of runtime but safes memory
---
--- basekerns are scaled and will be hashed by table id
--- sharedkerns are unscaled and are be hashed by concatenated indexes
-
---~ function constructors.check_base_kerns(tfmdata)
---~ if constructors.sharebasekerns then
---~ local sharedkerns = tfmdata.sharedkerns
---~ if sharedkerns then
---~ local basekerns = { }
---~ tfmdata.basekerns = basekerns
---~ return sharedkerns, basekerns
---~ end
---~ end
---~ return nil, nil
---~ end
-
---~ function constructors.prepare_base_kerns(tfmdata)
---~ if constructors.sharebasekerns 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 cache scaled characters when we are in node mode and don't have
--- protruding and expansion: hash == fullname @ size @ protruding @ expansion
--- but in practice (except from mk) the otf hash will be enough already so it
--- makes no sense to mess up the code now
-
-- The scaler is only used for otf and afm and virtual fonts. If
-- a virtual font has italic correction make sure to set the
-- italic_correction flag. Some more flags will be added in
@@ -186,6 +144,34 @@ function constructors.calculatescale(tfmdata,scaledpoints)
return scaledpoints, scaledpoints / (parameters.units or 1000) -- delta
end
+function constructors.assignmathparameters(target,tfmdata)
+ -- when a tfm file is loaded, it has already been scaled
+ -- and it never enters the scaled so this is otf only
+ local mathparameters = original.mathparameters
+ if mathparameters and next(mathparameters) then
+ local targetparameters = target.parameters
+ local targetmathparameters = { }
+ local factor = targetparameters.factor
+ for name, value in next, mathparameters do
+ if name == "RadicalDegreeBottomRaisePercent" then
+ targetmathparameters[name] = value
+ else
+ targetmathparameters[name] = value * factor
+ end
+ end
+ if not targetmathparameters.AccentBaseHeight then
+ targetmathparameters.AccentBaseHeight = nil -- safeguard, still needed?
+ end
+ if not targetmathparameters.FractionDelimiterSize then
+ targetmathparameters.FractionDelimiterSize = 0
+ end
+ if not mathparameters.FractionDelimiterDisplayStyleSize then
+ targetmathparameters.FractionDelimiterDisplayStyleSize = 0
+ end
+ target.mathparameters = targetmathparameters
+ end
+end
+
function constructors.scale(tfmdata,specification)
local target = { } -- the new table
--
@@ -205,23 +191,22 @@ function constructors.scale(tfmdata,specification)
local shared = tfmdata.shared or { }
local parameters = tfmdata.parameters or { }
local mathparameters = tfmdata.mathparameters or { }
- local MathConstants = tfmdata.mathconstants or { }
--
local targetcharacters = { }
local targetdescriptions = table.derive(descriptions)
local targetparameters = table.derive(parameters)
- local targetmathparameters = table.derive(mathparameters)
+ -- local targetmathparameters = table.fastcopy(mathparameters) -- happens elsewhere
local targetproperties = table.derive(properties)
- local targetgoodies = table.derive(goodies)
+ local targetgoodies = goodies -- we need to loop so no metatable
target.characters = targetcharacters
target.descriptions = targetdescriptions
target.parameters = targetparameters
- target.mathparameters = targetmathparameters
+ -- target.mathparameters = targetmathparameters -- happens elsewhere
target.properties = targetproperties
target.goodies = targetgoodies
target.shared = shared
target.resources = resources
- target.unscaled = tfmdata -- the original unscaled one (temp)
+ target.unscaled = tfmdata -- the original unscaled one
--
-- specification.mathsize : 1=text 2=script 3=scriptscript
-- specification.textsize : natural (text)size
@@ -331,9 +316,9 @@ function constructors.scale(tfmdata,specification)
target.slant = 0
end
--
+ targetparameters.factor = delta
targetparameters.hfactor = hdelta
targetparameters.vfactor = vdelta
- targetparameters.factor = delta
targetparameters.size = scaledpoints
targetparameters.units = units
targetparameters.scaledpoints = askedscaledpoints
@@ -350,18 +335,6 @@ function constructors.scale(tfmdata,specification)
end
--
target.type = isvirtual and "virtual" or "real"
- -- more extensive test
- local hasmath = (properties.math or next(mathparameters) or next(MathConstants)) and true
- if hasmath then
- properties.has_math = true
- target.nomath = false
- target.MathConstants = MathConstants
- target.mathconstants = MathConstants
- else
- properties.has_math = false
- target.nomath = true
- target.mathparameters = nil -- nop
- end
-- this will move to some subtable so that it is copied at once
target.postprocessors = tfmdata.postprocessors
--
@@ -389,45 +362,37 @@ function constructors.scale(tfmdata,specification)
if descender then
targetparameters.descender = delta * descender
end
+ -- copies, might disappear
+ targetparameters.xheight = targetparameters.xheight or parameters.x_height
+ targetparameters.extraspace = targetparameters.extraspace or parameters.extra_space
+ targetparameters.spacestretch = targetparameters.spacestretch or parameters.space_stretch
+ targetparameters.spaceshrink = targetparameters.spaceshrink or parameters.space_shrink
+ --
+ local protrusionfactor = (targetquad ~= 0 and 1000/targetquad) or 0
+ local scaledwidth = defaultwidth * hdelta
+ local scaledheight = defaultheight * vdelta
+ local scaleddepth = defaultdepth * vdelta
--
+ local hasmath = (properties.has_math or next(mathparameters)) and true
if hasmath then
- local ma = constructors.mathactions
- local ta = type(ma)
- if ta == "function" then -- context
- ma(target,tfmdata)
- elseif ta == "table" then -- generic (we keep the deltas)
- for i=1,#ma do
- ma[i](target,tfmdata,delta,hdelta,vdelta)
- end
- end
- if not targetparameters[13] then targetparameters[13] = .86*targetx_height end -- mathsupdisplay
- if not targetparameters[14] then targetparameters[14] = .86*targetx_height end -- mathsupnormal
- if not targetparameters[15] then targetparameters[15] = .86*targetx_height end -- mathsupcramped
- if not targetparameters[16] then targetparameters[16] = .48*targetx_height end -- mathsubnormal
- if not targetparameters[17] then targetparameters[17] = .48*targetx_height end -- mathsubcombined
- if not targetparameters[22] then targetparameters[22] = 0 end -- mathaxisheight
- if target.MathConstants then target.MathConstants.AccentBaseHeight = nil end -- safeguard
if trace_defining then
report_defining("math enabled for: name '%s', fullname: '%s', filename: '%s'",
name or "noname",fullname or "nofullname",filename or "nofilename")
end
+ constructors.assignmathparameters(target,tfmdata) -- does scaling and whatever is needed
+ properties.has_math = true
+ target.nomath = false
+ target.MathConstants = target.mathparameters
else
if trace_defining then
report_defining("math disabled for: name '%s', fullname: '%s', filename: '%s'",
name or "noname",fullname or "nofullname",filename or "nofilename")
end
+ properties.has_math = false
+ target.nomath = true
+ target.mathparameters = nil -- nop
end
--
- targetparameters.xheight = targetparameters.xheight or parameters.x_height
- targetparameters.extraspace = targetparameters.extraspace or parameters.extra_space
- targetparameters.spacestretch = targetparameters.spacestretch or parameters.space_stretch
- targetparameters.spaceshrink = targetparameters.spaceshrink or parameters.space_shrink
- --
- local protrusionfactor = (targetquad ~= 0 and 1000/targetquad) or 0
- local scaledwidth = defaultwidth * hdelta
- local scaledheight = defaultheight * vdelta
- local scaleddepth = defaultdepth * vdelta
- --
local sharedkerns = { }
--
for unicode, character in next, characters do
@@ -526,7 +491,7 @@ function constructors.scale(tfmdata,specification)
if vn then
chr.next = vn
-- if character.vert_variants or character.horiz_variants then
- -- report_defining("glyph 0x%05X has combination of next, vert_variants and horiz_variants",index)
+ -- report_defining("glyph U+%05X has combination of next, vert_variants and horiz_variants",index)
-- end
else
local vv = character.vert_variants
@@ -588,19 +553,6 @@ function constructors.scale(tfmdata,specification)
if not nodemode then
local vk = character.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*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 = { }
@@ -757,7 +709,6 @@ function constructors.finalize(tfmdata)
--
-- tfmdata.fonts
-- tfmdata.unscaled
- -- tfmdata.mathconstants
--
if not properties.has_math then
properties.has_math = not tfmdata.nomath