]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/qfont_loader.h
42c508e1811f84f7a81d1999c7dd1df33707da87
[lyx.git] / src / frontends / qt2 / qfont_loader.h
1 // -*- C++ -*-
2 /**
3  * \file qfont_loader.h
4  * Copyright 1997 the LyX Team
5  * Read the file COPYING
6  *
7  * \author John Levon <moz@compsoc.man.ac.uk>
8  */
9
10 #ifndef QFONTLOADER_H
11 #define QFONTLOADER_H 
12
13 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #include <config.h>
18 #include <boost/smart_ptr.hpp>
19  
20 #include "lyxfont.h"
21  
22 #include "font_loader.h"
23 #include "LString.h"
24
25 #include <qfont.h>
26 #include <qfontmetrics.h>
27
28 /**
29  * Qt font loader for LyX. Matches LyXFonts against
30  * actual QFont instances, and also caches metrics.
31  */
32 class qfont_loader {
33 public:
34         qfont_loader();
35
36         virtual ~qfont_loader();
37
38         /// update fonts after zoom, dpi, font names, or norm change
39         virtual void update();
40
41         /// do we have anything matching?
42         virtual bool available(LyXFont const & f);
43  
44         /// get the QFont for this LyXFont
45         QFont const & get(LyXFont const & f) {
46                 return getfontinfo(f)->font;
47         }
48
49         /// get the QFont metrics for this LyXFont
50         QFontMetrics const & metrics(LyXFont const & f) {
51                 return getfontinfo(f)->metrics;
52         }
53
54 private:
55         /// hold info about a particular font
56         struct font_info {
57                 font_info(LyXFont const & f);
58
59                 /// the font instance
60                 QFont font;
61                 /// metrics on the font
62                 QFontMetrics metrics;
63         };
64  
65         /// get font info (font + metrics) for the given LyX font. Does not fail.
66         font_info const * getfontinfo(LyXFont const & f);
67  
68         /// BUTT ugly !
69         boost::scoped_ptr<font_info> fontinfo_[LyXFont::NUM_FAMILIES][2][4][10]; 
70 };
71
72 extern qfont_loader fontloader;
73  
74 #endif // QFONT_LOADER_H