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"
40 /// Load font close to this size
41 string const FontInfo::getFontname(int size)
47 double error = 100000.0;
49 for (int i = 0; i < matches; ++i) {
51 // Scalable font should not be considered close
52 } else if (sizes[i] == size) {
53 lyxerr[Debug::FONT] << "Exact font match with\n"
54 << strings[i] << endl;
56 } else if (abs(sizes[i] - size - 0.1) < error) {
57 error = abs(sizes[i] - size - 0.1);
62 if (scalable && (lyxrc.use_scalable_fonts || closestind == -1)) {
63 // We can use scalable
64 string const font = resize(strings[scaleindex], size);
65 lyxerr[Debug::FONT] << "Using scalable font to get\n"
70 // Did any fonts get close?
71 if (closestind == -1) {
76 // We use the closest match
77 lyxerr[Debug::FONT] << "Using closest font match to get size "
79 << " with\n" << strings[closestind] << endl;
80 return strings[closestind];
84 /// Build newly sized font string
85 string const FontInfo::resize(string const & font, int size) const
88 // Find the position of the size spec
90 string::iterator before = string::iterator(0);
91 string::iterator after = string::iterator(0);
92 for (string::iterator sit = ret.begin();
93 sit != ret.end(); ++sit)
96 if (cut == 7) before = sit + 1;
102 ret.replace(before, after, convert<string>(size));
108 void FontInfo::setPattern(string const & pat)
115 /// Query font in X11
116 void FontInfo::query()
121 if (pattern.empty()) {
122 lyxerr << "Cannot use empty font name for font query."
129 if (lyx_gui::use_gui)
130 list = XListFonts(fl_get_display(), pattern.c_str(),
138 sizes.reset(new int[matches]);
139 strings.reset(new string[matches]);
141 // We have matches. Run them through
142 for (int i = 0; i < matches; ++i) {
143 string name(list[i]);
144 lyxerr[Debug::FONT] << "match #" << i << ' '
146 sizes[i] = atoi(token(name, '-', 7));
149 if (scaleindex == -1) {
153 } else if (atoi(token(name, '-', 12)) == 0)
154 // Ignore bogus matches of scalable fonts.
157 XFreeFontNames(list);
163 void FontInfo::init()
173 } // namespace frontend