1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::Parse;
use skia_safe::textlayout::{TextDecoration, TextDecorationStyle};

#[derive(Debug, PartialEq, Eq)]
pub struct ParseTextDecorationError;

impl Parse for TextDecoration {
    type Err = ParseTextDecorationError;

    fn parse(value: &str) -> Result<Self, Self::Err> {
        let mut decoration = TextDecoration::default();
        let values = value.split_ascii_whitespace();

        for val in values {
            decoration.set(
                match val {
                    "underline" => TextDecoration::UNDERLINE,
                    "overline" => TextDecoration::OVERLINE,
                    "line-through" => TextDecoration::LINE_THROUGH,
                    _ => TextDecoration::NO_DECORATION,
                },
                true,
            );
        }

        Ok(decoration)
    }
}

#[derive(Debug, PartialEq, Eq)]
pub struct ParseTextDecorationStyleError;

impl Parse for TextDecorationStyle {
    type Err = ParseTextDecorationStyleError;

    fn parse(value: &str) -> Result<Self, Self::Err> {
        Ok(match value {
            "solid" => TextDecorationStyle::Solid,
            "double" => TextDecorationStyle::Double,
            "dotted" => TextDecorationStyle::Dotted,
            "dashed" => TextDecorationStyle::Dashed,
            "wavy" => TextDecorationStyle::Wavy,
            _ => TextDecorationStyle::Solid,
        })
    }
}