3 * Copyright 1997-2002 the LyX Team
4 * Read the file COPYING
6 * \author Asger Alstrup
7 * \author John Levon <moz@compsoc.man.ac.uk>
13 #pragma implementation
18 #include "lyxrc.h" // lyxrc.use_scalable_fonts
20 #include "support/lstrings.h"
21 #include "support/lyxlib.h"
23 #include <cmath> // abs()
28 #include FORMS_H_LOCATION
30 /// Load font close to this size
31 string const FontInfo::getFontname(int size)
37 double error = 100000.0;
39 for (int i = 0; i < matches; ++i) {
41 // Scalable font should not be considered close
42 } else if (sizes[i] == size) {
43 lyxerr[Debug::FONT] << "Exact font match with\n"
44 << strings[i] << endl;
46 } else if (abs(sizes[i] - size - 0.1) < error) {
47 error = abs(sizes[i] - size - 0.1);
52 if (scalable && (lyxrc.use_scalable_fonts || closestind == -1)) {
53 // We can use scalable
54 string const font = resize(strings[scaleindex], size);
55 lyxerr[Debug::FONT] << "Using scalable font to get\n"
60 // Did any fonts get close?
61 if (closestind == -1) {
66 // We use the closest match
67 lyxerr[Debug::FONT] << "Using closest font match to get size "
69 << " with\n" << strings[closestind] << endl;
70 return strings[closestind];
74 /// Build newly sized font string
75 string const FontInfo::resize(string const & font, int size) const
78 // Find the position of the size spec
80 string::iterator before = string::iterator(0);
81 string::iterator after = string::iterator(0);
82 for (string::iterator sit = ret.begin();
83 sit != ret.end(); ++sit)
86 if (cut == 7) before = sit + 1;
92 ret.replace(before, after, tostr(size));
98 void FontInfo::setPattern(string const & pat)
105 /// Query font in X11
106 void FontInfo::query()
111 if (pattern.empty()) {
112 lyxerr << "Cannot use empty font name for font query."
120 list = XListFonts(fl_get_display(), pattern.c_str(),
128 sizes.reset(new int[matches]);
129 strings.reset(new string[matches]);
131 // We have matches. Run them through
132 for (int i = 0; i < matches; ++i) {
133 string name(list[i]);
134 lyxerr[Debug::FONT] << "match #" << i << " "
136 sizes[i] = lyx::atoi(token(name, '-', 7));
139 if (scaleindex == -1) {
145 XFreeFontNames(list);
151 void FontInfo::init()