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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
% \section{Programmer's interface}
%
% \iffalse
% \begin{macrocode}
%<*fontspec&(xetexx|luatex)>
% \end{macrocode}
% \fi
%
%
%
% These functions are not used directly by fontspec when defining fonts;
% they are designed to be used by other packages who wish to do font-related
% things on top of fontspec itself.
%
% Because I haven't fully explored how these functions will behave in
% practise, I am not giving them user-level names. As it becomes more clear
% which of these should be accessible by document writers, I'll open them up
% a little more.
%
% All functions are defined assuming that the font to be queried is
% currently selected as a fontspec font. (I.e., via \verb|\fontspec| or
% from a \verb|\newfontfamily| macro or from \verb|\setmainfont| and so on.)
%
% \begin{macro}{\fontspec_if_fontspec_font:TF}
% Test whether the currently selected font has been loaded by fontspec.
% \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_fontspec_font: {TF,T,F}
{
\cs_if_exist:cTF {g_@@_ \f@family _prop} \prg_return_true: \prg_return_false:
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_if_aat_feature:nnTF}
% Conditional to test if the currently selected font contains the \AAT\
% feature (|#1|,|#2|).
% \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_aat_feature:nn {TF,T,F}
{
\fontspec_if_fontspec_font:TF
{
\prop_get:cnN {g_@@_ \f@family _prop} {fontdef} \l_@@_fontdef_tl
\@@_font_set:Nnn \l_fontspec_font {\l_@@_fontdef_tl} {\f@size pt}
\bool_if:NTF \l_@@_atsui_bool
{
\fontspec_make_AAT_feature_string:nnTF {#1}{#2}
\prg_return_true: \prg_return_false:
}
{
\prg_return_false:
}
}
{
\prg_return_false:
}
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_if_opentype:TF}
% Test whether the currently selected font is an OpenType font.
% Always true for LuaTeX fonts.
% \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_opentype: {TF,T,F}
{
\fontspec_if_fontspec_font:TF
{
\prop_get:cnN {g_@@_ \f@family _prop} {fontdef} \l_@@_fontdef_tl
\@@_font_set:Nnn \l_fontspec_font {\l_@@_fontdef_tl} {\f@size pt}
\@@_set_font_type:
\bool_if:NTF \l_@@_ot_bool \prg_return_true: \prg_return_false:
}
{
\prg_return_false:
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_feature:nTF}
% Test whether the currently selected font contains the raw OpenType
% feature |#1|. E.g.: |\fontspec_if_feature:nTF {pnum} {True} {False}|
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
% \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_feature:n {TF,T,F}
{
\fontspec_if_fontspec_font:TF
{
\prop_get:cnN {g_@@_ \f@family _prop} {fontdef} \l_@@_fontdef_tl
\@@_font_set:Nnn \l_fontspec_font {\l_@@_fontdef_tl} {\f@size pt}
\@@_set_font_type:
\bool_if:NTF \l_@@_ot_bool
{
\prop_get:cnN {g_@@_ \f@family _prop} {script-num} \l_@@_tmp_tl
\int_set:Nn \l_fontspec_script_int {\l_@@_tmp_tl}
\prop_get:cnN {g_@@_ \f@family _prop} {lang-num} \l_@@_tmp_tl
\int_set:Nn \l_fontspec_language_int {\l_@@_tmp_tl}
\prop_get:cnN {g_@@_ \f@family _prop} {script-tag} \l_fontspec_script_tl
\prop_get:cnN {g_@@_ \f@family _prop} {lang-tag} \l_fontspec_lang_tl
\fontspec_check_ot_feat:nTF {#1} {\prg_return_true:} {\prg_return_false:}
}
{
\prg_return_false:
}
}
{
\prg_return_false:
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_feature:nnnTF}
% Test whether the currently selected font with raw OpenType script tag |#1| and raw OpenType language tag |#2| contains the raw OpenType feature tag |#3|. E.g.: |\fontspec_if_feature:nTF {latn} {ROM} {pnum} {True} {False}|
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
% \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_feature:nnn {TF,T,F}
{
\fontspec_if_fontspec_font:TF
{
\prop_get:cnN {g_@@_ \f@family _prop} {fontdef} \l_@@_fontdef_tl
\@@_font_set:Nnn \l_fontspec_font {\l_@@_fontdef_tl} {\f@size pt}
\@@_set_font_type:
\bool_if:NTF \l_@@_ot_bool
{
\fontspec_iv_str_to_num:Nn \l_fontspec_script_int {#1}
\fontspec_iv_str_to_num:Nn \l_fontspec_language_int {#2}
\fontspec_check_ot_feat:nTF {#3} \prg_return_true: \prg_return_false:
}
{ \prg_return_false: }
}
{ \prg_return_false: }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_script:nTF}
% Test whether the currently selected font contains the raw OpenType
% script |#1|. E.g.: |\fontspec_if_script:nTF {latn} {True} {False}|
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
% \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_script:n {TF,T,F}
{
\fontspec_if_fontspec_font:TF
{
\prop_get:cnN {g_@@_ \f@family _prop} {fontdef} \l_@@_fontdef_tl
\@@_font_set:Nnn \l_fontspec_font {\l_@@_fontdef_tl} {\f@size pt}
\@@_set_font_type:
\bool_if:NTF \l_@@_ot_bool
{
\fontspec_check_script:nTF {#1} \prg_return_true: \prg_return_false:
}
{ \prg_return_false: }
}
{ \prg_return_false: }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_language:nTF}
% Test whether the currently selected font contains the raw OpenType language
% tag |#1|. E.g.: |\fontspec_if_language:nTF {ROM} {True} {False}|.
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
% \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_language:n {TF,T,F}
{
\fontspec_if_fontspec_font:TF
{
\prop_get:cnN {g_@@_ \f@family _prop} {fontdef} \l_@@_fontdef_tl
\@@_font_set:Nnn \l_fontspec_font {\l_@@_fontdef_tl} {\f@size pt}
\@@_set_font_type:
\bool_if:NTF \l_@@_ot_bool
{
\prop_get:cnN {g_@@_ \f@family _prop} {script-num} \l_@@_tmp_tl
\int_set:Nn \l_fontspec_script_int {\l_@@_tmp_tl}
\prop_get:cnN {g_@@_ \f@family _prop} {script-tag} \l_fontspec_script_tl
\fontspec_check_lang:nTF {#1} \prg_return_true: \prg_return_false:
}
{ \prg_return_false: }
}
{ \prg_return_false: }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_language:nnTF}
% Test whether the currently selected font contains the raw OpenType language
% tag |#2| in script |#1|. E.g.: |\fontspec_if_language:nnTF {cyrl} {SRB} {True} {False}|.
% Returns false if the font is not loaded by fontspec or is not an OpenType
% font.
% \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_language:nn {TF,T,F}
{
\fontspec_if_fontspec_font:TF
{
\prop_get:cnN {g_@@_ \f@family _prop} {fontdef} \l_@@_fontdef_tl
\@@_font_set:Nnn \l_fontspec_font {\l_@@_fontdef_tl} {\f@size pt}
\@@_set_font_type:
\bool_if:NTF \l_@@_ot_bool
{
\tl_set:Nn \l_fontspec_script_tl {#1}
\fontspec_iv_str_to_num:Nn \l_fontspec_script_int {#1}
\fontspec_check_lang:nTF {#2} \prg_return_true: \prg_return_false:
}
{ \prg_return_false: }
}
{ \prg_return_false: }
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_if_current_script:nTF}
% Test whether the currently loaded font is using the specified raw
% OpenType script tag |#1|.
% \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_current_script:n {TF,T,F}
{
\fontspec_if_fontspec_font:TF
{
\prop_get:cnN {g_@@_ \f@family _prop} {fontdef} \l_@@_fontdef_tl
\@@_font_set:Nnn \l_fontspec_font {\l_@@_fontdef_tl} {\f@size pt}
\@@_set_font_type:
\bool_if:NTF \l_@@_ot_bool
{
\prop_get:cnN {g_@@_ \f@family _prop} {script-tag} \l_@@_tmp_tl
\str_if_eq:nVTF {#1} \l_@@_tmp_tl
{\prg_return_true:} {\prg_return_false:}
}
{ \prg_return_false: }
}
{ \prg_return_false: }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\fontspec_if_current_language:nTF}
% Test whether the currently loaded font is using the specified raw
% OpenType language tag |#1|.
% \begin{macrocode}
\prg_new_conditional:Nnn \fontspec_if_current_language:n {TF,T,F}
{
\fontspec_if_fontspec_font:TF
{
\prop_get:cnN {g_@@_ \f@family _prop} {fontdef} \l_@@_fontdef_tl
\@@_font_set:Nnn \l_fontspec_font {\l_@@_fontdef_tl} {\f@size pt}
\@@_set_font_type:
\bool_if:NTF \l_@@_ot_bool
{
\prop_get:cnN {g_@@_ \f@family _prop} {lang-tag} \l_@@_tmp_tl
\str_if_eq:nVTF {#1} \l_@@_tmp_tl
{\prg_return_true:} {\prg_return_false:}
}
{ \prg_return_false: }
}
{ \prg_return_false: }
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_set_family:Nnn}
% \darg{family}
% \darg{fontspec features}
% \darg{font name}
% Defines a new font family from given \meta{features} and \meta{font},
% and stores the name in the variable \meta{family}.
% See the standard \pkg{fontspec} user commands for applications of this
% function.
%
% We want to store the actual name of the font family within the \meta{family}
% variable because the actual \LaTeX\ family name is automatically generated
% by fontspec and it's easier to keep it that way.
%
% Please use |\fontspec_set_family:Nnn| instead of |\fontspec_select:nn|,
% which may change in the future.
% \begin{macrocode}
\cs_new:Nn \fontspec_set_family:Nnn
{
\tl_set:Nn \l_@@_family_label_tl { #1 }
\fontspec_select:nn {#2}{#3}
\tl_set_eq:NN #1 \l_fontspec_family_tl
}
\cs_generate_variant:Nn \fontspec_set_family:Nnn {c}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fontspec_set_fontface:NNnn}
% \begin{macrocode}
\cs_new:Nn \fontspec_set_fontface:NNnn
{
\tl_set:Nn \l_@@_family_label_tl { #1 }
\fontspec_select:nn {#3}{#4}
\tl_set_eq:NN #1 \l_fontspec_font
\tl_set_eq:NN #2 \l_fontspec_family_tl
}
% \end{macrocode}
% \end{macro}
%
% \iffalse
% \begin{macrocode}
%</fontspec&(xetexx|luatex)>
% \end{macrocode}
% \fi
|