3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
9 * Full author contact details are available in file CREDITS.
11 * General font utilities.
16 #include "fontutils.h"
18 #include "support/filetools.h"
19 #include "support/lstrings.h"
20 #include "support/systemcall.h"
23 #include <ApplicationServices/ApplicationServices.h>
26 #if defined(_WIN32) || (defined(__CYGWIN__) && defined(X_DISPLAY_MISSING))
32 #include "support/os.h"
33 #include "support/package.h"
34 #include "support/path.h"
35 using lyx::support::addName;
36 using lyx::support::addPath;
37 using lyx::support::package;
38 namespace os = lyx::support::os;
42 string const win_fonts_truetype[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
43 "eufm10", "msam10", "msbm10", "wasy10"};
44 const int num_fonts_truetype = sizeof(win_fonts_truetype) / sizeof(*win_fonts_truetype);
51 void addFontResources()
54 CFBundleRef myAppBundle = CFBundleGetMainBundle();
55 CFURLRef myAppResourcesURL, FontsURL;
58 CFStringRef filePath = CFStringCreateWithBytes(kCFAllocatorDefault,
59 (UInt8 *) "Fonts", strlen("Fonts"),
60 kCFStringEncodingISOLatin1, false);
62 myAppResourcesURL = CFBundleCopyResourcesDirectoryURL(myAppBundle);
63 FontsURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault,
64 myAppResourcesURL, filePath, true);
65 if (lyxerr.debugging(Debug::FONT)) {
67 if (CFURLGetFileSystemRepresentation(FontsURL, true, buf, 255))
68 lyxerr << "Adding Fonts directory: " << buf << endl;
70 CFURLGetFSRef (FontsURL, &fontDirRef);
71 OSStatus err = FSGetCatalogInfo (&fontDirRef, kFSCatInfoNone,
72 NULL, NULL, &fontDirSpec, NULL);
74 lyxerr << "FSGetCatalogInfo err = " << err << endl;
75 err = FMActivateFonts (&fontDirSpec, NULL, NULL,
76 kFMLocalActivationContext);
78 lyxerr << "FMActivateFonts err = " << err << endl;
81 #if defined(_WIN32) || (defined(__CYGWIN__) && defined(X_DISPLAY_MISSING))
82 // Windows only: Add BaKoMa TrueType font resources
83 string const fonts_dir = addPath(package().system_support(), "fonts");
85 for (int i = 0 ; i < num_fonts_truetype ; ++i) {
86 string const font_current =
87 addName(fonts_dir, win_fonts_truetype[i] + ".ttf");
88 AddFontResource(os::external_path(font_current).c_str());
94 void restoreFontResources()
96 #if defined(_WIN32) || (defined(__CYGWIN__) && defined(X_DISPLAY_MISSING))
97 // Windows only: Remove BaKoMa TrueType font resources
98 string const fonts_dir = addPath(package().system_support(), "fonts");
100 for(int i = 0 ; i < num_fonts_truetype ; ++i) {
101 string const font_current =
102 addName(fonts_dir, win_fonts_truetype[i] + ".ttf");
103 RemoveFontResource(os::external_path(font_current).c_str());
108 } //namespace support