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.
17 #include "lyxrc.h" // lyxrc.use_scalable_fonts
19 #include "frontends/lyx_gui.h"
21 #include "support/lstrings.h"
22 #include "support/lyxlib.h"
23 #include "support/convert.h"
25 #include "lyx_forms.h"
39 /// Load font close to this size
40 string const FontInfo::getFontname(int size)
46 double error = 100000.0;
48 for (int i = 0; i < matches; ++i) {
50 // Scalable font should not be considered close
51 } else if (sizes[i] == size) {
52 lyxerr[Debug::FONT] << "Exact font match with\n"
53 << strings[i] << endl;
55 } else if (abs(sizes[i] - size - 0.1) < error) {
56 error = abs(sizes[i] - size - 0.1);
61 if (scalable && (lyxrc.use_scalable_fonts || closestind == -1)) {
62 // We can use scalable
63 string const font = resize(strings[scaleindex], size);
64 lyxerr[Debug::FONT] << "Using scalable font to get\n"
69 // Did any fonts get close?
70 if (closestind == -1) {
75 // We use the closest match
76 lyxerr[Debug::FONT] << "Using closest font match to get size "
78 << " with\n" << strings[closestind] << endl;
79 return strings[closestind];
83 /// Build newly sized font string
84 string const FontInfo::resize(string const & font, int size) const
87 // Find the position of the size spec
89 string::iterator before = string::iterator(0);
90 string::iterator after = string::iterator(0);
91 for (string::iterator sit = ret.begin();
92 sit != ret.end(); ++sit)
95 if (cut == 7) before = sit + 1;
101 ret.replace(before, after, convert<string>(size));
107 void FontInfo::setPattern(string const & pat)
114 /// Query font in X11
115 void FontInfo::query()
120 if (pattern.empty()) {
121 lyxerr << "Cannot use empty font name for font query."
128 if (lyx_gui::use_gui)
129 list = XListFonts(fl_get_display(), pattern.c_str(),
137 sizes.reset(new int[matches]);
138 strings.reset(new string[matches]);
140 // We have matches. Run them through
141 for (int i = 0; i < matches; ++i) {
142 string name(list[i]);
143 lyxerr[Debug::FONT] << "match #" << i << ' '
145 sizes[i] = convert<int>(token(name, '-', 7));
148 if (scaleindex == -1) {
152 } else if (convert<int>(token(name, '-', 12)) == 0)
153 // Ignore bogus matches of scalable fonts.
156 XFreeFontNames(list);
162 void FontInfo::init()
172 } // namespace frontend