- current.vertical_position.line = 0;
- /* XXX: arbitrary */
- current.vertical_position.lines = 32;
- current.vertical_position.reference = TOP_OF_SUBTITLE;
+ if (!current.vertical_position.reference) {
+ current.vertical_position.reference = BOTTOM_OF_SCREEN;
+ }
+
+ if (!current.vertical_position.proportional) {
+ current.vertical_position.proportional = 0;
+ }
+
+ /* We must have a font size, as there could be a margin specified
+ in pixels and in that case we must know how big the subtitle
+ lines are to work out the position on screen.
+ */
+ if (!current.font_size.points()) {
+ current.font_size.set_points (72);
+ }
+
+ /* Count the number of line breaks */
+ int line_breaks = 0;
+ for (size_t i = 0; i < line.length() - 1; ++i) {
+ if (line[i] == '\\' && (line[i+1] == 'n' || line[i+1] == 'N')) {
+ ++line_breaks;
+ }
+ }
+
+ /* Imagine that the screen is 792 points (i.e. 11 inches) high (as with DCP) */
+ double const line_size = current.font_size.proportional(792) * 1.2;
+
+ /* Tweak vertical_position accordingly */
+ switch (current.vertical_position.reference.get()) {
+ case TOP_OF_SCREEN:
+ case TOP_OF_SUBTITLE:
+ /* Nothing to do */
+ break;
+ case CENTRE_OF_SCREEN:
+ current.vertical_position.proportional = current.vertical_position.proportional.get() - ((line_breaks + 1) * line_size) / 2;
+ break;
+ case BOTTOM_OF_SCREEN:
+ current.vertical_position.proportional = current.vertical_position.proportional.get() + line_breaks * line_size;
+ break;
+ }