3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
9 * Full author contact details are available in file CREDITS
15 #pragma implementation
18 #include "qfont_loader.h"
22 #include "BufferView.h"
26 #include "support/lstrings.h"
32 #include "support/systemcall.h"
33 #include "support/filetools.h"
39 qfont_loader::qfont_loader()
44 qfont_loader::~qfont_loader()
49 void qfont_loader::update()
53 for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) {
54 for (int i2 = 0; i1 < 2; ++i2) {
55 for (int i3 = 0; i1 < 4; ++i3) {
56 for (int i4 = 0; i1 < 10; ++i4) {
57 fontinfo_[i1][i2][i3][i4].reset(0);
66 QFont const & qfont_loader::get(LyXFont const & f)
68 QFont const & ret(getfontinfo(f)->font);
70 if (lyxerr.debugging(Debug::FONT)) {
71 lyxerr[Debug::FONT] << "Font '" << f.stateText(0)
72 << "' matched by\n" << ret.rawName() << endl;
75 lyxerr[Debug::FONT] << "The font has size: "
76 << ret.pointSizeFloat() << endl;
83 string const symbolPattern(LyXFont::FONT_FAMILY family)
86 case LyXFont::SYMBOL_FAMILY:
87 return "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific";
89 case LyXFont::CMR_FAMILY:
90 return "-*-cmr10-medium-*-*-*-*-*-*-*-*-*-*-*";
92 case LyXFont::CMSY_FAMILY:
93 return "-*-cmsy10-*-*-*-*-*-*-*-*-*-*-*-*";
95 case LyXFont::CMM_FAMILY:
96 return "-*-cmmi10-medium-*-*-*-*-*-*-*-*-*-*-*";
98 case LyXFont::CMEX_FAMILY:
99 return "-*-cmex10-*-*-*-*-*-*-*-*-*-*-*-*";
101 case LyXFont::MSA_FAMILY:
102 return "-*-msam10-*-*-*-*-*-*-*-*-*-*-*-*";
104 case LyXFont::MSB_FAMILY:
105 return "-*-msbm10-*-*-*-*-*-*-*-*-*-*-*-*";
107 case LyXFont::EUFRAK_FAMILY:
108 return "-*-eufm10-medium-*-*-*-*-*-*-*-*-*-*-*";
110 case LyXFont::WASY_FAMILY:
111 return "-*-wasy10-medium-*-*-*-*-*-*-*-*-*-*-*";
121 string const dir = OnlyPath(LibFileSearch("xfonts", "fonts.dir"));
125 char ** p = XGetFontPath(w.x11Display(), &n);
126 if (std::find(p, p + n, dir) != p + n)
128 lyxerr << "Adding " << dir << " to the font path.\n";
129 string const command = "xset fp+ " + dir;
131 if (!s.startscript(Systemcall::Wait, command))
133 lyxerr << "Unable to add font path.\n";
139 bool isAvailable(QFont const & font, LyXFont const & f) {
140 #if QT_VERSION >= 300
141 return font.exactMatch();
143 string tmp = symbolPattern(f.family());
147 return token(tmp, '-', 2) ==
148 token(font.rawName().latin1(), '-', 2);
154 qfont_loader::font_info::font_info(LyXFont const & f)
158 string pat = symbolPattern(f.family());
160 static bool first_time = true;
161 font.setRawName(pat.c_str());
162 if (f.family() != LyXFont::SYMBOL_FAMILY &&
163 !isAvailable(font, f) && first_time) {
166 font.setRawName(pat.c_str());
170 switch (f.family()) {
171 case LyXFont::ROMAN_FAMILY:
172 font.setFamily("times");
174 case LyXFont::SANS_FAMILY:
175 font.setFamily("helvetica");
177 case LyXFont::TYPEWRITER_FAMILY:
178 font.setFamily("courier");
184 font.setPointSizeFloat(lyxrc.font_sizes[f.size()]
185 * lyxrc.zoom / 100.0);
187 // FIXME: lyxrc, check for failure etc.
189 switch (f.series()) {
190 case LyXFont::MEDIUM_SERIES:
191 font.setWeight(QFont::Normal);
193 case LyXFont::BOLD_SERIES:
194 font.setWeight(QFont::Bold);
198 switch (f.realShape()) {
199 case LyXFont::ITALIC_SHAPE:
200 case LyXFont::SLANTED_SHAPE:
201 font.setItalic(true);
205 // Is this an exact match?
206 if (font.exactMatch()) {
207 lyxerr[Debug::FONT] << "This font is an exact match" << endl;
209 lyxerr[Debug::FONT] << "This font is NOT an exact match"
213 lyxerr[Debug::FONT] << "XFLD: " << font.rawName() << endl;
215 metrics = QFontMetrics(font);
219 qfont_loader::font_info const * qfont_loader::getfontinfo(LyXFont const & f)
221 if (!lyxrc.use_gui) {
225 font_info * fi = fontinfo_[f.family()][f.series()][f.realShape()][f.size()].get();
227 fi = new font_info(f);
228 fontinfo_[f.family()][f.series()][f.realShape()][f.size()].reset(fi);
235 bool qfont_loader::available(LyXFont const & f)
240 return isAvailable(getfontinfo(f)->font, f);