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