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))
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__);
441 if (!FontNames->
Size()) {
443 FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL);
444 FcPattern *pat = FcPatternCreate();
445 FcPatternAddBool(pat, FC_SCALABLE, FcTrue);
447 FcPatternAddInteger(pat, FC_SPACING, FC_MONO);
448 FcFontSet* fontset = FcFontList(NULL, pat, os);
449 for (
int i = 0; i < fontset->nfont; i++) {
450 char *s = (
char *)FcNameUnparse(fontset->fonts[i]);
453 char *c = strchr(s,
':');
455 char *p = strchr(c + 1,
',');
459 char *p = strchr(s,
',');
462 memmove(p, c, strlen(c) + 1);
472 FcFontSetDestroy(fontset);
473 FcPatternDestroy(pat);
474 FcObjectSetDestroy(os);
478 return FontNames->
Size() > 0;
489 FcPattern *pat = FcNameParse((FcChar8 *)fn);
490 FcPatternAddBool(pat, FC_SCALABLE, FcTrue);
491 FcConfigSubstitute(NULL, pat, FcMatchPattern);
492 FcDefaultSubstitute(pat);
494 FcFontSet *fontset = FcFontSort(NULL, pat, FcFalse, NULL, &fresult);
496 for (
int i = 0; i < fontset->nfont; i++) {
498 FcPatternGetBool(fontset->fonts[i], FC_SCALABLE, 0, &scalable);
501 FcPatternGetString(fontset->fonts[i], FC_FILE, 0, &s);
502 FontFileName = (
char *)s;
506 FcFontSetDestroy(fontset);
510 FcPatternDestroy(pat);
518 cString cFont::Bidi(
const char *Ltr)
521 fribidi_set_mirroring(
true);
522 fribidi_set_reorder_nsm(
false);
523 FriBidiCharSet fribidiCharset = FRIBIDI_CHAR_SET_UTF8;
524 int LtrLen = strlen(Ltr);
525 FriBidiCharType Base = FRIBIDI_TYPE_L;
526 FriBidiChar *Logical =
MALLOC(FriBidiChar, LtrLen + 1) ;
527 int RtlLen = fribidi_charset_to_unicode(fribidiCharset,
const_cast<char *
>(Ltr), LtrLen, Logical);
528 FriBidiChar *Visual =
MALLOC(FriBidiChar, LtrLen + 1) ;
530 bool ok = fribidi_log2vis(Logical, RtlLen, &Base, Visual, NULL, NULL, NULL);
532 fribidi_remove_bidi_marks(Visual, RtlLen, NULL, NULL, NULL);
533 Rtl =
MALLOC(
char, RtlLen * 4 + 1);
534 fribidi_unicode_to_charset(fribidiCharset, Visual, RtlLen, Rtl);
584 for (
char *p =
text; *p; ) {
590 Blank = Delim = NULL;
594 else if (sl == 1 && isspace(sym))
597 if (w + cw > Width) {
612 strcpy(s + l + 1, p);
620 if (strchr(
"-.,:;!?_", *p)) {
649 for (
int i = 0; i < Line; i++) {
658 if ((
eol = strchr(s,
'\n')) != NULL)
tColor GetColor(int x, int y) const
Returns the color at the given coordinates.
void SetIndex(int x, int y, tIndex Index)
Sets the index at the given coordinates to Index.
static const char * SystemCharacterTable(void)
virtual int Width(void) const
Returns the original character width as requested when the font was created, or 0 if the default widt...
virtual int Width(uint c) const
Returns the width of the given character in pixel.
virtual int Height(void) const
Returns the height of this font in pixel (all characters have the same height).
cDummyFont(int CharHeight, int CharWidth)
virtual int Width(const char *s) const
Returns the width of the given string in pixel.
virtual void DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const
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.
virtual int Width(void) const
Returns the original character width as requested when the font was created, or 0 if the default widt...
virtual const char * FontName(void) const
Returns the font name.
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.
virtual int Height(void) const =0
Returns the height of this font in pixel (all characters have the same height).
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.
static bool GetAvailableFontNames(cStringList *FontNames, bool Monospaced=false)
Queries the font configuration for a list of available font names, which is returned in FontNames.
static const cFont * GetFont(eDvbFont Font)
Gets the given Font, which was previously set by a call to SetFont().
static cString GetFontFileName(const char *FontName)
Returns the actual font file name for the given FontName.
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.
cGlyph * Glyph(uint CharCode, bool AntiAliased=false) const
FT_Library library
Handle to library.
FT_Face face
Handle to face object.
virtual int Width(void) const
Returns the original character width as requested when the font was created, or 0 if the default widt...
virtual int Height(void) const
Returns the height of this font in pixel (all characters have the same height).
int Kerning(cGlyph *Glyph, uint PrevSym) const
cFreetypeFont(const char *Name, int CharHeight, int CharWidth=0)
virtual int Size(void) const
Returns the original size as requested when the font was created.
virtual const char * FontName(void) const
Returns the font name.
cList< cGlyph > glyphCacheAntiAliased
cList< cGlyph > glyphCacheMonochrome
uchar * Bitmap(void) const
cGlyph(uint CharCode, FT_GlyphSlotRec_ *GlyphData)
cVector< tKerning > kerningCache
void SetKerningCache(uint PrevSym, int Kerning)
int left
The bitmap's left bearing expressed in integer pixels.
uint CharCode(void) const
int rows
The number of bitmap rows.
int width
The number of pixels per bitmap row.
int pitch
The pitch's absolute value is the number of bytes taken by one bitmap row, including padding.
int top
The bitmap's top bearing expressed in integer pixels.
int GetKerningCache(uint PrevSym) const
void Add(cListObject *Object, cListObject *After=NULL)
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
tColor Blend(tColor ColorFg, tColor ColorBg, uint8_t Level) const
Determines a color that consists of a linear blend between ColorFg and ColorBg.
int Index(tColor Color)
Returns the index of the given Color (the first color has index 0).
const cRect & DrawPort(void) const
Returns the pixmap's draw port, which is relative to the view port.
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.
char FontOsd[MAXFONTNAME]
char FontSml[MAXFONTNAME]
char FontFix[MAXFONTNAME]
void Sort(bool IgnoreCase=false)
const char * GetLine(int Line)
Returns the given Line. The first line is numbered 0.
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 ...
const char * Text(void)
Returns the full wrapped text.
virtual void Append(T Data)
const char * DefaultFontOsd
const char * DefaultFontSml
const char * DefaultFontFix
#define UNKNOWN_GLYPH_INDICATOR
static int Utf8CharLen(const char *s)
tColor AlphaBlend(tColor ColorFg, tColor ColorBg, uint8_t AlphaLayer)
static const cCursesFont Font
tKerning(uint PrevSym, int Kerning=0)