[Subtitle] added rewrap option for TTX subtitle.
authorsmlee <smlee@dev3>
Tue, 26 Apr 2016 07:42:42 +0000 (16:42 +0900)
committersmlee <smlee@dev3>
Tue, 26 Apr 2016 08:32:41 +0000 (17:32 +0900)
data/setup.xml
lib/dvb/teletext.cpp
lib/gui/esubtitle.cpp
lib/python/Components/UsageConfig.py
lib/python/Screens/AudioSelection.py

index 6100565..5ce6b62 100755 (executable)
                        <item level="2" text="Subtitle alignment" description="Configure the horizontal alignment of the subtitles.">config.subtitles.subtitle_alignment</item>
                        <item level="2" text="Subtitle position" description="Configure the vertical position of the subtitles, measured from the bottom of the screen.">config.subtitles.subtitle_position</item>
                        <item level="2" text="Center DVB subtitles" description="When enabled, graphical DVB subtitles will be centered horizontally.">config.subtitles.dvb_subtitles_centered</item>
+                       <item level="2" text="Rewrap subtitles" description="When enabled, reformat subtitles to match the width of the screen.">config.subtitles.subtitle_rewrap</item>
                        <item level="2" text="Subtitle delay when timing lacks" description="Configure the subtitle delay when timing information is not available.">config.subtitles.subtitle_noPTSrecordingdelay</item>
                        <item level="2" text="Subtitle delay when timing is bad" description="Configure an additional delay to improve subtitle synchronisation.">config.subtitles.subtitle_bad_timing_delay</item>
                        <item level="2" text="External subtitle switch fonts" description="Configure if the subtitle should switch between normal, italic, bold and bolditalic">config.subtitles.pango_subtitle_fontswitch</item>
                        <item level="2" text="External subtitle dialog colorisation" description="Replace `- ` in dialogs with colored text per speaker (like teletext subtitles for the hearing impaired)">config.subtitles.colourise_dialogs</item>
-                       <item level="2" text="Rewrap external subtitles" description="When enabled, reformat subtitles to match the width of the screen.">config.subtitles.subtitle_rewrap</item>
                        <item level="2" text="Delay for external subtitles" description="Configure an additional delay to improve external subtitle synchronisation.">config.subtitles.pango_subtitles_delay</item>
                        <item level="2" text="Set fps for external subtitles" description="Can be used for different fps between external subtitles and video.">config.subtitles.pango_subtitles_fps</item>
                        <item level="2" text="Automatically turn on external subtitles" description="When enabled, external subtitles will be always turned on for playback movie.">config.subtitles.pango_autoturnon</item>
index 40650c0..6a3daa8 100644 (file)
@@ -659,6 +659,14 @@ void eDVBTeletextParser::connectNewPage(const Slot1<void, const eDVBTeletextSubt
 
 void eDVBTeletextParser::addSubtitleString(int color, std::string string, int source_line)
 {
+#if 1
+       const gRGB pal[8] = { gRGB(102, 102, 102), gRGB(255, 0, 0), gRGB(0, 255, 0), gRGB(255, 255, 0),
+               gRGB(102, 102, 255), gRGB(255, 0, 255), gRGB(0, 255, 255), gRGB(255, 255, 255) };
+
+       if (string.empty()) return;
+
+       m_subtitle_page.m_elements.push_back(eDVBTeletextSubtitlePageElement(pal[color], string, source_line));
+#else
 //     eDebug("(%d)add subtitle string: %s, col %d", m_Y, string.c_str(), color);
        int force_cell = 0;
 
@@ -689,6 +697,7 @@ void eDVBTeletextParser::addSubtitleString(int color, std::string string, int so
                        m_subtitle_color = color;
                m_subtitle_text += string;
        }
+#endif
 }
 
 void eDVBTeletextParser::sendSubtitlePage()
index 00bf12d..be8ede6 100644 (file)
@@ -26,6 +26,7 @@ eSubtitleWidget::eSubtitleWidget(eWidget *parent)
 }
 
 #define startX 50
+#define paddingY 10
 void eSubtitleWidget::setPage(const eDVBTeletextSubtitlePage &p)
 {
        eDVBTeletextSubtitlePage newpage = p;
@@ -38,13 +39,13 @@ void eSubtitleWidget::setPage(const eDVBTeletextSubtitlePage &p)
        unsigned int elements = newpage.m_elements.size();
        if (elements)
        {
-               int startY = elements > 1
-                       ? size().height() / 2
-                       : size().height() / 3 * 2;
+               int fontsize = ePythonConfigQuery::getConfigIntValue("config.subtitles.subtitle_fontsize", 34) * getDesktop(0)->size().width()/1280;
+               int startY = size().height() - (size().height() / 3 * 1) / 2 - ((fontsize + paddingY) * elements) / 2;
                int width = size().width() - startX * 2;
                int height = size().height() - startY;
-               int size_per_element = height / (elements ? elements : 1);
+               int size_per_element = fontsize + paddingY;
                bool original_position = ePythonConfigQuery::getConfigBoolValue("config.subtitles.subtitle_original_position");
+               bool rewrap = ePythonConfigQuery::getConfigBoolValue("config.subtitles.subtitle_rewrap");
                gRGB color;
                bool original_colors = false;
                switch (ePythonConfigQuery::getConfigIntValue("config.subtitles.subtitle_fontcolor", 0))
@@ -96,8 +97,11 @@ void eSubtitleWidget::setPage(const eDVBTeletextSubtitlePage &p)
                        if (line != newpage.m_elements[i].m_source_line)
                        {
                                line = newpage.m_elements[i].m_source_line;
-                               m_page.m_elements.push_back(eDVBTeletextSubtitlePageElement(color, "", line));
-                               currentelement++;
+                               if (!rewrap)
+                               {
+                                       m_page.m_elements.push_back(eDVBTeletextSubtitlePageElement(color, "", line));
+                                       currentelement++;
+                               }
                        }
                        m_page.m_elements[currentelement].m_text += newpage.m_elements[i].m_text;
                }
@@ -108,11 +112,7 @@ void eSubtitleWidget::setPage(const eDVBTeletextSubtitlePage &p)
                        if (!original_position)
                        {
                                int lowerborder = ePythonConfigQuery::getConfigIntValue("config.subtitles.subtitle_position", 50);
-                               if (lowerborder == 0)
-                                       lowerborder -= 100 * getDesktop(0)->size().height()/720;
-                               else if (lowerborder == 50)
-                                       lowerborder -= 50 * getDesktop(0)->size().height()/720;
-                               area.setTop(size_per_element * i + startY - lowerborder);
+                               area.setTop(size().height() - size_per_element * (m_page.m_elements.size() - i) - lowerborder * getDesktop(0)->size().height()/720);
                        }
                        else
                                area.setTop(size_per_element * i + startY);
@@ -318,7 +318,6 @@ int eSubtitleWidget::event(int event, void *data, void *data2)
                                int bg_r, bg_g, bg_b, bg_a;
                                if (ePythonConfigQuery::getConfigIntValue("config.subtitles.subtitle_bgopacity") < 0xFF)
                                {
-                                       unsigned int padding = 10;
                                        eTextPara *para = new eTextPara(area);
                                        para->setFont(subtitleStyles[Subtitle_TTX].font);
                                        para->renderString(element.m_text.c_str(), RS_WRAP);
@@ -327,14 +326,14 @@ int eSubtitleWidget::event(int event, void *data, void *data2)
                                        int bgboxWidth = bgbox.width();
                                        int bgboxHeight = bgbox.height();
                                        if (alignmentValue == "left")
-                                               bgbox.setLeft(area.left() - padding - borderwidth);
+                                               bgbox.setLeft(area.left() - paddingY - borderwidth);
                                        else if (alignmentValue == "right")
-                                               bgbox.setLeft(area.left() + area.width() - bgboxWidth - padding - borderwidth);
+                                               bgbox.setLeft(area.left() + area.width() - bgboxWidth - paddingY - borderwidth);
                                        else
-                                               bgbox.setLeft(area.left() + area.width() / 2 - bgboxWidth / 2 - padding - borderwidth);
-                                       bgbox.setTop(area.top() + area.height() / 2 - bgboxHeight / 2 - padding * 2 - borderwidth);
-                                       bgbox.setWidth(bgboxWidth + padding * 2 + borderwidth * 2);
-                                       bgbox.setHeight(bgboxHeight + padding * 3 + borderwidth * 2);
+                                               bgbox.setLeft(area.left() + area.width() / 2 - bgboxWidth / 2 - paddingY - borderwidth);
+                                       bgbox.setTop(area.top());
+                                       bgbox.setWidth(bgboxWidth + paddingY * 2 + borderwidth * 2);
+                                       bgbox.setHeight(area.height());
 
                                        switch (ePythonConfigQuery::getConfigIntValue("config.subtitles.subtitle_bgcolor", 0))
                                        {
index fc7ae83..d262448 100644 (file)
@@ -187,7 +187,7 @@ def InitUsageConfig():
                ("150", "50%")])
        config.subtitles.subtitle_original_position = ConfigYesNo(default = True)
        config.subtitles.subtitle_alignment = ConfigSelection(choices = [("left", _("left")), ("center", _("center")), ("right", _("right"))], default = "center")
-       config.subtitles.subtitle_position = ConfigSelection( choices = ["0", "50", "100", "150", "200", "250", "300", "350", "400", "450", "500", "550", "600"], default = "50")
+       config.subtitles.subtitle_position = ConfigSelection( choices = ["0", "50", "100", "150", "200", "250", "300", "350", "400", "450", "500", "550", "600"], default = "100")
 
        config.subtitles.dvb_subtitles_centered = ConfigYesNo(default = False)
 
index 537aab4..715d922 100755 (executable)
@@ -379,6 +379,7 @@ class QuickSubtitlesConfigMenu(ConfigListScreen, Screen):
                                getConfigMenuItem("config.subtitles.subtitle_original_position"),
                                getConfigMenuItem("config.subtitles.subtitle_alignment"),
                                getConfigMenuItem("config.subtitles.subtitle_position"),
+                               getConfigMenuItem("config.subtitles.subtitle_rewrap"),
                                getConfigMenuItem("config.subtitles.subtitle_bad_timing_delay"),
                                getConfigMenuItem("config.subtitles.subtitle_noPTSrecordingdelay"),
                        ]