ass_core/parser/ast/style/definition.rs
1//! `Style` struct definition for ASS style nodes.
2//!
3//! Defines the zero-copy `Style` struct representing a single style from the
4//! V4+ Styles section, together with its `Default` implementation providing
5//! standard ASS style values.
6
7use super::super::Span;
8
9/// Style definition from [V4+ Styles] section
10///
11/// Represents a single style definition that can be referenced by events.
12/// All fields are stored as zero-copy string references to the original
13/// source text for maximum memory efficiency.
14///
15/// # Examples
16///
17/// ```rust
18/// use ass_core::parser::ast::Style;
19///
20/// let style = Style {
21/// name: "Default",
22/// fontname: "Arial",
23/// fontsize: "20",
24/// ..Style::default()
25/// };
26///
27/// assert_eq!(style.name, "Default");
28/// assert_eq!(style.fontname, "Arial");
29/// ```
30#[derive(Debug, Clone, PartialEq, Eq)]
31#[cfg_attr(feature = "serde", derive(serde::Serialize))]
32pub struct Style<'a> {
33 /// Style name (must be unique within script)
34 pub name: &'a str,
35
36 /// Parent style name for inheritance (None if no inheritance)
37 pub parent: Option<&'a str>,
38
39 /// Font name for text rendering
40 pub fontname: &'a str,
41
42 /// Font size in points
43 pub fontsize: &'a str,
44
45 /// Primary color in BGR format (&HBBGGRR)
46 pub primary_colour: &'a str,
47
48 /// Secondary color for collision effects
49 pub secondary_colour: &'a str,
50
51 /// Outline color
52 pub outline_colour: &'a str,
53
54 /// Shadow/background color
55 pub back_colour: &'a str,
56
57 /// Bold flag (-1/0 or weight)
58 pub bold: &'a str,
59
60 /// Italic flag (0/1)
61 pub italic: &'a str,
62
63 /// Underline flag (0/1)
64 pub underline: &'a str,
65
66 /// Strikeout flag (0/1)
67 pub strikeout: &'a str,
68
69 /// Horizontal scale percentage
70 pub scale_x: &'a str,
71
72 /// Vertical scale percentage
73 pub scale_y: &'a str,
74
75 /// Character spacing in pixels
76 pub spacing: &'a str,
77
78 /// Rotation angle in degrees
79 pub angle: &'a str,
80
81 /// Border style (1=outline+shadow, 3=opaque box)
82 pub border_style: &'a str,
83
84 /// Outline width in pixels
85 pub outline: &'a str,
86
87 /// Shadow depth in pixels
88 pub shadow: &'a str,
89
90 /// Alignment (1-3 + 4/8 for vertical positioning)
91 pub alignment: &'a str,
92
93 /// Left margin in pixels
94 pub margin_l: &'a str,
95
96 /// Right margin in pixels
97 pub margin_r: &'a str,
98
99 /// Vertical margin in pixels (V4+)
100 pub margin_v: &'a str,
101
102 /// Top margin in pixels (V4++)
103 pub margin_t: Option<&'a str>,
104
105 /// Bottom margin in pixels (V4++)
106 pub margin_b: Option<&'a str>,
107
108 /// Font encoding identifier
109 pub encoding: &'a str,
110
111 /// Positioning context (V4++)
112 pub relative_to: Option<&'a str>,
113
114 /// Span in source text where this style is defined
115 pub span: Span,
116}
117
118impl Default for Style<'_> {
119 /// Create default ASS style with standard values
120 ///
121 /// Provides the standard ASS default style values as defined
122 /// in the ASS specification for maximum compatibility.
123 fn default() -> Self {
124 Self {
125 name: "Default",
126 parent: None,
127 fontname: "Arial",
128 fontsize: "20",
129 primary_colour: "&Hffffff",
130 secondary_colour: "&H0000ff",
131 outline_colour: "&H000000",
132 back_colour: "&H000000",
133 bold: "0",
134 italic: "0",
135 underline: "0",
136 strikeout: "0",
137 scale_x: "100",
138 scale_y: "100",
139 spacing: "0",
140 angle: "0",
141 border_style: "1",
142 outline: "0",
143 shadow: "0",
144 alignment: "2",
145 margin_l: "10",
146 margin_r: "10",
147 margin_v: "10",
148 margin_t: None,
149 margin_b: None,
150 encoding: "1",
151 relative_to: None,
152 span: Span::new(0, 0, 0, 0),
153 }
154 }
155}