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()
51 for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) {
52 for (int i2 = 0; i1 < 2; ++i2) {
53 for (int i3 = 0; i1 < 4; ++i3) {
54 for (int i4 = 0; i1 < 10; ++i4) {
55 fontinfo_[i1][i2][i3][i4].reset(0);
63 QFont const & qfont_loader::get(LyXFont const & f)
65 QFont const & ret(getfontinfo(f)->font);
67 if (lyxerr.debugging(Debug::FONT)) {
68 lyxerr[Debug::FONT] << "Font '" << f.stateText(0)
69 << "' matched by\n" << ret.rawName() << endl;
72 lyxerr[Debug::FONT] << "The font has size: "
73 << ret.pointSizeFloat() << endl;
80 string const symbolPattern(LyXFont::FONT_FAMILY family)
83 case LyXFont::SYMBOL_FAMILY:
84 return "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific";
86 case LyXFont::CMR_FAMILY:
87 return "-*-cmr10-medium-*-*-*-*-*-*-*-*-*-*-*";
89 case LyXFont::CMSY_FAMILY:
90 return "-*-cmsy10-*-*-*-*-*-*-*-*-*-*-*-*";
92 case LyXFont::CMM_FAMILY:
93 return "-*-cmmi10-medium-*-*-*-*-*-*-*-*-*-*-*";
95 case LyXFont::CMEX_FAMILY:
96 return "-*-cmex10-*-*-*-*-*-*-*-*-*-*-*-*";
98 case LyXFont::MSA_FAMILY:
99 return "-*-msam10-*-*-*-*-*-*-*-*-*-*-*-*";
101 case LyXFont::MSB_FAMILY:
102 return "-*-msbm10-*-*-*-*-*-*-*-*-*-*-*-*";
104 case LyXFont::EUFRAK_FAMILY:
105 return "-*-eufm10-medium-*-*-*-*-*-*-*-*-*-*-*";
107 case LyXFont::WASY_FAMILY:
108 return "-*-wasy10-medium-*-*-*-*-*-*-*-*-*-*-*";
118 string const dir = OnlyPath(LibFileSearch("xfonts", "fonts.dir"));
122 char ** p = XGetFontPath(w.x11Display(), &n);
123 if (std::find(p, p + n, dir) != p + n)
125 lyxerr << "Adding " << dir << " to the font path.\n";
126 string const command = "xset fp+ " + dir;
128 if (!s.startscript(Systemcall::Wait, command))
130 lyxerr << "Unable to add font path.\n";
136 bool isAvailable(QFont const & font, LyXFont const & f) {
137 #if QT_VERSION >= 300
138 return font.exactMatch();
140 string tmp = symbolPattern(f.family());
144 return token(tmp, '-', 2) ==
145 token(font.rawName().latin1(), '-', 2);
151 qfont_loader::font_info::font_info(LyXFont const & f)
155 string pat = symbolPattern(f.family());
157 static bool first_time = true;
158 font.setRawName(pat.c_str());
159 if (f.family() != LyXFont::SYMBOL_FAMILY &&
160 !isAvailable(font, f) && first_time) {
163 font.setRawName(pat.c_str());
167 switch (f.family()) {
168 case LyXFont::ROMAN_FAMILY:
169 font.setFamily("times");
171 case LyXFont::SANS_FAMILY:
172 font.setFamily("helvetica");
174 case LyXFont::TYPEWRITER_FAMILY:
175 font.setFamily("courier");
181 font.setPointSizeFloat(lyxrc.font_sizes[f.size()]
182 * lyxrc.zoom / 100.0);
184 // FIXME: lyxrc, check for failure etc.
186 switch (f.series()) {
187 case LyXFont::MEDIUM_SERIES:
188 font.setWeight(QFont::Normal);
190 case LyXFont::BOLD_SERIES:
191 font.setWeight(QFont::Bold);
195 switch (f.realShape()) {
196 case LyXFont::ITALIC_SHAPE:
197 case LyXFont::SLANTED_SHAPE:
198 font.setItalic(true);
202 // Is this an exact match?
203 if (font.exactMatch()) {
204 lyxerr[Debug::FONT] << "This font is an exact match" << endl;
206 lyxerr[Debug::FONT] << "This font is NOT an exact match"
210 lyxerr[Debug::FONT] << "XFLD: " << font.rawName() << endl;
212 metrics = QFontMetrics(font);
216 qfont_loader::font_info const * qfont_loader::getfontinfo(LyXFont const & f)
218 if (!lyxrc.use_gui) {
222 font_info * fi = fontinfo_[f.family()][f.series()][f.realShape()][f.size()].get();
224 fi = new font_info(f);
225 fontinfo_[f.family()][f.series()][f.realShape()][f.size()].reset(fi);
232 bool qfont_loader::available(LyXFont const & f)
237 return isAvailable(getfontinfo(f)->font, f);