2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "DVDSubtitleTagMicroDVD.h"
22 #include "DVDCodecs/Overlay/DVDOverlayText.h"
24 void CDVDSubtitleTagMicroDVD::ConvertLine(CDVDOverlayText* pOverlay, const char* line, int len)
27 strUTF8.assign(line, len);
29 m_flag[FLAG_BOLD] = 0;
30 m_flag[FLAG_ITALIC] = 0;
31 m_flag[FLAG_COLOR] = 0;
33 int machine_status = 1;
36 while (machine_status > 0)
38 if (machine_status == 1)
40 if (strUTF8[pos] == '{')
43 if (((pos2 = strUTF8.find(':', pos)) != CStdString::npos) && \
44 ((pos3 = strUTF8.find('}', pos2)) != CStdString::npos))
46 CStdString tagName = strUTF8.substr(pos + 1, pos2 - pos - 1);
47 CStdString tagValue = strUTF8.substr(pos2 + 1, pos3 - pos2 - 1);
49 strUTF8.erase(pos, pos3 - pos + 1);
50 if ((tagName == "Y") || (tagName == "y"))
52 if ((tagValue == "b") && (m_flag[FLAG_BOLD] == 0))
54 m_flag[FLAG_BOLD] = (tagName == "Y")?TAG_ALL_LINE:TAG_ONE_LINE;
55 strUTF8.insert(pos, "[B]");
58 else if ((tagValue == "i") && (m_flag[FLAG_ITALIC] == 0))
60 m_flag[FLAG_ITALIC] = (tagName == "Y")?TAG_ALL_LINE:TAG_ONE_LINE;
61 strUTF8.insert(pos, "[I]");
65 else if ((tagName == "C") || (tagName == "c"))
67 if ((tagValue[0] == '$') && (tagValue.size() == 7))
70 for( int i=1 ; i<7 ; i++ )
72 char temp = tagValue[i];
73 if( !(('0' <= temp && temp <= '9') ||
74 ('a' <= temp && temp <= 'f') ||
75 ('A' <= temp && temp <= 'F') ))
81 if( bHex && (m_flag[FLAG_COLOR] == 0))
83 CStdString tempColorTag = "[COLOR ";
85 tempColorTag += tagValue.substr(1, 6);
87 m_flag[FLAG_COLOR] = (tagName == "C")?TAG_ALL_LINE:TAG_ONE_LINE;
88 strUTF8.insert(pos, tempColorTag);
89 pos += tempColorTag.length();
97 else if (strUTF8[pos] == '/')
99 if (m_flag[FLAG_ITALIC] == 0)
101 m_flag[FLAG_ITALIC] = TAG_ONE_LINE;
102 strUTF8.replace(pos, 1, "[I]");
106 strUTF8.erase(pos, 1);
111 else if (machine_status == 2)
114 if ((pos4= strUTF8.find('|', pos)) != CStdString::npos)
117 if (m_flag[FLAG_BOLD] == TAG_ONE_LINE)
119 m_flag[FLAG_BOLD] = 0;
120 strUTF8.insert(pos, "[/B]");
123 if (m_flag[FLAG_ITALIC] == TAG_ONE_LINE)
125 m_flag[FLAG_ITALIC] = 0;
126 strUTF8.insert(pos, "[/I]");
129 if (m_flag[FLAG_COLOR] == TAG_ONE_LINE)
131 m_flag[FLAG_COLOR] = 0;
132 strUTF8.insert(pos, "[/COLOR]");
135 strUTF8.replace(pos, 1, "[CR]");
141 if (m_flag[FLAG_BOLD] != 0)
142 strUTF8.append("[/B]");
143 if (m_flag[FLAG_ITALIC] != 0)
144 strUTF8.append("[/I]");
145 if (m_flag[FLAG_COLOR] != 0)
146 strUTF8.append("[/COLOR]");
152 if (strUTF8.IsEmpty())
155 if( strUTF8[strUTF8.size()-1] == '\n' )
156 strUTF8.Delete(strUTF8.size()-1);
158 // add a new text element to our container
159 pOverlay->AddElement(new CDVDOverlayText::CElementText(strUTF8.c_str()));