Skip to content

Commit

Permalink
Check and use Windows font files (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed Feb 6, 2024
1 parent 11bf0d8 commit eb938d8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion thuthesis-example.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
71 changes: 46 additions & 25 deletions thuthesis.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,7 @@
choices = {
auto,
windows,
windows-local,
mac,
mac-word,
noto,
Expand All @@ -1555,6 +1556,10 @@
},
default = auto,
},
windows-font-dir = {
name = windows@font@dir,
default = {.},
},
math-font = {
name = math@font,
choices = {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
%
Expand Down

0 comments on commit eb938d8

Please sign in to comment.