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