Skip to main content

ass_renderer/layout/positioning/
coords.rs

1/// Handle PlayResX/PlayResY coordinate scaling
2pub fn scale_coordinates(
3    x: f32,
4    y: f32,
5    play_res_x: f32,
6    play_res_y: f32,
7    screen_width: f32,
8    screen_height: f32,
9) -> (f32, f32) {
10    let scale_x = screen_width / play_res_x;
11    let scale_y = screen_height / play_res_y;
12    (x * scale_x, y * scale_y)
13}
14
15/// Convert SSA legacy alignment to ASS alignment
16pub fn convert_ssa_alignment(ssa_align: u8) -> u8 {
17    // SSA: 1=left, 2=center, 3=right
18    // +0=sub, +4=title, +8=top, +128=mid-title
19    let h_align = ssa_align & 3;
20    let v_align = (ssa_align >> 2) & 3;
21
22    let h_part = match h_align {
23        1 => 1, // Left
24        2 => 2, // Center
25        3 => 3, // Right
26        _ => 2, // Default center
27    };
28
29    let v_part = match v_align {
30        0 => 0,     // Bottom
31        1 | 3 => 3, // Middle (title or mid-title)
32        2 => 6,     // Top
33        _ => 0,     // Default bottom
34    };
35
36    h_part + v_part
37}