-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support w:textAlignment (#690)
- Loading branch information
Showing
14 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use serde::{Serialize, Serializer}; | ||
|
||
use crate::documents::BuildXML; | ||
use crate::{xml_builder::*, TextAlignmentType}; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct TextAlignment(pub TextAlignmentType); | ||
|
||
impl TextAlignment { | ||
pub fn new(val: TextAlignmentType) -> TextAlignment { | ||
TextAlignment(val) | ||
} | ||
} | ||
|
||
impl BuildXML for TextAlignment { | ||
fn build(&self) -> Vec<u8> { | ||
let b = XMLBuilder::new(); | ||
let v = format!("{}", self.0); | ||
b.text_alignment(&v).build() | ||
} | ||
} | ||
|
||
impl Serialize for TextAlignment { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
let v = format!("{}", self.0); | ||
serializer.serialize_str(&v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::fmt; | ||
#[cfg(feature = "wasm")] | ||
use wasm_bindgen::prelude::*; | ||
|
||
use serde::Serialize; | ||
|
||
use super::errors; | ||
use std::str::FromStr; | ||
|
||
#[cfg_attr(feature = "wasm", wasm_bindgen, derive(ts_rs::TS), ts(export))] | ||
#[derive(Debug, Clone, Copy, PartialEq, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum TextAlignmentType { | ||
Auto, | ||
Baseline, | ||
Bottom, | ||
Center, | ||
Top, | ||
} | ||
|
||
impl fmt::Display for TextAlignmentType { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match *self { | ||
TextAlignmentType::Auto => write!(f, "auto"), | ||
TextAlignmentType::Baseline => write!(f, "baseline"), | ||
TextAlignmentType::Bottom => write!(f, "bottom"), | ||
TextAlignmentType::Center => write!(f, "center"), | ||
TextAlignmentType::Top => write!(f, "top"), | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for TextAlignmentType { | ||
type Err = errors::TypeError; | ||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"auto" => Ok(TextAlignmentType::Auto), | ||
"baseline" => Ok(TextAlignmentType::Baseline), | ||
"bottom" => Ok(TextAlignmentType::Bottom), | ||
"center" => Ok(TextAlignmentType::Center), | ||
"top" => Ok(TextAlignmentType::Top), | ||
_ => Err(errors::TypeError::FromStrError), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
export type TextAlignmentType = "auto" | "baseline" | "bottom" | "center" | "top"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.