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"
23 #include "qt_helpers.h"
27 #include "support/lstrings.h"
33 #include "support/systemcall.h"
34 #include "support/filetools.h"
40 qfont_loader::qfont_loader()
42 for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) {
43 for (int i2 = 0; i2 < 2; ++i2) {
44 for (int i3 = 0; i3 < 4; ++i3) {
45 for (int i4 = 0; i4 < 10; ++i4) {
46 fontinfo_[i1][i2][i3][i4] = 0;
54 qfont_loader::~qfont_loader()
59 void qfont_loader::update()
61 for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) {
62 for (int i2 = 0; i2 < 2; ++i2) {
63 for (int i3 = 0; i3 < 4; ++i3) {
64 for (int i4 = 0; i4 < 10; ++i4) {
65 delete fontinfo_[i1][i2][i3][i4];
66 fontinfo_[i1][i2][i3][i4] = 0;
74 QFont const & qfont_loader::get(LyXFont const & f)
76 QFont const & ret(getfontinfo(f)->font);
78 if (lyxerr.debugging(Debug::FONT)) {
79 lyxerr[Debug::FONT] << "Font '" << f.stateText(0)
80 << "' matched by\n" << ret.rawName() << endl;
83 lyxerr[Debug::FONT] << "The font has size: "
84 << ret.pointSizeFloat() << endl;
91 string const symbolPattern(LyXFont::FONT_FAMILY family)
94 case LyXFont::SYMBOL_FAMILY:
95 return "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific";
97 case LyXFont::CMR_FAMILY:
98 return "-*-cmr10-medium-*-*-*-*-*-*-*-*-*-*-*";
100 case LyXFont::CMSY_FAMILY:
101 return "-*-cmsy10-*-*-*-*-*-*-*-*-*-*-*-*";
103 case LyXFont::CMM_FAMILY:
104 return "-*-cmmi10-medium-*-*-*-*-*-*-*-*-*-*-*";
106 case LyXFont::CMEX_FAMILY:
107 return "-*-cmex10-*-*-*-*-*-*-*-*-*-*-*-*";
109 case LyXFont::MSA_FAMILY:
110 return "-*-msam10-*-*-*-*-*-*-*-*-*-*-*-*";
112 case LyXFont::MSB_FAMILY:
113 return "-*-msbm10-*-*-*-*-*-*-*-*-*-*-*-*";
115 case LyXFont::EUFRAK_FAMILY:
116 return "-*-eufm10-medium-*-*-*-*-*-*-*-*-*-*-*";
118 case LyXFont::WASY_FAMILY:
119 return "-*-wasy10-medium-*-*-*-*-*-*-*-*-*-*-*";
129 string const dir = OnlyPath(LibFileSearch("xfonts", "fonts.dir"));
133 char ** p = XGetFontPath(w.x11Display(), &n);
134 if (std::find(p, p + n, dir) != p + n)
136 lyxerr << "Adding " << dir << " to the font path.\n";
137 string const command = "xset fp+ " + dir;
139 if (!s.startscript(Systemcall::Wait, command))
141 lyxerr << "Unable to add font path.\n";
147 bool isAvailable(QFont const & font, LyXFont const & f) {
148 #if QT_VERSION >= 300
149 return font.exactMatch();
151 string tmp = symbolPattern(f.family());
155 return token(tmp, '-', 2) ==
156 token(font.rawName().latin1(), '-', 2);
162 qfont_loader::font_info::font_info(LyXFont const & f)
166 string pat = symbolPattern(f.family());
168 static bool first_time = true;
169 font.setRawName(pat.c_str());
170 if (f.family() != LyXFont::SYMBOL_FAMILY &&
171 !isAvailable(font, f) && first_time) {
174 font.setRawName(pat.c_str());
178 switch (f.family()) {
179 case LyXFont::ROMAN_FAMILY:
180 font.setFamily(makeFontName(lyxrc.roman_font_name,
181 lyxrc.roman_font_foundry).c_str());
183 case LyXFont::SANS_FAMILY:
184 font.setFamily(makeFontName(lyxrc.sans_font_name,
185 lyxrc.sans_font_foundry).c_str());
187 case LyXFont::TYPEWRITER_FAMILY:
188 font.setFamily(makeFontName(lyxrc.typewriter_font_name,
189 lyxrc.typewriter_font_foundry).c_str());
195 font.setPointSizeFloat(lyxrc.font_sizes[f.size()]
196 * lyxrc.zoom / 100.0);
198 switch (f.series()) {
199 case LyXFont::MEDIUM_SERIES:
200 font.setWeight(QFont::Normal);
202 case LyXFont::BOLD_SERIES:
203 font.setWeight(QFont::Bold);
207 switch (f.realShape()) {
208 case LyXFont::ITALIC_SHAPE:
209 case LyXFont::SLANTED_SHAPE:
210 font.setItalic(true);
214 // Is this an exact match?
215 if (font.exactMatch()) {
216 lyxerr[Debug::FONT] << "This font is an exact match" << endl;
218 lyxerr[Debug::FONT] << "This font is NOT an exact match"
222 lyxerr[Debug::FONT] << "XFLD: " << font.rawName() << endl;
224 metrics = QFontMetrics(font);
228 qfont_loader::font_info const * qfont_loader::getfontinfo(LyXFont const & f)
230 if (!lyxrc.use_gui) {
234 font_info const * fi = fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
236 fi = new font_info(f);
237 fontinfo_[f.family()][f.series()][f.realShape()][f.size()] = fi;
244 bool qfont_loader::available(LyXFont const & f)
249 return isAvailable(getfontinfo(f)->font, f);