]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiFontLoader.h
867ac3dd3c3b61d2bacb40804878c8231268dd85
[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/assert.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         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;
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                 BOOST_ASSERT(f.family() < NUM_FAMILIES);
71                 BOOST_ASSERT(f.series() < 2);
72                 BOOST_ASSERT(f.realShape() < 4);
73                 BOOST_ASSERT(f.size() < 10);
74                 // fi is a reference to the pointer type (GuiFontInfo *) in the
75                 // fontinfo_ table.
76                 GuiFontInfo * & fi =
77                         fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
78                 if (!fi)
79                         fi = new GuiFontInfo(f);
80                 return *fi;
81         }
82
83 private:
84         /// BUTT ugly !
85         GuiFontInfo * fontinfo_[NUM_FAMILIES][2][4][10];
86 };
87
88
89 } // namespace frontend
90 } // namespace lyx
91
92 #endif // QT4_FONTLOADER_H