#include "frontends/FontLoader.h"
-#include "encoding.h"
-#include "lyxfont.h"
+#include "FontInfo.h"
-#include <QFont>
-#include <QFontMetrics>
+#include "GuiFontMetrics.h"
+
+#include "Encoding.h"
-//#if QT_VERSION < 0x030100
-#define USE_LYX_FONTCACHE
-//#endif
+#include <QFont>
-#if defined(USE_LYX_FONTCACHE)
-#include <map>
-#endif
+#include <boost/assert.hpp>
namespace lyx {
namespace frontend {
/**
- * Qt font loader for LyX. Matches LyXFonts against
+ * Qt font loader for LyX. Matches Fonts against
* actual QFont instances, and also caches metrics.
*/
-class QLFontInfo {
+class GuiFontInfo
+{
public:
- QLFontInfo(LyXFont const & f);
-
- /// Return pixel width for the given unicode char
- int width(Uchar val);
+ GuiFontInfo(FontInfo const & f);
/// The font instance
QFont font;
/// Metrics on the font
- QFontMetrics metrics;
-
-#if defined(USE_LYX_FONTCACHE)
- typedef std::map<Uchar, int> WidthCache;
- /// Cache of char widths
- WidthCache widthcache;
-#endif
+ GuiFontMetrics metrics;
};
/// Hold info about a particular font
-class GuiFontLoader: public FontLoader
+class GuiFontLoader : public FontLoader
{
public:
///
GuiFontLoader();
-
+
/// Destructor
virtual ~GuiFontLoader();
- /// Update fonts after zoom, dpi, font names, or norm change
virtual void update();
+ virtual bool available(FontInfo const & f);
+ inline virtual FontMetrics const & metrics(FontInfo const & f) {
+ return fontinfo(f).metrics;
+ }
- /// Do we have anything matching?
- virtual bool available(LyXFont const & f);
-
- /// Get the QFont for this LyXFont
- QFont const & get(LyXFont const & f) {
+ /// Get the QFont for this FontInfo
+ QFont const & get(FontInfo const & f) {
return fontinfo(f).font;
}
- /// Get the QFont metrics for this LyXFont
- QFontMetrics const & metrics(LyXFont const & f) {
- return fontinfo(f).metrics;
- }
/// 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
+ 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.
- QLFontInfo * & fi =
+ GuiFontInfo * & fi =
fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
if (!fi)
- fi = new QLFontInfo(f);
+ fi = new GuiFontInfo(f);
return *fi;
}
private:
/// BUTT ugly !
- QLFontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
+ GuiFontInfo * fontinfo_[NUM_FAMILIES][2][4][10];
};