summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkxl/font-ctx.lmt
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkxl/font-ctx.lmt')
-rw-r--r--Master/texmf-dist/tex/context/base/mkxl/font-ctx.lmt270
1 files changed, 129 insertions, 141 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkxl/font-ctx.lmt b/Master/texmf-dist/tex/context/base/mkxl/font-ctx.lmt
index b735e3d2f91..23c676e4ee5 100644
--- a/Master/texmf-dist/tex/context/base/mkxl/font-ctx.lmt
+++ b/Master/texmf-dist/tex/context/base/mkxl/font-ctx.lmt
@@ -90,6 +90,7 @@ local setsubtype = nuts.setsubtype
local texgetdimen = tex.getdimen
local texsetcount = tex.setcount
+local texiscount = tex.iscount
local texget = tex.get
local texdefinefont = tex.definefont
@@ -156,7 +157,8 @@ or
-- this will move elsewhere ...
local function getfontname(tfmdata)
- return basename(type(tfmdata) == "number" and properties[tfmdata].name or tfmdata.properties.name)
+ local p = type(tfmdata) == "number" and properties[tfmdata] or tfmdata.properties
+ return basename((p and (p.name or p.fullname or p.fontname)) or "unknown")
end
helpers.name = getfontname
@@ -185,6 +187,12 @@ constructors.noffontsloaded = 0
-- font.getcopy = font.getfont -- we always want the table that context uses
+local accuratefactors = false
+----- compactfontmode = false
+
+experiments.register("fonts.accurate", function(v) accuratefactors = v end)
+experiments.register("fonts.compact", function() accuratefactors = true end)
+
do
-- Does this still make sense?
@@ -302,14 +310,14 @@ function definers.resetnullfont()
-- resetting is needed because tikz misuses nullfont
local parameters = fonts.nulldata.parameters
--
- parameters.slant = 0 -- 1
- parameters.space = 0 -- 2
- parameters.space_stretch = 0 -- 3
- parameters.space_shrink = 0 -- 4
- parameters.x_height = 0 -- 5
- parameters.quad = 0 -- 6
- parameters.extra_space = 0 -- 7
- parameters.designsize = 655360
+ parameters.slant = 0 -- 1
+ parameters.space = 0 -- 2
+ parameters.spacestretch = 0 -- 3
+ parameters.spaceshrink = 0 -- 4
+ parameters.xheight = 0 -- 5
+ parameters.quad = 0 -- 6
+ parameters.extraspace = 0 -- 7
+ parameters.designsize = 655360
--
constructors.enhanceparameters(parameters) -- official copies for us
--
@@ -503,6 +511,22 @@ do
end
end
+ local beforepassingfonttotex = sequencers.new {
+ name = "beforepassingfonttotex",
+ arguments = "tfmdata",
+ }
+
+ appendgroup(beforepassingfonttotex,"before") -- user
+ appendgroup(beforepassingfonttotex,"system") -- private
+ appendgroup(beforepassingfonttotex,"after" ) -- user
+
+ function constructors.beforepassingfonttotex(tfmdata)
+ local runner = beforepassingfonttotex.runner
+ if runner then
+ runner(tfmdata)
+ end
+ end
+
end
--[[ldx--
@@ -1051,23 +1075,30 @@ local sizepattern, splitpattern, specialscale do
local withinparents = leftparent * (1-rightparent)^0 * rightparent
local withinbraces = leftbrace * (1-rightbrace )^0 * rightbrace
local value = C((withinparents + withinbraces + (1-space))^1)
- -- local dimension = C((space/"" + P(1))^1)
- local dimension = Cs((digit+period)^1 * (spaces/"") * (P(1)-digit)^0)
--- local scaler = C((digit+period)^1)
+ local dimension = Cs((digit+period)^1 * (spaces/"") * (P(1)-digit-space)^0)
+ -- local dimension_x = C((space/"" + P(1))^1)
+ local dimension_x = C((1-space)^1)
+ -- local scaler = C((digit+period)^1)
local scaler = lpeg.patterns.unsigned/function(s) return round(tonumber(s)*1000) end
+ C(lpeg.patterns.cardinal)
local rest = C(P(1)^0)
local scale_none = Cc(0)
- local scale_at = (P("at") + P("@")) * Cc(1) * spaces * dimension -- dimension
- local scale_sa = P("sa") * Cc(2) * spaces * dimension -- number
- local scale_mo = P("mo") * Cc(3) * spaces * dimension -- number
- local scale_scaled = P("scaled") * Cc(4) * spaces * dimension -- number
- local scale_ht = P("ht") * Cc(5) * spaces * dimension -- dimension
- local scale_cp = P("cp") * Cc(6) * spaces * dimension -- dimension
+ local scale_at = (P("at") + P("@")) * Cc(1) * spaces * dimension -- dimension
+ local scale_sa = P("sa") * Cc(2) * spaces * dimension_x -- number or string
+ local scale_mo = P("mo") * Cc(3) * spaces * dimension_x -- number or string
+ local scale_scaled = P("scaled") * Cc(4) * spaces * dimension -- number
+ local scale_ht = P("ht") * Cc(5) * spaces * dimension -- dimension
+ local scale_cp = P("cp") * Cc(6) * spaces * dimension -- dimension
+ local scale_sx = P("sx") * spaces * scaler -- scale
+ local scale_sy = P("sy") * spaces * scaler -- scale
specialscale = { [5] = "ht", [6] = "cp" }
- sizepattern = spaces * ((scale_at + scale_sa + scale_mo + scale_ht + scale_cp + scale_scaled) * (spaces * scaler)^0 + scale_none)
+ -- sizepattern = spaces * ((scale_at + scale_sa + scale_mo + scale_ht + scale_cp + scale_scaled) * (spaces * scaler)^0 + scale_none)
+
+ scaler = spaces * ( (scale_sx + Cc(0)) * spaces * (scale_sy + Cc(0)) )^-1
+ sizepattern = spaces * ((scale_at + scale_sa + scale_mo + scale_ht + scale_cp + scale_scaled) * scaler + scale_none)
+
splitpattern = spaces * value * spaces * rest
end
@@ -1095,12 +1126,16 @@ local specifiers = { }
do -- else too many locals
- local starttiming = statistics.starttiming
- local stoptiming = statistics.stoptiming
+ local starttiming = statistics.starttiming
+ local stoptiming = statistics.stoptiming
+
+ local setmacro = tokens.setters.macro
+ local ctxcatcodes = tex.ctxcatcodes
+ local texconditionals = tex.conditionals
- local setmacro = tokens.setters.macro
- local ctxcatcodes = tex.ctxcatcodes
- local texconditionals = tex.conditionals
+ local c_scaledfontmode = texiscount("scaledfontmode")
+ local c_scaledfontsize = texiscount("scaledfontsize")
+ local c_lastfontid = texiscount("lastfontid")
local reported = setmetatableindex(function(t,k)
local v = setmetatableindex(function(t,k)
@@ -1111,6 +1146,12 @@ do -- else too many locals
return v
end)
+ local obey_designsize = false
+
+ experiments.register("fonts.compact.obeydesignsize",function(v)
+ obey_designsize = v
+ end)
+
implement {
name = "definefont_one",
arguments = "string",
@@ -1133,13 +1174,14 @@ do -- else too many locals
end
-- we can also use a count for the size
if size and size ~= "" then
- local mode, size, sx, sy = lpegmatch(sizepattern,size)
- if mode and size and size ~= "" then
- texsetcount("scaledfontmode",mode)
- -- ctx_setsomefontsize(size)
+ local mode, fontsize, sx, sy = lpegmatch(sizepattern,size)
+-- print(size,mode,fontsize,sx,sy)
+ if mode and fontsize and fontsize ~= "" then
+ texsetcount(c_scaledfontmode,mode)
+ -- ctx_setsomefontsize(fontsize)
-- We use a catcodetable, just in case it's 1.2\exheight (a corner case that showed
-- up in the lmtx manual: marking that changed size in the mids of some verbatim).
- setmacro(ctxcatcodes,"somefontsize",size)
+ setmacro(ctxcatcodes,"somefontsize",fontsize)
if sx then
setmacro("somefontsizex",sx)
end
@@ -1147,15 +1189,15 @@ do -- else too many locals
setmacro("somefontsizey",sy)
end
else
- texsetcount("scaledfontmode",0)
+ texsetcount(c_scaledfontmode,0)
-- ctx_setemptyfontsize()
end
elseif true then
-- so we don't need to check in tex
- texsetcount("scaledfontmode",2)
+ texsetcount(c_scaledfontmode,2)
-- ctx_setemptyfontsize()
else
- texsetcount("scaledfontmode",0)
+ texsetcount(c_scaledfontmode,0)
-- ctx_setemptyfontsize()
end
specification = definers.makespecification(str,lookup,name,sub,method,detail,size)
@@ -1190,23 +1232,23 @@ do -- else too many locals
"integer",
},
actions = function (
- global, -- \ifx\fontclass\empty\s!false\else\s!true\fi
- cs, -- {#csname}%
- str, -- \somefontfile
- size, -- \d_font_scaled_font_size
- inheritancemode, -- \c_font_feature_inheritance_mode
- classfeatures, -- \m_font_class_features
- fontfeatures, -- \m_font_features
- classfallbacks, -- \m_font_class_fallbacks
- fontfallbacks, -- \m_font_fallbacks
- mathsize, -- \fontface
- textsize, -- \d_font_scaled_text_face
- classgoodies, -- \m_font_class_goodies
- goodies, -- \m_font_goodies
- classdesignsize, -- \m_font_class_designsize
- fontdesignsize, -- \m_font_designsize
- scaledfontmode -- \scaledfontmode
- )
+ global, -- \ifx\fontclass\empty\s!false\else\s!true\fi
+ cs, -- {#csname}%
+ str, -- \somefontfile
+ size, -- \d_font_scaled_font_size
+ inheritancemode, -- \c_font_feature_inheritance_mode
+ classfeatures, -- \m_font_class_features
+ fontfeatures, -- \m_font_features
+ classfallbacks, -- \m_font_class_fallbacks
+ fontfallbacks, -- \m_font_fallbacks
+ mathsize, -- \fontface
+ textsize, -- \d_font_scaled_text_face
+ classgoodies, -- \m_font_class_goodies
+ goodies, -- \m_font_goodies
+ classdesignsize, -- \m_font_class_designsize
+ fontdesignsize, -- \m_font_designsize
+ scaledfontmode -- \scaledfontmode
+ )
if trace_defining then
report_defining("start stage two: %s, size %s, features %a & %a, mode %a",str,size,classfeatures,fontfeatures,inheritancemode)
end
@@ -1214,7 +1256,7 @@ do -- else too many locals
local lookup, name, sub, method, detail = getspecification(str or "")
-- new (todo: inheritancemode)
local designsize = fontdesignsize ~= "" and fontdesignsize or classdesignsize or ""
- local designname = designsizefilename(name,designsize,size)
+ local designname = designsizefilename(name,designsize,size,obey_designsize)
if designname and designname ~= "" then
if trace_defining or trace_designsize then
report_defining("remapping name %a, specification %a, size %a, designsize %a",name,designsize,size,designname)
@@ -1343,98 +1385,36 @@ do -- else too many locals
local properties = tfmdata.properties
-- we use char0 as signal; cf the spec pdf can handle this (no char in slot)
characters[0] = nil
- -- characters[0x00A0] = { width = parameters.space }
- -- characters[0x2007] = { width = characters[0x0030] and characters[0x0030].width or parameters.space } -- figure
- -- characters[0x2008] = { width = characters[0x002E] and characters[0x002E].width or parameters.space } -- period
- --
- local fallbacks = specification.fallbacks or ""
- local mathsize = (mathsize == 1 or mathsize == 2 or mathsize == 3) and mathsize or nil -- can be unset so we test 1 2 3
- if fallbacks ~= "" and mathsize and not busy then
- busy = true
- -- We need this ugly hack in order to resolve fontnames (at the \TEX end). Originally
- -- math was done in Lua after loading (plugged into aftercopying).
- --
- -- After tl 2017 I'll also do text fallbacks this way (although backups there are done
- -- in a completely different way.)
- if trace_defining then
- report_defining("defining %a, id %a, target %a, features %a / %a, fallbacks %a / %a, step %a",
- name,id,nice_cs(cs),classfeatures,fontfeatures,classfallbacks,fontfallbacks,1)
- end
- mathematics.resolvefallbacks(tfmdata,specification,fallbacks)
- context(function()
- -- We're doing math fallbacks.
- busy = false
- mathematics.finishfallbacks(tfmdata,specification,fallbacks)
- tfmdata.original = specification.specification
- local id = definefont(tfmdata,properties.id)
- csnames[id] = specification.cs
- properties.id = id -- already set
- definers.register(tfmdata,id) -- to be sure, normally already done
- texdefinefont(global,cs,id)
- -- texdefinefont(cs,id,global and "global")
- constructors.finalize(tfmdata)
- if trace_defining then
- report_defining("defining %a, id %a, target %a, features %a / %a, fallbacks %a / %a, step %a",
- name,id,nice_cs(cs),classfeatures,fontfeatures,classfallbacks,fontfallbacks,2)
- end
- -- resolved (when designsize is used):
- local size = round(tfmdata.parameters.size or 655360)
- setmacro("somefontsize",size.."sp")
- -- ctx_setsomefontsize(size .. "sp")
- texsetcount("scaledfontsize",size)
- lastfontid = id
- --
- if trace_defining then
- report_defining("memory usage after: %s",statistics.memused())
- report_defining("stop stage two")
- end
- --
- texsetcount("global","lastfontid",lastfontid)
- specifiers[lastfontid] = { str, size }
- if not mathsize then
- -- forget about it (can't happen here)
- elseif mathsize == 0 then
- -- can't happen (here)
- else
- -- maybe only 1 2 3 (we already test for this)
- lastmathids[mathsize] = lastfontid
- end
- stoptiming(fonts)
- end)
- return
- else
- tfmdata.original = specification.specification
- local id = definefont(tfmdata,properties.id)
- csnames[id] = specification.cs
- properties.id = id -- already set
- definers.register(tfmdata,id) -- to be sure, normally already done
- texdefinefont(global,cs,id)
- -- texdefinefont(cs,id,global and "global")
- constructors.finalize(tfmdata)
- if trace_defining then
- report_defining("defining %a, id %a, target %a, features %a / %a, fallbacks %a / %a, step %a",
- name,id,nice_cs(cs),classfeatures,fontfeatures,classfallbacks,fontfallbacks,"-")
- end
- -- resolved (when designsize is used):
- local size = round(tfmdata.parameters.size or 655360)
- setmacro("somefontsize",size.."sp")
- -- ctx_setsomefontsize(size .. "sp")
- texsetcount("scaledfontsize",size)
- lastfontid = id
+ tfmdata.original = specification.specification
+ local id = definefont(tfmdata,properties.id)
+ csnames[id] = specification.cs
+ properties.id = id -- already set
+ definers.register(tfmdata,id) -- to be sure, normally already done
+ texdefinefont(global,cs,id)
+ -- texdefinefont(cs,id,global and "global")
+ constructors.finalize(tfmdata)
+ if trace_defining then
+ report_defining("defining %a, id %a, target %a, features %a / %a, fallbacks %a / %a, step %a",
+ name,id,nice_cs(cs),classfeatures,fontfeatures,classfallbacks,fontfallbacks,"-")
end
+ -- resolved (when designsize is used):
+ local size = round(tfmdata.parameters.size or 655360)
+ setmacro("somefontsize",size.."sp")
+ texsetcount(c_scaledfontsize,size)
+ lastfontid = id
elseif tfmtype == "number" then
if trace_defining then
report_defining("reusing %s, id %a, target %a, features %a / %a, fallbacks %a / %a, goodies %a / %a, designsize %a / %a",
name,tfmdata,nice_cs(cs),classfeatures,fontfeatures,classfallbacks,fontfallbacks,classgoodies,goodies,classdesignsize,fontdesignsize)
end
csnames[tfmdata] = specification.cs
+-- \definedfont ends up here
texdefinefont(global,cs,tfmdata)
-- texdefinefont(cs,tfmdata,global and "global")
-- resolved (when designsize is used):
local size = round(fontdata[tfmdata].parameters.size or 0)
- -- ctx_setsomefontsize(size .. "sp")
setmacro("somefontsize",size.."sp")
- texsetcount("scaledfontsize",size)
+ texsetcount(c_scaledfontsize,size)
lastfontid = tfmdata
else
local nice = nice_cs(cs)
@@ -1442,7 +1422,7 @@ do -- else too many locals
report_defining("unable to define %a as %a",name,nice)
end
lastfontid = -1
- texsetcount("scaledfontsize",0)
+ texsetcount(c_scaledfontsize,0)
-- ctx_letvaluerelax(cs) -- otherwise the current definition takes the previous one
end
if trace_defining then
@@ -1450,7 +1430,7 @@ do -- else too many locals
report_defining("stop stage two")
end
--
- texsetcount("global","lastfontid",lastfontid)
+ texsetcount("global",c_lastfontid,lastfontid)
specifiers[lastfontid] = { str, size }
if not mathsize then
-- forget about it
@@ -1574,6 +1554,8 @@ do -- else too many locals
local n = 0
+ local d_bodyfontsize = tex.isdimen("bodyfontsize")
+
function definers.internal(specification,cs)
specification = specification or { }
local name = specification.name
@@ -1581,7 +1563,7 @@ do -- else too many locals
local number = tonumber(specification.number)
local id = nil
if not size then
- size = texgetdimen("bodyfontsize")
+ size = texgetdimen(d_bodyfontsize)
end
if number then
id = number
@@ -1623,7 +1605,7 @@ do -- else too many locals
return infofont
end
- -- abstract interfacing
+ -- abstract interfacing : we could actually do a runmacro or so
implement { name = "tf", actions = function() setmacro("fontalternative","tf") end }
implement { name = "bf", actions = function() setmacro("fontalternative","bf") end }
@@ -1638,6 +1620,8 @@ end
-- have delayed definitions and so we never know what style is taken
-- as start.
+local c_font_scaled_points = texiscount("c_font_scaled_points")
+
function constructors.calculatescale(tfmdata,scaledpoints,relativeid,specification)
local parameters = tfmdata.parameters
local units = parameters.units or 1000
@@ -1657,9 +1641,12 @@ function constructors.calculatescale(tfmdata,scaledpoints,relativeid,specificati
scaledpoints = (- scaledpoints/1000) * (tfmdata.designsize or parameters.designsize) -- already in sp
end
-- a temp hack till we have upgraded all mechanisms
- local delta = round(scaledpoints/units)
+ local delta = scaledpoints/units
local size = round(scaledpoints)
- texsetcount("c_font_scaled_points",size)
+ if not accuratefactors then
+ delta = round(delta)
+ end
+ texsetcount(c_font_scaled_points,size)
--
return size, delta
end
@@ -1684,16 +1671,17 @@ function constructors.hashinstance(specification,force)
end
specification.size = size
if fallbacks then
- return hash .. ' @ ' .. size .. ' @ ' .. fallbacks
+ hash = hash .. ' @ ' .. size .. ' @ ' .. fallbacks
else
local scalemode = specification.scalemode
local special = scalemode and specialscale[scalemode]
if special then
- return hash .. ' @ ' .. size .. ' @ ' .. special
+ hash = hash .. ' @ ' .. size .. ' @ ' .. special
else
- return hash .. ' @ ' .. size
+ hash = hash .. ' @ ' .. size
end
end
+ return hash
end
-- We overload the (generic) resolver:
@@ -2378,7 +2366,7 @@ do
end
implement {
- name = "nbfs",
+ name = "normalizedbodyfontsize",
arguments = "dimen",
actions = function(d)
context(lpegmatch(stripper,f_strip(d/65536)))
@@ -3032,7 +3020,7 @@ end
do
- local getfontoffamily = font.getfontoffamily
+ local getfontoffamily = tex.getfontoffamily
local new_glyph = nodes.pool.glyph
local fontproperties = fonts.hashes.properties