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