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