yes! ich habs kaputt gemacht! (doesn't compile anymore, doesn't work anymore,
[vuplus_dvbapp] / 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 <lib/base/estring.h>
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                 eString 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 eString &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         eString AddFont(const eString &filename, const eString &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 eString &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 struct pGlyph
67 {
68         int x, y, w;
69         ePtr<Font> font;
70         FT_ULong glyph_index;
71         int flags;
72         eRect bbox;
73 };
74
75 typedef std::vector<pGlyph> glyphString;
76
77 class Font;
78 class eLCD;
79
80 class eTextPara: public iObject
81 {
82 DECLARE_REF;
83 private:
84         ePtr<Font> current_font, replacement_font;
85         FT_Face current_face, replacement_face;
86         int use_kerning;
87         int previous;
88         static eString replacement_facename;
89
90         eRect area;
91         ePoint cursor;
92         eSize maximum;
93         int left;
94         glyphString glyphs;
95         int refcnt;
96
97         int appendGlyph(Font *current_font, FT_Face current_face, FT_UInt glyphIndex, int flags, int rflags);
98         void newLine(int flags);
99         void setFont(Font *font, Font *replacement_font);
100         eRect boundBox;
101         void calc_bbox();
102         int bboxValid;
103 public:
104         eTextPara(eRect area, ePoint start=ePoint(-1, -1))
105                 : current_font(0), replacement_font(0), current_face(0), replacement_face(0),
106                         area(area), cursor(start), maximum(0, 0), left(start.x()), refcnt(0), bboxValid(0)
107         {
108         }
109         virtual ~eTextPara();
110         
111         static void setReplacementFont(eString font) { replacement_facename=font; }
112
113         void destroy();
114         eTextPara *grab();
115
116         void setFont(const gFont *font);
117         int renderString(const eString &string, int flags=0);
118
119         void clear();
120
121         void blit(gDC &dc, const ePoint &offset, const gRGB &background, const gRGB &foreground);
122
123         enum
124         {
125                 dirLeft, dirRight, dirCenter, dirBlock
126         };
127
128         void realign(int dir);
129
130         const eRect & getBoundBox()
131         {
132                 if (!bboxValid)
133                         calc_bbox();
134
135                 return boundBox;
136         }
137
138         const eRect& getGlyphBBox(int num) const
139         {
140                 return glyphs[num].bbox;
141         }
142 };
143
144 class Font: public iObject
145 {
146 DECLARE_REF;
147 public:
148         FTC_Image_Desc font;
149         fontRenderClass *renderer;
150         FT_Error getGlyphBitmap(FT_ULong glyph_index, FTC_SBit *sbit);
151         FT_Face face;
152         FT_Size size;
153         
154         int tabwidth;
155         int height;
156         Font(fontRenderClass *render, FTC_FaceID faceid, int isize, int tabwidth);
157         virtual ~Font();
158 };
159
160 extern fontRenderClass *font;
161
162 #endif