\addfontfeatures 合并问题

\addfontfeatures 合并问题

我正在尝试为可变字体设置额外的粗细和宽度:

\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

这两个问题彼此独立:

  1. 第一个问题是,通过明确指定直立字体的 RawFeature,会覆盖“通用”RawFeature \addfontfeature。您可以通过UprightFeatures={RawFeature={...}}在 中设置\addfontfeature而不是RawFeature={...}直接设置来避免这种情况,但当然这仅适用于直立字体……当然,在这种情况下,权重 400 无论如何都是默认值,因此只需删除显式的UprightFeatures和即可轻松避免此问题ItalicFeatures。如果不是这种情况,您可以RawFeature={+axis={wght=400}}直接在\setmainfont参数中设置以使其成为默认值,而不是在UprightFeatures和中设置ItalicFeatures。这可以避免重复,并避免以后覆盖不太具体的值。

  2. \blackseries将这些和组合在一起的另一个问题与\condfontspec 缺少对设置可变字体轴值的直接支持直接相关。由于您必须使用RawFeatures按原样传递的参数,因此最终会得到一个指定两个不同axis特征的字体,而不是一个axis指定两个值的特征。通常,字体处理总是通过让后一个覆盖第一个来处理重复的字体特征,因此这不会产生预期的效果。未来的 fontspec 版本可能会添加用于设置此值的本机语法,从而避免这种情况。

目前,您必须手动指定组合。这可以通过使用 fontspec 的FontFace功能轻松完成,将附加系列值集成到 LaTeX 的 NFSS 中,然后 NFSS 将负责正确处理组合。这里black映射到 NFSS 等效项ub(超粗体)和condensedc然后您会得到类似以下内容:

\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}

在此处输入图片描述

相关内容