servo_webvtt/cue/settings.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5/// <https://w3c.github.io/webvtt/#webvtt-cue-writing-direction>
6#[derive(Debug, Default, PartialEq)]
7pub enum WebVttWritingDirection {
8 /// <https://w3c.github.io/webvtt/#webvtt-cue-horizontal-writing-direction>
9 #[default]
10 Horizontal,
11 /// <https://w3c.github.io/webvtt/#webvtt-cue-vertical-growing-left-writing-direction>
12 VerticalGrowingLeft,
13 /// <https://w3c.github.io/webvtt/#webvtt-cue-vertical-growing-right-writing-direction>
14 VerticalGrowingRight,
15}
16
17/// <https://w3c.github.io/webvtt/#webvtt-cue-text-alignment>
18#[derive(Debug, Default, PartialEq)]
19pub enum WebVttTextAlignment {
20 /// <https://w3c.github.io/webvtt/#webvtt-cue-start-alignment>
21 Start,
22 /// <https://w3c.github.io/webvtt/#webvtt-cue-center-alignment>
23 #[default]
24 Center,
25 /// <https://w3c.github.io/webvtt/#webvtt-cue-end-alignment>
26 End,
27 /// <https://w3c.github.io/webvtt/#webvtt-cue-left-alignment>
28 Left,
29 /// <https://w3c.github.io/webvtt/#webvtt-cue-right-alignment>
30 Right,
31}
32
33/// <https://w3c.github.io/webvtt/#webvtt-cue-position-alignment>
34#[derive(Debug, Default, PartialEq)]
35pub enum WebVttPositionAlignment {
36 /// <https://w3c.github.io/webvtt/#webvtt-cue-position-line-left-alignment>
37 LineLeft,
38 /// <https://w3c.github.io/webvtt/#webvtt-cue-position-center-alignment>
39 Center,
40 /// <https://w3c.github.io/webvtt/#webvtt-cue-position-line-right-alignment>
41 LineRight,
42 /// <https://w3c.github.io/webvtt/#webvtt-cue-position-automatic-alignment>
43 #[default]
44 Auto,
45}
46
47/// <https://w3c.github.io/webvtt/#webvtt-cue-position>
48#[derive(Clone, Debug, Default, PartialEq)]
49pub enum WebVttLineAndPositionSetting {
50 Double(f64),
51 #[default]
52 Auto,
53}
54
55/// <https://w3c.github.io/webvtt/#webvtt-cue-line-alignment>
56#[derive(Debug, Default, PartialEq)]
57pub enum WebVttLineAlignment {
58 /// <https://w3c.github.io/webvtt/#webvtt-cue-line-start-alignment>
59 #[default]
60 Start,
61 /// <https://w3c.github.io/webvtt/#webvtt-cue-line-center-alignment>
62 Center,
63 /// <https://w3c.github.io/webvtt/#webvtt-cue-line-end-alignment>
64 End,
65}
66
67/// <https://w3c.github.io/webvtt/#webvtt-cue-snap-to-lines-flag>
68/// This is an enum, since the default value is `true`
69#[derive(Debug, Default, PartialEq)]
70pub enum WebVttSnapToLines {
71 #[default]
72 Yes,
73 No,
74}
75
76impl From<bool> for WebVttSnapToLines {
77 fn from(boolean: bool) -> Self {
78 match boolean {
79 true => WebVttSnapToLines::Yes,
80 false => WebVttSnapToLines::No,
81 }
82 }
83}
84
85/// <https://w3c.github.io/webvtt/#webvtt-cue-size>
86/// This is a struct, since the default value is 100
87#[derive(Debug, PartialEq)]
88pub struct WebVttCueSize(pub f64);
89
90impl Default for WebVttCueSize {
91 fn default() -> Self {
92 Self(100.)
93 }
94}
95
96/// <https://w3c.github.io/webvtt/#webvtt-cue>
97#[derive(Debug, Default, PartialEq)]
98pub struct WebVttCue {
99 /// <https://html.spec.whatwg.org/multipage/#text-track-cue-identifier>
100 pub identifier: String,
101 /// <https://html.spec.whatwg.org/multipage/#text-track-cue-start-time>
102 pub start_time: f64,
103 /// <https://html.spec.whatwg.org/multipage/#text-track-cue-end-time>
104 pub end_time: f64,
105 /// <https://w3c.github.io/webvtt/#cue-text>
106 pub text: String,
107 /// <https://w3c.github.io/webvtt/#webvtt-cue-writing-direction>
108 pub writing_direction: WebVttWritingDirection,
109 /// <https://w3c.github.io/webvtt/#webvtt-cue-text-alignment>
110 pub text_alignment: WebVttTextAlignment,
111 /// <https://w3c.github.io/webvtt/#webvtt-cue-position-alignment>
112 pub position_alignment: WebVttPositionAlignment,
113 /// <https://w3c.github.io/webvtt/#webvtt-cue-position>
114 pub position: WebVttLineAndPositionSetting,
115 /// <https://w3c.github.io/webvtt/#webvtt-cue-line-alignment>
116 pub line_alignment: WebVttLineAlignment,
117 /// <https://w3c.github.io/webvtt/#webvtt-cue-line>
118 pub line: WebVttLineAndPositionSetting,
119 /// <https://w3c.github.io/webvtt/#webvtt-cue-snap-to-lines-flag>
120 pub snap_to_lines: WebVttSnapToLines,
121 /// <https://w3c.github.io/webvtt/#webvtt-cue-size>
122 pub size: WebVttCueSize,
123}