Basic adaptations for changes to libdcp1 colour conversion handling.
[dcpomatic.git] / src / lib / render_subtitles.cc
index c18cb4272440958db21d27f055ae0eb003131b5c..b2900d27a8dfdc3e99f0f5fd289b45beb3b56c8e 100644 (file)
@@ -28,6 +28,7 @@ using std::cout;
 using std::string;
 using std::min;
 using std::max;
+using std::pair;
 using boost::shared_ptr;
 using boost::optional;
 
@@ -36,22 +37,21 @@ calculate_position (dcp::VAlign v_align, double v_position, int target_height, i
 {
        switch (v_align) {
        case dcp::TOP:
-               return (v_position / 100) * target_height - offset;
+               return v_position * target_height - offset;
        case dcp::CENTER:
-               return (0.5 + v_position / 100) * target_height - offset;
+               return (0.5 + v_position) * target_height - offset;
        case dcp::BOTTOM:
-               return (1.0 - v_position / 100) * target_height - offset;
+               return (1.0 - v_position) * target_height - offset;
        }
 
        return 0;
 }
 
-void
-render_subtitles (list<dcp::SubtitleString> subtitles, dcp::Size target, shared_ptr<Image>& image, Position<int>& position)
+PositionImage
+render_subtitles (list<dcp::SubtitleString> subtitles, dcp::Size target)
 {
        if (subtitles.empty ()) {
-               image.reset ();
-               return;
+               return PositionImage ();
        }
 
        /* Estimate height that the subtitle image needs to be */
@@ -68,7 +68,7 @@ render_subtitles (list<dcp::SubtitleString> subtitles, dcp::Size target, shared_
        top = top.get() - 32;
        bottom = bottom.get() + 32;
 
-       image.reset (new Image (PIX_FMT_RGBA, dcp::Size (target.width, bottom.get() - top.get ()), false));
+       shared_ptr<Image> image (new Image (PIX_FMT_RGBA, dcp::Size (target.width, bottom.get() - top.get ()), false));
        image->make_black ();
 
        Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create (
@@ -88,11 +88,7 @@ render_subtitles (list<dcp::SubtitleString> subtitles, dcp::Size target, shared_
        context->set_line_width (1);
 
        for (list<dcp::SubtitleString>::const_iterator i = subtitles.begin(); i != subtitles.end(); ++i) {
-               string f = i->font ();
-               if (f.empty ()) {
-                       f = "Arial";
-               }
-               Pango::FontDescription font (f);
+               Pango::FontDescription font (i->font().get_value_or ("Arial"));
                font.set_absolute_size (i->size_in_pixels (target.height) * PANGO_SCALE);
                if (i->italic ()) {
                        font.set_style (Pango::STYLE_ITALIC);
@@ -146,5 +142,7 @@ render_subtitles (list<dcp::SubtitleString> subtitles, dcp::Size target, shared_
                        context->stroke ();
                }
        }
+
+       return PositionImage (image, Position<int> (0, top.get ()));
 }