parent
806028ccbd
commit
5bb2d7d761
|
@ -6,6 +6,7 @@ node_modules
|
|||
# pkg
|
||||
*.docx#
|
||||
*.docx
|
||||
!fixtures/**/*.docx
|
||||
output/*.docx
|
||||
output/*.json
|
||||
output/*.xml
|
||||
|
|
|
@ -59,7 +59,7 @@ mod tests {
|
|||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&graphic).unwrap(),
|
||||
r#"{"children":[{"dataType":"wpShape","children":[{"type":"shape","data":{"children":[{"type":"textbox","data":{"children":[{"children":[{"type":"paragraph","data":{"id":"12345678","children":[{"type":"run","data":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"children":[{"type":"text","data":{"preserveSpace":true,"text":"pattern1"}}]}}],"property":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"hasNumbering":false}}],"has_numbering":false}],"hasNumbering":false}}]}}]}]}"#,
|
||||
r#"{"children":[{"dataType":"wpShape","children":[{"type":"shape","data":{"children":[{"type":"textbox","data":{"children":[{"children":[{"type":"paragraph","data":{"id":"12345678","children":[{"type":"run","data":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"vertAlign":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"children":[{"type":"text","data":{"preserveSpace":true,"text":"pattern1"}}]}}],"property":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"vertAlign":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"hasNumbering":false}}],"has_numbering":false}],"hasNumbering":false}}]}}]}]}"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ mod tests {
|
|||
.num_style_link("style1");
|
||||
assert_eq!(
|
||||
serde_json::to_string(&c).unwrap(),
|
||||
r#"{"id":0,"styleLink":null,"numStyleLink":"style1","levels":[{"level":1,"start":1,"format":"decimal","text":"%4.","jc":"left","paragraphProperty":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"suffix":"tab","pstyle":null,"levelRestart":null}]}"#,
|
||||
r#"{"id":0,"styleLink":null,"numStyleLink":"style1","levels":[{"level":1,"start":1,"format":"decimal","text":"%4.","jc":"left","paragraphProperty":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"vertAlign":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"vertAlign":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"suffix":"tab","pstyle":null,"levelRestart":null}]}"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,8 +83,9 @@ mod text_border;
|
|||
mod text_box_content;
|
||||
mod text_direction;
|
||||
mod underline;
|
||||
mod v_align;
|
||||
mod vanish;
|
||||
mod vertical_align;
|
||||
mod vert_align;
|
||||
mod vertical_merge;
|
||||
mod wp_anchor;
|
||||
mod wps_shape;
|
||||
|
@ -176,8 +177,9 @@ pub use text_border::*;
|
|||
pub use text_box_content::*;
|
||||
pub use text_direction::*;
|
||||
pub use underline::*;
|
||||
pub use v_align::*;
|
||||
pub use vanish::*;
|
||||
pub use vertical_align::*;
|
||||
pub use vert_align::*;
|
||||
pub use vertical_merge::*;
|
||||
pub use wp_anchor::*;
|
||||
pub use wps_shape::*;
|
||||
|
|
|
@ -325,7 +325,7 @@ mod tests {
|
|||
let p = Paragraph::new().add_run(run);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&p).unwrap(),
|
||||
r#"{"id":"12345678","children":[{"type":"run","data":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"children":[{"type":"text","data":{"preserveSpace":true,"text":"Hello"}}]}}],"property":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"hasNumbering":false}"#,
|
||||
r#"{"id":"12345678","children":[{"type":"run","data":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"vertAlign":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"children":[{"type":"text","data":{"preserveSpace":true,"text":"Hello"}}]}}],"property":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"vertAlign":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"hasNumbering":false}"#,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,7 @@ mod tests {
|
|||
let p = Paragraph::new().add_insert(ins);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&p).unwrap(),
|
||||
r#"{"id":"12345678","children":[{"type":"insert","data":{"children":[{"type":"run","data":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"children":[{"type":"text","data":{"preserveSpace":true,"text":"Hello"}}]}}],"author":"unnamed","date":"1970-01-01T00:00:00Z"}}],"property":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"hasNumbering":false}"#
|
||||
r#"{"id":"12345678","children":[{"type":"insert","data":{"children":[{"type":"run","data":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"vertAlign":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"children":[{"type":"text","data":{"preserveSpace":true,"text":"Hello"}}]}}],"author":"unnamed","date":"1970-01-01T00:00:00Z"}}],"property":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"vertAlign":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"hasNumbering":false}"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,7 +204,7 @@ mod tests {
|
|||
let b = c.indent(Some(20), Some(SpecialIndentType::FirstLine(10)), None, None);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&b).unwrap(),
|
||||
r#"{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":{"start":20,"startChars":null,"end":null,"specialIndent":{"type":"firstLine","val":10},"hangingChars":null,"firstLineChars":null},"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null}"#
|
||||
r#"{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"vertAlign":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":{"start":20,"startChars":null,"end":null,"specialIndent":{"type":"firstLine","val":10},"hangingChars":null,"firstLineChars":null},"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null}"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -283,7 +283,7 @@ mod tests {
|
|||
};
|
||||
assert_eq!(
|
||||
serde_json::to_string(&run).unwrap(),
|
||||
r#"{"runProperty":{"sz":30,"szCs":30,"color":"C9211E","highlight":"yellow","underline":"single","bold":true,"boldCs":true,"italic":true,"italicCs":true,"vanish":true,"spacing":100,"fonts":null,"textBorder":null,"del":null,"ins":null},"children":[{"type":"tab"},{"type":"text","data":{"preserveSpace":true,"text":"Hello"}},{"type":"break","data":{"breakType":"page"}},{"type":"deleteText","data":{"text":"deleted","preserveSpace":true}}]}"#,
|
||||
r#"{"runProperty":{"sz":30,"szCs":30,"color":"C9211E","highlight":"yellow","vertAlign":null,"underline":"single","bold":true,"boldCs":true,"italic":true,"italicCs":true,"vanish":true,"spacing":100,"fonts":null,"textBorder":null,"del":null,"ins":null},"children":[{"type":"tab"},{"type":"text","data":{"preserveSpace":true,"text":"Hello"}},{"type":"break","data":{"breakType":"page"}},{"type":"deleteText","data":{"text":"deleted","preserveSpace":true}}]}"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ use serde::Serialize;
|
|||
|
||||
use super::*;
|
||||
use crate::documents::BuildXML;
|
||||
use crate::types::*;
|
||||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, PartialEq)]
|
||||
|
@ -11,6 +12,7 @@ pub struct RunProperty {
|
|||
pub sz_cs: Option<SzCs>,
|
||||
pub color: Option<Color>,
|
||||
pub highlight: Option<Highlight>,
|
||||
pub vert_align: Option<VertAlign>,
|
||||
pub underline: Option<Underline>,
|
||||
pub bold: Option<Bold>,
|
||||
pub bold_cs: Option<BoldCs>,
|
||||
|
@ -50,6 +52,11 @@ impl RunProperty {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn vert_align(mut self, a: VertAlignType) -> Self {
|
||||
self.vert_align = Some(VertAlign::new(a));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn bold(mut self) -> RunProperty {
|
||||
self.bold = Some(Bold::new());
|
||||
self.bold_cs = Some(BoldCs::new());
|
||||
|
@ -112,6 +119,7 @@ impl Default for RunProperty {
|
|||
sz: None,
|
||||
sz_cs: None,
|
||||
highlight: None,
|
||||
vert_align: None,
|
||||
underline: None,
|
||||
bold: None,
|
||||
bold_cs: None,
|
||||
|
@ -148,6 +156,7 @@ impl BuildXML for RunProperty {
|
|||
.add_optional_child(&self.text_border)
|
||||
.add_optional_child(&self.ins)
|
||||
.add_optional_child(&self.del)
|
||||
.add_optional_child(&self.vert_align)
|
||||
.add_optional_child(&spacing)
|
||||
.close()
|
||||
.build()
|
||||
|
|
|
@ -185,7 +185,7 @@ mod tests {
|
|||
.grid_span(2);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&c).unwrap(),
|
||||
r#"{"children":[{"type":"paragraph","data":{"id":"12345678","children":[{"type":"run","data":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"children":[{"type":"text","data":{"preserveSpace":true,"text":"Hello"}}]}}],"property":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"hasNumbering":false}}],"property":{"width":null,"borders":null,"gridSpan":2,"verticalMerge":null,"verticalAlign":null,"textDirection":null,"shading":null},"hasNumbering":false}"#,
|
||||
r#"{"children":[{"type":"paragraph","data":{"id":"12345678","children":[{"type":"run","data":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"vertAlign":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"children":[{"type":"text","data":{"preserveSpace":true,"text":"Hello"}}]}}],"property":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"vertAlign":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null,"textBorder":null,"del":null,"ins":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null,"keepNext":false,"keepLines":false,"pageBreakBefore":false,"windowControl":false,"divId":null},"hasNumbering":false}}],"property":{"width":null,"borders":null,"gridSpan":2,"verticalMerge":null,"verticalAlign":null,"textDirection":null,"shading":null},"hasNumbering":false}"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
use serde::{Serialize, Serializer};
|
||||
|
||||
use crate::documents::BuildXML;
|
||||
use crate::types::*;
|
||||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct VertAlign {
|
||||
val: VertAlignType,
|
||||
}
|
||||
|
||||
impl VertAlign {
|
||||
pub fn new(val: VertAlignType) -> VertAlign {
|
||||
Self { val }
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for VertAlign {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(&format!("{}", &self.val))
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for VertAlign {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
let b = XMLBuilder::new();
|
||||
b.vert_align(&self.val.to_string() ).build()
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@ use std::str::FromStr;
|
|||
use xml::attribute::OwnedAttribute;
|
||||
use xml::reader::{EventReader, XmlEvent};
|
||||
|
||||
use crate::VertAlignType;
|
||||
|
||||
use super::*;
|
||||
|
||||
impl ElementReader for RunProperty {
|
||||
|
@ -28,6 +30,11 @@ impl ElementReader for RunProperty {
|
|||
rp = rp.bold();
|
||||
}
|
||||
XMLElement::Highlight => rp = rp.highlight(attributes[0].value.clone()),
|
||||
XMLElement::VertAlign => {
|
||||
if let Ok(v) = VertAlignType::from_str(&attributes[0].value) {
|
||||
rp = rp.vert_align(v)
|
||||
}
|
||||
}
|
||||
XMLElement::Color => rp = rp.color(attributes[0].value.clone()),
|
||||
XMLElement::Size => rp = rp.size(usize::from_str(&attributes[0].value)?),
|
||||
XMLElement::Spacing => {
|
||||
|
|
|
@ -24,6 +24,7 @@ pub enum XMLElement {
|
|||
ItalicCs,
|
||||
Text,
|
||||
Highlight,
|
||||
VertAlign,
|
||||
Bold,
|
||||
BoldCs,
|
||||
Break,
|
||||
|
@ -103,7 +104,6 @@ pub enum XMLElement {
|
|||
WidthBefore,
|
||||
Style,
|
||||
Next,
|
||||
VertAlign,
|
||||
Styles,
|
||||
Relationship,
|
||||
Relationships,
|
||||
|
|
|
@ -18,6 +18,7 @@ pub mod style_type;
|
|||
pub mod table_alignment_type;
|
||||
pub mod table_layout_type;
|
||||
pub mod text_direction_type;
|
||||
pub mod vert_align_type;
|
||||
pub mod vertical_align_type;
|
||||
pub mod vertical_merge_type;
|
||||
pub mod width_type;
|
||||
|
@ -42,6 +43,7 @@ pub use style_type::*;
|
|||
pub use table_alignment_type::*;
|
||||
pub use table_layout_type::*;
|
||||
pub use text_direction_type::*;
|
||||
pub use vert_align_type::*;
|
||||
pub use vertical_align_type::*;
|
||||
pub use vertical_merge_type::*;
|
||||
pub use width_type::*;
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use super::errors;
|
||||
|
||||
#[wasm_bindgen]
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum VertAlignType {
|
||||
Baseline,
|
||||
SuperScript,
|
||||
SubScript,
|
||||
Unsupported,
|
||||
}
|
||||
|
||||
// <xsd:enumeration value="baseline"/>
|
||||
// <xsd:enumeration value="superscript"/>
|
||||
// <xsd:enumeration value="subscript"/>
|
||||
impl fmt::Display for VertAlignType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
VertAlignType::SuperScript => write!(f, "superscript"),
|
||||
VertAlignType::SubScript => write!(f, "subscript"),
|
||||
VertAlignType::Baseline => write!(f, "baseline"),
|
||||
_ => write!(f, "unsupported"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for VertAlignType {
|
||||
type Err = errors::TypeError;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"subscript" => Ok(VertAlignType::SubScript),
|
||||
"superscript" => Ok(VertAlignType::SuperScript),
|
||||
"baseline" => Ok(VertAlignType::Baseline),
|
||||
_ => Ok(VertAlignType::Unsupported),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -75,6 +75,8 @@ impl XMLBuilder {
|
|||
closed_with_str!(name, "w:name");
|
||||
// i.e. <w:jc ... >
|
||||
closed_with_str!(justification, "w:jc");
|
||||
// i.e. <w:vertAlign ... >
|
||||
closed_with_str!(vert_align, "w:vertAlign");
|
||||
// i.e. <w:pStyle ... >
|
||||
closed_with_str!(paragraph_style, "w:pStyle");
|
||||
// i.e. <w:sz ... >
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -225,6 +225,14 @@ export class Docx {
|
|||
run = run.highlight(r.property.highlight);
|
||||
}
|
||||
|
||||
if (r.property.vertAlign) {
|
||||
if (r.property.vertAlign === "superscript") {
|
||||
run = run.vert_align(wasm.VertAlignType.SuperScript);
|
||||
} else if (r.property.vertAlign === "subscript") {
|
||||
run = run.vert_align(wasm.VertAlignType.SubScript);
|
||||
}
|
||||
}
|
||||
|
||||
if (r.property.bold) {
|
||||
run = run.bold();
|
||||
}
|
||||
|
@ -764,15 +772,8 @@ export class Docx {
|
|||
});
|
||||
|
||||
if (this.sectionProperty._pageMargin) {
|
||||
const {
|
||||
top,
|
||||
left,
|
||||
right,
|
||||
bottom,
|
||||
header,
|
||||
footer,
|
||||
gutter,
|
||||
} = this.sectionProperty._pageMargin;
|
||||
const { top, left, right, bottom, header, footer, gutter } =
|
||||
this.sectionProperty._pageMargin;
|
||||
const margin = wasm
|
||||
.createPageMargin()
|
||||
.top(top)
|
||||
|
|
|
@ -2,6 +2,7 @@ import { DrawingJSON } from "./drawing";
|
|||
import { CommentRangeStartJSON, CommentRangeEndJSON } from "..";
|
||||
import { BorderType } from "../border";
|
||||
import { InsertJSON, DeleteJSON } from "./paragraph";
|
||||
import { VertAlignType } from "../run";
|
||||
|
||||
export type TextBorderJSON = {
|
||||
borderType: BorderType;
|
||||
|
@ -15,6 +16,7 @@ export type RunPropertyJSON = {
|
|||
szCs: number | null;
|
||||
color: string | null;
|
||||
highlight: string | null;
|
||||
vertAlign: VertAlignType | null;
|
||||
underline: string | null;
|
||||
bold: boolean | null;
|
||||
boldCs: boolean | null;
|
||||
|
|
|
@ -13,10 +13,13 @@ export type TextBorder = {
|
|||
size: number;
|
||||
};
|
||||
|
||||
export type VertAlignType = "baseline" | "superscript" | "subscript";
|
||||
|
||||
export type RunProperty = {
|
||||
size?: number;
|
||||
color?: string;
|
||||
highlight?: string;
|
||||
vertAlign?: VertAlignType;
|
||||
bold?: boolean;
|
||||
italic?: boolean;
|
||||
underline?: string;
|
||||
|
@ -96,6 +99,11 @@ export class Run {
|
|||
return this;
|
||||
}
|
||||
|
||||
vertAlign(vertAlign: VertAlignType) {
|
||||
this.property = { ...this.property, vertAlign };
|
||||
return this;
|
||||
}
|
||||
|
||||
bold() {
|
||||
this.property = { ...this.property, bold: true };
|
||||
return this;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "docx-wasm",
|
||||
"version": "0.0.196",
|
||||
"version": "0.0.197",
|
||||
"main": "dist/node/index.js",
|
||||
"browser": "dist/web/index.js",
|
||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::*;
|
||||
use docx_rs::{BorderType, TextBorder};
|
||||
use docx_rs::{BorderType, TextBorder, VertAlignType};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
@ -86,6 +86,11 @@ impl Run {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn vert_align(mut self, a: VertAlignType) -> Run {
|
||||
self.0.run_property = self.0.run_property.vert_align(a);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text_border(
|
||||
mut self,
|
||||
border_type: BorderType,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -49,6 +49,12 @@ describe("reader", () => {
|
|||
const json = w.readDocx(buffer);
|
||||
expect(json).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("should read vertAlign docx", () => {
|
||||
const buffer = readFileSync("../fixtures/vert_align/vert_align.docx");
|
||||
const json = w.readDocx(buffer);
|
||||
expect(json).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe("writer", () => {
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue