summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/font-sel.mklx
blob: a1fc8cd7ff0f4c839ce6f00a3ef703e65ac1458c (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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
%D \module
%D   [     file=font-sel,
%D      version=2016.08.28,
%D        title=\CONTEXT\ User Module,
%D     subtitle=Selectfont,
%D       author=Wolfgang Schuster,
%D         date=\currentdate,
%D    copyright=Wolfgang Schuster,
%D      license=GNU General Public License]

\writestatus{loading}{ConTeXt User Module / Selectfont}

\registerctxluafile{font-sel}{}

\unprotect

\installcorenamespace                      {selectfont}
\installsimplecommandhandler \??selectfont {selectfont}

\protected\def\selectfont_register[#style][#settings]%
  {\begingroup
   \edef\currentselectfont{\expandnamespacevalue\??fontshortstyle{#style}\s!rm}%
   \checkselectfontparent
   \setupcurrentselectfont[#settings]%
   \edef\p_selectfont_preset{\selectfontparameter\c!preset}%
   \ifempty\p_selectfont_preset \else
     \processcommacommand[\p_selectfont_preset]\selectfont_preset_process
     \setupcurrentselectfont[#settings]%
   \fi
   \font_helpers_process_alternative_list\clf_registerfontalternative
   \setexpandedselectfontparameter\c!style{\expandnamespaceparameter\??fontshortstyle\selectfontparameter\c!style\s!rm}%
   \xdef\selectfont_index{\clf_registerfontfamily
        metadata {%
            typeface    {\selectfontparameter\c!label}%
            style       {\selectfontparameter\c!style}%
            family      {\selectfontparameter\c!name}%
        }
        options {%
            designsize  {\selectfontparameter\s!designsize}%
            rscale      {\selectfontparameter\s!rscale}%
            goodies     {\selectfontparameter\c!goodies}%
            extras      {\selectfontparameter\c!extras}%
            features    {\selectfontparameter\c!features}%
            preset      {\selectfontparameter\c!preset}%
            range       {\selectfontparameter\c!range}%  fallback only
            offset      {\selectfontparameter\c!offset}% fallback only
            check       {\selectfontparameter\c!check}%  fallback only
            force       {\selectfontparameter\c!force}%  fallback only
        }
        userdata {%
            \luaexpanded{#settings}%
        }}%
   \endgroup}

%D \macros
%D   {definefontfamilypreset}

\installcorenamespace {selectfontpreset}

\permanent\tolerant\protected\def\definefontfamilypreset[#name]#spacer[#settings]%
  {\defcsname\??selectfontpreset#name\endcsname{\setupcurrentselectfont[#settings]}%
   \clf_definefontfamilypreset{#name}{\luaexpanded{#settings}}}

\def\selectfont_preset_process#name%
  {\ifcsname\??selectfontpreset#name\endcsname
     \lastnamedcs
   \else
     % unknown preset
   \fi}

\definefontfamilypreset
  [range:chinese]
  [\c!range={cjkcompatibilityforms,
             cjkcompatibilityideographs,
             cjkcompatibilityideographssupplement,
             cjkradicalssupplement,
             cjkstrokes,
             cjksymbolsandpunctuation,
             cjkunifiedideographs,
             cjkunifiedideographsextensiona,
             cjkunifiedideographsextensionb,
             halfwidthandfullwidthforms,
             verticalforms,
             bopomofo,
             bopomofoextended}]

\definefontfamilypreset
  [range:japanese]
  [\c!range={cjkcompatibilityforms,
             cjkcompatibilityideographs,
             cjkcompatibilityideographssupplement,
             cjkradicalssupplement,
             cjkstrokes,
             cjksymbolsandpunctuation,
             cjkunifiedideographs,
             cjkunifiedideographsextensiona,
             cjkunifiedideographsextensionb,
             halfwidthandfullwidthforms,
             verticalforms,
             hiragana,
             katakana}]

\definefontfamilypreset
  [range:korean]
  [\c!range={cjkcompatibilityforms,
             cjkcompatibilityideographs,
             cjkcompatibilityideographssupplement,
             cjkradicalssupplement,
             cjkstrokes,
             cjksymbolsandpunctuation,
             cjkunifiedideographs,
             cjkunifiedideographsextensiona,
             cjkunifiedideographsextensionb,
             halfwidthandfullwidthforms,
             verticalforms,
             hangulcompatibilityjamo,
             hanguljamo,
             hanguljamoextendeda,
             hanguljamoextendedb,
             hangulsyllables}]

\definefontfamilypreset
  [range:cyrillic]
  [\c!range={cyrillic,
             cyrillicextendeda,
             cyrillicextendedb,
             cyrillicsupplement}]

\definefontfamilypreset
  [range:greek]
  [\c!range={greekandcoptic,
             greekextended,
             ancientgreeknumbers}]

\definefontfamilypreset
  [range:hebrew]
  [\c!range={hebrew,
             alphabeticpresentationforms}]

\definefontfamilypreset [math:digitsnormal]             [\c!range=digitsnormal]
\definefontfamilypreset [math:digitsbold]               [\c!range=digitsnormal,\c!offset=digitsbold,\s!tf=style:bold]

\definefontfamilypreset [math:uppercasenormal]          [\c!range=uppercasenormal]
\definefontfamilypreset [math:uppercaseitalic]          [\c!range=uppercasenormal,\c!offset=uppercaseitalic,    \s!tf=style:italic]
\definefontfamilypreset [math:uppercasebold]            [\c!range=uppercasenormal,\c!offset=uppercasebold,      \s!tf=style:bold]
\definefontfamilypreset [math:uppercasebolditalic]      [\c!range=uppercasenormal,\c!offset=uppercasebolditalic,\s!tf=style:bolditalic]

\definefontfamilypreset [math:lowercasenormal]          [\c!range=lowercasenormal]
\definefontfamilypreset [math:lowercaseitalic]          [\c!range=lowercasenormal,\c!offset=lowercaseitalic,    \s!tf=style:italic]
\definefontfamilypreset [math:lowercasebold]            [\c!range=lowercasenormal,\c!offset=lowercasebold,      \s!tf=style:bold]
\definefontfamilypreset [math:lowercasebolditalic]      [\c!range=lowercasenormal,\c!offset=lowercasebolditalic,\s!tf=style:bolditalic]

\definefontfamilypreset [math:mathematicaloperators]    [\c!range=mathematicaloperators]

\definefontfamilypreset [math:lowercasegreeknormal]     [\c!range=lowercasegreeknormal]
\definefontfamilypreset [math:lowercasegreekitalic]     [\c!range=lowercasegreeknormal,\c!offset=lowercasegreekitalic,    \s!tf=style:italic]
\definefontfamilypreset [math:lowercasegreekbold]       [\c!range=lowercasegreeknormal,\c!offset=lowercasegreekbold,      \s!tf=style:bold]
\definefontfamilypreset [math:lowercasegreekbolditalic] [\c!range=lowercasegreeknormal,\c!offset=lowercasegreekbolditalic,\s!tf=style:bolditalic]

\definefontfamilypreset [math:uppercasegreeknormal]     [\c!range=uppercasegreeknormal]
\definefontfamilypreset [math:uppercasegreekitalic]     [\c!range=uppercasegreeknormal,\c!offset=uppercasegreekitalic,    \s!tf=style:italic]
\definefontfamilypreset [math:uppercasegreekbold]       [\c!range=uppercasegreeknormal,\c!offset=uppercasegreekbold,      \s!tf=style:bold]
\definefontfamilypreset [math:uppercasegreekbolditalic] [\c!range=uppercasegreeknormal,\c!offset=uppercasegreekbolditalic,\s!tf=style:bolditalic]

%D \macros
%D   {definefontfamily,definefallbackfamily}
%D
%D The \tex{definefontfamily} creates like \tex{definetypeface} a collection of font
%D with different styles which can be later called with the \tex{setupbodyfont} command.
%D
%D The command takes three mandatory commands which are (a) the name of the fontclass,
%D (b) the styles of the font and (c) the name of the font.
%D
%D \starttyping
%D \definefontfamily [dejavu] [serif] [DejaVu Serif]
%D \definefontfamily [dejavu] [sans]  [DejaVu Sans]
%D \definefontfamily [dejavu] [mono]  [DejaVu Sans Mono]
%D \definefontfamily [dejavu] [math]  [XITS Math] [rscale=1.1]
%D
%D \definefontfamily [office] [serif] [Times New Roman]
%D \definefontfamily [office] [sans]  [Arial] [rscale=0.9]
%D \definefontfamily [office] [mono]  [Courier]
%D \definefontfamily [office] [math]  [TeX Gyre Termes Math]
%D
%D \definefontfamily [linux] [serif] [Linux Libertine O]
%D \definefontfamily [linux] [sans]  [Linux Biolinum O]
%D \definefontfamily [linux] [mono]  [Latin Modern Mono]
%D \definefontfamily [linux] [math]  [TeX Gyre Pagella Math] [rscale=0.9]
%D
%D \setupbodyfont[dejavu]
%D
%D \starttext
%D
%D \rm Serif \ss Sans \tt Mono \m{1+2=3}
%D
%D \switchtobodyfont[office]
%D
%D \rm Serif 123 \ss Sans \tt Mono \m{1+2=3}
%D
%D \switchtobodyfont[linux]
%D
%D \rm Serif 123 \ss Sans \tt Mono \m{1+2=3}
%D
%D \stoptext
%D \stoptyping
%D
%D When a document contains different languages and the global font lacks some characters
%D for one language, one could set a different font where these charcters are taken from.
%D This fallback font (there can be more than one for a certain style) could be set with
%D the \tex{definefallbackfamily} command which takes the same argument as
%D the \tex{definefontfamily} command.
%D
%D \starttyping
%D \definefallbackfamily [mainface] [serif] [DejaVu Serif] [range=cyrillic]
%D \definefontfamily     [mainface] [serif] [TeX Gyre Pagella]
%D
%D \setupbodyfont[mainface]
%D
%D \setuplanguage[en][patterns={us,ru}]
%D
%D \starttext
%D
%D \input knuth
%D
%D Традиционная систематика лишайников оказывается во многом условна и
%D
%D \stoptext
%D \stoptyping
%D
%D Another feature of the module is the \type{designsize} key which allows one to enable
%D optical sizes when they are a feature of the requested font.
%D
%D \starttyping
%D \definefontfamily[mainface][serif][Latin Modern Roman][designsize=auto]
%D
%D \setupbodyfont[mainface]
%D
%D \starttext
%D \scale[width=\textwidth]{\switchtobodyfont   [6pt]\tf Regular, \it Italic \bf Bold and \bi BoldItalic}
%D \scale[width=\textwidth]{\switchtobodyfont   [8pt]\tf Regular, \it Italic \bf Bold and \bi BoldItalic}
%D \scale[width=\textwidth]{\switchtobodyfont  [10pt]\tf Regular, \it Italic \bf Bold and \bi BoldItalic}
%D \scale[width=\textwidth]{\switchtobodyfont  [12pt]\tf Regular, \it Italic \bf Bold and \bi BoldItalic}
%D \scale[width=\textwidth]{\switchtobodyfont[17.3pt]\tf Regular, \it Italic \bf Bold and \bi BoldItalic}
%D \stoptext
%D \stoptyping

% tf = … | * … | name:… | name:* … | file:… | file:* … | style:medium

\permanent\tolerant\protected\def\definefontfamily[#typeface]#spacer[#style]#spacer[#family]#spacer[#settings]%
  {\ifhastok={#settings}%
     \selectfont_register[#style][\c!label={#typeface},\c!style={#style},\c!name={#family},#settings]%
   \else
     \selectfont_register[#style][\c!label={#typeface},\c!style={#style},\c!name={#family},\c!preset={#settings}]%
   \fi
   \clf_definefontfamily\selectfont_index\relax}

\permanent\tolerant\def\definefallbackfamily[#typeface]#spacer[#style]#spacer[#family]#spacer[#settings]%
  {\ifhastok={#settings}%
     \selectfont_register[#style][\c!label={#typeface},\c!style={#style},\c!name={#family},#settings]%
   \else
     \selectfont_register[#style][\c!label={#typeface},\c!style={#style},\c!name={#family},\c!preset={#settings}]%
   \fi
   \clf_definefallbackfamily\selectfont_index\relax}

\permanent\tolerant\protected\def\setupfontfamily[#style]#spacer[#settings]%
  {\ifparameter#settings\or
     \edef\currentselectfont{\expandnamespacevalue\??fontshortstyle{#style}\s!rm}%
     \setupcurrentselectfont[#settings]%
   \else
     \let\currentselectfont\empty
     \setupcurrentselectfont[#style]%
   \fi}

\setupselectfont
  [  \c!features=\s!default,
   \s!designsize=\s!default,
       \s!rscale=\selectfontparameter\c!scale,
        \c!scale=1]

\protect