export gRGB to python again
[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
78 #define GS_INVERT   8
79
80 struct pGlyph
81 {
82         int x, y, w;
83         ePtr<Font> font;
84         FT_ULong glyph_index;
85         int flags;
86         eRect bbox;
87 };
88
89 typedef std::vector<pGlyph> glyphString;
90
91 class Font;
92 class eLCD;
93
94 class eTextPara: public iObject
95 {
96 DECLARE_REF(eTextPara);
97 private:
98         ePtr<Font> current_font, replacement_font;
99         FT_Face current_face, replacement_face;
100         int use_kerning;
101         int previous;
102         static std::string replacement_facename;
103         static std::set<int> forced_replaces;
104
105         eRect area;
106         ePoint cursor;
107         eSize maximum;
108         int left;
109         glyphString glyphs;
110
111         int appendGlyph(Font *current_font, FT_Face current_face, FT_UInt glyphIndex, int flags, int rflags);
112         void newLine(int flags);
113         void setFont(Font *font, Font *replacement_font);
114         eRect boundBox;
115         void calc_bbox();
116         int bboxValid;
117 public:
118         eTextPara(eRect area, ePoint start=ePoint(-1, -1))
119                 : current_font(0), replacement_font(0), current_face(0), replacement_face(0),
120                         area(area), cursor(start), maximum(0, 0), left(start.x()), bboxValid(0)
121         {
122         }
123         virtual ~eTextPara();
124         
125         static void setReplacementFont(std::string font) { replacement_facename=font; }
126         static void forceReplacementGlyph(int unicode) { forced_replaces.insert(unicode); }
127
128         void setFont(const gFont *font);
129         int renderString(const char *string, int flags=0);
130
131         void clear();
132
133         void blit(gDC &dc, const ePoint &offset, const gRGB &background, const gRGB &foreground);
134
135         enum
136         {
137                 dirLeft, dirRight, dirCenter, dirBlock
138         };
139
140         void realign(int dir);
141
142         const eRect & getBoundBox()
143         {
144                 if (!bboxValid)
145                         calc_bbox();
146
147                 return boundBox;
148         }
149         
150         const int size() const
151         {
152                 return glyphs.size();
153         }
154
155         const eRect& getGlyphBBox(int num) const
156         {
157                 assert(num >= 0);
158                 assert(num < (int)glyphs.size());
159                 return glyphs[num].bbox;
160         }
161         
162         void setGlyphFlag(int g, int f)
163         {
164                 assert(g >= 0);
165                 assert(g < (int)glyphs.size());
166                 glyphs[g].flags |= f;
167         }
168
169         void clearGlyphFlag(int g, int f)
170         {
171                 assert(g >= 0);
172                 assert(g < (int)glyphs.size());
173                 glyphs[g].flags |= f;
174         }
175 };
176
177 class Font: public iObject
178 {
179 DECLARE_REF(Font);
180 public:
181         FTC_Image_Desc font;
182         fontRenderClass *renderer;
183         FT_Error getGlyphBitmap(FT_ULong glyph_index, FTC_SBit *sbit);
184         FT_Face face;
185         FT_Size size;
186         
187         int tabwidth;
188         int height;
189         Font(fontRenderClass *render, FTC_FaceID faceid, int isize, int tabwidth);
190         virtual ~Font();
191 };
192
193 extern fontRenderClass *font;
194
195 #endif  // !SWIG
196
197 #endif