Components/-{ChoiceList.py, EpgList.py, FileList.py, MediaPlayer.py, ParentalControl...
[enigma2.git] / lib / gui / esubtitle.cpp
index 085a749a6fde71fdb0264160bc18ee161ab77de0..594ed8a8630082f44870189d8ded43339953bf99 100644 (file)
@@ -10,6 +10,8 @@
                ....
        */      
 
                ....
        */      
 
+eSubtitleWidget::eSubtitleStyle eSubtitleWidget::subtitleStyles[Subtitle_MAX];
+
 eSubtitleWidget::eSubtitleWidget(eWidget *parent)
        : eWidget(parent), m_hide_subtitles_timer(eTimer::create(eApp))
 {
 eSubtitleWidget::eSubtitleWidget(eWidget *parent)
        : eWidget(parent), m_hide_subtitles_timer(eTimer::create(eApp))
 {
@@ -60,7 +62,10 @@ void eSubtitleWidget::setPage(const eDVBSubtitlePage &p)
        for (std::list<eDVBSubtitleRegion>::iterator it(m_dvb_page.m_regions.begin()); it != m_dvb_page.m_regions.end(); ++it)
        {
                eDebug("add %d %d %d %d", it->m_position.x(), it->m_position.y(), it->m_pixmap->size().width(), it->m_pixmap->size().height());
        for (std::list<eDVBSubtitleRegion>::iterator it(m_dvb_page.m_regions.begin()); it != m_dvb_page.m_regions.end(); ++it)
        {
                eDebug("add %d %d %d %d", it->m_position.x(), it->m_position.y(), it->m_pixmap->size().width(), it->m_pixmap->size().height());
-               m_visible_region.rects.push_back(eRect(it->m_position, it->m_pixmap->size()));
+               eDebug("disp width %d, disp height %d", p.m_display_size.width(), p.m_display_size.height());
+               eRect r = eRect(it->m_position, it->m_pixmap->size());
+               r.scale(size().width(), p.m_display_size.width(), size().height(), p.m_display_size.height());
+               m_visible_region.rects.push_back(r);
        }
        m_dvb_page_ok = 1;
        m_hide_subtitles_timer->start(7500, true);
        }
        m_dvb_page_ok = 1;
        m_hide_subtitles_timer->start(7500, true);
@@ -108,19 +113,19 @@ void eSubtitleWidget::clearPage()
        m_visible_region.rects.clear();
 }
 
        m_visible_region.rects.clear();
 }
 
-void eSubtitleWidget::setPixmap(ePtr<gPixmap> &pixmap, gRegion changed)
+void eSubtitleWidget::setPixmap(ePtr<gPixmap> &pixmap, gRegion changed, eRect pixmap_dest)
 {
        m_pixmap = pixmap;
 {
        m_pixmap = pixmap;
-       invalidate(changed);
-}
+       m_pixmap_dest = pixmap_dest; /* this is in a virtual 720x576 cage */
+       
+               /* incoming "changed" regions are relative to the physical pixmap area, so they have to be scaled to the virtual pixmap area, then to the screen */
+       changed.scale(m_pixmap_dest.width(), 720, m_pixmap_dest.height(), 576);
+       changed.moveBy(ePoint(m_pixmap_dest.x(), m_pixmap_dest.y()));
 
 
-std::string eSubtitleWidget::replace_all(const std::string &in, const std::string &entity, const std::string &symbol)
-{
-       std::string out = in;
-       std::string::size_type loc = 0;
-       while (( loc = out.find(entity, loc)) != std::string::npos )
-       out.replace(loc, entity.length(), symbol);
-       return out;
+       if (pixmap->size().width() && pixmap->size().height())
+               changed.scale(size().width(), pixmap->size().width(), size().height(), pixmap->size().height());
+       
+       invalidate(changed);
 }
 
 int eSubtitleWidget::event(int event, void *data, void *data2)
 }
 
 int eSubtitleWidget::event(int event, void *data, void *data2)
@@ -136,46 +141,49 @@ int eSubtitleWidget::event(int event, void *data, void *data2)
                eWidget::event(event, data, data2);
 
                if (m_pixmap)
                eWidget::event(event, data, data2);
 
                if (m_pixmap)
-                       painter.blit(m_pixmap, ePoint(0,0));
-               else if (m_page_ok)
+               {
+                       eRect r = m_pixmap_dest;
+                       r.scale(size().width(), 720, size().height(), 576);
+                       painter.blitScale(m_pixmap, r);
+               } else if (m_page_ok)
                {
                        int elements = m_page.m_elements.size();
                {
                        int elements = m_page.m_elements.size();
-                       ePtr<gFont> font = new gFont("Regular", 38);
-                       painter.setFont(font);
+                       painter.setFont(subtitleStyles[Subtitle_TTX].font);
                        for (int i=0; i<elements; ++i)
                        {
                                eDVBTeletextSubtitlePageElement &element = m_page.m_elements[i];
                                eRect &area = element.m_area;
                                eRect shadow = area;
                        for (int i=0; i<elements; ++i)
                        {
                                eDVBTeletextSubtitlePageElement &element = m_page.m_elements[i];
                                eRect &area = element.m_area;
                                eRect shadow = area;
-                               shadow.moveBy(3,3);
-                               painter.setForegroundColor(gRGB(0,0,0));
+                               shadow.moveBy(subtitleStyles[Subtitle_TTX].shadow_offset);
+                               painter.setForegroundColor(subtitleStyles[Subtitle_TTX].shadow_color);
                                painter.renderText(shadow, element.m_text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
                                painter.renderText(shadow, element.m_text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
-                               painter.setForegroundColor(element.m_color);
+                               if ( !subtitleStyles[Subtitle_TTX].have_foreground_color )
+                                       painter.setForegroundColor(element.m_color);
+                               else
+                                       painter.setForegroundColor(subtitleStyles[Subtitle_TTX].foreground_color);
                                painter.renderText(area, element.m_text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
                        }
                }
                else if (m_pango_page_ok)
                {
                        int elements = m_pango_page.m_elements.size();
                                painter.renderText(area, element.m_text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
                        }
                }
                else if (m_pango_page_ok)
                {
                        int elements = m_pango_page.m_elements.size();
-                       ePtr<gFont> font = new gFont("Regular", 38);
+                       subfont_t face;
+
                        for (int i=0; i<elements; ++i)
                        {
                        for (int i=0; i<elements; ++i)
                        {
+                               face = Subtitle_Regular;
                                ePangoSubtitlePageElement &element = m_pango_page.m_elements[i];
                                ePangoSubtitlePageElement &element = m_pango_page.m_elements[i];
-                               std::string text = element.m_pango_line;                                
+                               std::string text = element.m_pango_line;
                                std::string::size_type loc = text.find("<", 0 );
                                if ( loc != std::string::npos )
                                {
                                        switch (char(text.at(1)))
                                        {
                                        case 'i':
                                std::string::size_type loc = text.find("<", 0 );
                                if ( loc != std::string::npos )
                                {
                                        switch (char(text.at(1)))
                                        {
                                        case 'i':
-                                               eDebug("found italic");
-                                               font = new gFont("LCD", 40);
+                                               face = Subtitle_Italic;
                                                break;
                                        case 'b':
                                                break;
                                        case 'b':
-                                               eDebug("found bold");
-                                               font = new gFont("Replacement", 40);
-                                               break;
-                                       default:
+                                               face = Subtitle_Bold;
                                                break;
                                        }
                                        text = text.substr(3, text.length()-7);
                                                break;
                                        }
                                        text = text.substr(3, text.length()-7);
@@ -183,20 +191,27 @@ int eSubtitleWidget::event(int event, void *data, void *data2)
                                text = replace_all(text, "&apos;", "'");
                                text = replace_all(text, "&quot;", "\"");
                                text = replace_all(text, "&amp;", "&");
                                text = replace_all(text, "&apos;", "'");
                                text = replace_all(text, "&quot;", "\"");
                                text = replace_all(text, "&amp;", "&");
-                               painter.setFont(font);          
+                               painter.setFont(subtitleStyles[face].font);
                                eRect &area = element.m_area;
                                eRect shadow = area;
                                eRect &area = element.m_area;
                                eRect shadow = area;
-                               shadow.moveBy(3,3);
-                               painter.setForegroundColor(gRGB(0,0,0));
+                               shadow.moveBy(subtitleStyles[face].shadow_offset);
+                               painter.setForegroundColor(subtitleStyles[face].shadow_color);
                                painter.renderText(shadow, text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
                                painter.renderText(shadow, text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
-                               painter.setForegroundColor(element.m_color);
+                               if ( !subtitleStyles[face].have_foreground_color && element.m_have_color )
+                                       painter.setForegroundColor(element.m_color);
+                               else
+                                       painter.setForegroundColor(subtitleStyles[face].foreground_color);
                                painter.renderText(area, text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
                        }
                }
                else if (m_dvb_page_ok)
                {
                        for (std::list<eDVBSubtitleRegion>::iterator it(m_dvb_page.m_regions.begin()); it != m_dvb_page.m_regions.end(); ++it)
                                painter.renderText(area, text, gPainter::RT_WRAP|gPainter::RT_VALIGN_CENTER|gPainter::RT_HALIGN_CENTER);
                        }
                }
                else if (m_dvb_page_ok)
                {
                        for (std::list<eDVBSubtitleRegion>::iterator it(m_dvb_page.m_regions.begin()); it != m_dvb_page.m_regions.end(); ++it)
-                               painter.blit(it->m_pixmap, it->m_position);
+                       {
+                               eRect r = eRect(it->m_position, it->m_pixmap->size());
+                               r.scale(size().width(), m_dvb_page.m_display_size.width(), size().height(),  m_dvb_page.m_display_size.height());
+                               painter.blitScale(it->m_pixmap, r);
+                       }
                }
                return 0;
        }
                }
                return 0;
        }
@@ -204,3 +219,13 @@ int eSubtitleWidget::event(int event, void *data, void *data2)
                return eWidget::event(event, data, data2);
        }
 }
                return eWidget::event(event, data, data2);
        }
 }
+
+void eSubtitleWidget::setFontStyle(subfont_t face, gFont *font, int haveColor, const gRGB &col, const gRGB &shadowCol, const ePoint &shadowOffset)
+{
+       subtitleStyles[face].font = font;
+       subtitleStyles[face].have_foreground_color = haveColor;
+       subtitleStyles[face].foreground_color = col;
+       subtitleStyles[face].shadow_color = shadowCol;
+       subtitleStyles[face].shadow_offset = shadowOffset;
+}
+