From 077de5d5611ac047172e466800a4e120e1c82b29 Mon Sep 17 00:00:00 2001 From: bokuweb Date: Fri, 2 May 2025 09:07:47 +0900 Subject: [PATCH] Add titlepg (#816) * feat: add title_pg * chore: rc46 * fix: add title_pg * fix: add title pg * rc47 * rc48 --- CHANGELOG.md | 1 + docx-core/src/documents/document.rs | 5 +++++ docx-core/src/documents/mod.rs | 5 +++++ docx-wasm/js/index.ts | 9 +++++++++ docx-wasm/js/section-property.ts | 6 ++++++ docx-wasm/package.json | 2 +- docx-wasm/src/doc.rs | 5 +++++ 7 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee3a067..c2a6e6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ 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) diff --git a/docx-core/src/documents/document.rs b/docx-core/src/documents/document.rs index 7a1967b..b79b702 100644 --- a/docx-core/src/documents/document.rs +++ b/docx-core/src/documents/document.rs @@ -140,6 +140,11 @@ 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 diff --git a/docx-core/src/documents/mod.rs b/docx-core/src/documents/mod.rs index 5644f38..4172f41 100644 --- a/docx-core/src/documents/mod.rs +++ b/docx-core/src/documents/mod.rs @@ -457,6 +457,11 @@ 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 diff --git a/docx-wasm/js/index.ts b/docx-wasm/js/index.ts index a2fe4f2..187c03a 100644 --- a/docx-wasm/js/index.ts +++ b/docx-wasm/js/index.ts @@ -152,6 +152,11 @@ export class Docx { return this; } + titlePg() { + this.sectionProperty.titlePg(); + return this; + } + pageSize(w: number, h: number) { this.sectionProperty.pageSize(w, h); return this; @@ -549,6 +554,10 @@ 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); diff --git a/docx-wasm/js/section-property.ts b/docx-wasm/js/section-property.ts index ac9d257..2dd6bc0 100644 --- a/docx-wasm/js/section-property.ts +++ b/docx-wasm/js/section-property.ts @@ -14,6 +14,7 @@ export class SectionProperty { w: 11906, h: 16838, }; + _titlePg: boolean | null = null; _pageMargin: PageMargin | null = null; _docGrid: DocGrid | null = null; _header: Header | null = null; @@ -24,6 +25,11 @@ 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; diff --git a/docx-wasm/package.json b/docx-wasm/package.json index 593b04b..b580609 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.4.18-rc45", + "version": "0.4.18-rc48", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ", diff --git a/docx-wasm/src/doc.rs b/docx-wasm/src/doc.rs index 7e2ec45..11d521d 100644 --- a/docx-wasm/src/doc.rs +++ b/docx-wasm/src/doc.rs @@ -123,6 +123,11 @@ 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