Compare commits

..

No commits in common. "f5fda75a96c90ab0931c7804d2d95a893c4ea2cd" and "c492b86abad1d37d5d5ba66389cb086278fdbe2b" have entirely different histories.

35 changed files with 19 additions and 3676 deletions

View File

@ -10,7 +10,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support `dstrike`
- Update Add after for default toc styles #806
- Update `Level` styles.
- Support `titlePg`
-->
## @0.4.17 (26. Apr, 2024)

4
Cargo.lock generated
View File

@ -28,9 +28,9 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "base64"
version = "0.22.1"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]]
name = "bitflags"

View File

@ -29,7 +29,7 @@ thiserror = "1.0"
zip = { version = "0.6.3", default-features = false, features = ["deflate"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = {version = "1.0" }
base64 = "0.22.1"
base64 = "0.13.1"
image = { version = "0.24.4", default-features = false, features=["gif", "jpeg", "png", "bmp", "tiff"], optional = true }
wasm-bindgen = { version = "0.2.78", optional = true }
ts-rs = { version = "6.1", optional = true }

View File

@ -140,11 +140,6 @@ impl Document {
self
}
pub fn title_pg(mut self) -> Self {
self.section_property = self.section_property.title_pg();
self
}
pub fn page_size(mut self, size: PageSize) -> Self {
self.section_property = self.section_property.page_size(size);
self

View File

@ -40,10 +40,6 @@ impl BuildXML for Bold {
&self,
stream: xml::writer::EventWriter<W>,
) -> xml::writer::Result<xml::writer::EventWriter<W>> {
if self.val {
XMLBuilder::from(stream).b()?.into_inner()
} else {
XMLBuilder::from(stream).disable_bold()?.into_inner()
}
XMLBuilder::from(stream).b()?.into_inner()
}
}

View File

@ -40,10 +40,6 @@ impl BuildXML for Dstrike {
&self,
stream: xml::writer::EventWriter<W>,
) -> xml::writer::Result<xml::writer::EventWriter<W>> {
if self.val {
XMLBuilder::from(stream).dstrike()?.into_inner()
} else {
XMLBuilder::from(stream).disable_dstrike()?.into_inner()
}
XMLBuilder::from(stream).dstrike()?.into_inner()
}
}

View File

@ -40,10 +40,6 @@ impl BuildXML for Italic {
&self,
stream: xml::writer::EventWriter<W>,
) -> xml::writer::Result<xml::writer::EventWriter<W>> {
if self.val {
XMLBuilder::from(stream).i()?.into_inner()
} else {
XMLBuilder::from(stream).disable_italic()?.into_inner()
}
XMLBuilder::from(stream).i()?.into_inner()
}
}

View File

@ -94,7 +94,6 @@ mod shading;
mod shape;
mod spec_vanish;
mod start;
mod stretch;
mod strike;
mod structured_data_tag;
mod structured_data_tag_property;
@ -233,7 +232,6 @@ pub use shading::*;
pub use shape::*;
pub use spec_vanish::*;
pub use start::*;
pub use stretch::*;
pub use strike::*;
pub use structured_data_tag::*;
pub use structured_data_tag_property::*;

View File

@ -263,11 +263,6 @@ impl Run {
self
}
pub fn stretch(mut self, v: i32) -> Run {
self.run_property = self.run_property.stretch(v);
self
}
pub fn color(mut self, color: impl Into<String>) -> Run {
self.run_property = self.run_property.color(color);
self

View File

@ -40,8 +40,6 @@ pub struct RunProperty {
#[serde(skip_serializing_if = "Option::is_none")]
pub character_spacing: Option<CharacterSpacing>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stretch: Option<Stretch>,
#[serde(skip_serializing_if = "Option::is_none")]
pub fonts: Option<RunFonts>,
#[serde(skip_serializing_if = "Option::is_none")]
pub text_border: Option<TextBorder>,
@ -171,11 +169,6 @@ impl RunProperty {
self
}
pub fn stretch(mut self, v: i32) -> RunProperty {
self.stretch = Some(Stretch::new(v));
self
}
pub fn text_border(mut self, b: TextBorder) -> Self {
self.text_border = Some(b);
self
@ -229,7 +222,6 @@ impl BuildXML for RunProperty {
.add_optional_child(&self.del)?
.add_optional_child(&self.vert_align)?
.add_optional_child(&self.character_spacing)?
.add_optional_child(&self.stretch)?
.add_optional_child(&self.style)?
.add_optional_child(&self.positional_tab)?
.add_optional_child(&self.shading)?
@ -326,16 +318,6 @@ mod tests {
);
}
#[test]
fn test_stretch() {
let c = RunProperty::new().stretch(80);
let b = c.build();
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<w:rPr><w:w w:val="80" /></w:rPr>"#
);
}
#[test]
fn test_ptab() {
let c = RunProperty::new().ptab(PositionalTab::new(

View File

@ -1,55 +0,0 @@
use crate::documents::BuildXML;
use crate::xml_builder::*;
use std::io::Write;
use serde::*;
#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct Stretch {
value: i32,
}
impl Stretch {
pub fn new(s: i32) -> Stretch {
Self { value: s }
}
}
impl BuildXML for Stretch {
fn build_to<W: Write>(
&self,
stream: xml::writer::EventWriter<W>,
) -> xml::writer::Result<xml::writer::EventWriter<W>> {
XMLBuilder::from(stream).w(self.value)?.into_inner()
}
}
impl Serialize for Stretch {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_i32(self.value)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[cfg(test)]
use pretty_assertions::assert_eq;
use std::str;
#[test]
fn test_stretch() {
let b = Stretch::new(200).build();
assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:w w:val="200" />"#);
}
#[test]
fn test_stretch_json() {
let s = Stretch { value: 100 };
assert_eq!(serde_json::to_string(&s).unwrap(), r#"100"#);
}
}

View File

@ -40,10 +40,6 @@ impl BuildXML for Strike {
&self,
stream: xml::writer::EventWriter<W>,
) -> xml::writer::Result<xml::writer::EventWriter<W>> {
if self.val {
XMLBuilder::from(stream).strike()?.into_inner()
} else {
XMLBuilder::from(stream).disable_strike()?.into_inner()
}
XMLBuilder::from(stream).strike()?.into_inner()
}
}

View File

@ -78,7 +78,6 @@ pub use web_settings::*;
pub use webextension::*;
pub use xml_docx::*;
use base64::Engine;
use serde::{ser, Serialize};
use self::image_collector::{collect_images_from_paragraph, collect_images_from_table};
@ -97,7 +96,7 @@ impl ser::Serialize for Image {
where
S: ser::Serializer,
{
let base64 = base64::engine::general_purpose::STANDARD.encode(&self.0);
let base64 = base64::display::Base64Display::with_config(&self.0, base64::STANDARD);
serializer.collect_str(&base64)
}
}
@ -107,7 +106,7 @@ impl ser::Serialize for Png {
where
S: ser::Serializer,
{
let base64 = base64::engine::general_purpose::STANDARD.encode(&self.0);
let base64 = base64::display::Base64Display::with_config(&self.0, base64::STANDARD);
serializer.collect_str(&base64)
}
}
@ -458,11 +457,6 @@ impl Docx {
self
}
pub fn title_pg(mut self) -> Self {
self.document = self.document.title_pg();
self
}
pub fn page_size(mut self, w: u32, h: u32) -> Self {
self.document = self.document.page_size(PageSize::new().size(w, h));
self

View File

@ -67,9 +67,7 @@ impl ElementReader for Level {
is_lgl = Some(IsLgl::new());
}
XMLElement::LevelText => {
if !attributes.is_empty() {
level_text = LevelText::new(attributes[0].value.clone());
}
level_text = LevelText::new(attributes[0].value.clone());
}
XMLElement::LevelRestart => {
if let Ok(v) = u32::from_str(&attributes[0].value) {

View File

@ -418,7 +418,6 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
)?;
let nums = Numberings::from_xml(&data[..])?;
docx = docx.numberings(nums);
docx.document_rels.has_numberings = true;
}
}

View File

@ -92,13 +92,6 @@ impl ElementReader for RunProperty {
}
rp = rp.strike();
}
XMLElement::Dstrike => {
if !read_bool(&attributes) {
rp.dstrike = Some(Dstrike::new().disable());
continue;
}
rp = rp.dstrike();
}
XMLElement::VertAlign => {
if let Ok(v) = VertAlignType::from_str(&attributes[0].value) {
rp = rp.vert_align(v)
@ -128,11 +121,6 @@ impl ElementReader for RunProperty {
}
rp = rp.italic();
}
XMLElement::Shading => {
if let Ok(shd) = Shading::read(r, &attributes) {
rp = rp.shading(shd);
}
}
XMLElement::Vanish => rp = rp.vanish(),
XMLElement::SpecVanish => rp = rp.spec_vanish(),
XMLElement::TextBorder => {

View File

@ -183,39 +183,14 @@ impl<W: Write> XMLBuilder<W> {
closed!(b, "w:b");
closed!(b_cs, "w:bCs");
pub(crate) fn disable_bold(self) -> Result<Self> {
let f = "false";
self.write(XmlEvent::start_element("w:b").attr("w:val", &f))?
.close()
}
closed_with_str!(caps, "w:caps");
closed!(i, "w:i");
closed!(i_cs, "w:iCs");
pub(crate) fn disable_italic(self) -> Result<Self> {
let f = "false";
self.write(XmlEvent::start_element("w:i").attr("w:val", &f))?
.close()
}
closed!(strike, "w:strike");
pub(crate) fn disable_strike(self) -> Result<Self> {
let f = "false";
self.write(XmlEvent::start_element("w:strike").attr("w:val", &f))?
.close()
}
closed!(dstrike, "w:dstrike");
pub(crate) fn disable_dstrike(self) -> Result<Self> {
let f = "false";
self.write(XmlEvent::start_element("w:dstrike").attr("w:val", &f))?
.close()
}
// Build w:style element
// i.e. <w:style ... >
pub(crate) fn open_style(self, style_type: StyleType, id: &str) -> Result<Self> {
@ -278,12 +253,6 @@ impl<W: Write> XMLBuilder<W> {
.close()
}
// i.e. <w:w ... >
pub(crate) fn w(self, s: i32) -> Result<Self> {
self.write(XmlEvent::start_element("w:w").attr("w:val", &format!("{}", s)))?
.close()
}
// i.e. <w:spacing ... >
pub(crate) fn line_spacing(
self,
@ -502,7 +471,7 @@ impl<W: Write> XMLBuilder<W> {
closed!(keep_lines, "w:keepLines");
closed!(page_break_before, "w:pageBreakBefore");
closed!(widow_control, "w:widowControl", "w:val");
closed!(bidi, "w:bidi");
closed!(bidi,"w:bidi");
/*
<w:lvlOverride w:ilvl="0">
<w:startOverride w:val="1"/>

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

View File

@ -152,11 +152,6 @@ export class Docx {
return this;
}
titlePg() {
this.sectionProperty.titlePg();
return this;
}
pageSize(w: number, h: number) {
this.sectionProperty.pageSize(w, h);
return this;
@ -554,10 +549,6 @@ export class Docx {
}
}
if (this.sectionProperty._titlePg) {
docx = docx.title_pg();
}
if (this.sectionProperty._pageTypeNum) {
const { start, chapStyle } = this.sectionProperty._pageTypeNum;
const p = wasm.createPageNumType(start, chapStyle);

View File

@ -5,7 +5,6 @@ import {
CommentRangeEndJSON,
InsertJSONData,
DeleteJSONData,
ShadingJSON,
} from "..";
import { BorderType } from "../border";
import { VertAlignType } from "../run-property";
@ -57,7 +56,6 @@ export type RunPropertyJSON = {
del?: DeleteJSONData | null;
strike?: boolean;
dstrike?: boolean;
shading?: ShadingJSON | null;
};
export type RunChildJSON =

View File

@ -1,7 +1,6 @@
import * as wasm from "./pkg/docx_wasm";
import { BorderType } from "./border";
import { Shading } from "./shading";
export type TextBorder = {
borderType: BorderType;
@ -39,7 +38,6 @@ export class RunProperty {
_textBorder?: TextBorder;
_ins?: RunPropertyIns;
_del?: RunPropertyDel;
_shading?: Shading;
style(style: string) {
this._style = style;
@ -145,15 +143,6 @@ export class RunProperty {
};
return this;
}
shading(type: string, color: string, fill: string) {
const s = new Shading();
s.color(color);
s.fill(fill);
s.type(type);
this._shading = s;
return this;
}
}
export const convertBorderType = (t: BorderType) => {
@ -351,14 +340,6 @@ export const setRunProperty = <T extends wasm.Run | wasm.Style>(
target = target.fonts(fonts) as T;
}
if (property._shading != null) {
target = target.shading(
property._shading._type,
property._shading._color,
property._shading._fill
) as T;
}
return target;
};
@ -448,13 +429,5 @@ export const createRunProperty = (property: RunProperty): wasm.RunProperty => {
target = target.fonts(fonts);
}
if (property._shading != null) {
target = target.shading(
property._shading._type,
property._shading._color,
property._shading._fill
);
}
return target;
};

View File

@ -160,12 +160,6 @@ export class Run {
return this;
}
shading(type: string, color: string, fill: string) {
this.property ??= createDefaultRunProperty();
this.property.shading(type, color, fill);
return this;
}
build() {
let run = wasm.createRun();
this.children.forEach((child) => {

View File

@ -14,7 +14,6 @@ export class SectionProperty {
w: 11906,
h: 16838,
};
_titlePg: boolean | null = null;
_pageMargin: PageMargin | null = null;
_docGrid: DocGrid | null = null;
_header: Header | null = null;
@ -25,11 +24,6 @@ export class SectionProperty {
_evenFooter: Footer | null = null;
_pageTypeNum: PageNumType | null = null;
titlePg() {
this._titlePg = true;
return this;
}
pageSize(w: number, h: number) {
this._pageSize.w = w;
this._pageSize.h = h;

View File

@ -1,6 +1,6 @@
{
"name": "docx-wasm",
"version": "0.4.18-rc48",
"version": "0.4.18-rc41",
"main": "dist/node/index.js",
"browser": "dist/web/index.js",
"author": "bokuweb <bokuweb12@gmail.com>",

View File

@ -123,11 +123,6 @@ impl Docx {
self
}
pub fn title_pg(mut self) -> Docx {
self.0 = self.0.title_pg();
self
}
pub fn page_size(mut self, w: u32, h: u32) -> Docx {
self.0 = self.0.page_size(w, h);
self

View File

@ -1,6 +1,5 @@
use super::*;
use docx_rs::{BorderType, Shading, TextBorder, VertAlignType};
use std::str::FromStr;
use docx_rs::{BorderType, TextBorder, VertAlignType};
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
@ -138,15 +137,6 @@ impl Run {
self
}
pub fn shading(mut self, t: &str, color: &str, fill: &str) -> Self {
let mut s = Shading::new().color(color).fill(fill);
if let Ok(t) = docx_rs::ShdType::from_str(t) {
s = s.shd_type(t);
}
self.0.run_property = self.0.run_property.shading(s);
self
}
pub fn text_border(
mut self,
border_type: BorderType,

View File

@ -1,7 +1,5 @@
use super::*;
use wasm_bindgen::prelude::*;
use std::str::FromStr;
#[wasm_bindgen]
pub struct RunProperty(docx_rs::RunProperty);
@ -132,15 +130,6 @@ impl RunProperty {
self.0 = self.0.text_border(border);
self
}
pub fn shading(mut self, t: &str, color: &str, fill: &str) -> Self {
let mut s = docx_rs::Shading::new().color(color).fill(fill);
if let Ok(t) = docx_rs::ShdType::from_str(t) {
s = s.shd_type(t);
}
self.0 = self.0.shading(s);
self
}
}
impl RunProperty {

View File

@ -1,6 +1,5 @@
use super::*;
use docx_rs::{BorderType, Shading, TextBorder, VertAlignType, WidthType};
use std::str::FromStr;
use docx_rs::{BorderType, TextBorder, VertAlignType, WidthType};
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
@ -64,15 +63,6 @@ impl Style {
self
}
pub fn shading(mut self, t: &str, color: &str, fill: &str) -> Self {
let mut s = Shading::new().color(color).fill(fill);
if let Ok(t) = docx_rs::ShdType::from_str(t) {
s = s.shd_type(t);
}
self.0.run_property = self.0.run_property.shading(s);
self
}
pub fn link(mut self, link: &str) -> Self {
self.0 = self.0.link(link);
self

File diff suppressed because it is too large Load Diff

View File

@ -220,12 +220,6 @@ describe("reader", () => {
const json = w.readDocx(buffer);
expect(json).toMatchSnapshot();
});
test("should read dstrike", () => {
const buffer = readFileSync("../fixtures/dstrike/dstrike.docx");
const json = w.readDocx(buffer);
expect(json).toMatchSnapshot();
});
});
describe("writer", () => {
@ -470,20 +464,6 @@ describe("writer", () => {
}
});
test("should write shd", () => {
const p = new w.Paragraph()
.addRun(new w.Run().addText("Hello "))
.addRun(new w.Run().addText("World!").shading("clear", "auto", "FFC000"));
const buffer = new w.Docx().addParagraph(p).build();
writeFileSync("../output/js/shading.docx", buffer);
const z = new Zip(Buffer.from(buffer));
for (const e of z.getEntries()) {
if (e.entryName.match(/document.xml|numbering.xml/)) {
expect(z.readAsText(e)).toMatchSnapshot();
}
}
});
test("should write page orientation", () => {
const p = new w.Paragraph().addRun(new w.Run().addText("Hello "));
const buffer = new w.Docx()

Binary file not shown.

View File

@ -1 +1 @@
1.85
1.73