]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FontInfo.h
Introduce LFUN_PRINT.
[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 /** This class manages a font.
21     The idea is to create a FontInfo object with a font name pattern with a
22     wildcard at the size field. Then this object can host request for font-
23     instances of any given size. If no exact match is found, the closest size
24     is chosen instead. If the font is scalable, the flag
25     lyxrc.use_scalable_fonts determines whether to allow scalable fonts to
26     give an exact match.
27 */
28 class FontInfo {
29 public:
30         ///
31         FontInfo() { init(); }
32
33         ///
34         explicit FontInfo(std::string const & pat)
35                 : pattern(pat) { init(); }
36
37         /// Does any font match our pattern?
38         bool exist() {
39                 query();
40                 return matches != 0;
41         }
42
43         /// Is this font scalable?
44         bool isScalable() {
45                 query();
46                 return scalable;
47         }
48
49         /// Get existing pattern
50         std::string const & getPattern() const { return pattern; }
51
52         /// Set new pattern
53         void setPattern(std::string const & pat);
54
55         /** Return full name of font close to this size.
56           If impossible, result is the empty string */
57         std::string const getFontname(int size);
58 private:
59         /// Font pattern (with wildcard for size)
60         std::string pattern;
61
62         /// Available size list
63         boost::scoped_array<int> sizes;
64
65         /// Corresponding name list
66         boost::scoped_array<std::string> strings;
67
68         /// Number of matches
69         int matches;
70
71         /// Did we query X about this font?
72         bool queried;
73
74         /// Is this font scalable?
75         bool scalable;
76
77         /// Which index points to scalable font entry?
78         int scaleindex;
79
80         /// Initialize empty record
81         void init();
82
83         /// Ask X11 about this font pattern
84         void query();
85
86         /// Build newly sized font string
87         std::string const resize(std::string const &, int size) const;
88 };
89
90 #endif // FONTINFO_H