parent
83139b233e
commit
dcc524e6c9
|
@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## @0.4.15 (12. Apr, 2024)
|
## @0.4.16 (24. Apr, 2024)
|
||||||
|
|
||||||
|
- Fixed a `framePr`
|
||||||
|
|
||||||
|
## @0.4.14 (12. Apr, 2024)
|
||||||
|
|
||||||
- Remove `dbg!`
|
- Remove `dbg!`
|
||||||
- Support `caps`
|
- Support `caps`
|
||||||
|
|
|
@ -9,6 +9,8 @@ pub struct PageNum {
|
||||||
pub instr: InstrPAGE,
|
pub instr: InstrPAGE,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub frame_property: Option<FrameProperty>,
|
pub frame_property: Option<FrameProperty>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub paragraph_property: Option<ParagraphProperty>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PageNum {
|
impl Default for PageNum {
|
||||||
|
@ -16,6 +18,7 @@ impl Default for PageNum {
|
||||||
Self {
|
Self {
|
||||||
instr: InstrPAGE {},
|
instr: InstrPAGE {},
|
||||||
frame_property: None,
|
frame_property: None,
|
||||||
|
paragraph_property: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,6 +124,15 @@ impl PageNum {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn align(mut self, alignment_type: AlignmentType) -> Self {
|
||||||
|
self.paragraph_property = Some(
|
||||||
|
self.paragraph_property
|
||||||
|
.unwrap_or_default()
|
||||||
|
.align(alignment_type),
|
||||||
|
);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
fn inner_build(&self) -> Vec<u8> {
|
fn inner_build(&self) -> Vec<u8> {
|
||||||
let p = StructuredDataTagProperty::new();
|
let p = StructuredDataTagProperty::new();
|
||||||
let mut b = XMLBuilder::new();
|
let mut b = XMLBuilder::new();
|
||||||
|
@ -139,6 +151,10 @@ impl PageNum {
|
||||||
.add_field_char(FieldCharType::End, false),
|
.add_field_char(FieldCharType::End, false),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if let Some(ref pr) = self.paragraph_property {
|
||||||
|
p.property = pr.clone();
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ref f) = self.frame_property {
|
if let Some(ref f) = self.frame_property {
|
||||||
p.property.frame_property = Some(f.clone());
|
p.property.frame_property = Some(f.clone());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
import {
|
||||||
|
AlignmentType,
|
||||||
|
ParagraphProperty,
|
||||||
|
createDefaultParagraphProperty,
|
||||||
|
createParagraphAlignment,
|
||||||
|
} from "./paragraph-property";
|
||||||
import * as wasm from "./pkg/docx_wasm";
|
import * as wasm from "./pkg/docx_wasm";
|
||||||
|
|
||||||
export type FrameProperty = {
|
export type FrameProperty = {
|
||||||
|
@ -17,6 +23,7 @@ export type FrameProperty = {
|
||||||
|
|
||||||
export class PageNum {
|
export class PageNum {
|
||||||
frameProperty: FrameProperty | null = null;
|
frameProperty: FrameProperty | null = null;
|
||||||
|
paragraphProperty: ParagraphProperty | null = null;
|
||||||
|
|
||||||
height(h: number) {
|
height(h: number) {
|
||||||
this.frameProperty = { ...this.frameProperty };
|
this.frameProperty = { ...this.frameProperty };
|
||||||
|
@ -89,6 +96,14 @@ export class PageNum {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
align(align: AlignmentType) {
|
||||||
|
this.paragraphProperty = {
|
||||||
|
...createDefaultParagraphProperty(),
|
||||||
|
align,
|
||||||
|
};
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
let pageNum = wasm.createPageNum();
|
let pageNum = wasm.createPageNum();
|
||||||
if (this.frameProperty?.h != null) {
|
if (this.frameProperty?.h != null) {
|
||||||
|
@ -127,6 +142,12 @@ export class PageNum {
|
||||||
if (this.frameProperty?.yAlign != null) {
|
if (this.frameProperty?.yAlign != null) {
|
||||||
pageNum = pageNum.y_align(this.frameProperty.yAlign);
|
pageNum = pageNum.y_align(this.frameProperty.yAlign);
|
||||||
}
|
}
|
||||||
|
if (this.paragraphProperty?.align != null) {
|
||||||
|
const align = createParagraphAlignment(this.paragraphProperty.align);
|
||||||
|
if (align) {
|
||||||
|
pageNum = pageNum.align(align);
|
||||||
|
}
|
||||||
|
}
|
||||||
return pageNum;
|
return pageNum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,9 @@ import { RunProperty, createDefaultRunProperty } from "./run";
|
||||||
import * as wasm from "./pkg";
|
import * as wasm from "./pkg";
|
||||||
import { TextAlignmentType } from "./json/bindings/TextAlignmentType";
|
import { TextAlignmentType } from "./json/bindings/TextAlignmentType";
|
||||||
import { Tab } from "./json/bindings/Tab";
|
import { Tab } from "./json/bindings/Tab";
|
||||||
|
import { AlignmentType } from "./json/bindings/AlignmentType";
|
||||||
|
|
||||||
export type AlignmentType =
|
export { AlignmentType } from "./json/bindings/AlignmentType";
|
||||||
| "center"
|
|
||||||
| "left"
|
|
||||||
| "right"
|
|
||||||
| "both"
|
|
||||||
| "justified"
|
|
||||||
| "distribute"
|
|
||||||
| "end";
|
|
||||||
|
|
||||||
export type SpecialIndentKind = "firstLine" | "hanging";
|
export type SpecialIndentKind = "firstLine" | "hanging";
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "docx-wasm",
|
"name": "docx-wasm",
|
||||||
"version": "0.4.15",
|
"version": "0.4.16",
|
||||||
"main": "dist/node/index.js",
|
"main": "dist/node/index.js",
|
||||||
"browser": "dist/web/index.js",
|
"browser": "dist/web/index.js",
|
||||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||||
|
@ -24,32 +24,5 @@
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"**/serialize-javascript": "6.0.1"
|
"**/serialize-javascript": "6.0.1"
|
||||||
},
|
}
|
||||||
"devDependencies": {
|
}
|
||||||
"@types/file-saver": "2.0.5",
|
|
||||||
"@wasm-tool/wasm-pack-plugin": "1.6.0",
|
|
||||||
"adm-zip": "0.5.10",
|
|
||||||
"cpy-cli": "4.2.0",
|
|
||||||
"file-saver": "2.0.5",
|
|
||||||
"html-webpack-plugin": "5.5.3",
|
|
||||||
"jest": "28.1.3",
|
|
||||||
"npm-run-all": "4.1.5",
|
|
||||||
"text-encoding": "0.7.0",
|
|
||||||
"ts-loader": "9.4.2",
|
|
||||||
"typescript": "4.9.3",
|
|
||||||
"webpack": "4.46.0",
|
|
||||||
"webpack-cli": "5.0.1",
|
|
||||||
"webpack-dev-server": "3.11.3",
|
|
||||||
"webpack-merge": "5.8.0"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"dist",
|
|
||||||
"dist/web/pkg",
|
|
||||||
"dist/node/pkg",
|
|
||||||
"js/*"
|
|
||||||
],
|
|
||||||
"module": "dist/web/index.js",
|
|
||||||
"types": "dist/web/index.d.ts",
|
|
||||||
"dependencies": {}
|
|
||||||
}
|
|
||||||
|
|
|
@ -76,4 +76,15 @@ impl PageNum {
|
||||||
self.0.frame_property = Some(self.0.frame_property.unwrap_or_default().height(n));
|
self.0.frame_property = Some(self.0.frame_property.unwrap_or_default().height(n));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: add other pPr fields
|
||||||
|
pub fn align(mut self, alignment_type: docx_rs::AlignmentType) -> Self {
|
||||||
|
self.0.paragraph_property = Some(
|
||||||
|
self.0
|
||||||
|
.paragraph_property
|
||||||
|
.unwrap_or_default()
|
||||||
|
.align(alignment_type),
|
||||||
|
);
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1046,7 +1046,7 @@ describe("writer", () => {
|
||||||
|
|
||||||
test("should write pageNum in header", () => {
|
test("should write pageNum in header", () => {
|
||||||
const p = new w.Paragraph().addRun(new w.Run().addText("Hello world!!"));
|
const p = new w.Paragraph().addRun(new w.Run().addText("Hello world!!"));
|
||||||
const page = new w.PageNum();
|
const page = new w.PageNum().align('center');
|
||||||
const header = new w.Header().addParagraph(p).addPageNum(page);
|
const header = new w.Header().addParagraph(p).addPageNum(page);
|
||||||
const buffer = new w.Docx().header(header).addParagraph(p).build();
|
const buffer = new w.Docx().header(header).addParagraph(p).build();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue