Use SimSun as default for Ubuntu running in WSL
Recently, I’ve started building automated workflows for daily works. One of those is to convert PDF-format invoices into JPEG images. It’s easy to achieve with an image library such as ImageMagick, except that a few characters look strange.
To make the invoices more formal, we should force to use SimSun (宋体), an out fashioned font but still commonly used by government institutions, as default for Simplified Chinese characters.
Step 1: Install the fonts
-
Open C:\Windows\Fonts folder, copy SimSun font to desktop alongside other fonts we may need in the future (such as SimHei, SimKai, SimFang).
-
Install these fonts to Ubuntu:
$ sudo mkdir /usr/share/fonts/win_fonts $ sudo mv /mnt/c/Users/USER_NAME/Desktop/*.tt* /usr/share/fonts/win_fonts/
-
Refresh font caches:
sudo fc-cache -fv
$ sudo fc-cache -fv
-
Check the results:
fc-list :lang=zh-cn | sort
$ fc-list :lang=zh-cn|sort /usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans CJK SC:style=Bold …… /usr/share/fonts/win_fonts/simfang.ttf: FangSong,仿宋:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta /usr/share/fonts/win_fonts/simhei.ttf: SimHei,黑体:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta /usr/share/fonts/win_fonts/simkai.ttf: KaiTi,楷体:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta /usr/share/fonts/win_fonts/simsun.ttc: NSimSun,新宋体:style=Regular,常规 /usr/share/fonts/win_fonts/simsun.ttc: SimSun,宋体:style=Regular,常规
Step 2: Set as defaults
Edit /etc/fonts/conf.avail/69-language-selector-zh-cn.conf to add two lines (marked by <!-- ADDED -->
):
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="pattern">
<test name="lang">
<string>zh-cn</string>
</test>
<test qual="any" name="family">
<string>serif</string>
</test>
<edit name="family" mode="prepend" binding="strong">
<string>Simsun</string> <!-- ADDED -->
......
</edit>
</match>
<match target="pattern">
<test name="lang">
<string>zh-cn</string>
</test>
<test qual="any" name="family">
<string>sans-serif</string>
</test>
<edit name="family" mode="prepend" binding="strong">
<string>SimHei</string> <!-- ADDED -->
......
</edit>
</match>
......
</fontconfig>