feat: Support specVanish (#559)

main
bokuweb 2022-11-01 15:10:06 +09:00 committed by GitHub
parent 698939d728
commit 154a61f3fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 12794 additions and 2 deletions

View File

@ -106,6 +106,7 @@ mod text_direction;
mod underline; mod underline;
mod v_align; mod v_align;
mod vanish; mod vanish;
mod spec_vanish;
mod vert_align; mod vert_align;
mod vertical_merge; mod vertical_merge;
mod wp_anchor; mod wp_anchor;
@ -221,6 +222,7 @@ pub use text_direction::*;
pub use underline::*; pub use underline::*;
pub use v_align::*; pub use v_align::*;
pub use vanish::*; pub use vanish::*;
pub use spec_vanish::*;
pub use vert_align::*; pub use vert_align::*;
pub use vertical_merge::*; pub use vertical_merge::*;
pub use wp_anchor::*; pub use wp_anchor::*;

View File

@ -33,6 +33,8 @@ pub struct RunProperty {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub vanish: Option<Vanish>, pub vanish: Option<Vanish>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub spec_vanish: Option<SpecVanish>,
#[serde(skip_serializing_if = "Option::is_none")]
pub character_spacing: Option<CharacterSpacing>, pub character_spacing: Option<CharacterSpacing>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub fonts: Option<RunFonts>, pub fonts: Option<RunFonts>,
@ -121,6 +123,11 @@ impl RunProperty {
self self
} }
pub fn spec_vanish(mut self) -> RunProperty {
self.spec_vanish = Some(SpecVanish::new());
self
}
pub fn fonts(mut self, font: RunFonts) -> RunProperty { pub fn fonts(mut self, font: RunFonts) -> RunProperty {
self.fonts = Some(font); self.fonts = Some(font);
self self
@ -157,6 +164,7 @@ impl BuildXML for RunProperty {
.add_optional_child(&self.highlight) .add_optional_child(&self.highlight)
.add_optional_child(&self.underline) .add_optional_child(&self.underline)
.add_optional_child(&self.vanish) .add_optional_child(&self.vanish)
.add_optional_child(&self.spec_vanish)
.add_optional_child(&self.fonts) .add_optional_child(&self.fonts)
.add_optional_child(&self.text_border) .add_optional_child(&self.text_border)
.add_optional_child(&self.ins) .add_optional_child(&self.ins)

View File

@ -0,0 +1,35 @@
use serde::{Deserialize, Serialize, Serializer};
use crate::documents::BuildXML;
use crate::xml_builder::*;
#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct SpecVanish {}
impl SpecVanish {
pub fn new() -> SpecVanish {
SpecVanish {}
}
}
impl Default for SpecVanish {
fn default() -> Self {
SpecVanish {}
}
}
impl BuildXML for SpecVanish {
fn build(&self) -> Vec<u8> {
let b = XMLBuilder::new();
b.spec_vanish().build()
}
}
impl Serialize for SpecVanish {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_bool(true)
}
}

View File

@ -107,6 +107,7 @@ impl ElementReader for RunProperty {
rp = rp.italic(); rp = rp.italic();
} }
XMLElement::Vanish => rp = rp.vanish(), XMLElement::Vanish => rp = rp.vanish(),
XMLElement::SpecVanish => rp = rp.spec_vanish(),
XMLElement::TextBorder => { XMLElement::TextBorder => {
if let Ok(attr) = read_border(&attributes) { if let Ok(attr) = read_border(&attributes) {
let mut border = TextBorder::new() let mut border = TextBorder::new()

View File

@ -20,6 +20,7 @@ pub enum XMLElement {
SizeCs, SizeCs,
Spacing, Spacing,
Vanish, Vanish,
SpecVanish,
TextBorder, TextBorder,
Italic, Italic,
ItalicCs, ItalicCs,
@ -256,6 +257,7 @@ impl FromStr for XMLElement {
"i" => Ok(XMLElement::Italic), "i" => Ok(XMLElement::Italic),
"iCs" => Ok(XMLElement::ItalicCs), "iCs" => Ok(XMLElement::ItalicCs),
"vanish" => Ok(XMLElement::Vanish), "vanish" => Ok(XMLElement::Vanish),
"specVanish" => Ok(XMLElement::SpecVanish),
"italic" => Ok(XMLElement::Italic), "italic" => Ok(XMLElement::Italic),
"name" => Ok(XMLElement::Name), "name" => Ok(XMLElement::Name),
"tab" => Ok(XMLElement::Tab), "tab" => Ok(XMLElement::Tab),

View File

@ -410,6 +410,7 @@ impl XMLBuilder {
closed_with_str!(level_justification, "w:lvlJc"); closed_with_str!(level_justification, "w:lvlJc");
closed_with_str!(abstract_num_id, "w:abstractNumId"); closed_with_str!(abstract_num_id, "w:abstractNumId");
closed!(vanish, "w:vanish"); closed!(vanish, "w:vanish");
closed!(spec_vanish, "w:specVanish");
open!(open_drawing, "w:drawing"); open!(open_drawing, "w:drawing");
open!(open_anchor, "wp:anchor"); open!(open_anchor, "wp:anchor");

View File

@ -40,6 +40,7 @@ export type RunPropertyJSON = {
italic?: boolean | null; italic?: boolean | null;
italicCs?: boolean | null; italicCs?: boolean | null;
vanish?: boolean | null; vanish?: boolean | null;
specVanish?: boolean | null;
spacing?: number | null; spacing?: number | null;
textBorder?: TextBorderJSON | null; textBorder?: TextBorderJSON | null;
ins?: InsertJSONData | null; ins?: InsertJSONData | null;

File diff suppressed because it is too large Load Diff

View File

@ -166,7 +166,9 @@ describe("reader", () => {
}); });
test("should read sectionProperty in ppr", () => { test("should read sectionProperty in ppr", () => {
const buffer = readFileSync("../fixtures/section_property_in_ppr/section_property_in_ppr.docx"); const buffer = readFileSync(
"../fixtures/section_property_in_ppr/section_property_in_ppr.docx"
);
const json = w.readDocx(buffer); const json = w.readDocx(buffer);
expect(json).toMatchSnapshot(); expect(json).toMatchSnapshot();
}); });
@ -176,6 +178,12 @@ describe("reader", () => {
const json = w.readDocx(buffer); const json = w.readDocx(buffer);
expect(json).toMatchSnapshot(); expect(json).toMatchSnapshot();
}); });
test("should read specVanish", () => {
const buffer = readFileSync("../fixtures/spec_vanish/spec_vanish.docx");
const json = w.readDocx(buffer);
expect(json).toMatchSnapshot();
});
}); });
describe("writer", () => { describe("writer", () => {
@ -202,7 +210,6 @@ describe("writer", () => {
} }
} }
writeFileSync("../output/js/align.docx", buffer); writeFileSync("../output/js/align.docx", buffer);
}); });
test("should write strike", () => { test("should write strike", () => {

Binary file not shown.