added alignment methods to paragraph style

This commit is contained in:
felipe
2017-03-12 21:40:01 +01:00
parent b3524971ac
commit df8ba1e8b8
2 changed files with 80 additions and 0 deletions

View File

@ -136,6 +136,26 @@ export class ParagraphStyle extends Style {
// --------------------- Paragraph formatting ------------------------ // // --------------------- Paragraph formatting ------------------------ //
public center(): ParagraphStyle {
this.addParagraphProperty(new paragraph.Alignment("center"));
return this;
}
public left(): ParagraphStyle {
this.addParagraphProperty(new paragraph.Alignment("left"));
return this;
}
public right(): ParagraphStyle {
this.addParagraphProperty(new paragraph.Alignment("right"));
return this;
}
public justified(): ParagraphStyle {
this.addParagraphProperty(new paragraph.Alignment("both"));
return this;
}
public indent(left: number, hanging?: number): ParagraphStyle { public indent(left: number, hanging?: number): ParagraphStyle {
this.addParagraphProperty(new paragraph.Indent(left, hanging)); this.addParagraphProperty(new paragraph.Indent(left, hanging));
return this; return this;

View File

@ -212,6 +212,66 @@ describe("ParagraphStyle", () => {
], ],
}); });
}); });
it("#center", () => {
const style = new ParagraphStyle("myStyleId")
.center();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [
{"w:jc": [{_attr: {"w:val": "center"}}]},
]},
{"w:rPr": []},
],
});
});
it("#left", () => {
const style = new ParagraphStyle("myStyleId")
.left();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [
{"w:jc": [{_attr: {"w:val": "left"}}]},
]},
{"w:rPr": []},
],
});
});
it("#right", () => {
const style = new ParagraphStyle("myStyleId")
.right();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [
{"w:jc": [{_attr: {"w:val": "right"}}]},
]},
{"w:rPr": []},
],
});
});
it("#justified", () => {
const style = new ParagraphStyle("myStyleId")
.justified();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [
{"w:jc": [{_attr: {"w:val": "both"}}]},
]},
{"w:rPr": []},
],
});
});
}); });
describe("formatting methods: run properties", () => { describe("formatting methods: run properties", () => {