summaryrefslogtreecommitdiffstats
path: root/security/sandbox/test/mac_register_font.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /security/sandbox/test/mac_register_font.py
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'security/sandbox/test/mac_register_font.py')
-rwxr-xr-xsecurity/sandbox/test/mac_register_font.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/security/sandbox/test/mac_register_font.py b/security/sandbox/test/mac_register_font.py
new file mode 100755
index 0000000000..549becf565
--- /dev/null
+++ b/security/sandbox/test/mac_register_font.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"""
+mac_register_font.py
+
+Mac-specific utility command to register a font file with the OS.
+"""
+
+import argparse
+import sys
+
+import Cocoa
+import CoreText
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "-v",
+ "--verbose",
+ action="store_true",
+ help="print verbose registration failures",
+ default=False,
+ )
+ parser.add_argument(
+ "file", nargs="*", help="font file to register or unregister", default=[]
+ )
+ parser.add_argument(
+ "-u",
+ "--unregister",
+ action="store_true",
+ help="unregister the provided fonts",
+ default=False,
+ )
+ parser.add_argument(
+ "-p",
+ "--persist-user",
+ action="store_true",
+ help="permanently register the font",
+ default=False,
+ )
+
+ args = parser.parse_args()
+
+ if args.persist_user:
+ scope = CoreText.kCTFontManagerScopeUser
+ scopeDesc = "user"
+ else:
+ scope = CoreText.kCTFontManagerScopeSession
+ scopeDesc = "session"
+
+ failureCount = 0
+ for fontPath in args.file:
+ fontURL = Cocoa.NSURL.fileURLWithPath_(fontPath)
+ (result, error) = register_or_unregister_font(fontURL, args.unregister, scope)
+ if result:
+ print(
+ "%sregistered font %s with %s scope"
+ % (("un" if args.unregister else ""), fontPath, scopeDesc)
+ )
+ else:
+ print(
+ "Failed to %sregister font %s with %s scope"
+ % (("un" if args.unregister else ""), fontPath, scopeDesc)
+ )
+ if args.verbose:
+ print(error)
+ failureCount += 1
+
+ sys.exit(failureCount)
+
+
+def register_or_unregister_font(fontURL, unregister, scope):
+ return (
+ CoreText.CTFontManagerUnregisterFontsForURL(fontURL, scope, None)
+ if unregister
+ else CoreText.CTFontManagerRegisterFontsForURL(fontURL, scope, None)
+ )
+
+
+if __name__ == "__main__":
+ main()