trunk 20080912
[gitenigma.git] / include / lib / gdi / font.h
blob0a2dfc4a49437e51ea6217411ac5c6060d92ff4a
1 #ifndef __FONT_H
2 #define __FONT_H
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>
12 #include <lib/gdi/fb.h>
13 #include <lib/base/esize.h>
14 #include <lib/base/epoint.h>
15 #include <lib/base/erect.h>
16 #include <lib/base/estring.h>
18 class FontRenderClass;
19 class Font;
20 class gPixmapDC;
21 class gFont;
22 class gRGB;
24 class fontRenderClass
26 friend class Font;
27 friend class eTextPara;
28 fbClass *fb;
29 struct fontListEntry
31 eString filename, face;
32 int scale; // 100 is 1:1
33 fontListEntry *next;
34 ~fontListEntry();
35 } *font;
37 FT_Library library;
38 FTC_Manager cacheManager; /* the cache manager */
39 FTC_Image_Cache imageCache; /* the glyph image cache */
40 FTC_SBit_Cache sbitsCache; /* the glyph small bitmaps cache */
42 FTC_FaceID getFaceID(const eString &face);
43 FT_Error getGlyphBitmap(FTC_Image_Desc *font, FT_ULong glyph_index, FTC_SBit *sbit);
44 static fontRenderClass *instance;
45 public:
46 float getLineHeight(const gFont& font);
47 eString AddFont(const eString &filename, const eString &name, int scale);
48 static fontRenderClass *getInstance();
49 FT_Error FTC_Face_Requester(FTC_FaceID face_id,
50 FT_Face* aface);
51 Font *getFont(const eString &face, int size, int tabwidth=-1);
52 fontRenderClass();
53 ~fontRenderClass();
56 #define RS_WRAP 1
57 #define RS_DOT 2
58 #define RS_DIRECT 4
59 #define RS_FADE 8
61 #define GS_ISSPACE 1
62 #define GS_ISFIRST 2
63 #define GS_USED 4
65 struct pGlyph
67 int x, y, w;
68 Font *font;
69 FT_ULong glyph_index;
70 int flags;
71 eRect bbox;
74 typedef std::vector<pGlyph> glyphString;
76 class Font;
77 class eLCD;
79 class eTextPara
81 Font *current_font, *replacement_font;
82 FT_Face current_face, replacement_face;
83 int use_kerning;
84 int previous;
85 static eString replacement_facename;
87 eRect area;
88 ePoint cursor;
89 eSize maximum;
90 int left;
91 glyphString glyphs;
92 int refcnt;
93 eRect boundBox;
94 int bboxValid;
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 void calc_bbox();
100 void clear();
101 public:
102 eTextPara(eRect area, ePoint start=ePoint(-1, -1))
103 : current_font(0), replacement_font(0), current_face(0), replacement_face(0),
104 area(area), cursor(start), maximum(0, 0), left(start.x()), refcnt(0), bboxValid(0)
107 ~eTextPara();
109 static void setReplacementFont(eString font) { replacement_facename=font; }
111 void destroy();
112 eTextPara *grab();
114 void setFont(const gFont &font);
115 int renderString(const eString &string, int flags=0);
117 void blit(gPixmapDC &dc, const ePoint &offset, const gRGB &background, const gRGB &foreground);
119 enum
121 dirLeft, dirRight, dirCenter, dirBlock
124 void realign(int dir);
126 const eRect & getBoundBox()
128 if (!bboxValid)
129 calc_bbox();
130 return boundBox;
133 const eRect& getGlyphBBox(int num) const
135 return glyphs[num].bbox;
139 class Font
141 public:
142 FTC_Image_Desc font;
143 fontRenderClass *renderer;
144 int ref;
145 FT_Error getGlyphBitmap(FT_ULong glyph_index, FTC_SBit *sbit);
146 FT_Face face;
147 FT_Size size;
149 int tabwidth;
150 int height;
151 Font(fontRenderClass *render, FTC_FaceID faceid, int isize, int tabwidth);
152 ~Font();
154 void lock();
155 void unlock(); // deletes if ref==0
158 extern fontRenderClass *font;
160 #endif