Rename SafeStringStream -> locked_stringstream. Bump deps for removal of stringstream.
[dcpomatic.git] / src / lib / render_subtitles.cc
index 16c6a3c4eee13552ecdd1f9b8581854b9b5ee1e6..782d06532e378d240699419c3031ae41fe04191a 100644 (file)
@@ -1,19 +1,20 @@
 /*
     Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
+    DCP-o-matic is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 
@@ -43,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)
@@ -196,27 +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;
-       BOOST_FOREACH (dcp::SubtitleString const & i, subtitles) {
-               if (i.italic() != italic) {
-                       if (i.italic()) {
-                               marked_up += "<i>";
-                       } else {
-                               marked_up += "</i>";
-                       }
-                       italic = i.italic ();
-               }
-
-               marked_up += i.text ();
-       }
-
-       if (italic) {
-               marked_up += "</i>";
-       }
-
-       layout->set_markup (marked_up);
+       layout->set_markup (marked_up (subtitles));
 
        /* Compute fade factor */
        /* XXX */