]> git.lyx.org Git - lyx.git/blob - src/FontInfo.h
ba856eb19cecf175d0621e98fdfd9b0bc4ed4e37
[lyx.git] / src / FontInfo.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *       
7  *          Copyright (C) 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 lyxrc->use_scalable_fonts
26 determines whether to allow scalable fonts to give an exact match. */
27 class FontInfo {
28 public:
29         ///
30         FontInfo() { init(); }
31
32         ///
33         FontInfo(string const & pat)
34         : pattern(pat) { init(); }
35
36         /// Destructor
37         ~FontInfo() { release(); }
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 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 getFontname(int size);
60 private:
61         /// Font pattern (with wildcard for size)
62         string pattern;
63
64         /// Available size list
65         int * sizes;
66
67         /// Corresponding name list
68         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                 sizes = 0;
86                 strings = 0;
87                 matches = 0;
88                 queried = false;
89                 scalable = false;
90                 scaleindex = -1;
91         }
92
93         /// Release allocated stuff
94         void release();
95
96         /// Ask X11 about this font pattern
97         void query();
98
99         /// Build newly sized font string 
100         string resize(string const &, int size) const;
101 };
102 #endif