Debian Codegraph @

texmf-dist/source/latex/fontspec/fontspec-code-keyval.dtx

raw
1 %%^^A%% fontspec-code-keyval.dtx -- part of FONTSPEC <latex3.github.io/fontspec>
2
3 % \section{Font loading (\pkg{keyval}) definitions}
4 %
5 % \iffalse
6 % \begin{macrocode}
7 %<*fontspec>
8 % \end{macrocode}
9 % \fi
10 %
11 % This package uses a large number of keyval modules which operate sequentially on keyval
12 % input to ensure priority.
13 % \begin{macrocode}
14 \clist_gset:Nn \g_@@_all_keyval_modules_clist
15 {
16 fontspec, fontspec-opentype, fontspec-aat,
17 fontspec-preparse, fontspec-preparse-cfg, fontspec-preparse-external, fontspec-preparse-nested,
18 fontspec-renderer
19 }
20 % \end{macrocode}
21 %
22 % Wrapper function to save some characters in the source:
23 % \begin{macrocode}
24 \cs_new:Nn \@@_keys_define_code:nnn
25 {
26 \keys_define:nn {#1} { #2 .code:n = {#3} }
27 }
28 % \end{macrocode}
29 %
30 % For catching features that cannot be used in |\addfontfeatures|:
31 % \begin{macrocode}
32 \cs_new:Nn \@@_aff_error:n
33 {
34 \@@_keys_define_code:nnn {fontspec-addfeatures} {#1}
35 { \@@_error:nx {not-in-addfontfeatures} {#1} }
36 }
37 % \end{macrocode}
38 %
39 % \subsection{Pre-pre-parsing stages}
40 %
41 % These features are extracted from the font feature list before all others.
42 %
43 % \paragraph{Don't load font config file}
44 % \begin{macrocode}
45 \@@_keys_define_code:nnn {fontspec-preparse-cfg} {IgnoreFontspecFile}
46 {
47 \bool_set_false:N \l_@@_fontcfg_bool
48 }
49 \@@_keys_define_code:nnn {fontspec-preparse-external} {IgnoreFontspecFile}
50 {
51 \bool_set_false:N \l_@@_fontcfg_bool
52 }
53 % \end{macrocode}
54 %
55 % \begin{macro}{Path}
56 % For fonts that aren't installed in the system. If no argument is given, the font is located
57 % with |kpsewhich|; it's either in the current directory or the \TeX\ tree. Otherwise, the
58 % argument given defines the file path of the font.
59 % \begin{macrocode}
60 \@@_keys_define_code:nnn {fontspec-preparse-external} {Path}
61 {
62 \bool_set_true:N \l_@@_nobf_bool
63 \bool_set_true:N \l_@@_noit_bool
64 \tl_set:Nn \l_@@_font_path_tl {#1}
65 \@@_font_is_file:
66 %<*XE>
67 \keys_set:nn {fontspec-renderer} {Renderer=OpenType}
68 %</XE>
69 }
70 \aliasfontfeature{Path}{ExternalLocation}
71 \@@_keys_define_code:nnn {fontspec} {Path} {}
72 % \end{macrocode}
73 % \end{macro}
74 %
75 % \paragraph{\feat{Extension}}
76 % For fonts that aren't installed in the system. Specifies the font extension
77 % to use.
78 % \begin{macrocode}
79 \@@_keys_define_code:nnn {fontspec-preparse-external} {Extension}
80 {
81 \tl_set:Nn \l_@@_extension_tl {#1}
82 \bool_if:NF \l_@@_external_bool
83 {
84 \keys_set:nn {fontspec-preparse-external} {Path}
85 }
86 }
87 \tl_clear:N \l_@@_extension_tl
88 \@@_keys_define_code:nnn {fontspec} {Extension} {}
89 % \end{macrocode}
90 %
91 % \paragraph{\feat{KpseOnly}}
92 % If the font is specified by filename, only search for it through kpse.
93 % \XeTeX\ does not support finding system fonts by filename so this is always implicitly set
94 % there.
95 % \begin{macrocode}
96 \@@_keys_define_code:nnn {fontspec-preparse-external} {KpseOnly}
97 {
98 \bool_set_true:N \l_@@_external_kpse_bool
99 \bool_if:NT \l_@@_external_bool \@@_font_is_file:
100 }
101 \@@_keys_define_code:nnn {fontspec} {KpseOnly} {}
102 % \end{macrocode}
103 %
104 %
105 % \paragraph{\feat{Renderer}}
106 % This feature must be processed before all others (the other font shape and features
107 % options are also pre-parsed for convenience) because the renderer determines the format
108 % of the features and whether certain features are available.
109 % \begin{macrocode}
110 %<*XE>
111 \keys_define:nn {fontspec-renderer}
112 {
113 Renderer .choices:nn =
114 {AAT,ICU,OpenType,Graphite,Full,Basic,Node,Base,HarfBuzz,Harfbuzz}
115 {
116 \int_compare:nTF {\l_keys_choice_int <= 4}
117 {
118 \tl_set:Nx \l_@@_renderer_tl
119 {
120 \int_case:nn \l_keys_choice_int { 1 {/AAT} 2 {/OT} 3 {/OT} 4 {/GR} }
121 }
122 %<debug>\typeout{Renderer:~ \l_@@_renderer_tl}
123 \tl_gset:Nx \g_@@_single_feat_tl { \l_@@_renderer_tl }
124 }
125 {
126 \@@_warning:nx {only-luatex-feature} {Renderer=Full/Basic/Node/Base/HarfBuzz}
127 }
128 }
129 }
130 %</XE>
131 %<*LU>
132 \keys_define:nn {fontspec-renderer}
133 {
134 Renderer .choices:nn =
135 {Full,Node,Basic,Base,HarfBuzz,Harfbuzz,OpenType,AAT,Graphite}
136 {
137 \int_compare:nT {\l_keys_choice_int >= 5} { \bool_set_true:N \l_@@_harfbuzz_bool }
138
139 \tl_set:Nx \l_@@_mode_tl
140 {
141 \int_case:nn \l_keys_choice_int { 1 {node} 2 {node} 3 {base} 4 {base} 5 {harf} 6 {harf} 7 {harf} 8 {harf} 9 {harf}}
142 }
143
144 \tl_set:Nx \l_@@_shaper_tl
145 {
146 \int_case:nn \l_keys_choice_int { 1 {} 2 {} 3 {} 4 {} 5 {} 6 {} 7 {ot} 8 {coretext_aat} 9 {graphite2} }
147 }
148
149 %<debug>\typeout{Mode:~"\l_@@_mode_tl"~/~Shaper:~"\l_@@_shaper_tl"}
150
151 \tl_gset:Nx \g_@@_single_feat_tl
152 {
153 mode=\l_@@_mode_tl ;
154 \tl_if_empty:NF \l_@@_shaper_tl { shaper=\l_@@_shaper_tl}
155 }
156 } ,
157
158 Renderer unknown .code:n =
159 {
160 \bool_set_true:N \l_@@_harfbuzz_bool
161 \@@_warning:nx {unknown-renderer} {#1}
162 \tl_set:Nn \l_@@_mode_tl {harf}
163 \tl_set:Nn \l_@@_shaper_tl {#1}
164 } ,
165 }
166 %</LU>
167 % \end{macrocode}
168 %
169 % \subsection{Pre-parsed features}
170 %
171 % \paragraph{OpenType script/language}
172 % See later for the resolutions from \pkg{fontspec} features to OpenType definitions.
173 % \begin{macrocode}
174 \@@_keys_define_code:nnn {fontspec-preparse} {Script}
175 {
176 %<XE> \tl_if_empty:NT \l_@@_renderer_tl { \keys_set:nn {fontspec-renderer} {Renderer=OpenType} }
177 \tl_set:Nn \l_@@_script_name_tl {#1}
178 }
179 % \end{macrocode}
180 % Exactly the same:
181 % \begin{macrocode}
182 \@@_keys_define_code:nnn {fontspec-preparse} {Language}
183 {
184 %<XE> \tl_if_empty:NT \l_@@_renderer_tl { \keys_set:nn {fontspec-renderer} {Renderer=OpenType} }
185 \tl_set:Nn \l_@@_lang_name_tl {#1}
186 }
187 % \end{macrocode}
188 %
189 %
190 % \paragraph{TTC font index}
191 % \begin{macrocode}
192 \@@_keys_define_code:nnn {fontspec-preparse} {FontIndex}
193 {
194 \str_if_eq:eeF { \str_lowercase:f {\l_@@_extension_tl} } {.ttc}
195 { \@@_warning:n {font-index-needs-ttc} }
196 %<XE> \tl_set:Nn \l_@@_ttc_index_tl {:#1}
197 %<LU> \tl_set:Nn \l_@@_ttc_index_tl {(#1)}
198 }
199 \@@_keys_define_code:nnn {fontspec} {FontIndex}
200 {
201 %<XE> \tl_set:Nn \l_@@_ttc_index_tl {:#1}
202 %<LU> \tl_set:Nn \l_@@_ttc_index_tl {(#1)}
203 }
204 % \end{macrocode}
205 %
206 % \subsection{Font faces}
207 %
208 % \paragraph{Upright}
209 % \begin{macrocode}
210 \@@_keys_define_code:nnn {fontspec-preparse-external} {UprightFont}
211 {
212 \fontspec_complete_fontname:Nn \l_@@_fontname_up_tl {#1}
213 }
214 % \end{macrocode}
215 %
216 % \paragraph{Italic and slanted}
217 % \begin{macrocode}
218 \@@_keys_define_code:nnn {fontspec-preparse-external} {ItalicFont}
219 {
220 \tl_if_empty:nTF {#1}
221 {
222 \bool_set_true:N \l_@@_noit_bool
223 }
224 {
225 \bool_set_false:N \l_@@_noit_bool
226 \fontspec_complete_fontname:Nn \l_@@_fontname_it_tl {#1}
227 }
228 }
229 % \end{macrocode}
230 %
231 % \begin{macrocode}
232 \@@_keys_define_code:nnn {fontspec-preparse-external} {SlantedFont}
233 {
234 \fontspec_complete_fontname:Nn \l_@@_fontname_sl_tl {#1}
235 }
236 % \end{macrocode}
237 %
238 % \begin{macrocode}
239 \@@_keys_define_code:nnn {fontspec-preparse-external} {SwashFont}
240 {
241 \fontspec_complete_fontname:Nn \l_@@_fontname_sw_tl {#1}
242 }
243 % \end{macrocode}
244 %
245 %
246 % \paragraph{Bold (NFSS) Series}
247 % By default, \pkg{fontspec} uses the default bold series, \cs{bfdefault}.
248 % We want to be able to make this extensible. This code is not yet functional!
249 % \begin{macrocode}
250 %\@@_keys_define_code:nnn {fontspec-preparse-external} {BoldSeries}
251 % {
252 % \tl_gset:Nx \g_@@_curr_series_tl { #1 }
253 % \seq_put_right:Nx \l_@@_bf_series_seq { #1 }
254 % }
255 % \end{macrocode}
256 %
257 % \paragraph{Bold}
258 % This contains some stubb code to allow more than one bold font to be loaded.
259 % \begin{macrocode}
260 \@@_keys_define_code:nnn {fontspec-preparse-external} {BoldFont}
261 {
262 \tl_if_empty:nTF {#1}
263 {
264 \bool_set_true:N \l_@@_nobf_bool
265 }
266 {
267 \bool_set_false:N \l_@@_nobf_bool
268 \fontspec_complete_fontname:Nn \l_@@_curr_bfname_tl {#1}
269
270 \seq_if_empty:NT \l_@@_bf_series_seq
271 {
272 \tl_gset:Nx \g_@@_curr_series_tl {\bfdefault}
273 \seq_put_right:Nx \l_@@_bf_series_seq {\bfdefault}
274 }
275
276 \tl_if_eq:oeT \g_@@_curr_series_tl {\bfdefault}
277 {
278 \tl_set_eq:NN \l_@@_fontname_bf_tl \l_@@_curr_bfname_tl
279 }
280
281 \prop_put:NeV \l_@@_nfss_prop {BoldFont-\g_@@_curr_series_tl} \l_@@_curr_bfname_tl
282
283 %<debug>\typeout{Setting~bold~font~"\l_@@_curr_bfname_tl"~with~series~"\g_@@_curr_series_tl"}
284
285 }
286 }
287 % \end{macrocode}
288 %
289 % \paragraph{Bold italic/slanted}
290 % \begin{macrocode}
291 \@@_keys_define_code:nnn {fontspec-preparse-external} {BoldItalicFont}
292 {
293 \fontspec_complete_fontname:Nn \l_@@_fontname_bfit_tl {#1}
294 }
295 % \end{macrocode}
296 %
297 % \begin{macrocode}
298 \@@_keys_define_code:nnn {fontspec-preparse-external} {BoldSlantedFont}
299 {
300 \fontspec_complete_fontname:Nn \l_@@_fontname_bfsl_tl {#1}
301 }
302 % \end{macrocode}
303 %
304 % \begin{macrocode}
305 \@@_keys_define_code:nnn {fontspec-preparse-external} {BoldSwashFont}
306 {
307 \fontspec_complete_fontname:Nn \l_@@_fontname_bfsw_tl {#1}
308 }
309 % \end{macrocode}
310 %
311 % \paragraph{Small caps}
312 % Small caps isn't pre-parsed because it can vary with others above:
313 % \begin{macrocode}
314 \@@_keys_define_code:nnn {fontspec} {SmallCapsFont}
315 {
316 \tl_if_empty:nTF {#1}
317 {
318 \bool_set_true:N \l_@@_nosc_bool
319 }
320 {
321 \bool_set_false:N \l_@@_nosc_bool
322 \fontspec_complete_fontname:Nn \l_@@_fontname_sc_tl {#1}
323 }
324 }
325 % \end{macrocode}
326 %
327 %
328 % \subsubsection{Preparsed font features}
329 %
330 % \begin{macrocode}
331 \@@_keys_define_code:nnn {fontspec-preparse} {UprightFeatures}
332 {
333 \clist_put_right:Nn \l_@@_fontfeat_up_clist {#1}
334 }
335 \@@_keys_define_code:nnn {fontspec-preparse} {BoldFeatures}
336 {
337 \clist_put_right:Nn \l_@@_fontfeat_bf_clist {#1}
338 % \prop_put:NeV \l_@@_nfss_prop
339 % {BoldFont-\g_@@_curr_series_tl} \l_@@_curr_bfname_tl
340 }
341 \@@_keys_define_code:nnn {fontspec-preparse} {ItalicFeatures}
342 {
343 \clist_put_right:Nn \l_@@_fontfeat_it_clist {#1}
344 }
345 \@@_keys_define_code:nnn {fontspec-preparse} {BoldItalicFeatures}
346 {
347 \clist_put_right:Nn \l_@@_fontfeat_bfit_clist {#1}
348 }
349 \@@_keys_define_code:nnn {fontspec-preparse} {SlantedFeatures}
350 {
351 \clist_put_right:Nn \l_@@_fontfeat_sl_clist {#1}
352 }
353 \@@_keys_define_code:nnn {fontspec-preparse} {BoldSlantedFeatures}
354 {
355 \clist_put_right:Nn \l_@@_fontfeat_bfsl_clist {#1}
356 }
357 \@@_keys_define_code:nnn {fontspec-preparse} {SwashFeatures}
358 {
359 \clist_put_right:Nn \l_@@_fontfeat_sw_clist {#1}
360 }
361 \@@_keys_define_code:nnn {fontspec-preparse} {BoldSwashFeatures}
362 {
363 \clist_put_right:Nn \l_@@_fontfeat_bfsw_clist {#1}
364 }
365 % \end{macrocode}
366 % Note that small caps features can vary by shape, so these in fact \emph{aren't} pre-parsed.
367 % \begin{macrocode}
368 \@@_keys_define_code:nnn {fontspec} {SmallCapsFeatures}
369 {
370 \bool_if:NF \l_@@_firsttime_bool
371 {
372 \clist_put_right:Nn \l_@@_fontfeat_sc_clist {#1}
373 }
374 }
375 % \end{macrocode}
376 %
377 % \paragraph{Features varying by size}
378 % \begin{macrocode}
379 \@@_keys_define_code:nnn {fontspec-preparse} {SizeFeatures}
380 {
381 \clist_set:Nn \l_@@_sizefeat_clist {#1}
382 \clist_put_right:Nn \l_@@_fontfeat_up_clist { SizeFeatures = {#1} }
383 }
384 \@@_keys_define_code:nnn {fontspec-preparse-nested} {SizeFeatures}
385 {
386 \clist_set:Nn \l_@@_sizefeat_clist {#1}
387 \tl_if_empty:NT \l_@@_this_font_tl
388 { \tl_set:Nn \l_@@_this_font_tl { -- } } % needs to be non-empty as a flag
389 }
390 \@@_keys_define_code:nnn {fontspec-preparse-nested} {Font}
391 {
392 \tl_set:Nn \l_@@_this_font_tl {#1}
393 }
394 \@@_keys_define_code:nnn {fontspec} {SizeFeatures}
395 {
396 % dummy
397 }
398 \@@_keys_define_code:nnn {fontspec} {Font}
399 {
400 % dummy
401 }
402 % \end{macrocode}
403 %
404 % \begin{macrocode}
405 \@@_keys_define_code:nnn {fontspec-sizing} {Size}
406 {
407 \tl_set:Nn \l_@@_size_tl {#1}
408 }
409 \@@_keys_define_code:nnn {fontspec-sizing} {Font}
410 {
411 \fontspec_complete_fontname:Nn \l_@@_sizedfont_tl {#1}
412 }
413 % \end{macrocode}
414 %
415 % A hack to fix a test, needs to be investigated why necessary!
416 % \begin{macrocode}
417 \@@_keys_define_code:nnn {fontspec-opentype} {UprightFont} {}
418 \@@_keys_define_code:nnn {fontspec-opentype} {ItalicFont} {}
419 \@@_keys_define_code:nnn {fontspec-opentype} {SlantedFont} {}
420 \@@_keys_define_code:nnn {fontspec-opentype} {BoldFont} {}
421 \@@_keys_define_code:nnn {fontspec-opentype} {BoldItalicFont} {}
422 \@@_keys_define_code:nnn {fontspec-opentype} {BoldSlantedFont} {}
423 % \end{macrocode}
424 %
425 %
426 %
427 % \subsection{General font-independent features}
428 %
429 % These features can be applied to any font.
430 %
431 % \paragraph{NFSS encoding}
432 % For the very brave.
433 % \begin{macrocode}
434 \@@_keys_define_code:nnn {fontspec-preparse} {NFSSEncoding}
435 {
436 \tl_gset:Nx \g_@@_nfss_enc_tl { #1 }
437 }
438 % \end{macrocode}
439 %
440 % \paragraph{NFSS family}
441 % Interactions with other packages will sometimes require setting the NFSS family explicitly.
442 % (By default \pkg{fontspec} auto-generates one based on the font name.)
443 % \begin{macrocode}
444 \@@_keys_define_code:nnn {fontspec-preparse} {NFSSFamily}
445 {
446 \tl_set:Nx \l_@@_nfss_fam_tl { #1 }
447 }
448 % \end{macrocode}
449 %
450 % \paragraph{NFSS series/shape}
451 % This option looks similar in name but has a very different function.
452 % \begin{macrocode}
453 \@@_keys_define_code:nnn {fontspec-preparse} {FontFace}
454 {
455 \tl_clear:N \l_@@_this_font_tl
456 \clist_set:No \l_@@_arg_clist { \use_iii:nnn #1 }
457 \clist_set_eq:NN \l_@@_this_feat_clist \l_@@_arg_clist
458 \int_compare:nT { \clist_count:N \l_@@_arg_clist = 1 }
459 {
460 %<debug>\typeout{FontFace~ parsing:~ one~ clist~ item}
461 \tl_if_in:NnF \l_@@_arg_clist {=}
462 {
463 %<debug>\typeout{FontFace~ parsing:~ no~ equals~ =>~ font~ name~ only}
464 \tl_set_eq:NN \l_@@_this_font_tl \l_@@_arg_clist
465 \tl_clear:N \l_@@_this_feat_clist
466 }
467 }
468
469 \@@_add_nfssfont:nnnn
470 {\use_i:nnn #1} {\use_ii:nnn #1} {\l_@@_this_font_tl} {\l_@@_this_feat_clist}
471 }
472 % \end{macrocode}
473 %
474 %
475 %
476 % \paragraph{Scale}
477 % If the input isn't one of the pre-defined string options, then
478 % it's gotta be numerical. \cs{fontspec_calc_scale:n} and \cs{fontspec_calc_scale:nn}
479 % do all the work in the auto-scaling cases.
480 % \begin{macrocode}
481 \@@_keys_define_code:nnn {fontspec} {Scale}
482 {
483 \str_case:nnF {#1}
484 {
485 {MatchLowercase} { \@@_calc_scale:n {5} }
486 {MatchUppercase} { \@@_calc_scale:n {8} }
487 {MatchAveragecase} { \@@_calc_scale:nn {5} {8} }
488 }
489 { \tl_set:Nx \l_@@_scale_tl {#1} }
490 \@@_info:n {set-scale}
491 }
492 % \end{macrocode}
493 %
494 % \paragraph{ScaleAgain}
495 % \begin{macrocode}
496 \@@_keys_define_code:nnn {fontspec} {ScaleAgain}
497 {
498 \tl_if_empty:NT \l_@@_scale_tl { \tl_set:Nn \l_@@_scale_tl {1} }
499 \tl_set:Nx \l_@@_scale_tl { \fp_eval:n { #1 * \l_@@_scale_tl } }
500 \@@_info:n {set-scale}
501 }
502 % \end{macrocode}
503 %
504 % \begin{macro}{\@@_calc_scale:n}
505 % This macro calculates the amount of scaling between the default
506 % roman font and the (default shape of) the font being selected such
507 % that the font dimension that is input is equal for both. The only
508 % font dimensions that justify this are 5 (lowercase height)
509 % and 8 (uppercase height in \XeTeX).
510 %
511 % This script is executed for every extra shape, which seems wasteful,
512 % but allows alternate italic shapes from a separate font, say, to
513 % be loaded and to be auto-scaled correctly. Even if this would be ugly.
514 %
515 % To begin, change to \cs{rmfamily} but use internal commands in case cs{rmfamily}
516 % has been overwritten.
517 % (Note that changing \cs{rmfamily} with fontspec resets \cs{encodingdefault}
518 % appropriately.)
519 % \begin{macrocode}
520 \cs_new:Nn \@@_calc_scale:n
521 {
522 \group_begin:
523
524 \fontencoding { \encodingdefault }
525 \fontfamily { \familydefault }
526 \selectfont
527
528 \@@_set_font_dimen:NnN \l_@@_tmpa_dim {#1} \font
529 \@@_set_font_dimen:NnN \l_@@_tmpb_dim {#1} \l_@@_fontface_cs_tl
530
531 \tl_set:Nx \l_@@_scale_tl
532 {
533 \fp_eval:n { \dim_to_fp:n {\l_@@_tmpa_dim} /
534 \dim_to_fp:n {\l_@@_tmpb_dim} }
535 }
536
537 \exp_args:NNNx
538 \group_end:
539 \tl_set:Nx \l_@@_scale_tl { \l_@@_scale_tl }
540 }
541 % \end{macrocode}
542 % \end{macro}
543 %
544 %
545 % \begin{macro}{\@@_calc_scale:nn}
546 % This macro calls \cs{fontspec_calc_scale:n} twice
547 % and then sets the scale to the average of the two results.
548 % \begin{macrocode}
549 \cs_new:Nn \@@_calc_scale:nn
550 {
551 \group_begin:
552 \__fontspec_calc_scale:n {#1}
553 \tl_set_eq:NN \l_@@_tmp_tl \l_@@_scale_tl
554 \__fontspec_calc_scale:n {#2}
555 \tl_set:Nx \l_@@_scale_tl
556 {
557 \fp_eval:n { (\l_@@_tmp_tl + \l_@@_scale_tl)/2 }
558 }
559 \exp_args:NNNx
560 \group_end:
561 \tl_set:Nx \l_@@_scale_tl { \l_@@_scale_tl }
562 }
563 % \end{macrocode}
564 % \end{macro}
565 % \begin{macro}{\@@_set_font_dimen:NnN}
566 % This function sets the dimension |#1| (for font |#3|) to `fontdimen' |#2|
567 % for either font dimension 5 (x-height) or 8 (cap-height). If, for some
568 % reason, these return an incorrect `zero' value (as \cs{fontdimen8} might
569 % for a \texttt{.tfm} font), then we cheat and measure the height of a glyph.
570 % We assume in this case that the font contains either an `X' or an `x'.
571 % \begin{macrocode}
572 \cs_new:Nn \@@_set_font_dimen:NnN
573 {
574 \dim_set:Nn #1 { \fontdimen #2 #3 }
575 \dim_compare:nNnT #1 = {0pt}
576 {
577 \settoheight #1
578 {
579 \str_if_eq:nnTF {#3} {\font} \rmfamily #3
580 \int_case:nnF #2
581 {
582 {5} {x} % x-height
583 {8} {X} % cap-height
584 } {?} % "else" clause; never reached.
585 }
586 }
587 }
588 % \end{macrocode}
589 % \end{macro}
590 %
591 %
592 % \paragraph{Inter-word space}
593 % These options set the relevant \cmd\fontdimen s for the
594 % font being loaded.
595 % \begin{macrocode}
596 \@@_keys_define_code:nnn {fontspec} {WordSpace}
597 {
598 \bool_if:NF \l_@@_firsttime_bool
599 { \_fontspec_parse_wordspace:w #1,,,\q_stop }
600 }
601 \@@_aff_error:n {WordSpace}
602 % \end{macrocode}
603 %
604 % \begin{macro}{\_fontspec_parse_wordspace:w}
605 % This macro determines if the input to \feat{WordSpace} is
606 % of the form |{X}| or |{X,Y,Z}| and executes the font scaling.
607 % If the former input, it executes |{X,X,X}|.
608 % \begin{macrocode}
609 \cs_set:Npn \_fontspec_parse_wordspace:w #1,#2,#3,#4 \q_stop
610 {
611 \tl_if_empty:nTF {#4}
612 {
613 \tl_set:Nn \l_@@_wordspace_adjust_tl
614 {
615 \fontdimen 2 \font = #1 \fontdimen 2 \font
616 \fontdimen 3 \font = #1 \fontdimen 3 \font
617 \fontdimen 4 \font = #1 \fontdimen 4 \font
618 }
619 }
620 {
621 \tl_set:Nn \l_@@_wordspace_adjust_tl
622 {
623 \fontdimen 2 \font = #1 \fontdimen 2 \font
624 \fontdimen 3 \font = #2 \fontdimen 3 \font
625 \fontdimen 4 \font = #3 \fontdimen 4 \font
626 }
627 }
628 }
629 % \end{macrocode}
630 % \end{macro}
631 %
632 % \paragraph{Punctuation space}
633 % Scaling factor for the nominal \cmd\fontdimen \#7.
634 % \begin{macrocode}
635 \@@_keys_define_code:nnn {fontspec} {PunctuationSpace}
636 {
637 \str_case_e:nnF {#1}
638 {
639 {WordSpace}
640 {
641 \tl_set:Nn \l_@@_punctspace_adjust_tl
642 { \fontdimen 7 \font = 0 \fontdimen 2 \font }
643 }
644 {TwiceWordSpace}
645 {
646 \tl_set:Nn \l_@@_punctspace_adjust_tl
647 { \fontdimen 7 \font = 1 \fontdimen 2 \font }
648 }
649 }
650 {
651 \tl_set:Nn \l_@@_punctspace_adjust_tl
652 { \fontdimen 7 \font = #1 \fontdimen 7 \font }
653 }
654 }
655 \@@_aff_error:n {PunctuationSpace}
656 % \end{macrocode}
657 %
658 % \paragraph{Secret hook into the font-adjustment code}
659 %
660 % \begin{macrocode}
661 \@@_keys_define_code:nnn {fontspec} {FontAdjustment}
662 {
663 \tl_put_right:Nx \l_@@_postadjust_tl {#1}
664 }
665 % \end{macrocode}
666 %
667 % \paragraph{Letterspacing}
668 % \begin{macrocode}
669 \@@_keys_define_code:nnn {fontspec} {LetterSpace}
670 {
671 \@@_update_featstr:n {letterspace=#1}
672 }
673 % \end{macrocode}
674 %
675 % \paragraph{Hyphenation character}
676 % This feature takes one of three arguments: `\opt{None}',
677 % \meta{glyph}, or \meta{slot}. If the input isn't the first,
678 % and it's one character, then it's the second; otherwise, it's
679 % the third.
680 %
681 % LuaTeX decouples hyphenation from font settings, so only \verb|HyphenChar=None| works
682 % for that engine.
683 % \begin{macrocode}
684 \@@_keys_define_code:nnn {fontspec} {HyphenChar}
685 {
686 \str_if_eq:nnTF {#1} {None}
687 {
688 \tl_put_right:Nn \l_@@_postadjust_tl
689 { \@@_primitive_font_set_hyphenchar:Nn \font {-1} }
690 }
691 {
692 %<LU> \@@_warning:nx {only-xetex-feature} {HyphenChar}
693
694 \tl_if_single:nTF {#1}
695 { \tl_set:Nn \l_@@_hyphenchar_tl {`#1} }
696 { \tl_set:Nn \l_@@_hyphenchar_tl { #1} }
697
698 \exp_args:No \@@_primitive_font_glyph_if_exist:NnTF \l_@@_fontface_cs_tl {\l_@@_hyphenchar_tl}
699 {
700 \tl_put_right:Nn \l_@@_postadjust_tl
701 { \@@_primitive_font_set_hyphenchar:Nn \font { \l_@@_hyphenchar_tl } }
702 }
703 { \@@_error:nxx {no-glyph}{\l_fontspec_fontname_tl}{#1} }
704
705 }
706 }
707 \@@_aff_error:n {HyphenChar}
708 % \end{macrocode}
709 %
710 % \paragraph{Color}
711 % Test first if the color is a named l3color, then if it is a color from
712 % \pkg{xcolor}, which names its colours \texttt{\char`\\color@<name>}.
713 % If this fails the argument is assumed to be a hex color.
714 %
715 % \begin{macrocode}
716 \@@_keys_define_code:nnn {fontspec} {Color}
717 {
718 %<*XE>
719 \color_if_exist:nTF {#1}
720 {
721 \color_export:nnN {#1} {HTML}\l_@@_hexcol_tl
722 }
723 {
724 \cs_if_exist:cTF { \token_to_str:N \color@ #1 }
725 {
726 \convertcolorspec{named}{#1}{HTML}\l_@@_hexcol_tl
727 }
728 {
729 \int_compare:nTF { \tl_count:n {#1} == 6 }
730 { \tl_set:Nn \l_@@_hexcol_tl {#1} }
731 {
732 \int_compare:nTF { \tl_count:n {#1} == 8 }
733 { \fontspec_parse_colour:viii #1 }
734 {
735 \bool_if:NF \l_@@_firsttime_bool
736 { \@@_warning:nx {bad-colour} {#1} }
737 }
738 }
739 }
740 }
741 %</XE>
742 %<*LU>
743 \color_if_exist:nTF {#1}
744 {
745 \tl_set:Nn \l_@@_hexcol_tl {#1}
746 }
747 {
748 \cs_if_exist:cTF { \token_to_str:N \color@ #1 }
749 {
750 \convertcolorspec{named}{#1}{HTML}\l_@@_hexcol_tl
751 }
752 {
753 \int_compare:nTF { \tl_count:n {#1} == 6 }
754 { \tl_set:Nn \l_@@_hexcol_tl {#1} }
755 {
756 \int_compare:nTF { \tl_count:n {#1} == 8 }
757 { \fontspec_parse_colour:viii #1 }
758 {
759 \bool_if:NF \l_@@_firsttime_bool
760 { \@@_warning:nx {bad-colour} {#1} }
761 }
762 }
763 }
764 }
765 %</LU>
766 }
767 % \end{macrocode}
768 %
769 % \begin{macrocode}
770 \cs_set:Npn \fontspec_parse_colour:viii #1#2#3#4#5#6#7#8
771 {
772 \tl_set:Nn \l_@@_hexcol_tl {#1#2#3#4#5#6}
773 \tl_if_eq:NNF \l_@@_opacity_tl \c_@@_opacity_tl
774 {
775 \bool_if:NF \l_@@_firsttime_bool
776 { \@@_warning:nx {opa-twice-col} {#7#8} }
777 }
778 \tl_set:Nn \l_@@_opacity_tl {#7#8}
779 }
780 \aliasfontfeature{Color}{Colour}
781 % \end{macrocode}
782 % \begin{macrocode}
783 \@@_keys_define_code:nnn {fontspec} {Opacity}
784 {
785 \int_set:Nn \l_@@_tmp_int {255}
786 \@@_int_mult_truncate:Nn \l_@@_tmp_int { #1 }
787 \tl_if_eq:NNF \l_@@_opacity_tl \c_@@_opacity_tl
788 {
789 \bool_if:NF \l_@@_firsttime_bool
790 { \@@_warning:nx {opa-twice} {#1} }
791 }
792 \tl_set:Nx \l_@@_opacity_tl
793 {
794 %<LU> ,
795 \int_compare:nT { \l_@@_tmp_int <= "F } {0} % zero pad
796 \int_to_hex:n { \l_@@_tmp_int }
797 }
798 }
799 % \end{macrocode}
800 %
801 %
802 % \paragraph{Mapping}
803 % \begin{macrocode}
804 %<*XE>
805 \@@_keys_define_code:nnn {fontspec-aat} {Mapping}
806 {
807 \tl_set:Nn \l_@@_mapping_tl { #1 }
808 }
809 \@@_keys_define_code:nnn {fontspec-opentype} {Mapping}
810 {
811 \tl_set:Nn \l_@@_mapping_tl { #1 }
812 }
813 %</XE>
814 %<*LU>
815 \@@_keys_define_code:nnn {fontspec-opentype} {Mapping}
816 {
817 \str_if_eq:nnTF {#1} {tex-text}
818 {
819 \@@_warning:n {no-mapping-ligtex}
820 \msg_redirect_name:nnn {fontspec} {no-mapping-ligtex} {none}
821 \keys_set:nn {fontspec-opentype} { Ligatures=TeX }
822 }
823 { \@@_warning:n {no-mapping} }
824 }
825 %</LU>
826 % \end{macrocode}
827 %
828 %
829 % \subsubsection{Continuous font axes}
830 %
831 % \begin{macrocode}
832 %<*XE>
833 \@@_keys_define_code:nnn {fontspec} {Weight}
834 {
835 \@@_update_featstr:n{weight=#1}
836 }
837 %</XE>
838 %<LU>\@@_define_opentype_variation_axis:nn {Weight} {wght}
839 %<*XE>
840 \@@_keys_define_code:nnn {fontspec} {Width}
841 {
842 \@@_update_featstr:n{width=#1}
843 }
844 %</XE>
845 %<LU>\@@_define_opentype_variation_axis:nn {Width} {wdth}
846 \@@_define_opentype_variation_axis:nn {Slant} {slnt}
847 \@@_keys_define_code:nnn {fontspec} {OpticalSize}
848 %<*XE>
849 {
850 \bool_if:NTF \l_@@_ot_bool
851 {
852 \tl_set:Nn \l_@@_optical_size_tl {/ S = #1}
853 }
854 {
855 \bool_if:NT \l_@@_mm_bool
856 {
857 \@@_update_featstr:n { optical size = #1 }
858 }
859 }
860 \bool_if:nT { !\l_@@_ot_bool && !\l_@@_mm_bool }
861 {
862 \bool_if:NT \l_@@_firsttime_bool
863 { \@@_warning:nx {no-opticals} {\l_fontspec_fontname_tl} }
864 }
865 }
866 %</XE>
867 %<*LU>
868 {
869 \tl_set:Nn \l_@@_optical_size_tl {/ S = #1}
870 }
871 %</LU>
872 % \end{macrocode}
873 %
874 % For other potentially font specific variation axes, there is a raw setter available:
875 % \begin{macrocode}
876 \@@_keys_define_code:nnn {fontspec-opentype} {RawAxis}
877 {
878 \prop_gput_from_keyval:Nn \g_@@_rawvariations_prop {#1}
879 }
880 % \end{macrocode}
881 %
882 % \subsubsection{Variation instances}
883 %
884 % \begin{macrocode}
885 \@@_keys_define_code:nnn {fontspec-opentype} {Instance}
886 {
887 \tl_gset:Nn \g_@@_instance_tl {#1}
888 }
889 % \end{macrocode}
890 %
891 % \subsubsection{Font transformations}
892 % These are to be specified to apply directly to a font shape:
893 % \begin{macrocode}
894 \keys_define:nn {fontspec}
895 {
896 FakeSlant .code:n =
897 {
898 \@@_update_featstr:n {slant=#1}
899 },
900 FakeSlant .default:n = {0.2}
901 }
902 \keys_define:nn {fontspec}
903 {
904 FakeStretch .code:n =
905 {
906 \@@_update_featstr:n {extend=#1}
907 },
908 FakeStretch .default:n = {1.2}
909 }
910 \keys_define:nn {fontspec}
911 {
912 FakeBold .code:n =
913 {
914 \@@_update_featstr:n {embolden=#1}
915 },
916 FakeBold .default:n = {1.5}
917 }
918 % \end{macrocode}
919 % These are to be given to a shape that has no real bold/italic
920 % to signal that \pkg{fontspec} should automatically create `fake' shapes.
921 %
922 % The behaviour is currently that only if both \opt{AutoFakeSlant} \emph{and}
923 % \opt{AutoFakeBold} are specified, the bold italic is also faked.
924 %
925 % These features presently \emph{override} real shapes found in the font;
926 % in the future I'd like these features to be ignored in this case, instead.
927 % (This is just a bit harder to program in the current design of
928 % \pkg{fontspec}.)
929 % \begin{macrocode}
930 \keys_define:nn {fontspec}
931 {
932 AutoFakeSlant .code:n =
933 {
934 \bool_if:NT \l_@@_firsttime_bool
935 {
936 \tl_set:Nn \l_@@_fake_slant_tl {#1}
937 \clist_put_right:Nn \l_@@_fontfeat_it_clist {FakeSlant=#1}
938 \tl_set_eq:NN \l_@@_fontname_it_tl \l_fontspec_fontname_tl
939 \bool_set_false:N \l_@@_noit_bool
940
941 \tl_if_empty:NF \l_@@_fake_embolden_tl
942 {
943 \clist_put_right:Nx \l_@@_fontfeat_bfit_clist
944 {FakeBold=\l_@@_fake_embolden_tl}
945 \clist_put_right:Nx \l_@@_fontfeat_bfit_clist {FakeSlant=#1}
946 \tl_set_eq:NN \l_@@_fontname_bfit_tl \l_fontspec_fontname_tl
947 }
948 }
949 },
950 AutoFakeSlant .default:n = {0.2}
951 }
952 % \end{macrocode}
953 % Same but reversed:
954 % \begin{macrocode}
955 \keys_define:nn {fontspec}
956 {
957 AutoFakeBold .code:n =
958 {
959 \bool_if:NT \l_@@_firsttime_bool
960 {
961 \tl_set:Nn \l_@@_fake_embolden_tl {#1}
962 \clist_put_right:Nn \l_@@_fontfeat_bf_clist {FakeBold=#1}
963 \tl_set_eq:NN \l_@@_fontname_bf_tl \l_fontspec_fontname_tl
964 \bool_set_false:N \l_@@_nobf_bool
965
966 \tl_if_empty:NF \l_@@_fake_slant_tl
967 {
968 \clist_put_right:Nx \l_@@_fontfeat_bfit_clist
969 {FakeSlant=\l_@@_fake_slant_tl}
970 \clist_put_right:Nx \l_@@_fontfeat_bfit_clist {FakeBold=#1}
971 \tl_set_eq:NN \l_@@_fontname_bfit_tl \l_fontspec_fontname_tl
972 }
973 }
974 },
975 AutoFakeBold .default:n = {1.5}
976 }
977 % \end{macrocode}
978 %
979 %
980 % \subsubsection{Raw feature string}
981 % This allows savvy \XeTeX-ers to input font features manually if they have
982 % already memorised the OpenType abbreviations and don't mind not having error checking.
983 % \begin{macrocode}
984 \@@_keys_define_code:nnn {fontspec-opentype} {RawFeature}
985 {
986 \@@_update_featstr:n {#1}
987 }
988 \@@_keys_define_code:nnn {fontspec-aat} {RawFeature}
989 {
990 \@@_update_featstr:n {#1}
991 }
992 % \end{macrocode}
993 %
994 %
995 %
996 %
997 % \iffalse
998 % \begin{macrocode}
999 %</fontspec>
1000 % \end{macrocode}
1001 % \fi
1002
1003
1004 \endinput
1005
1006 % /©
1007 % ------------------------------------------------
1008 % The FONTSPEC package <latex3.github.io/fontspec>
1009 % ------------------------------------------------
1010 % Copyright 2022-2025 The LaTeX project, LPPL "maintainer"
1011 % Copyright 2004-2022 Will Robertson
1012 % Copyright 2009-2015 Khaled Hosny
1013 % Copyright 2013 Philipp Gesang
1014 % Copyright 2013-2016 Joseph Wright
1015 % ------------------------------------------------
1016 % This package is free software and may be redistributed and/or modified under
1017 % the conditions of the LaTeX Project Public License, version 1.3c or higher
1018 % (your choice): <http://www.latex-project.org/lppl/>.
1019 % ------------------------------------------------
1020 % ©/