경로때문에 개고생한 썰 푼다

일단 개고생한 원인이 뭐냐면

  1. 리눅스는 /usr/share/fonts에 글꼴이 다 저장되어 있고(벌크로 깔거면 cp *ttf 쓰자) 거기 있는 글꼴 파일을 그냥 갖다 쓰면 된다. 이건 본인이 예전에 작성한 워드클라우드 코드를 보면 아실 것이다.
  2. 근데 윈도우는 C:\Windows\Fonts에 설치된 글꼴이 저장되지만 거기서 글꼴을 갖다 쓰는 게 아니라 TTF, OTF파일이 있는 경로를 직접 입력해서 거기서 갖다 써야 한다.

아니 농담이 아니라 이거때문에 노트북 1호에 파이썬 깔았음… 웹IDE는 OS 정보가 제대로 안 나오니… 아무튼.

OS = platform.platform()
if 'Linux' in OS: 
    default_dir = '/home'
    root = tkinter.Tk()
    root.withdraw()
    font_dir = '/usr/share/fonts'
    font_path = filedialog.askopenfilename(parent=root, initialdir=font_dir, title='Choose your fonts for Wordcloud',
                                           filetypes=(("*.ttf", "*ttf"), ("*.otf", "*otf")))
elif 'Windows' in OS:
    default_dir = 'C:\\'
    root = tkinter.Tk()
    root.withdraw()
    font_path = filedialog.askopenfilename(parent=root, initialdir=default_dir, title='Choose your fonts for Wordcloud',
                                           filetypes=(("*.ttf", "*ttf"), ("*.otf", "*otf")))

그래서 글꼴 파일 여는 코드가 OS 따라서 아예 분기로 갈려버림.