From: Andreas Monzner Date: Sun, 29 Oct 2006 01:06:00 +0000 (+0000) Subject: fix displaying teletext subtitle characters > 0x80 X-Git-Tag: 2.6.0~2824 X-Git-Url: https://git.cweiske.de/enigma2.git/commitdiff_plain/1ac36b6e99c0b4196f4e9358c2810b9aba6ced33 fix displaying teletext subtitle characters > 0x80 --- diff --git a/lib/dvb/teletext.cpp b/lib/dvb/teletext.cpp index c96fbed9..ecfdb086 100644 --- a/lib/dvb/teletext.cpp +++ b/lib/dvb/teletext.cpp @@ -3,14 +3,79 @@ #include #include -/* - This is a very simple en300 706 telext decoder. - - It can only decode a single page at a time, thus it's only used - for subtitles. - - */ +// Try to map teletext characters into ISO-8859-1 charset +// Use similar looking or similar meaning characters when possible. + +// G0 and G2 national option table +// see table 33 in ETSI EN 300 706 +// use it with (triplet 1 bits 14-11)*(ctrl bits C12-14) + +unsigned char LatinNationalOptionSubsetsLookup[16*8] = +{ + 1, 4, 11, 5, 3, 8, 0, 1, + 7, 4, 11, 5, 3, 1, 0, 1, + 1, 4, 11, 5, 3, 8, 12, 1, + 1, 1, 1, 1, 1, 10, 1, 9, + 1, 4, 2, 6, 1, 1, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, // reserved + 1, 1, 1, 1, 1, 1, 12, 1, + 1, 1, 1, 1, 1, 1, 1, 1, // reserved + 1, 1, 1, 1, 3, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, // reserved + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, // reserved + 1, 1, 1, 1, 1, 1, 1, 1, // reserved + 1, 1, 1, 1, 1, 1, 1, 1, // reserved + 1, 1, 1, 1, 1, 1, 1, 1, // reserved + 1, 1, 1, 1, 1, 1, 1, 1 // reserved +}; + +unsigned char LatinNationalReplaceMap[128] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 8, + 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 0 +}; + +// latin national option subsets +// see table 36 in ETSI EN 300 706 + +unsigned char LatinNationalOptionSubsets[13*14] = { + 0, '#', 'u', 'c', 't', 'z', 'ý', 'í', 'r', 'é', 'á', 'e', 'ú', 's', // Slovak/Czech + 0, '£', '$', '@', '-', '½', '-', '|', '#', '-', '¼', '#', '¾', '÷', // English + 0, '#', 'õ', 'S', 'Ä', 'Ö', 'Z', 'Ü', 'Õ', 's', 'ä', 'ö', 'z', 'ü', // Estonian + 0, 'é', 'ï', 'à', 'ë', 'ê', 'ù', 'î', '#', 'è', 'â', 'ô', 'û', 'ç', // French + 0, '#', '$', '§', 'Ä', 'Ö', 'Ü', '^', '_', 'º', 'ä', 'ö', 'ü', 'ß', // German + 0, '£', '$', 'é', 'º', 'ç', '-', '|', '#', 'ù', 'à', 'ò', 'è', 'ì', // Italian + 0, '#', '$', 'S', 'e', 'e', 'Z', 'c', 'u', 's', 'a', 'u', 'z', 'i', // Lithuanian/Lettish + 0, '#', 'n', 'a', 'Z', 'S', 'L', 'c', 'ó', 'e', 'z', 's', 'l', 'z', // Polish + 0, 'ç', '$', 'i', 'á', 'é', 'í', 'ó', 'ú', '¿', 'ü', 'ñ', 'è', 'à', // Spanish/Portuguese + 0, '#', '¤', 'T', 'Â', 'S', 'A', 'Î', 'i', 't', 'â', 's', 'a', 'î', // Rumanian + 0, '#', 'Ë', 'C', 'C', 'Z', 'D', 'S', 'ë', 'c', 'c', 'z', 'd', 's', // Slovenian/Serbian/Croation + 0, '#', '¤', 'É', 'Ä', 'Ö', 'Å', 'Ü', '_', 'é', 'ä', 'ö', 'å', 'ü', // Finnish/Hungarian/Swedish + 0, 'T', 'g', 'I', 'S', 'Ö', 'Ç', 'Ü', 'G', 'i', 's', 'ö', 'ç', 'ü' // Turkish +}; + +unsigned char MapTeletextG0Latin1Char(int Gtriplet, int NatOpts, unsigned char inchar) +{ + int num = LatinNationalOptionSubsetsLookup[(Gtriplet&0xf)*(NatOpts&0x7)]; + unsigned char c = inchar&0x7f; + unsigned char cc = LatinNationalReplaceMap[c]; + if(cc) + return LatinNationalOptionSubsets[num*cc]; + else + return c; +} +// This is a very simple en300 706 telext decoder. +// It can only decode a single page at a time, thus it's only used +// for subtitles. + DEFINE_REF(eDVBTeletextParser); /* we asumme error free transmission! */ @@ -118,6 +183,12 @@ void eDVBTeletextParser::processPESPacket(__u8 *pkt, int len) break; } + if (data_unit_id != 0x03) + { + /* eDebug("non subtitle data unit id %d", data_unit_id); */ + break; + } + unsigned char line_offset = *p++; len--; unsigned char framing_code = *p++; len--; @@ -294,13 +365,23 @@ void eDVBTeletextParser::addSubtitleString(int color, std::string string) // eDebug("add subtitle string: %s, col %d", string.c_str(), color); int force_cell = 0; - + if (string.substr(0, 2) == "- ") { string = string.substr(2); force_cell = 1; } + int len = string.length(); + int idx = 0; + + while (idx < len) + { + if (string[idx] >= 0x20) + string[idx] = MapTeletextG0Latin1Char(0, (m_C >> 11), string[idx]); + ++idx; + } + // eDebug("color %d, m_subtitle_color %d", color, m_subtitle_color); gRGB rgbcol((color & 1) ? 255 : 128, (color & 2) ? 255 : 128, (color & 4) ? 255 : 128); if ((color != m_subtitle_color || force_cell) && !m_subtitle_text.empty() && ((color == -2) || !string.empty())) diff --git a/lib/dvb/teletext.h b/lib/dvb/teletext.h index 821a9226..8c5dfa3e 100644 --- a/lib/dvb/teletext.h +++ b/lib/dvb/teletext.h @@ -10,6 +10,7 @@ struct eDVBTeletextSubtitlePageElement { gRGB m_color; std::string m_text; + eRect m_area; eDVBTeletextSubtitlePageElement(const gRGB &color, const std::string &text) : m_color(color), m_text(text) { diff --git a/lib/gui/esubtitle.cpp b/lib/gui/esubtitle.cpp index af96ef8c..729f6b4d 100644 --- a/lib/gui/esubtitle.cpp +++ b/lib/gui/esubtitle.cpp @@ -1,5 +1,6 @@ #include #include +#include /* ok, here's much room for improvements. @@ -18,12 +19,35 @@ eSubtitleWidget::eSubtitleWidget(eWidget *parent) CONNECT(m_hide_subtitles_timer.timeout, eSubtitleWidget::clearPage); } +#define startX 50 void eSubtitleWidget::setPage(const eDVBTeletextSubtitlePage &p) { m_page = p; m_page_ok = 1; - m_hide_subtitles_timer.start(5000, true); - invalidate(); // FIXME + invalidate(m_visible_region); // invalidate old visible regions + m_visible_region.rects.clear(); + + int elements = m_page.m_elements.size(); + if (elements) + { + int startY = elements > 1 + ? size().height() / 2 + : size().height() / 3 * 2; + int width = size().width() - startX * 2; + int height = size().height() - startY; + int size_per_element = height / (elements ? elements : 1); + for (int i=0; i::iterator it(m_dvb_page.m_regions.begin()); it != m_dvb_page.m_regions.end(); ++it) m_visible_region.rects.push_back(eRect(it->m_position, it->m_pixmap->size())); m_dvb_page_ok = 1; - m_hide_subtitles_timer.start(5000, true); + m_hide_subtitles_timer.start(7500, true); invalidate(m_visible_region); // invalidate new regions } @@ -59,22 +83,23 @@ int eSubtitleWidget::event(int event, void *data, void *data2) getStyle(style); eWidget::event(event, data, data2); - ePtr font = new gFont("Regular", 30); + ePtr font = new gFont("Regular", 38); painter.setFont(font); -/* if (!m_page_ok && !m_dvb_page_ok) - painter.renderText(eRect(ePoint(0, 0), size()), "waiting for subtitles...", gPainter::RT_WRAP); - else */if (m_page_ok) + if (m_page_ok) { int elements = m_page.m_elements.size(); - int height = size().height(); - int size_per_element = height / (elements ? elements : 1); for (int i=0; i