+static int
+y_position (StringText const& first, int target_height, int baseline_to_bottom, int layout_height)
+{
+ int y = 0;
+ 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;
+ }
+ }