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