]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
two patches from john
[lyx.git] / src / FontInfo.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 1997 Asger Alstrup
8  *           and the LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef FONTINFO_H
13 #define FONTINFO_H 
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "LString.h"
20
21 #include <boost/smart_ptr.hpp>
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(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         string const & getPattern() const { return pattern; }
54
55         /// Set new pattern
56         void setPattern(string const & pat);
57
58         /** Return full name of font close to this size.
59           If impossible, result is the empty string */
60         string const getFontname(int size);
61 private:
62         /// Font pattern (with wildcard for size)
63         string pattern;
64
65         /// Available size list
66         boost::scoped_array<int> sizes;
67
68         /// Corresponding name list
69         boost::scoped_array<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         string const resize(string const &, int size) const;
91 };
92 #endif