1use std::str::FromStr;
2use asai_macro::FromLine;
3use crate::structure::InvalidValue;
4use super::base_types::*;
5
6#[derive(Debug, Copy, Clone, Eq, PartialEq)]
7pub enum BorderStyle {
8 Outline,
9 Opaque,
10}
11
12impl<'a> TryFrom<LineField<'a>> for BorderStyle {
13 type Error = InvalidValue;
14
15 fn try_from(value: LineField<'a>) -> Result<Self, Self::Error> {
16 let i: u8 = value.value().parse()?;
17 match i {
18 1 => Ok(Self::Outline),
19 3 => Ok(Self::Opaque),
20 _ => Err(InvalidValue)
21 }
22 }
23}
24
25#[derive(Debug, Copy, Clone, Eq, PartialEq)]
26pub enum Alignment {
27 TopLeft,
28 TopCenter,
29 TopRight,
30 CenterLeft,
31 CenterCenter,
32 CenterRight,
33 BottomLeft,
34 BottomCenter,
35 BottomRight,
36}
37
38impl<'a> TryFrom<LineField<'a>> for Alignment {
39 type Error = InvalidValue;
40
41 fn try_from(value: LineField<'a>) -> Result<Self, Self::Error> {
42 let i: u8 = value.value().parse()?;
43 match i {
44 1 => {Ok(Self::BottomLeft)}
45 2 => {Ok(Self::BottomCenter)}
46 3 => {Ok(Self::BottomRight)}
47 4 => {Ok(Self::CenterLeft)}
48 5 => {Ok(Self::CenterCenter)}
49 6 => {Ok(Self::CenterRight)}
50 7 => {Ok(Self::TopLeft)}
51 8 => {Ok(Self::TopCenter)}
52 9 => {Ok(Self::TopRight)}
53 _ => Err(InvalidValue)
54 }
55 }
56}
57
58#[derive(FromLine, Debug, Clone, PartialEq)]
59pub struct Style<'a> {
60 #[name("Name")]
61 name: LineField<'a>,
62 #[name("Fontname")]
63 font_name: LineField<'a>,
64 #[name("Fontsize")]
65 font_size: u32,
66 #[name("PrimaryColour")]
67 primary_color: Color,
68 #[name("SecondaryColour")]
69 secondary_color: Color,
70 #[name("OutlineColor")]
71 outline_color: Color,
72 #[name("BackColour")]
73 background_color: Color,
74 #[name("Bold")]
75 bold: bool,
76 #[name("Italic")]
77 italic: bool,
78 #[name("Underline")]
79 underline: bool,
80 #[name("Strikeout")]
81 strikeout: bool,
82 #[name("ScaleX")]
83 scale_x: f32,
84 #[name("ScaleY")]
85 scale_y: f32,
86 #[name("Spacing")]
87 spacing: u32,
88 #[name("Angle")]
89 angle: f32,
90 #[name("BorderStyle")]
91 border_style: BorderStyle,
92 #[name("Outline")]
93 outline: f32,
94 #[name("Shadow")]
95 shadow: f32,
96 #[name("Alignment")]
97 alignment: Alignment,
98 #[name("MarginL")]
99 margin_l: u32,
100 #[name("MarginR")]
101 margin_r: u32,
102 #[name("MarginV")]
103 margin_v: u32,
104 #[name("Encoding")]
105 encoding: u32,
106}
107
108
109pub enum StyleKey {
110 Style,
111}
112
113impl FromStr for StyleKey {
114 type Err = InvalidValue;
115
116 fn from_str(s: &str) -> Result<Self, Self::Err> {
117 match s {
118 "Style" => Ok(Self::Style),
119 _ => Err(InvalidValue)
120 }
121 }
122}
123
124
125mod asai {
127 pub use crate::*;
128}