知名的免費字型「瀨戶字體 setofont」,裡有很多空白的字, 會造成無法讓系統自動用預設字體來補字。
解法之一是使用FontForge開啟字體檔案,手動按右鍵去把空白的字,使用clear 功能清除掉,最後再匯出成新的字型檔。

這種「重複性高」的「手動」的事情,不適合人來做,所以我寫一個 python 的 script 來解決。完整程式如下:
from os import listdir, remove
from os.path import join, getsize
def scan_files_from_folder(ff_folder, size_to_delete, readonly):
files = listdir(ff_folder)
match_count = 0
for f in files:
if '.glyph' in f:
# skip hidden files.
if f[:1] == ".":
continue
target_path = join(ff_folder,f)
filesize = getsize(target_path)
if filesize <= size_to_delete:
match_count += 1
print("path:%s, size:%d" % (f,filesize))
if not readonly:
remove(target_path)
print("remove count:", match_count)
source_ff = 'NaikaiFont-Regular.sfdir'
size_to_delete=100
readonly=False
scan_files_from_folder(source_ff, size_to_delete, readonly)
程式說明:
- 請先指定一個 FontForge 的資料夾,放到變數:source_ff。
- 必誤刪可以先設定 readonly=True ,不過我已經測試過了,這個程式應該可以直接用。
- size_to_delete目前是 100,代表 100 bytes目前程式的設定是刪除 byte 數低於 100bytes 的檔案 。
(在 seto font 裡,空白的 glyph 檔案,最多是 92byte)
