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