summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2007-06-15 12:24:06 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2007-06-15 12:24:06 +0200
commit3224fffe8751732ec3304d8f540e832929933f27 (patch)
treee3711af3cc5769aeec6d6bf612da1f5f515fba94
parent824b974b812903dea368f3a1b8ba70a40cdc96f7 (diff)
downloadvdr-3224fffe8751732ec3304d8f540e832929933f27.tar.gz
vdr-3224fffe8751732ec3304d8f540e832929933f27.tar.bz2
Implemented UTF-8 handling in skincurses
-rw-r--r--PLUGINS/src/skincurses/HISTORY4
-rw-r--r--PLUGINS/src/skincurses/Makefile4
-rw-r--r--PLUGINS/src/skincurses/skincurses.c26
-rw-r--r--tools.c14
-rw-r--r--tools.h7
5 files changed, 37 insertions, 18 deletions
diff --git a/PLUGINS/src/skincurses/HISTORY b/PLUGINS/src/skincurses/HISTORY
index 96ff93c8..3204f204 100644
--- a/PLUGINS/src/skincurses/HISTORY
+++ b/PLUGINS/src/skincurses/HISTORY
@@ -39,3 +39,7 @@ VDR Plugin 'skincurses' Revision History
2006-09-10: Version 0.0.8
- The size of the OSD is now adjusted to the size of the console window.
+
+2007-06-15: Version 0.1.0
+
+- Implemented UTF-8 handling.
diff --git a/PLUGINS/src/skincurses/Makefile b/PLUGINS/src/skincurses/Makefile
index 4f83614f..9ab37cee 100644
--- a/PLUGINS/src/skincurses/Makefile
+++ b/PLUGINS/src/skincurses/Makefile
@@ -1,7 +1,7 @@
#
# Makefile for a Video Disk Recorder plugin
#
-# $Id: Makefile 1.7 2006/09/09 12:38:35 kls Exp $
+# $Id: Makefile 1.8 2007/06/15 12:23:00 kls Exp $
# The official name of this plugin.
# This name will be used in the '-P...' option of VDR to load the plugin.
@@ -66,7 +66,7 @@ $(DEPFILE): Makefile
all: libvdr-$(PLUGIN).so
libvdr-$(PLUGIN).so: $(OBJS)
- $(CXX) $(CXXFLAGS) -shared $(OBJS) -lncurses -o $@
+ $(CXX) $(CXXFLAGS) -shared $(OBJS) -lncursesw -o $@
@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
dist: clean
diff --git a/PLUGINS/src/skincurses/skincurses.c b/PLUGINS/src/skincurses/skincurses.c
index 243ddcec..f9a030f4 100644
--- a/PLUGINS/src/skincurses/skincurses.c
+++ b/PLUGINS/src/skincurses/skincurses.c
@@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
- * $Id: skincurses.c 1.11 2006/09/10 14:23:55 kls Exp $
+ * $Id: skincurses.c 1.12 2007/06/15 12:23:31 kls Exp $
*/
#include <ncurses.h>
@@ -11,7 +11,7 @@
#include <vdr/plugin.h>
#include <vdr/skins.h>
-static const char *VERSION = "0.0.8";
+static const char *VERSION = "0.1.0";
static const char *DESCRIPTION = "A text only skin";
static const char *MAINMENUENTRY = NULL;
@@ -19,12 +19,10 @@ static const char *MAINMENUENTRY = NULL;
class cCursesFont : public cFont {
public:
- cCursesFont(void): cFont(NULL) {}
- virtual int Width(unsigned char c) const { return 1; }
- virtual int Width(const char *s) const { return s ? strlen(s) : 0; }
- virtual int Height(unsigned char c) const { return 1; }
- virtual int Height(const char *s) const { return 1; }
+ virtual int Width(uint c) const { return 1; }
+ virtual int Width(const char *s) const { return s ? Utf8NumSyms(s) : 0; }
virtual int Height(void) const { return 1; }
+ virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const {}
};
static const cCursesFont Font;
@@ -135,6 +133,8 @@ void cCursesOsd::RestoreRegion(void)
void cCursesOsd::DrawText(int x, int y, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font, int Width, int Height, int Alignment)
{
+ if (!s)
+ return;
int w = Font->Width(s);
int h = Font->Height();
if (Width || Height) {
@@ -253,7 +253,7 @@ void cSkinCursesDisplayChannel::Flush(void)
{
if (!message) {
cString date = DayDateTime();
- osd->DrawText(OsdWidth - strlen(date), 0, date, clrWhite, clrBackground, &Font);
+ osd->DrawText(OsdWidth - Utf8NumSyms(date), 0, date, clrWhite, clrBackground, &Font);
}
osd->Flush();
}
@@ -388,7 +388,7 @@ void cSkinCursesDisplayMenu::SetEvent(const cEvent *Event)
if (Event->Vps() && Event->Vps() != Event->StartTime()) {
char *buffer;
asprintf(&buffer, " VPS: %s", *Event->GetVpsString());
- osd->DrawText(OsdWidth - strlen(buffer), y, buffer, clrBlack, clrYellow, &Font);
+ osd->DrawText(OsdWidth - Utf8NumSyms(buffer), y, buffer, clrBlack, clrYellow, &Font);
free(buffer);
}
y += ts.Height();
@@ -443,7 +443,7 @@ void cSkinCursesDisplayMenu::SetText(const char *Text, bool FixedFont)
void cSkinCursesDisplayMenu::Flush(void)
{
cString date = DayDateTime();
- osd->DrawText(OsdWidth - strlen(date) - 2, 0, date, clrBlack, clrCyan, &Font);
+ osd->DrawText(OsdWidth - Utf8NumSyms(date) - 2, 0, date, clrBlack, clrCyan, &Font);
osd->Flush();
}
@@ -508,12 +508,12 @@ void cSkinCursesDisplayReplay::SetProgress(int Current, int Total)
void cSkinCursesDisplayReplay::SetCurrent(const char *Current)
{
- osd->DrawText(0, 2, Current, clrWhite, clrBackground, &Font, strlen(Current) + 3);
+ osd->DrawText(0, 2, Current, clrWhite, clrBackground, &Font, Utf8NumSyms(Current) + 3);
}
void cSkinCursesDisplayReplay::SetTotal(const char *Total)
{
- osd->DrawText(OsdWidth - strlen(Total), 2, Total, clrWhite, clrBackground, &Font);
+ osd->DrawText(OsdWidth - Utf8NumSyms(Total), 2, Total, clrWhite, clrBackground, &Font);
}
void cSkinCursesDisplayReplay::SetJump(const char *Jump)
@@ -569,7 +569,7 @@ void cSkinCursesDisplayVolume::SetVolume(int Current, int Total, bool Mute)
}
else {
const char *Prompt = tr("Volume ");
- int l = strlen(Prompt);
+ int l = Utf8NumSyms(Prompt);
int p = (OsdWidth - l) * Current / Total;
osd->DrawText(0, 0, Prompt, clrGreen, clrBackground, &Font);
osd->DrawRectangle(l, 0, l + p - 1, 0, clrGreen);
diff --git a/tools.c b/tools.c
index a6af97a6..4498e6ae 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 1.123 2007/06/09 14:21:21 kls Exp $
+ * $Id: tools.c 1.124 2007/06/15 12:20:40 kls Exp $
*/
#include "tools.h"
@@ -649,6 +649,18 @@ int Utf8SymChars(const char *s, int Symbols)
return n;
}
+int Utf8NumSyms(const char *s)
+{
+ if (cCharSetConv::SystemCharacterTable())
+ return strlen(s);
+ int n = 0;
+ while (*s) {
+ s += Utf8CharLen(s);
+ n++;
+ }
+ return n;
+}
+
int Utf8ToArray(const char *s, uint *a, int Size)
{
int n = 0;
diff --git a/tools.h b/tools.h
index 5d048076..3256c352 100644
--- a/tools.h
+++ b/tools.h
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.h 1.98 2007/06/10 08:46:23 kls Exp $
+ * $Id: tools.h 1.99 2007/06/15 12:18:37 kls Exp $
*/
#ifndef __TOOLS_H
@@ -92,7 +92,10 @@ int Utf8CharSet(uint c, char *s = NULL);
///< is given, only the number of bytes is returned and nothing is copied.
int Utf8SymChars(const char *s, int Symbols);
///< Returns the number of character bytes at the beginning of the given
- ///< string that form at most the given number of UTF-8 Symbols.
+ ///< string that form at most the given number of UTF-8 symbols.
+int Utf8NumSyms(const char *s);
+ ///< Returns the number of UTF-8 symbols formed by the given string of
+ ///< character bytes.
int Utf8ToArray(const char *s, uint *a, int Size);
///< Converts the given character bytes (including the terminating 0) into an
///< array of UTF-8 symbols of the given Size. Returns the number of symbols