]> git.lyx.org Git - lyx.git/blob - src/FontLoader.h
ws change
[lyx.git] / src / FontLoader.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 FONTLOADER_H_
13 #define FONTLOADER_H_
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include <X11/Xlib.h>
20 #include "lyxfont.h"
21 #include "LString.h"
22
23 class FontInfo;
24
25 /** This class takes care of loading fonts. It uses FontInfo to make
26 intelligent guesses about matching font size, and it tries different tags
27 itself in order to match the font loading demands.  Later, I plan to extend
28 this with support for T1Lib, probably via a new class building on this.
29 (Asger) */
30 class FontLoader {
31 public:
32         ///
33         FontLoader();
34
35         ///
36         ~FontLoader();
37
38         /// Update fonts after zoom, dpi, font names, or norm change
39         void update();
40
41         /// Load font
42         XFontStruct * load(LyXFont::FONT_FAMILY family,
43                            LyXFont::FONT_SERIES series,
44                            LyXFont::FONT_SHAPE shape,
45                            LyXFont::FONT_SIZE size) {
46                 if (fontstruct[family][series][shape][size] != 0)
47                         return fontstruct[family][series][shape][size];
48                 else
49                         return doLoad(family, series, shape, size);
50         };
51         /// Do we have anything matching?
52         bool available(LyXFont const & f);
53
54 private:
55         /// Array of font structs
56         XFontStruct * fontstruct[LyXFont::NUM_FAMILIES][2][4][10];
57
58         /// Array of font infos
59         FontInfo * fontinfo[LyXFont::NUM_FAMILIES][2][4];
60
61         /// Reset font handler
62         void reset();
63
64         /// Unload all fonts
65         void unload();
66
67         /// Get font info
68         void getFontinfo(LyXFont::FONT_FAMILY family,
69                          LyXFont::FONT_SERIES series,
70                          LyXFont::FONT_SHAPE shape);
71
72         /** Does the actual loading of a font. Updates fontstruct. */
73         XFontStruct * doLoad(LyXFont::FONT_FAMILY family,
74                              LyXFont::FONT_SERIES series,
75                              LyXFont::FONT_SHAPE shape,
76                              LyXFont::FONT_SIZE size);
77 };
78
79 ///
80 extern FontLoader fontloader;
81
82 #endif