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/tostr.h"
25 #include "lyx_forms.h"
29 using namespace lyx::support;
35 /// Load font close to this size
36 string const FontInfo::getFontname(int size)
42 double error = 100000.0;
44 for (int i = 0; i < matches; ++i) {
46 // Scalable font should not be considered close
47 } else if (sizes[i] == size) {
48 lyxerr[Debug::FONT] << "Exact font match with\n"
49 << strings[i] << endl;
51 } else if (abs(sizes[i] - size - 0.1) < error) {
52 error = abs(sizes[i] - size - 0.1);
57 if (scalable && (lyxrc.use_scalable_fonts || closestind == -1)) {
58 // We can use scalable
59 string const font = resize(strings[scaleindex], size);
60 lyxerr[Debug::FONT] << "Using scalable font to get\n"
65 // Did any fonts get close?
66 if (closestind == -1) {
71 // We use the closest match
72 lyxerr[Debug::FONT] << "Using closest font match to get size "
74 << " with\n" << strings[closestind] << endl;
75 return strings[closestind];
79 /// Build newly sized font string
80 string const FontInfo::resize(string const & font, int size) const
83 // Find the position of the size spec
85 string::iterator before = string::iterator(0);
86 string::iterator after = string::iterator(0);
87 for (string::iterator sit = ret.begin();
88 sit != ret.end(); ++sit)
91 if (cut == 7) before = sit + 1;
97 ret.replace(before, after, tostr(size));
103 void FontInfo::setPattern(string const & pat)
110 /// Query font in X11
111 void FontInfo::query()
116 if (pattern.empty()) {
117 lyxerr << "Cannot use empty font name for font query."
124 if (lyx_gui::use_gui)
125 list = XListFonts(fl_get_display(), pattern.c_str(),
133 sizes.reset(new int[matches]);
134 strings.reset(new string[matches]);
136 // We have matches. Run them through
137 for (int i = 0; i < matches; ++i) {
138 string name(list[i]);
139 lyxerr[Debug::FONT] << "match #" << i << ' '
141 sizes[i] = atoi(token(name, '-', 7));
144 if (scaleindex == -1) {
148 } else if (atoi(token(name, '-', 12)) == 0)
149 // Ignore bogus matches of scalable fonts.
152 XFreeFontNames(list);
158 void FontInfo::init()