- memset (buffer, 0, 1024);
-
- /* Subtitle group number */
- put_int_as_int (buffer + 0, 1, 1);
- /* Subtitle number */
- put_int_as_int (buffer + 1, N, 2);
- /* Extension block number. Use 0xff here to indicate that it is the last TTI
- block in this subtitle "set", as we only ever use one.
- */
- put_int_as_int (buffer + 3, 255, 1);
- /* Cumulative status */
- put_int_as_int (buffer + 4, tables.cumulative_status_enum_to_file (CUMULATIVE_STATUS_NOT_CUMULATIVE), 1);
- /* Time code in */
- put_int_as_int (buffer + 5, i->from.hours (), 1);
- put_int_as_int (buffer + 6, i->from.minutes (), 1);
- put_int_as_int (buffer + 7, i->from.seconds (), 1);
- put_int_as_int (buffer + 8, i->from.frames_at (sub::Rational (frames_per_second * 1000, 1000)), 1);
- /* Time code out */
- put_int_as_int (buffer + 9, i->to.hours (), 1);
- put_int_as_int (buffer + 10, i->to.minutes (), 1);
- put_int_as_int (buffer + 11, i->to.seconds (), 1);
- put_int_as_int (buffer + 12, i->to.frames_at (sub::Rational (frames_per_second * 1000, 1000)), 1);
- /* Vertical position */
- int vp = 0;
- if (j->vertical_position.proportional) {
- switch (j->vertical_position.reference.get_value_or (TOP_OF_SCREEN)) {
- case TOP_OF_SCREEN:
- vp = rint (j->vertical_position.proportional.get() * ROWS);
- break;
- case CENTRE_OF_SCREEN:
- vp = rint (j->vertical_position.proportional.get() * ROWS + (ROWS / 2.0));
- break;
- case BOTTOM_OF_SCREEN:
- vp = rint (ROWS - (j->vertical_position.proportional.get() * ROWS));
- break;
- default:
- break;
- }
- } else if (j->vertical_position.line) {
- float const prop = float (j->vertical_position.line.get()) / j->vertical_position.lines.get ();
- switch (j->vertical_position.reference.get_value_or (TOP_OF_SCREEN)) {
- case TOP_OF_SCREEN:
- vp = prop * ROWS;
- break;
- case CENTRE_OF_SCREEN:
- vp = (prop + 0.5) * ROWS;
- break;
- case BOTTOM_OF_SCREEN:
- vp = (1 - prop) * ROWS;
- break;
- default:
- break;
+ memset (buffer, 0, 1024);
+
+ /* Subtitle group number */
+ put_int_as_int (buffer + 0, 1, 1);
+ /* Subtitle number */
+ put_int_as_int (buffer + 1, 0, 2);
+ /* Extension block number. Use 0xff here to indicate that it is the last TTI
+ block in this subtitle "set", as we only ever use one.
+ */
+ put_int_as_int (buffer + 3, 255, 1);
+ /* Cumulative status */
+ put_int_as_int (buffer + 4, tables.cumulative_status_enum_to_file (CUMULATIVE_STATUS_NOT_CUMULATIVE), 1);
+ /* Time code in */
+ put_int_as_int (buffer + 5, i->from.hours(), 1);
+ put_int_as_int (buffer + 6, i->from.minutes(), 1);
+ put_int_as_int (buffer + 7, i->from.seconds(), 1);
+ put_int_as_int (buffer + 8, i->from.frames_at(sub::Rational (frames_per_second * 1000, 1000)), 1);
+ /* Time code out */
+ put_int_as_int (buffer + 9, i->to.hours(), 1);
+ put_int_as_int (buffer + 10, i->to.minutes(), 1);
+ put_int_as_int (buffer + 11, i->to.seconds(), 1);
+ put_int_as_int (buffer + 12, i->to.frames_at(sub::Rational (frames_per_second * 1000, 1000)), 1);
+ /* Vertical position */
+ put_int_as_int (buffer + 13, top.get(), 1);
+
+ /* Justification code */
+ /* XXX: this assumes the first line has the right value */
+ switch (i->lines.front().horizontal_position.reference) {
+ case LEFT_OF_SCREEN:
+ put_int_as_int (buffer + 14, tables.justification_enum_to_file (JUSTIFICATION_LEFT), 1);
+ break;
+ case HORIZONTAL_CENTRE_OF_SCREEN:
+ put_int_as_int (buffer + 14, tables.justification_enum_to_file (JUSTIFICATION_CENTRE), 1);
+ break;
+ case RIGHT_OF_SCREEN:
+ put_int_as_int (buffer + 14, tables.justification_enum_to_file (JUSTIFICATION_RIGHT), 1);
+ break;
+ }
+
+ /* Comment flag */
+ put_int_as_int (buffer + 15, tables.comment_enum_to_file (COMMENT_NO), 1);
+
+ /* Text */
+ string text;
+ bool italic = false;
+ bool underline = false;
+ optional<int> last_vp;
+
+ for (list<Line>::const_iterator j = i->lines.begin(); j != i->lines.end(); ++j) {
+
+ /* CR/LF down to this line */
+ int const vp = vertical_position (*j);
+
+ if (last_vp) {
+ for (int i = last_vp.get(); i < vp; ++i) {
+ text += "\x8A";