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