Merge branch 'master' of github.com:h4buli/docx

This commit is contained in:
Igor Bulovski
2018-04-17 15:34:46 +02:00
2 changed files with 17 additions and 54 deletions

View File

@ -1,13 +1,14 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent, IXmlableObject } from "file/xml-components";
import { DocumentAttributes } from "../document/document-attributes"; import { DocumentAttributes } from "../document/document-attributes";
import { Indent } from "../paragraph/formatting";
import { RunFonts } from "../paragraph/run/run-fonts";
import { AbstractNumbering } from "./abstract-numbering"; import { AbstractNumbering } from "./abstract-numbering";
import { Num } from "./num"; import { Num } from "./num";
export class Numbering extends XmlComponent { export class Numbering extends XmlComponent {
private nextId: number; private nextId: number;
private abstractNumbering: Array<XmlComponent> = [];
private concreteNumbering: Array<XmlComponent> = [];
constructor() { constructor() {
super("w:numbering"); super("w:numbering");
this.root.push( this.root.push(
@ -33,66 +34,23 @@ export class Numbering extends XmlComponent {
); );
this.nextId = 0; this.nextId = 0;
const abstractNumbering = this.createAbstractNumbering();
abstractNumbering
.createLevel(0, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 720, hanging: 360 }))
.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering
.createLevel(1, "bullet", "o", "left")
.addParagraphProperty(new Indent({ left: 1440, hanging: 360 }))
.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering
.createLevel(2, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 2160, hanging: 360 }))
.addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering
.createLevel(3, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 2880, hanging: 360 }))
.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering
.createLevel(4, "bullet", "o", "left")
.addParagraphProperty(new Indent({ left: 3600, hanging: 360 }))
.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering
.createLevel(5, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 4320, hanging: 360 }))
.addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering
.createLevel(6, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 5040, hanging: 360 }))
.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering
.createLevel(7, "bullet", "o", "left")
.addParagraphProperty(new Indent({ left: 5760, hanging: 360 }))
.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering
.createLevel(8, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 6480, hanging: 360 }))
.addRunProperty(new RunFonts("Wingdings", "default"));
this.createConcreteNumbering(abstractNumbering);
} }
public createAbstractNumbering(): AbstractNumbering { public createAbstractNumbering(): AbstractNumbering {
const num = new AbstractNumbering(this.nextId++); const num = new AbstractNumbering(this.nextId++);
this.root.push(num); this.abstractNumbering.push(num);
return num; return num;
} }
public createConcreteNumbering(abstractNumbering: AbstractNumbering): Num { public createConcreteNumbering(abstractNumbering: AbstractNumbering): Num {
const num = new Num(this.nextId++, abstractNumbering.id); const num = new Num(this.nextId++, abstractNumbering.id);
this.root.push(num); this.concreteNumbering.push(num);
return num; return num;
} }
public prepForXml(): IXmlableObject {
this.abstractNumbering.forEach(x => this.root.push(x));
this.concreteNumbering.forEach(x => this.root.push(x));
return super.prepForXml();
}
} }

View File

@ -136,6 +136,11 @@ export class Paragraph extends XmlComponent {
return this; return this;
} }
public setCustomNumbering(numberId: number, indentLevel: number): Paragraph {
this.properties.push(new NumberProperties(numberId, indentLevel));
return this;
}
public style(styleId: string): Paragraph { public style(styleId: string): Paragraph {
this.properties.push(new Style(styleId)); this.properties.push(new Style(styleId));
return this; return this;