Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
243fcce
commit cca95ba
Showing
4 changed files
with
193 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// A small python module that registers a font with ATS, given the name of | ||
// the font. | ||
|
||
#include <Python/Python.h> | ||
#include <CoreFoundation/CoreFoundation.h> | ||
#include <Carbon/Carbon.h> | ||
|
||
static PyObject* loadfont(PyObject* self, PyObject* args) { | ||
PyObject* result = Py_False; | ||
const char* path = NULL; | ||
int ok = PyArg_ParseTuple(args, "s", &path); | ||
|
||
if (ok) { | ||
CFStringRef componentPath = CFStringCreateWithCString(kCFAllocatorDefault, | ||
path, kCFStringEncodingUTF8); | ||
CFURLRef componentURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, | ||
componentPath, kCFURLPOSIXPathStyle, false); | ||
FSRef fsref; | ||
|
||
if (CFURLGetFSRef(componentURL, &fsref)) { | ||
OSStatus err = noErr; | ||
ATSFontContainerRef fontContainerRef; // we don't deactivate the font | ||
#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) | ||
err = ATSFontActivateFromFileReference(&fsref, | ||
kATSFontContextLocal, kATSFontFormatUnspecified, NULL, | ||
kATSOptionFlagsDefault, &fontContainerRef); | ||
#else | ||
FSSpec fsSpec; | ||
FSRef fsRef; | ||
if ((err = FSGetCatalogInfo( | ||
&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL)) == noErr) { | ||
err = ATSFontActivateFromFileSpecification(&fsSpec, | ||
kATSFontContextLocal, kATSFontFormatUnspecified, NULL, | ||
kATSOptionFlagsDefault, &fontContainerRef); | ||
} | ||
|
||
#endif | ||
|
||
if (err == noErr) { | ||
result = Py_True; | ||
} | ||
} | ||
CFRelease(componentURL); | ||
CFRelease(componentPath); | ||
} | ||
return result; | ||
} | ||
|
||
static PyMethodDef LoadfontMethods[] = { | ||
{ "loadfont", loadfont, METH_VARARGS, "Locally activates font from file." }, | ||
{ NULL, NULL, 0, NULL } | ||
}; | ||
|
||
PyMODINIT_FUNC initloadfont(void) { | ||
Py_InitModule("loadfont", LoadfontMethods); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters