meta-imp-placeholders.mkxl /size: 2651 b    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=meta-imp-placeholders,
3%D        version=2021.02.01,
4%D          title=\METAPOST\ Graphics,
5%D       subtitle=Missing Glyph Placeholders,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D This is a drop in for the already existing placeholder function. It could be made
15%D more clever by hashing similar shapes but as this is mostly a diagnostic feature
16%D we go a quick an ddirty two dimensional array.
17
18%D It is now mostly a file one can run to get an idea what the replace macro triggers
19%D so I've added it to the distribution.
20
21% \startMPcalculation{simplefun}
22%     loadfile("mp-miss.mpxl") ;
23% \stopMPcalculation
24%
25% \startluacode
26%
27% local chardata = characters.data
28% local fontdata = fonts.hashes.identifiers
29% local mapping  = fonts.checkers.mapping
30%
31% function fonts.checkers.placeholder(font,char)
32%     local category = chardata[char].category or "lu" -- todo: unknown
33%     local fakedata = mapping[category]
34%     local tfmdata  = fontdata[font]
35%     local units    = tfmdata.parameters.units or 1000
36%     local slant    = (tfmdata.parameters.slant or 0)/65536
37%     local scale    = units/1000
38%     local rawdata  = tfmdata.shared and tfmdata.shared.rawdata
39%     local weight   = (rawdata and rawdata.metadata and rawdata.metadata.pfmweight or 400)/400
40%     local specification = {
41%         code      = "MissingGlyph",
42%         scale     = scale,
43%         slant     = slant,
44%         weight    = weight,
45%         namespace = font,
46%         shapes    = { { shape = fakedata[1], color = fakedata[2] } },
47%     }
48%     fonts.helpers.setmetaglyphs("missing", font, char, specification)
49% end
50%
51% \stopluacode
52
53%D We enable the checker:
54
55% \enabletrackers[fonts.missing=replace]
56
57\replacemissingcharacters
58
59\continueifinputfile{meta-imp-placeholders.mkxl}
60
61% \enableexperiments[fonts.compact]
62
63% \showglyphs
64
65\startbuffer
66    \startlines[before=,after=]
67        \strut {\tf test \char 12345\ test \char 12346\ test}
68        \strut {\bf test \char 12345\ test \char 12346\ test}
69        \strut {\it test \char 12345\ test \char 12346\ test}
70        \strut {\bi test \char 12345\ test \char 12346\ test}
71        \strut {test  ρ φ α ν  ο ς test}
72    \stoplines
73\stopbuffer
74
75\starttext
76    \startTEXpage[offset=2pt,strut=no]
77        \getbuffer
78        \switchtobodyfont[pagella]
79        \getbuffer
80        \switchtobodyfont[dejavu]
81        \getbuffer
82    \stopTEXpage
83\stoptext
84