summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/modules/mkiv/s-fonts-charts.mkiv
blob: e94b52a2e76898055cecd00132ebee98d136f1d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
%D \module
%D   [      file=s-fonts-charts,
%D        version=2015.08.08,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Show Fonts Charts,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% begin info
%
% title   : show unicode blocks
%
% comment : show charts of a given fgont
%
% end info

\startmodule[fonts-charts]

% \registerctxluafile{s-fonts-charts}{}
\starttexdefinition unexpanded FontChartSetSlot #1#2
    \dontleavehmode
    \setbox\scratchbox\vbox to 1cm \bgroup
        \vss
        \hbox to 1cm \bgroup
            \infofont \hss\raise.25mm\hbox{#2}\hss
        \egroup
    \egroup
    \wd\scratchbox0mm
    \ht\scratchbox5mm
    \dp\scratchbox5mm
    \box\scratchbox
    \setbox\scratchbox\ruledhbox to 1cm \bgroup
        \hss\char#1\hss
    \egroup
    \ht\scratchbox5mm
    \dp\scratchbox5mm
    \box\scratchbox
\stoptexdefinition

\starttexdefinition unexpanded FontChartNoSlot
    \dontleavehmode
    \setbox\scratchbox\hbox to 1cm \bgroup
        % empty
    \egroup
    \ht\scratchbox5mm
    \dp\scratchbox5mm
    \box\scratchbox
\stoptexdefinition

\starttexdefinition unexpanded FontChartSetLegend #1
    \dontleavehmode
    \setbox\scratchbox\hbox to 1cm \bgroup
        \infofont\hss#1\hss
    \egroup
    \ht\scratchbox5mm
    \dp\scratchbox5mm
    \box\scratchbox
\stoptexdefinition

\starttexdefinition unexpanded FontChartSetCaption #1#2
    \dontleavehmode
    \setbox\scratchbox\hbox to 16cm \bgroup
        \infofontbold\hskip1cm#1: #2\hss
    \egroup
    \ht\scratchbox7.5mm
    \dp\scratchbox2.5mm
    \box\scratchbox
\stoptexdefinition

\starttexdefinition unexpanded FontChartGap
    \kern .5mm
\stoptexdefinition

\startluacode
    local div, mod = math.div, math.mod
    local formatters = string.formatters

    moduledata.fonts        = moduledata.fonts        or { }
    moduledata.fonts.charts = moduledata.fonts.charts or { }

    function moduledata.fonts.charts.show(settings)

        local settings = utilities.parsers.settings_to_hash(settings)

        local filename = settings.filename or ""
        local fontid   = true
        local newpage  = settings.page == interfaces.variables.yes

        if filename ~= "" then
            fontid = fonts.definers.internal({ name = filename, size = "10pt" },"chartfont")
        end

        local ranges   = { }
        local data     = fonts.hashes.identifiers[fontid]
        local private  = fonts.constructors.privateoffset
        local chars    = data.characters

        for u in table.sortedhash(chars) do
            if u >= private then
                break
            else
                ranges[div(u,0xFF)] = true
            end
        end

        local ctx_setlegend  = context.FontChartSetLegend
        local ctx_noslot     = context.FontChartNoSlot
        local ctx_setslot    = context.FontChartSetSlot
        local ctx_setcaption = context.FontChartSetCaption
        local ctx_par        = context.par
        local ctx_gap        = context.FontChartGap

        for r in table.sortedhash(ranges) do
            if newpage then
                context.page()
            end
            context.startframed { offset = "overlay", frame = "off", align = "normal" }
                if filename ~= "" then
                    context.chartfont()
                end
                context.dontcomplain()
                context.offinterlineskip()
                ctx_noslot()
                for i=0,0xF do
                    ctx_setlegend(formatters["%03X"](r*0x10+i))
                end
                r = r * 0xFF
                ctx_par()
                for i=0,0xF do
                    ctx_setlegend(formatters["%0X"](i))
                    ctx_gap()
                    for j=0,0xF do
                        local u = r + i*0x10 + j
                        local d = chars[u]
                        if d then
                            ctx_setslot(u,formatters["%04X"](u))
                        else
                            ctx_noslot()
                        end
                        if j ~= 0xF then
                            ctx_gap()
                        end
                    end
                    ctx_par()
                    ctx_gap()
                end
                ctx_setcaption(formatters["%04X-%04X"](r,r+0xFF),file.basename(data.properties.filename))
                ctx_par()
            context.stopframed()
            if newpage then
                context.page()
            end
        end
    end
\stopluacode

\installmodulecommandluasingle \showfontchart {moduledata.fonts.charts.show}

\stopmodule

\continueifinputfile{s-fonts-charts.mkiv}

\usemodule[art-01]

\starttext

    \showfontchart[filename=LucidaBrightOT.otf,page=yes]
    \showfontchart[filename=LucidaBrightOT-Demi.otf,page=yes]
    \showfontchart[filename=LucidaBrightOT-DemiItalic.otf,page=yes]
    \showfontchart[filename=LucidaBrightOT-Italic.otf,page=yes]

    \showfontchart[filename=LucidaSansOT.otf,page=yes]
    \showfontchart[filename=LucidaSansOT-Demi.otf,page=yes]
    \showfontchart[filename=LucidaSansOT-DemiItalic.otf,page=yes]
    \showfontchart[filename=LucidaSansOT-Italic.otf,page=yes]

    \showfontchart[filename=LucidaSansTypewriterOT.otf,page=yes]
    \showfontchart[filename=LucidaSansTypewriterOT-Bold.otf,page=yes]
    \showfontchart[filename=LucidaSansTypewriterOT-BoldOblique.otf,page=yes]
    \showfontchart[filename=LucidaSansTypewriterOT-Oblique.otf,page=yes]

    \showfontchart[filename=LucidaConsoleDK.otf,page=yes]
    \showfontchart[filename=LucidaConsoleDK-Bold.otf,page=yes]
    \showfontchart[filename=LucidaConsoleDK-BoldItalic.otf,page=yes]
    \showfontchart[filename=LucidaConsoleDK-Italic.otf,page=yes]

    \showfontchart[filename=LucidaGrandeMonoDK.otf,page=yes]
    \showfontchart[filename=LucidaGrandeMonoDK-Bold.otf,page=yes]
    \showfontchart[filename=LucidaGrandeMonoDK-BoldItalic.otf,page=yes]
    \showfontchart[filename=LucidaGrandeMonoDK-Italic.otf,page=yes]

    \showfontchart[filename=LucidaBrightMathOT.otf,page=yes]
    \showfontchart[filename=LucidaBrightMathOT-Demi.otf,page=yes]

    \showfontchart[filename=LucidaBlackletterOT.otf,page=yes]
    \showfontchart[filename=LucidaCalligraphyOT.otf,page=yes]
    \showfontchart[filename=LucidaHandwritingOT.otf,page=yes]

\stoptext