Rename SafeStringStream -> locked_stringstream. Bump deps for removal of stringstream.
[dcpomatic.git] / src / lib / render_subtitles.cc
index 76aa092297d9c880a6a5949f78354d953e249e93..782d06532e378d240699419c3031ae41fe04191a 100644 (file)
@@ -44,6 +44,54 @@ using boost::optional;
 static FcConfig* fc_config = 0;
 static list<pair<FontFiles, string> > fc_config_fonts;
 
+string
+marked_up (list<dcp::SubtitleString> subtitles)
+{
+       string out;
+       bool italic = false;
+       bool bold = false;
+       bool underline = false;
+       BOOST_FOREACH (dcp::SubtitleString const & i, subtitles) {
+
+               if (i.italic() && !italic) {
+                       out += "<i>";
+               }
+               if (i.bold() && !bold) {
+                       out += "<b>";
+               }
+               if (i.underline() && !underline) {
+                       out += "<u>";
+               }
+               if (!i.underline() && underline) {
+                       out += "</u>";
+               }
+               if (!i.bold() && bold) {
+                       out += "</b>";
+               }
+               if (!i.italic() && italic) {
+                       out += "</i>";
+               }
+
+               italic = i.italic ();
+               bold = i.bold ();
+               underline = i.underline ();
+
+               out += i.text ();
+       }
+
+       if (underline) {
+               out += "</u>";
+       }
+       if (bold) {
+               out += "</b>";
+       }
+       if (italic) {
+               out += "</i>";
+       }
+
+       return out;
+}
+
 /** @param subtitles A list of subtitles that are all on the same line */
 static PositionImage
 render_line (list<dcp::SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target)
@@ -197,41 +245,7 @@ render_line (list<dcp::SubtitleString> subtitles, list<shared_ptr<Font> > fonts,
        Pango::FontDescription font (font_name);
        font.set_absolute_size (subtitles.front().size_in_pixels (target.height) * PANGO_SCALE);
        layout->set_font_description (font);
-
-       string marked_up;
-       bool italic = false;
-       bool bold = false;
-       BOOST_FOREACH (dcp::SubtitleString const & i, subtitles) {
-               if (i.italic() != italic) {
-                       if (i.italic()) {
-                               marked_up += "<i>";
-                       } else {
-                               marked_up += "</i>";
-                       }
-                       italic = i.italic ();
-               }
-
-               if (i.bold() != bold) {
-                       if (i.bold()) {
-                               marked_up += "<b>";
-                       } else {
-                               marked_up += "</b>";
-                       }
-                       bold = i.bold ();
-               }
-
-               marked_up += i.text ();
-       }
-
-       if (italic) {
-               marked_up += "</i>";
-       }
-
-       if (bold) {
-               marked_up += "</b>";
-       }
-
-       layout->set_markup (marked_up);
+       layout->set_markup (marked_up (subtitles));
 
        /* Compute fade factor */
        /* XXX */