使用 LuaTeX 從 TrueType Collection 中選擇字型時出現問題

使用 LuaTeX 從 TrueType Collection 中選擇字型時出現問題

我想使用/Library/Fonts/GillSans.ttc我的 Mac 上安裝的 Gill Sans 字體。根據fontspec文檔,我應該能夠透過指定字型索引來使用 TrueType Collections。文件聲稱這應該適用於 LuaTeX,但我在讓它工作時遇到了麻煩。

對 TrueType 集合的支援僅在 XeTeX 中進行了測試,但也應該適用於最新版本的 LuaTeX 和軟體包luaotfload

以下最小文件在使用 Gill Sans 的情況下有效,並且似乎甚至可以透過定義新的字體系列來使用字體的特定粗細/形狀,但它不適用於\setmainfont並且無法使用諸如\textbf{}\textit{}ETC。,如編譯本文檔的輸出螢幕截圖所示。

\documentclass{article}

\usepackage{fontspec}
\setmainfont[
  Ligatures=TeX,
  Extension=.ttc,
  UprightFeatures={FontIndex=0},
  BoldFeatures={FontIndex=4},
  ItalicFeatures={FontIndex=2},
  BoldItalicFeatures={FontIndex=5}]{GillSans}

\newfontfamily\SemiBold[
  Ligatures=TeX,
  Extension=.ttc,
  UprightFeatures={FontIndex=4}]{GillSans}

\begin{document}
\textbf{asdf}
\textit{asdf}
asdf
\textbf{\textit{asdf}}

{\SemiBold asdf}
\end{document}

編譯文件的輸出,其中「asdf」以相同字體出現,除非切換到 \SemiBold 字體

有誰知道問題可能是什麼以及如何解決?日誌顯示以下內容:

LaTeX Font Warning: Font shape `TU/GillSans(0)/b/n' undefined
(Font)              using `TU/GillSans(0)/m/n' instead on input line 18.

LaTeX Font Warning: Font shape `TU/GillSans(0)/m/it' undefined
(Font)              using `TU/GillSans(0)/m/n' instead on input line 19.

LaTeX Font Warning: Font shape `TU/GillSans(0)/b/it' undefined
(Font)              using `TU/GillSans(0)/b/n' instead on input line 21.

此外,在 shell 中執行以下命令

luaotfload-tool --find 'Gill Sans SemiBold' -i

傳回以下內容,這表示上述文件應該可以透過索引 4 選擇半粗體字體作為 BoldFont:

luaotfload | resolve : Font "Gill Sans SemiBold" found!
luaotfload | resolve : Resolved file name "/Library/Fonts/GillSans.ttc", subfont nr. 4


** 1 Gill Sans SemiBold ********************************************************

        ascender: 1487
    averagewidth: 1154
     boundingbox: <table>
                   1: -1162
                   2: -512
                   3: 2279
                   4: 1931
       capheight: 1397
  defaultvheight: 0
       descender: -561
          family: Gill Sans
        fontname: GillSans-SemiBold
        fullname: Gill Sans SemiBold
     italicangle: 0.0
      monospaced: false
    panoseweight: demi
     panosewidth: normal
       pfmweight: 600
        pfmwidth: 5
   platformnames: <table>
           macintosh: <table>
                  family: Gill Sans
                fullname: Gill Sans SemiBold
          postscriptname: GillSans-SemiBold
               subfamily: SemiBold
             windows: <table>
                  family: Gill Sans
                fullname: Gill Sans SemiBold
          postscriptname: GillSans-SemiBold
               subfamily: SemiBold
       subfamily: SemiBold
    subfontindex: 4
           units: 2048
         version: 13.0d1e4
          weight: semibold
           width: normal
         xheight: 934

我正在使用 MacTeX 2020、v3.14/2020-05-06luaotfload-tool和 v2.7i fontspec

答案1

當使用 ttc 檔案時,你不應該使用Extension而是直接添加.ttc到名稱中,否則檢測到為時已晚,你必須手動ItalicFont設定:BoldFontBoldItalicFont

\documentclass{article}

\usepackage{fontspec}
\setmainfont[
  Ligatures=TeX,
  UprightFeatures={FontIndex=0},
  BoldFeatures={FontIndex=4},
  ItalicFeatures={FontIndex=2},
  BoldItalicFeatures={FontIndex=5}]{GillSans.ttc}

\newfontfamily\SemiBold[
  Ligatures=TeX,
  Extension=.ttc,
  UprightFeatures={FontIndex=4}]{GillSans}

\begin{document}
\textbf{asdf}
\textit{asdf}
asdf
\textbf{\textit{asdf}}

{\SemiBold asdf}
\end{document}

相關內容