Skip to content

Commit

Permalink
Merge pull request #43 from jacwright/default-run-styles
Browse files Browse the repository at this point in the history
Making it easier to work with default styles
  • Loading branch information
dolanmiu authored Sep 16, 2017
2 parents 258adba + 190208d commit 5ae02c3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
16 changes: 15 additions & 1 deletion ts/styles/defaults/run-properties.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { RunProperties } from "../../docx/run/properties";
import { XmlComponent } from "../../docx/xml-components";
import { RunFonts } from "../../docx/run/run-fonts";
import { Size } from "../../docx/run/formatting";

export class RunPropertiesDefaults extends XmlComponent {
private properties: RunProperties;

constructor() {
super("w:rPrDefault");
this.root.push(new RunProperties());
this.properties = new RunProperties();
this.root.push(this.properties);
}

public size(size: number): RunPropertiesDefaults {
this.properties.push(new Size(size));
return this;
}

public font(fontName: string): RunPropertiesDefaults {
this.properties.push(new RunFonts(fontName));
return this;
}
}
2 changes: 1 addition & 1 deletion ts/styles/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class DefaultStylesFactory {

public newInstance(): Styles {
const styles = new Styles();
styles.push(new DocumentDefaults());
styles.createDocumentDefaults();

const titleStyle = new TitleStyle();
titleStyle.addRunProperty(new Size(56));
Expand Down
13 changes: 8 additions & 5 deletions ts/styles/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DocumentAttributes } from "../docx/document/document-attributes";
import { XmlComponent } from "../docx/xml-components";
import { ParagraphStyle } from "./style";
import { DocumentDefaults } from "./defaults";

export class Styles extends XmlComponent {

Expand All @@ -14,18 +15,20 @@ export class Styles extends XmlComponent {
w15: "http://schemas.microsoft.com/office/word/2012/wordml",
Ignorable: "w14 w15",
}));
// let latentStyles = new LatentStyles();
// latentStyles.push(new LatentStyleException(new LatentStyleExceptionAttributes({
// name: "Normal"
// })));
// this.root.push(latentStyles);

}

public push(style: XmlComponent): Styles {
this.root.push(style);
return this;
}

public createDocumentDefaults(): DocumentDefaults {
const defaults = new DocumentDefaults();
this.push(defaults);
return defaults;
}

public createParagraphStyle(styleId: string, name?: string): ParagraphStyle {
const para = new ParagraphStyle(styleId, name);
this.push(para);
Expand Down

0 comments on commit 5ae02c3

Please sign in to comment.