lyx_mirror/src/frontends/qt4/GuiFontLoader.h
Abdelrazak Younes 00edcc582f This commit is a big rework of the FontLoader/FontMetrics interaction. Only Qt4 for now, I would be grateful is somebody steps up for qt3 and gtk.
Basically, I replaced all methods in the font_metrics namespace by a proper virtual interface FontMetrics. The FontLoader is _the_ container for FontMetrics.

This patch should also bring some optimizations in a number of place in the code. This is because we do not need any more to search for the LyXFont at each font_metrics call. In effect, the speed advantage is not as sensible and this is a bit deceiving considering that this was my primary motivation behind the patch. But I like the patch anyway as it cleans up the relation and interfacing between fonts, metrics and frontends.

* frontends/FontMetrics.h: new virtual interface. Renamed from font_metrics.h

* qt4/GuiFontMetrics: corresponding qt4 implememtation. Renamed from qfont_metrics.C. The smallCaps particular case treatment has been transfered here as well as the width cache for MacOSX and Windows.

* qt4/QLPainter.C: the smallCapsText has been reworked to return the width of the drawn text.C

all other files: replace font_metric helper function call with corresponding FontMetrics method calls.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15265 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-07 16:15:06 +00:00

85 lines
1.6 KiB
C++

// -*- C++ -*-
/**
* \file GuiFontLoader.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author John Levon
*
* Full author contact details are available in file CREDITS.
*/
#ifndef QT4_FONTLOADER_H
#define QT4_FONTLOADER_H
#include "frontends/FontLoader.h"
#include "GuiFontMetrics.h"
#include "encoding.h"
#include "lyxfont.h"
#include <QFont>
namespace lyx {
namespace frontend {
/**
* Qt font loader for LyX. Matches LyXFonts against
* actual QFont instances, and also caches metrics.
*/
class QLFontInfo {
public:
QLFontInfo(LyXFont const & f);
/// The font instance
QFont font;
/// Metrics on the font
boost::scoped_ptr<GuiFontMetrics> metrics;
};
/// Hold info about a particular font
class GuiFontLoader: public FontLoader
{
public:
///
GuiFontLoader();
/// Destructor
virtual ~GuiFontLoader();
virtual void update();
virtual bool available(LyXFont const & f);
inline virtual FontMetrics const & metrics(LyXFont const & f) {
return *fontinfo(f).metrics.get();
}
/// Get the QFont for this LyXFont
QFont const & get(LyXFont const & f) {
return fontinfo(f).font;
}
/// Get font info (font + metrics) for the given LyX font.
QLFontInfo & fontinfo(LyXFont const & f) {
// fi is a reference to the pointer type (QLFontInfo *) in the
// fontinfo_ table.
QLFontInfo * & fi =
fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
if (!fi)
fi = new QLFontInfo(f);
return *fi;
}
private:
/// BUTT ugly !
QLFontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
};
} // namespace frontend
} // namespace lyx
#endif // QT4_FONTLOADER_H