remove lib/content
[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 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 std::string replacement_facename;
89
90         eRect area;
91         ePoint cursor;
92         eSize maximum;
93         int left;
94         glyphString glyphs;
95
96         int appendGlyph(Font *current_font, FT_Face current_face, FT_UInt glyphIndex, int flags, int rflags);
97         void newLine(int flags);
98         void setFont(Font *font, Font *replacement_font);
99         eRect boundBox;
100         void calc_bbox();
101         int bboxValid;
102 public:
103         eTextPara(eRect area, ePoint start=ePoint(-1, -1))
104                 : current_font(0), replacement_font(0), current_face(0), replacement_face(0),
105                         area(area), cursor(start), maximum(0, 0), left(start.x()), bboxValid(0)
106         {
107         }
108         virtual ~eTextPara();
109         
110         static void setReplacementFont(std::string font) { replacement_facename=font; }
111
112         void setFont(const gFont *font);
113         int renderString(const std::string &string, int flags=0);
114
115         void clear();
116
117         void blit(gDC &dc, const ePoint &offset, const gRGB &background, const gRGB &foreground);
118
119         enum
120         {
121                 dirLeft, dirRight, dirCenter, dirBlock
122         };
123
124         void realign(int dir);
125
126         const eRect & getBoundBox()
127         {
128                 if (!bboxValid)
129                         calc_bbox();
130
131                 return boundBox;
132         }
133
134         const eRect& getGlyphBBox(int num) const
135         {
136                 return glyphs[num].bbox;
137         }
138 };
139
140 class Font: public iObject
141 {
142 DECLARE_REF;
143 public:
144         FTC_Image_Desc font;
145         fontRenderClass *renderer;
146         FT_Error getGlyphBitmap(FT_ULong glyph_index, FTC_SBit *sbit);
147         FT_Face face;
148         FT_Size size;
149         
150         int tabwidth;
151         int height;
152         Font(fontRenderClass *render, FTC_FaceID faceid, int isize, int tabwidth);
153         virtual ~Font();
154 };
155
156 extern fontRenderClass *font;
157
158 #endif