|
1 | 1 | use crate::comment::{Comment, CommentPosition}; |
| 2 | +use crate::writer::rows; |
2 | 3 | use crate::writer::utils; |
3 | 4 |
|
4 | 5 | pub fn write_head( |
@@ -47,8 +48,8 @@ pub fn write_comment( |
47 | 48 | height: u32, |
48 | 49 | bottom_reserved: u32, |
49 | 50 | fontsize: f32, |
50 | | - duration_marquee: f32, |
51 | | - duration_still: f32, |
| 51 | + duration_marquee: f64, |
| 52 | + duration_still: f64, |
52 | 53 | styleid: &str, |
53 | 54 | ) -> String { |
54 | 55 | let text = utils::ass_escape(&comment.comment); |
@@ -91,7 +92,68 @@ pub fn write_comment( |
91 | 92 | } |
92 | 93 | } |
93 | 94 | let start = utils::convert_timestamp(comment.timeline); |
94 | | - let end = utils::convert_timestamp(comment.timeline + duration as f64); |
| 95 | + let end = utils::convert_timestamp(comment.timeline + duration); |
95 | 96 | let styles = styles.join(""); |
96 | 97 | format!("Dialogue: 2,{start},{end},{styleid},,0000,0000,0000,,{{{styles}}}{text}\n") |
97 | 98 | } |
| 99 | + |
| 100 | +#[allow(clippy::too_many_arguments)] |
| 101 | +pub fn write_normal_comment( |
| 102 | + rows: &mut rows::Rows, |
| 103 | + comment: &Comment, |
| 104 | + width: u32, |
| 105 | + height: u32, |
| 106 | + bottom_reserved: u32, |
| 107 | + fontsize: f32, |
| 108 | + duration_marquee: f64, |
| 109 | + duration_still: f64, |
| 110 | + styleid: &str, |
| 111 | + reduced: bool, |
| 112 | +) -> String { |
| 113 | + let mut row: usize = 0; |
| 114 | + let rowmax = height - bottom_reserved - comment.height as u32; |
| 115 | + while row <= rowmax as usize { |
| 116 | + let freerows = rows::test_free_rows( |
| 117 | + rows, |
| 118 | + comment, |
| 119 | + row, |
| 120 | + width, |
| 121 | + height, |
| 122 | + bottom_reserved, |
| 123 | + duration_marquee, |
| 124 | + duration_still, |
| 125 | + ); |
| 126 | + if freerows >= comment.height as usize { |
| 127 | + rows::mark_comment_row(rows, comment, row); |
| 128 | + return write_comment( |
| 129 | + comment, |
| 130 | + row, |
| 131 | + width, |
| 132 | + height, |
| 133 | + bottom_reserved, |
| 134 | + fontsize, |
| 135 | + duration_marquee, |
| 136 | + duration_still, |
| 137 | + styleid, |
| 138 | + ); |
| 139 | + } else { |
| 140 | + row += if freerows == 0 { 1 } else { freerows }; |
| 141 | + } |
| 142 | + } |
| 143 | + if !reduced { |
| 144 | + row = rows::find_alternative_row(rows, comment, height, bottom_reserved); |
| 145 | + rows::mark_comment_row(rows, comment, row); |
| 146 | + return write_comment( |
| 147 | + comment, |
| 148 | + row, |
| 149 | + width, |
| 150 | + height, |
| 151 | + bottom_reserved, |
| 152 | + fontsize, |
| 153 | + duration_marquee, |
| 154 | + duration_still, |
| 155 | + styleid, |
| 156 | + ); |
| 157 | + } |
| 158 | + "".to_owned() |
| 159 | +} |
0 commit comments