create global (real) config entries, update setup on hotplug (untested), fix apply...
[enigma2.git] / lib / gdi / font.h
1 #ifndef __FONT_H
2 #define __FONT_H
3
4 #ifndef SWIG
5
6 #include <ft2build.h>
7 #include FT_FREETYPE_H
8 #include FT_CACHE_H
9 #include FT_CACHE_IMAGE_H
10 #include FT_CACHE_SMALL_BITMAPS_H
11 #include <vector>
12
13 #include <lib/gdi/fb.h>
14 #include <lib/gdi/esize.h>
15 #include <lib/gdi/epoint.h>
16 #include <lib/gdi/erect.h>
17 #include <string>
18 #include <lib/base/object.h> 
19
20 #include <set>
21
22 class FontRenderClass;
23 class Font;
24 class gDC;
25 class gFont;
26 class gRGB;
27
28 #endif
29 class fontRenderClass
30
31 #ifndef SWIG
32         friend class Font;
33         friend class eTextPara;
34         fbClass *fb;
35         struct fontListEntry
36         {
37                 std::string filename, face;
38                 int scale; // 100 is 1:1
39                 fontListEntry *next;
40                 ~fontListEntry();
41         } *font;
42
43         FT_Library library;
44         FTC_Manager                     cacheManager;                           /* the cache manager                                                     */
45         FTC_Image_Cache imageCache;                                     /* the glyph image cache                                         */
46         FTC_SBit_Cache   sbitsCache;                            /* the glyph small bitmaps cache         */
47
48         FTC_FaceID getFaceID(const std::string &face);
49         FT_Error getGlyphBitmap(FTC_Image_Desc *font, FT_ULong glyph_index, FTC_SBit *sbit);
50         static fontRenderClass *instance;
51 #else
52         fontRenderClass();
53         ~fontRenderClass();
54 #endif
55 public:
56         float getLineHeight(const gFont& font);
57         static fontRenderClass *getInstance();
58 #ifndef SWIG
59         std::string AddFont(const std::string &filename, const std::string &name, int scale);
60         FT_Error FTC_Face_Requester(FTC_FaceID  face_id, FT_Face* aface);
61         int getFont(ePtr<Font> &font, const std::string &face, int size, int tabwidth=-1);
62         fontRenderClass();
63         ~fontRenderClass();
64 #endif
65 };
66
67 #ifndef SWIG
68
69 #define RS_WRAP         1
70 #define RS_DOT          2
71 #define RS_DIRECT       4
72 #define RS_FADE         8
73
74 #define GS_ISSPACE  1
75 #define GS_ISFIRST  2
76 #define GS_USED                 4
77 #define GS_INVERT   8
78 #define GS_SOFTHYPHEN 16
79 #define GS_HYPHEN   32
80 #define GS_CANBREAK (GS_ISSPACE|GS_SOFTHYPHEN|GS_HYPHEN)
81
82 struct pGlyph
83 {
84         int x, y, w;
85         ePtr<Font> font;
86         FT_ULong glyph_index;
87         int flags;
88         eRect bbox;
89 };
90
91 typedef std::vector<pGlyph> glyphString;
92
93 class Font;
94 class eLCD;
95
96 class eTextPara: public iObject
97 {
98 DECLARE_REF(eTextPara);
99 private:
100         ePtr<Font> current_font, replacement_font;
101         FT_Face current_face, replacement_face;
102         int use_kerning;
103         int previous;
104         static std::string replacement_facename;
105         static std::set<int> forced_replaces;
106
107         eRect area;
108         ePoint cursor;
109         eSize maximum;
110         int left;
111         glyphString glyphs;
112
113         int appendGlyph(Font *current_font, FT_Face current_face, FT_UInt glyphIndex, int flags, int rflags);
114         void newLine(int flags);
115         void setFont(Font *font, Font *replacement_font);
116         eRect boundBox;
117         void calc_bbox();
118         int bboxValid;
119 public:
120         eTextPara(eRect area, ePoint start=ePoint(-1, -1))
121                 : current_font(0), replacement_font(0), current_face(0), replacement_face(0),
122                         area(area), cursor(start), maximum(0, 0), left(start.x()), bboxValid(0)
123         {
124         }
125         virtual ~eTextPara();
126         
127         static void setReplacementFont(std::string font) { replacement_facename=font; }
128         static void forceReplacementGlyph(int unicode) { forced_replaces.insert(unicode); }
129
130         void setFont(const gFont *font);
131         int renderString(const char *string, int flags=0);
132
133         void clear();
134
135         void blit(gDC &dc, const ePoint &offset, const gRGB &background, const gRGB &foreground);
136
137         enum
138         {
139                 dirLeft, dirRight, dirCenter, dirBlock
140         };
141
142         void realign(int dir);
143
144         const eRect & getBoundBox()
145         {
146                 if (!bboxValid)
147                         calc_bbox();
148
149                 return boundBox;
150         }
151         
152         const int size() const
153         {
154                 return glyphs.size();
155         }
156
157         const eRect& getGlyphBBox(int num) const
158         {
159                 assert(num >= 0);
160                 assert(num < (int)glyphs.size());
161                 return glyphs[num].bbox;
162         }
163         
164         void setGlyphFlag(int g, int f)
165         {
166                 assert(g >= 0);
167                 assert(g < (int)glyphs.size());
168                 glyphs[g].flags |= f;
169         }
170
171         void clearGlyphFlag(int g, int f)
172         {
173                 assert(g >= 0);
174                 assert(g < (int)glyphs.size());
175                 glyphs[g].flags |= f;
176         }
177 };
178
179 class Font: public iObject
180 {
181 DECLARE_REF(Font);
182 public:
183         FTC_Image_Desc font;
184         fontRenderClass *renderer;
185         FT_Error getGlyphBitmap(FT_ULong glyph_index, FTC_SBit *sbit);
186         FT_Face face;
187         FT_Size size;
188         
189         int tabwidth;
190         int height;
191         Font(fontRenderClass *render, FTC_FaceID faceid, int isize, int tabwidth);
192         virtual ~Font();
193 };
194
195 extern fontRenderClass *font;
196
197 #endif  // !SWIG
198
199 #endif