]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/xftFontLoader.h
fontloader for gtk, probably not efficient
[lyx.git] / src / frontends / gtk / xftFontLoader.h
1 // -*- C++ -*-
2 /**
3  * \file xftFontLoader.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Huang Ying
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef XFT_FONT_LOADER_H
13 #define XFT_FONT_LOADER_H
14
15 #include "frontends/FontLoader.h"
16
17 #include "xftFontMetrics.h"
18
19 #include "lyxfont.h"
20
21 #include <gtkmm.h>
22 #include <X11/Xft/Xft.h>
23
24 class GWorkArea;
25
26
27 class xftFontLoader: public lyx::frontend::FontLoader {
28 public:
29         ///
30         xftFontLoader();
31
32         ///
33         virtual ~xftFontLoader();
34
35         /// Update fonts after zoom, dpi, font names, or norm change
36         virtual void update();
37
38         virtual bool available(LyXFont const & f);
39         virtual lyx::frontend::FontMetrics const & metrics(LyXFont const & f)
40         {
41                 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE)
42                         return font_metrics(load(f.family(), f.series(), f.realShape(), f.size()), 0);
43                 LyXFont scf(f);
44                 scf.decSize().decSize().setShape(LyXFont::UP_SHAPE);
45                 return font_metrics(load(f.family(), f.series(), f.realShape(), f.size()),
46                                 load(scf.family(), scf.series(), scf.realShape(), scf.size()));
47         }
48
49         /// Load font
50         XftFont * load(LyXFont::FONT_FAMILY family,
51                       LyXFont::FONT_SERIES series,
52                       LyXFont::FONT_SHAPE shape,
53                       LyXFont::FONT_SIZE size)
54         {
55                 if (fonts_[family][series][shape][size])
56                         return fonts_[family][series][shape][size];
57                 else
58                         return doLoad(family, series, shape, size);
59         }
60
61         bool isSpecial(LyXFont const & f)
62         {
63                 switch (f.family()) {
64                 case LyXFont::CMR_FAMILY:
65                 case LyXFont::EUFRAK_FAMILY:
66                         return true;
67                 default:
68                         break;
69                 }
70                 return f.isSymbolFont();
71         }
72 private:
73         /// Array of fonts
74         XftFont * fonts_[LyXFont::NUM_FAMILIES][2][4][10];
75         XftPattern * getFontPattern(LyXFont::FONT_FAMILY family,
76                                     LyXFont::FONT_SERIES series,
77                                     LyXFont::FONT_SHAPE shape,
78                                     LyXFont::FONT_SIZE size);
79         std::string familyString(LyXFont::FONT_FAMILY family);
80         /// Reset font handler
81         void reset();
82
83         /// Unload all fonts
84         void unload();
85
86         /** Does the actual loading of a font. Updates fontstruct. */
87         XftFont * doLoad(LyXFont::FONT_FAMILY family,
88                          LyXFont::FONT_SERIES series,
89                          LyXFont::FONT_SHAPE shape,
90                          LyXFont::FONT_SIZE size);
91 };
92
93 ///
94 extern xftFontLoader fontLoader;
95
96 #endif