Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable #467

Merged
merged 9 commits into from
Jun 24, 2022
Merged

Variable #467

merged 9 commits into from
Jun 24, 2022

Conversation

zauguin
Copy link
Member

@zauguin zauguin commented May 23, 2022

Status

READY/FOR DISCUSSION

Description

Add an interface for loading variable fonts under LuaLaTeX.

While fontspec already had undocumented Width and Weight font features (probably for Multiple Master fonts), these didn't set the current values to work for Variable fonts with luaotfload. Also there was no interface to set arbitrary axes. This was particularly problematic since luaotfload expects all axis values to be passed in a single axis feature, so using RawFeature to set one axis overwrites the values for all previously set axes.

Therefore this PR, besides making Weight and Width compatible with luaotfload and Variable fonts, adds a companion to RawFeature called RawAxis which allows to set arbitrary axis values.

Todos

  • Tests added to cover new/fixed functionality
  • Documentation if necessary
  • Code follows expl3 style guidelines

Minimal example demonstrating the new/fixed functionality

\documentclass{article}
\usepackage{unicode-math}
\setmainfont{NotoSerif}[
  Extension = .ttf,
  UprightFont = *-VF,
  ItalicFont  = *-Italic-VF,
  Weight = 200,
  Width = 75,
  RawAxis = {CTGR=100},
]
\begin{document}
This is the Extra Light Condensed Display style.
\end{document}

@@ -608,6 +608,66 @@ \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}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the best place for this, but since it's not really OpenType specific due to the MM stuff I thought that a generic place is best.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay for now. The situation would anything non-OpenType fontspec is rather weird and uncertain

Comment on lines +638 to +658
\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}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not tested with Multiple Master fonts, but since the code was already there I assume that it works for them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if anyone actually tries :) From memory MacOS has deprecated a number of APIs that XeTeX used to use to make this work in the older xdv2pdf backend. I can't recall what xdvipdfmx does

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xdvipdfmx never supported Apple GX, and when xdv2pdf was finally retired I foolishly removed GX support from XeTeX as being dead technology (I thought no the primitives are still there by they do nothing).

Comment on lines +5 to +7
\ifluahbtex
\defaultfontfeatures{Renderer=HarfBuzz}
\fi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature generally also works for the Node renderer, but the HarfBuzz supports is a bit more consistent IMO. (I'm probably biased though)

Comment on lines 1055 to 1078
% \begin{macro}{\@@_get_variations:}
% \cmd{\@@_get_variations:} builds the feature string representing the
% current variation instance and/or axis settings.
% \begin{macrocode}
\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 = {
\prop_map_function:NN \g_@@_rawvariations_prop \@@_format_axis:nn
};
}
}
% \end{macrocode}
% \end{macro}
%
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not made LuaTeX specific since I could imagine a similar interface applying to XeTeX too if they ever get Variable font support.

@zauguin
Copy link
Member Author

zauguin commented May 23, 2022

This would require adding NotoSerif-VF.ttf from https://github.com/googlefonts/noto-fonts/raw/main/unhinted/variable-ttf/NotoSerif-VF.ttf to @wspr's fontspec-test-fonts repo

@zauguin zauguin requested review from u-fischer and wspr May 23, 2022 21:58
Copy link
Collaborator

@wspr wspr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thank you so much! I had one question about naming -- wdyt?

I am sorry I have never had the time to explore this properly, I have always been very excited for MM technology. Sigh, if only there were more hours in the day. Next someone needs to integrate microtype expansion using variable axes fonts :)

@@ -608,6 +608,66 @@ \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}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay for now. The situation would anything non-OpenType fontspec is rather weird and uncertain

% \subsubsection{Variation instances}
%
% \begin{macrocode}
\@@_keys_define_code:nnn {fontspec-opentype} {Instance}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "Instance" specific enough or would "VariationInstance" be better? (Not sure, just thinking out loud). WDYT?

Copy link
Member Author

@zauguin zauguin May 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really have a qualified opinion on that. Personally I prefer Instance, but that's purely subjective.

Comment on lines +638 to +658
\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}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if anyone actually tries :) From memory MacOS has deprecated a number of APIs that XeTeX used to use to make this work in the older xdv2pdf backend. I can't recall what xdvipdfmx does

@zauguin zauguin merged commit 8e3494e into main Jun 24, 2022
@zauguin zauguin deleted the variable branch June 30, 2022 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants