]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiFontLoader.h
5fc718fbbfa1f07dab6f8be7cf705bf5bfc4ec18
[lyx.git] / src / frontends / qt4 / GuiFontLoader.h
1 // -*- C++ -*-
2 /**
3  * \file GuiFontLoader.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef QT4_FONTLOADER_H
13 #define QT4_FONTLOADER_H
14
15 #include "frontends/FontLoader.h"
16
17 #include "GuiFontMetrics.h"
18
19 #include "Encoding.h"
20 #include "Font.h"
21
22 #include <QFont>
23
24 namespace lyx {
25 namespace frontend {
26
27 /**
28  * Qt font loader for LyX. Matches Fonts against
29  * actual QFont instances, and also caches metrics.
30  */
31 class QLFontInfo
32 {
33 public:
34         QLFontInfo(Font const & f);
35
36         /// The font instance
37         QFont font;
38         /// Metrics on the font
39         boost::scoped_ptr<GuiFontMetrics> metrics;
40 };
41
42
43 /// Hold info about a particular font
44 class GuiFontLoader : public FontLoader
45 {
46 public:
47         ///
48         GuiFontLoader();
49
50         /// Destructor
51         virtual ~GuiFontLoader() {}
52
53         virtual void update();
54         virtual bool available(Font const & f);
55         inline virtual FontMetrics const & metrics(Font const & f) {
56                 return *fontinfo(f).metrics.get();
57         }
58
59         /// Get the QFont for this Font
60         QFont const & get(Font const & f) {
61                 return fontinfo(f).font;
62         }
63
64
65         /// Get font info (font + metrics) for the given LyX font.
66         QLFontInfo & fontinfo(Font const & f) {
67                 // fi is a reference to the pointer type (QLFontInfo *) in the
68                 // fontinfo_ table.
69                 QLFontInfo * & fi =
70                         fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
71                 if (!fi)
72                         fi = new QLFontInfo(f);
73                 return *fi;
74         }
75
76 private:
77         /// BUTT ugly !
78         QLFontInfo * fontinfo_[Font::NUM_FAMILIES][2][4][10];
79 };
80
81
82 } // namespace frontend
83 } // namespace lyx
84
85 #endif // QT4_FONTLOADER_H