Create section properties section
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -9,7 +9,7 @@
|
|||||||
],
|
],
|
||||||
"prettier.trailingComma": "all",
|
"prettier.trailingComma": "all",
|
||||||
"prettier.printWidth": 140,
|
"prettier.printWidth": 140,
|
||||||
"editor.formatOnSave": false,
|
"editor.formatOnSave": true,
|
||||||
"prettier.tabWidth": 4,
|
"prettier.tabWidth": 4,
|
||||||
"prettier.arrowParens": "always",
|
"prettier.arrowParens": "always",
|
||||||
"prettier.bracketSpacing": true,
|
"prettier.bracketSpacing": true,
|
||||||
|
@ -2,22 +2,22 @@ import { assert } from "chai";
|
|||||||
|
|
||||||
import { Utility } from "../../../tests/utility";
|
import { Utility } from "../../../tests/utility";
|
||||||
import { Body } from "./";
|
import { Body } from "./";
|
||||||
import { Columns } from "./columns";
|
import { Columns } from "./section-properties/columns/columns";
|
||||||
import { DocumentGrid } from "./doc-grid";
|
import { DocumentGrid } from "./section-properties/doc-grid/doc-grid";
|
||||||
import { PageMargin } from "./page-margin";
|
import { PageMargin } from "./section-properties/page-margin/page-margin";
|
||||||
import { PageSize } from "./page-size";
|
import { PageSize } from "./section-properties/page-size/page-size";
|
||||||
import { SectionProperties } from "./section-properties";
|
import { SectionProperties } from "./section-properties/section-properties";
|
||||||
|
|
||||||
describe("Body", () => {
|
describe("Body", () => {
|
||||||
let body: Body;
|
let body: Body;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
body = new Body();
|
body = new Body();
|
||||||
body.push(new SectionProperties());
|
body.push(new SectionProperties(0));
|
||||||
body.push(new PageSize());
|
body.push(new PageSize(0, 0));
|
||||||
body.push(new PageMargin());
|
body.push(new PageMargin(0, 0, 0, 0, 0, 0, 0));
|
||||||
body.push(new Columns());
|
body.push(new Columns(0));
|
||||||
body.push(new DocumentGrid());
|
body.push(new DocumentGrid(0));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
import { SectionProperties } from "./section-properties/section-properties";
|
||||||
|
|
||||||
export class Body extends XmlComponent {
|
export class Body extends XmlComponent {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -7,5 +8,21 @@ export class Body extends XmlComponent {
|
|||||||
|
|
||||||
public push(component: XmlComponent): void {
|
public push(component: XmlComponent): void {
|
||||||
this.root.push(component);
|
this.root.push(component);
|
||||||
|
|
||||||
|
this.root.push(
|
||||||
|
new SectionProperties({
|
||||||
|
width: 11906,
|
||||||
|
height: 16838,
|
||||||
|
top: 1440,
|
||||||
|
right: 1440,
|
||||||
|
bottom: 1440,
|
||||||
|
left: 1440,
|
||||||
|
header: 708,
|
||||||
|
footer: 708,
|
||||||
|
gutter: 0,
|
||||||
|
space: 708,
|
||||||
|
linePitch: 360,
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
import { Attributes, XmlComponent } from "file/xml-components";
|
|
||||||
|
|
||||||
export class Columns extends XmlComponent {
|
|
||||||
constructor() {
|
|
||||||
super("w:cols");
|
|
||||||
this.root.push(
|
|
||||||
new Attributes({
|
|
||||||
space: "708",
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
import { Attributes, XmlComponent } from "file/xml-components";
|
|
||||||
|
|
||||||
export class DocumentGrid extends XmlComponent {
|
|
||||||
constructor() {
|
|
||||||
super("w:docGrid");
|
|
||||||
this.root.push(
|
|
||||||
new Attributes({
|
|
||||||
linePitch: "360",
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
import { Attributes, XmlComponent } from "file/xml-components";
|
|
||||||
|
|
||||||
export class PageMargin extends XmlComponent {
|
|
||||||
constructor() {
|
|
||||||
super("w:pgMar");
|
|
||||||
this.root.push(
|
|
||||||
new Attributes({
|
|
||||||
top: "1440",
|
|
||||||
right: "1440",
|
|
||||||
bottom: "1440",
|
|
||||||
left: "1440",
|
|
||||||
header: "708",
|
|
||||||
footer: "708",
|
|
||||||
gutter: "0",
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
import { Attributes, XmlComponent } from "file/xml-components";
|
|
||||||
|
|
||||||
export class PageSize extends XmlComponent {
|
|
||||||
constructor() {
|
|
||||||
super("w:pgSz");
|
|
||||||
this.root.push(
|
|
||||||
new Attributes({
|
|
||||||
w: "11906",
|
|
||||||
h: "16838",
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
import { Attributes, XmlComponent } from "file/xml-components";
|
|
||||||
import { Columns } from "./columns";
|
|
||||||
import { DocumentGrid } from "./doc-grid";
|
|
||||||
import { PageMargin } from "./page-margin";
|
|
||||||
import { PageSize } from "./page-size";
|
|
||||||
|
|
||||||
export class SectionProperties extends XmlComponent {
|
|
||||||
constructor() {
|
|
||||||
super("w:sectPr");
|
|
||||||
this.root.push(
|
|
||||||
new Attributes({
|
|
||||||
rsidR: "00B64E8F",
|
|
||||||
rsidRPr: "00D842E4",
|
|
||||||
rsidSect: "000A6AD0",
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
this.root.push(new PageSize());
|
|
||||||
this.root.push(new PageMargin());
|
|
||||||
this.root.push(new Columns());
|
|
||||||
this.root.push(new DocumentGrid());
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,11 @@
|
|||||||
|
import { XmlAttributeComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
export interface IColumnsAttributes {
|
||||||
|
space?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
|
||||||
|
protected xmlKeys = {
|
||||||
|
space: "w:space",
|
||||||
|
};
|
||||||
|
}
|
13
src/file/document/body/section-properties/columns/columns.ts
Normal file
13
src/file/document/body/section-properties/columns/columns.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
import { ColumnsAttributes } from "./columns-attributes";
|
||||||
|
|
||||||
|
export class Columns extends XmlComponent {
|
||||||
|
constructor(space: number) {
|
||||||
|
super("w:cols");
|
||||||
|
this.root.push(
|
||||||
|
new ColumnsAttributes({
|
||||||
|
space: space,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
import { XmlAttributeComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
export interface IDocGridAttributesProperties {
|
||||||
|
linePitch?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DocGridAttributes extends XmlAttributeComponent<IDocGridAttributesProperties> {
|
||||||
|
protected xmlKeys = {
|
||||||
|
linePitch: "w:linePitch",
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
import { DocGridAttributes } from "./doc-grid-attributes";
|
||||||
|
|
||||||
|
export class DocumentGrid extends XmlComponent {
|
||||||
|
constructor(linePitch: number) {
|
||||||
|
super("w:docGrid");
|
||||||
|
this.root.push(
|
||||||
|
new DocGridAttributes({
|
||||||
|
linePitch: linePitch,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
import { XmlAttributeComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
export interface IPageMarginAttributes {
|
||||||
|
top: number;
|
||||||
|
right: number;
|
||||||
|
bottom: number;
|
||||||
|
left: number;
|
||||||
|
header: number;
|
||||||
|
footer: number;
|
||||||
|
gutter: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class PageMarginAttributes extends XmlAttributeComponent<IPageMarginAttributes> {
|
||||||
|
protected xmlKeys = {
|
||||||
|
top: "w:top",
|
||||||
|
right: "w:right",
|
||||||
|
bottom: "w:bottom",
|
||||||
|
left: "w:left",
|
||||||
|
header: "w:header",
|
||||||
|
footer: "w:footer",
|
||||||
|
gutter: "w:gutter",
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
import { PageMarginAttributes } from "./page-margin-attributes";
|
||||||
|
|
||||||
|
export class PageMargin extends XmlComponent {
|
||||||
|
constructor(top: number, right: number, bottom: number, left: number, header: number, footer: number, gutter: number) {
|
||||||
|
super("w:pgMar");
|
||||||
|
this.root.push(
|
||||||
|
new PageMarginAttributes({
|
||||||
|
top: top,
|
||||||
|
right: right,
|
||||||
|
bottom: bottom,
|
||||||
|
left: left,
|
||||||
|
header: header,
|
||||||
|
footer: footer,
|
||||||
|
gutter: gutter,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
import { XmlAttributeComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
export interface IPageSizeAttributes {
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> {
|
||||||
|
protected xmlKeys = {
|
||||||
|
width: "w:w",
|
||||||
|
height: "w:h",
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
import { PageSizeAttributes } from "./page-size-attributes";
|
||||||
|
|
||||||
|
export class PageSize extends XmlComponent {
|
||||||
|
constructor(width: number, height: number) {
|
||||||
|
super("w:pgSz");
|
||||||
|
|
||||||
|
this.root.push(
|
||||||
|
new PageSizeAttributes({
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
// http://officeopenxml.com/WPsection.php
|
||||||
|
import { IColumnsAttributes } from "file/document/body/section-properties/columns/columns-attributes";
|
||||||
|
import { IPageMarginAttributes } from "file/document/body/section-properties/page-margin/page-margin-attributes";
|
||||||
|
import { IPageSizeAttributes } from "file/document/body/section-properties/page-size/page-size-attributes";
|
||||||
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
import { Columns } from "./columns/columns";
|
||||||
|
import { DocumentGrid } from "./doc-grid/doc-grid";
|
||||||
|
import { IDocGridAttributesProperties } from "./doc-grid/doc-grid-attributes";
|
||||||
|
import { PageMargin } from "./page-margin/page-margin";
|
||||||
|
import { PageSize } from "./page-size/page-size";
|
||||||
|
|
||||||
|
export type SectionPropertiesOptions = IPageSizeAttributes & IPageMarginAttributes & IColumnsAttributes & IDocGridAttributesProperties;
|
||||||
|
|
||||||
|
export class SectionProperties extends XmlComponent {
|
||||||
|
constructor(options: SectionPropertiesOptions) {
|
||||||
|
super("w:sectPr");
|
||||||
|
|
||||||
|
this.root.push(new PageSize(11906, 16838));
|
||||||
|
this.root.push(new PageMargin(1440, 1440, 1440, 1440, 708, 708, 0));
|
||||||
|
this.root.push(new Columns(708));
|
||||||
|
this.root.push(new DocumentGrid(308));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user