summaryrefslogtreecommitdiff
path: root/tex/context/base/font-chk.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/font-chk.lua')
-rw-r--r--tex/context/base/font-chk.lua171
1 files changed, 118 insertions, 53 deletions
diff --git a/tex/context/base/font-chk.lua b/tex/context/base/font-chk.lua
index 6dc1667bb..41205ce5e 100644
--- a/tex/context/base/font-chk.lua
+++ b/tex/context/base/font-chk.lua
@@ -9,12 +9,16 @@ if not modules then modules = { } end modules ['font-chk'] = {
-- possible optimization: delayed initialization of vectors
-- move to the nodes namespace
+local next = next
+
local formatters = string.formatters
local bpfactor = number.dimenfactors.bp
local fastcopy = table.fastcopy
local report_fonts = logs.reporter("fonts","checking")
+local allocate = utilities.storage.allocate
+
local fonts = fonts
fonts.checkers = fonts.checkers or { }
@@ -32,6 +36,8 @@ local getprivatenode = helpers.getprivatenode
local otffeatures = fonts.constructors.newfeatures("otf")
local registerotffeature = otffeatures.register
+local afmfeatures = fonts.constructors.newfeatures("afm")
+local registerafmfeature = afmfeatures.register
local is_character = characters.is_character
local chardata = characters.data
@@ -40,10 +46,21 @@ local tasks = nodes.tasks
local enableaction = tasks.enableaction
local disableaction = tasks.disableaction
+local implement = interfaces.implement
+
local glyph_code = nodes.nodecodes.glyph
-local traverse_id = node.traverse_id
-local remove_node = nodes.remove
-local insert_node_after = node.insert_after
+
+local nuts = nodes.nuts
+local tonut = nuts.tonut
+local tonode = nuts.tonode
+
+local getfont = nuts.getfont
+local getchar = nuts.getchar
+local setfield = nuts.setfield
+
+local traverse_id = nuts.traverse_id
+local remove_node = nuts.remove
+local insert_node_after = nuts.insert_after
-- maybe in fonts namespace
-- deletion can be option
@@ -75,7 +92,7 @@ end
fonts.loggers.onetimemessage = onetimemessage
-local mapping = { -- this is just an experiment to illustrate some principles elsewhere
+local mapping = allocate { -- this is just an experiment to illustrate some principles elsewhere
lu = "placeholder uppercase red",
ll = "placeholder lowercase red",
lt = "placeholder uppercase red",
@@ -100,9 +117,15 @@ local mapping = { -- this is just an experiment to illustrate some principles el
so = "placeholder lowercase yellow",
}
-table.setmetatableindex(mapping,function(t,k) v = "placeholder unknown gray" t[k] = v return v end)
+table.setmetatableindex(mapping,
+ function(t,k)
+ v = "placeholder unknown gray"
+ t[k] = v
+ return v
+ end
+)
-local fakes = {
+local fakes = allocate {
{
name = "lowercase",
code = ".025 -.175 m .425 -.175 l .425 .525 l .025 .525 l .025 -.175 l .025 0 l .425 0 l .025 -.175 m h S",
@@ -140,7 +163,7 @@ local fakes = {
},
}
-local variants = {
+local variants = allocate {
{ tag = "gray", r = .6, g = .6, b = .6 },
{ tag = "red", r = .6, g = 0, b = 0 },
{ tag = "green", r = 0, g = .6, b = 0 },
@@ -150,7 +173,7 @@ local variants = {
{ tag = "yellow", r = .6, g = .6, b = 0 },
}
-local pdf_blob = "pdf: q %0.6f 0 0 %0.6f 0 0 cm %s %s %s rg %s %s %s RG 10 M 1 j 1 J 0.05 w %s Q"
+local pdf_blob = "pdf: q %0.6F 0 0 %0.6F 0 0 cm %s %s %s rg %s %s %s RG 10 M 1 j 1 J 0.05 w %s Q"
local cache = { } -- saves some tables but not that impressive
@@ -203,11 +226,34 @@ function commands.getplaceholderchar(name)
context(helpers.getprivatenode(fontdata[id],name))
end
+local function placeholder(font,char)
+ local tfmdata = fontdata[font]
+ local properties = tfmdata.properties
+ local privates = properties.privates
+ local category = chardata[char].category
+ local fakechar = mapping[category]
+ local p = privates and privates[fakechar]
+ if not p then
+ addmissingsymbols(tfmdata)
+ p = properties.privates[fakechar]
+ end
+ if properties.lateprivates then
+ -- frozen already
+ return "node", getprivatenode(tfmdata,fakechar)
+ else
+ -- good, we have \definefontfeature[default][default][missing=yes]
+ return "char", p
+ end
+end
+
+checkers.placeholder = placeholder
+
function checkers.missing(head)
local lastfont, characters, found = nil, nil, nil
+ head = tonut(head)
for n in traverse_id(glyph_code,head) do -- faster than while loop so we delay removal
- local font = n.font
- local char = n.char
+ local font = getfont(n)
+ local char = getchar(n)
if font ~= lastfont then
characters = fontcharacters[font]
lastfont = font
@@ -235,42 +281,34 @@ function checkers.missing(head)
end
elseif action == "replace" then
for i=1,#found do
- local n = found[i]
- local font = n.font
- local char = n.char
- local tfmdata = fontdata[font]
- local properties = tfmdata.properties
- local privates = properties.privates
- local category = chardata[char].category
- local fakechar = mapping[category]
- local p = privates and privates[fakechar]
- if not p then
- addmissingsymbols(tfmdata)
- p = properties.privates[fakechar]
- end
- if properties.lateprivates then -- .frozen
- -- bad, we don't have them at the tex end
- local fake = getprivatenode(tfmdata,fakechar)
- insert_node_after(head,n,fake)
- head = remove_node(head,n,true)
+ local node = found[i]
+ local kind, char = placeholder(getfont(node),getchar(node))
+ if kind == "node" then
+ insert_node_after(head,node,tonut(char))
+ head = remove_node(head,node,true)
+ elseif kind == "char" then
+ setfield(node,"char",char)
else
- -- good, we have \definefontfeature[default][default][missing=yes]
- n.char = p
+ -- error
end
end
else
-- maye write a report to the log
end
- return head, false
+ return tonode(head), false
end
-local relevant = { "missing (will be deleted)", "missing (will be flagged)", "missing" }
+local relevant = {
+ "missing (will be deleted)",
+ "missing (will be flagged)",
+ "missing"
+}
-function checkers.getmissing(id)
+local function getmissing(id)
if id then
- local list = checkers.getmissing(font.current())
+ local list = getmissing(font.current())
if list then
- local _, list = next(checkers.getmissing(font.current()))
+ local _, list = next(getmissing(font.current()))
return list
else
return { }
@@ -300,6 +338,8 @@ function checkers.getmissing(id)
end
end
+checkers.getmissing = getmissing
+
local tracked = false
trackers.register("fonts.missing", function(v)
@@ -315,24 +355,6 @@ trackers.register("fonts.missing", function(v)
action = v
end)
-function commands.checkcharactersinfont()
- enableaction("processors","fonts.checkers.missing")
- tracked = true
-end
-
-function commands.removemissingcharacters()
- enableaction("processors","fonts.checkers.missing")
- action = "remove"
- tracked = true
-end
-
-function commands.replacemissingcharacters()
- enableaction("processors","fonts.checkers.missing")
- action = "replace"
- otffeatures.defaults.missing = true
- tracked = true
-end
-
local report_characters = logs.reporter("fonts","characters")
local report_character = logs.reporter("missing")
@@ -393,3 +415,46 @@ local function expandglyph(characters,index,done)
end
helpers.expandglyph = expandglyph
+
+-- should not be needed as we add .notdef in the engine
+
+local dummyzero = {
+ -- width = 0,
+ -- height = 0,
+ -- depth = 0,
+ commands = { { "special", "" } },
+}
+
+local function adddummysymbols(tfmdata,...)
+ local characters = tfmdata.characters
+ if not characters[0] then
+ characters[0] = dummyzero
+ end
+ -- if not characters[1] then
+ -- characters[1] = dummyzero -- test only
+ -- end
+end
+
+registerotffeature {
+ name = "dummies",
+ description = "dummy symbols",
+ default = true,
+ manipulators = {
+ base = adddummysymbols,
+ node = adddummysymbols,
+ }
+}
+
+registerafmfeature {
+ name = "dummies",
+ description = "dummy symbols",
+ default = true,
+ manipulators = {
+ base = adddummysymbols,
+ node = adddummysymbols,
+ }
+}
+
+-- callback.register("char_exists",function(f,c) -- to slow anyway as called often so we should flag in tfmdata
+-- return true
+-- end)