]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/qfont_loader.C
Lots and lots of little trivial bits.
[lyx.git] / src / frontends / qt2 / qfont_loader.C
1 /**
2  * \file qfont_loader.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  * \author John Levon 
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "qfont_loader.h"
19 #include "gettext.h"
20 #include "debug.h"
21 #include "lyxrc.h"
22 #include "BufferView.h"
23  
24 using std::endl;
25  
26 qfont_loader::qfont_loader()
27 {
28 }
29
30
31 qfont_loader::~qfont_loader()
32 {
33 }
34
35
36 void qfont_loader::update()
37 {
38         int i1,i2,i3,i4;
39
40         // fuck this !
41  
42         for (i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) {
43                 for (i2 = 0; i1 < 2; ++i2) {
44                         for (i3 = 0; i1 < 4; ++i3) {
45                                 for (i4 = 0; i1 < 10; ++i4) {
46                                         fontinfo_[i1][i2][i3][i4].reset(0);
47                                 }
48                         }
49                 }
50         }
51 }
52
53  
54 QFont const & qfont_loader::get(LyXFont const & f)
55 {
56         QFont const & ret(getfontinfo(f)->font);
57  
58         if (lyxerr.debugging(Debug::FONT)) {
59                 lyxerr[Debug::FONT] << "Font '" << f.stateText(0)
60                         << "' matched by\n" << ret.rawName().latin1() << endl;
61         }
62         return ret;
63 }
64
65  
66 qfont_loader::font_info::font_info(LyXFont const & f)
67         : metrics(font)
68 {
69         switch (f.family()) {
70                 case LyXFont::SYMBOL_FAMILY:
71                         font.setRawName("-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific");
72                         break;
73                 case LyXFont::CMR_FAMILY:
74                         font.setRawName("-*-cmr10-medium-*-*-*-*-*-*-*-*-*-*-*");
75                         break;
76                 case LyXFont::CMSY_FAMILY:
77                         font.setRawName("-*-cmsy10-*-*-*-*-*-*-*-*-*-*-*-*");
78                         break;
79                 case LyXFont::CMM_FAMILY:
80                         font.setRawName("-*-cmmi10-medium-*-*-*-*-*-*-*-*-*-*-*");
81                         break;
82                 case LyXFont::CMEX_FAMILY:
83                         font.setRawName("-*-cmex10-*-*-*-*-*-*-*-*-*-*-*-*");
84                         break;
85                 case LyXFont::MSA_FAMILY:
86                         font.setRawName("-*-msam10-*-*-*-*-*-*-*-*-*-*-*-*");
87                         break;
88                 case LyXFont::MSB_FAMILY:
89                         font.setRawName("-*-msbm10-*-*-*-*-*-*-*-*-*-*-*-*");
90                         break;
91                 case LyXFont::EUFRAK_FAMILY:
92                         font.setRawName("-*-eufm10-medium-*-*-*-*-*-*-*-*-*-*-*");
93                         break;
94                 case LyXFont::ROMAN_FAMILY:
95                         font.setFamily("times");
96                         break;
97                 case LyXFont::SANS_FAMILY:
98                         font.setFamily("helvetica");
99                         break;
100                 case LyXFont::TYPEWRITER_FAMILY:
101                         font.setFamily("courier");
102                         break;
103         }
104  
105         font.setPointSize(int((lyxrc.font_sizes[f.size()] * lyxrc.dpi * 
106                 (lyxrc.zoom / 100.0)) / 72.27 + 0.5));
107  
108         // FIXME: lyxrc, check for failure etc.
109  
110         switch (f.series()) {
111                 case LyXFont::MEDIUM_SERIES:
112                         font.setWeight(QFont::Normal);
113                         break;
114                 case LyXFont::BOLD_SERIES:
115                         font.setWeight(QFont::Bold);
116                         break;
117         }
118  
119         switch (f.realShape()) {
120                 case LyXFont::ITALIC_SHAPE:
121                 case LyXFont::SLANTED_SHAPE:
122                         font.setItalic(true);
123                         break;
124         }
125
126         metrics = QFontMetrics(font);
127 }
128
129
130 qfont_loader::font_info const * qfont_loader::getfontinfo(LyXFont const & f)
131 {
132         if (!lyxrc.use_gui) {
133                 // FIXME
134         }
135
136         font_info * fi = fontinfo_[f.family()][f.series()][f.realShape()][f.size()].get();
137         if (fi) {
138                 return fi;
139         } else {
140                 fi = new font_info(f);
141                 fontinfo_[f.family()][f.series()][f.realShape()][f.size()].reset(fi);
142                 return fi;
143         }
144 }
145
146  
147 bool qfont_loader::available(LyXFont const &)
148 {
149         // FIXME (see getRawName docs)
150         return true;
151 }