vdr  2.2.0
font.c
Go to the documentation of this file.
1 /*
2  * font.c: Font handling for the DVB On Screen Display
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * BiDi support by Osama Alrawab <alrawab@hotmail.com> @2008 Tripoli-Libya.
8  *
9  * $Id: font.c 3.2 2014/01/07 12:19:45 kls Exp $
10  */
11 
12 #include "font.h"
13 #include <ctype.h>
14 #include <fontconfig/fontconfig.h>
15 #ifdef BIDI
16 #include <fribidi.h>
17 #endif
18 #include <ft2build.h>
19 #include FT_FREETYPE_H
20 #include "config.h"
21 #include "osd.h"
22 #include "tools.h"
23 
24 const char *DefaultFontOsd = "Sans Serif:Bold";
25 const char *DefaultFontSml = "Sans Serif";
26 const char *DefaultFontFix = "Courier:Bold";
27 
28 // --- cFreetypeFont ---------------------------------------------------------
29 
30 #define KERNING_UNKNOWN (-10000)
31 
32 struct tKerning {
33  uint prevSym;
34  int kerning;
35  tKerning(uint PrevSym, int Kerning = 0) { prevSym = PrevSym; kerning = Kerning; }
36  };
37 
38 class cGlyph : public cListObject {
39 private:
40  uint charCode;
42  int advanceX;
43  int advanceY;
44  int left;
45  int top;
46  int width;
47  int rows;
48  int pitch;
50 public:
51  cGlyph(uint CharCode, FT_GlyphSlotRec_ *GlyphData);
52  virtual ~cGlyph();
53  uint CharCode(void) const { return charCode; }
54  uchar *Bitmap(void) const { return bitmap; }
55  int AdvanceX(void) const { return advanceX; }
56  int AdvanceY(void) const { return advanceY; }
57  int Left(void) const { return left; }
58  int Top(void) const { return top; }
59  int Width(void) const { return width; }
60  int Rows(void) const { return rows; }
61  int Pitch(void) const { return pitch; }
62  int GetKerningCache(uint PrevSym) const;
63  void SetKerningCache(uint PrevSym, int Kerning);
64  };
65 
66 cGlyph::cGlyph(uint CharCode, FT_GlyphSlotRec_ *GlyphData)
67 {
68  charCode = CharCode;
69  advanceX = GlyphData->advance.x >> 6;
70  advanceY = GlyphData->advance.y >> 6;
71  left = GlyphData->bitmap_left;
72  top = GlyphData->bitmap_top;
73  width = GlyphData->bitmap.width;
74  rows = GlyphData->bitmap.rows;
75  pitch = GlyphData->bitmap.pitch;
76  bitmap = MALLOC(uchar, rows * pitch);
77  memcpy(bitmap, GlyphData->bitmap.buffer, rows * pitch);
78 }
79 
81 {
82  free(bitmap);
83 }
84 
85 int cGlyph::GetKerningCache(uint PrevSym) const
86 {
87  for (int i = kerningCache.Size(); --i > 0; ) {
88  if (kerningCache[i].prevSym == PrevSym)
89  return kerningCache[i].kerning;
90  }
91  return KERNING_UNKNOWN;
92 }
93 
94 void cGlyph::SetKerningCache(uint PrevSym, int Kerning)
95 {
96  kerningCache.Append(tKerning(PrevSym, Kerning));
97 }
98 
99 class cFreetypeFont : public cFont {
100 private:
102  int size;
103  int height;
104  int bottom;
105  FT_Library library;
106  FT_Face face;
109  int Bottom(void) const { return bottom; }
110  int Kerning(cGlyph *Glyph, uint PrevSym) const;
111  cGlyph* Glyph(uint CharCode, bool AntiAliased = false) const;
112 public:
113  cFreetypeFont(const char *Name, int CharHeight, int CharWidth = 0);
114  virtual ~cFreetypeFont();
115  virtual const char *FontName(void) const { return fontName; }
116  virtual int Size(void) const { return size; }
117  virtual int Width(uint c) const;
118  virtual int Width(const char *s) const;
119  virtual int Height(void) const { return height; }
120  virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const;
121  virtual void DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const;
122  };
123 
124 cFreetypeFont::cFreetypeFont(const char *Name, int CharHeight, int CharWidth)
125 {
126  fontName = Name;
127  size = CharHeight;
128  height = 0;
129  bottom = 0;
130  int error = FT_Init_FreeType(&library);
131  if (!error) {
132  error = FT_New_Face(library, Name, 0, &face);
133  if (!error) {
134  if (face->num_fixed_sizes && face->available_sizes) { // fixed font
135  // TODO what exactly does all this mean?
136  height = face->available_sizes->height;
137  for (uint sym ='A'; sym < 'z'; sym++) { // search for descender for fixed font FIXME
138  FT_UInt glyph_index = FT_Get_Char_Index(face, sym);
139  error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
140  if (!error) {
141  error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
142  if (!error) {
143  if (face->glyph->bitmap.rows-face->glyph->bitmap_top > bottom)
144  bottom = face->glyph->bitmap.rows-face->glyph->bitmap_top;
145  }
146  else
147  esyslog("ERROR: FreeType: error %d in FT_Render_Glyph", error);
148  }
149  else
150  esyslog("ERROR: FreeType: error %d in FT_Load_Glyph", error);
151  }
152  }
153  else {
154  error = FT_Set_Char_Size(face, // handle to face object
155  CharWidth * 64, // CharWidth in 1/64th of points
156  CharHeight * 64, // CharHeight in 1/64th of points
157  0, // horizontal device resolution
158  0); // vertical device resolution
159  if (!error) {
160  height = (face->size->metrics.ascender - face->size->metrics.descender + 63) / 64;
161  bottom = abs((face->size->metrics.descender - 63) / 64);
162  }
163  else
164  esyslog("ERROR: FreeType: error %d during FT_Set_Char_Size (font = %s)\n", error, Name);
165  }
166  }
167  else
168  esyslog("ERROR: FreeType: load error %d (font = %s)", error, Name);
169  }
170  else
171  esyslog("ERROR: FreeType: initialization error %d (font = %s)", error, Name);
172 }
173 
175 {
176  FT_Done_Face(face);
177  FT_Done_FreeType(library);
178 }
179 
180 int cFreetypeFont::Kerning(cGlyph *Glyph, uint PrevSym) const
181 {
182  int kerning = 0;
183  if (Glyph && PrevSym) {
184  kerning = Glyph->GetKerningCache(PrevSym);
185  if (kerning == KERNING_UNKNOWN) {
186  FT_Vector delta;
187  FT_UInt glyph_index = FT_Get_Char_Index(face, Glyph->CharCode());
188  FT_UInt glyph_index_prev = FT_Get_Char_Index(face, PrevSym);
189  FT_Get_Kerning(face, glyph_index_prev, glyph_index, FT_KERNING_DEFAULT, &delta);
190  kerning = delta.x / 64;
191  Glyph->SetKerningCache(PrevSym, kerning);
192  }
193  }
194  return kerning;
195 }
196 
197 cGlyph* cFreetypeFont::Glyph(uint CharCode, bool AntiAliased) const
198 {
199  // Non-breaking space:
200  if (CharCode == 0xA0)
201  CharCode = 0x20;
202 
203  // Lookup in cache:
204  cList<cGlyph> *glyphCache = AntiAliased ? &glyphCacheAntiAliased : &glyphCacheMonochrome;
205  for (cGlyph *g = glyphCache->First(); g; g = glyphCache->Next(g)) {
206  if (g->CharCode() == CharCode)
207  return g;
208  }
209 
210  FT_UInt glyph_index = FT_Get_Char_Index(face, CharCode);
211 
212  // Load glyph image into the slot (erase previous one):
213  int error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
214  if (error)
215  esyslog("ERROR: FreeType: error during FT_Load_Glyph");
216  else {
217 #if ((FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 1 && FREETYPE_PATCH >= 7) || (FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 2 && FREETYPE_PATCH <= 1))// TODO workaround for bug? which one?
218  if (AntiAliased || CharCode == 32)
219 #else
220  if (AntiAliased)
221 #endif
222  error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
223  else
224  error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO);
225  if (error)
226  esyslog("ERROR: FreeType: error during FT_Render_Glyph %d, %d\n", CharCode, glyph_index);
227  else { //new bitmap
228  cGlyph *Glyph = new cGlyph(CharCode, face->glyph);
229  glyphCache->Add(Glyph);
230  return Glyph;
231  }
232  }
233 #define UNKNOWN_GLYPH_INDICATOR '?'
234  if (CharCode != UNKNOWN_GLYPH_INDICATOR)
235  return Glyph(UNKNOWN_GLYPH_INDICATOR, AntiAliased);
236  return NULL;
237 }
238 
239 int cFreetypeFont::Width(uint c) const
240 {
241  cGlyph *g = Glyph(c, Setup.AntiAlias);
242  return g ? g->AdvanceX() : 0;
243 }
244 
245 int cFreetypeFont::Width(const char *s) const
246 {
247  int w = 0;
248  if (s) {
249 #ifdef BIDI
250  cString bs = Bidi(s);
251  s = bs;
252 #endif
253  uint prevSym = 0;
254  while (*s) {
255  int sl = Utf8CharLen(s);
256  uint sym = Utf8CharGet(s, sl);
257  s += sl;
258  cGlyph *g = Glyph(sym, Setup.AntiAlias);
259  if (g)
260  w += g->AdvanceX() + Kerning(g, prevSym);
261  prevSym = sym;
262  }
263  }
264  return w;
265 }
266 
267 #define MAX_BLEND_LEVELS 256
268 
269 void cFreetypeFont::DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const
270 {
271  if (s && height) { // checking height to make sure we actually have a valid font
272 #ifdef BIDI
273  cString bs = Bidi(s);
274  s = bs;
275 #endif
276  bool AntiAliased = Setup.AntiAlias && Bitmap->Bpp() >= 8;
277  bool TransparentBackground = ColorBg == clrTransparent;
278  int16_t BlendLevelIndex[MAX_BLEND_LEVELS]; // tIndex is 8 bit unsigned, so a negative value can be used to mark unused entries
279  if (AntiAliased && !TransparentBackground)
280  memset(BlendLevelIndex, 0xFF, sizeof(BlendLevelIndex)); // initializes the array with negative values
281  tIndex fg = Bitmap->Index(ColorFg);
282  uint prevSym = 0;
283  while (*s) {
284  int sl = Utf8CharLen(s);
285  uint sym = Utf8CharGet(s, sl);
286  s += sl;
287  cGlyph *g = Glyph(sym, AntiAliased);
288  if (!g)
289  continue;
290  int kerning = Kerning(g, prevSym);
291  prevSym = sym;
292  uchar *buffer = g->Bitmap();
293  int symWidth = g->Width();
294  if (Width && x + symWidth + g->Left() + kerning - 1 > Width)
295  break; // we don't draw partial characters
296  if (x + symWidth + g->Left() + kerning > 0) {
297  for (int row = 0; row < g->Rows(); row++) {
298  for (int pitch = 0; pitch < g->Pitch(); pitch++) {
299  uchar bt = *(buffer + (row * g->Pitch() + pitch));
300  if (AntiAliased) {
301  if (bt > 0x00) {
302  int px = x + pitch + g->Left() + kerning;
303  int py = y + row + (height - Bottom() - g->Top());
304  tColor bg;
305  if (bt == 0xFF)
306  bg = fg;
307  else if (TransparentBackground)
308  bg = Bitmap->Index(Bitmap->Blend(ColorFg, Bitmap->GetColor(px, py), bt));
309  else if (BlendLevelIndex[bt] >= 0)
310  bg = BlendLevelIndex[bt];
311  else
312  bg = BlendLevelIndex[bt] = Bitmap->Index(Bitmap->Blend(ColorFg, ColorBg, bt));
313  Bitmap->SetIndex(px, py, bg);
314  }
315  }
316  else { //monochrome rendering
317  for (int col = 0; col < 8 && col + pitch * 8 <= symWidth; col++) {
318  if (bt & 0x80)
319  Bitmap->SetIndex(x + col + pitch * 8 + g->Left() + kerning, y + row + (height - Bottom() - g->Top()), fg);
320  bt <<= 1;
321  }
322  }
323  }
324  }
325  }
326  x += g->AdvanceX() + kerning;
327  if (x > Bitmap->Width() - 1)
328  break;
329  }
330  }
331 }
332 
333 void cFreetypeFont::DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const
334 {
335  if (s && height) { // checking height to make sure we actually have a valid font
336 #ifdef BIDI
337  cString bs = Bidi(s);
338  s = bs;
339 #endif
340  bool AntiAliased = Setup.AntiAlias;
341  uint prevSym = 0;
342  while (*s) {
343  int sl = Utf8CharLen(s);
344  uint sym = Utf8CharGet(s, sl);
345  s += sl;
346  cGlyph *g = Glyph(sym, AntiAliased);
347  if (!g)
348  continue;
349  int kerning = Kerning(g, prevSym);
350  prevSym = sym;
351  uchar *buffer = g->Bitmap();
352  int symWidth = g->Width();
353  if (Width && x + symWidth + g->Left() + kerning - 1 > Width)
354  break; // we don't draw partial characters
355  if (x + symWidth + g->Left() + kerning > 0) {
356  for (int row = 0; row < g->Rows(); row++) {
357  for (int pitch = 0; pitch < g->Pitch(); pitch++) {
358  uchar bt = *(buffer + (row * g->Pitch() + pitch));
359  if (AntiAliased) {
360  if (bt > 0x00)
361  Pixmap->DrawPixel(cPoint(x + pitch + g->Left() + kerning, y + row + (height - Bottom() - g->Top())), AlphaBlend(ColorFg, ColorBg, bt));
362  }
363  else { //monochrome rendering
364  for (int col = 0; col < 8 && col + pitch * 8 <= symWidth; col++) {
365  if (bt & 0x80)
366  Pixmap->DrawPixel(cPoint(x + col + pitch * 8 + g->Left() + kerning, y + row + (height - Bottom() - g->Top())), ColorFg);
367  bt <<= 1;
368  }
369  }
370  }
371  }
372  }
373  x += g->AdvanceX() + kerning;
374  if (x > Pixmap->DrawPort().Width() - 1)
375  break;
376  }
377  }
378 }
379 
380 // --- cDummyFont ------------------------------------------------------------
381 
382 // A dummy font, in case there are no fonts installed:
383 
384 class cDummyFont : public cFont {
385 private:
386  int height;
387 public:
388  cDummyFont(int CharHeight) { height = CharHeight; }
389  virtual int Width(uint c) const { return height; }
390  virtual int Width(const char *s) const { return height; }
391  virtual int Height(void) const { return height; }
392  virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const {}
393  virtual void DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const {};
394  };
395 
396 // --- cFont -----------------------------------------------------------------
397 
398 cFont *cFont::fonts[eDvbFontSize] = { NULL };
399 
400 void cFont::SetFont(eDvbFont Font, const char *Name, int CharHeight)
401 {
402  delete fonts[Font];
403  fonts[Font] = CreateFont(Name, constrain(CharHeight, MINFONTSIZE, MAXFONTSIZE));
404 }
405 
407 {
408  if (Setup.UseSmallFont == 0 && Font == fontSml)
409  Font = fontOsd;
410  else if (Setup.UseSmallFont == 2)
411  Font = fontSml;
412  if (!fonts[Font]) {
413  switch (Font) {
414  case fontOsd: SetFont(Font, Setup.FontOsd, Setup.FontOsdSize); break;
415  case fontSml: SetFont(Font, Setup.FontSml, min(Setup.FontSmlSize, Setup.FontOsdSize)); break;
416  case fontFix: SetFont(Font, Setup.FontFix, Setup.FontFixSize); break;
417  default: esyslog("ERROR: unknown Font %d (%s %d)", Font, __FUNCTION__, __LINE__);
418  }
419  }
420  return fonts[Font];
421 }
422 
423 cFont *cFont::CreateFont(const char *Name, int CharHeight, int CharWidth)
424 {
425  cString fn = GetFontFileName(Name);
426  cFont *f = *fn ? new cFreetypeFont(fn, CharHeight, CharWidth) : NULL;
427  if (!f || !f->Height())
428  f = new cDummyFont(CharHeight);
429  return f;
430 }
431 
432 bool cFont::GetAvailableFontNames(cStringList *FontNames, bool Monospaced)
433 {
434  if (!FontNames->Size()) {
435  FcInit();
436  FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL);
437  FcPattern *pat = FcPatternCreate();
438  FcPatternAddBool(pat, FC_SCALABLE, FcTrue);
439  if (Monospaced)
440  FcPatternAddInteger(pat, FC_SPACING, FC_MONO);
441  FcFontSet* fontset = FcFontList(NULL, pat, os);
442  for (int i = 0; i < fontset->nfont; i++) {
443  char *s = (char *)FcNameUnparse(fontset->fonts[i]);
444  if (s) {
445  // Strip i18n stuff:
446  char *c = strchr(s, ':');
447  if (c) {
448  char *p = strchr(c + 1, ',');
449  if (p)
450  *p = 0;
451  }
452  char *p = strchr(s, ',');
453  if (p) {
454  if (c)
455  memmove(p, c, strlen(c) + 1);
456  else
457  *p = 0;
458  }
459  // Make it user presentable:
460  s = strreplace(s, "\\", ""); // '-' is escaped
461  s = strreplace(s, "style=", "");
462  FontNames->Append(s); // takes ownership of s
463  }
464  }
465  FcFontSetDestroy(fontset);
466  FcPatternDestroy(pat);
467  FcObjectSetDestroy(os);
468  //FcFini(); // older versions of fontconfig are broken - and FcInit() can be called more than once
469  FontNames->Sort();
470  }
471  return FontNames->Size() > 0;
472 }
473 
474 cString cFont::GetFontFileName(const char *FontName)
475 {
476  cString FontFileName;
477  if (FontName) {
478  char *fn = strdup(FontName);
479  fn = strreplace(fn, ":", ":style=");
480  fn = strreplace(fn, "-", "\\-");
481  FcInit();
482  FcPattern *pat = FcNameParse((FcChar8 *)fn);
483  FcPatternAddBool(pat, FC_SCALABLE, FcTrue);
484  FcConfigSubstitute(NULL, pat, FcMatchPattern);
485  FcDefaultSubstitute(pat);
486  FcResult fresult;
487  FcFontSet *fontset = FcFontSort(NULL, pat, FcFalse, NULL, &fresult);
488  if (fontset) {
489  for (int i = 0; i < fontset->nfont; i++) {
490  FcBool scalable;
491  FcPatternGetBool(fontset->fonts[i], FC_SCALABLE, 0, &scalable);
492  if (scalable) {
493  FcChar8 *s = NULL;
494  FcPatternGetString(fontset->fonts[i], FC_FILE, 0, &s);
495  FontFileName = (char *)s;
496  break;
497  }
498  }
499  FcFontSetDestroy(fontset);
500  }
501  else
502  esyslog("ERROR: no usable font found for '%s'", FontName);
503  FcPatternDestroy(pat);
504  free(fn);
505  //FcFini(); // older versions of fontconfig are broken - and FcInit() can be called more than once
506  }
507  return FontFileName;
508 }
509 
510 #ifdef BIDI
511 cString cFont::Bidi(const char *Ltr)
512 {
513  if (!cCharSetConv::SystemCharacterTable()) { // bidi requires UTF-8
514  fribidi_set_mirroring(true);
515  fribidi_set_reorder_nsm(false);
516  FriBidiCharSet fribidiCharset = FRIBIDI_CHAR_SET_UTF8;
517  int LtrLen = strlen(Ltr);
518  FriBidiCharType Base = FRIBIDI_TYPE_L;
519  FriBidiChar *Logical = MALLOC(FriBidiChar, LtrLen + 1) ;
520  int RtlLen = fribidi_charset_to_unicode(fribidiCharset, const_cast<char *>(Ltr), LtrLen, Logical);
521  FriBidiChar *Visual = MALLOC(FriBidiChar, LtrLen + 1) ;
522  char *Rtl = NULL;
523  bool ok = fribidi_log2vis(Logical, RtlLen, &Base, Visual, NULL, NULL, NULL);
524  if (ok) {
525  fribidi_remove_bidi_marks(Visual, RtlLen, NULL, NULL, NULL);
526  Rtl = MALLOC(char, RtlLen * 4 + 1);
527  fribidi_unicode_to_charset(fribidiCharset, Visual, RtlLen, Rtl);
528  }
529  free(Logical);
530  free(Visual);
531  if (ok)
532  return cString(Rtl, true);
533  }
534  return cString(Ltr);
535 }
536 #endif
537 
538 // --- cTextWrapper ----------------------------------------------------------
539 
541 {
542  text = eol = NULL;
543  lines = 0;
544  lastLine = -1;
545 }
546 
547 cTextWrapper::cTextWrapper(const char *Text, const cFont *Font, int Width)
548 {
549  text = NULL;
550  Set(Text, Font, Width);
551 }
552 
554 {
555  free(text);
556 }
557 
558 void cTextWrapper::Set(const char *Text, const cFont *Font, int Width)
559 {
560  free(text);
561  text = Text ? strdup(Text) : NULL;
562  eol = NULL;
563  lines = 0;
564  lastLine = -1;
565  if (!text)
566  return;
567  lines = 1;
568  if (Width <= 0)
569  return;
570 
571  char *Blank = NULL;
572  char *Delim = NULL;
573  int w = 0;
574 
575  stripspace(text); // strips trailing newlines
576 
577  for (char *p = text; *p; ) {
578  int sl = Utf8CharLen(p);
579  uint sym = Utf8CharGet(p, sl);
580  if (sym == '\n') {
581  lines++;
582  w = 0;
583  Blank = Delim = NULL;
584  p++;
585  continue;
586  }
587  else if (sl == 1 && isspace(sym))
588  Blank = p;
589  int cw = Font->Width(sym);
590  if (w + cw > Width) {
591  if (Blank) {
592  *Blank = '\n';
593  p = Blank;
594  continue;
595  }
596  else if (w > 0) { // there has to be at least one character before the newline
597  // Here's the ugly part, where we don't have any whitespace to
598  // punch in a newline, so we need to make room for it:
599  if (Delim)
600  p = Delim + 1; // let's fall back to the most recent delimiter
601  char *s = MALLOC(char, strlen(text) + 2); // The additional '\n' plus the terminating '\0'
602  int l = p - text;
603  strncpy(s, text, l);
604  s[l] = '\n';
605  strcpy(s + l + 1, p);
606  free(text);
607  text = s;
608  p = text + l;
609  continue;
610  }
611  }
612  w += cw;
613  if (strchr("-.,:;!?_", *p)) {
614  Delim = p;
615  Blank = NULL;
616  }
617  p += sl;
618  }
619 }
620 
621 const char *cTextWrapper::Text(void)
622 {
623  if (eol) {
624  *eol = '\n';
625  eol = NULL;
626  }
627  return text;
628 }
629 
630 const char *cTextWrapper::GetLine(int Line)
631 {
632  char *s = NULL;
633  if (Line < lines) {
634  if (eol) {
635  *eol = '\n';
636  if (Line == lastLine + 1)
637  s = eol + 1;
638  eol = NULL;
639  }
640  if (!s) {
641  s = text;
642  for (int i = 0; i < Line; i++) {
643  s = strchr(s, '\n');
644  if (s)
645  s++;
646  else
647  break;
648  }
649  }
650  if (s) {
651  if ((eol = strchr(s, '\n')) != NULL)
652  *eol = 0;
653  }
654  lastLine = Line;
655  }
656  return s;
657 }
cTextWrapper(void)
Definition: font.c:540
int AntiAlias
Definition: config.h:323
unsigned char uchar
Definition: tools.h:30
cList< cGlyph > glyphCacheAntiAliased
Definition: font.c:108
Definition: osd.h:454
virtual void DrawPixel(const cPoint &Point, tColor Color)=0
Sets the pixel at the given Point to the given Color, which is a full 32 bit ARGB value...
virtual int Height(void) const
Returns the height of this font in pixel (all characters have the same height).
Definition: font.c:391
int top
The bitmap&#39;s top bearing expressed in integer pixels.
Definition: font.c:45
int GetKerningCache(uint PrevSym) const
Definition: font.c:85
Definition: font.h:23
uchar * Bitmap(void) const
Definition: font.c:54
void Add(cListObject *Object, cListObject *After=NULL)
Definition: tools.c:2014
char * stripspace(char *s)
Definition: tools.c:201
const char * Text(void)
Returns the full wrapped text.
Definition: font.c:621
static const char * SystemCharacterTable(void)
Definition: tools.h:164
static void SetFont(eDvbFont Font, const char *Name, int CharHeight)
< Draws the given text into the Pixmap at position (x, y) with the given colors.
Definition: font.c:400
cString fontName
Definition: font.c:101
const cRect & DrawPort(void) const
Returns the pixmap&#39;s draw port, which is relative to the view port.
Definition: osd.h:539
int Index(tColor Color)
Returns the index of the given Color (the first color has index 0).
Definition: osd.c:144
virtual void Append(T Data)
Definition: tools.h:571
virtual ~cGlyph()
Definition: font.c:80
const char * DefaultFontSml
Definition: font.c:25
int Width(void) const
Definition: osd.h:367
#define esyslog(a...)
Definition: tools.h:34
int FontFixSize
Definition: config.h:332
int Left(void) const
Definition: font.c:57
uint CharCode(void) const
Definition: font.c:53
uint prevSym
Definition: font.c:33
int Bottom(void) const
Definition: font.c:109
int advanceY
Definition: font.c:43
char FontSml[MAXFONTNAME]
Definition: config.h:325
Definition: osd.h:306
int rows
The number of bitmap rows.
Definition: font.c:47
int size
Definition: font.c:102
tColor Blend(tColor ColorFg, tColor ColorBg, uint8_t Level) const
Determines a color that consists of a linear blend between ColorFg and ColorBg.
Definition: osd.c:216
static cFont * fonts[]
Definition: font.h:39
T min(T a, T b)
Definition: tools.h:54
int AdvanceY(void) const
Definition: font.c:56
int Top(void) const
Definition: font.c:58
int Bpp(void) const
Definition: osd.h:111
#define MALLOC(type, size)
Definition: tools.h:46
Definition: osd.h:169
int Width(void) const
Definition: osd.h:188
virtual int Width(uint c) const
Returns the width of the given character in pixel.
Definition: font.c:239
virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const
Draws the given text into the Bitmap at position (x, y) with the given colors.
Definition: font.c:269
#define UNKNOWN_GLYPH_INDICATOR
FT_Library library
Handle to library.
Definition: font.c:105
int pitch
The pitch&#39;s absolute value is the number of bytes taken by one bitmap row, including padding...
Definition: font.c:48
int Rows(void) const
Definition: font.c:60
T * Next(const T *object) const
Definition: tools.h:495
eDvbFont
Definition: font.h:21
Definition: font.h:22
T constrain(T v, T l, T h)
Definition: tools.h:60
void Set(const char *Text, const cFont *Font, int Width)
Wraps the Text to make it fit into the area defined by the given Width when displayed with the given ...
Definition: font.c:558
void SetKerningCache(uint PrevSym, int Kerning)
Definition: font.c:94
FT_Face face
Handle to face object.
Definition: font.c:106
char FontOsd[MAXFONTNAME]
Definition: config.h:324
~cTextWrapper()
Definition: font.c:553
tColor AlphaBlend(tColor ColorFg, tColor ColorBg, uint8_t AlphaLayer)
Definition: osd.c:81
#define KERNING_UNKNOWN
Definition: font.c:30
static const cCursesFont Font
Definition: skincurses.c:30
cSetup Setup
Definition: config.c:373
#define MINFONTSIZE
Definition: font.h:18
cGlyph(uint CharCode, FT_GlyphSlotRec_ *GlyphData)
Definition: font.c:66
static int Utf8CharLen(const char *s)
Definition: si.c:417
#define MAXFONTSIZE
Definition: font.h:19
static cFont * CreateFont(const char *Name, int CharHeight, int CharWidth=0)
Creates a new font object with the given Name and makes its characters CharHeight pixels high...
Definition: font.c:423
int Size(void) const
Definition: tools.h:551
int advanceX
Definition: font.c:42
int AdvanceX(void) const
Definition: font.c:55
#define MAX_BLEND_LEVELS
Definition: font.c:267
cVector< tKerning > kerningCache
Definition: font.c:49
const char * DefaultFontFix
Definition: font.c:26
const char * GetLine(int Line)
Returns the given Line. The first line is numbered 0.
Definition: font.c:630
int bottom
Definition: font.c:104
uchar * bitmap
Definition: font.c:41
int Width(void) const
Definition: font.c:59
cGlyph * Glyph(uint CharCode, bool AntiAliased=false) const
Definition: font.c:197
T * First(void) const
Definition: tools.h:492
char FontFix[MAXFONTNAME]
Definition: config.h:326
int kerning
Definition: font.c:34
static cString GetFontFileName(const char *FontName)
Returns the actual font file name for the given FontName.
Definition: font.c:474
virtual int Width(const char *s) const
Returns the width of the given string in pixel.
Definition: font.c:390
virtual int Width(uint c) const =0
Returns the width of the given character in pixel.
int height
Definition: font.c:103
static bool GetAvailableFontNames(cStringList *FontNames, bool Monospaced=false)
Queries the font configuration for a list of available font names, which is returned in FontNames...
Definition: font.c:432
virtual void DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const
Definition: font.c:393
int width
The number of pixels per bitmap row.
Definition: font.c:46
uint Utf8CharGet(const char *s, int Length)
Returns the UTF-8 symbol at the beginning of the given string.
Definition: tools.c:771
virtual int Height(void) const
Returns the height of this font in pixel (all characters have the same height).
Definition: font.c:119
cFreetypeFont(const char *Name, int CharHeight, int CharWidth=0)
Definition: font.c:124
int FontOsdSize
Definition: config.h:330
int UseSmallFont
Definition: config.h:322
Definition: font.c:38
virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const
Draws the given text into the Bitmap at position (x, y) with the given colors.
Definition: font.c:392
void Sort(bool IgnoreCase=false)
Definition: tools.h:629
cList< cGlyph > glyphCacheMonochrome
Definition: font.c:107
uint charCode
Definition: font.c:40
tColor GetColor(int x, int y) const
Returns the color at the given coordinates.
Definition: osd.h:277
int height
Definition: font.c:386
int left
The bitmap&#39;s left bearing expressed in integer pixels.
Definition: font.c:44
virtual int Height(void) const =0
Returns the height of this font in pixel (all characters have the same height).
virtual ~cFreetypeFont()
Definition: font.c:174
int FontSmlSize
Definition: config.h:331
uint8_t tIndex
Definition: font.h:31
const char * DefaultFontOsd
Definition: font.c:24
cDummyFont(int CharHeight)
Definition: font.c:388
int Kerning(cGlyph *Glyph, uint PrevSym) const
Definition: font.c:180
tKerning(uint PrevSym, int Kerning=0)
Definition: font.c:35
void SetIndex(int x, int y, tIndex Index)
Sets the index at the given coordinates to Index.
Definition: osd.c:500
int Pitch(void) const
Definition: font.c:61
char * strreplace(char *s, char c1, char c2)
Definition: tools.c:139
#define eDvbFontSize
Definition: font.h:25
Definition: font.h:37
virtual const char * FontName(void) const
Returns the font name.
Definition: font.c:115
Definition: tools.h:168
Definition: font.c:32
static const cFont * GetFont(eDvbFont Font)
Gets the given Font, which was previously set by a call to SetFont().
Definition: font.c:406
virtual int Size(void) const
Returns the original size as requested when the font was created.
Definition: font.c:116
uint32_t tColor
Definition: font.h:29
virtual int Width(uint c) const
Returns the width of the given character in pixel.
Definition: font.c:389