diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-07-06 12:25:15 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-07-20 10:22:55 +0200 |
| commit | 9726a58f44d52d235b027225ddd68c6acf83c733 (patch) | |
| tree | 4616ea2ccfc9793cb08a752678e7c537a858815d /src/lib/render_text.cc | |
| parent | d70f755dde2812bf2311e2ce09563af1b5334d03 (diff) | |
Handle vertical alignment of subs correctly wrt the difference between Interop and SMPTE.
Diffstat (limited to 'src/lib/render_text.cc')
| -rw-r--r-- | src/lib/render_text.cc | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc index 574ee21a0..9c1c233c2 100644 --- a/src/lib/render_text.cc +++ b/src/lib/render_text.cc @@ -245,27 +245,41 @@ x_position (StringText const& first, int target_width, int layout_width) static int -y_position (StringText const& first, int target_height, int layout_height) +y_position (StringText const& first, int target_height, int baseline_to_bottom, int layout_height) { int y = 0; - switch (first.v_align()) { - case dcp::VAlign::TOP: - /* SMPTE says that v_position is the distance between top - of frame and top of subtitle, but this doesn't always seem to be - the case in practice; Gunnar Ásgeirsson's Dolby server appears - to put VAlign::TOP subs with v_position as the distance between top - of frame and bottom of subtitle. - */ - y = first.v_position() * target_height - layout_height; - break; - case dcp::VAlign::CENTER: - /* v_position is distance between centre of frame and centre of subtitle */ - y = (0.5 + first.v_position()) * target_height - layout_height / 2; - break; - case dcp::VAlign::BOTTOM: - /* v_position is distance between bottom of frame and bottom of subtitle */ - y = (1.0 - first.v_position()) * target_height - layout_height; + switch (first.valign_standard) { + case dcp::Standard::INTEROP: + switch (first.v_align()) { + case dcp::VAlign::TOP: + /* v_position is distance from top of frame to subtitle baseline */ + y = first.v_position() * target_height - (layout_height - baseline_to_bottom); + break; + case dcp::VAlign::CENTER: + /* v_position is distance from centre of frame to subtitle baseline */ + y = (0.5 + first.v_position()) * target_height - (layout_height - baseline_to_bottom); + break; + case dcp::VAlign::BOTTOM: + /* v_position is distance from bottom of frame to subtitle baseline */ + y = (1.0 - first.v_position()) * target_height - (layout_height - baseline_to_bottom); + break; + } break; + case dcp::Standard::SMPTE: + switch (first.v_align()) { + case dcp::VAlign::TOP: + /* v_position is distance from top of frame to top of subtitle */ + y = first.v_position() * target_height; + break; + case dcp::VAlign::CENTER: + /* v_position is distance from centre of frame to centre of subtitle */ + y = (0.5 + first.v_position()) * target_height - layout_height / 2; + break; + case dcp::VAlign::BOTTOM: + /* v_position is distance from bottom of frame to bottom of subtitle */ + y = (1.0 - first.v_position()) * target_height - layout_height; + break; + } } return y; @@ -359,7 +373,7 @@ render_line (list<StringText> subtitles, dcp::Size target, DCPTime time, int fra context->stroke (); int const x = x_position (first, target.width, size.width); - int const y = y_position (first, target.height, size.height); + int const y = y_position (first, target.height, ink.get_y() / Pango::SCALE, size.height); return PositionImage (image, Position<int>(max (0, x), max(0, y))); } |
