3 * \file GuiFontLoader.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef QT4_FONTLOADER_H
13 #define QT4_FONTLOADER_H
15 #include "frontends/FontLoader.h"
21 #include <QFontMetrics>
23 // Starting with version 3.1.0, Qt/X11 does its own caching of
24 // character width, so it is not necessary to provide ours.
25 #if defined(Q_WS_MACX)
26 #define USE_LYX_FONTCACHE
34 * Qt font loader for LyX. Matches LyXFonts against
35 * actual QFont instances, and also caches metrics.
39 QLFontInfo(LyXFont const & f);
43 /// Metrics on the font
46 #ifndef USE_LYX_FONTCACHE
47 /// Return pixel width for the given unicode char
48 int width(Uchar val) { return metrics.width(QChar(val)); }
51 /// Return pixel width for the given unicode char
55 typedef std::map<Uchar, int> WidthCache;
56 /// Cache of char widths
57 WidthCache widthcache;
58 #endif // USE_LYX_FONTCACHE
62 /// Hold info about a particular font
63 class GuiFontLoader: public FontLoader
70 virtual ~GuiFontLoader();
72 /// Update fonts after zoom, dpi, font names, or norm change
73 virtual void update();
75 /// Do we have anything matching?
76 virtual bool available(LyXFont const & f);
78 /// Get the QFont for this LyXFont
79 QFont const & get(LyXFont const & f) {
80 return fontinfo(f).font;
83 /// Get the QFont metrics for this LyXFont
84 QFontMetrics const & metrics(LyXFont const & f) {
85 return fontinfo(f).metrics;
88 /// Get font info (font + metrics) for the given LyX font.
89 QLFontInfo & fontinfo(LyXFont const & f) {
90 // fi is a reference to the pointer type (QLFontInfo *) in the
93 fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
95 fi = new QLFontInfo(f);
101 QLFontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
105 } // namespace frontend
108 #endif // QT4_FONTLOADER_H