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