Skip to content

Commit

Permalink
Variable font support for LuaLaTeX
Browse files Browse the repository at this point in the history
  • Loading branch information
zauguin committed Jun 24, 2022
1 parent d0ebbc7 commit 8e3494e
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 24 deletions.
35 changes: 32 additions & 3 deletions fontspec-code-internal.dtx
Expand Up @@ -455,7 +455,7 @@
\prop_gput:cnx {g_@@_fontinfo_ \g_@@_nfss_family_tl _prop} {fontdef}
{
\@@_construct_font_call:nn {\l_fontspec_fontname_tl}
{ \l_@@_pre_feat_sclist \g_@@_rawfeatures_sclist }
{ \l_@@_pre_feat_sclist \g_@@_rawfeatures_sclist \@@_get_variations: }
}
\prop_gput:cnV {g_@@_fontinfo_ \g_@@_nfss_family_tl _prop} {script-num} \l_@@_script_int
\prop_gput:cnV {g_@@_fontinfo_ \g_@@_nfss_family_tl _prop} {lang-num} \l_@@_language_int
Expand Down Expand Up @@ -800,7 +800,7 @@
%<debug>\typeout{====~Setup~NFSS~shape:~<\l_@@_size_tl>~\l_fontspec_fontname_tl}

\@@_get_features:n { #2 , #3 , #4 }
%<debug>\typeout{====~Gathered~features:~\g_@@_rawfeatures_sclist}
%<debug>\typeout{====~Gathered~features:~\g_@@_rawfeatures_sclist \@@_get_variations:}

\tl_if_empty:NF \l_@@_scale_tl
{
Expand All @@ -811,7 +811,7 @@
{
<\l_@@_size_tl> \l_@@_scale_tl
\@@_construct_font_call:nn { \l_fontspec_fontname_tl }
{ \l_@@_pre_feat_sclist \g_@@_rawfeatures_sclist }
{ \l_@@_pre_feat_sclist \g_@@_rawfeatures_sclist \@@_get_variations: }
}
}
% \end{macrocode}
Expand Down Expand Up @@ -1062,6 +1062,33 @@
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_get_variations:}
% \cmd{\@@_get_variations:} builds the feature string representing the
% current variation instance and/or axis settings.
% \begin{macrocode}
\cs_generate_variant:Nn \tl_tail:n { e }
\cs_new:Nn \@@_format_axis:nn
{
, #1 = #2
}
\cs_new:Nn \@@_get_variations:
{
\tl_if_empty:NF \g_@@_instance_tl
{
instance = { \g_@@_instance_tl };
}
\prop_if_empty:NF \g_@@_rawvariations_prop
{
axis = {
\tl_tail:e {
\prop_map_function:NN \g_@@_rawvariations_prop \@@_format_axis:nn
}
};
}
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Initialisation}
%
% \begin{macro}{\@@_init:}
Expand Down Expand Up @@ -1099,6 +1126,8 @@
\cs_new:Nn \@@_init_fontface:
{
\tl_gclear:N \g_@@_rawfeatures_sclist
\prop_gclear:N \g_@@_rawvariations_prop
\tl_gclear:N \g_@@_instance_tl
\tl_clear:N \l_@@_scale_tl
\tl_set_eq:NN \l_@@_opacity_tl \c_@@_opacity_tl
\tl_set_eq:NN \l_@@_hexcol_tl \c_@@_hexcol_tl
Expand Down
24 changes: 24 additions & 0 deletions fontspec-code-keyval.dtx
Expand Up @@ -782,14 +782,21 @@
% \subsubsection{Continuous font axes}
%
% \begin{macrocode}
%<*XE>
\@@_keys_define_code:nnn {fontspec} {Weight}
{
\@@_update_featstr:n{weight=#1}
}
%</XE>
%<LU>\@@_define_opentype_variation_axis:nn {Weight} {wght}
%<*XE>
\@@_keys_define_code:nnn {fontspec} {Width}
{
\@@_update_featstr:n{width=#1}
}
%</XE>
%<LU>\@@_define_opentype_variation_axis:nn {Width} {wdth}
\@@_define_opentype_variation_axis:nn {Slant} {slnt}
\@@_keys_define_code:nnn {fontspec} {OpticalSize}
%<*XE>
{
Expand Down Expand Up @@ -817,6 +824,23 @@
%</LU>
% \end{macrocode}
%
% For other potentially font specific variation axes, there is a raw setter available:
% \begin{macrocode}
\@@_keys_define_code:nnn {fontspec-opentype} {RawAxis}
{
\prop_gput_from_keyval:Nn \g_@@_rawvariations_prop {#1}
}
% \end{macrocode}
%
% \subsubsection{Variation instances}
%
% \begin{macrocode}
\@@_keys_define_code:nnn {fontspec-opentype} {Instance}
{
\tl_gset:Nn \g_@@_instance_tl {#1}
}
% \end{macrocode}
%
% \subsubsection{Font transformations}
% These are to be specified to apply directly to a font shape:
% \begin{macrocode}
Expand Down
16 changes: 16 additions & 0 deletions fontspec-code-opentype.dtx
Expand Up @@ -10,6 +10,22 @@
%
%
%
% \begin{macro}{\@@_define_opentype_variation_axis:nn}
% \begin{macrocode}
\cs_new:Nn \@@_define_opentype_variation_axis:nn
{
\keys_define:nn {fontspec-opentype}
{
#1 .code:n = {
\prop_gput:Nnn \g_@@_rawvariations_prop { #2 } { ##1 }
},
#1 .value_required:n = true,
#1 .groups:n = {opentype},
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_define_opentype_feature_group:n}
% \begin{macrocode}
\cs_new:Nn \@@_define_opentype_feature_group:n
Expand Down
2 changes: 2 additions & 0 deletions fontspec-code-vars.dtx
Expand Up @@ -152,6 +152,7 @@
\prop_new:N \g_@@_strong_prop
\prop_new:N \g_@@_fontid_family_prop
\prop_new:N \g_@@_family_int_prop
\prop_new:N \g_@@_rawvariations_prop
% \end{macrocode}
%
% \paragraph{Token lists}
Expand Down Expand Up @@ -289,6 +290,7 @@
\tl_new:N \l_@@_punctspace_adjust_tl
\tl_new:N \l_@@_wordspace_adjust_tl
\tl_new:N \l_@@_postadjust_tl
\tl_new:N \g_@@_instance_tl
% \end{macrocode}
%
% \begin{macrocode}
Expand Down
84 changes: 84 additions & 0 deletions fontspec-doc-featset.tex
Expand Up @@ -608,6 +608,90 @@ \subsection{Letter spacing}
In particular, small amounts of letter spacing can be very useful, when setting small caps or all caps titles.
Also see the OpenType \opt{Uppercase} option of the \feat{Letters} feature (\vref{sec:letters}).


\section{Variable fonts} \label{sec:variable}

OpenType variable fonts and Multiple Master fonts are parameterised over
orthogonal font axes, allowing continuous selection along such features
as weight, width, and optical size.

Currently OpenType variable fonts are only supported in \LuaTeX, while
Multiple Master fonts only work with \XeTeX.

\subsection{Optical font sizes} \label{sec:aat-opticalsize}
Whereas traditional OpenType fonts will have only a few separate
optical sizes, a Variable or Multiple Master font's optical size can be
specified over a continuous range. Unfortunately, this flexibility makes
it harder to create an automatic interface through \LaTeX, and the
optical size for a Variable or Multiple Master font must always be specified
explicitly.
\begin{Verbatim}
\fontspec{Minion MM Roman}[OpticalSize=11]
MM optical size test \\
\fontspec{Minion MM Roman}[OpticalSize=47]
MM optical size test \\
\fontspec{Minion MM Roman}[OpticalSize=71]
MM optical size test \\
\end{Verbatim}


\subsection{Weight} \label{sec:variable-weight}
For fonts with a variable weight axis, the weight can be specified through the
\feat{Weight} feature. The value should be between 0 and 1000, where typically
400 corresponds to regular wight and 700 is a bold font.
\begin{Verbatim}
\fontspec{Source Serif Variable}[Weight=700]
Bold \\
\fontspec{Source Serif Variable}[Weight=200]
Extra Light \\
\end{Verbatim}


\subsection{Width} \label{sec:variable-width}
Similarly, the \feat{Width} feature allows specifying the value of the width axis,
where the value is a percentage of normal width.
\begin{Verbatim}
\fontspec{Noto Serif}[Width=100]
Normal Width \\
\fontspec{Noto Serif}[Width=75]
Condensed \\
\end{Verbatim}

\subsection{Slant} \label{sec:variable-slant}
Also fonts with a slant axis can be controlled with the \feat{Slant} feature.
In a standard compliant font the value should specify the clockwise angle in degree
the glyphs are slanted. Therefore for a typical forward leaning slanted font, a
negative value should be passed.

Many fonts use this feature in non-standard ways, so you might have to experiment
a bit with the value.
\begin{Verbatim}
\fontspec{Roboto Flex}[Slant=0]
Upright \\
\fontspec{Roboto Flex}[Slant=-5]
Slanted \\
\end{Verbatim}

\subsection{Other axes} \label{sec:variable-raw}
For OpenType variable fonts, additional axis values can be specified
if the four letter tag of these axes is known.
Than their value can be set with the \feat{RawAxis} feature:
\begin{Verbatim}
\fontspec{Noto Serif}[RawAxis={CTGR=100}]
Maximal contrast \\
\fontspec{Noto Serif}[RawAxis={CTGR=0}]
Regular contrast \\
\end{Verbatim}

\subsection{Instances} \label{sec:variable-instances}
Instead of manually setting axis values, many fonts contain named instances which are predefined settings of all axes.

To select such an instance, the \feat{Instance} feature can be used:
\begin{Verbatim}
\fontspec{Noto Serif}[Instance=ExtraCondensed Bold]
This is in extra condensed bold.
\end{Verbatim}

\end{document}

%
Expand Down
21 changes: 0 additions & 21 deletions fontspec-doc-xetex.tex
Expand Up @@ -58,27 +58,6 @@ \subsection{Different font technologies: \AAT, OpenType, and Graphite}\label{sec
select the \opt{OpenType} renderer.}


\subsection{Optical font sizes} \label{sec:aat-opticalsize}

Multiple Master fonts are parameterised over
orthogonal font axes, allowing continuous selection along such
features as weight, width, and optical size.
Whereas an OpenType font will have only a few separate
optical sizes, a Multiple Master font's optical size can be
specified over a continuous range. Unfortunately, this flexibility makes
it harder to create an automatic interface through \LaTeX, and the
optical size for a Multiple Master font must always be specified
explicitly.
\begin{Verbatim}
\fontspec{Minion MM Roman}[OpticalSize=11]
MM optical size test \\
\fontspec{Minion MM Roman}[OpticalSize=47]
MM optical size test \\
\fontspec{Minion MM Roman}[OpticalSize=71]
MM optical size test \\
\end{Verbatim}


\subsection{Vertical typesetting}

\XeTeX\ provides for vertical typesetting simply with the ability to rotate
Expand Down
9 changes: 9 additions & 0 deletions testfiles/fontload-variable.luatex.tlg
@@ -0,0 +1,9 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
Default: 9.45pt
Bold: 9.86pt
Black: 10.16pt
Black condensed: 8.98pt
Extracondensed Bold: 8.07pt
***************
Compilation 1 of test file completed with exit status 0
33 changes: 33 additions & 0 deletions testfiles/fontload-variable.lvt
@@ -0,0 +1,33 @@
\input{fontspec-testsetup.tex}

\usepackage{fontspec}
\usepackage{iftex}
\ifluahbtex
\defaultfontfeatures{Renderer=HarfBuzz}
\fi

\begin{document}

\START

\fontspec{NotoSerif-VF.ttf}
\setbox0\hbox{m}
\MSG{Default: \the\wd0}

\fontspec[Weight=700]{NotoSerif-VF.ttf}
\setbox0\hbox{m}
\MSG{Bold: \the\wd0}

\fontspec[Weight=900]{NotoSerif-VF.ttf}
\setbox0\hbox{m}
\MSG{Black: \the\wd0}

\fontspec[Weight=900, Width=75]{NotoSerif-VF.ttf}
\setbox0\hbox{m}
\MSG{Black condensed: \the\wd0}

\fontspec[Instance=ExtraCondensed Bold]{NotoSerif-VF.ttf}
\setbox0\hbox{m}
\MSG{Extracondensed Bold: \the\wd0}

\end{document}
9 changes: 9 additions & 0 deletions testfiles/fontload-variable.xetex.tlg
@@ -0,0 +1,9 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
Default: 9.45pt
Bold: 9.45pt
Black: 9.45pt
Black condensed: 9.45pt
Extracondensed Bold: 9.45pt
***************
Compilation 1 of test file completed with exit status 0

0 comments on commit 8e3494e

Please sign in to comment.