1pub mod ass {
2 pub const LIBASS_VERSION: i32 = 0x0170_4000;
3
4 pub const VALIGN_SUB: i32 = 0;
5 pub const VALIGN_CENTER: i32 = 8;
6 pub const VALIGN_TOP: i32 = 4;
7 pub const HALIGN_LEFT: i32 = 1;
8 pub const HALIGN_CENTER: i32 = 2;
9 pub const HALIGN_RIGHT: i32 = 3;
10 pub const ASS_JUSTIFY_AUTO: i32 = 0;
11 pub const ASS_JUSTIFY_LEFT: i32 = 1;
12 pub const ASS_JUSTIFY_CENTER: i32 = 2;
13 pub const ASS_JUSTIFY_RIGHT: i32 = 3;
14
15 pub const FONT_WEIGHT_LIGHT: i32 = 300;
16 pub const FONT_WEIGHT_MEDIUM: i32 = 400;
17 pub const FONT_WEIGHT_BOLD: i32 = 700;
18 pub const FONT_SLANT_NONE: i32 = 0;
19 pub const FONT_SLANT_ITALIC: i32 = 100;
20 pub const FONT_SLANT_OBLIQUE: i32 = 110;
21 pub const FONT_WIDTH_CONDENSED: i32 = 75;
22 pub const FONT_WIDTH_NORMAL: i32 = 100;
23 pub const FONT_WIDTH_EXPANDED: i32 = 125;
24
25 #[repr(i32)]
26 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
27 pub enum Hinting {
28 #[default]
29 None = 0,
30 Light = 1,
31 Normal = 2,
32 Native = 3,
33 }
34
35 #[repr(i32)]
36 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
37 pub enum ShapingLevel {
38 Simple = 0,
39 #[default]
40 Complex = 1,
41 }
42
43 #[repr(i32)]
44 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
45 pub enum DefaultFontProvider {
46 #[default]
47 None = 0,
48 Autodetect = 1,
49 CoreText = 2,
50 Fontconfig = 3,
51 DirectWrite = 4,
52 }
53
54 #[repr(i32)]
55 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
56 pub enum Feature {
57 IncompatibleExtensions = 0,
58 BidiBrackets = 1,
59 WholeTextLayout = 2,
60 WrapUnicode = 3,
61 }
62
63 pub mod override_bits {
64 pub const DEFAULT: i32 = 0;
65 pub const STYLE: i32 = 1 << 0;
66 pub const SELECTIVE_FONT_SCALE: i32 = 1 << 1;
67 pub const FONT_SIZE: i32 = 1 << 1;
68 pub const FONT_SIZE_FIELDS: i32 = 1 << 2;
69 pub const FONT_NAME: i32 = 1 << 3;
70 pub const COLORS: i32 = 1 << 4;
71 pub const ATTRIBUTES: i32 = 1 << 5;
72 pub const BORDER: i32 = 1 << 6;
73 pub const ALIGNMENT: i32 = 1 << 7;
74 pub const MARGINS: i32 = 1 << 8;
75 pub const FULL_STYLE: i32 = 1 << 9;
76 pub const JUSTIFY: i32 = 1 << 10;
77 pub const BLUR: i32 = 1 << 11;
78 }
79
80 #[repr(i32)]
81 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
82 pub enum YCbCrMatrix {
83 #[default]
84 Default = 0,
85 Unknown = 1,
86 None = 2,
87 Bt601Tv = 3,
88 Bt601Pc = 4,
89 Bt709Tv = 5,
90 Bt709Pc = 6,
91 Smpte240mTv = 7,
92 Smpte240mPc = 8,
93 FccTv = 9,
94 FccPc = 10,
95 }
96
97 #[repr(i32)]
98 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
99 pub enum TrackType {
100 #[default]
101 Unknown = 0,
102 Ass = 1,
103 Ssa = 2,
104 }
105
106 #[repr(i32)]
107 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
108 pub enum ImageType {
109 #[default]
110 Character = 0,
111 Outline = 1,
112 Shadow = 2,
113 }
114}
115
116#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
117pub struct Point {
118 pub x: i32,
119 pub y: i32,
120}
121
122#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
123pub struct Size {
124 pub width: i32,
125 pub height: i32,
126}
127
128#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
129pub struct Rect {
130 pub x_min: i32,
131 pub y_min: i32,
132 pub x_max: i32,
133 pub y_max: i32,
134}
135
136impl Rect {
137 pub fn width(self) -> i32 {
138 (self.x_max - self.x_min).max(0)
139 }
140
141 pub fn height(self) -> i32 {
142 (self.y_max - self.y_min).max(0)
143 }
144
145 pub fn is_empty(self) -> bool {
146 self.width() <= 0 || self.height() <= 0
147 }
148
149 pub fn intersect(self, other: Self) -> Option<Self> {
150 let rect = Self {
151 x_min: self.x_min.max(other.x_min),
152 y_min: self.y_min.max(other.y_min),
153 x_max: self.x_max.min(other.x_max),
154 y_max: self.y_max.min(other.y_max),
155 };
156 (!rect.is_empty()).then_some(rect)
157 }
158}
159
160#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
161pub struct Margins {
162 pub top: i32,
163 pub bottom: i32,
164 pub left: i32,
165 pub right: i32,
166}
167
168#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
169pub struct RgbaColor(pub u32);
170
171#[derive(Clone, Debug, Default, PartialEq, Eq)]
172pub struct ImagePlane {
173 pub size: Size,
174 pub stride: i32,
175 pub color: RgbaColor,
176 pub destination: Point,
177 pub kind: ass::ImageType,
178 pub bitmap: Vec<u8>,
179}
180
181#[derive(Clone, Debug, Default, PartialEq)]
182pub struct RendererConfig {
183 pub frame: Size,
184 pub storage: Size,
185 pub margins: Margins,
186 pub use_margins: bool,
187 pub pixel_aspect: f64,
188 pub font_scale: f64,
189 pub line_spacing: f64,
190 pub line_position: f64,
191 pub hinting: ass::Hinting,
192 pub shaping: ass::ShapingLevel,
193}
194
195#[derive(Clone, Debug, PartialEq, Eq)]
196pub struct RassaError {
197 message: String,
198}
199
200impl RassaError {
201 pub fn new(message: impl Into<String>) -> Self {
202 Self {
203 message: message.into(),
204 }
205 }
206
207 pub fn message(&self) -> &str {
208 &self.message
209 }
210}
211
212impl std::fmt::Display for RassaError {
213 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
214 formatter.write_str(&self.message)
215 }
216}
217
218impl std::error::Error for RassaError {}
219
220pub type RassaResult<T> = Result<T, RassaError>;