font-sel.mkvi /size: 11 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=font-sel,
3
%D version=2016.08.28,
4
%D title=\CONTEXT\ User Module,
5
%D subtitle=Selectfont,
6
%D author=Wolfgang Schuster,
7
%D date=\currentdate,
8
%D copyright=Wolfgang Schuster,
9
%D license=GNU General Public License]
10 11
\writestatus
{
loading
}{
ConTeXt
User
Module
/
Selectfont
}
12 13
\registerctxluafile
{
font
-
sel
}{}
14 15
\unprotect
16 17
\installcorenamespace
{
selectfont
}
18
\installsimplecommandhandler
\??selectfont
{
selectfont
}
19 20
\unexpanded
\def
\selectfont_register
[#
style
][#
settings
]
%
21
{
\begingroup
22
\edef
\currentselectfont
{
\expandnamespacevalue
\??fontshortstyle
{
#
style
}
\s!rm
}
%
23
\checkselectfontparent
24
\setupcurrentselectfont
[#
settings
]
%
25
\edef
\p_selectfont_preset
{
\selectfontparameter
\c!preset
}
%
26
\ifx
\p_selectfont_preset
\empty
\else
27
\processcommacommand
[
\p_selectfont_preset
]
\selectfont_preset_process
28
\setupcurrentselectfont
[#
settings
]
%
29
\fi
30
\font_helpers_process_alternative_list
\clf_registerfontalternative
31
\setexpandedselectfontparameter
\c!style
{
\expandnamespaceparameter
\??fontshortstyle
\selectfontparameter
\c!style\s!rm
}
%
32
\xdef
\selectfont_index
{
\clf_registerfontfamily
33
metadata
{
%
34
typeface
{
\selectfontparameter
\c!label
}
%
35
style
{
\selectfontparameter
\c!style
}
%
36
family
{
\selectfontparameter
\c!name
}
%
37
}
38
options
{
%
39
designsize
{
\selectfontparameter
\s!designsize
}
%
40
rscale
{
\selectfontparameter
\s!rscale
}
%
41
goodies
{
\selectfontparameter
\c!goodies
}
%
42
extras
{
\selectfontparameter
\c!extras
}
%
43
features
{
\selectfontparameter
\c!features
}
%
44
preset
{
\selectfontparameter
\c!preset
}
%
45
range
{
\selectfontparameter
\c!range
}
% fallback only
46
offset
{
\selectfontparameter
\c!offset
}
% fallback only
47
check
{
\selectfontparameter
\c!check
}
% fallback only
48
force
{
\selectfontparameter
\c!force
}
% fallback only
49
}
50
userdata
{
%
51
\luaexpanded
{
#
settings
}
%
52
}}
%
53
\endgroup
}
54 55
%D \macros
56
%D {definefontfamilypreset}
57 58
\installcorenamespace
{
selectfontpreset
}
59 60
\unexpanded
\def
\definefontfamilypreset
61
{
\dodoubleargument
\selectfont_preset_define
}
62 63
\def
\selectfont_preset_define
[#
name
][#
settings
]
%
64
{
\doifelseassignment
{
#
settings
}
65
{
\setvalue
{
\??selectfontpreset
#
name
}{
\setupcurrentselectfont
[#
settings
]
}}
66
{
\setvalue
{
\??selectfontpreset
#
name
}{
\csname
\??selectfontpreset
#
settings
\endcsname
}}}
67 68
\def
\selectfont_preset_process
#
name
%
69
{
\ifcsname
\??selectfontpreset
#
name
\endcsname
70
\lastnamedcs
71
\else
72
% unknown preset
73
\fi
}
74 75
\def
\selectfont_preset_define
[#
name
][#
settings
]
%
76
{
\setvalue
{
\??selectfontpreset
#
name
}{
\setupcurrentselectfont
[#
settings
]
}
%
77
\clf_definefontfamilypreset
{
#
name
}{
\luaexpanded
{
#
settings
}}}
78 79
\definefontfamilypreset
80
[
range
:
chinese
]
81
[
\c!range
=
{
cjkcompatibilityforms
,
82
cjkcompatibilityideographs
,
83
cjkcompatibilityideographssupplement
,
84
cjkradicalssupplement
,
85
cjkstrokes
,
86
cjksymbolsandpunctuation
,
87
cjkunifiedideographs
,
88
cjkunifiedideographsextensiona
,
89
cjkunifiedideographsextensionb
,
90
halfwidthandfullwidthforms
,
91
verticalforms
,
92
bopomofo
,
93
bopomofoextended
}
]
94 95
\definefontfamilypreset
96
[
range
:
japanese
]
97
[
\c!range
=
{
cjkcompatibilityforms
,
98
cjkcompatibilityideographs
,
99
cjkcompatibilityideographssupplement
,
100
cjkradicalssupplement
,
101
cjkstrokes
,
102
cjksymbolsandpunctuation
,
103
cjkunifiedideographs
,
104
cjkunifiedideographsextensiona
,
105
cjkunifiedideographsextensionb
,
106
halfwidthandfullwidthforms
,
107
verticalforms
,
108
hiragana
,
109
katakana
}
]
110 111
\definefontfamilypreset
112
[
range
:
korean
]
113
[
\c!range
=
{
cjkcompatibilityforms
,
114
cjkcompatibilityideographs
,
115
cjkcompatibilityideographssupplement
,
116
cjkradicalssupplement
,
117
cjkstrokes
,
118
cjksymbolsandpunctuation
,
119
cjkunifiedideographs
,
120
cjkunifiedideographsextensiona
,
121
cjkunifiedideographsextensionb
,
122
halfwidthandfullwidthforms
,
123
verticalforms
,
124
hangulcompatibilityjamo
,
125
hanguljamo
,
126
hanguljamoextendeda
,
127
hanguljamoextendedb
,
128
hangulsyllables
}
]
129 130
\definefontfamilypreset
131
[
range
:
cyrillic
]
132
[
\c!range
=
{
cyrillic
,
133
cyrillicextendeda
,
134
cyrillicextendedb
,
135
cyrillicsupplement
}
]
136 137
\definefontfamilypreset
138
[
range
:
greek
]
139
[
\c!range
=
{
greekandcoptic
,
140
greekextended
,
141
ancientgreeknumbers
}
]
142 143
\definefontfamilypreset
144
[
range
:
hebrew
]
145
[
\c!range
=
{
hebrew
,
146
alphabeticpresentationforms
}
]
147 148
\definefontfamilypreset
[
math
:
digitsnormal
]
[
\c!range
=
digitsnormal
]
149
\definefontfamilypreset
[
math
:
digitsbold
]
[
\c!range
=
digitsnormal
,
\c!offset
=
digitsbold
,
\s!tf
=
style
:
bold
]
150 151
\definefontfamilypreset
[
math
:
uppercasenormal
]
[
\c!range
=
uppercasenormal
]
152
\definefontfamilypreset
[
math
:
uppercaseitalic
]
[
\c!range
=
uppercasenormal
,
\c!offset
=
uppercaseitalic
,
\s!tf
=
style
:
italic
]
153
\definefontfamilypreset
[
math
:
uppercasebold
]
[
\c!range
=
uppercasenormal
,
\c!offset
=
uppercasebold
,
\s!tf
=
style
:
bold
]
154
\definefontfamilypreset
[
math
:
uppercasebolditalic
]
[
\c!range
=
uppercasenormal
,
\c!offset
=
uppercasebolditalic
,
\s!tf
=
style
:
bolditalic
]
155 156
\definefontfamilypreset
[
math
:
lowercasenormal
]
[
\c!range
=
lowercasenormal
]
157
\definefontfamilypreset
[
math
:
lowercaseitalic
]
[
\c!range
=
lowercasenormal
,
\c!offset
=
lowercaseitalic
,
\s!tf
=
style
:
italic
]
158
\definefontfamilypreset
[
math
:
lowercasebold
]
[
\c!range
=
lowercasenormal
,
\c!offset
=
lowercasebold
,
\s!tf
=
style
:
bold
]
159
\definefontfamilypreset
[
math
:
lowercasebolditalic
]
[
\c!range
=
lowercasenormal
,
\c!offset
=
lowercasebolditalic
,
\s!tf
=
style
:
bolditalic
]
160 161
\definefontfamilypreset
[
math
:
mathematicaloperators
]
[
\c!range
=
mathematicaloperators
]
162 163
\definefontfamilypreset
[
math
:
lowercasegreeknormal
]
[
\c!range
=
lowercasegreeknormal
]
164
\definefontfamilypreset
[
math
:
lowercasegreekitalic
]
[
\c!range
=
lowercasegreeknormal
,
\c!offset
=
lowercasegreekitalic
,
\s!tf
=
style
:
italic
]
165
\definefontfamilypreset
[
math
:
lowercasegreekbold
]
[
\c!range
=
lowercasegreeknormal
,
\c!offset
=
lowercasegreekbold
,
\s!tf
=
style
:
bold
]
166
\definefontfamilypreset
[
math
:
lowercasegreekbolditalic
]
[
\c!range
=
lowercasegreeknormal
,
\c!offset
=
lowercasegreekbolditalic
,
\s!tf
=
style
:
bolditalic
]
167 168
\definefontfamilypreset
[
math
:
uppercasegreeknormal
]
[
\c!range
=
uppercasegreeknormal
]
169
\definefontfamilypreset
[
math
:
uppercasegreekitalic
]
[
\c!range
=
uppercasegreeknormal
,
\c!offset
=
uppercasegreekitalic
,
\s!tf
=
style
:
italic
]
170
\definefontfamilypreset
[
math
:
uppercasegreekbold
]
[
\c!range
=
uppercasegreeknormal
,
\c!offset
=
uppercasegreekbold
,
\s!tf
=
style
:
bold
]
171
\definefontfamilypreset
[
math
:
uppercasegreekbolditalic
]
[
\c!range
=
uppercasegreeknormal
,
\c!offset
=
uppercasegreekbolditalic
,
\s!tf
=
style
:
bolditalic
]
172 173
%D \macros
174
%D {definefontfamily,definefallbackfamily}
175
%D
176
%D The \tex{definefontfamily} creates like \tex{definetypeface} a collection of font
177
%D with different styles which can be later called with the \tex{setupbodyfont} command.
178
%D
179
%D The command takes three mandatory commands which are (a) the name of the fontclass,
180
%D (b) the styles of the font and (c) the name of the font.
181
%D
182
%D \starttyping
183
%D \definefontfamily [dejavu] [serif] [DejaVu Serif]
184
%D \definefontfamily [dejavu] [sans] [DejaVu Sans]
185
%D \definefontfamily [dejavu] [mono] [DejaVu Sans Mono]
186
%D \definefontfamily [dejavu] [math] [XITS Math] [rscale=1.1]
187
%D
188
%D \definefontfamily [office] [serif] [Times New Roman]
189
%D \definefontfamily [office] [sans] [Arial] [rscale=0.9]
190
%D \definefontfamily [office] [mono] [Courier]
191
%D \definefontfamily [office] [math] [TeX Gyre Termes Math]
192
%D
193
%D \definefontfamily [linux] [serif] [Linux Libertine O]
194
%D \definefontfamily [linux] [sans] [Linux Biolinum O]
195
%D \definefontfamily [linux] [mono] [Latin Modern Mono]
196
%D \definefontfamily [linux] [math] [TeX Gyre Pagella Math] [rscale=0.9]
197
%D
198
%D \setupbodyfont[dejavu]
199
%D
200
%D \starttext
201
%D
202
%D \rm Serif \ss Sans \tt Mono \m{1+2=3}
203
%D
204
%D \switchtobodyfont[office]
205
%D
206
%D \rm Serif 123 \ss Sans \tt Mono \m{1+2=3}
207
%D
208
%D \switchtobodyfont[linux]
209
%D
210
%D \rm Serif 123 \ss Sans \tt Mono \m{1+2=3}
211
%D
212
%D \stoptext
213
%D \stoptyping
214
%D
215
%D When a document contains different languages and the global font lacks some characters
216
%D for one language, one could set a different font where these charcters are taken from.
217
%D This fallback font (there can be more than one for a certain style) could be set with
218
%D the \tex{definefallbackfamily} command which takes the same argument as
219
%D the \tex{definefontfamily} command.
220
%D
221
%D \starttyping
222
%D \definefallbackfamily [mainface] [serif] [DejaVu Serif] [range=cyrillic]
223
%D \definefontfamily [mainface] [serif] [TeX Gyre Pagella]
224
%D
225
%D \setupbodyfont[mainface]
226
%D
227
%D \setuplanguage[en][patterns={us,ru}]
228
%D
229
%D \starttext
230
%D
231
%D \input knuth
232
%D
233
%D Традиционная систематика лишайников оказывается во многом условна и
234
%D
235
%D \stoptext
236
%D \stoptyping
237
%D
238
%D Another feature of the module is the \type{designsize} key which allows one to enable
239
%D optical sizes when they are a feature of the requested font.
240
%D
241
%D \starttyping
242
%D \definefontfamily[mainface][serif][Latin Modern Roman][designsize=auto]
243
%D
244
%D \setupbodyfont[mainface]
245
%D
246
%D \starttext
247
%D \scale[width=\textwidth]{\switchtobodyfont [6pt]\tf Regular, \it Italic \bf Bold and \bi BoldItalic}
248
%D \scale[width=\textwidth]{\switchtobodyfont [8pt]\tf Regular, \it Italic \bf Bold and \bi BoldItalic}
249
%D \scale[width=\textwidth]{\switchtobodyfont [10pt]\tf Regular, \it Italic \bf Bold and \bi BoldItalic}
250
%D \scale[width=\textwidth]{\switchtobodyfont [12pt]\tf Regular, \it Italic \bf Bold and \bi BoldItalic}
251
%D \scale[width=\textwidth]{\switchtobodyfont[17.3pt]\tf Regular, \it Italic \bf Bold and \bi BoldItalic}
252
%D \stoptext
253
%D \stoptyping
254 255
% tf = … | * … | name:… | name:* … | file:… | file:* … | style:medium
256 257
\unexpanded
\def
\definefontfamily
258
{
\doquadrupleempty
\selectfont_family_define
}
259 260
\def
\selectfont_family_define
[#
typeface
][#
style
][#
family
][#
settings
]
%
261
{
\doifelseassignment
{
#
settings
}
262
{
\selectfont_register
[#
style
][
\c!label
=
{
#
typeface
}
,
\c!style
=
{
#
style
}
,
\c!name
=
{
#
family
}
,
#
settings
]
}
263
{
\selectfont_register
[#
style
][
\c!label
=
{
#
typeface
}
,
\c!style
=
{
#
style
}
,
\c!name
=
{
#
family
}
,
\c!preset
=
{
#
settings
}
]
}
%
264
\clf_definefontfamily
\selectfont_index
\relax
}
265 266
\unexpanded
\def
\definefallbackfamily
267
{
\doquadrupleempty
\selectfont_fallback_define
}
268 269
\def
\selectfont_fallback_define
[#
typeface
][#
style
][#
family
][#
settings
]
%
270
{
\doifelseassignment
{
#
settings
}
271
{
\selectfont_register
[#
style
][
\c!label
=
{
#
typeface
}
,
\c!style
=
{
#
style
}
,
\c!name
=
{
#
family
}
,
#
settings
]
}
272
{
\selectfont_register
[#
style
][
\c!label
=
{
#
typeface
}
,
\c!style
=
{
#
style
}
,
\c!name
=
{
#
family
}
,
\c!preset
=
{
#
settings
}
]
}
%
273
\clf_definefallbackfamily
\selectfont_index
\relax
}
274 275
\unexpanded
\def
\setupfontfamily
276
{
\dodoubleargument
\selectfont_family_setup
}
277 278
\def
\selectfont_family_setup
[#
style
][#
settings
]
%
279
{
\ifsecondargument
280
\edef
\currentselectfont
{
\expandnamespacevalue
\??fontshortstyle
{
#
style
}
\s!rm
}
%
281
\setupcurrentselectfont
[#
settings
]
%
282
\else
283
\let
\currentselectfont
\empty
284
\setupcurrentselectfont
[#
style
]
%
285
\fi
}
286 287
\setupselectfont
288
[
\c!features
=
\s!default
,
289
\s!designsize
=
\s!default
,
290
\s!rscale
=
\selectfontparameter
\c!scale
,
291
\c!scale
=
1
]
292 293
\protect
294