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
20 #include "lyxrc.h" // lyxrc.use_scalable_fonts
22 #include "support/lstrings.h"
23 #include "support/lyxlib.h"
25 #include <cmath> // abs()
30 #include FORMS_H_LOCATION
32 /// Load font close to this size
33 string const FontInfo::getFontname(int size)
39 double error = 100000.0;
41 for (int i = 0; i < matches; ++i) {
43 // Scalable font should not be considered close
44 } else if (sizes[i] == size) {
45 lyxerr[Debug::FONT] << "Exact font match with\n"
46 << strings[i] << endl;
48 } else if (abs(sizes[i] - size - 0.1) < error) {
49 error = abs(sizes[i] - size - 0.1);
54 if (scalable && (lyxrc.use_scalable_fonts || closestind == -1)) {
55 // We can use scalable
56 string const font = resize(strings[scaleindex], size);
57 lyxerr[Debug::FONT] << "Using scalable font to get\n"
62 // Did any fonts get close?
63 if (closestind == -1) {
68 // We use the closest match
69 lyxerr[Debug::FONT] << "Using closest font match to get size "
71 << " with\n" << strings[closestind] << endl;
72 return strings[closestind];
76 /// Build newly sized font string
77 string const FontInfo::resize(string const & font, int size) const
80 // Find the position of the size spec
82 string::iterator before = string::iterator(0);
83 string::iterator after = string::iterator(0);
84 for (string::iterator sit = ret.begin();
85 sit != ret.end(); ++sit)
88 if (cut == 7) before = sit + 1;
94 ret.replace(before, after, tostr(size));
100 void FontInfo::setPattern(string const & pat)
107 /// Query font in X11
108 void FontInfo::query()
113 if (pattern.empty()) {
114 lyxerr << "Cannot use empty font name for font query."
122 list = XListFonts(fl_get_display(), pattern.c_str(),
130 sizes.reset(new int[matches]);
131 strings.reset(new string[matches]);
133 // We have matches. Run them through
134 for (int i = 0; i < matches; ++i) {
135 string name(list[i]);
136 lyxerr[Debug::FONT] << "match #" << i << " "
138 sizes[i] = lyx::atoi(token(name, '-', 7));
141 if (scaleindex == -1) {
147 XFreeFontNames(list);
153 void FontInfo::init()