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