2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2008-03-20 00:00:53 +00:00
|
|
|
* \file FontLoader.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Asger Alstrup
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2008-03-20 00:00:53 +00:00
|
|
|
#include "FontLoader.h"
|
|
|
|
|
|
|
|
#include "FontInfo.h"
|
2008-03-20 00:19:10 +00:00
|
|
|
#include "GuiFontMetrics.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include "support/convert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/filetools.h"
|
2013-04-25 21:27:10 +00:00
|
|
|
#include "support/gettext.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/lstrings.h"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
#include "support/Systemcall.h"
|
2007-09-07 16:22:05 +00:00
|
|
|
#include "support/Package.h"
|
|
|
|
#include "support/os.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-11 21:27:57 +00:00
|
|
|
#include <QFontInfo>
|
2007-09-07 16:22:05 +00:00
|
|
|
#include <QFontDatabase>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2008-03-20 00:00:53 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
using namespace std;
|
2007-12-12 19:57:42 +00:00
|
|
|
using namespace lyx::support;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-15 22:56:09 +00:00
|
|
|
QString const math_fonts[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
|
2012-12-15 12:02:40 +00:00
|
|
|
"esint10", "eufm10", "msam10", "msbm10", "rsfs10", "stmary10",
|
|
|
|
"wasy10"};
|
2007-09-07 16:22:05 +00:00
|
|
|
int const num_math_fonts = sizeof(math_fonts) / sizeof(*math_fonts);
|
|
|
|
|
2006-10-03 16:17:32 +00:00
|
|
|
namespace lyx {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
|
|
|
extern docstring const stateText(FontInfo const & f);
|
|
|
|
|
2006-10-03 16:17:32 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2008-03-20 00:19:10 +00:00
|
|
|
/**
|
|
|
|
* Matches Fonts against
|
|
|
|
* actual QFont instances, and also caches metrics.
|
|
|
|
*/
|
|
|
|
class GuiFontInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GuiFontInfo(FontInfo const & f);
|
|
|
|
|
|
|
|
/// The font instance
|
|
|
|
QFont font;
|
|
|
|
/// Metrics on the font
|
|
|
|
GuiFontMetrics metrics;
|
|
|
|
};
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace {
|
|
|
|
|
2007-09-15 22:56:09 +00:00
|
|
|
struct SymbolFont {
|
2007-10-28 18:51:54 +00:00
|
|
|
FontFamily lyx_family;
|
2007-09-15 22:56:09 +00:00
|
|
|
QString family;
|
|
|
|
QString xlfd;
|
2006-03-05 17:24:44 +00:00
|
|
|
};
|
|
|
|
|
2007-09-15 22:56:09 +00:00
|
|
|
SymbolFont symbol_fonts[] = {
|
2008-03-21 16:16:43 +00:00
|
|
|
{ SYMBOL_FAMILY,"symbol", "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific"},
|
|
|
|
{ CMR_FAMILY, "cmr10", "-*-cmr10-medium-*-*-*-*-*-*-*-*-*-*-*" },
|
|
|
|
{ CMSY_FAMILY, "cmsy10", "-*-cmsy10-*-*-*-*-*-*-*-*-*-*-*-*" },
|
|
|
|
{ CMM_FAMILY, "cmmi10", "-*-cmmi10-medium-*-*-*-*-*-*-*-*-*-*-*" },
|
|
|
|
{ CMEX_FAMILY, "cmex10", "-*-cmex10-*-*-*-*-*-*-*-*-*-*-*-*" },
|
|
|
|
{ MSA_FAMILY, "msam10", "-*-msam10-*-*-*-*-*-*-*-*-*-*-*-*" },
|
|
|
|
{ MSB_FAMILY, "msbm10", "-*-msbm10-*-*-*-*-*-*-*-*-*-*-*-*" },
|
|
|
|
{ EUFRAK_FAMILY,"eufm10", "-*-eufm10-medium-*-*-*-*-*-*-*-*-*-*-*" },
|
2010-07-17 15:51:11 +00:00
|
|
|
{ RSFS_FAMILY, "rsfs10", "-*-rsfs10-medium-*-*-*-*-*-*-*-*-*-*-*" },
|
2012-12-15 12:02:40 +00:00
|
|
|
{ STMARY_FAMILY,"stmary10","-*-stmary10-medium-*-*-*-*-*-*-*-*-*-*-*" },
|
2008-03-21 16:16:43 +00:00
|
|
|
{ WASY_FAMILY, "wasy10", "-*-wasy10-medium-*-*-*-*-*-*-*-*-*-*-*" },
|
|
|
|
{ ESINT_FAMILY, "esint10","-*-esint10-medium-*-*-*-*-*-*-*-*-*-*-*" }
|
2006-03-05 17:24:44 +00:00
|
|
|
};
|
|
|
|
|
2008-03-20 00:00:53 +00:00
|
|
|
size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(symbol_fonts[0]);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-20 00:00:53 +00:00
|
|
|
/// BUTT ugly !
|
2012-12-09 12:04:29 +00:00
|
|
|
static GuiFontInfo * fontinfo_[NUM_FAMILIES][NUM_SERIES][NUM_SHAPE][NUM_SIZE];
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-20 00:00:53 +00:00
|
|
|
|
2013-04-25 21:27:10 +00:00
|
|
|
// Get font info (font + metrics) for the given LyX font.
|
2008-03-20 00:00:53 +00:00
|
|
|
// if not cached, create it.
|
|
|
|
GuiFontInfo & fontinfo(FontInfo const & f)
|
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
// LASSERT: Is there anything we might do here besides crash?
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(f.family() < NUM_FAMILIES);
|
|
|
|
LBUFERR(f.series() < NUM_SERIES);
|
|
|
|
LBUFERR(f.realShape() < NUM_SHAPE);
|
|
|
|
LBUFERR(f.size() < NUM_SIZE);
|
2008-03-20 00:00:53 +00:00
|
|
|
// fi is a reference to the pointer type (GuiFontInfo *) in the
|
|
|
|
// fontinfo_ table.
|
|
|
|
GuiFontInfo * & fi =
|
|
|
|
fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
|
|
|
|
if (!fi)
|
|
|
|
fi = new GuiFontInfo(f);
|
|
|
|
return *fi;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString rawName(QString const & family)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < nr_symbol_fonts; ++i)
|
|
|
|
if (family == symbol_fonts[i].family)
|
|
|
|
return symbol_fonts[i].xlfd;
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::FONT, "BUG: family not found !");
|
2007-09-15 22:56:09 +00:00
|
|
|
return QString();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-20 00:00:53 +00:00
|
|
|
QString symbolFamily(FontFamily family)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < nr_symbol_fonts; ++i) {
|
|
|
|
if (family == symbol_fonts[i].lyx_family)
|
|
|
|
return symbol_fonts[i].family;
|
|
|
|
}
|
2007-09-15 22:56:09 +00:00
|
|
|
return QString();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-02 14:38:25 +00:00
|
|
|
#if 0
|
2007-10-28 18:51:54 +00:00
|
|
|
bool isSymbolFamily(FontFamily family)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
return family >= SYMBOL_FAMILY && family <= ESINT_FAMILY;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2013-05-02 14:38:25 +00:00
|
|
|
#endif
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
Solve the "soft-hyphen" (0x00ad) symbol problem.
After the str-metrics merge, the kludge for displaying symbols whose
code point corresponds to a soft-hyphen was not working anymore.
The solution is replicating the offending glyphs with index 0x00ad
at a different index. They were replicated at 0x00ac, whose glyph
was missing in all affected fonts.
However, this would not work by alone because, if a system font with
same family name exists, it would be picked up instead of the right one
(at least on non-Windows platforms). For this reason, the style of the
fonts has been changed from "Regular" to "Lyx", so that we can discriminate
the right font. However, this requires using at least Qt 4.8. If an
older Qt is used *and* a system font with same family name is already
available, the affected glyphs will all turn out on screen as the
"logical not" symbol.
I have also set the executable flag on the font files, because on Windows
they are loaded only in this case.
This solves #9229.
2015-01-21 12:57:55 +00:00
|
|
|
static bool isChosenFont(QFont & font, QString const & family,
|
|
|
|
QString const & style)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-11-13 17:35:18 +00:00
|
|
|
// QFontInfo won't find a font that has only a few glyphs at unusual
|
|
|
|
// positions, e.g. the original esint10 font.
|
|
|
|
// The workaround is to add dummy glyphs at least at all ASCII
|
|
|
|
// positions.
|
2006-12-06 13:38:07 +00:00
|
|
|
QFontInfo fi(font);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-05-02 22:07:51 +00:00
|
|
|
LYXERR(Debug::FONT, "got: " << fi.family());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
Solve the "soft-hyphen" (0x00ad) symbol problem.
After the str-metrics merge, the kludge for displaying symbols whose
code point corresponds to a soft-hyphen was not working anymore.
The solution is replicating the offending glyphs with index 0x00ad
at a different index. They were replicated at 0x00ac, whose glyph
was missing in all affected fonts.
However, this would not work by alone because, if a system font with
same family name exists, it would be picked up instead of the right one
(at least on non-Windows platforms). For this reason, the style of the
fonts has been changed from "Regular" to "Lyx", so that we can discriminate
the right font. However, this requires using at least Qt 4.8. If an
older Qt is used *and* a system font with same family name is already
available, the affected glyphs will all turn out on screen as the
"logical not" symbol.
I have also set the executable flag on the font files, because on Windows
they are loaded only in this case.
This solves #9229.
2015-01-21 12:57:55 +00:00
|
|
|
if (fi.family().contains(family)
|
|
|
|
#if QT_VERSION >= 0x040800
|
|
|
|
&& (style.isEmpty() || fi.styleName().contains(style))
|
|
|
|
#endif
|
|
|
|
) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::FONT, " got it ");
|
2006-03-05 17:24:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-29 22:38:53 +00:00
|
|
|
QFont symbolFont(QString const & family, bool * ok)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-04-20 21:05:35 +00:00
|
|
|
LYXERR(Debug::FONT, "Looking for font family " << family << " ... ");
|
2007-09-15 22:56:09 +00:00
|
|
|
QString upper = family;
|
|
|
|
upper[0] = family[0].toUpper();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
QFont font;
|
2007-09-15 22:56:09 +00:00
|
|
|
font.setFamily(family);
|
Solve the "soft-hyphen" (0x00ad) symbol problem.
After the str-metrics merge, the kludge for displaying symbols whose
code point corresponds to a soft-hyphen was not working anymore.
The solution is replicating the offending glyphs with index 0x00ad
at a different index. They were replicated at 0x00ac, whose glyph
was missing in all affected fonts.
However, this would not work by alone because, if a system font with
same family name exists, it would be picked up instead of the right one
(at least on non-Windows platforms). For this reason, the style of the
fonts has been changed from "Regular" to "Lyx", so that we can discriminate
the right font. However, this requires using at least Qt 4.8. If an
older Qt is used *and* a system font with same family name is already
available, the affected glyphs will all turn out on screen as the
"logical not" symbol.
I have also set the executable flag on the font files, because on Windows
they are loaded only in this case.
This solves #9229.
2015-01-21 12:57:55 +00:00
|
|
|
#if QT_VERSION >= 0x040800
|
|
|
|
font.setStyleName("LyX");
|
|
|
|
|
|
|
|
if (isChosenFont(font, family, "LyX")) {
|
|
|
|
LYXERR(Debug::FONT, "lyx!");
|
|
|
|
*ok = true;
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
LYXERR(Debug::FONT, "Trying normal " << family << " ... ");
|
|
|
|
font.setStyleName(QString());
|
|
|
|
#endif
|
2006-03-05 17:24:44 +00:00
|
|
|
|
Solve the "soft-hyphen" (0x00ad) symbol problem.
After the str-metrics merge, the kludge for displaying symbols whose
code point corresponds to a soft-hyphen was not working anymore.
The solution is replicating the offending glyphs with index 0x00ad
at a different index. They were replicated at 0x00ac, whose glyph
was missing in all affected fonts.
However, this would not work by alone because, if a system font with
same family name exists, it would be picked up instead of the right one
(at least on non-Windows platforms). For this reason, the style of the
fonts has been changed from "Regular" to "Lyx", so that we can discriminate
the right font. However, this requires using at least Qt 4.8. If an
older Qt is used *and* a system font with same family name is already
available, the affected glyphs will all turn out on screen as the
"logical not" symbol.
I have also set the executable flag on the font files, because on Windows
they are loaded only in this case.
This solves #9229.
2015-01-21 12:57:55 +00:00
|
|
|
if (isChosenFont(font, family, QString())) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::FONT, "normal!");
|
2007-11-29 22:38:53 +00:00
|
|
|
*ok = true;
|
|
|
|
return font;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 21:05:35 +00:00
|
|
|
LYXERR(Debug::FONT, "Trying " << upper << " ... ");
|
2007-09-15 22:56:09 +00:00
|
|
|
font.setFamily(upper);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
Solve the "soft-hyphen" (0x00ad) symbol problem.
After the str-metrics merge, the kludge for displaying symbols whose
code point corresponds to a soft-hyphen was not working anymore.
The solution is replicating the offending glyphs with index 0x00ad
at a different index. They were replicated at 0x00ac, whose glyph
was missing in all affected fonts.
However, this would not work by alone because, if a system font with
same family name exists, it would be picked up instead of the right one
(at least on non-Windows platforms). For this reason, the style of the
fonts has been changed from "Regular" to "Lyx", so that we can discriminate
the right font. However, this requires using at least Qt 4.8. If an
older Qt is used *and* a system font with same family name is already
available, the affected glyphs will all turn out on screen as the
"logical not" symbol.
I have also set the executable flag on the font files, because on Windows
they are loaded only in this case.
This solves #9229.
2015-01-21 12:57:55 +00:00
|
|
|
if (isChosenFont(font, upper, QString())) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::FONT, "upper!");
|
2007-11-29 22:38:53 +00:00
|
|
|
*ok = true;
|
|
|
|
return font;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A simple setFamily() fails on Qt 2
|
|
|
|
|
2008-03-20 00:19:10 +00:00
|
|
|
QString const raw = rawName(family);
|
2008-04-20 21:05:35 +00:00
|
|
|
LYXERR(Debug::FONT, "Trying " << raw << " ... ");
|
2008-03-20 00:19:10 +00:00
|
|
|
font.setRawName(raw);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
Solve the "soft-hyphen" (0x00ad) symbol problem.
After the str-metrics merge, the kludge for displaying symbols whose
code point corresponds to a soft-hyphen was not working anymore.
The solution is replicating the offending glyphs with index 0x00ad
at a different index. They were replicated at 0x00ac, whose glyph
was missing in all affected fonts.
However, this would not work by alone because, if a system font with
same family name exists, it would be picked up instead of the right one
(at least on non-Windows platforms). For this reason, the style of the
fonts has been changed from "Regular" to "Lyx", so that we can discriminate
the right font. However, this requires using at least Qt 4.8. If an
older Qt is used *and* a system font with same family name is already
available, the affected glyphs will all turn out on screen as the
"logical not" symbol.
I have also set the executable flag on the font files, because on Windows
they are loaded only in this case.
This solves #9229.
2015-01-21 12:57:55 +00:00
|
|
|
if (isChosenFont(font, family, QString())) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::FONT, "raw version!");
|
2007-11-29 22:38:53 +00:00
|
|
|
*ok = true;
|
|
|
|
return font;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::FONT, " FAILED :-(");
|
2007-11-29 22:38:53 +00:00
|
|
|
*ok = false;
|
|
|
|
return font;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2008-03-20 00:00:53 +00:00
|
|
|
FontLoader::FontLoader()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-15 22:56:09 +00:00
|
|
|
QString const fonts_dir =
|
2010-04-21 01:19:09 +00:00
|
|
|
toqstr(addPath(package().system_support().absFileName(), "fonts"));
|
2007-09-07 16:22:05 +00:00
|
|
|
|
|
|
|
for (int i = 0 ; i < num_math_fonts; ++i) {
|
2014-05-19 20:09:12 +00:00
|
|
|
QString const font_file = fonts_dir + math_fonts[i] + ".ttf";
|
2007-09-15 22:56:09 +00:00
|
|
|
int fontID = QFontDatabase::addApplicationFont(font_file);
|
2007-09-07 16:22:05 +00:00
|
|
|
|
2008-04-20 21:05:35 +00:00
|
|
|
LYXERR(Debug::FONT, "Adding font " << font_file
|
|
|
|
<< (fontID < 0 ? " FAIL" : " OK"));
|
2007-09-07 16:22:05 +00:00
|
|
|
}
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
for (int i1 = 0; i1 < NUM_FAMILIES; ++i1)
|
2012-12-09 12:04:29 +00:00
|
|
|
for (int i2 = 0; i2 < NUM_SERIES; ++i2)
|
|
|
|
for (int i3 = 0; i3 < NUM_SHAPE; ++i3)
|
|
|
|
for (int i4 = 0; i4 < NUM_SIZE; ++i4)
|
2006-03-05 17:24:44 +00:00
|
|
|
fontinfo_[i1][i2][i3][i4] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-20 00:00:53 +00:00
|
|
|
void FontLoader::update()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-03-21 16:16:43 +00:00
|
|
|
for (int i1 = 0; i1 < NUM_FAMILIES; ++i1)
|
2012-12-09 12:04:29 +00:00
|
|
|
for (int i2 = 0; i2 < NUM_SERIES; ++i2)
|
|
|
|
for (int i3 = 0; i3 < NUM_SHAPE; ++i3)
|
|
|
|
for (int i4 = 0; i4 < NUM_SIZE; ++i4) {
|
2006-03-05 17:24:44 +00:00
|
|
|
delete fontinfo_[i1][i2][i3][i4];
|
|
|
|
fontinfo_[i1][i2][i3][i4] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-20 00:00:53 +00:00
|
|
|
FontLoader::~FontLoader()
|
2007-12-02 18:39:05 +00:00
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/////////////////////////////////////////////////
|
|
|
|
|
2015-11-09 09:11:57 +00:00
|
|
|
namespace {
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2015-11-09 09:11:57 +00:00
|
|
|
QString makeFontName(QString const & family, QString const & foundry)
|
2007-09-15 15:42:22 +00:00
|
|
|
{
|
2007-09-15 22:56:09 +00:00
|
|
|
QString res = family;
|
|
|
|
if (!foundry.isEmpty())
|
|
|
|
res += " [" + foundry + ']';
|
2007-09-15 15:42:22 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-09 09:11:57 +00:00
|
|
|
QFont makeQFont(FontInfo const & f)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2015-11-09 09:11:57 +00:00
|
|
|
QFont font;
|
2007-09-15 22:56:09 +00:00
|
|
|
QString const pat = symbolFamily(f.family());
|
|
|
|
if (!pat.isEmpty()) {
|
2007-11-29 22:38:53 +00:00
|
|
|
bool ok;
|
|
|
|
font = symbolFont(pat, &ok);
|
2006-03-05 17:24:44 +00:00
|
|
|
} else {
|
|
|
|
switch (f.family()) {
|
2007-10-28 18:51:54 +00:00
|
|
|
case ROMAN_FAMILY: {
|
2007-09-15 22:56:09 +00:00
|
|
|
QString family = makeFontName(toqstr(lyxrc.roman_font_name),
|
2010-12-29 05:50:50 +00:00
|
|
|
toqstr(lyxrc.roman_font_foundry));
|
2007-06-04 12:10:30 +00:00
|
|
|
font.setFamily(family);
|
2014-08-25 18:08:59 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2010-12-29 05:50:50 +00:00
|
|
|
#if QT_VERSION >= 0x040300 //&& QT_VERSION < 0x040800
|
2009-12-11 00:59:10 +00:00
|
|
|
// Workaround for a Qt bug, see http://www.lyx.org/trac/ticket/3684
|
2010-12-29 05:50:50 +00:00
|
|
|
// and http://bugreports.qt.nokia.com/browse/QTBUG-11145.
|
|
|
|
// FIXME: Check whether this is really fixed in Qt 4.8
|
2007-06-04 12:10:30 +00:00
|
|
|
if (family == "Times" && !font.exactMatch())
|
2007-09-15 22:56:09 +00:00
|
|
|
font.setFamily("Times New Roman");
|
2007-06-04 12:10:30 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
2007-06-04 12:10:30 +00:00
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
case SANS_FAMILY:
|
2007-09-15 22:56:09 +00:00
|
|
|
font.setFamily(makeFontName(toqstr(lyxrc.sans_font_name),
|
|
|
|
toqstr(lyxrc.sans_font_foundry)));
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
2007-10-28 18:51:54 +00:00
|
|
|
case TYPEWRITER_FAMILY:
|
2007-09-15 22:56:09 +00:00
|
|
|
font.setFamily(makeFontName(toqstr(lyxrc.typewriter_font_name),
|
|
|
|
toqstr(lyxrc.typewriter_font_foundry)));
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (f.series()) {
|
2007-10-28 18:51:54 +00:00
|
|
|
case MEDIUM_SERIES:
|
2006-03-05 17:24:44 +00:00
|
|
|
font.setWeight(QFont::Normal);
|
|
|
|
break;
|
2007-10-28 18:51:54 +00:00
|
|
|
case BOLD_SERIES:
|
2006-03-05 17:24:44 +00:00
|
|
|
font.setWeight(QFont::Bold);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (f.realShape()) {
|
2007-10-28 18:51:54 +00:00
|
|
|
case ITALIC_SHAPE:
|
2014-05-07 10:06:56 +00:00
|
|
|
font.setStyle(QFont::StyleItalic);
|
|
|
|
break;
|
2007-10-28 18:51:54 +00:00
|
|
|
case SLANTED_SHAPE:
|
2014-05-07 10:06:56 +00:00
|
|
|
font.setStyle(QFont::StyleOblique);
|
|
|
|
break;
|
|
|
|
case SMALLCAPS_SHAPE:
|
|
|
|
font.setCapitalization(QFont::SmallCaps);
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-20 21:05:35 +00:00
|
|
|
LYXERR(Debug::FONT, "Font '" << stateText(f)
|
|
|
|
<< "' matched by\n" << font.family());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// Is this an exact match?
|
|
|
|
if (font.exactMatch())
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::FONT, "This font is an exact match");
|
2006-03-05 17:24:44 +00:00
|
|
|
else
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::FONT, "This font is NOT an exact match");
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-05-02 22:07:51 +00:00
|
|
|
LYXERR(Debug::FONT, "XFLD: " << font.rawName());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
|
|
|
|
* lyxrc.zoom / 100.0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::FONT, "The font has size: " << font.pointSizeF());
|
2006-10-07 16:15:06 +00:00
|
|
|
|
2015-11-09 09:11:57 +00:00
|
|
|
return font;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 09:11:57 +00:00
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
|
|
|
GuiFontInfo::GuiFontInfo(FontInfo const & f)
|
|
|
|
: font(makeQFont(f)), metrics(font)
|
|
|
|
{}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-20 00:00:53 +00:00
|
|
|
bool FontLoader::available(FontInfo const & f)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2013-10-07 22:59:05 +00:00
|
|
|
// FIXME THREAD
|
2007-12-12 19:28:07 +00:00
|
|
|
static vector<int> cache_set(NUM_FAMILIES, false);
|
|
|
|
static vector<int> cache(NUM_FAMILIES, false);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
FontFamily family = f.family();
|
2014-08-25 18:08:59 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2014-06-07 08:50:11 +00:00
|
|
|
// Apple ships a font name "Symbol", which has more or less the same
|
|
|
|
// glyphs as the original PostScript Symbol font, but it uses a different
|
|
|
|
// encoding (see https://en.wikipedia.org/wiki/Symbol_(typeface)#cite_note-2).
|
|
|
|
// Since we expect the font specific encoding of the original
|
|
|
|
// PostScript Symbol font, we can't use the one provided on OS X.
|
|
|
|
// See also the discussion in bug 7954.
|
|
|
|
if (f.family() == SYMBOL_FAMILY)
|
|
|
|
return false;
|
|
|
|
#endif
|
2006-03-05 17:24:44 +00:00
|
|
|
if (cache_set[family])
|
|
|
|
return cache[family];
|
|
|
|
cache_set[family] = true;
|
|
|
|
|
2007-09-15 22:56:09 +00:00
|
|
|
QString const pat = symbolFamily(family);
|
|
|
|
if (pat.isEmpty())
|
2006-03-05 17:24:44 +00:00
|
|
|
// We don't care about non-symbol fonts
|
|
|
|
return false;
|
|
|
|
|
2007-11-29 22:38:53 +00:00
|
|
|
bool ok;
|
|
|
|
symbolFont(pat, &ok);
|
|
|
|
if (!ok)
|
2006-03-05 17:24:44 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
cache[family] = true;
|
|
|
|
return true;
|
|
|
|
}
|
2006-10-03 16:17:32 +00:00
|
|
|
|
2008-03-20 00:19:10 +00:00
|
|
|
|
2014-03-08 10:13:39 +00:00
|
|
|
bool FontLoader::canBeDisplayed(char_type c)
|
|
|
|
{
|
|
|
|
// bug 8493
|
|
|
|
if (c == 0x0009)
|
|
|
|
// FIXME check whether this is still needed for Qt5
|
|
|
|
return false;
|
|
|
|
#if QT_VERSION < 0x050000 && defined(QT_MAC_USE_COCOA) && (QT_MAC_USE_COCOA > 0)
|
|
|
|
// bug 7954, see also comment in GuiPainter::text()
|
|
|
|
if (c == 0x00ad)
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-20 00:00:53 +00:00
|
|
|
FontMetrics const & FontLoader::metrics(FontInfo const & f)
|
|
|
|
{
|
|
|
|
return fontinfo(f).metrics;
|
|
|
|
}
|
|
|
|
|
2008-03-20 00:19:10 +00:00
|
|
|
|
|
|
|
GuiFontMetrics const & getFontMetrics(FontInfo const & f)
|
2008-03-20 00:00:53 +00:00
|
|
|
{
|
2008-03-20 00:19:10 +00:00
|
|
|
return fontinfo(f).metrics;
|
2008-03-20 00:00:53 +00:00
|
|
|
}
|
|
|
|
|
2008-03-20 00:19:10 +00:00
|
|
|
|
|
|
|
QFont const & getFont(FontInfo const & f)
|
2008-03-20 00:00:53 +00:00
|
|
|
{
|
2008-03-20 00:19:10 +00:00
|
|
|
return fontinfo(f).font;
|
2008-03-20 00:00:53 +00:00
|
|
|
}
|
|
|
|
|
2006-10-03 16:17:32 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|