diff options
author | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2007-06-17 18:00:00 +0200 |
---|---|---|
committer | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2007-06-17 18:00:00 +0200 |
commit | b1e4da3be6552f58f3890bf2ad48879823d2e130 (patch) | |
tree | cf42a1e6b296956b82a2820948c7b90dbcddf26e /font.c | |
parent | b9b9ace9a8d2d1c0beda1dc0a2ebc6be9b47c305 (diff) | |
download | vdr-patch-lnbsharing-b1e4da3be6552f58f3890bf2ad48879823d2e130.tar.gz vdr-patch-lnbsharing-b1e4da3be6552f58f3890bf2ad48879823d2e130.tar.bz2 |
Version 1.5.4vdr-1.5.4
- Increased APIVERSION (forgot to do that in 1.5.2 and 1.5.3).
- Fixed a crash in i18n character set conversion (thanks to Alexander Riedel,
Jose Alberto Reguero and Christian Wieninger for patches that cured part of
the problem).
- Adjusted the 'skincurses' plugin to UTF-8 handling.
- Using nl_langinfo(CODESET) to determine the local codeset to use (thanks to
Thomas Günther). The codeset names in 'libsi/si.c' have been changed to the
canonical spelling with '-' (thanks to Ludwig Nussel for pointing this out).
- Modified handling invalid characters in VFAT mode.
- Replaced strn0cpy() with Utf8Strn0Cpy() where necessary.
- Now using 'fontconfig' to determine which fonts to use (thanks to Anssi Hannula
for code and hints on how to do this).
- If no fonts are installed, VDR now uses a dummy font that doesn't actually draw
any text, and logs an error message.
- The new function cFont::CreateFont() can be used by plugins to create and use
fonts of their own, independent of VDR's standard fonts.
- Updated the Finnish OSD texts (thanks to Rolf Ahrenberg).
- Changed the parameter "OSD font" to "Default font" in "Setup/OSD" (suggested
by Rolf Ahrenberg).
- Fixed handling detached processes in SystemExec() (thanks to Udo Richter).
- The info.vdr file now also stores the name of the channel, and the new function
cRecordingInfo::ChannelName() returns this information if available (based on
a patch from Alexander Hans).
- The new function cOsd::SetOsdPosition() can be used to dynamically change the
position and size of the OSD (based on a request from Christoph Haubrich).
Plugins that implement skins should no longer use Setup.OSDWidth etc. directly,
but should rather use cOsd::OsdWidth() etc. instead.
Currently a change to the OSD position will only apply to newly opened OSDs.
Diffstat (limited to 'font.c')
-rw-r--r-- | font.c | 103 |
1 files changed, 97 insertions, 6 deletions
@@ -4,17 +4,22 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: font.c 1.15 2007/06/09 14:41:27 kls Exp $ + * $Id: font.c 1.19 2007/06/17 12:13:49 kls Exp $ */ #include "font.h" #include <ctype.h> +#include <fontconfig/fontconfig.h> #include <ft2build.h> #include FT_FREETYPE_H #include "config.h" #include "osd.h" #include "tools.h" +const char *DefaultFontOsd = "Sans Serif:Bold"; +const char *DefaultFontSml = "Sans Serif"; +const char *DefaultFontFix = "Courier:Bold"; + // --- cFreetypeFont --------------------------------------------------------- #define KERNING_UNKNOWN (-10000) @@ -22,7 +27,7 @@ struct tKerning { uint prevSym; int kerning; - tKerning(uint PrevSym, int Kerning) { prevSym = PrevSym; kerning = Kerning; } + tKerning(uint PrevSym, int Kerning = 0) { prevSym = PrevSym; kerning = Kerning; } }; class cGlyph : public cListObject { @@ -286,14 +291,29 @@ void cFreetypeFont::DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColo } } +// --- cDummyFont ------------------------------------------------------------ + +// A dummy font, in case there are no fonts installed: + +class cDummyFont : public cFont { +public: + virtual int Width(uint c) const { return 10; } + virtual int Width(const char *s) const { return 50; } + virtual int Height(void) const { return 20; } + virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const {} + }; + // --- cFont ----------------------------------------------------------------- cFont *cFont::fonts[eDvbFontSize] = { NULL }; void cFont::SetFont(eDvbFont Font, const char *Name, int CharHeight) { + cFont *f = CreateFont(Name, CharHeight); + if (!f || !f->Height()) + f = new cDummyFont; delete fonts[Font]; - fonts[Font] = new cFreetypeFont(*Name == '/' ? Name : *AddDirectory(FONTDIR, Name), CharHeight); + fonts[Font] = f; } const cFont *cFont::GetFont(eDvbFont Font) @@ -304,14 +324,85 @@ const cFont *cFont::GetFont(eDvbFont Font) Font = fontSml; if (!fonts[Font]) { switch (Font) { - case fontOsd: SetFont(Font, AddDirectory(FONTDIR, Setup.FontOsd), Setup.FontOsdSize); break; - case fontSml: SetFont(Font, AddDirectory(FONTDIR, Setup.FontSml), Setup.FontSmlSize); break; - case fontFix: SetFont(Font, AddDirectory(FONTDIR, Setup.FontFix), Setup.FontFixSize); break; + case fontOsd: SetFont(Font, Setup.FontOsd, Setup.FontOsdSize); break; + case fontSml: SetFont(Font, Setup.FontSml, Setup.FontSmlSize); break; + case fontFix: SetFont(Font, Setup.FontFix, Setup.FontFixSize); break; } } return fonts[Font]; } +cFont *cFont::CreateFont(const char *Name, int CharHeight) +{ + cString fn = GetFontFileName(Name); + if (*fn) + return new cFreetypeFont(fn, CharHeight); + return NULL; +} + +bool cFont::GetAvailableFontNames(cStringList *FontNames, bool Monospaced) +{ + if (!FontNames->Size()) { + FcInit(); + FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL); + FcPattern *pat = FcPatternCreate(); + FcPatternAddBool(pat, FC_SCALABLE, FcTrue); + if (Monospaced) + FcPatternAddInteger(pat, FC_SPACING, FC_MONO); + FcFontSet* fontset = FcFontList(NULL, pat, os); + for (int i = 0; i < fontset->nfont; i++) { + char *s = (char *)FcNameUnparse(fontset->fonts[i]); + if (s) { + // Strip i18n stuff: + char *p = strchr(s, ','); + if (p) + *p = 0; + // Make it user presentable: + s = strreplace(s, "\\", ""); // '-' is escaped + s = strreplace(s, "style=", ""); + FontNames->Append(s); // takes ownership of s + } + } + FcFontSetDestroy(fontset); + FcPatternDestroy(pat); + FcObjectSetDestroy(os); + FcFini(); + FontNames->Sort(); + } + return FontNames->Size() > 0; +} + +cString cFont::GetFontFileName(const char *FontName) +{ + cString FontFileName; + if (FontName) { + char *fn = strdup(FontName); + fn = strreplace(fn, ":", ":style="); + fn = strreplace(fn, "-", "\\-"); + FcInit(); + FcPattern *pat = FcNameParse((FcChar8 *)fn); + FcPatternAddBool(pat, FC_SCALABLE, FcTrue); + FcConfigSubstitute(NULL, pat, FcMatchPattern); + FcDefaultSubstitute(pat); + FcFontSet *fontset = FcFontSort(NULL, pat, FcFalse, NULL, NULL); + for (int i = 0; i < fontset->nfont; i++) { + FcBool scalable; + FcPatternGetBool(fontset->fonts[i], FC_SCALABLE, 0, &scalable); + if (scalable) { + FcChar8 *s = NULL; + FcPatternGetString(fontset->fonts[i], FC_FILE, 0, &s); + FontFileName = (char *)s; + break; + } + } + FcFontSetDestroy(fontset); + FcPatternDestroy(pat); + free(fn); + FcFini(); + } + return FontFileName; +} + // --- cTextWrapper ---------------------------------------------------------- cTextWrapper::cTextWrapper(void) |