s-fonts-charts.mkiv /size: 7256 b    last modification: 2023-12-21 09:45
1%D \module
2%D   [      file=s-fonts-charts,
3%D        version=2015.08.08,
4%D          title=\CONTEXT\ Style File,
5%D       subtitle=Show Fonts Charts,
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% begin info
15%
16% title   : show unicode blocks
17%
18% comment : show charts of a given font
19%
20% end info
21
22\startmodule[fonts-charts]
23
24% \registerctxluafile{s-fonts-charts}{}
25\starttexdefinition unexpanded FontChartSetSlot #1#2
26    \dontleavehmode
27    \setbox\scratchbox\vbox to 1cm \bgroup
28        \vss
29        \hbox to 1cm \bgroup
30            \infofont \hss\raise.25mm\hbox{#2}\hss
31        \egroup
32    \egroup
33    \wd\scratchbox0mm
34    \ht\scratchbox5mm
35    \dp\scratchbox5mm
36    \box\scratchbox
37    \setbox\scratchbox\ruledhbox to 1cm \bgroup
38        \hss\char#1\hss
39    \egroup
40    \ht\scratchbox5mm
41    \dp\scratchbox5mm
42    \box\scratchbox
43\stoptexdefinition
44
45\starttexdefinition unexpanded FontChartNoSlot
46    \dontleavehmode
47    \setbox\scratchbox\hbox to 1cm \bgroup
48        % empty
49    \egroup
50    \ht\scratchbox5mm
51    \dp\scratchbox5mm
52    \box\scratchbox
53\stoptexdefinition
54
55\starttexdefinition unexpanded FontChartSetLegend #1
56    \dontleavehmode
57%     \kern .5mm
58    \setbox\scratchbox\hbox to 1cm \bgroup
59        \infofont\hss#1\hss
60    \egroup
61    \ht\scratchbox5mm
62    \dp\scratchbox5mm
63    \box\scratchbox
64\stoptexdefinition
65
66\starttexdefinition unexpanded FontChartSetCaption #1#2
67    \dontleavehmode
68    \setbox\scratchbox\hbox to 16cm \bgroup
69        \infofontbold\hskip1cm#1: #2\hss
70    \egroup
71    \ht\scratchbox7.5mm
72    \dp\scratchbox2.5mm
73    \box\scratchbox
74\stoptexdefinition
75
76\starttexdefinition unexpanded FontChartGap
77    \kern .5mm
78\stoptexdefinition
79
80\startluacode
81    local div, mod = math.div, math.mod
82    local formatters = string.formatters
83
84    moduledata.fonts        = moduledata.fonts        or { }
85    moduledata.fonts.charts = moduledata.fonts.charts or { }
86
87    function moduledata.fonts.charts.show(settings)
88
89        local settings = utilities.parsers.settings_to_hash(settings)
90
91        local filename = settings.filename or settings.name or ""
92        local fontid   = true
93        local newpage  = settings.page   == interfaces.variables.yes
94        local all      = settings.option == interfaces.variables.all
95
96        if filename ~= "" then
97            fontid = fonts.definers.internal({ name = filename, size = "10pt" },"chartfont")
98        end
99
100        local ranges   = { }
101        local data     = fonts.hashes.identifiers[fontid]
102        local private  = fonts.constructors.privateoffset
103        local chars    = data.characters
104
105        for u in table.sortedhash(chars) do
106            if not all and u >= private then
107                break
108            else
109                ranges[div(u,0xFF)] = true
110            end
111        end
112
113        local ctx_setlegend  = context.FontChartSetLegend
114        local ctx_noslot     = context.FontChartNoSlot
115        local ctx_setslot    = context.FontChartSetSlot
116        local ctx_setcaption = context.FontChartSetCaption
117        local ctx_par        = context.par
118        local ctx_gap        = context.FontChartGap
119
120        for r in table.sortedhash(ranges) do
121            if newpage then
122                context.page()
123            end
124            context.startframed { offset = "overlay", frame = "off", align = "normal" }
125                if filename ~= "" then
126                    context.chartfont()
127                end
128                context.dontcomplain()
129                context.offinterlineskip()
130                ctx_noslot()
131                for i=0,0xF do
132                    ctx_gap()
133                    ctx_setlegend(formatters["%03X"](r*0x10+i))
134                end
135                r = r * 0xFF
136                ctx_par()
137                for i=0,0xF do
138                    ctx_setlegend(formatters["%0X"](i))
139                    ctx_gap()
140                    for j=0,0xF do
141                        local u = r + i*0x10 + j
142                        local d = chars[u]
143                        if d then
144                            ctx_setslot(u,formatters["%04X"](u))
145                        else
146                            ctx_noslot()
147                        end
148                        if j ~= 0xF then
149                            ctx_gap()
150                        end
151                    end
152                    ctx_par()
153                    ctx_gap()
154                end
155                ctx_setcaption(formatters["%04X-%04X"](r,r+0xFF),file.basename(data.properties.filename))
156                ctx_par()
157            context.stopframed()
158            if newpage then
159                context.page()
160            end
161        end
162    end
163\stopluacode
164
165\installmodulecommandluasingle \showfontchart {moduledata.fonts.charts.show}
166
167\stopmodule
168
169\continueifinputfile{s-fonts-charts.mkiv}
170
171\usemodule[art-01]
172
173\starttext
174
175%     \showfontchart[filename=texgyredejavu-math.otf,page=yes,option=all]
176
177%     \showfontchart[filename=danlan.otf]      % ,page=yes,option=all]
178%     \showfontchart[filename=danlan-bold.otf] % ,page=yes,option=all]
179
180%     \showfontchart[filename=aegean,page=yes]
181%     \showfontchart[filename=veramono.ttf,page=yes]
182%     \showfontchart[filename=CoelacanthSubhdHeavy.otf,page=yes]
183
184%     \showfontchart[filename=LucidaBrightOT.otf,page=yes]
185%     \showfontchart[filename=LucidaBrightOT-Demi.otf,page=yes]
186%     \showfontchart[filename=LucidaBrightOT-DemiItalic.otf,page=yes]
187%     \showfontchart[filename=LucidaBrightOT-Italic.otf,page=yes]
188
189%     \showfontchart[filename=LucidaSansOT.otf,page=yes]
190%     \showfontchart[filename=LucidaSansOT-Demi.otf,page=yes]
191%     \showfontchart[filename=LucidaSansOT-DemiItalic.otf,page=yes]
192%     \showfontchart[filename=LucidaSansOT-Italic.otf,page=yes]
193
194%     \showfontchart[filename=LucidaSansTypewriterOT.otf,page=yes]
195%     \showfontchart[filename=LucidaSansTypewriterOT-Bold.otf,page=yes]
196%     \showfontchart[filename=LucidaSansTypewriterOT-BoldOblique.otf,page=yes]
197%     \showfontchart[filename=LucidaSansTypewriterOT-Oblique.otf,page=yes]
198
199%     \showfontchart[filename=LucidaConsoleDK.otf,page=yes]
200%     \showfontchart[filename=LucidaConsoleDK-Bold.otf,page=yes]
201%     \showfontchart[filename=LucidaConsoleDK-BoldItalic.otf,page=yes]
202%     \showfontchart[filename=LucidaConsoleDK-Italic.otf,page=yes]
203
204%     \showfontchart[filename=LucidaGrandeMonoDK.otf,page=yes]
205%     \showfontchart[filename=LucidaGrandeMonoDK-Bold.otf,page=yes]
206%     \showfontchart[filename=LucidaGrandeMonoDK-BoldItalic.otf,page=yes]
207%     \showfontchart[filename=LucidaGrandeMonoDK-Italic.otf,page=yes]
208
209%     \showfontchart[filename=LucidaBrightMathOT.otf,page=yes]
210%     \showfontchart[filename=LucidaBrightMathOT-Demi.otf,page=yes]
211
212%     \showfontchart[filename=LucidaBlackletterOT.otf,page=yes]
213%     \showfontchart[filename=LucidaCalligraphyOT.otf,page=yes]
214%     \showfontchart[filename=LucidaHandwritingOT.otf,page=yes]
215
216%     \showfontchart[filename=iwonar.afm,page=yes]
217%     \showfontchart[filename=iwonarz.afm,page=yes]
218    \showfontchart[filename=e:/tmp/Iwona-Math.otf,page=yes]
219
220\stoptext
221