Fix scaling of subtitles to be more correct when stretching the fonts.
authorCarl Hetherington <cth@carlh.net>
Mon, 15 Feb 2016 15:17:32 +0000 (15:17 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 15 Feb 2016 22:34:57 +0000 (22:34 +0000)
src/lib/player.cc
src/lib/render_subtitles.cc

index fc13325730142222a5bbc18185ebe6d019416689..3e92eb3d9090040f94868e6dbc8a9203cb326d3f 100644 (file)
@@ -670,8 +670,17 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt,
                                s.set_v_position (s.v_position() + subtitle_content->subtitle_y_offset ());
                                float const xs = subtitle_content->subtitle_x_scale();
                                float const ys = subtitle_content->subtitle_y_scale();
-                               float const average = s.size() * (xs + ys) / 2;
-                               s.set_size (average);
+                               float size = s.size();
+
+                               /* Adjust size to express the common part of the scaling;
+                                  e.g. if xs = ys = 0.5 we scale size by 2.
+                               */
+                               if (xs > 1e-5 && ys > 1e-5) {
+                                       size *= 1 / min (1 / xs, 1 / ys);
+                               }
+                               s.set_size (size);
+
+                               /* Then express aspect ratio changes */
                                if (fabs (1.0 - xs / ys) > dcp::ASPECT_ADJUST_EPSILON) {
                                        s.set_aspect_adjust (xs / ys);
                                }
index dd8e8870b780df70363acda41518870ef5f7b05c..ed7d131fd7455352d6a49aa695629eb2a9667814 100644 (file)
@@ -208,9 +208,8 @@ render_line (list<dcp::SubtitleString> subtitles, list<shared_ptr<Font> > fonts,
        /* XXX */
        float fade_factor = 1;
 
-       layout->update_from_cairo_context (context);
-
        context->scale (xscale, yscale);
+       layout->update_from_cairo_context (context);
 
        if (subtitles.front().effect() == dcp::SHADOW) {
                /* Drop-shadow effect */
@@ -241,6 +240,8 @@ render_line (list<dcp::SubtitleString> subtitles, list<shared_ptr<Font> > fonts,
        int layout_width;
        int layout_height;
        layout->get_pixel_size (layout_width, layout_height);
+       layout_width *= xscale;
+       layout_height *= yscale;
 
        int x = 0;
        switch (subtitles.front().h_align ()) {