我正在尝试为可变字体设置额外的粗细和宽度:
\DeclareRobustCommand{\blackseries}{\addfontfeature{RawFeature={+axis={wght=900}}}}
\DeclareRobustCommand{\cond}{\addfontfeature{RawFeature={+axis={wdth=50}}}}
但是,我有两个可能相关的问题。如果我UprightFeatures
在
\setmainfont{NotoSans-VF.ttf}[
Path = Fonts/Noto/variable-ttf/,
UprightFont = *,
UprightFeatures = {RawFeature={+axis={wght=400}}},
ItalicFont = NotoSerif-Italic-VF.ttf,
ItalicFeatures = {RawFeature={+axis={wght=400}}},
BoldFont = *,
BoldItalicFont = *,
BoldFeatures = {RawFeature={+axis={wght=700}}},
BoldItalicFeatures = {RawFeature={+axis={wght=700}}},
Renderer = HarfBuzz,
]
那么\blackseries
根本不起作用。如果我将其注释掉,\blackseries
就可以了。
第二个问题是,当我使用\blackseries\cond
它时,只是压缩它,而不是使其加粗。
完整 MWE:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{NotoSans-VF.ttf}[
Path = Fonts/Noto/variable-ttf/,
UprightFont = *,
UprightFeatures = {RawFeature={+axis={wght=400}}},
ItalicFont = NotoSerif-Italic-VF.ttf,
ItalicFeatures = {RawFeature={+axis={wght=400}}},
BoldFont = *,
BoldItalicFont = *,
BoldFeatures = {RawFeature={+axis={wght=700}}},
BoldItalicFeatures = {RawFeature={+axis={wght=700}}},
Renderer = HarfBuzz,
]
\DeclareRobustCommand{\blackseries}{\addfontfeature{RawFeature={+axis={wght=900}}}}
\DeclareRobustCommand{\cond}{\addfontfeature{RawFeature={+axis={wdth=50}}}}
\begin{document}
\blackseries Text
\cond condensed text
\end{document}
答案1
这两个问题彼此独立:
第一个问题是,通过明确指定直立字体的 RawFeature,会覆盖“通用”RawFeature
\addfontfeature
。您可以通过UprightFeatures={RawFeature={...}}
在 中设置\addfontfeature
而不是RawFeature={...}
直接设置来避免这种情况,但当然这仅适用于直立字体……当然,在这种情况下,权重 400 无论如何都是默认值,因此只需删除显式的UprightFeatures
和即可轻松避免此问题ItalicFeatures
。如果不是这种情况,您可以RawFeature={+axis={wght=400}}
直接在\setmainfont
参数中设置以使其成为默认值,而不是在UprightFeatures
和中设置ItalicFeatures
。这可以避免重复,并避免以后覆盖不太具体的值。\blackseries
将这些和组合在一起的另一个问题与\cond
fontspec 缺少对设置可变字体轴值的直接支持直接相关。由于您必须使用RawFeatures
按原样传递的参数,因此最终会得到一个指定两个不同axis
特征的字体,而不是一个axis
指定两个值的特征。通常,字体处理总是通过让后一个覆盖第一个来处理重复的字体特征,因此这不会产生预期的效果。未来的 fontspec 版本可能会添加用于设置此值的本机语法,从而避免这种情况。
目前,您必须手动指定组合。这可以通过使用 fontspec 的FontFace
功能轻松完成,将附加系列值集成到 LaTeX 的 NFSS 中,然后 NFSS 将负责正确处理组合。这里black
映射到 NFSS 等效项ub
(超粗体)和condensed
。c
然后您会得到类似以下内容:
\documentclass{article}
\usepackage{fontspec}
% Attention, different font filenames. On my system the variable fonts don't have the -VF suffix, so you might want to add that back.
% Also I use the Sans version also for italic since I think that they fit better. Of course YMMV.
\setmainfont{NotoSans.ttf}[
UprightFont = *,
BoldFont = *,
BoldFeatures = {Weight=700},
FontFace = {ub}{n}{Font = *, RawFeature={+axis={wght=900}}},
FontFace = {c}{n}{Font = *, RawFeature={+axis={wdth=50}}},
FontFace = {bc}{n}{Font = *, RawFeature={+axis={wght=700,wdth=50}}},
FontFace = {ubc}{n}{Font = *, RawFeature={+axis={wght=900,wdth=50}}},
ItalicFont = NotoSans-Italic.ttf,
BoldItalicFont = NotoSans-Italic.ttf,
BoldItalicFeatures = {Weight=700},
FontFace = {ub}{it}{Font = NotoSans-Italic.ttf, RawFeature={+axis={wght=900}}},
FontFace = {c}{it}{Font = NotoSans-Italic.ttf, RawFeature={+axis={wdth=50}}},
FontFace = {bc}{it}{Font = NotoSans-Italic.ttf, RawFeature={+axis={wght=700,wdth=50}}},
FontFace = {ubc}{it}{Font = NotoSans-Italic.ttf, RawFeature={+axis={wght=900,wdth=50}}},
Renderer = HarfBuzz,
]
\DeclareRobustCommand{\blackseries}{\fontseries{ub}\selectfont}
\DeclareRobustCommand{\cond}{\fontseries{c}\selectfont}
\begin{document}
\blackseries Text
\cond condensed text
\end{document}