Skip to content

Commit

Permalink
fix: add page num type writer
Browse files Browse the repository at this point in the history
  • Loading branch information
bokuweb committed Mar 4, 2024
1 parent d17c669 commit dbc7db9
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docx-core/src/documents/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ impl Document {
self.section_property.text_direction = direction;
self
}

pub fn page_num_type(mut self, p: PageNumType) -> Self {
self.section_property = self.section_property.page_num_type(p);
self
}
}

impl BuildXML for DocumentChild {
Expand Down
5 changes: 5 additions & 0 deletions docx-core/src/documents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ impl Docx {
self
}

pub fn page_num_type(mut self, p: PageNumType) -> Self {
self.document = self.document.page_num_type(p);
self
}

pub fn build(mut self) -> XMLDocx {
self.reset();

Expand Down
6 changes: 6 additions & 0 deletions docx-wasm/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ export class Docx {
}
}

if (this.sectionProperty._pageTypeNum) {
const { start, chapStyle } = this.sectionProperty._pageTypeNum;
const p = wasm.createPageNumType(start, chapStyle);
docx = docx.page_num_type(p);
}

if (this.sectionProperty._docGrid) {
const { gridType, charSpace, linePitch } = this.sectionProperty._docGrid;
let type = wasm.DocGridType.Default;
Expand Down
7 changes: 7 additions & 0 deletions docx-wasm/js/section-property.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DocGridType } from ".";
import { Footer } from "./footer";
import { Header } from "./header";
import { PageNumType } from "./json/bindings/PageNumType";

export type DocGrid = {
gridType: DocGridType;
Expand All @@ -21,6 +22,7 @@ export class SectionProperty {
_footer: Footer | null = null;
_firstFooter: Footer | null = null;
_evenFooter: Footer | null = null;
_pageTypeNum: PageNumType | null = null;

pageSize(w: number, h: number) {
this._pageSize.w = w;
Expand Down Expand Up @@ -72,6 +74,11 @@ export class SectionProperty {
this._evenFooter = footer;
return this;
}

pageTypeNum(start?: number, chapStyle?: string) {
this._pageTypeNum = { start, chapStyle };
return this;
}
}

export type PageOrientationType = "landscape" | "portrait";
Expand Down
5 changes: 5 additions & 0 deletions docx-wasm/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ impl Docx {
self
}

pub fn page_num_type(mut self, p: PageNumType) -> Self {
self.0 = self.0.page_num_type(p.take());
self
}

pub fn doc_grid(
mut self,
grid_type: docx_rs::DocGridType,
Expand Down
2 changes: 2 additions & 0 deletions docx-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod level_override;
mod line_spacing;
mod numbering;
mod page_margin;
mod page_num_type;
mod paragraph;
mod pic;
mod reader;
Expand Down Expand Up @@ -40,6 +41,7 @@ pub use level_override::*;
pub use line_spacing::*;
pub use numbering::*;
pub use page_margin::*;
pub use page_num_type::*;
pub use paragraph::*;
pub use pic::*;
pub use reader::*;
Expand Down
23 changes: 23 additions & 0 deletions docx-wasm/src/page_num_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
#[derive(Debug)]
pub struct PageNumType(docx_rs::PageNumType);

#[wasm_bindgen(js_name = createPageNumType)]
pub fn create_page_num_type(start: Option<u32>, chap_style: Option<String>) -> PageNumType {
let mut p = docx_rs::PageNumType::new();
if let Some(start) = start {
p = p.start(start);
}
if let Some(chap_style) = chap_style {
p = p.chap_style(chap_style);
}
PageNumType(p)
}

impl PageNumType {
pub fn take(self) -> docx_rs::PageNumType {
self.0
}
}

0 comments on commit dbc7db9

Please sign in to comment.