]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/qfont_loader.h
widthcache ting
[lyx.git] / src / frontends / qt2 / qfont_loader.h
1 // -*- C++ -*-
2 /**
3  * \file qfont_loader.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 QFONTLOADER_H
13 #define QFONTLOADER_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include <map>
20  
21 #include "encoding.h"
22 #include "lyxfont.h"
23
24 #include <qfont.h>
25 #include <qfontmetrics.h>
26  
27 /**
28  * Qt font loader for LyX. Matches LyXFonts against
29  * actual QFont instances, and also caches metrics.
30  */
31 class qfont_loader {
32 public:
33         qfont_loader();
34
35         ~qfont_loader();
36
37         /// update fonts after zoom, dpi, font names, or norm change
38         void update();
39
40         /// do we have anything matching?
41         bool available(LyXFont const & f);
42
43         /// get the QFont for this LyXFont
44         QFont const & get(LyXFont const & f);
45
46         /// get the QFont metrics for this LyXFont
47         QFontMetrics const & metrics(LyXFont const & f) {
48                 return getfontinfo(f)->metrics;
49         }
50
51         /// return pixel width for the given unicode char
52         int charwidth(LyXFont const & f, Uchar val);
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                 typedef std::map<Uchar, int> WidthCache;
65                 /// cache of char widths 
66                 WidthCache widthcache;
67         };
68
69         /// get font info (font + metrics) for the given LyX font. Does not fail.
70         font_info * getfontinfo(LyXFont const & f);
71
72         /// BUTT ugly !
73         font_info * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
74 };
75
76 extern qfont_loader fontloader;
77
78 #endif // QFONT_LOADER_H