Go to the documentation of this file.
14 #include <fontconfig/fontconfig.h>
19 #include FT_FREETYPE_H
30 #define KERNING_UNKNOWN (-10000)
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;
112 cGlyph*
Glyph(uint CharCode,
bool AntiAliased =
false)
const;
114 cFreetypeFont(
const char *Name,
int CharHeight,
int CharWidth = 0);
119 virtual int Width(uint c)
const;
120 virtual int Width(
const char *s)
const;
133 int error = FT_Init_FreeType(&
library);
137 if (
face->num_fixed_sizes &&
face->available_sizes) {
140 for (uint sym =
'A'; sym <
'z'; sym++) {
141 FT_UInt glyph_index = FT_Get_Char_Index(
face, sym);
142 error = FT_Load_Glyph(
face, glyph_index, FT_LOAD_DEFAULT);
144 error = FT_Render_Glyph(
face->glyph, FT_RENDER_MODE_NORMAL);
146 if (
int(
face->glyph->bitmap.rows-
face->glyph->bitmap_top) >
bottom)
150 esyslog(
"ERROR: FreeType: error %d in FT_Render_Glyph", error);
153 esyslog(
"ERROR: FreeType: error %d in FT_Load_Glyph", error);
157 error = FT_Set_Char_Size(
face,
163 height = (
face->size->metrics.ascender -
face->size->metrics.descender + 63) / 64;
164 bottom = abs((
face->size->metrics.descender - 63) / 64);
167 esyslog(
"ERROR: FreeType: error %d during FT_Set_Char_Size (font = %s)\n", error, Name);
171 esyslog(
"ERROR: FreeType: load error %d (font = %s)", error, Name);
174 esyslog(
"ERROR: FreeType: initialization error %d (font = %s)", error, Name);
186 if (
Glyph && PrevSym) {
191 FT_UInt glyph_index_prev = FT_Get_Char_Index(
face, PrevSym);
192 FT_Get_Kerning(
face, glyph_index_prev, glyph_index, FT_KERNING_DEFAULT, &delta);
193 kerning = delta.x / 64;
203 if (CharCode == 0xA0)
209 if (g->CharCode() == CharCode)
213 FT_UInt glyph_index = FT_Get_Char_Index(
face, CharCode);
216 int error = FT_Load_Glyph(
face, glyph_index, FT_LOAD_DEFAULT);
218 esyslog(
"ERROR: FreeType: error during FT_Load_Glyph");
220 #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?
221 if (AntiAliased || CharCode == 32)
225 error = FT_Render_Glyph(
face->glyph, FT_RENDER_MODE_NORMAL);
227 error = FT_Render_Glyph(
face->glyph, FT_RENDER_MODE_MONO);
229 esyslog(
"ERROR: FreeType: error during FT_Render_Glyph %d, %d\n", CharCode, glyph_index);
236 #define UNKNOWN_GLYPH_INDICATOR '?'
270 #define MAX_BLEND_LEVELS 256
282 if (AntiAliased && !TransparentBackground)
283 memset(BlendLevelIndex, 0xFF,
sizeof(BlendLevelIndex));
293 int kerning =
Kerning(g, prevSym);
296 int symWidth = g->
Width();
299 if (x + symWidth + g->
Left() + kerning > 0) {
300 for (
int row = 0; row < g->
Rows(); row++) {
301 for (
int pitch = 0; pitch < g->
Pitch(); pitch++) {
302 uchar bt = *(buffer + (row * g->
Pitch() + pitch));
305 int px = x + pitch + g->
Left() + kerning;
310 else if (TransparentBackground)
312 else if (BlendLevelIndex[bt] >= 0)
313 bg = BlendLevelIndex[bt];
315 bg = BlendLevelIndex[bt] = Bitmap->
Index(Bitmap->
Blend(ColorFg, ColorBg, bt));
320 for (
int col = 0; col < 8 && col + pitch * 8 <= symWidth; col++) {
330 if (x > Bitmap->
Width() - 1)
352 int kerning =
Kerning(g, prevSym);
355 int symWidth = g->
Width();
358 if (x + symWidth + g->
Left() + kerning > 0) {
359 for (
int row = 0; row < g->
Rows(); row++) {
360 for (
int pitch = 0; pitch < g->
Pitch(); pitch++) {
361 uchar bt = *(buffer + (row * g->
Pitch() + pitch));
367 for (
int col = 0; col < 8 && col + pitch * 8 <= symWidth; col++) {
422 default:
esyslog(
"ERROR: unknown Font %d (%s %d)",
Font, __FUNCTION__, __LINE__);
439 if (!FontNames->
Size()) {
441 FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL);
442 FcPattern *pat = FcPatternCreate();
443 FcPatternAddBool(pat, FC_SCALABLE, FcTrue);
445 FcPatternAddInteger(pat, FC_SPACING, FC_MONO);
446 FcFontSet* fontset = FcFontList(NULL, pat, os);
447 for (
int i = 0; i < fontset->nfont; i++) {
448 char *s = (
char *)FcNameUnparse(fontset->fonts[i]);
451 char *c = strchr(s,
':');
453 char *p = strchr(c + 1,
',');
457 char *p = strchr(s,
',');
460 memmove(p, c, strlen(c) + 1);
470 FcFontSetDestroy(fontset);
471 FcPatternDestroy(pat);
472 FcObjectSetDestroy(os);
476 return FontNames->
Size() > 0;
487 FcPattern *pat = FcNameParse((FcChar8 *)fn);
488 FcPatternAddBool(pat, FC_SCALABLE, FcTrue);
489 FcConfigSubstitute(NULL, pat, FcMatchPattern);
490 FcDefaultSubstitute(pat);
492 FcFontSet *fontset = FcFontSort(NULL, pat, FcFalse, NULL, &fresult);
494 for (
int i = 0; i < fontset->nfont; i++) {
496 FcPatternGetBool(fontset->fonts[i], FC_SCALABLE, 0, &scalable);
499 FcPatternGetString(fontset->fonts[i], FC_FILE, 0, &s);
500 FontFileName = (
char *)s;
504 FcFontSetDestroy(fontset);
508 FcPatternDestroy(pat);
516 cString cFont::Bidi(
const char *Ltr)
519 fribidi_set_mirroring(
true);
520 fribidi_set_reorder_nsm(
false);
521 FriBidiCharSet fribidiCharset = FRIBIDI_CHAR_SET_UTF8;
522 int LtrLen = strlen(Ltr);
523 FriBidiCharType Base = FRIBIDI_TYPE_L;
524 FriBidiChar *Logical =
MALLOC(FriBidiChar, LtrLen + 1) ;
525 int RtlLen = fribidi_charset_to_unicode(fribidiCharset,
const_cast<char *
>(Ltr), LtrLen, Logical);
526 FriBidiChar *Visual =
MALLOC(FriBidiChar, LtrLen + 1) ;
528 bool ok = fribidi_log2vis(Logical, RtlLen, &Base, Visual, NULL, NULL, NULL);
530 fribidi_remove_bidi_marks(Visual, RtlLen, NULL, NULL, NULL);
531 Rtl =
MALLOC(
char, RtlLen * 4 + 1);
532 fribidi_unicode_to_charset(fribidiCharset, Visual, RtlLen, Rtl);
582 for (
char *p =
text; *p; ) {
588 Blank = Delim = NULL;
592 else if (sl == 1 && isspace(sym))
595 if (w + cw > Width) {
610 strcpy(s + l + 1, p);
618 if (strchr(
"-.,:;!?_", *p)) {
647 for (
int i = 0; i < Line; i++) {
656 if ((
eol = strchr(s,
'\n')) != NULL)
static const char * SystemCharacterTable(void)
uchar * Bitmap(void) const
void SetIndex(int x, int y, tIndex Index)
Sets the index at the given coordinates to Index.
cList< cGlyph > glyphCacheMonochrome
tColor GetColor(int x, int y) const
Returns the color at the given coordinates.
static const cFont * GetFont(eDvbFont Font)
Gets the given Font, which was previously set by a call to SetFont().
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.
cVector< tKerning > kerningCache
virtual int Height(void) const
Returns the height of this font in pixel (all characters have the same height).
const char * GetLine(int Line)
Returns the given Line. The first line is numbered 0.
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.
#define UNKNOWN_GLYPH_INDICATOR
virtual int Height(void) const
Returns the height of this font in pixel (all characters have the same height).
void Add(cListObject *Object, cListObject *After=NULL)
virtual int Width(void) const
Returns the original character width as requested when the font was created, or 0 if the default widt...
char FontFix[MAXFONTNAME]
int top
The bitmap's top bearing expressed in integer pixels.
tColor AlphaBlend(tColor ColorFg, tColor ColorBg, uint8_t AlphaLayer)
const char * Text(void)
Returns the full wrapped text.
virtual int Width(void) const
Returns the original character width as requested when the font was created, or 0 if the default widt...
int Kerning(cGlyph *Glyph, uint PrevSym) const
FT_Face face
Handle to face object.
char FontSml[MAXFONTNAME]
cGlyph(uint CharCode, FT_GlyphSlotRec_ *GlyphData)
virtual void DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const
int GetKerningCache(uint PrevSym) const
virtual int Height(void) const =0
Returns the height of this font in pixel (all characters have the same height).
const char * DefaultFontOsd
virtual int Width(void) const
Returns the original character width as requested when the font was created, or 0 if the default widt...
int pitch
The pitch's absolute value is the number of bytes taken by one bitmap row, including padding.
cList< cGlyph > glyphCacheAntiAliased
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
int left
The bitmap's left bearing expressed in integer pixels.
virtual const char * FontName(void) const
Returns the font name.
tColor Blend(tColor ColorFg, tColor ColorBg, uint8_t Level) const
Determines a color that consists of a linear blend between ColorFg and ColorBg.
void SetKerningCache(uint PrevSym, int Kerning)
const char * DefaultFontSml
virtual int Size(void) const
Returns the original size as requested when the font was created.
static bool GetAvailableFontNames(cStringList *FontNames, bool Monospaced=false)
Queries the font configuration for a list of available font names, which is returned in FontNames.
uint CharCode(void) const
virtual const char * FontName(void) const
Returns the font name.
static int Utf8CharLen(const char *s)
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.
int rows
The number of bitmap rows.
virtual int Width(const char *s) const
Returns the width of the given string in pixel.
static cString GetFontFileName(const char *FontName)
Returns the actual font file name for the given FontName.
const cRect & DrawPort(void) const
Returns the pixmap's draw port, which is relative to the view port.
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
cDummyFont(int CharHeight, int CharWidth)
virtual void Append(T Data)
void Sort(bool IgnoreCase=false)
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.
FT_Library library
Handle to library.
int Index(tColor Color)
Returns the index of the given Color (the first color has index 0).
const char * DefaultFontFix
cFreetypeFont(const char *Name, int CharHeight, int CharWidth=0)
char FontOsd[MAXFONTNAME]
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.
tKerning(uint PrevSym, int Kerning=0)
static const cCursesFont Font
cGlyph * Glyph(uint CharCode, bool AntiAliased=false) const
int width
The number of pixels per bitmap row.
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 ...
virtual int Width(uint c) const
Returns the width of the given character in pixel.