]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/qfont_loader.C
add debug for what fonts we use
[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         font.setPointSize(int((lyxrc.font_sizes[f.size()] * lyxrc.dpi * 
68                 (lyxrc.zoom / 100.0)) / 72.27 + 0.5));
69  
70         // FIXME: lyxrc, check for failure etc.
71  
72         switch (f.family()) {
73                 case LyXFont::SYMBOL_FAMILY:
74                         font.setRawName("-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific");
75                         break;
76                 case LyXFont::CMR_FAMILY:
77                         font.setRawName("-*-cmr10-medium-*-*-*-*-*-*-*-*-*-*-*");
78                         break;
79                 case LyXFont::CMSY_FAMILY:
80                         font.setRawName("-*-cmsy10-*-*-*-*-*-*-*-*-*-*-*-*");
81                         break;
82                 case LyXFont::CMM_FAMILY:
83                         font.setRawName("-*-cmmi10-medium-*-*-*-*-*-*-*-*-*-*-*");
84                         break;
85                 case LyXFont::CMEX_FAMILY:
86                         font.setRawName("-*-cmex10-*-*-*-*-*-*-*-*-*-*-*-*");
87                         break;
88                 case LyXFont::MSA_FAMILY:
89                         font.setRawName("-*-msam10-*-*-*-*-*-*-*-*-*-*-*-*");
90                         break;
91                 case LyXFont::MSB_FAMILY:
92                         font.setRawName("-*-msbm10-*-*-*-*-*-*-*-*-*-*-*-*");
93                         break;
94                 case LyXFont::EUFRAK_FAMILY:
95                         font.setRawName("-*-eufm10-medium-*-*-*-*-*-*-*-*-*-*-*");
96                         break;
97                 case LyXFont::ROMAN_FAMILY:
98                         font.setFamily("times");
99                         break;
100                 case LyXFont::SANS_FAMILY:
101                         font.setFamily("helvetica");
102                         break;
103                 case LyXFont::TYPEWRITER_FAMILY:
104                         font.setFamily("courier");
105                         break;
106         }
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.shape()) {
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.shape()][f.size()].get();
135         if (fi) {
136                 return fi;
137         } else {
138                 fi = new font_info(f); 
139                 fontinfo_[f.family()][f.series()][f.shape()][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 }