mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-25 17:44:59 +00:00
simpliofy {Gui}FontLoader architecture a bit
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23842 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
bef955a971
commit
de17493932
@ -9,8 +9,8 @@
|
|||||||
* Full author contact details are available in file CREDITS.
|
* Full author contact details are available in file CREDITS.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LYX_FONTLOADER_H
|
#ifndef FONTLOADER_H
|
||||||
#define LYX_FONTLOADER_H
|
#define FONTLOADER_H
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
@ -25,18 +25,19 @@ class FontLoader
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
FontLoader() {}
|
FontLoader();
|
||||||
///
|
/// Clears cache
|
||||||
virtual ~FontLoader() {}
|
~FontLoader();
|
||||||
|
|
||||||
/// Update fonts after zoom, dpi, font names, or norm change
|
/// Update fonts after zoom, dpi, font names, or norm change
|
||||||
virtual void update() = 0;
|
// (basically by deleting all cached values)
|
||||||
|
void update();
|
||||||
|
|
||||||
/// Is the given font available ?
|
/// Is the given font available ?
|
||||||
virtual bool available(FontInfo const & f) = 0;
|
bool available(FontInfo const & f);
|
||||||
|
|
||||||
/// Get the Font metrics for this FontInfo
|
/// Get the Font metrics for this FontInfo
|
||||||
virtual FontMetrics const & metrics(FontInfo const & f) = 0;
|
FontMetrics const & metrics(FontInfo const & f);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -47,4 +48,4 @@ extern frontend::FontLoader & theFontLoader();
|
|||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
#endif // QFONT_LOADER_H
|
#endif // FONTLOADER_H
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#define GUIAPPLICATION_H
|
#define GUIAPPLICATION_H
|
||||||
|
|
||||||
#include "ColorCache.h"
|
#include "ColorCache.h"
|
||||||
#include "GuiFontLoader.h"
|
#include "FontLoader.h"
|
||||||
#include "GuiClipboard.h"
|
#include "GuiClipboard.h"
|
||||||
#include "GuiSelection.h"
|
#include "GuiSelection.h"
|
||||||
#include "Menus.h"
|
#include "Menus.h"
|
||||||
@ -104,8 +104,6 @@ public:
|
|||||||
|
|
||||||
///
|
///
|
||||||
ColorCache & colorCache() { return color_cache_; }
|
ColorCache & colorCache() { return color_cache_; }
|
||||||
///
|
|
||||||
GuiFontLoader & guiFontLoader() { return font_loader_; }
|
|
||||||
|
|
||||||
/// return a suitable serif font name.
|
/// return a suitable serif font name.
|
||||||
virtual QString const romanFontName();
|
virtual QString const romanFontName();
|
||||||
@ -142,7 +140,7 @@ private:
|
|||||||
///
|
///
|
||||||
GuiSelection selection_;
|
GuiSelection selection_;
|
||||||
///
|
///
|
||||||
GuiFontLoader font_loader_;
|
FontLoader font_loader_;
|
||||||
///
|
///
|
||||||
ColorCache color_cache_;
|
ColorCache color_cache_;
|
||||||
///
|
///
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "GuiDelimiter.h"
|
#include "GuiDelimiter.h"
|
||||||
|
|
||||||
#include "GuiApplication.h"
|
#include "GuiApplication.h"
|
||||||
|
#include "GuiFontLoader.h"
|
||||||
#include "GuiView.h"
|
#include "GuiView.h"
|
||||||
|
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
@ -91,8 +92,7 @@ GuiDelimiter::GuiDelimiter(GuiView & lv)
|
|||||||
lwi->setToolTip(toqstr(delim));
|
lwi->setToolTip(toqstr(delim));
|
||||||
FontInfo lyxfont;
|
FontInfo lyxfont;
|
||||||
lyxfont.setFamily(ms.fontfamily);
|
lyxfont.setFamily(ms.fontfamily);
|
||||||
QFont const & symbol_font = guiApp->guiFontLoader().get(lyxfont);
|
lwi->setFont(frontend::getFont(lyxfont));
|
||||||
lwi->setFont(symbol_font);
|
|
||||||
list_items[ms.unicode] = lwi;
|
list_items[ms.unicode] = lwi;
|
||||||
leftLW->addItem(lwi);
|
leftLW->addItem(lwi);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* \file GuiFontLoader.cpp
|
* \file FontLoader.cpp
|
||||||
* This file is part of LyX, the document processor.
|
* This file is part of LyX, the document processor.
|
||||||
* Licence details can be found in the file COPYING.
|
* Licence details can be found in the file COPYING.
|
||||||
*
|
*
|
||||||
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
#include "FontLoader.h"
|
||||||
|
|
||||||
|
#include "FontInfo.h"
|
||||||
#include "GuiFontLoader.h"
|
#include "GuiFontLoader.h"
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
|
||||||
@ -27,6 +30,8 @@
|
|||||||
#include <QFontInfo>
|
#include <QFontInfo>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace lyx::support;
|
using namespace lyx::support;
|
||||||
|
|
||||||
@ -34,7 +39,6 @@ QString const math_fonts[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
|
|||||||
"eufm10", "msam10", "msbm10", "wasy10", "esint10"};
|
"eufm10", "msam10", "msbm10", "wasy10", "esint10"};
|
||||||
int const num_math_fonts = sizeof(math_fonts) / sizeof(*math_fonts);
|
int const num_math_fonts = sizeof(math_fonts) / sizeof(*math_fonts);
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
extern docstring const stateText(FontInfo const & f);
|
extern docstring const stateText(FontInfo const & f);
|
||||||
@ -91,10 +95,31 @@ SymbolFont symbol_fonts[] = {
|
|||||||
"-*-esint10-medium-*-*-*-*-*-*-*-*-*-*-*" }
|
"-*-esint10-medium-*-*-*-*-*-*-*-*-*-*-*" }
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(SymbolFont);
|
size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(symbol_fonts[0]);
|
||||||
|
|
||||||
|
/// BUTT ugly !
|
||||||
|
static GuiFontInfo * fontinfo_[NUM_FAMILIES][2][4][10];
|
||||||
|
|
||||||
|
|
||||||
QString getRawName(QString const & family)
|
/// Get font info (font + metrics) for the given LyX font.
|
||||||
|
// if not cached, create it.
|
||||||
|
GuiFontInfo & fontinfo(FontInfo const & f)
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(f.family() < NUM_FAMILIES);
|
||||||
|
BOOST_ASSERT(f.series() < 2);
|
||||||
|
BOOST_ASSERT(f.realShape() < 4);
|
||||||
|
BOOST_ASSERT(f.size() < 10);
|
||||||
|
// 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)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < nr_symbol_fonts; ++i)
|
for (size_t i = 0; i < nr_symbol_fonts; ++i)
|
||||||
if (family == symbol_fonts[i].family)
|
if (family == symbol_fonts[i].family)
|
||||||
@ -105,7 +130,7 @@ QString getRawName(QString const & family)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString const symbolFamily(FontFamily family)
|
QString symbolFamily(FontFamily family)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < nr_symbol_fonts; ++i) {
|
for (size_t i = 0; i < nr_symbol_fonts; ++i) {
|
||||||
if (family == symbol_fonts[i].lyx_family)
|
if (family == symbol_fonts[i].lyx_family)
|
||||||
@ -168,7 +193,7 @@ QFont symbolFont(QString const & family, bool * ok)
|
|||||||
|
|
||||||
// A simple setFamily() fails on Qt 2
|
// A simple setFamily() fails on Qt 2
|
||||||
|
|
||||||
QString const rawName = getRawName(family);
|
QString const rawName = rawName(family);
|
||||||
LYXERR(Debug::FONT, "Trying " << fromqstr(rawName) << " ... ");
|
LYXERR(Debug::FONT, "Trying " << fromqstr(rawName) << " ... ");
|
||||||
font.setRawName(rawName);
|
font.setRawName(rawName);
|
||||||
|
|
||||||
@ -186,7 +211,7 @@ QFont symbolFont(QString const & family, bool * ok)
|
|||||||
} // namespace anon
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
GuiFontLoader::GuiFontLoader()
|
FontLoader::FontLoader()
|
||||||
{
|
{
|
||||||
QString const fonts_dir =
|
QString const fonts_dir =
|
||||||
toqstr(addPath(package().system_support().absFilename(), "fonts"));
|
toqstr(addPath(package().system_support().absFilename(), "fonts"));
|
||||||
@ -208,7 +233,7 @@ GuiFontLoader::GuiFontLoader()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiFontLoader::update()
|
void FontLoader::update()
|
||||||
{
|
{
|
||||||
for (int i1 = 0; i1 < NUM_FAMILIES; ++i1) {
|
for (int i1 = 0; i1 < NUM_FAMILIES; ++i1) {
|
||||||
for (int i2 = 0; i2 < 2; ++i2)
|
for (int i2 = 0; i2 < 2; ++i2)
|
||||||
@ -221,7 +246,7 @@ void GuiFontLoader::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GuiFontLoader::~GuiFontLoader()
|
FontLoader::~FontLoader()
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -328,7 +353,7 @@ GuiFontInfo::GuiFontInfo(FontInfo const & f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool GuiFontLoader::available(FontInfo const & f)
|
bool FontLoader::available(FontInfo const & f)
|
||||||
{
|
{
|
||||||
static vector<int> cache_set(NUM_FAMILIES, false);
|
static vector<int> cache_set(NUM_FAMILIES, false);
|
||||||
static vector<int> cache(NUM_FAMILIES, false);
|
static vector<int> cache(NUM_FAMILIES, false);
|
||||||
@ -352,5 +377,22 @@ bool GuiFontLoader::available(FontInfo const & f)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FontMetrics const & FontLoader::metrics(FontInfo const & f)
|
||||||
|
{
|
||||||
|
return fontinfo(f).metrics;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the QFont for this FontInfo
|
||||||
|
QFont const & getFont(FontInfo const & f)
|
||||||
|
{
|
||||||
|
return fontinfo(f).font;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the QFont for this FontInfo
|
||||||
|
GuiFontInfo const & getFontInfo(FontInfo const & f)
|
||||||
|
{
|
||||||
|
return fontinfo(f);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -9,21 +9,13 @@
|
|||||||
* Full author contact details are available in file CREDITS.
|
* Full author contact details are available in file CREDITS.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef QT4_FONTLOADER_H
|
#ifndef GUI_FONTLOADER_H
|
||||||
#define QT4_FONTLOADER_H
|
#define GUI_FONTLOADER_H
|
||||||
|
|
||||||
#include "frontends/FontLoader.h"
|
|
||||||
|
|
||||||
#include "FontInfo.h"
|
|
||||||
|
|
||||||
#include "GuiFontMetrics.h"
|
#include "GuiFontMetrics.h"
|
||||||
|
|
||||||
#include "Encoding.h"
|
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
|
|
||||||
@ -43,50 +35,12 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Hold info about a particular font
|
// Load font
|
||||||
class GuiFontLoader : public FontLoader
|
GuiFontInfo const & getFontInfo(FontInfo const & f);
|
||||||
{
|
/// Get the QFont for this FontInfo
|
||||||
public:
|
QFont const & getFont(FontInfo const & f);
|
||||||
///
|
|
||||||
GuiFontLoader();
|
|
||||||
|
|
||||||
/// Destructor
|
|
||||||
virtual ~GuiFontLoader();
|
|
||||||
|
|
||||||
virtual void update();
|
|
||||||
virtual bool available(FontInfo const & f);
|
|
||||||
inline virtual FontMetrics const & metrics(FontInfo const & f) {
|
|
||||||
return fontinfo(f).metrics;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the QFont for this FontInfo
|
|
||||||
QFont const & get(FontInfo const & f) {
|
|
||||||
return fontinfo(f).font;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Get font info (font + metrics) for the given LyX font.
|
|
||||||
GuiFontInfo & fontinfo(FontInfo const & f) {
|
|
||||||
BOOST_ASSERT(f.family() < NUM_FAMILIES);
|
|
||||||
BOOST_ASSERT(f.series() < 2);
|
|
||||||
BOOST_ASSERT(f.realShape() < 4);
|
|
||||||
BOOST_ASSERT(f.size() < 10);
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
/// BUTT ugly !
|
|
||||||
GuiFontInfo * fontinfo_[NUM_FAMILIES][2][4][10];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
#endif // QT4_FONTLOADER_H
|
#endif // GUI_FONTLOADER_H
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "GuiPainter.h"
|
#include "GuiPainter.h"
|
||||||
|
|
||||||
#include "GuiApplication.h"
|
#include "GuiApplication.h"
|
||||||
|
#include "GuiFontLoader.h"
|
||||||
#include "GuiFontMetrics.h"
|
#include "GuiFontMetrics.h"
|
||||||
#include "GuiImage.h"
|
#include "GuiImage.h"
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
@ -271,8 +272,8 @@ int GuiPainter::smallCapsText(int x, int y,
|
|||||||
FontInfo smallfont(f);
|
FontInfo smallfont(f);
|
||||||
smallfont.decSize().decSize().setShape(UP_SHAPE);
|
smallfont.decSize().decSize().setShape(UP_SHAPE);
|
||||||
|
|
||||||
QFont const & qfont = guiApp->guiFontLoader().get(f);
|
QFont const & qfont = getFont(f);
|
||||||
QFont const & qsmallfont = guiApp->guiFontLoader().get(smallfont);
|
QFont const & qsmallfont = getFont(smallfont);
|
||||||
|
|
||||||
setQPainterPen(computeColor(f.realColor()));
|
setQPainterPen(computeColor(f.realColor()));
|
||||||
int textwidth = 0;
|
int textwidth = 0;
|
||||||
@ -318,7 +319,7 @@ int GuiPainter::text(int x, int y, docstring const & s,
|
|||||||
str = ' ' + str;
|
str = ' ' + str;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GuiFontInfo & fi = guiApp->guiFontLoader().fontinfo(f);
|
GuiFontInfo const & fi = getFontInfo(f);
|
||||||
|
|
||||||
int textwidth;
|
int textwidth;
|
||||||
|
|
||||||
|
@ -35,11 +35,11 @@
|
|||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "Converter.h"
|
#include "Converter.h"
|
||||||
#include "Cursor.h"
|
#include "Cursor.h"
|
||||||
|
#include "Encoding.h"
|
||||||
#include "ErrorList.h"
|
#include "ErrorList.h"
|
||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
#include "FuncStatus.h"
|
#include "FuncStatus.h"
|
||||||
#include "FuncRequest.h"
|
#include "FuncRequest.h"
|
||||||
#include "support/gettext.h"
|
|
||||||
#include "Intl.h"
|
#include "Intl.h"
|
||||||
#include "Layout.h"
|
#include "Layout.h"
|
||||||
#include "Lexer.h"
|
#include "Lexer.h"
|
||||||
@ -57,6 +57,7 @@
|
|||||||
#include "support/FileFilterList.h"
|
#include "support/FileFilterList.h"
|
||||||
#include "support/FileName.h"
|
#include "support/FileName.h"
|
||||||
#include "support/filetools.h"
|
#include "support/filetools.h"
|
||||||
|
#include "support/gettext.h"
|
||||||
#include "support/ForkedCalls.h"
|
#include "support/ForkedCalls.h"
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
#include "support/os.h"
|
#include "support/os.h"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user