diff options
author | Karl Berry <karl@freefriends.org> | 2017-01-22 22:34:22 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-01-22 22:34:22 +0000 |
commit | 4f70a140932277cc2ef6292e47ebe25c5d8c3230 (patch) | |
tree | 09c23cbf4ffd71fde1b8049902f73511adef85d9 /Master/texmf-dist/source/latex/fontspec/fontspec-user.dtx | |
parent | 60a21cad39ca930406807ef85e67b5b3f8407b2a (diff) |
fontspec (22jan17)
git-svn-id: svn://tug.org/texlive/trunk@43016 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/fontspec/fontspec-user.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/fontspec/fontspec-user.dtx | 257 |
1 files changed, 137 insertions, 120 deletions
diff --git a/Master/texmf-dist/source/latex/fontspec/fontspec-user.dtx b/Master/texmf-dist/source/latex/fontspec/fontspec-user.dtx index f9db2c2d2fc..cf9e95e1a17 100644 --- a/Master/texmf-dist/source/latex/fontspec/fontspec-user.dtx +++ b/Master/texmf-dist/source/latex/fontspec/fontspec-user.dtx @@ -11,18 +11,6 @@ % \end{macrocode} % \fi % -% \subsubsection{Helper macros for argument mangling} -% \begin{macrocode} -\cs_new:Nn \@@_pass_args:nnn - { - \IfNoValueTF {#2} - { \@@_post_arg:w {#1} {#3} } - { #1 {#2} {#3} } - } -\NewDocumentCommand \@@_post_arg:w { m m O{} } - { #1 {#3} {#2} } -% \end{macrocode} -% % \subsubsection{Font selection} % \begin{macro}{\fontspec} % This is the main command of the package that @@ -30,12 +18,9 @@ % font name and the optional requested features of that % font. Then this new font family is selected. % \begin{macrocode} -\NewDocumentCommand \fontspec { o m } - { \@@_pass_args:nnn \@@_fontspec:nn {#1} {#2} } - -\cs_new:Nn \@@_fontspec:nn +\NewDocumentCommand \fontspec { O{} m O{} } { - \fontspec_set_family:Nnn \f@family {#1} {#2} + \fontspec_set_family:Nnn \f@family {#1,#3} {#2} \fontencoding { \l_@@_nfss_enc_tl } \selectfont \ignorespaces @@ -44,50 +29,77 @@ % \end{macro} % % \begin{macro}{\setmainfont} -% \begin{macro}{\setsansfont} -% \begin{macro}{\setmonofont} % The following three macros perform equivalent operations setting % the default font for a % particular family: `roman', sans serif, or typewriter % (monospaced). I end them with |\normalfont| so that if they're % used in the document, the change registers immediately. % \begin{macrocode} -\DeclareDocumentCommand \setmainfont { o m } - { \@@_pass_args:nnn \@@_setmainfont:nn {#1} {#2} } - -\cs_new:Nn \@@_setmainfont:nn +\DeclareDocumentCommand \setmainfont { O{} m O{} } { - \fontspec_set_family:Nnn \rmdefault {#1}{#2} + \fontspec_set_family:Nnn \g_@@_rmfamily_family {#1,#3} {#2} + \tl_set_eq:NN \rmdefault \g_@@_rmfamily_family + \use:x { \exp_not:n { \DeclareRobustCommand \rmfamily } + { + \exp_not:N \fontencoding { \l_@@_nfss_enc_tl } + \exp_not:N \fontfamily { \g_@@_rmfamily_family } + \exp_not:N \selectfont + } + } + \str_if_eq_x:nnT {\familydefault} {\rmdefault} + { \tl_set_eq:NN \encodingdefault \l_@@_nfss_enc_tl } \normalfont \ignorespaces } - -\DeclareDocumentCommand \setsansfont { o m } - { \@@_pass_args:nnn \@@_setsansfont:nn {#1} {#2} } - -\cs_new:Nn \@@_setsansfont:nn +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\setsansfont} +% \begin{macrocode} +\DeclareDocumentCommand \setsansfont { O{} m O{} } { - \fontspec_set_family:Nnn \sfdefault {#1}{#2} + \fontspec_set_family:Nnn \g_@@_sffamily_family {#1,#3} {#2} + \tl_set_eq:NN \sfdefault \g_@@_sffamily_family + \use:x { \exp_not:n { \DeclareRobustCommand \sffamily } + { + \exp_not:N \fontencoding { \l_@@_nfss_enc_tl } + \exp_not:N \fontfamily { \g_@@_sffamily_family } + \exp_not:N \selectfont + } + } + \str_if_eq_x:nnT {\familydefault} {\sfdefault} + { \tl_set_eq:NN \encodingdefault \l_@@_nfss_enc_tl } \normalfont \ignorespaces } - -\DeclareDocumentCommand \setmonofont { o m } - { \@@_pass_args:nnn \@@_setmonofont:nn {#1} {#2} } - -\cs_new:Nn \@@_setmonofont:nn +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\setmonofont} +% \begin{macrocode} +\DeclareDocumentCommand \setmonofont { O{} m O{} } { - \fontspec_set_family:Nnn \ttdefault {#1}{#2} + \fontspec_set_family:Nnn \g_@@_ttfamily_family {#1,#3} {#2} + \tl_set_eq:NN \ttdefault \g_@@_ttfamily_family + \use:x { \exp_not:n { \DeclareRobustCommand \ttfamily } + { + \exp_not:N \fontencoding { \l_@@_nfss_enc_tl } + \exp_not:N \fontfamily { \g_@@_ttfamily_family } + \exp_not:N \selectfont + } + } + \str_if_eq_x:nnT {\familydefault} {\ttdefault} + { \tl_set_eq:NN \encodingdefault \l_@@_nfss_enc_tl } \normalfont \ignorespaces } % \end{macrocode} -% \end{macro} \end{macro} \end{macro} +% \end{macro} % % % \begin{macro}{\setromanfont} -% This is the old name for \cs{setmainfont}, retained -% for backwards compatibility. +% This is the old name for \cs{setmainfont}, retained \emph{ad infinitum} +% for backwards compatibility. It was deprecated in 2010. % \begin{macrocode} \cs_set_eq:NN \setromanfont \setmainfont % \end{macrocode} @@ -104,38 +116,22 @@ % document. \cmd\setboldmathrm\ is used for specifying which % fonts should be used in \cmd\boldmath. % \begin{macrocode} -\tl_new:N \g_@@_mathrm_tl -\tl_new:N \g_@@_bfmathrm_tl -\tl_new:N \g_@@_mathsf_tl -\tl_new:N \g_@@_mathtt_tl -\DeclareDocumentCommand \setmathrm { o m } - { \@@_pass_args:nnn \@@_setmathrm:nn {#1} {#2} } - -\cs_new:Nn \@@_setmathrm:nn +\DeclareDocumentCommand \setmathrm { O{} m O{} } { \fontspec_set_family:Nnn \g_@@_mathrm_tl {#1} {#2} } -\DeclareDocumentCommand \setboldmathrm { o m } - { \@@_pass_args:nnn \@@_setboldmathrm:nn {#1} {#2} } - -\cs_new:Nn \@@_setboldmathrm:nn +\DeclareDocumentCommand \setboldmathrm { O{} m O{} } { \fontspec_set_family:Nnn \g_@@_bfmathrm_tl {#1} {#2} } -\DeclareDocumentCommand \setmathsf { o m } - { \@@_pass_args:nnn \@@_setmathsf:nn {#1} {#2} } - -\cs_new:Nn \@@_setmathsf:nn +\DeclareDocumentCommand \setmathsf { O{} m O{} } { \fontspec_set_family:Nnn \g_@@_mathsf_tl {#1} {#2} } -\DeclareDocumentCommand \setmathtt { o m } - { \@@_pass_args:nnn \@@_setmathtt:nn {#1} {#2} } - -\cs_new:Nn \@@_setmathtt:nn +\DeclareDocumentCommand \setmathtt { O{} m O{} } { \fontspec_set_family:Nnn \g_@@_mathtt_tl {#1} {#2} } @@ -155,7 +151,6 @@ % \end{macro} % % \begin{macro}{\newfontfamily} -% \begin{macro}{\newfontface} % This macro takes the arguments of \cs{fontspec} with a prepended % \meta{instance cmd}. This command is used % when a specific font instance needs to be referred to repetitively @@ -167,12 +162,9 @@ % \cs{l_fontspec_family_tl}. This family is then used in a typical NFSS \cmd\fontfamily\ % declaration, saved in the macro name specified. % \begin{macrocode} -\DeclareDocumentCommand \newfontfamily { m o m } - { \@@_pass_args:nnn { \@@_newfontfamily:Nnn #1 } {#2} {#3} } - -\cs_new:Nn \@@_newfontfamily:Nnn +\DeclareDocumentCommand \newfontfamily { m O{} m O{} } { - \fontspec_set_family:cnn { g_@@_ \cs_to_str:N #1 _family } {#2} {#3} + \fontspec_set_family:cnn { g_@@_ \cs_to_str:N #1 _family } {#2,#4} {#3} \use:x { \exp_not:N \DeclareRobustCommand \exp_not:N #1 @@ -184,17 +176,17 @@ } } % \end{macrocode} +% \end{macro} +% +% \begin{macro}{\newfontface} % \cmd\newfontface\ uses the fact that if the argument to \feat{BoldFont}, etc., is empty (\ie, |BoldFont={}|), then no bold font is searched for. % \begin{macrocode} -\DeclareDocumentCommand \newfontface { m o m } - { \@@_pass_args:nnn { \@@_newfontface:Nnn #1 } {#2} {#3} } - -\cs_new:Nn \@@_newfontface:Nnn +\DeclareDocumentCommand \newfontface { m O{} m O{} } { - \newfontfamily #1 [ BoldFont={},ItalicFont={},SmallCapsFont={},#2 ] {#3} + \newfontfamily #1 [ BoldFont={},ItalicFont={},SmallCapsFont={},#2,#4 ] {#3} } % \end{macrocode} -% \end{macro} \end{macro} +% \end{macro} % % \subsubsection{Font feature selection} % @@ -205,10 +197,6 @@ % \cs{g_fontspec_default_fontopts_tl} (initialised empty), which is % concatenated with the individual macro choices in the % [...] macro. -% \begin{macrocode} -\clist_new:N \g_@@_default_fontopts_clist -\prop_new:N \g_@@_fontopts_prop -% \end{macrocode} % % \begin{macrocode} \DeclareDocumentCommand \defaultfontfeatures { t+ o m } @@ -251,28 +239,6 @@ } } % \end{macrocode} -% -% \begin{macro}{\@@_sanitise_fontname:Nn} -% Assigns font name |#2| to token list variable |#1| and strips extension(s) from it in the case of an external font. -% We strip spaces for luatex for consistency with luaotfload, although I'm not sure this is necessary any more. -% At one stage this also lowercased the name, but this step has been removed unless someone can remind me why it was necessary. -% \begin{macrocode} -\cs_new:Nn \@@_sanitise_fontname:Nn - { - \tl_set:Nx #1 {#2} -%<luatex> \tl_remove_all:Nn #1 {~} - \clist_map_inline:Nn \l_@@_extensions_clist - { - \tl_if_in:NnT #1 {##1} - { - \tl_remove_once:Nn #1 {##1} -% \keys_set:nn {fontspec-preparse-external} { Extension = ##1 } - \clist_map_break: - } - } - } -% \end{macrocode} -% \end{macro} % \end{macro} % % @@ -290,16 +256,16 @@ % % The default options are \emph{not} applied (which is why % \cs{g_fontspec_default_fontopts_tl} is emptied inside the group; this is allowed -% as \cmd\l_fontspec_family_tl\ is globally defined in \cmd\fontspec_select:nn), so this +% as \cmd\l_fontspec_family_tl\ is globally defined in \cmd\@@_select_font_family:nn), so this % means that the only added features to the font are strictly those % specified by this command. % % \cs{addfontfeature} is defined as an alias, as I found that I % often typed this instead when adding only a single font feature. % \begin{macrocode} -\bool_new:N \l_@@_disable_defaults_bool \DeclareDocumentCommand \addfontfeatures {m} { +%<debug> \typeout{^^J::::::::::::::::::::::::::::::::::^^J: addfontfeatures} \fontspec_if_fontspec_font:TF { \group_begin: @@ -307,9 +273,10 @@ \prop_get:cnN {g_@@_ \f@family _prop} {options} \l_@@_options_tl \prop_get:cnN {g_@@_ \f@family _prop} {fontname} \l_@@_fontname_tl \bool_set_true:N \l_@@_disable_defaults_bool +%<debug> \typeout{ \@@_select_font_family:nn { \l_@@_options_tl , #1 } {\l_@@_fontname_tl} } \use:x { - \exp_not:N \fontspec_select:nn + \@@_select_font_family:nn { \l_@@_options_tl , #1 } {\l_@@_fontname_tl} } \group_end: @@ -324,8 +291,6 @@ % \end{macrocode} % \end{macro} % -% -% % \subsubsection{Defining new font features} % % \begin{macro}{\newfontfeature} @@ -355,16 +320,15 @@ \DeclareDocumentCommand \newAATfeature {mmmm} { \keys_if_exist:nnF { fontspec } {#1} - { \@@_define_font_feature:n {#1} } + { \@@_define_aat_feature_group:n {#1} } \keys_if_choice_exist:nnnT {fontspec} {#1} {#2} { \@@_warning:nxx {feature-option-overwrite} {#1} {#2} } - \@@_define_feature_option:nnnnn {#1}{#2}{#3}{#4}{} + \@@_define_aat_feature:nnnn {#1}{#2}{#3}{#4} } % \end{macrocode} % \end{macro} % % \begin{macro}{\newopentypefeature} -% \begin{macro}{\newICUfeature} % This command assigns a new OpenType feature by its abbreviation (|#2|) to a new name (|#1|). % Better than \cmd\newfontfeature\ because it checks if the feature exists in the % font it's being used for. @@ -372,52 +336,68 @@ \DeclareDocumentCommand \newopentypefeature {mmm} { \keys_if_exist:nnF { fontspec / options } {#1} - { \@@_define_font_feature:n {#1} } + { \@@_define_opentype_feature_group:n {#1} } \keys_if_choice_exist:nnnT {fontspec} {#1} {#2} { \@@_warning:nxx {feature-option-overwrite} {#1} {#2} } - \@@_define_feature_option:nnnnn {#1}{#2}{}{}{#3} + \@@_define_opentype_feature:nnn {#1}{#2}{#3} } -\cs_set_eq:NN \newICUfeature \newopentypefeature % deprecated % \end{macrocode} % \end{macro} +% +% \begin{macro}{\newICUfeature} +% \begin{macrocode} +\cs_set_eq:NN \newICUfeature \newopentypefeature % deprecated +% \end{macrocode} % \end{macro} % % % \begin{macro}{\aliasfontfeature} -% \begin{macro}{\aliasfontfeatureoption} % User commands for renaming font features and font feature options. % \begin{macrocode} -\bool_new:N \l_@@_alias_bool \DeclareDocumentCommand \aliasfontfeature {mm} { \bool_set_false:N \l_@@_alias_bool \clist_map_inline:nn - { fontspec, fontspec-preparse, fontspec-preparse-external, + { fontspec, fontspec-opentype, fontspec-aat, fontspec-preparse, fontspec-preparse-external, fontspec-preparse-nested, fontspec-renderer } { \keys_if_exist:nnT {##1} {#1} { \bool_set_true:N \l_@@_alias_bool - \@@_alias_font_feature:nnn {##1} {#1} {#2} + \keys_define:nn {##1} + { #2 .code:n = { \keys_set:nn {##1} { #1 = {####1} } } } } } \bool_if:NF \l_@@_alias_bool { \@@_warning:nx {rename-feature-not-exist} {#1} } } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\aliasfontfeatureoption} +% \begin{macrocode} +\DeclareDocumentCommand \aliasfontfeatureoption {mmm} + { + \bool_set_false:N \l_@@_alias_bool -\cs_set:Nn \@@_alias_font_feature:nnn - { - \keys_define:nn {#1} - { #3 .code:n = { \keys_set:nn {#1} { #2 = {##1} } } } - } + \clist_map_inline:Nn \g_@@_all_keyval_modules_clist + { -\DeclareDocumentCommand \aliasfontfeatureoption {mmm} - { \keys_define:nn { fontspec / #1 } { #3 .meta:n = {#2} } } + \keys_if_exist:nnT {##1} {#1} + { + \bool_set_true:N \l_@@_alias_bool + \keys_define:nn { ##1 / #1 } { #3 .meta:n = {#2} } + } + } + + \bool_if:NF \l_@@_alias_bool + { \@@_warning:nx {rename-feature-not-exist} {#1} } + } % \end{macrocode} -% \end{macro} \end{macro} +% \end{macro} % % \begin{macro}{\newfontscript} % Mostly used internally, but also possibly useful for users, to define new OpenType @@ -453,6 +433,43 @@ \DeclareFontsExtensions{.otf,.ttf,.OTF,.TTF,.ttc,.TTC,.dfont} % \end{macrocode} % \end{macro} + + +% \begin{macro}{\IfFontFeaturesTF} +% \begin{macrocode} +\DeclareDocumentCommand \IfFontFeatureActiveTF {mmm} + { +%<debug> \typeout{^^J:::::::::::::::::::::::::::::::::::::::::::::::} +%<debug> \typeout{:IfFontFeatureActiveTF \exp_not:n{{#1}{#2}{#3}}} + \@@_if_font_feature:nTF {#1} {#2} {#3} + } +% \end{macrocode} +% +% \begin{macrocode} +\prg_new_conditional:Nnn \@@_if_font_feature:n {TF} + { + \tl_gclear:N \g_@@_single_feat_tl + \group_begin: + \@@_font_suppress_not_found_error: + \@@_init: + \bool_set_true:N \l_@@_ot_bool + \bool_set_true:N \l_@@_never_check_bool + \bool_set_false:N \l_@@_firsttime_bool + \clist_clear:N \l_@@_fontfeat_clist + \@@_get_features:Nn \l_@@_rawfeatures_sclist {#1} + \group_end: + +%<debug> \typeout{:::> \exp_not:N\l_@@_rawfeatures_sclist->~{\l_@@_rawfeatures_sclist}} +%<debug> \typeout{:::> \exp_not:N\g_@@_single_feat_tl->~{\g_@@_single_feat_tl}} + + \tl_if_empty:NTF \g_@@_single_feat_tl { \prg_return_false: } + { + \exp_args:NV \fontspec_if_current_feature:nTF \g_@@_single_feat_tl + { \prg_return_true: } { \prg_return_false: } + } + } +% \end{macrocode} +% \end{macro} % % \iffalse % \begin{macrocode} |