]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
make doc++ able to generate the source documentation for lyx
[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 /** 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         /// Destructor
39         ~FontInfo() { release(); }
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 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 getFontname(int size);
62 private:
63         /// Font pattern (with wildcard for size)
64         string pattern;
65
66         /// Available size list
67         int * sizes;
68
69         /// Corresponding name list
70         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         /// Release allocated stuff
88         void release();
89
90         /// Ask X11 about this font pattern
91         void query();
92
93         /// Build newly sized font string 
94         string resize(string const &, int size) const;
95 };
96 #endif