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"
25 #if QT_VERSION < 0x030000
26 #include "support/lstrings.h"
32 qfont_loader::qfont_loader()
37 qfont_loader::~qfont_loader()
42 void qfont_loader::update()
44 for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) {
45 for (int i2 = 0; i1 < 2; ++i2) {
46 for (int i3 = 0; i1 < 4; ++i3) {
47 for (int i4 = 0; i1 < 10; ++i4) {
48 fontinfo_[i1][i2][i3][i4].reset(0);
56 QFont const & qfont_loader::get(LyXFont const & f)
58 QFont const & ret(getfontinfo(f)->font);
60 if (lyxerr.debugging(Debug::FONT)) {
61 lyxerr[Debug::FONT] << "Font '" << f.stateText(0)
62 << "' matched by\n" << ret.rawName() << endl;
65 lyxerr[Debug::FONT] << "The font has size: "
66 << ret.pointSizeFloat() << endl;
72 qfont_loader::font_info::font_info(LyXFont const & f)
76 case LyXFont::SYMBOL_FAMILY:
77 font.setRawName("-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific");
79 case LyXFont::CMR_FAMILY:
80 font.setRawName("-*-cmr10-medium-*-*-*-*-*-*-*-*-*-*-*");
82 case LyXFont::CMSY_FAMILY:
83 font.setRawName("-*-cmsy10-*-*-*-*-*-*-*-*-*-*-*-*");
85 case LyXFont::CMM_FAMILY:
86 font.setRawName("-*-cmmi10-medium-*-*-*-*-*-*-*-*-*-*-*");
88 case LyXFont::CMEX_FAMILY:
89 font.setRawName("-*-cmex10-*-*-*-*-*-*-*-*-*-*-*-*");
91 case LyXFont::MSA_FAMILY:
92 font.setRawName("-*-msam10-*-*-*-*-*-*-*-*-*-*-*-*");
94 case LyXFont::MSB_FAMILY:
95 font.setRawName("-*-msbm10-*-*-*-*-*-*-*-*-*-*-*-*");
97 case LyXFont::EUFRAK_FAMILY:
98 font.setRawName("-*-eufm10-medium-*-*-*-*-*-*-*-*-*-*-*");
100 case LyXFont::ROMAN_FAMILY:
101 font.setFamily("times");
103 case LyXFont::SANS_FAMILY:
104 font.setFamily("helvetica");
106 case LyXFont::TYPEWRITER_FAMILY:
107 font.setFamily("courier");
111 font.setPointSizeFloat(lyxrc.font_sizes[f.size()]
112 * lyxrc.zoom / 100.0);
114 // FIXME: lyxrc, check for failure etc.
116 switch (f.series()) {
117 case LyXFont::MEDIUM_SERIES:
118 font.setWeight(QFont::Normal);
120 case LyXFont::BOLD_SERIES:
121 font.setWeight(QFont::Bold);
125 switch (f.realShape()) {
126 case LyXFont::ITALIC_SHAPE:
127 case LyXFont::SLANTED_SHAPE:
128 font.setItalic(true);
132 // Is this an exact match?
133 if (font.exactMatch()) {
134 lyxerr[Debug::FONT] << "This font is an exact match" << endl;
136 lyxerr[Debug::FONT] << "This font is NOT an exact match"
140 lyxerr[Debug::FONT] << "XFLD: " << font.rawName() << endl;
142 metrics = QFontMetrics(font);
146 qfont_loader::font_info const * qfont_loader::getfontinfo(LyXFont const & f)
148 if (!lyxrc.use_gui) {
152 font_info * fi = fontinfo_[f.family()][f.series()][f.realShape()][f.size()].get();
154 fi = new font_info(f);
155 fontinfo_[f.family()][f.series()][f.realShape()][f.size()].reset(fi);
162 bool qfont_loader::available(LyXFont const & f)
167 #if QT_VERSION >= 0x030000
168 return getfontinfo(f)->font.exactMatch();
171 switch (f.family()) {
172 case LyXFont::SYMBOL_FAMILY: tmp = "symbol"; break;
173 case LyXFont::CMR_FAMILY: tmp = "cmr10"; break;
174 case LyXFont::CMSY_FAMILY: tmp = "cmsy10"; break;
175 case LyXFont::CMM_FAMILY: tmp = "cmmi10"; break;
176 case LyXFont::CMEX_FAMILY: tmp = "cmex10"; break;
177 case LyXFont::MSA_FAMILY: tmp = "msam10"; break;
178 case LyXFont::MSB_FAMILY: tmp = "msbm10"; break;
184 return token(getfontinfo(f)->font.rawName().latin1(), '-', 2)