xft-fonts package is still required. However, on *nix there seem
to be no way to tell fontconfig to prefer our fonts instead of
others matching the requirements, so, in case of conflict, the
fontconfig files should be manually adjusted, or some existing
font package used (note that the quality of the bakoma fonts is
better than that of the xft ones). There is no such problem on
Windows where our private fonts are always preferred over the
installed ones (and I hope the same holds true for Mac).
* src/LyX.cpp
(LyX::exec): don't call addFontResources() and restoreFontResources()
anymore, as the frontend code will do the job.
* src/frontends/qt4/GuiFontLoader.{cpp,h}
(GuiFontLoader::GuiFontLoader): register math fonts with Qt.
(GuiFontLoader::~GuiFontLoader): unregister math fonts.
* src/support/os.h
* src/support/os_unix.cpp
* src/support/os_win32.cpp
* src/support/os_cygwin.cpp:
remove code dealing with fonts.
* configure.ac: don't check for fontconfig headers anymore.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20128
a592a061-630c-0410-9148-
cb99ea01b6c8
# some standard header files
AC_HEADER_DIRENT
AC_HEADER_MAJOR
-AC_CHECK_HEADERS(sys/time.h sys/types.h sys/select.h strings.h locale.h io.h process.h NewAPIs.h utime.h sys/utime.h fontconfig/fontconfig.h)
+AC_CHECK_HEADERS(sys/time.h sys/types.h sys/select.h strings.h locale.h io.h process.h NewAPIs.h utime.h sys/utime.h)
# some standard structures
AC_HEADER_STAT
return !final_success;
}
- // Force adding of font path _before_ Application is initialized
- support::os::addFontResources();
-
// Let the frontend parse and remove all arguments that it knows
pimpl_->application_.reset(createApplication(argc, argv));
prepareExit();
- // Restore original font resources after Application is destroyed.
- support::os::restoreFontResources();
-
return exit_status;
}
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/Systemcall.h"
+#include "support/Package.h"
+#include "support/os.h"
#include <qfontinfo.h>
+#include <QFontDatabase>
#include <boost/tuple/tuple.hpp>
#endif
using lyx::support::contains;
+using lyx::support::package;
+using lyx::support::addPath;
+using lyx::support::addName;
using std::endl;
using std::make_pair;
using std::vector;
using std::string;
+#if QT_VERSION >= 0x040200
+string const math_fonts[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
+ "eufm10", "msam10", "msbm10", "wasy10", "esint10"};
+int const num_math_fonts = sizeof(math_fonts) / sizeof(*math_fonts);
+#endif
+
namespace lyx {
namespace frontend {
GuiFontLoader::GuiFontLoader()
{
+#if QT_VERSION >= 0x040200
+ fontID = new int[num_math_fonts];
+
+ string const fonts_dir =
+ addPath(package().system_support().absFilename(), "fonts");
+
+ for (int i = 0 ; i < num_math_fonts; ++i) {
+ string const font_file = lyx::support::os::external_path(
+ addName(fonts_dir, math_fonts[i] + ".ttf"));
+ fontID[i] = QFontDatabase::addApplicationFont(toqstr(font_file));
+
+ LYXERR(Debug::FONT) << "Adding font " << font_file
+ << static_cast<const char *>
+ (fontID[i] < 0 ? " FAIL" : " OK")
+ << endl;
+ }
+#endif
+
for (int i1 = 0; i1 < Font::NUM_FAMILIES; ++i1)
for (int i2 = 0; i2 < 2; ++i2)
for (int i3 = 0; i3 < 4; ++i3)
}
+GuiFontLoader::~GuiFontLoader()
+{
+#if QT_VERSION >= 0x040200
+ for (int i = 0 ; i < num_math_fonts; ++i) {
+ if (fontID[i] >= 0)
+ QFontDatabase::removeApplicationFont(fontID[i]);
+ }
+
+ delete [] fontID;
+#endif
+}
+
+
void GuiFontLoader::update()
{
for (int i1 = 0; i1 < Font::NUM_FAMILIES; ++i1) {
GuiFontLoader();
/// Destructor
- virtual ~GuiFontLoader() {}
+ ~GuiFontLoader();
virtual void update();
virtual bool available(Font const & f);
}
private:
+#if QT_VERSION >= 0x040200
+ int * fontID;
+#endif
/// BUTT ugly !
QLFontInfo * fontinfo_[Font::NUM_FAMILIES][2][4][10];
};
*/
bool autoOpenFile(std::string const & filename, auto_open_mode const mode = VIEW);
-/** General font utilities.
- * FIXME: only MAC and WIN32 for now but it would be nice to convince
- * fontconfig to do the same for linux.
- */
-
-/// Add fonts to the font subsystem, must be called before Application
-/// is initialized.
-void addFontResources();
-
-/// Restore original font resources, must be called after Application
-/// is destroyed.
-void restoreFontResources();
-
} // namespace os
} // namespace support
} // namespace lyx
using lyx::support::contains;
-#ifdef X_DISPLAY_MISSING
-#include "support/filetools.h"
-#include "support/Package.h"
-#include "support/Path.h"
-using lyx::support::addName;
-using lyx::support::addPath;
-using lyx::support::package;
-
-// API definition for manually calling font functions on Windows 2000 and later
-typedef int (WINAPI *FONTAPI)(LPCSTR, DWORD, PVOID);
-#define FR_PRIVATE 0x10
-
-// Names of TrueType fonts to load
-string const win_fonts_truetype[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
- "eufm10", "msam10", "msbm10", "wasy10", "esint10"};
-const int num_fonts_truetype = sizeof(win_fonts_truetype) / sizeof(*win_fonts_truetype);
-#endif
-
namespace lyx {
namespace support {
win_path.c_str(), NULL, NULL, 1)) > 32;
}
-
-void addFontResources()
-{
-#ifdef X_DISPLAY_MISSING
- // Windows only: Add BaKoMa TrueType font resources
- string const fonts_dir = addPath(package().system_support().absFilename(), "fonts");
-
- HMODULE hDLL = LoadLibrary("gdi32");
- FONTAPI pAddFontResourceEx =
- (FONTAPI) GetProcAddress(hDLL, "AddFontResourceExA");
-
- for (int i = 0 ; i < num_fonts_truetype ; ++i) {
- string const font_current = to_local8bit(from_utf8(convert_path(
- addName(fonts_dir, win_fonts_truetype[i] + ".ttf"),
- PathStyle(windows))));
- if (pAddFontResourceEx) {
- // Windows 2000 and later: Use AddFontResourceEx
- pAddFontResourceEx(font_current.c_str(), FR_PRIVATE, 0);
- } else {
- // Older Windows versions: Use AddFontResource
- AddFontResource(font_current.c_str());
- }
- }
- FreeLibrary(hDLL);
-#endif
-}
-
-
-void restoreFontResources()
-{
-#ifdef X_DISPLAY_MISSING
- // Windows only: Remove BaKoMa TrueType font resources
- string const fonts_dir = addPath(package().system_support().absFilename(), "fonts");
-
- HMODULE hDLL = LoadLibrary("gdi32");
- FONTAPI pRemoveFontResourceEx = (FONTAPI) GetProcAddress(hDLL, "RemoveFontResourceExA");
-
- for(int i = 0 ; i < num_fonts_truetype ; ++i) {
- string const font_current = to_local8bit(from_utf8(convert_path(
- addName(fonts_dir, win_fonts_truetype[i] + ".ttf"),
- PathStyle(windows))));
- if (pRemoveFontResourceEx) {
- // Windows 2000 and later: Use RemoveFontResourceEx
- pRemoveFontResourceEx(font_current.c_str(), FR_PRIVATE, 0);
- } else {
- // Older Windows versions: Use RemoveFontResource
- RemoveFontResource(font_current.c_str());
- }
- }
- FreeLibrary(hDLL);
-#endif
-}
-
} // namespace os
} // namespace support
} // namespace lyx
#include <config.h>
#include "support/os.h"
-#include "debug.h"
#ifdef __APPLE__
#include <Carbon/Carbon.h>
-#include <ApplicationServices/ApplicationServices.h>
-#elif defined(HAVE_FONTCONFIG_FONTCONFIG_H)
-#include "support/filetools.h"
-#include "support/Package.h"
-#include <fontconfig/fontconfig.h>
-using lyx::support::addPath;
#endif
-using std::endl;
using std::string;
#endif
}
-
-void addFontResources()
-{
-#ifdef __APPLE__
- 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;
-#elif defined(HAVE_FONTCONFIG_FONTCONFIG_H)
- // Register BaKoMa truetype fonts with fontconfig
- string const fonts_dir =
- addPath(package().system_support().absFilename(), "fonts");
- if (!FcConfigAppFontAddDir(0, (FcChar8 const *)fonts_dir.c_str()))
- lyxerr << "Unable to register fonts with fontconfig." << endl;
-#endif
-}
-
-
-void restoreFontResources()
-{
-#if defined(HAVE_FONTCONFIG_FONTCONFIG_H) && !defined(__APPLE__)
- FcConfigAppFontClear(0);
-#endif
-}
-
} // namespace os
} // namespace support
} // namespace lyx
#include "support/lstrings.h"
#include "support/filetools.h"
#include "support/ExceptionMessage.h"
-#include "support/Package.h"
-#include "support/Path.h"
#include "debug.h"
#include "gettext.h"
using lyx::support::runCommand;
using lyx::support::split;
-using lyx::support::addName;
-using lyx::support::addPath;
-using lyx::support::package;
-
-// API definition for manually calling font functions on Windows 2000 and later
-typedef int (WINAPI *FONTAPI)(LPCSTR, DWORD, PVOID);
-#define FR_PRIVATE 0x10
-
-// Names of TrueType fonts to load
-string const win_fonts_truetype[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
- "eufm10", "msam10", "msbm10", "wasy10", "esint10"};
-const int num_fonts_truetype = sizeof(win_fonts_truetype) / sizeof(*win_fonts_truetype);
namespace lyx {
to_local8bit(from_utf8(filename)).c_str(), NULL, NULL, 1)) > 32;
}
-
-void addFontResources()
-{
- // Windows only: Add BaKoMa TrueType font resources
- string const fonts_dir = addPath(package().system_support().absFilename(), "fonts");
-
- HMODULE hDLL = LoadLibrary("gdi32");
- FONTAPI pAddFontResourceEx = (FONTAPI) GetProcAddress(hDLL, "AddFontResourceExA");
-
- for (int i = 0 ; i < num_fonts_truetype ; ++i) {
- string const font_current =
- addName(fonts_dir, win_fonts_truetype[i] + ".ttf");
- if (pAddFontResourceEx) {
- // Windows 2000 and later: Use AddFontResourceEx for private font
- pAddFontResourceEx(to_local8bit(from_utf8(external_path(font_current))).c_str(), FR_PRIVATE, 0);
- } else {
- // Older Windows versions: Use AddFontResource
- AddFontResource(to_local8bit(from_utf8(external_path(font_current))).c_str());
- }
- }
-
- FreeLibrary(hDLL);
-}
-
-
-void restoreFontResources()
-{
- // Windows only: Remove BaKoMa TrueType font resources
- string const fonts_dir = addPath(package().system_support().absFilename(), "fonts");
-
- HMODULE hDLL = LoadLibrary("gdi32");
- FONTAPI pRemoveFontResourceEx = (FONTAPI) GetProcAddress(hDLL, "RemoveFontResourceExA");
-
- for(int i = 0 ; i < num_fonts_truetype ; ++i) {
- string const font_current =
- addName(fonts_dir, win_fonts_truetype[i] + ".ttf");
- if (pRemoveFontResourceEx) {
- // Windows 2000 and later: Use RemoveFontResourceEx for private font
- pRemoveFontResourceEx(to_local8bit(from_utf8(external_path(font_current))).c_str(), FR_PRIVATE, 0);
- } else {
- // Older Windows versions: Use RemoveFontResource
- RemoveFontResource(to_local8bit(from_utf8(external_path(font_current))).c_str());
- }
- }
-
- FreeLibrary(hDLL);
-}
-
} // namespace os
} // namespace support
} // namespace lyx