Skip to content

Commit

Permalink
more clever checking for small caps
Browse files Browse the repository at this point in the history
closes #517
  • Loading branch information
wspr committed May 11, 2024
1 parent 4ce232c commit ab0d464
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 37 deletions.
2 changes: 1 addition & 1 deletion fontspec-code-api.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
\prop_get:cnN {g_@@_fontinfo_ \f@family _prop} {script-tag} \l_@@_script_tl
\prop_get:cnN {g_@@_fontinfo_ \f@family _prop} {lang-tag} \l_@@_lang_tl

\@@_check_ot_feat:NnTF \font {#1} {\prg_return_true:} {\prg_return_false:}
\@@_check_ot_feat:NnnnTF \font {#1} {\l_@@_lang_tl} {\l_@@_script_tl} {\prg_return_true:} {\prg_return_false:}
}
{
\prg_return_false:
Expand Down
59 changes: 35 additions & 24 deletions fontspec-code-feat-opentype.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -489,37 +489,42 @@
}
}
}
\cs_new:Nn \fontspec_default_script:nn
% \end{macrocode}
% When script is not explicitly requested, use this list:
% \begin{macrocode}
\clist_new:N \g_@@_default_scripts_clist
\cs_new:Nn \fontspec_default_script:n
{
\keys_define:nn {fontspec-opentype} { Script / #1 .code:n =
\clist_gset:Nn \g_@@_default_scripts_clist {#1}
}
\fontspec_default_script:n {latn,DFLT}
% \end{macrocode}
%
% \begin{macrocode}
\keys_define:nn {fontspec-opentype} { Script / CustomDefault .code:n =
{
%<debug>\typeout{Trying~CustomDefault~Script}
\bool_set_false:N \l_@@_scriptlang_exist_bool
\clist_map_inline:Nn \g_@@_default_scripts_clist
{
%<debug>\typeout{Trying~[Script=#1:#2]}
\bool_set_false:N \l_@@_scriptlang_exist_bool
\clist_map_inline:nn {#2}
\exp_args:No \@@_check_script:NnT \l_@@_fontface_cs_tl {##1}
{
\exp_args:No \@@_check_script:NnT \l_@@_fontface_cs_tl {####1}
{
%<debug>\typeout{Script~tag~found:~####1}
\tl_set:Nn \l_@@_script_name_tl {#1}
\tl_set:Nn \l_@@_script_tl {####1}
\int_set:Nn \l_@@_script_int {\l_@@_strnum_int}
\bool_set_true:N \l_@@_scriptlang_exist_bool
\tl_gset:Nx \g_@@_single_feat_tl { script=####1 }
\clist_map_break:
}
%<debug>\typeout{Script~tag~found:~##1}
\tl_set:Nn \l_@@_script_name_tl {Default (##1)}
\tl_set:Nn \l_@@_script_tl {##1}
\int_set:Nn \l_@@_script_int {\l_@@_strnum_int}
\bool_set_true:N \l_@@_scriptlang_exist_bool
\tl_gset:Nx \g_@@_single_feat_tl { script=##1 }
\clist_map_break:
}
\bool_if:NF \l_@@_scriptlang_exist_bool
{
}
\bool_if:NF \l_@@_scriptlang_exist_bool
{
%<debug>\typeout{Script~not~found!}
\tl_clear:N \l_@@_script_name_tl
}
\tl_clear:N \l_@@_script_name_tl
}
}
}
% \end{macrocode}
% When script is not explicitly requested, use this list:
% \begin{macrocode}
\fontspec_default_script:nn {CustomDefault} {latn,DFLT}
}
% \end{macrocode}
%
%
Expand Down Expand Up @@ -574,6 +579,12 @@
% language is hardcoded to have a zero value,
% although this might be some \XeTeX-specific thing.
% \begin{macrocode}
\clist_new:N \g_@@_default_langs_clist
\cs_new:Nn \fontspec_default_lang:n
{
\clist_gset:Nn \g_@@_default_langs_clist {#1}
}
\fontspec_default_lang:n {dflt}
\@@_keys_define_code:nnn {fontspec-opentype} { Language / Default }
{
\tl_set:Nn \l_@@_lang_tl {dflt}
Expand Down
17 changes: 16 additions & 1 deletion fontspec-code-internal.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,23 @@
% \begin{macrocode}
\cs_new:Nn \@@_make_ot_smallcaps:TF
{
\exp_args:No \@@_check_ot_feat:NnTF \l_@@_fontface_cs_tl {smcp} {#1} {#2}
\bool_set_false:N \l_@@_tmpa_bool
\exp_args:Ne \clist_map_inline:nn { \l_@@_lang_tl , \g_@@_default_langs_clist }
{
\exp_args:Ne \clist_map_inline:nn { \l_@@_script_tl , \g_@@_default_scripts_clist }
{
\exp_args:No \@@_check_ot_feat:NnnnT \l_@@_fontface_cs_tl {smcp} {##1} {####1}
{
%<debug>\typeout{SMCP~found~for~script/lang: ####1/##1~-~assuming~okay}
\bool_set_true:N \l_@@_tmpa_bool
\clist_map_break:
}
}
}
\bool_if:NTF \l_@@_tmpa_bool {#1} {#2}
}
% \end{macrocode}
% \begin{macrocode}
\cs_new:Nn \@@_make_smallcaps:TF
{
\bool_if:NTF \l_@@_ot_bool
Expand Down
12 changes: 1 addition & 11 deletions fontspec-code-opentype.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_check_ot_feat:NnTF}
% \begin{macro}{\@@_check_ot_feat:NnnnTF}
% This macro takes an OpenType feature tag and checks if it exists in the current
% font/script/language.
Expand All @@ -267,15 +266,7 @@
% number corresponding to `|latn|'. The language used is \cmd\l_@@_language_int,
% by default |0|, the `default language'.
% \begin{macrocode}
\prg_new_conditional:Nnn \@@_check_ot_feat:Nn {TF,F}
{
\@@_check_ot_feat:NnnnTF #1 {#2} {\l_@@_lang_tl} {\l_@@_script_tl}
{\prg_return_true:} {\prg_return_false:}
}
% \end{macrocode}
%
% \begin{macrocode}
\prg_new_conditional:Nnn \@@_check_ot_feat:Nnnn {TF,F}
\prg_new_conditional:Nnn \@@_check_ot_feat:Nnnn {TF,T,F}
{
\bool_if:NTF \l_@@_never_check_bool
{ \prg_return_true: }
Expand Down Expand Up @@ -325,7 +316,6 @@
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{OpenType feature information}
%
Expand Down
8 changes: 8 additions & 0 deletions testfiles/small-caps-lang.luatex.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
SMALL CAPS (PASS)
SMALL CAPS (PASS)
SMALL CAPS (PASS)
SMALL CAPS (PASS)
***************
Compilation 1 of test file completed with exit status 0
37 changes: 37 additions & 0 deletions testfiles/small-caps-lang.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
\input{fontspec-testsetup.tex}

\usepackage{fontspec}

\begin{document}

\setmainfont{EBGaramond-Regular.otf}
{abc \scshape abc}
\ExplSyntaxOn
\fontspec_if_small_caps:TF { \MSG{SMALL~CAPS~(PASS)} }{ \MSG{NO~SMALL~CAPS~(FAIL)} }
\ExplSyntaxOff

\SEPARATOR

\setmainfont{EBGaramond-Regular.otf}[Script=CJK] % font does NOT have script=hani
{abc \scshape abc}
\ExplSyntaxOn
\fontspec_if_small_caps:TF { \MSG{SMALL~CAPS~(PASS)} }{ \MSG{NO~SMALL~CAPS~(FAIL)} }
\ExplSyntaxOff

\SEPARATOR

\setmainfont{EBGaramond-Regular.otf}[Language=English] % font does NOT have language=ENG
{abc \scshape abc}
\ExplSyntaxOn
\fontspec_if_small_caps:TF { \MSG{SMALL~CAPS~(PASS)} }{ \MSG{NO~SMALL~CAPS~(FAIL)} }
\ExplSyntaxOff

\SEPARATOR

\setmainfont{EBGaramond-Regular.otf}[Language=Default] % font does NOT have language=ENG
{abc \scshape abc}
\ExplSyntaxOn
\fontspec_if_small_caps:TF { \MSG{SMALL~CAPS~(PASS)} }{ \MSG{NO~SMALL~CAPS~(FAIL)} }
\ExplSyntaxOff

\end{document}
8 changes: 8 additions & 0 deletions testfiles/small-caps-lang.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
SMALL CAPS (PASS)
SMALL CAPS (PASS)
SMALL CAPS (PASS)
SMALL CAPS (PASS)
***************
Compilation 1 of test file completed with exit status 0

0 comments on commit ab0d464

Please sign in to comment.