]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt2/qfont_loader.C
allow mac os x to find its fonts
[features.git] / src / frontends / qt2 / qfont_loader.C
index 8fb2f8bc75392ce618b11e7fd63fe56d2a333df5..7d545405e1804fdc9a77bcb7d37f5078aaabfa79 100644 (file)
@@ -43,6 +43,10 @@ using std::pair;
 using std::vector;
 using std::string;
 
+#ifdef Q_WS_MACX
+#include <ApplicationServices/ApplicationServices.h>
+#endif
+
 namespace {
 
 void addFontPath()
@@ -65,6 +69,33 @@ void addFontPath()
                       << endl;
        }
 #endif
+#ifdef Q_WS_MACX
+       CFBundleRef  myAppBundle = CFBundleGetMainBundle();
+       CFURLRef  myAppResourcesURL, FontsURL;
+       FSRef  fontDirRef;
+       FSSpec  fontDirSpec;
+       CFStringRef  filePath = CFStringCreateWithBytes(kCFAllocatorDefault,
+                                       (UInt8 *) "Fonts", strlen("Fonts"),  
+                                       kCFStringEncodingISOLatin1, false);
+
+       myAppResourcesURL = CFBundleCopyResourcesDirectoryURL(myAppBundle);
+       FontsURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, 
+                       myAppResourcesURL, filePath, true);
+       if (lyxerr.debugging(Debug::FONT)) {
+               UInt8  buf[255];
+               if (CFURLGetFileSystemRepresentation(FontsURL, true, buf, 255))
+                       lyxerr << "Adding Fonts directory: " << buf << endl;
+       }
+       CFURLGetFSRef (FontsURL, &fontDirRef);
+       OSStatus err = FSGetCatalogInfo (&fontDirRef, kFSCatInfoNone, 
+                                        NULL, NULL, &fontDirSpec, NULL);
+       if (err) 
+               lyxerr << "FSGetCatalogInfo err = " << err << endl;
+       err = FMActivateFonts (&fontDirSpec, NULL, NULL, 
+                              kFMLocalActivationContext); 
+       if (err)
+               lyxerr << "FMActivateFonts err = " << err << endl;
+#endif
 }
 
 
@@ -351,6 +382,13 @@ bool qfont_loader::available(LyXFont const & f)
 {
        if (!lyx_gui::use_gui)
                return false;
+#ifdef Q_WS_MACX
+       static bool need_bundle_fonts = true;
+       if (need_bundle_fonts) {
+               addFontPath();
+               need_bundle_fonts = false;
+       }
+#endif
 
        static vector<bool> cache_set(LyXFont::NUM_FAMILIES, false);
        static vector<bool> cache(LyXFont::NUM_FAMILIES, false);