rtf_parser_tt/
paragraph.rs1use serde::{Deserialize, Serialize};
3
4#[cfg(feature = "jsbindings")]
5use tsify::Tsify;
6#[cfg(feature = "jsbindings")]
7use wasm_bindgen::prelude::wasm_bindgen;
8
9use crate::tokens::ControlWord;
10
11#[derive(Debug, Default, Clone, Copy, PartialEq, Hash, Deserialize, Serialize)]
12#[cfg_attr(feature = "jsbindings", wasm_bindgen)]
13#[non_exhaustive]
14pub struct Paragraph {
15 pub alignment: Alignment,
16 pub spacing: Spacing,
17 pub indent: Indentation,
18 pub tab_width: i32,
19}
20
21#[derive(Debug, Default, Clone, Copy, PartialEq, Hash, Deserialize, Serialize)]
23#[cfg_attr(feature = "jsbindings", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
24#[non_exhaustive]
25pub enum Alignment {
26 #[default]
27 LeftAligned, RightAligned, Center, Justify, }
32
33impl From<&ControlWord<'_>> for Alignment {
34 fn from(cw: &ControlWord) -> Self {
35 match cw {
36 ControlWord::LeftAligned => Alignment::LeftAligned,
37 ControlWord::RightAligned => Alignment::RightAligned,
38 ControlWord::Center => Alignment::Center,
39 ControlWord::Justify => Alignment::Justify,
40 _ => Alignment::LeftAligned,
41 }
42 }
43}
44
45#[derive(Debug, Default, Clone, Copy, PartialEq, Hash, Deserialize, Serialize)]
47#[cfg_attr(feature = "jsbindings", wasm_bindgen)]
48#[non_exhaustive]
49pub struct Spacing {
50 pub before: i32,
51 pub after: i32,
52 pub between_line: SpaceBetweenLine,
53 pub line_multiplier: i32,
54}
55
56#[derive(Default, Debug, Clone, Copy, PartialEq, Hash, Deserialize, Serialize)]
57#[cfg_attr(feature = "jsbindings", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
58#[non_exhaustive]
59pub enum SpaceBetweenLine {
60 Value(i32),
61 #[default]
62 Auto,
63 Invalid,
64}
65
66impl From<i32> for SpaceBetweenLine {
71 fn from(value: i32) -> Self {
72 match value {
73 1000 => SpaceBetweenLine::Auto,
74 val if val < 0 => SpaceBetweenLine::Value(val.abs()),
75 val => SpaceBetweenLine::Value(val),
76 }
77 }
78}
79
80#[derive(Default, Debug, Clone, Copy, PartialEq, Hash, Deserialize, Serialize)]
82#[cfg_attr(feature = "jsbindings", wasm_bindgen)]
83#[non_exhaustive]
84pub struct Indentation {
85 pub left: i32,
86 pub right: i32,
87 pub first_line: i32,
88}