json2pdf_client/protocol/elements/
paragraph.rs

1use crate::protocol::elements::Element;
2use serde::Serialize;
3
4/// A paragraph
5#[derive(Debug, Clone, Serialize)]
6#[serde(rename_all = "camelCase")]
7pub struct Paragraph {
8    #[serde(skip_serializing_if = "Option::is_none")]
9    font_color: Option<String>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    font_size: Option<f32>,
12    text: String,
13}
14
15impl Paragraph {
16    /// Create a new paragraph
17    pub fn new<S: AsRef<str>>(text: S) -> Self {
18        Self {
19            font_color: None,
20            font_size: None,
21            text: text.as_ref().to_string(),
22        }
23    }
24
25    /// Set the font color. Must be six digit hex without the `#` prefix
26    pub fn font_color(mut self, color: String) -> Self {
27        self.font_color = Some(color);
28        self
29    }
30
31    /// Set the font size
32    pub fn font_size(mut self, size: f32) -> Self {
33        self.font_size = Some(size);
34        self
35    }
36}
37
38#[allow(clippy::from_over_into)]
39impl Into<Element> for Paragraph {
40    fn into(self) -> Element {
41        Element::paragraph(self)
42    }
43}