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