LuaLaTeX
我正在尝试通过包设置可变字体fontspec
。我试图让字体大小和光学尺寸(opsz
)具有几乎相同的值。(我知道opsz
可变轴必须在和之间6
,144
步长为0.1
,因此数字不会完美同步。请参阅:https://fonts.google.com/knowledge/glossary/optical_size_axis)
文档fontspec
显示您必须手动设置每种字体大小的光学尺寸,并且每次添加新字体时都必须添加额外的字体大小-光学尺寸对。显然,这会很累,而且需要很长时间。我希望光学尺寸(几乎总是)自动等于字体大小。({Size=X,RawFeature={axis={opsz=X}}}
对于 X 的每个可能值。)
在以下 MWE 中,我手动设置了由文档类定义的每种字体大小的光学尺寸。 (并且,由于某种原因,带有、和 的article
段落的行距混乱了。)\LARGE
\huge
\Huge
编辑:我添加了粗体、斜体和粗斜体的代码,以帮助读者了解手动设置每种字体大小的视觉尺寸是多么繁琐。我甚至还没有设置不同粗细的命令:ExtraLight、Light、Medium、SemiBold、ExtraBold 和 Black。
\documentclass{article}
\usepackage[lmargin=1in,rmargin=1in]{geometry}
\raggedright\raggedbottom
\parindent=0pt
\parskip=7pt
\usepackage{blindtext}
\usepackage{fontspec}
\setmonofont{Source Code Pro}%Available for free on Google Fonts.
\setmainfont{SourceSerif4-VariableFont_opsz,wght.ttf}[%Available for free on Google Fonts.
,Kerning=On,Numbers={Lining,Tabular}
%Regular
,SizeFeatures={
{Size=7,RawFeature={axis={opsz=7}}}%\scriptsize
,{Size=8,RawFeature={axis={opsz=8}}}%\footnotesize
,{Size=9,RawFeature={axis={opsz=9}}}%\small
,{Size=10,RawFeature={axis={opsz=10}}}%\normalsize
,{Size=12,RawFeature={axis={opsz=12}}}%\large
,{Size=14.4,RawFeature={axis={opsz=14.4}}}%\Large
,{Size=17.28,RawFeature={axis={opsz=17.3}}}%\LARGE
,{Size=20.74,RawFeature={axis={opsz=20.7}}}%\huge
,{Size=24.88,RawFeature={axis={opsz=24.9}}}%\Huge
}
%Bold
,BoldFont={SourceSerif4-VariableFont_opsz,wght.ttf}
,BoldFeatures={
SizeFeatures={
{Size=7,RawFeature={axis={wght=700,opsz=7}}}%\scriptsize
,{Size=8,RawFeature={axis={wght=700,opsz=8}}}%\footnotesize
,{Size=9,RawFeature={axis={wght=700,opsz=9}}}%\small
,{Size=10,RawFeature={axis={wght=700,opsz=10}}}%\normalsize
,{Size=12,RawFeature={axis={wght=700,opsz=12}}}%\large
,{Size=14.4,RawFeature={axis={wght=700,opsz=14.4}}}%\Large
,{Size=17.28,RawFeature={axis={wght=700,opsz=17.3}}}%\LARGE
,{Size=20.74,RawFeature={axis={wght=700,opsz=20.7}}}%\huge
,{Size=24.88,RawFeature={axis={wght=700,opsz=24.9}}}%\Huge
}
}
%Italics
,ItalicFont={SourceSerif4-Italic-VariableFont_opsz,wght.ttf}
,ItalicFeatures={
SizeFeatures={
{Size=7,RawFeature={axis={opsz=7}}}%\scriptsize
,{Size=8,RawFeature={axis={opsz=8}}}%\footnotesize
,{Size=9,RawFeature={axis={opsz=9}}}%\small
,{Size=10,RawFeature={axis={opsz=10}}}%\normalsize
,{Size=12,RawFeature={axis={opsz=12}}}%\large
,{Size=14.4,RawFeature={axis={opsz=14.4}}}%\Large
,{Size=17.28,RawFeature={axis={opsz=17.3}}}%\LARGE
,{Size=20.74,RawFeature={axis={opsz=20.7}}}%\huge
,{Size=24.88,RawFeature={axis={opsz=24.9}}}%\Huge
}
}
%Bold Italics
,BoldItalicFont={SourceSerif4-Italic-VariableFont_opsz,wght.ttf}
,BoldItalicFeatures={
SizeFeatures={
{Size=7,RawFeature={axis={wght=700,opsz=7}}}%\scriptsize
,{Size=8,RawFeature={axis={wght=700,opsz=8}}}%\footnotesize
,{Size=9,RawFeature={axis={wght=700,opsz=9}}}%\small
,{Size=10,RawFeature={axis={wght=700,opsz=10}}}%\normalsize
,{Size=12,RawFeature={axis={wght=700,opsz=12}}}%\large
,{Size=14.4,RawFeature={axis={wght=700,opsz=14.4}}}%\Large
,{Size=17.28,RawFeature={axis={wght=700,opsz=17.3}}}%\LARGE
,{Size=20.74,RawFeature={axis={wght=700,opsz=20.7}}}%\huge
,{Size=24.88,RawFeature={axis={wght=700,opsz=24.9}}}%\Huge
}
}
]
\begin{document}
\texttt{REGULAR}
\par
{\scriptsize\texttt{scriptsize}\hspace{0.5em}\blindtext}
\par
{\footnotesize\texttt{footnotesize}\hspace{0.5em}\blindtext}
\par
{\small\texttt{small}\hspace{0.5em}\blindtext}
\par
{\normalsize\texttt{normalsize}\hspace{0.5em}\blindtext}
\par
{\large\texttt{large}\hspace{0.5em}\blindtext}
\par
{\Large\texttt{Large}\hspace{0.5em}\blindtext}
\par
{\LARGE\texttt{LARGE}\hspace{0.5em}\blindtext}
\par
{\huge\texttt{huge}\hspace{0.5em}\blindtext}
\par
{\Huge\texttt{Huge}\hspace{0.5em}\blindtext}
\par
\texttt{BOLD}{\bfseries
\par
{\scriptsize\texttt{scriptsize}\hspace{0.5em}\blindtext}
\par
{\footnotesize\texttt{footnotesize}\hspace{0.5em}\blindtext}
\par
{\small\texttt{small}\hspace{0.5em}\blindtext}
\par
{\normalsize\texttt{normalsize}\hspace{0.5em}\blindtext}
\par
{\large\texttt{large}\hspace{0.5em}\blindtext}
\par
{\Large\texttt{Large}\hspace{0.5em}\blindtext}
\par
{\LARGE\texttt{LARGE}\hspace{0.5em}\blindtext}
\par
{\huge\texttt{huge}\hspace{0.5em}\blindtext}
\par
{\Huge\texttt{Huge}\hspace{0.5em}\blindtext}
}
\par
\texttt{ITALICS}{\itshape
\par
{\scriptsize\texttt{scriptsize}\hspace{0.5em}\blindtext}
\par
{\footnotesize\texttt{footnotesize}\hspace{0.5em}\blindtext}
\par
{\small\texttt{small}\hspace{0.5em}\blindtext}
\par
{\normalsize\texttt{normalsize}\hspace{0.5em}\blindtext}
\par
{\large\texttt{large}\hspace{0.5em}\blindtext}
\par
{\Large\texttt{Large}\hspace{0.5em}\blindtext}
\par
{\LARGE\texttt{LARGE}\hspace{0.5em}\blindtext}
\par
{\huge\texttt{huge}\hspace{0.5em}\blindtext}
\par
{\Huge\texttt{Huge}\hspace{0.5em}\blindtext}
}
\par
\texttt{BOLD ITALICS}{\itshape\bfseries
\par
{\scriptsize\texttt{scriptsize}\hspace{0.5em}\blindtext}
\par
{\footnotesize\texttt{footnotesize}\hspace{0.5em}\blindtext}
\par
{\small\texttt{small}\hspace{0.5em}\blindtext}
\par
{\normalsize\texttt{normalsize}\hspace{0.5em}\blindtext}
\par
{\large\texttt{large}\hspace{0.5em}\blindtext}
\par
{\Large\texttt{Large}\hspace{0.5em}\blindtext}
\par
{\LARGE\texttt{LARGE}\hspace{0.5em}\blindtext}
\par
{\huge\texttt{huge}\hspace{0.5em}\blindtext}
\par
{\Huge\texttt{Huge}\hspace{0.5em}\blindtext}
}
\end{document}
更新 2023-01-02:我一直在测试Marcel Kruger 建议的HarfBuzz
自动调整opsz
轴大小的方法。我发现它除了自动调整轴大小之外还有其他功能opsz
。两个主要问题:
(1) 如果我将字体更改为Source Sans 3
另一种可变字体(代码与 Marcel Kruger 提供的代码几乎相同),并测试使用/不使用HarfBuzz
,我发现使用和不使用的文档版本HarfBuzz
看起来彼此明显不同。文档版本应该看起来相同,因为Source Sans 3
缺少opsz
轴。因此,Renderer=HarfBuzz
除了修改opsz
轴之外,还具有其他功能。添加的功能在印刷上可能是也可能不是最佳的。您可以在下面的第二个 MWE 中亲自看到这一点。
(2) 使用Renderer=HarfBuzz
withSource Serif 4
和\textls
包中的 letterspacing 命令microtype
有时会产生错误的字母间距。我没有发现错误模式,但我在第二个 MWE 中复制了一些错误。我发现可以通过使用代替Source Sans 3
或本地设置来修复此错误Kerning=Off
。在修复此 letterspacing 错误时,我希望该\textls
命令自动在本地禁用字距调整。
\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}%clears default header footers
\fancyhead[C]{%
%\addfontfeatures{Kerning=Off}%In my testing, this fixes the bugged letterspacing.
\textls[100]{LETTERSPACING IS BUGGED}%
}
\fancyfoot[C]{%
%\addfontfeatures{Kerning=Off}%In my testing, this fixes the bugged letterspacing.
~\textls[100]{BUGGED}%
~(%
\textls[100]{LETTER}%
~\textls[100]{SPACING}%
)%
}
\usepackage{microtype}
\usepackage{blindtext}
\usepackage{fontspec}
\setmonofont{Source Code Pro}
\setromanfont{SourceSerif4-VariableFont_opsz,wght.ttf}[%Available for free on Google Fonts.
,Kerning=On,Numbers={Lining,Tabular},Renderer=HarfBuzz
%Bold
,BoldFont={SourceSerif4-VariableFont_opsz,wght.ttf}
,BoldFeatures={RawFeature={axis={wght=700}}}
%Italics
,ItalicFont={SourceSerif4-Italic-VariableFont_opsz,wght.ttf}
%Bold Italics
,BoldItalicFont={SourceSerif4-Italic-VariableFont_opsz,wght.ttf}
,BoldItalicFeatures={RawFeature={axis={wght=700}}}
]
\setsansfont{SourceSans3-VariableFont_wght.ttf}[%Available for free on Google Fonts.
Kerning=On
%,Renderer=HarfBuzz%In my testing Renderer=HarfBuzz will change the text display even though Source Sans 3 lacks an opsz axis.
%Regular
,RawFeature={axis={wght=400}}
%Bold
,BoldFont={SourceSans3-VariableFont_wght.ttf}
,BoldFeatures={RawFeature={axis={wght=700}}}
%Italics
,ItalicFont={SourceSans3-Italic-VariableFont_wght.ttf}
,ItalicFeatures={RawFeature={axis={wght=400}}}
%Bold Italics
,BoldItalicFont={SourceSans3-Italic-VariableFont_wght.ttf}
,BoldItalicFeatures={RawFeature={axis={wght=700}}}
]
\renewcommand{\familydefault}{%use this to switch between serif and sans fonts
\rmdefault%
%\sfdefault%
}
\begin{document}
{%
%\addfontfeatures{Kerning=Off}%In my testing, this fixes the bugged letterspacing. Note that I have disabled kerning locally to not mess up the rest of the document.
\textls[100]{LETTER SPACING IS BUGGED}%
}%
\par
\blinddocument
\small\blinddocument
\tiny\blinddocument
\end{document}
编辑:我使用了启用了该功能的showhyphenation
软件包Renderer=HarfBuzz
,发现后者严重扰乱了连字。我使用其他文档对此进行了测试。
答案1
您可以请求基于 HarfBuzz 的渲染器,而无需指定任何opsz
功能。如果没有给出明确的值,HarfBuzz 模式会自动opsz
根据字体大小确定:
\documentclass{article}
\usepackage{blindtext}
\usepackage{fontspec}
\setmonofont{Source Code Pro}
\setmainfont{SourceSerif4-VariableFont_opsz,wght.ttf}[%Available for free on Google Fonts.
,Kerning=On,Numbers={Lining,Tabular},Renderer=HarfBuzz
%Bold
,BoldFont={SourceSerif4-VariableFont_opsz,wght.ttf}
,BoldFeatures={RawFeature={axis={wght=700}}}
%Italics
,ItalicFont={SourceSerif4-Italic-VariableFont_opsz,wght.ttf}
%Bold Italics
,BoldItalicFont={SourceSerif4-Italic-VariableFont_opsz,wght.ttf}
,BoldItalicFeatures={RawFeature={axis={wght=700}}}
]
\begin{document}
\blinddocument
\small\blinddocument
\tiny\blinddocument
\end{document}