From eb938d8ebc87ee68270ab7bdd3d281b6db5524fa Mon Sep 17 00:00:00 2001 From: Zeping Lee Date: Tue, 6 Feb 2024 16:15:55 +0800 Subject: [PATCH] Check and use Windows font files (#747) --- CHANGELOG.md | 1 + thuthesis-example.tex | 2 +- thuthesis.dtx | 71 ++++++++++++++++++++++++++++--------------- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1dc6a3a..ea4fa031 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - 统一并简化封面的布局([#900](https://github.com/tuna/thuthesis/issues/900))。 - 英文封面的导师姓名居中对齐([#883](https://github.com/tuna/thuthesis/issues/883))。 - 修正 macOS 的 MS Office 字体名([#913](https://github.com/tuna/thuthesis/issues/913))。 +- 检测并使用 Windows 字体文件,默认从当前目录查找([#747](https://github.com/tuna/thuthesis/discussions/747))。 ### Fixed diff --git a/thuthesis-example.tex b/thuthesis-example.tex index 298c45fd..5d0be6f1 100644 --- a/thuthesis-example.tex +++ b/thuthesis-example.tex @@ -2,7 +2,7 @@ % !TeX program = xelatex % !TeX spellcheck = en_US -\documentclass[degree=master]{thuthesis} +\documentclass[degree=master, cjk-font=mac-word]{thuthesis} % 学位 degree: % doctor | master | bachelor | postdoc % 学位类型 degree-type: diff --git a/thuthesis.dtx b/thuthesis.dtx index e261a14c..8ad5f9f7 100644 --- a/thuthesis.dtx +++ b/thuthesis.dtx @@ -1547,6 +1547,7 @@ choices = { auto, windows, + windows-local, mac, mac-word, noto, @@ -1555,6 +1556,10 @@ }, default = auto, }, + windows-font-dir = { + name = windows@font@dir, + default = {.}, + }, math-font = { name = math@font, choices = { @@ -2241,8 +2246,8 @@ % % 使用 \pkg{fontspec} 配置字体。 % \begin{macrocode} -\newcommand\thu@mac@word@font@path{% - /Applications/Microsoft Word.app/Contents/Resources/DFonts/% +\newcommand\thu@mac@word@font@dir{% + /Applications/Microsoft Word.app/Contents/Resources/DFonts% } \ifthu@fontset@auto \ifthu@system@windows @@ -2251,18 +2256,22 @@ \IfFontExistsTF{SimSun}{ \thusetup{fontset = windows} }{ - \IfFileExists{\thu@mac@word@font@path/Simsun.ttc}{ - \thusetup{fontset = windows, cjk-font = mac-word} + \IfFileExists{\thu@windows@font@dir/Simsun.ttc}{ + \thusetup{fontset = windows, cjk-font = windows-local} }{ - \ifthu@system@mac - \thusetup{fontset = mac} - \else - \IfFontExistsTF{Noto Serif CJK SC}{ - \thusetup{fontset = ubuntu} - }{ - \thusetup{fontset = fandol} - } - \fi + \IfFileExists{\thu@mac@word@font@dir/Simsun.ttc}{ + \thusetup{fontset = windows, cjk-font = mac-word} + }{ + \ifthu@system@mac + \thusetup{fontset = mac} + \else + \IfFontExistsTF{Noto Serif CJK SC}{ + \thusetup{fontset = ubuntu} + }{ + \thusetup{fontset = fandol} + } + \fi + } } } \fi @@ -2545,10 +2554,14 @@ \IfFontExistsTF{SimSun}{ \thusetup{cjk-font = windows} }{ - \IfFileExists{\thu@mac@word@font@path/Simsun.ttc}{ - \thusetup{cjk-font = mac-word} + \IfFileExists{\thu@windows@font@dir/Simsun.ttc}{ + \thusetup{cjk-font = windows-local} }{ - \thu@error{Cannot find "SimSun" font} + \IfFileExists{\thu@mac@word@font@dir/Simsun.ttc}{ + \thusetup{cjk-font = mac-word} + }{ + \thu@error{Cannot find "SimSun" font} + } } } \else @@ -2578,29 +2591,37 @@ } % \end{macrocode} % -% macOS 的 Microsoft Word 字体。 +% 使用的 Windows 字体文件。 % \begin{macrocode} -\@namedef{thu@set@cjk@font@mac-word}{% +\@namedef{thu@set@cjk@font@windows-local}{% \setCJKmainfont{SimSun}[% - Path = \thu@mac@word@font@path, + Path = \thu@windows@font@dir/, AutoFakeBold = 3, ItalicFont = KaiTi, ]% \setCJKsansfont{SimHei}[% - Path = \thu@mac@word@font@path, + Path = \thu@windows@font@dir/, AutoFakeBold = 3, ]% - \setCJKmonofont{FangSong}[Path=\thu@mac@word@font@path]% + \setCJKmonofont{FangSong}[Path=\thu@windows@font@dir/]% \setCJKfamilyfont{zhsong}{SimSun}[% - Path = \thu@mac@word@font@path, + Path = \thu@windows@font@dir/, AutoFakeBold = 3, ]% \setCJKfamilyfont{zhhei}{SimHei}[% - Path = \thu@mac@word@font@path, + Path = \thu@windows@font@dir/, AutoFakeBold = 3, ]% - \setCJKfamilyfont{zhkai}{KaiTi}[Path = \thu@mac@word@font@path]% - \setCJKfamilyfont{zhfs}{FangSong}[Path = \thu@mac@word@font@path]% + \setCJKfamilyfont{zhkai}{KaiTi}[Path = \thu@windows@font@dir/]% + \setCJKfamilyfont{zhfs}{FangSong}[Path = \thu@windows@font@dir/]% +} +% \end{macrocode} +% +% macOS 的 Microsoft Word 字体。 +% \begin{macrocode} +\@namedef{thu@set@cjk@font@mac-word}{% + \let\thu@windows@font@dir\thu@mac@word@font@dir + \@nameuse{thu@set@cjk@font@windows-local}% } % \end{macrocode} %