Components/-{ChoiceList.py, EpgList.py, FileList.py, MediaPlayer.py, ParentalControl...
[enigma2.git] / lib / gui / esubtitle.cpp
index ca5c20d789fee53540f9b50683ded51bb6cdd591..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))
 {
@@ -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());
-               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);
@@ -108,9 +113,18 @@ void eSubtitleWidget::clearPage()
        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_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()));
+
+       if (pixmap->size().width() && pixmap->size().height())
+               changed.scale(size().width(), pixmap->size().width(), size().height(), pixmap->size().height());
+       
        invalidate(changed);
 }
 
@@ -127,46 +141,49 @@ int eSubtitleWidget::event(int event, void *data, void *data2)
                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();
-                       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;
-                               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.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();
-                       ePtr<gFont> font = new gFont("Regular", 38);
+                       subfont_t face;
+
                        for (int i=0; i<elements; ++i)
                        {
+                               face = Subtitle_Regular;
                                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':
-                                               eDebug("found italic");
-                                               font = new gFont("LCD", 40);
+                                               face = Subtitle_Italic;
                                                break;
                                        case 'b':
-                                               eDebug("found bold");
-                                               font = new gFont("Replacement", 40);
-                                               break;
-                                       default:
+                                               face = Subtitle_Bold;
                                                break;
                                        }
                                        text = text.substr(3, text.length()-7);
@@ -174,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;", "&");
-                               painter.setFont(font);          
+                               painter.setFont(subtitleStyles[face].font);
                                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.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.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;
        }
@@ -195,3 +219,13 @@ int eSubtitleWidget::event(int event, void *data, void *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;
+}
+