openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
font.h
Go to the documentation of this file.
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 FT_STROKER_H
12 typedef FTC_ImageCache FTC_Image_Cache;
13 typedef FTC_ImageTypeRec FTC_Image_Desc;
14 typedef FTC_SBitCache FTC_SBit_Cache;
15 #include <vector>
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 <list>
23 #include <lib/base/object.h>
24 
25 #include <set>
26 
27 class FontRenderClass;
28 class Font;
29 class gDC;
30 class gFont;
31 struct gRGB;
32 
33 #endif
35 {
36 #ifndef SWIG
37  friend class Font;
38  friend class eTextPara;
39  fbClass *fb;
40  struct fontListEntry
41  {
42  std::string filename, face;
43  int scale; // 100 is 1:1
44  int renderflags;
45  fontListEntry *next;
46  ~fontListEntry();
47  } *font;
48 
49  FT_Library library;
50  FTC_Manager cacheManager; /* the cache manager */
51  FTC_Image_Cache imageCache; /* the glyph image cache */
52  FTC_SBit_Cache sbitsCache; /* the glyph small bitmaps cache */
53  FT_Stroker stroker;
54  int strokerRadius;
55 
56  int getFaceProperties(const std::string &face, FTC_FaceID &id, int &renderflags);
57  FT_Error getGlyphBitmap(FTC_Image_Desc *font, FT_UInt glyph_index, FTC_SBit *sbit);
58  FT_Error getGlyphImage(FTC_Image_Desc *font, FT_UInt glyph_index, FT_Glyph *glyph, FT_Glyph *borderglyph, int bordersize);
59  static fontRenderClass *instance;
60 #else
63 #endif
64 public:
65  float getLineHeight(const gFont& font);
66  static fontRenderClass *getInstance();
67 #ifndef SWIG
68  std::string AddFont(const std::string &filename, const std::string &name, int scale, int renderflags = 0);
69  FT_Error FTC_Face_Requester(FTC_FaceID face_id, FT_Face* aface);
70  int getFont(ePtr<Font> &font, const std::string &face, int size, int tabwidth=-1);
71  std::vector<std::string> getFontFaces();
74 #endif
75 };
76 
77 #ifndef SWIG
78 
79 #define RS_WRAP 1
80 #define RS_DOT 2
81 #define RS_DIRECT 4
82 #define RS_FADE 8
83 
84 #define GS_ISSPACE 1
85 #define GS_ISFIRST 2
86 #define GS_USED 4
87 #define GS_INVERT 8
88 #define GS_SOFTHYPHEN 16
89 #define GS_HYPHEN 32
90 #define GS_COLORCHANGE 64
91 #define GS_LF 128
92 #define GS_FIXED 256
93 #define GS_MAYBREAK 512
94 #define GS_CANBREAK (GS_ISSPACE|GS_SOFTHYPHEN|GS_HYPHEN)
95 
96 struct pGlyph
97 {
98  int x, y, w;
99  unsigned long newcolor;
101  FT_UInt glyph_index;
102  int flags;
104  FT_Glyph image, borderimage;
106  {
107  image = NULL;
108  borderimage = NULL;
109  }
110 };
111 
112 typedef std::vector<pGlyph> glyphString;
113 
114 class Font;
115 class eLCD;
116 
117 class eTextPara: public iObject
118 {
119  DECLARE_REF(eTextPara);
120  ePtr<Font> current_font, replacement_font, fallback_font;
121  FT_Face current_face, replacement_face, fallback_face;
122  int use_kerning;
123  int previous;
124  static std::string replacement_facename;
125  static std::string fallback_facename;
126  static std::set<int> forced_replaces;
127 
128  eRect area;
129  ePoint cursor;
130  eSize maximum;
131  int left;
132  glyphString glyphs;
133  std::list<int> lineOffsets;
134  std::list<int> lineChars;
135  int charCount;
136  int lineCount;
137  int totalheight;
138  int bboxValid;
139  eRect boundBox;
140  bool doTopBottomReordering;
141  int m_offset;
142 
143  int appendGlyph(Font *current_font, FT_Face current_face, FT_UInt glyphIndex, int flags, int rflags, int border, bool last,
144  bool activate_newcolor, unsigned long newcolor);
145  void newLine(int flags);
146  void setFont(Font *font, Font *replacement_font, Font *fallback_font);
147  void calc_bbox();
148 public:
149  eTextPara(eRect area, ePoint start=ePoint(-1, -1))
150  : current_font(0), replacement_font(0), fallback_font(0),
151  current_face(0), replacement_face(0), fallback_face(0),
152  area(area), cursor(start), maximum(0, 0), left(start.x()), charCount(0), totalheight(0),
153  bboxValid(0), doTopBottomReordering(false), m_offset(0)
154  {
155  }
156  virtual ~eTextPara();
157 
158  static void setReplacementFont(std::string font) { replacement_facename=font; }
159  static void forceReplacementGlyph(int unicode) { forced_replaces.insert(unicode); }
160 
161  static void setFallbackFont(std::string font) { fallback_facename=font; }
162 
163  void setFont(const gFont *font);
164  int renderString(const char *string, int flags=0, int border=0, int markedpos=-1);
165 
166  void clear();
167  int getLineCount(void) const { return lineCount; }
168 
169  void blit(gDC &dc, const ePoint &offset, const gRGB &background, const gRGB &foreground, bool border = false);
170 
171  enum
172  {
174  };
175 
176  void setTextOffset(int offset)
177  {
178  m_offset = offset;
179  }
180  void realign(int dir, int markedpos=-1, int scrollpos=0);
182  {
183  return m_offset;
184  }
185 
186  const eRect & getBoundBox()
187  {
188  if (!bboxValid)
189  calc_bbox();
190 
191  return boundBox;
192  }
193 
194  const int size() const
195  {
196  return glyphs.size();
197  }
198 
199  const eRect& getGlyphBBox(int num) const
200  {
201  ASSERT(num >= 0);
202  ASSERT(num < (int)glyphs.size());
203  return glyphs[num].bbox;
204  }
205 
206  void setGlyphFlag(int g, int f)
207  {
208  ASSERT(g >= 0);
209  ASSERT(g < (int)glyphs.size());
210  glyphs[g].flags |= f;
211  }
212 
213  void clearGlyphFlag(int g, int f)
214  {
215  ASSERT(g >= 0);
216  ASSERT(g < (int)glyphs.size());
217  glyphs[g].flags |= f;
218  }
219 };
220 
221 class Font: public iObject
222 {
223  DECLARE_REF(Font);
224 public:
225  FTC_ScalerRec scaler;
228  FT_Error getGlyphBitmap(FT_UInt glyph_index, FTC_SBit *sbit);
229  FT_Error getGlyphImage(FT_UInt glyph_index, FT_Glyph *glyph, FT_Glyph *borderglyph, int bordersize);
230  FT_Face face;
231  FT_Size size;
232 
233  int tabwidth;
234  int height;
235  Font(fontRenderClass *render, FTC_FaceID faceid, int isize, int tabwidth, int renderflags);
236  virtual ~Font();
237 };
238 
239 extern fontRenderClass *font;
240 
241 #endif // !SWIG
242 
243 #endif
Definition: font.h:222
FT_Error getGlyphBitmap(FT_UInt glyph_index, FTC_SBit *sbit)
Definition: font.cpp:322
virtual ~Font()
Definition: font.cpp:332
int tabwidth
Definition: font.h:233
FT_Size size
Definition: font.h:231
fontRenderClass * renderer
Definition: font.h:227
FTC_Image_Desc font
Definition: font.h:226
int height
Definition: font.h:234
FT_Error getGlyphImage(FT_UInt glyph_index, FT_Glyph *glyph, FT_Glyph *borderglyph, int bordersize)
Definition: font.cpp:327
Font(fontRenderClass *render, FTC_FaceID faceid, int isize, int tabwidth, int renderflags)
Definition: font.cpp:305
FTC_ScalerRec scaler
Definition: font.h:225
FT_Face face
Definition: font.h:230
Definition: lcd.h:22
Definition: epoint.h:9
Definition: erect.h:11
Definition: esize.h:8
Definition: font.h:118
int getLineCount(void) const
Definition: font.h:167
@ dirRight
Definition: font.h:173
@ dirBlock
Definition: font.h:173
@ dirLeft
Definition: font.h:173
@ dirCenter
Definition: font.h:173
@ dirBidi
Definition: font.h:173
@ dirCenterIfFits
Definition: font.h:173
static void forceReplacementGlyph(int unicode)
Definition: font.h:159
static void setReplacementFont(std::string font)
Definition: font.h:158
const eRect & getBoundBox()
Definition: font.h:186
void setTextOffset(int offset)
Definition: font.h:176
void clear()
Definition: font.cpp:1398
static void setFallbackFont(std::string font)
Definition: font.h:161
virtual ~eTextPara()
Definition: font.cpp:580
const eRect & getGlyphBBox(int num) const
Definition: font.h:199
const int size() const
Definition: font.h:194
void setGlyphFlag(int g, int f)
Definition: font.h:206
void realign(int dir, int markedpos=-1, int scrollpos=0)
Definition: font.cpp:1225
int getTextOffset()
Definition: font.h:181
void blit(gDC &dc, const ePoint &offset, const gRGB &background, const gRGB &foreground, bool border=false)
Definition: font.cpp:933
void clearGlyphFlag(int g, int f)
Definition: font.h:213
eTextPara(eRect area, ePoint start=ePoint(-1, -1))
Definition: font.h:149
int renderString(const char *string, int flags=0, int border=0, int markedpos=-1)
Definition: font.cpp:656
Definition: fb.h:15
Definition: font.h:35
int getFont(ePtr< Font > &font, const std::string &face, int size, int tabwidth=-1)
Definition: font.cpp:269
~fontRenderClass()
Definition: font.cpp:255
static fontRenderClass * getInstance()
Definition: font.cpp:73
std::string AddFont(const std::string &filename, const std::string &name, int scale, int renderflags=0)
Definition: font.cpp:150
fontRenderClass()
Definition: font.cpp:182
FT_Error FTC_Face_Requester(FTC_FaceID face_id, FT_Face *aface)
Definition: font.cpp:87
float getLineHeight(const gFont &font)
Definition: font.cpp:229
std::vector< std::string > getFontFaces()
Definition: font.cpp:283
Definition: grc.h:330
A softreference to a font.
Definition: gfont.h:14
Definition: object.h:15
#define NULL
Definition: eerror.h:101
#define ASSERT(x)
Definition: eerror.h:155
const char * filename
Definition: epng.h:36
const char int int int float scale
Definition: epng.h:39
FTC_ImageCache FTC_Image_Cache
Definition: font.h:12
fontRenderClass * font
FTC_ImageTypeRec FTC_Image_Desc
Definition: font.h:13
FTC_SBitCache FTC_SBit_Cache
Definition: font.h:14
std::vector< pGlyph > glyphString
Definition: font.h:112
size
Definition: Plugins/SystemPlugins/PositionerSetup/log.py:16
name
Definition: newplugin.py:9
std::string int int int int int unsigned int background
Definition: picload.cpp:1503
std::string int x
Definition: picload.cpp:1503
#define f
Definition: rotor_calc.cpp:143
Definition: gpixmap.h:14
Definition: font.h:97
pGlyph()
Definition: font.h:105
eRect bbox
Definition: font.h:103
int w
Definition: font.h:98
FT_UInt glyph_index
Definition: font.h:101
unsigned long newcolor
Definition: font.h:99
FT_Glyph image
Definition: font.h:104
FT_Glyph borderimage
Definition: font.h:104
int y
Definition: font.h:98
int flags
Definition: font.h:102
int x
Definition: font.h:98
ePtr< Font > font
Definition: font.h:100