-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcore_text.py
More file actions
71 lines (57 loc) · 3.55 KB
/
Copy pathcore_text.py
File metadata and controls
71 lines (57 loc) · 3.55 KB
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
from .types import CFIndex
from ctypes import c_bool, c_uint32, c_void_p, CDLL, util
from enum import IntEnum
__all__ = [
"CoreText",
"CTFontFormat",
"CTFontManagerScope"
]
class CTFontFormat(IntEnum):
# https://developer.apple.com/documentation/coretext/ctfontformat?language=objc
kCTFontFormatUnrecognized = 0
kCTFontFormatOpenTypePostScript = 1
kCTFontFormatOpenTypeTrueType = 2
kCTFontFormatTrueType = 3
kCTFontFormatPostScript = 4
kCTFontFormatBitmap = 5
class CTFontManagerScope(IntEnum):
# https://developer.apple.com/documentation/coretext/ctfontmanagerscope?language=objc
kCTFontManagerScopeNone = 0
kCTFontManagerScopeProcess = 1
kCTFontManagerScopePersistent = 2
kCTFontManagerScopeSession = 3
kCTFontManagerScopeUser = 2
class CoreText():
def __init__(self) -> None:
core_text_library_name = util.find_library("CoreText")
# Hack for compatibility with macOS greater or equals to 11.0.
# From: https://github.com/pyglet/pyglet/blob/a44e83a265e7df8ece793de865bcf3690f66adbd/pyglet/libs/darwin/cocoapy/cocoalibs.py#L520-L524
if core_text_library_name is None:
core_text_library_name = "/System/Library/Frameworks/CoreText.framework/CoreText"
core_text = CDLL(core_text_library_name)
self.kCTFontURLAttribute = c_void_p.in_dll(core_text, "kCTFontURLAttribute")
self.kCTFontFormatAttribute = c_void_p.in_dll(core_text, "kCTFontFormatAttribute")
# https://developer.apple.com/documentation/coretext/1509907-ctfontcollectioncreatefromavaila?language=objc
self.CTFontCollectionCreateFromAvailableFonts = core_text.CTFontCollectionCreateFromAvailableFonts
self.CTFontCollectionCreateFromAvailableFonts.restype = c_void_p
self.CTFontCollectionCreateFromAvailableFonts.argtypes = [c_void_p]
# https://developer.apple.com/documentation/coretext/1511091-ctfontcollectioncreatematchingfo?language=objc
self.CTFontCollectionCreateMatchingFontDescriptors = core_text.CTFontCollectionCreateMatchingFontDescriptors
self.CTFontCollectionCreateMatchingFontDescriptors.restype = c_void_p
self.CTFontCollectionCreateMatchingFontDescriptors.argtypes = [c_void_p]
# https://developer.apple.com/documentation/coretext/1510346-ctfontdescriptorcopyattribute?language=objc
self.CTFontDescriptorCopyAttribute = core_text.CTFontDescriptorCopyAttribute
self.CTFontDescriptorCopyAttribute.restype = c_void_p
self.CTFontDescriptorCopyAttribute.argtypes = [c_void_p, c_void_p]
# https://developer.apple.com/documentation/corefoundation/1541581-cfurlcopyfilesystempath?language=objc
self.CFURLCopyFileSystemPath = core_text.CFURLCopyFileSystemPath
self.CFURLCopyFileSystemPath.restype = c_void_p
self.CFURLCopyFileSystemPath.argtypes = [c_void_p, CFIndex]
# https://developer.apple.com/documentation/coretext/1499468-ctfontmanagerregisterfontsforurl?language=objc
self.CTFontManagerRegisterFontsForURL = core_text.CTFontManagerRegisterFontsForURL
self.CTFontManagerRegisterFontsForURL.restype = c_bool
self.CTFontManagerRegisterFontsForURL.argtypes = [c_void_p, c_uint32, c_void_p]
# https://developer.apple.com/documentation/coretext/1499496-ctfontmanagerunregisterfontsforu?language=objc
self.CTFontManagerUnregisterFontsForURL = core_text.CTFontManagerUnregisterFontsForURL
self.CTFontManagerUnregisterFontsForURL.restype = c_bool
self.CTFontManagerUnregisterFontsForURL.argtypes = [c_void_p, c_uint32, c_void_p]