-
Notifications
You must be signed in to change notification settings - Fork 1
/
pyGenRandFontObj.py
82 lines (72 loc) · 2.57 KB
/
pyGenRandFontObj.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# =============================================================================
# Created Syst: macOS Monterey 12.4 (21F79) Kernel: Darwin 21.5.0
# Created Plat: Python 3.10.5 ('v3.10.5:f377153967', 'Jun 6 2022 12:36:10')
# Created By : Jeromie Kirchoff
# Created Date: Wed Jun 29 20:00:35 2022 CDT
# Last ModDate: Tue Jul 12 16:47:08 2022 CDT
# =============================================================================
# Notes: Get a listing of all known fonts from your mac.
# =============================================================================
import glob
from getpass import getuser
from os.path import exists as filepathexist
from os.path import expanduser
from os.path import join
from random import choice
FontPath = ''
FontList = []
GLOBList = []
FontPath = r'/Applications'
exists = filepathexist(FontPath)
if exists:
FontPath = fr'{FontPath}/*.otf'
List_GLOB = glob.glob(FontPath)
FontList.extend(List_GLOB)
FontList
if exists:
FontPath = fr'{FontPath}/*.ttf'
List_GLOB = glob.glob(FontPath)
FontList.extend(List_GLOB)
if exists:
FontPath = fr'{FontPath}/*.ttc'
List_GLOB = glob.glob(FontPath)
FontList.extend(List_GLOB)
def getFontList():
"""Compile a list of all known fonts on the MacOS into a list.
"""
FontPath = r'/System/Library/Fonts/Supplemental'
exists = filepathexist(FontPath)
if exists:
FontPath = fr'{FontPath}/*.*'
List_GLOB = glob.glob(FontPath)
FontList.extend(List_GLOB)
FontPath = r'/Library/Fonts'
exists = filepathexist(FontPath)
if exists:
FontPath = fr'{FontPath}/*.*'
List_GLOB = glob.glob(FontPath)
FontList.extend(List_GLOB)
FontPath = r'/System/Library/Fonts'
exists = filepathexist(FontPath)
if exists:
FontPath = fr'{FontPath}/*.*'
List_GLOB = glob.glob(FontPath)
FontList.extend(List_GLOB)
FontPath = fr'/Users/{getuser()}/Library/Fonts'
exists = filepathexist(FontPath)
if exists:
FontPath = fr'{FontPath}/*.*'
List_GLOB = glob.glob(FontPath)
FontList.extend(List_GLOB)
FontList.sort()
FontList.remove('/System/Library/Fonts/Apple Color Emoji.ttc') # Removed for Breaking when used by PIL.
return FontList
if __name__ == '__main__':
a = choice(getFontList())
FontNameStr = a.split('/')[-1].split('.')[0]
print(f"Your Random Font: {FontNameStr}\tPath: {a}")
for i in sorted(getFontList()):
FontNameStr = i.split('/')[-1].split('.')[0]
print(f"CurrentFontName: {FontNameStr}: {i}")