]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiFontLoader.h
eeae2903ebced622998a32f6ef6fd885d526112a
[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 "FontInfo.h"
18
19 #include "GuiFontMetrics.h"
20
21 #include "Encoding.h"
22
23 #include <QFont>
24
25 #include <boost/scoped_ptr.hpp>
26
27 namespace lyx {
28 namespace frontend {
29
30 /**
31  * Qt font loader for LyX. Matches Fonts against
32  * actual QFont instances, and also caches metrics.
33  */
34 class GuiFontInfo
35 {
36 public:
37         GuiFontInfo(FontInfo const & f);
38
39         /// The font instance
40         QFont font;
41         /// Metrics on the font
42         boost::scoped_ptr<GuiFontMetrics> metrics;
43 };
44
45
46 /// Hold info about a particular font
47 class GuiFontLoader : public FontLoader
48 {
49 public:
50         ///
51         GuiFontLoader();
52
53         /// Destructor
54         virtual ~GuiFontLoader() {}
55
56         virtual void update();
57         virtual bool available(FontInfo const & f);
58         inline virtual FontMetrics const & metrics(FontInfo const & f) {
59                 return *fontinfo(f).metrics.get();
60         }
61
62         /// Get the QFont for this FontInfo
63         QFont const & get(FontInfo const & f) {
64                 return fontinfo(f).font;
65         }
66
67
68         /// Get font info (font + metrics) for the given LyX font.
69         GuiFontInfo & fontinfo(FontInfo const & f) {
70                 // fi is a reference to the pointer type (GuiFontInfo *) in the
71                 // fontinfo_ table.
72                 GuiFontInfo * & fi =
73                         fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
74                 if (!fi)
75                         fi = new GuiFontInfo(f);
76                 return *fi;
77         }
78
79 private:
80         /// BUTT ugly !
81         GuiFontInfo * fontinfo_[NUM_FAMILIES][2][4][10];
82 };
83
84
85 } // namespace frontend
86 } // namespace lyx
87
88 #endif // QT4_FONTLOADER_H