pub struct V4Format { /* private fields */ }Expand description
§V4Format
The Second part of any Advanced SubStation Alpha file is V4Format.
This is the part which has fields separated by comma which specify the format, styling,
encoding colors and many other important parts of the the .ass file.
Implementations§
Source§impl V4Format
impl V4Format
Sourcepub fn set_v4(&mut self, v4: V4Format) -> &mut V4Format
pub fn set_v4(&mut self, v4: V4Format) -> &mut V4Format
Set V4 from a V4 Struct.
Examples found in repository?
4fn main() {
5 let mut ass_file = AssFile::new();
6
7 ass_file.components.script
8 .set_script(ScriptInfo::default());
9
10 ass_file.components.v4
11 .set_v4(V4Format::default());
12
13 ass_file.components.events
14 .set_events(Events::default());
15
16 AssFile::save_file(&ass_file, "default_subtitles.ass");
17}More examples
5fn main() {
6 let mut ass_file = AssFile::new();
7
8 let dialogue = Dialogue::new()
9 .set_start("0:00:00:00")
10 .set_end("0:00:02:00")
11 .set_text("Hello Friend!")
12 .set_colour(HexColor::YELLOW);
13
14 ass_file.components.script
15 .set_script(ScriptInfo::default());
16
17 ass_file.components.v4
18 .set_v4(V4Format::default());
19
20 ass_file.components.events
21 .set_events(Events::default())
22 .add_dialogue(dialogue);
23
24 AssFile::save_file(&ass_file, "new_subtitles.ass");
25}6fn main() {
7 let hexcolor = AssFileOptions::get_ass_color(HexColor::YELLOW);
8 let srt_file = AssFile::from_srt("RapGod.srt");
9 let mut ass_file = AssFile::new();
10 let mut event = Events::default();
11
12 for srt_seg in srt_file.iter() {
13 let start = &srt_seg.start;
14 let end = &srt_seg.end;
15 let text = &srt_seg.text;
16
17 let random_color:HexColor = rand::random();
18
19 let dialogue = Dialogue::default()
20 .set_start(&start)
21 .set_end(&end)
22 .set_text(&text)
23 .set_colour(random_color);
24
25 event.add_dialogue(dialogue);
26 }
27
28
29 ass_file.components.script
30 .set_script(ScriptInfo::default());
31
32
33
34 ass_file.components.v4
35 .set_v4(V4Format::default())
36 .set_primarycolour(&hexcolor);
37 ass_file.components.events
38 .set_events(event);
39
40 AssFile::save_file(&ass_file, "new_subtitle.ass");
41}5fn main() -> Result<(), IndexNotFound>{
6 let mut ass_file = AssFile::new();
7 let hexcolor = AssFileOptions::get_ass_color(HexColor::YELLOW);
8
9 let first_dialogue = Dialogue::default()
10 .set_start("0:00:00.10")
11 .set_end("0:00:00.50")
12 .set_text("Hello There.");
13
14 let second_dialogue = Dialogue::default()
15 .set_start("00:00.50")
16 .set_end("00:00.58")
17 .set_text("Hello Friend.");
18
19 let third_dialogue = Dialogue::default()
20 .set_start("0:00:00.58")
21 .set_end("0:00:01.01")
22 .set_text("Goodbye Friend.");
23
24 let events = Events::new()
25 .add_first_dialogue(first_dialogue)?
26 .add_dialogue(second_dialogue)
27 .add_dialogue(third_dialogue)
28 .create();
29
30
31 ass_file.components.script
32 .set_script(ScriptInfo::default())
33 .set_scripttype("FFMPEG");
34
35 ass_file.components.v4
36 .set_v4(V4Format::default())
37 .set_primarycolour(&hexcolor);
38
39 ass_file.components.events
40 .set_events(events);
41
42 AssFile::save_file(&ass_file, "new_subtitles.ass");
43
44 Ok(())
45
46}Source§impl V4Format
impl V4Format
Sourcepub fn set_name(&mut self, value: &str) -> &mut Self
pub fn set_name(&mut self, value: &str) -> &mut Self
set the name for the V4 field. The name of the Style. Case sensitive. Cannot include commas
Sourcepub fn set_fontname(&mut self, value: &str) -> &mut Self
pub fn set_fontname(&mut self, value: &str) -> &mut Self
set the fontname for the V4 field. The fontname as used by Windows. Case-sensitive.
Sourcepub fn set_fontsize(&mut self, value: &str) -> &mut Self
pub fn set_fontsize(&mut self, value: &str) -> &mut Self
set the fontsize for the V4 field.
Sourcepub fn set_primarycolour(&mut self, value: &str) -> &mut Self
pub fn set_primarycolour(&mut self, value: &str) -> &mut Self
set the primarycolour for the V4 field.
use ass_parser::{AssFile, ScriptInfo, V4Format, Events, AssFileOptions};
use hex_color::HexColor;
fn main() {
let mut ass_file = AssFile::new();
let hexcolor = AssFileOptions::get_ass_color(HexColor::YELLOW);
ass_file.components.script
.set_script(ScriptInfo::default());
ass_file.components.v4
.set_v4(V4Format::default())
.set_primarycolour(&hexcolor);
ass_file.components.events
.set_events(Events::default());
AssFile::save_file(&ass_file, "new_subtitles.ass")
}Examples found in repository?
4fn main() -> Result<(), std::io::Error>{
5 let mut ass_file = AssFile::from_file("./examples/subtitles.ass")?;
6 let dialogue = Dialogue::default()
7 .set_text("Hello Friend!");
8 let primary_color = AssFileOptions::get_ass_color(HexColor::RED);
9
10 ass_file.components.v4
11 .set_primarycolour(&primary_color);
12
13 ass_file.components.events
14 .add_dialogue(dialogue);
15
16 AssFile::save_file(&ass_file, "sub.ass");
17 println!("modified subtitles saved!");
18
19 Ok(())
20}More examples
6fn main() {
7 let hexcolor = AssFileOptions::get_ass_color(HexColor::YELLOW);
8 let srt_file = AssFile::from_srt("RapGod.srt");
9 let mut ass_file = AssFile::new();
10 let mut event = Events::default();
11
12 for srt_seg in srt_file.iter() {
13 let start = &srt_seg.start;
14 let end = &srt_seg.end;
15 let text = &srt_seg.text;
16
17 let random_color:HexColor = rand::random();
18
19 let dialogue = Dialogue::default()
20 .set_start(&start)
21 .set_end(&end)
22 .set_text(&text)
23 .set_colour(random_color);
24
25 event.add_dialogue(dialogue);
26 }
27
28
29 ass_file.components.script
30 .set_script(ScriptInfo::default());
31
32
33
34 ass_file.components.v4
35 .set_v4(V4Format::default())
36 .set_primarycolour(&hexcolor);
37 ass_file.components.events
38 .set_events(event);
39
40 AssFile::save_file(&ass_file, "new_subtitle.ass");
41}5fn main() -> Result<(), IndexNotFound>{
6 let mut ass_file = AssFile::new();
7 let hexcolor = AssFileOptions::get_ass_color(HexColor::YELLOW);
8
9 let first_dialogue = Dialogue::default()
10 .set_start("0:00:00.10")
11 .set_end("0:00:00.50")
12 .set_text("Hello There.");
13
14 let second_dialogue = Dialogue::default()
15 .set_start("00:00.50")
16 .set_end("00:00.58")
17 .set_text("Hello Friend.");
18
19 let third_dialogue = Dialogue::default()
20 .set_start("0:00:00.58")
21 .set_end("0:00:01.01")
22 .set_text("Goodbye Friend.");
23
24 let events = Events::new()
25 .add_first_dialogue(first_dialogue)?
26 .add_dialogue(second_dialogue)
27 .add_dialogue(third_dialogue)
28 .create();
29
30
31 ass_file.components.script
32 .set_script(ScriptInfo::default())
33 .set_scripttype("FFMPEG");
34
35 ass_file.components.v4
36 .set_v4(V4Format::default())
37 .set_primarycolour(&hexcolor);
38
39 ass_file.components.events
40 .set_events(events);
41
42 AssFile::save_file(&ass_file, "new_subtitles.ass");
43
44 Ok(())
45
46}Sourcepub fn set_secondarycolour(&mut self, value: &str) -> &mut Self
pub fn set_secondarycolour(&mut self, value: &str) -> &mut Self
set the secondarycolour for the V4 field.
use ass_parser::{AssFile, ScriptInfo, V4Format, Events, AssFileOptions};
use hex_color::HexColor;
fn main() {
let mut ass_file = AssFile::new();
let hexcolor = AssFileOptions::get_ass_color(HexColor::YELLOW);
ass_file.components.script
.set_script(ScriptInfo::default());
ass_file.components.v4
.set_v4(V4Format::default())
.set_secondarycolour(&hexcolor);
ass_file.components.events
.set_events(Events::default());
AssFile::save_file(&ass_file, "new_subtitles.ass")
}Sourcepub fn set_outlinecolour(&mut self, value: &str) -> &mut Self
pub fn set_outlinecolour(&mut self, value: &str) -> &mut Self
set the outlinecolour for the V4 field.
use ass_parser::{AssFile, ScriptInfo, V4Format, Events, AssFileOptions};
use hex_color::HexColor;
fn main() {
let mut ass_file = AssFile::new();
let hexcolor = AssFileOptions::get_ass_color(HexColor::YELLOW);
ass_file.components.script
.set_script(ScriptInfo::default());
ass_file.components.v4
.set_v4(V4Format::default())
.set_outlinecolour(&hexcolor);
ass_file.components.events
.set_events(Events::default());
AssFile::save_file(&ass_file, "new_subtitles.ass")
}Sourcepub fn set_backcolour(&mut self, value: &str) -> &mut Self
pub fn set_backcolour(&mut self, value: &str) -> &mut Self
set the backcolour for the V4 field.
use ass_parser::{AssFile, ScriptInfo, V4Format, Events, AssFileOptions};
use hex_color::HexColor;
fn main() {
let mut ass_file = AssFile::new();
let hexcolor = AssFileOptions::get_ass_color(HexColor::YELLOW);
ass_file.components.script
.set_script(ScriptInfo::default());
ass_file.components.v4
.set_v4(V4Format::default())
.set_backcolour(&hexcolor);
ass_file.components.events
.set_events(Events::default());
AssFile::save_file(&ass_file, "new_subtitles.ass")
}Sourcepub fn set_bold(&mut self, value: &str) -> &mut Self
pub fn set_bold(&mut self, value: &str) -> &mut Self
set the bold for the V4 field. This defines whether text is bold (true) or not (false). -1 is True, 0 is False. This is independant of the Italic attribute - you can have have text which is both bold and italic
Sourcepub fn set_italic(&mut self, value: &str) -> &mut Self
pub fn set_italic(&mut self, value: &str) -> &mut Self
set the italic for the V4 field. This defines whether text is italic (true) or not (false). -1 is True, 0 is False. This is independant of the bold attribute - you can have have text which is both bold and italic.
Sourcepub fn set_underline(&mut self, value: &str) -> &mut Self
pub fn set_underline(&mut self, value: &str) -> &mut Self
set the underline for the V4 field. use either of [-1 or 0] where -1 is considered True and 0 is considered False.
Sourcepub fn set_strikeout(&mut self, value: &str) -> &mut Self
pub fn set_strikeout(&mut self, value: &str) -> &mut Self
set the strikeout for the V4 field. use either of [-1 or 0] where -1 is considered True and 0 is considered False.
Sourcepub fn set_scalex(&mut self, value: &str) -> &mut Self
pub fn set_scalex(&mut self, value: &str) -> &mut Self
set the scalex for the V4 field. ScaleX. Modifies the width of the font. [percent]
Sourcepub fn set_scaley(&mut self, value: &str) -> &mut Self
pub fn set_scaley(&mut self, value: &str) -> &mut Self
set the scaley for the V4 field. ScaleX. Modifies the height of the font. [percent]
Sourcepub fn set_spacing(&mut self, value: &str) -> &mut Self
pub fn set_spacing(&mut self, value: &str) -> &mut Self
set the spacing for the V4 field. Extra space between characters. [pixels]
Sourcepub fn set_angle(&mut self, value: &str) -> &mut Self
pub fn set_angle(&mut self, value: &str) -> &mut Self
set the angle for the V4 field. The origin of the rotation is defined by the alignment. Can be a floating point number. [degrees]
Sourcepub fn set_borderstyle(&mut self, value: &str) -> &mut Self
pub fn set_borderstyle(&mut self, value: &str) -> &mut Self
set the borderstyle for the V4 field. pass either 1 or 3. where 1=Outline + drop shadow, 3=Opaque box.
Sourcepub fn set_outline(&mut self, value: &str) -> &mut Self
pub fn set_outline(&mut self, value: &str) -> &mut Self
set the outline for the V4 field. If BorderStyle is 1, then this specifies the width of the outline around the text, in pixels. Values may be 0, 1, 2, 3 or 4.
Sourcepub fn set_shadow(&mut self, value: &str) -> &mut Self
pub fn set_shadow(&mut self, value: &str) -> &mut Self
set the shadow for the V4 field. If BorderStyle is 1, then this specifies the depth of the drop shadow behind the text, in pixels. Values may be 0, 1, 2, 3 or 4. Drop shadow is always used in addition to an outline.
Sourcepub fn set_alignment(&mut self, value: &str) -> &mut Self
pub fn set_alignment(&mut self, value: &str) -> &mut Self
set the alignment for the V4 field. This sets how text is “justified” within the Left/Right onscreen margins, and also the vertical placing. Values may be 1=Left, 2=Centered, 3=Right. Add 4 to the value for a “Toptitle”. Add 8 to the value for a “Midtitle”. eg. 5 = left-justified toptitle
Sourcepub fn set_marginl(&mut self, value: &str) -> &mut Self
pub fn set_marginl(&mut self, value: &str) -> &mut Self
set the marginl for the V4 field. This defines the Left Margin in pixels. It is the distance from the left-hand edge of the screen.The three onscreen margins (MarginL, MarginR, MarginV) define areas in which the subtitle text will be displayed.
Sourcepub fn set_marginr(&mut self, value: &str) -> &mut Self
pub fn set_marginr(&mut self, value: &str) -> &mut Self
set the marginr for the V4 field. This defines the Right Margin in pixels. It is the distance from the right-hand edge of the screen. The three onscreen margins (MarginL, MarginR, MarginV) define areas in which the subtitle text will be displayed.
Sourcepub fn set_marginv(&mut self, value: &str) -> &mut Self
pub fn set_marginv(&mut self, value: &str) -> &mut Self
set the marginv for the V4 field. This defines the vertical Left Margin in pixels. For a subtitle, it is the distance from the bottom of the screen. For a toptitle, it is the distance from the top of the screen. For a midtitle, the value is ignored - the text will be vertically centred.