Multiple columns in a section

This commit is contained in:
Zahra
2019-06-21 01:22:27 +05:30
parent 58dc6fe389
commit 1dfc27ba08
6 changed files with 37 additions and 6 deletions

View File

@ -2,10 +2,12 @@ import { XmlAttributeComponent } from "file/xml-components";
export interface IColumnsAttributes {
readonly space?: number;
readonly num?: number;
}
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
protected readonly xmlKeys = {
space: "w:space",
num: "w:num",
};
}

View File

@ -2,11 +2,12 @@ import { XmlComponent } from "file/xml-components";
import { ColumnsAttributes } from "./columns-attributes";
export class Columns extends XmlComponent {
constructor(space: number) {
constructor(space: number, num: number) {
super("w:cols");
this.root.push(
new ColumnsAttributes({
space: space,
num: num,
}),
);
}

View File

@ -26,6 +26,7 @@ describe("SectionProperties", () => {
gutter: 0,
mirror: false,
space: 708,
num: 1,
linePitch: 360,
headers: {
default: new HeaderWrapper(media, 100),
@ -55,7 +56,7 @@ describe("SectionProperties", () => {
},
});
expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708 } } });
expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708, "w:num": 1 } } });
expect(tree["w:sectPr"][3]).to.deep.equal({ "w:docGrid": { _attr: { "w:linePitch": 360 } } });
expect(tree["w:sectPr"][4]).to.deep.equal({ "w:headerReference": { _attr: { "r:id": "rId100", "w:type": "default" } } });
expect(tree["w:sectPr"][5]).to.deep.equal({ "w:footerReference": { _attr: { "r:id": "rId200", "w:type": "even" } } });
@ -82,7 +83,7 @@ describe("SectionProperties", () => {
},
},
});
expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708 } } });
expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708, "w:num": 1 } } });
expect(tree["w:sectPr"][3]).to.deep.equal({ "w:docGrid": { _attr: { "w:linePitch": 360 } } });
});

View File

@ -67,6 +67,7 @@ export class SectionProperties extends XmlComponent {
gutter = 0,
mirror = false,
space = 708,
num = 1,
linePitch = 360,
orientation = PageOrientation.PORTRAIT,
headers,
@ -88,7 +89,7 @@ export class SectionProperties extends XmlComponent {
this.options = options;
this.root.push(new PageSize(width, height, orientation));
this.root.push(new PageMargin(top, right, bottom, left, header, footer, gutter, mirror));
this.root.push(new Columns(space));
this.root.push(new Columns(space, num));
this.root.push(new DocumentGrid(linePitch));
this.addHeaders(headers);