Skip to content

Instantly share code, notes, and snippets.

@ikasamah
Created November 29, 2011 09:58
Show Gist options
  • Save ikasamah/1404238 to your computer and use it in GitHub Desktop.
Save ikasamah/1404238 to your computer and use it in GitHub Desktop.
管理者権限なしでWindowsにフォントをインストール
# -*- coding: utf-8 -*-
import os, ctypes
from fnmatch import fnmatch
#
# install_font.py
#
# for Windows
# 管理者権限なしでフォントをインストールします.(ログアウトまで有効)
# %USER_PROFILE%\fonts 以下にフォントを置いてください.
# ログインスクリプトに指定すると良いです.
#
FONT_PATH = '%s\\fonts' % os.environ.get('USERPROFILE')
FONT_PATTERN = ('*.fon', '*.fnt', '*.ttf', '*.ttc', '*.fot',
'*.otf', '*.mmm', '*.pfb', '*.pfm')
def install_fonts(fonts):
for font in fonts:
result = ctypes.windll.gdi32.AddFontResourceA(font)
if result != 0:
print '%s has been installed.' % font
def find_fonts(path):
matches = []
for root, dirs, files in os.walk(path):
for file in filter(is_font, files):
matches.append(os.path.join(root, file))
return matches
def is_font(file, pattern=FONT_PATTERN):
for p in pattern:
if fnmatch(file, p):
return True
return False
if __name__ == '__main__':
install_fonts(find_fonts(FONT_PATH))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment