]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FontInfo.h
get rid of broken_header.h and some unneeded tests
[lyx.git] / src / frontends / xforms / FontInfo.h
1 // -*- C++ -*-
2 /**
3  * \file FontInfo.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef FONTINFO_H
14 #define FONTINFO_H
15
16 #include <boost/scoped_array.hpp>
17
18 #include <string>
19
20 namespace lyx {
21 namespace frontend {
22
23 /** This class manages a font.
24     The idea is to create a FontInfo object with a font name pattern with a
25     wildcard at the size field. Then this object can host request for font-
26     instances of any given size. If no exact match is found, the closest size
27     is chosen instead. If the font is scalable, the flag
28     lyxrc.use_scalable_fonts determines whether to allow scalable fonts to
29     give an exact match.
30 */
31 class FontInfo {
32 public:
33         ///
34         FontInfo() { init(); }
35
36         ///
37         explicit FontInfo(std::string const & pat)
38                 : pattern(pat) { init(); }
39
40         /// Does any font match our pattern?
41         bool exist() {
42                 query();
43                 return matches != 0;
44         }
45
46         /// Is this font scalable?
47         bool isScalable() {
48                 query();
49                 return scalable;
50         }
51
52         /// Get existing pattern
53         std::string const & getPattern() const { return pattern; }
54
55         /// Set new pattern
56         void setPattern(std::string const & pat);
57
58         /** Return full name of font close to this size.
59           If impossible, result is the empty string */
60         std::string const getFontname(int size);
61 private:
62         /// Font pattern (with wildcard for size)
63         std::string pattern;
64
65         /// Available size list
66         boost::scoped_array<int> sizes;
67
68         /// Corresponding name list
69         boost::scoped_array<std::string> strings;
70
71         /// Number of matches
72         int matches;
73
74         /// Did we query X about this font?
75         bool queried;
76
77         /// Is this font scalable?
78         bool scalable;
79
80         /// Which index points to scalable font entry?
81         int scaleindex;
82
83         /// Initialize empty record
84         void init();
85
86         /// Ask X11 about this font pattern
87         void query();
88
89         /// Build newly sized font string
90         std::string const resize(std::string const &, int size) const;
91 };
92
93 } // namespace frontend
94 } // namespace lyx
95
96 #endif // FONTINFO_H